image.png

  1. const useGraphConfig = createGraphConfig(config => {})
  2. // Object.keys(config)
  3. [
  4. "CONFIG_TYPE",
  5. "dispose",
  6. "edgeRender",
  7. "edgeTypeParser",
  8. "events",
  9. "getConfig",
  10. "getDefaultGraphOptions",
  11. "getX6Config",
  12. "graphContainer",
  13. "graphId",
  14. "mergeX6Config",
  15. "nodeRender",
  16. "nodeTypeParser",
  17. "rootContainer",
  18. "setAppContainer",
  19. "setDefaultEdgeRender",
  20. "setDefaultNodeRender",
  21. "setEdgeRender",
  22. "setEdgeTypeParser",
  23. "setEvents",
  24. "setGraphContainer",
  25. "setNodeRender",
  26. "setNodeTypeParser",
  27. "setRootContainer",
  28. "setX6Config",
  29. "x6Options"
  30. ]

setX6Config

https://antv-xflow.gitee.io/api/interface/graph

grid网格配置

https://X6.antv.vision/zh/docs/tutorial/basic/grid

useGraphConfig

  1. import {useGraphConfig} from './config-graph';
  2. function App() {
  3. // 画布配置
  4. const graphConfig = useGraphConfig();
  5. return (
  6. <XFlow>
  7. <XFlowCanvas config={graphConfig}>
  8. {/*缩放工具*/}
  9. <CanvasScaleToolbar position={{top: 8, left: 8}}/>
  10. {/*迷你地图*/}
  11. <CanvasMiniMap
  12. miniMapClz="xflow-custom-minimap"
  13. nodeFillColor="#ccc"
  14. minimapOptions={{
  15. width: 120,
  16. height: 80,
  17. }}
  18. position={{top: 12, right: 12}}
  19. />
  20. {/*对齐线*/}
  21. <CanvasSnapline color="#1890ff"/>
  22. </XFlowCanvas>
  23. </XFlow>
  24. )
  25. }

config-graph

  1. import React from 'react';
  2. import { createGraphConfig } from '@antv/xflow';
  3. /** 自定义React节点/边 */
  4. import Node1 from '../node/node1';
  5. import Node2 from '../node/node2';
  6. import Edge1 from '../edge/edge1';
  7. import Edge2 from '../edge/edge2';
  8. export const useGraphConfig = createGraphConfig((config) => {
  9. // XFlow画布配置项
  10. config.setX6Config({
  11. // 画布网格
  12. grid: {
  13. size: 8,
  14. visible: true,
  15. },
  16. // 画布缩放等级
  17. scaling: {
  18. min: 0.2,
  19. max: 3,
  20. },
  21. // 画布滚轮缩放
  22. mousewheel: {
  23. enabled: true,
  24. /** 将鼠标位置作为中心缩放 */
  25. zoomAtMousePosition: true,
  26. },
  27. });
  28. // 设置XFlow画布需要渲染的React节点/边
  29. config.setNodeRender('NODE1', (props) => <Node1 {...props} />);
  30. config.setNodeRender('NODE2', Node2);
  31. config.setEdgeRender('EDGE1', (props) => <Edge1 {...props} />);
  32. config.setEdgeRender('EDGE2', (props) => <Edge2 {...props} />);
  33. });