1. CanvasScaleToolbar 缩放工具
    1. image.png
  2. CanvasMiniMap 迷你地图
    1. image.png
  3. CanvasSnapline 对齐线
    1. image.png
  4. CanvasContextMenu
    1. image.png
  5. CanvasNodePortTooltip

  1. import {useGraphConfig} from './config';
  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: 200,
  16. height: 80,
  17. }}
  18. position={{top: 12, right: 12}}
  19. />
  20. {/*对齐线*/}
  21. <CanvasSnapline color="#1890ff"/>
  22. </XFlowCanvas>
  23. </XFlow>
  24. )
  25. }

graphConfig

  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. grid: true, // 画布网格
  12. scaling: { // 画布缩放等级
  13. min: 0.2,
  14. max: 3,
  15. },
  16. // 画布滚轮缩放
  17. mousewheel: {
  18. enabled: true,
  19. /** 将鼠标位置作为中心缩放 */
  20. zoomAtMousePosition: true,
  21. },
  22. });
  23. // 设置XFlow画布需要渲染的React节点/边
  24. config.setNodeRender('NODE1', (props) => <Node1 {...props} />);
  25. config.setNodeRender('NODE2', Node2);
  26. config.setEdgeRender('EDGE1', (props) => <Edge1 {...props} />);
  27. config.setEdgeRender('EDGE2', (props) => <Edge2 {...props} />);
  28. });

setX6Config