我正在使用arbor js使用基于力的算法创建图表。
我希望能够在总能量低于某个点之后保存节点的x,y系统坐标,以便我可以在访问图形时将它们加载回来,以避免重新从头开始处理所有能量。
我这样做有两个问题:
sys.energy().sum
始终返回NaN
setTimeout
来保存图表节点位置当我尝试将数据加载到图表中时(使用sys.merge
或sys.addNode
)保存xy,我能够将节点x,y系统坐标保存到DB坐标,图形无法显示,控制台日志中显示“内存不足”消息。
以下是节点x,y系统坐标已保存的数据示例,这会导致arbor js崩溃加载:
{"nodes":{"0":{"edgeCount":0,"x":13.11901,"y":14.89151,"id":0,"name":"Global"},"23":
{"edgeCount":1,"x":18.08981,"y":-0.8355745,"id":23,"name":"Aristotle"},"26":
{"edgeCount":1,"x":5.688836,"y":14.86863,"id":26,"name":"Socrates"},"27":
{"edgeCount":1,"x":14.84461,"y":-1.687457,"id":27,"name":"Christianity"},"34":
{"edgeCount":1,"x":-2.265221,"y":13.59168,"id":34,"name":"Maths"},"91":
{"edgeCount":11,"x":5.868572,"y":-1.315289,"id":91,"name":"Plato"},"92":
{"edgeCount":4,"x":-3.14131,"y":8.81194,"id":92,"name":"Virtue"},"127":
{"edgeCount":1,"x":-3.308347,"y":8.463552,"id":127,"name":"Poetry"},"131":
{"edgeCount":1,"x":7.605158,"y":-3.951363,"id":131,"name":"Wisdom"},"147":
{"edgeCount":1,"x":6.195698,"y":-4.572639,"id":147,"name":"Person"},"149":
{"edgeCount":1,"x":2.10395,"y":-2.390886,"id":149,"name":"Republic"},"171":
{"edgeCount":1,"x":3.359434,"y":-3.996424,"id":171,"name":"Justice"},"172":
{"edgeCount":1,"x":-0.2544371,"y":-4.218832,"id":172,"name":"Temperance"},"173":
{"edgeCount":1,"x":-8.773163,"y":2.587845,"id":173,"name":"Courage"},"178":
{"edgeCount":1,"x":-2.380451,"y":-5.787674,"id":178,"name":"Schopenhauer"},"194":
{"edgeCount":2,"x":-7.747643,"y":-1.653015,"id":194,"name":"Beauty"},"195":
{"edgeCount":1,"x":-10.45985,"y":-2.670299,"id":195,"name":"Objective"},"196":
{"edgeCount":1,"x":-10.64573,"y":-6.874766,"id":196,"name":"Truth"},"219":
{"edgeCount":1,"x":-6.22574,"y":-7.565969,"id":219,"name":"Theory of forms"},"221":
{"edgeCount":1,"x":-8.314561,"y":-7.570002,"id":221,"name":"Platinus"},"245":
{"edgeCount":0,"x":-13.20351,"y":-8.421284,"id":245,"name":"Diagram"},"254":
{"edgeCount":1,"x":-13.54734,"y":-7.7437,"id":254,"name":"Green"}},
"edges":{"23":{"91":{"context":{"id":0,"name":"Global"},"source":
{"id":23,"name":"Aristotle"},"predicate":{"id":21,"name":"studied with"},"target":
{"id":91,"name":"Plato"}}},"26":{"91":{"context":{"id":0,"name":"Global"},"source":
{"id":26,"name":"Socrates"},"predicate":{"id":2,"name":"inspires"},"target":
{"id":91,"name":"Plato"}}},"91":{"149":{"context":{"id":0,"name":"Global"},"source":
{"id":91,"name":"Plato"},"predicate":{"id":1,"name":"writes"},"target":
{"id":149,"name":"Republic"}},"219":{"context":{"id":0,"name":"Global"},"source":
{"id":91,"name":"Plato"},"predicate":{"id":1,"name":"writes"},"target":{"id":219,"name":"Theory of forms"}},"27":{"context":{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":
{"id":3,"name":"influences"},"target":{"id":27,"name":"Christianity"}},"178":{"context":
{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":
{"id":3,"name":"influences"},"target":{"id":178,"name":"Schopenhauer"}},"221":{"context":
{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":
{"id":3,"name":"influences"},"target":{"id":221,"name":"Platinus"}},"254":{"context":
{"id":245,"name":"Diagram"},"source":{"id":91,"name":"Plato"},"predicate":
{"id":28,"name":"is"},"target":{"id":254,"name":"Green"}},"34":{"context":
{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":{"id":33,"name":"is associated with"},"target":{"id":34,"name":"Maths"}},"127":{"context":
{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":{"id":47,"name":"is obsessed with"},"target":{"id":127,"name":"Poetry"}},"147":{"context":
{"id":0,"name":"Global"},"source":{"id":91,"name":"Plato"},"predicate":{"id":56,"name":"is type of"},"target":{"id":147,"name":"Person"}}},"92":{"131":{"context":{"id":91,"name":"Plato"},"source":
{"id":92,"name":"Virtue"},"predicate":{"id":28,"name":"is"},"target":
{"id":131,"name":"Wisdom"}},"171":{"context":{"id":91,"name":"Plato"},"source":
{"id":92,"name":"Virtue"},"predicate":{"id":28,"name":"is"},"target":
{"id":171,"name":"Justice"}},"172":{"context":{"id":91,"name":"Plato"},"source":
{"id":92,"name":"Virtue"},"predicate":{"id":28,"name":"is"},"target":
{"id":172,"name":"Temperance"}},"173":{"context":{"id":91,"name":"Plato"},"source":
{"id":92,"name":"Virtue"},"predicate":{"id":28,"name":"is"},"target":
{"id":173,"name":"Courage"}}},"194":{"195":{"context":{"id":91,"name":"Plato"},"source":
{"id":194,"name":"Beauty"},"predicate":{"id":28,"name":"is"},"target":
{"id":195,"name":"Objective"}},"196":{"context":{"id":91,"name":"Plato"},"source":
{"id":194,"name":"Beauty"},"predicate":{"id":33,"name":"is associated with"},"target":
{"id":196,"name":"Truth"}}}}}
我找不到节点x,y坐标在输入数据中的图形示例。
答案 0 :(得分:0)
查看https://github.com/samizdatco/arbor/blob/master/src/physics/system.js#L83似乎可以在数据字典中包含x和y值。我不能确定你的例子如何将数据传递给方法。也许只是尝试添加一些节点并查看它们的放置位置。我有同样的问题,能量是NaN。可能使用调试器会有所帮助。