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

Generated graphml with labels and layout

+2 votes
Hi,

I'm auto generating a graphml file to represent a workflow task in order to get a diagram of the flow. Each stage of the task is numbered, i'm using this number a sthe node ID. Each possible next stage in the task is represented as an edge.

See below for an partial example of the generated file.

Is there an XML attribute or different syntax I can generate to populate the node text?

Also, it would be nice to be able to control the edge text and node style, and be super nice if I could get it to auto layout too.

The desired end result is an auto generated graphml file which when openned by the user displays a layed out graph with node and edge text.

Unfortunately the graphml primer does not go into enough detail for me to be able to achieve this.

Also, i've noticed that if I save the graphml in yEd, all of my node and edge IDs are replaced with auto generated ones such as n01 e01 etc, is there any way to retain the original IDs?

Partial sample of currently generated graphml

<node id="95"/>
<edge source="120" target="130"/>
<edge source="120" target="500"/>
<node id="120"/>
<edge source="130" target="135"/>
<edge source="130" target="27"/>
<node id="130"/>
<edge source="135" target="27"/>
<edge source="135" target="500"/>
<node id="135"/>
in Help by

1 Answer

+1 vote

Yes, it is possible to specify label texts, style, and position for nodes. I suggest to create a simple graph with a single node in yEd and then write that graph to GraphML.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml
 xmlns="http://graphml.graphdrawing.org/xmlns"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:y="http://www.yworks.com/xml/graphml"
 xmlns:yed="http://www.yworks.com/xml/yed/3"
 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
  <key for="node" id="d1" yfiles.type="nodegraphics"/>
  <graph edgedefault="directed" id="G">
    <node id="n0">
      <data key="d1">
        <y:ShapeNode>
          <y:Shape type="rectangle"/>                              <!-- node shape -->
          <y:Geometry height="30.0" width="30.0" x="0.0" y="0.0"/> <!-- position and size -->
          <y:Fill color="#FFCC00" transparent="false"/>            <!-- fill color -->
          <y:BorderStyle color="#000000" type="line" width="1.0"/> <!-- border -->
          <y:NodeLabel>Label Text</y:NodeLabel>                    <!-- label text -->
        </y:ShapeNode>
      </data>
    </node>
  </graph>
</graphml>

 

As for the IDs, it is not possible to prevent yEd from changing IDs when writing to GraphML. GraphML IDs are not meant to be used for anything but reading/writing GraphML. If you need IDs for external processing, add a custom ID property to your nodes and edges.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml
 xmlns="http://graphml.graphdrawing.org/xmlns"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:y="http://www.yworks.com/xml/graphml"
 xmlns:yed="http://www.yworks.com/xml/yed/3"
 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
  <key attr.name="ID" attr.type="int" for="node" id="d3">
    <default>-1</default>
  </key>
  <graph edgedefault="directed" id="G">
    <node id="n0">
      <data key="d3">0</data> <!-- ID -->
    </node>
  </graph>
</graphml>

 

Of course, the easiest way to generate compatible GraphML for an already laid out graph would be using yFiles for Java.

by [yWorks] (161k points)
edited by
Legal Disclosure | Privacy Policy
...