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

How do I encode information for nodes (and edges) in GraphML?

0 votes
in Help by (3.4k points)

1 Answer

+1 vote
 
Best answer

If you don't need custom properties (as described in the answer to How can I associate additional data with my nodes (and edges)?), but want to encode appropriate information using fill color or multiple labels, you can use the standard yFiles-specific GraphML attributes that specify the visual appearance of graph elements.

For example, the following GraphML excerpt shows the definition for the visual appearance of a node.
In the <y:Fill> element inside the <y:ShapeNode> the color of a node is specified. The label is specified in the <y:NodeLabel> element:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml ... >
  <!--Created by yFiles for Java 2.7-->
  <key for="node" id="d3" yfiles.type="nodegraphics"/>
  <graph edgedefault="directed" id="G">
  ...
  <node id="n1">
    <data key="d3"><!-- a yFiles-specific GraphML attribute -->
      <y:ShapeNode>
        <y:Geometry height="30.0" width="109.0" x="545.0" y="324.0"/>
        <y:Fill color="#FFCC00" transparent="false"/>
        <y:BorderStyle color="#000000" type="line" width="1.0"/>
        <y:NodeLabel alignment="center" autoSizePolicy="content" borde
rDistance="0.0" fontFamily="Dialog"
                     fontSize="13" fontStyle="plain" hasBackgroundColo
r="false" hasLineColor="false"
                     height="19.92626953125" modelName="internal" mode
lPosition="c" textColor="#000000"
                     visible="true" width="43.76171875" x="32.61914062
5" y="5.036865234375">node 2</y:NodeLabel>
        <y:Shape type="rectangle"/>
      </y:ShapeNode>
    </data>
  </node>
  ...

Using another shape type for a node can be achieved by modifying the value of the type attribute in the <y:Shape> element. For example, using <y:Shape type="ellipse"/> or <y:Shape type="roundrectangle"/> instead of the <y:Shape type="rectangle"/>.

Note that you need only specify the essential aspects when setting up your custom information for graph elements. yEd will use reasonable default values for many of the attributes (of <y:NodeLabel>, for example), meaning they can be omitted initially.
In summary, the following is a perfectly valid definition for the visual representation of a node:

<node id="n1">
  <data key="d3">
    <y:ShapeNode>
      <y:Geometry height="30.0" width="109.0"/>
      <y:Fill color="#FFCC00" transparent="false"/>
      <y:NodeLabel>Some additional data.</y:NodeLabel>
      <y:Shape type="rectangle"/>
    </y:ShapeNode>
  </data>
</node>

Note

If you want to create more than one label for a graph element, then be sure to also specify the following attributes of <y:NodeLabel>:

  • modelName (default is ="eight_pos")
  • modelPosition (default is ="c")

Choose a different value than the default for the latter, otherwise your labels will overlap.

<y:NodeLabel>Some additional data.</y:NodeLabel><!-- will be assigned the defau
lt model and position -->
<y:NodeLabel modelName="eight_pos" modelPosition="n">Even more data.</y:NodeLabel>

A list of available values can be found in our GraphML documentation here: http://www.yworks.com/xml/schema/graphml/1.1/doc/index.html

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