var nodes = [
{id: 1001, label: "A"},
{id: 1002, label: "B"},
{id: 1003, label: "C"},
{id: 1004, label: "D"},
{id: 1005, label: "E"},
{id: 1006, label: "F"},
{id: 1007, label: "G"},
{id: 1008, label: "H"},
{id: 1009, label: "I"}
];
var edges = [
{from:1002,to:1001,id:"10021001"},//B>A
{from:1003,to:1002,id:"10031002"},//C>B
{from:1004,to:1003,id:"10021001"},//D>C
{from:1005,to:1003,id:"10021001"},//E>C
{from:1006,to:1002,id:"10021001"},//F>B
{from:1007,to:1004,id:"10021001"},//G>D
{from:1008,to:1007,id:"10021001"},//H>G
{from:1009,to:1007,id:"10021001"} //I>G
]
graph LR
B-->A
C-->B
F-->B
D-->C
E-->C
G-->D
H-->G
I-->G
当删除 D 时,G、H、I 及连接线都要清除,数据是这样的
var nodes = [
{id: 1001, label: "A"},
{id: 1002, label: "B"},
{id: 1003, label: "C"},
{id: 1005, label: "E"},
{id: 1006, label: "F"}
];
var edges = [
{from:1002,to:1001,id:"10021001"},//B>A
{from:1003,to:1002,id:"10031002"},//C>B
{from:1005,to:1003,id:"10021001"},//E>C
{from:1006,to:1002,id:"10021001"}//F>B
]
graph LR
B-->A
C-->B
F-->B
E-->C
1
XiaoxiaoPu 2017-05-26 10:30:13 +08:00 via iPhone 1
遍历图,找出 D 的前驱和后继,删除包含 D 的边,新建从 D 的前驱到 D 的后继的边
|
2
yalanaika 2017-05-26 10:30:18 +08:00
写个递归
|
3
WenJimmy OP id 忘记改了,是 from 到 to 的 id 拼接
|
4
Exin 2017-05-26 10:31:18 +08:00 via iPhone 1
将 edge 数据整合到 nodes 中,令每个 node 中包含连接到它的点的数据(不能修改 nodes 数组的话另起一个哈希表 /Map 也是可以的)
删除的时候递归一下就行了 |
5
WenJimmy OP @XiaoxiaoPu #1 太高深了,看不懂
|