antvis/G6

两个节点中有多条线,一半红色一半绿色,线重叠 #4518

pupu0520 posted onGitHub

问题描述

// 两个节点中有多条线,一半红色一半绿色,如何不重叠 import G6 from '@antv/g6';

/**

  • Extend the built-in line edge and override getPath and getShapeStyle to custom a polyline edge
  • by siogo's issue(https://github.com/antvis/g6/issues/814)
  • If you want to fit the dragging, you need to adjust the controlpoints while dragging
  • /

G6.registerEdge( 'line-arrow', { draw(cfg, group) { const startPoint = cfg.startPoint; const endPoint = cfg.endPoint; const midPoint = { x: startPoint.x + (endPoint.x - startPoint.x) / 2, y: startPoint.y + (endPoint.y - startPoint.y) / 2, }; group.addShape('path', { attrs: { path: [ ['M', startPoint.x, startPoint.y], ['L', midPoint.x, midPoint.y], ], stroke: 'red', lineWidth: 1 }, name: 'path-left', }); group.addShape('path', { attrs: { path: [ ['M', midPoint.x, midPoint.y], ['L', endPoint.x, endPoint.y], ], stroke: 'green', lineWidth: 1 }, name: 'path-right', }); return group; }, update: undefined }, 'line', );

const data = { nodes: [ { id: '7', x: 150, y: 100, size: 40, anchorPoints: [ [1, 0.5], [1, 0], ], }, { id: '8', x: 300, y: 200, size: 40, anchorPoints: [ [0, 0.5], [0, 1], ], }, ], edges: [ { source: '7', target: '8', sourceAnchor: 0, targetAnchor: 0, }, { source: '8', target: '7', sourceAnchor: 0, targetAnchor: 0, }, ], };

const container = document.getElementById('container'); const width = container.scrollWidth; const height = container.scrollHeight || 500; const graph = new G6.Graph({ container: 'container', width, height, // translate the graph to align the canvas's center, support by v3.5.1 fitCenter: true, modes: { // behavior default: ['drag-node', 'drag-canvas'], }, defaultNode: { type: 'circle', style: { fill: '#DEE9FF', stroke: '#5B8FF9', }, linkPoints: { left: true, right: true, fill: '#fff', stroke: '#1890FF', size: 3, }, }, defaultEdge: { type: 'line-arrow', }, });

graph.data(data); graph.render();

const edges = graph.save().edges; G6.Util.processParallelEdges(edges);

if (typeof window !== 'undefined') window.onresize = () => { if (!graph || graph.get('destroyed')) return; if (!container || !container.scrollWidth || !container.scrollHeight) return; graph.changeSize(container.scrollWidth, container.scrollHeight); };

重现链接

https://g6.antv.antgroup.com/examples/item/customEdge/#customPolyline

重现步骤

问题描述代码

预期行为

不重叠

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.5.1 ... ]

屏幕截图或视频(可选)

image

补充说明(可选)

No response


自定义边 或者 或者使用 G6.Util.processParallelEdges(graph.edges)统一处理边

posted by auuunya almost 2 years ago

自定义边 或者 或者使用 G6.Util.processParallelEdges(graph.edges)统一处理边

问题描述中就是使用自定义线,不知道如何产生弧度。使用processParallelEdges方法修改了自定的样式

posted by pupu0520 almost 2 years ago

弧度需要你自己计算自己画,使用贝塞尔曲线画路径path就好了

posted by auuunya almost 2 years ago

你的例子中写死了直线,所有边的路径都一样,一定会重叠的。可以用贝塞尔曲线加渐变色 https://codesandbox.io/s/broken-glade-u6hzfr

posted by Yanyan-Wang almost 2 years ago

你的例子中写死了直线,所有边的路径都一样,一定会重叠的。可以用贝塞尔曲线加渐变色 https://codesandbox.io/s/broken-glade-u6hzfr

image 这样处理后,节点移动并没有等分为两条线 只在上述列子中添加linkCenter:true

posted by pupu0520 almost 2 years ago

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 10 months ago

Fund this Issue

$0.00
Funded

Pull requests