mirror of
https://gitee.com/antv/g6.git
synced 2024-12-01 19:28:39 +08:00
Ensure only one vedge connects a combo to a node (#6488)
This commit is contained in:
parent
1baa161d9f
commit
36b58da39f
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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 });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user