在使用D3画力导向图(force-directed graph)时,报错:
Cannot construct a LineSegment with two equal endpoints.
原因可能有:
一、存在不同节点的name值一样的情况
[ { "name" : "Fauchelevent", // Duplicated "type" : "group0", "depends" : [ "Valjean", "Javert" ] }, { "name" : "Myriel", "type" : "group1", "depends" : [] }, { "name" : "Fauchelevent", // Duplicated "type" : "group1", "depends" : [ "Myriel" ] } ]
二、存在自回环情况
也就是节点出来的线又指向了这个节点,也就是depends里面有这个节点的name值,
这种情况下从depends里面剔除这个节点的name值就好了,
stackoverflow也有这个问题:
https://stackoverflow.com/questions/28811950/uncaught-error-cannot-construct-a-line-segment-with-two-equal-endpoints