-
I see that there is an old version of G6 where this could be solved by custom edge: http://g6-v3-2.antv.vision/en/docs/manual/FAQ/multi-line But in v5, it seems that I cannot access the edge data when implementing a custom edge? How could I do it in v5? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
In G6 version 5, implementing multiple edges between nodes can be achieved by customizing the edge rendering. Although the approach has changed from previous versions, you can still create custom edges by leveraging the new API and features available in G6 v5. Here's a general approach to implement multiple edges between nodes in G6 v5:
Here's a basic example of how you might define a custom edge to handle multiple edges between nodes: import G6 from '@antv/g6';
// Define a custom edge
G6.registerEdge('custom-edge', {
draw(cfg, group) {
const startPoint = cfg.startPoint;
const endPoint = cfg.endPoint;
// Create a path for the edge
const path = [
['M', startPoint.x, startPoint.y],
['L', endPoint.x, endPoint.y],
];
// Draw the edge
const keyShape = group.addShape('path', {
attrs: {
path,
stroke: '#333',
lineWidth: 2,
},
});
return keyShape;
},
afterDraw(cfg, group) {
// Access edge data and modify the edge if needed
// Example: Add a label or additional visual elements
},
});
// Initialize the graph
const graph = new G6.Graph({
container: 'mountNode',
width: 800,
height: 600,
defaultEdge: {
type: 'custom-edge',
},
modes: {
default: ['drag-canvas', 'zoom-canvas'],
},
});
// Add nodes and edges
graph.data({
nodes: [
{ id: 'node1', x: 100, y: 200 },
{ id: 'node2', x: 300, y: 200 },
],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node1', target: 'node2' }, // Multiple edges
],
});
graph.render(); This example demonstrates how to create a custom edge type and use it to render multiple edges between two nodes. You can further customize the appearance and behavior of the edges by modifying the If you have specific requirements or encounter any issues, feel free to ask for further assistance! 🪧 TipsFor further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. |
Beta Was this translation helpful? Give feedback.
-
It seems that could be done by |
Beta Was this translation helpful? Give feedback.
-
It is called parallel edges in docs. https://g6.antv.antgroup.com/manual/transform/build-in/process-parallel-edges |
Beta Was this translation helpful? Give feedback.
It is called parallel edges in docs.
https://g6.antv.antgroup.com/manual/transform/build-in/process-parallel-edges