KGraph is the central data structure in KIELER for representation of graphs. It was generated using EMF and therefore inherits all capabilities of EMF models such as storage in XML format, transformation, and validation. The KGraph is used for several purposes:
- as intermediate data structure in the KIML project for exchanging layout information between graphical diagrams and graph layout algorithms,
- as a file format for graphs in the KWebS project, and
- as basic structure for the notational model of the KLighD project.
The meta model and generated data structure is contained in the plugin
The Meta Model
Each node in a KGraph may contain other nodes, thus representing a nested sub-graph. The graph itself is represented by a top-level node that has no parent node. Nodes may have incoming and outgoing edges, and each edge has references to its source node and its target node. Usage of ports is optional and can be applied to special cases such as data flow diagrams. If ports are used, they each contain a list of connected edges, and the edges have references to their corresponding source port and target port. Nodes, edges, and ports may have arbitrarily many labels, which are usually (but not necessarily) represented by text.
Each element of the graph may contain arbitrary additional data, which must implement the interface KGraphData. There are two important extending models that use this interface: KLayoutData, which is used to store layout data for the graph, and KRendering, which adds graphical information. Graph data inherits from the plain Java IPropertyHolder interface, which enables it to provide a key-value mapping. Keys are IProperty instances, which have an identifier string and a type, and values are arbitrary objects of the corresponding type. This mapping is transient and is thus not stored in the XML format. The makePersistent() operation can be used to translate the mapping into a serializable list of string pairs.
KGraphs can be easily created and edited using our Textual KGraph (KGT) format.
A larger example that uses the KGraph for automatic layout is found in standalone/LayoutTest/src/test/layout/Test.java.