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组件
- Host: GitHub
- URL: https://github.com/renzp94/x6-react-components
- Owner: renzp94
- Created: 2023-12-15T10:04:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-22T03:31:31.000Z (about 1 year ago)
- Last Synced: 2025-02-10T17:44:15.263Z (4 months ago)
- Language: TypeScript
- Size: 399 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
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
```
