Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Diagrams



A diagram is an instance of the GraphMLDiagram.

A diagram is created through the the GraphmlFactory class. For example:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();
A diagram contains nodes and edges which connect the nodes.

Diagram defaults

Main Article: Diagram defaults

You can set default values for the diagram elements parameters.

In the following example, we will change the default background color for nodes:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();

      DiagramDefaults defaults = diagram.getDefaults();
      defaults.nodeFillColor = "#FFFFFF";

Diagram edge type

The AbstractGraphMLDiagram.setDefaultEdgeType(EdgeType) method allows to set the type of the diagram:
  • By default diagrams are directed, which means that edges are from on node to another node, and the direction of edges is significant
  • it is possible to set the diagram as undirected, which means that the direction of edges is not significant
This property is only useful if you want to apply layouts on the diagram, because some algorithms are eant to work on undirected diagrams.

Note that in our implementation, it is still no possible to set different edge types for different edges in the same diagram.

Opening a diagram

To open a diagram file:
      GraphmlDiagram diagram = factory.openDiagram(file);
or:
      GraphmlDiagram diagram = factory.openDiagram(file, defaults);
Note that you can open a diagrams produced by the yEd tool.

Saving the diagram

To save the diagram as a graphml file:
      factory.saveDiagram(diagram, file);
Note that saved diagrams are compatible with the yEd tool.

Computing the diagram size

Main Article: Group nodes

It is possible to compute the sizes of the nodes in the diagram in the diagram using GraphmlDiagram.computeSize() or GraphmlDiagram.computeSize(float).

The computeSize() uses the groupNodePadding property of the defaults between the children nodes. The computeSize(float) uses a custom groupNodePadding.

Example

Suppose that we want to create a diagram with two nodes and one edge between these nodes. We will use the default properties for the nodes and the edge:
      GraphmlFactory factory = GraphmlFactory.getInstance();
      GraphmlDiagram diagram = factory.newDiagram();

      GraphMLNode node1 = diagram.addNode();
      node1.setX(10);
      node1.setY(10);
      GraphMLNode node2 = diagram.addNode();
      node2.setX(100);
      node2.setY(100);

      GraphMLEdge edge = diagram.addEdge(node1, node2);

See also


Categories: general

Copyright 2021 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence