Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ensure only one vedge connects a combo to a node #6488

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
27 changes: 25 additions & 2 deletions packages/core/tests/unit/graph/graph-combo-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 });

Expand Down
Loading