Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

Importing Networkx write_graphml file does not import any node/edge attribute data

+1 vote

I have created a basic networkx graph using the following code in python-

```
from networkx import les_miserables_graph

g = les_miserables_graph()

nx.write_graphml(g, 'demo.graphml')

```

When I import this graphml file into yed live. I can only see the structure of the graph (using different layouts).
I am not able to check the node name, it's attributes and also edge attributes if any.

I have also attached the graphml file down below. Let me know what am I doing wrong in this scenario.

demo.graphml

in Help by

1 Answer

0 votes

The GraphML standard specifies how to encode structural information and how to associate additional data to graph elements in general. Applications and toolkits are free to choose how they store data like node names and the like.

networkx seems to have chosen the least portable way to store node names by misusing the GraphML-internal IDs for nodes. As a result, neither yEd Live nor yEd will be able to extract the networkx node names from your GraphML files.

Indeed, yEd Live does not use the concept of node names at all, but allows for arbitrarily many node labels:

<graphml ...>
  ...
  <key id="d4" for="node" attr.name="NodeLabels" y:attr.uri="http://www.yworks.com/xml/yfiles-common/2.0/NodeLabels"/>
  ...
  <graph ...>
    <node ...>
      <data key="d4">
        <x:List>
          <y:Label>
            <y:Label.Text><![CDATA[Node name]]></y:Label.Text>
          </y:Label>
          ...
        </x:List>
    </node>
  </graph>
</graphml>

Moreover, yEd Live does not read generic data like additional attributes from GraphML. (However, yEd is able to do that.)

In short, your only option to import node names into yEd Live is by generating a GraphML file that stores said data in a way that yEd Live supports.
Your best option to learn "what yEd Live supports" is by creating sample diagrams in yEd Live, saving these diagrams to a local GraphML file, and inspecting those files in a text editor.

If you want to import several types of data, you will need to use yEd instead of yEd Live. (Again, you would have to create sample diagrams with user-defined properties in yEd and save these diagrams to GraphML to learn how to store additional data in GraphML for yEd to be able to read that additional data.)

by [yWorks] (160k points)
Alright thanks for the clarification.

Currently I'm using the GraphWidget from yfiles_jupyter_graphs library and rendering the graph in the jupyter widget itself and then loading the data from there into yworks Data Explorer. Just to make sure, I wanted to ask is this the only way to get data into yworks data explorer with all attributes from networkx graph in python?
Let me know about it. Also additionally how can i color different nodes based on node type attribute? Is it something that can be handled within networkx or yworks and which one would be most optimal.
Using the yfiles_jupyter_graphs widget is actually a good entry point to the yFiles apps here.

For example, see the NetworkX graph-import example notebook https://colab.research.google.com/github/yWorks/yfiles-jupyter-graphs/blob/main/examples/13_networkx_import.ipynb

The widget makes NetworkX attributes in the node's/edge's properties available. These properties may then be used in the different yfiles_jupyter_graphs mapping functions, e.g.

* node_label_mapping
* node_color_mapping
* edge_label_mapping
* edge_color_mapping (note how the above-mentioned sample notebook shows this is the very last embedding)
* etc. (see the documentation https://yworks.github.io/yfiles-jupyter-graphs/02_graph_widget/#methods or the extensive examples https://github.com/yWorks/yfiles-jupyter-graphs/tree/main/examples).

Once the properties are mapped in the widget's graph, you can either use the "Export to yEd Live" or "Export to Data Explorer" feature. The graph will then be sent to these applications just like it is configured in the widget.
Technically, the other NetworkX attributes are also available in the sent data, because all properties are stored in the GraphML file that is generated by the "Export to <app>" feature.

You could also export it to yEd Live and use it to download a GraphML file (Menu -> Save -> Download) that is compatible with yEd Live / yEd / Data Explorer, although the properties won't be available in yEd Live and yEd (only the Data Explorer allows some access to it afterward). Therefore, you should map them already within the yfiles_jupyter_graphs_widget to your liking.

Of course, you could also use different approaches to create a compatible file (e.g. nx.write_graphml) but you need to modify the file programmatically to make specific attributes appear in the other yFiles apps, otherwise, only the structure is read (as Thomas explained).

Tl;dr: So my recommendation is to use the yfiles_jupyter_graphs widget as a starting point, apply the data mappings as you see fit, then export it to yEd Live (or Data Explorer) from within the jupyter widget, and go from there.
Thanks.

One final issue that I am facing is that on EC2 instance I'm getting this error while showing the GraphWidget-

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'GraphModel' from module 'yfiles-jupyter-graphs'
Error: Load timeout for modules: nbextensions/yfiles-jupyter-graphs/index
http://requirejs.org/docs/errors.html#timeout
    at makeError (http://localhost:8891/static/components/requirejs/require.js?v=951f856e81496aaeec2e71a1c2c0d51f:168:17)
    at checkLoaded (http://localhost:8891/static/components/requirejs/require.js?v=951f856e81496aaeec2e71a1c2c0d51f:696:23)
    at http://localhost:8891/static/components/requirejs/require.js?v=951f856e81496aaeec2e71a1c2c0d51f:717:25

the same error is not appearing on my local jupyter instance. What could be possible issues and how could I resolve it?
Looks like the package is not installed, or not yet available in the kernel. Please try to restart the kernel.

If you keep having trouble with it (or questions/feedback etc.), please open an issue on GitHub (https://github.com/yWorks/yfiles-jupyter-graphs/) because this forum is the wrong place to discuss issues with the jupyter widget.
Legal Disclosure | Privacy Policy
...