cytoscape.js-graphml
cytoscape.js-graphml copied to clipboard
Loses positions of nodes
For the graph below with the layout option "preset" initial positions of the nodes are lost
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph id="G" edgedefault="undirected">
<node id="n0"/>
<data key="x">122.50374073928583</data>
<data key="y">367.98329788349827</data>
<node id="n1"/>
<data key="x">100</data>
<data key="y">300</data>
<node id="n2"/>
<data key="x">150</data>
<data key="y">300</data>
<node id="n3"/>
<node id="n4"/>
<node id="n5"/>
<node id="n6"/>
<node id="n7"/>
<node id="n8"/>
<node id="n9"/>
<node id="n10"/>
<edge source="n0" target="n2"/>
<edge source="n1" target="n2"/>
<edge source="n2" target="n3"/>
<edge source="n3" target="n5"/>
<edge source="n3" target="n4"/>
<edge source="n4" target="n6"/>
<edge source="n6" target="n5"/>
<edge source="n5" target="n7"/>
<edge source="n6" target="n8"/>
<edge source="n8" target="n7"/>
<edge source="n8" target="n9"/>
<edge source="n8" target="n10"/>
</graph>
</graphml>
AFAIK, graphml format doesn't include a separate structure or keyword for the position information. It is also given as a data element, so extension stores that information in node's data field. Position information can be reached from node's data field after import.
In my opinion, estimating position information from a data element and assigning it directly to the node's position field is not so convenient. Because, user may define position information with different names. (In the above file, it is x and y, but in another file it can be xPos and yPos.)
@hasanbalci Does this extension recognize any of these ways to specify location? Can we perhaps make it recognize some commonly accepted location and dimension specification keywords?
No, it doesn't recognize. But maybe we can specify 'x' and 'y' for the position and 'width' and 'height' for the dimension.
@JustDoIt1999 Could you please work on this and modify this extension to recognize 'x', 'y', 'width', and 'height'?
@ugurdogrusoz of course
A node in my graphml looks like this
<node id="n0">
<data key="d0">
<y:ImageNode>
<y:Geometry height="48.0" width="48.0" x="-24.0" y="694.0"/>
<y:Fill color="#CCCCFF" transparent="false"/>
<y:BorderStyle color="#000000" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" backgroundColor="#FFFFFF" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasLineColor="false" height="18.701171875" modelName="sides" modelPosition="e" textColor="#000000" visible="true" width="39.34375" x="52.0" y="14.6494140625">Server</y:NodeLabel>
<y:Image refid="1"/>
</y:ImageNode>
</data>
<data key="d1"/>
</node>
I am interested in the nodes position x and y. Since position cannot be recognized by the library, Can you guide me how can I access that manually? @PermanAtayev
You can access it as follows:
let obj = {}; obj["position"] = { x: parseInt(ele.data('x')), y: parseInt(ele.data('y')) };
where ele is a node in cytoscape.js
@zeeshanullah
I already tried this but it returns NaN for both values.
$graph.children("node").each(function () {
var $node = $(this);
var settings = {
data: {id: $node.attr("id")},
css: {},
position: { x: parseInt($node.data('x')), y: parseInt($node.data('y')) }
};
@PermanAtayev
This type of graphml is not supported by the extension, please use the format I provided for this issue. @zeeshanullah