简体   繁体   English

arbor js-保存和加载图

[英]arbor js - save and load graph

I'm using arbor js to create diagrams using its force-based alorithm. 我正在使用arbor js通过基于力的算法创建图表。

I would like to be able to save the x,y system coordinates of the nodes after the total energy has got below a certain point, so that I can load them back in when accessing the graph, to avoid having to re-process all the energy from scratch. 我希望能够在总能量低于某个点之后保存节点的x,y系统坐标,以便在访问图形时可以将其重新加载,从而不必重新处理所有从头开始的能量。

I have had two problems doing this: 我这样做有两个问题:

  1. sys.energy().sum always returns NaN sys.energy().sum始终返回NaN

    • as an alternative I decided to use setTimeout to save the graph node positions after a given period of time has elapsed 作为替代方案,我决定在给定的时间段后使用setTimeout保存图形节点的位置
  2. While I have been able to save the nodes x,y system coordinates to DB, when I try to load the data into the graph (using sys.merge or sys.addNode ) with saved xy coordinates, the graph fails to display, and an 'out of memory' message appears in the console log. 虽然我已经能够将节点x,y系统坐标保存到DB,但是当我尝试使用sys.merge保存的xy坐标将数据加载到图中(使用sys.mergesys.addNode )时,该图无法显示,并且“内存不足”消息出现在控制台日志中。

Here is an example of data with node x,y system coordinates that were saved, and which causes arbor js to crash which loading: 这是一个已保存的带有节点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"}}}}} 

I can find no examples of graphs where the node x,y coordinates are in the input data. 我找不到在输入数据中有节点x,y坐标的图的示例。

Looking at https://github.com/samizdatco/arbor/blob/master/src/physics/system.js#L83 it seems that it should be alright to include x and y value in the data dictionary. 查看https://github.com/samizdatco/arbor/blob/master/src/physics/system.js#L83 ,似乎应该在数据字典中包含x和y值。 I'm not really sure from your example how you pass the data to the methods. 从您的示例中,我不太确定如何将数据传递给方法。 Maybe try just adding a few of the nodes and see where they are placed. 也许尝试仅添加一些节点,然后查看它们的放置位置。 I have the same problem with the energy being NaN. 能量为NaN时,我有同样的问题。 Probably using a debugger will help. 可能使用调试器会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM