lloydzhou / react-x6

react-reconciler to render x6 object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-x6

NPM Package npm bundle size npm MIT License

提供自定义渲染器在react中直接渲染x6画布

  1. 使用react-reconciler自定义渲染器
  2. 只需抽象create/update/removeFrom既可
  3. 最后渲染出来的instance就是Graph/Node/Edge对象,这些对象使用ref可以直接绑定
  4. Graph内部将Children做进一步处理,通过cloneElement强行生成带key的子组件(避免list diff导致元素id变化)

安装

npm install react-x6
yarn add react-x6

demo

online demo

import { Graph, Node, Edge } from 'react-x6'
import { Snapline } from "@antv/x6-plugin-snapline";

// 使用ElementOfPlugin定义组件
const SnaplinePlugin = ElementOfPlugin('Snapline', Snapline)


export default function App() {
  // ...
  return (
    <Graph background grid width={800} height={600}>
      <SnaplinePlugin key="snapline" enabled={true}/>
      <Node id="1" x={100} y={100} label="node1" width={80} height={40}></Node>
      <Node id="3" x={200} y={100} label="node3" width={80} height={40} parent="1" />
      <Node id="2" x={200} y={200} label="node2" width={80} height={40} />
      <Node id="4" x={200} y={250} label="node4" width={80} height={40} ref={node4} />
      <Node id="5" x={300} y={250} label="node5" width={80} height={40} onClick={e => {
        console.log('onClick', e)
      }} />
      <Edge source="1" target="2" />
    </Graph>
  )
}

TODO

  • 提供渲染器
  • Graph组件
  • Node/Edge组件
  • ElementOfPlugin函数方便封装官方plugin
  • Label(Edge)
  • NodePort
  • NodeTool/EdgeTool
  • SourceMarker/TargetMarker

changelog

2023-03-22

remove Fragment, using flat array

About

react-reconciler to render x6 object

License:MIT License


Languages

Language:TypeScript 87.6%Language:CSS 10.3%Language:HTML 2.1%