【发布时间】:2017-10-21 03:32:32
【问题描述】:
我正在尝试从this example 做力导向图,但我的数据非常大(5000 个节点),所以我想删除一些不链接到任何其他节点的节点。
但是,在我的 JSON 中,每个节点至少有 1 个链接(链接到自身)。这是我的数据示例:
{"directed": false, "graph": {},
"nodes": [{"id": 0}, {"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5},
{"id": 6}, {"id": 7}, {"id": 8}, {"id": 9}, {"id": 10}, {"id": 11}, {"id": 12}],
"links": [{"source": 0, "target": 0}, {"source": 1, "target": 1},
{"source": 2, "target": 2}, {"source": 3, "target": 3},
{"source": 4, "target": 4}, {"source": 5, "target": 5},
{"source": 6, "target": 6}, {"source": 7, "target": 8},
{"source": 7, "target": 9}, {"source": 7, "target": 10},
{"source": 7, "target": 11}, {"source": 7, "target": 7},
{"source": 8, "target": 8}, {"source": 9, "target": 9},
{"source": 10, "target": 10}, {"source": 11, "target": 11},
{"source": 12, "target": 12}], "multigraph": false}
即,节点id:0 仅具有链接{"source": 0, "target": 0},因此应将其删除,但节点id:7 具有链接{"source": 7, "target": 8}, {"source": 7, "target": 7}。它已链接到另一个节点,因此不应被删除。
我的问题是如何删除只链接到自身的节点?
【问题讨论】:
标签: javascript d3.js graph force-layout