An open API service indexing awesome lists of open source software.

https://github.com/renzp94/x6-react-components

基于@antv/x6封装的React组件
https://github.com/renzp94/x6-react-components

Last synced: 3 months ago
JSON representation

基于@antv/x6封装的React组件

Awesome Lists containing this project

README

        




@renzp/x6-react-components



基于@antv/x6封装的React组件

## 安装

```sh
npm install @antv/x6 @renzp/x6-react-components
```

## 使用

```ts
import { Graph } from '@antv/x6'
import { useRef } from 'react'
import {
X6CircleNode,
X6Graph,
X6ImageEdge,
X6RectNode,
X6SnapLine,
X6ZoomTools,
XDotGrid,
} from '../packages'
import ArrowImg from './assets/arrow.png'

const App = () => {
const ref = useRef()
const nodes = Array.from({ length: 10 }).map((_, i: number) => {
return {
id: `node_${i}`,
name: `Node-${i + 1}`,
x: 200 * (i + 1),
y: 400,
type: i % 2 ? 'rect' : 'circle',
}
})

const edges = nodes.reduce((prev: Array, curr, i: number) => {
let source = ''
let target = ''

if (i < nodes.length - 1) {
const nextTarget = nodes[i + 1]
source = curr.id
target = nextTarget.id
} else {
return prev
}
return [...prev, { source, target }]
}, [])

const x6Data: any = { nodes, edges }

const onMount = (graph: Graph) => {
ref.current = graph
}

return (






{x6Data.nodes.map((item: any) => {
return item.type === 'rect' ? (

) : (

)
})}
{x6Data.edges.map((item: any, i: number) => {
return (

)
})}

{}

)
}

export default App
```
![](demo.png)