Ensure only one vedge connects a combo to a node (#6488)

This commit is contained in:
Fabio Tacchelli 2024-11-08 07:18:59 +01:00 committed by GitHub
parent 1baa161d9f
commit 36b58da39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View File

@ -2781,6 +2781,12 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
if (addedVEdgeMap[key]) {
addedVEdgeMap[key].size += size;
return;
} else {
const inverseKey = `${vEdgeInfo.target}-${vEdgeInfo.source}`;
if (addedVEdgeMap[inverseKey]) {
addedVEdgeMap[inverseKey].size += size;
return;
}
}
addedVEdgeMap[key] = vEdgeInfo;
}

View File

@ -45,7 +45,7 @@ export const dataValidation = (data?: GraphData | TreeGraphData): boolean => {
// 3. 边的 source 和 target 必须存在于节点 或 Combo中
const ids = new Set<string>();
((nodes as NodeConfig[]) || []).forEach(node => ids.add(node.id));
((nodes as ComboConfig[]) || []).forEach(combo => ids.add(combo.id));
((combos as ComboConfig[]) || []).forEach(combo => ids.add(combo.id));
const nonEdges = ((edges as EdgeConfig[]) || []).find(function (edge) {
return !ids.has(edge.source) || !ids.has(edge.target);
});

View File

@ -114,14 +114,14 @@ const data = {
describe('graph with combo', () => {
let graph: Graph;
function makeGraph(config = {}) {
function makeGraph(config = {}, forceData = undefined) {
graph = new Graph({
container: div,
width: 500,
height: 600,
...config
});
graph.read(clone(data));
graph.read(clone(forceData || data));
}
it('createCombo', () => {
@ -329,6 +329,29 @@ describe('graph with combo', () => {
graph.destroy();
});
it('collapse combo should create only one edge', () => {
// this data reproduces the issue where one combo was connected to a node with 2 vedges
const data = {
nodes: [
{ id: "node1", x: 250, y: 150, comboId: "combo" },
{ id: "node2", x: 350, y: 150, comboId: "combo" },
{ id: "node3", x: 250, y: 300 },
],
combos: [{ id: "combo", label: "Combo" }],
edges: [
{ id: "edge1", source: "node1", target: "node3" },
{ id: "edge2", target: "node2", source: "node3" },
],
};
makeGraph({}, data);
graph.collapseCombo('combo');
const edges = graph.get('vedges');
expect(edges).toHaveLength(1);
});
it('combo mapper', () => {
makeGraph({ groupByTypes: false });