The layout data structure was generated with EMF and is used in KIML to attach layout options as well as layout information to each element of a KGraph structure. Layout options specify the behavior of layout algorithms for the specific graph instance, and layout information is written by layout algorithms to describe the position and size of each graph element. Many commonly used layout options are defined in the class LayoutOptions, while each layout algorithm may additionally define its own specific options.
The KShapeLayout information is used for nodes, labels, and ports. It stores the position coordinates of the top left corner of the corresponding graph element as well as the size of its bounding box. Nodes may contain nested sub-graphs represented by their children reference; these child nodes are drawn inside the parent's bounding box respecting a certain border given by the KInsets object. The KEdgeLayout information is used for edges. It stores the position coordinates of the points where an edge touches its source node and its target node as well as the bend points.
The meta model and generated data structure is contained in the plugin
Graph elements have the following reference points for their position:
- Nodes: the parent node position plus its top / left insets (the child area)
- Node labels: the position of the containing node
- Ports: the position of the containing node
- Port labels: the position of the containing port
- Edge bend points and source / target points: the source node child area if the target node is directly or indirectly contained by the source node, the source node's parent child area otherwise
- Edge labels: same as bend points
Consider the following example, where graph element positions are visualized as red dotted vectors pointing to the corresponding reference points. See also the SVG version.
A larger example that uses the KGraph with layout data for automatic layout is found in standalone/LayoutTest/src/test/layout/Test.java.