Is there a way to group edges with the same source and target into a single edge? #6821
Replies: 6 comments 3 replies
-
In the latest version of G6, you can achieve the grouping of edges with the same source and target into a single edge by using custom rendering logic. Here's a general approach to achieve this:
Here's a basic example of how you might implement this: // Assuming you have a graph instance
graph.on('afterlayout', () => {
const edges = graph.getEdges();
const edgeMap = {};
edges.forEach(edge => {
const source = edge.getSource().getID();
const target = edge.getTarget().getID();
const key = `${source}-${target}`;
if (!edgeMap[key]) {
edgeMap[key] = {
count: 0,
titles: [],
edge
};
}
edgeMap[key].count += 1;
edgeMap[key].titles.push(edge.getModel().label);
});
Object.values(edgeMap).forEach(({ count, titles, edge }) => {
if (count > 1) {
graph.updateItem(edge, {
style: {
lineWidth: count, // Adjust thickness based on count
},
label: titles.join(', ') // Combine titles
});
}
});
}); This code snippet demonstrates how to aggregate edges and update their styles based on the number of edges between the same source and target. You can customize the logic further to fit your specific requirements. If you need more detailed guidance or have specific requirements, feel free to ask! 🪧 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 like you've shared a detailed explanation on how to group edges with the same source and target into a single edge in G6. If you have any specific questions or need further clarification on any part of the process, feel free to ask! I'm here to help with any additional guidance or information you might need. 🪧 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 like you've shared a detailed explanation on how to group edges with the same source and target into a single edge in G6. If you have any specific questions or need further clarification on any part of the process, feel free to ask! I'm here to help with any additional guidance or information you might need. 🪧 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.
-
@petercat-assistant is there a way to catch expand\collapse event on combo? From expanded combo class? |
Beta Was this translation helpful? Give feedback.
-
In G6, you can catch the expand and collapse events on a combo by listening to the Here's an example of how you can catch these events: // Assuming you have a graph instance
graph.on('combo:expand', (evt) => {
const combo = evt.item; // The combo that was expanded
console.log('Combo expanded:', combo);
// Perform actions when a combo is expanded
});
graph.on('combo:collapse', (evt) => {
const combo = evt.item; // The combo that was collapsed
console.log('Combo collapsed:', combo);
// Perform actions when a combo is collapsed
}); In this example, when a combo is expanded or collapsed, the corresponding event listener is triggered, and you can access the combo item through If you need further assistance or have more specific requirements, feel free to ask! 🪧 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.
-
In G6, you can catch the expand and collapse events on a combo by listening to the Here's an example of how you can catch these events: // Assuming you have a graph instance
graph.on('combo:expand', (evt) => {
const combo = evt.item; // The combo that was expanded
console.log('Combo expanded:', combo);
// Perform actions when a combo is expanded
});
graph.on('combo:collapse', (evt) => {
const combo = evt.item; // The combo that was collapsed
console.log('Combo collapsed:', combo);
// Perform actions when a combo is collapsed
}); In this example, when a combo is expanded or collapsed, the corresponding event listener is triggered, and you can access the combo item through If you need further assistance or have more specific requirements, feel free to ask! 🪧 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.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to group edges that go from the same source to the same target (when combos are collapsed) into a single edge with a different thickness and a combined title?
Beta Was this translation helpful? Give feedback.
All reactions