Show last authors
1 (% class="wikipage searchable" %)
2 (((
3 (((
4 See also [[KLayoutData>>doc:KLayoutData Meta Model]] and [[KRendering>>doc:The KRendering Notation Model]].
5
6 [[image:attach:kgraph.png]]
7
8 KGraph is the central data structure in KIELER for representation of graphs. It was generated using [[EMF>>url:http://www.eclipse.org/modeling/emf/||style="text-decoration: none;" shape="rect" class="ext-link"]] and therefore inherits all capabilites of EMF models such as storage in XML format, transformation, and validation. The KGraph is used for several purposes:
9
10 * as intermediate data structure in the [[KIML>>doc:Infrastructure for Meta Layout (KIML)]] project for exchanging layout information between graphical diagrams and graph layout algorithms,
11 * as a file format for graphs in the [[KWebS>>doc:Web Services (KWebS)]] project, and
12 * as basic structure for the notational model of the [[KLighD>>doc:Lightweight Diagrams (KLighD)]] project.
13
14 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.
15
16 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>>doc:KLayoutData Meta Model]], which is used to store layout data for the graph, and [[KRendering>>doc:The KRendering Notation Model]], 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.
17
18 == API Example ==
19
20 {{code theme="Eclipse" language="java"}}
21  
22 KGraphFactory factory = KGraphFactory.eINSTANCE;
23 KNode myGraph = factory.createKNode();
24
25 // Setting the parent reference automatically adds a node to
26 // the parent's list of children.
27 KNode node1 = factory.createKNode();
28 node1.setParent(myGraph);
29 KNode node2 = factory.createKNode();
30 node2.setParent(myGraph);
31
32 // Setting the source and target references automatically adds
33 // an edge to the corresponding incoming and outgoing edges lists.
34 // In the XML structure edges are contained by their source node.
35 KEdge edge = factory.createKEdge();
36 edge.setSource(node1);
37 edge.setTarget(node2);
38
39 // Setting the parent reference automatically adds a label to
40 // the parent's list of labels.
41 KLabel label = factory.createKLabel();
42 label.setText("Hello, World!");
43 label.setParent(edge);
44
45 // Setting the node reference automatically adds a port to the
46 // node's list of ports.
47 KPort port1 = factory.createKPort();
48 port1.setNode(node1);
49 KPort port2 = factory.createKPort();
50 port2.setNode(node2);
51
52 // The 'edges' and 'sourcePort' / 'targetPort' references are not
53 // opposite, so they all have to be set explicitly.
54 edge.setSourcePort(port1);
55 port1.getEdges().add(edge);
56 edge.setTargetPort(port2);
57 port2.getEdges().add(edge);
58 {{/code}}
59
60 A larger example that uses the KGraph for automatic layout is found in [[standalone/LayoutTest/src/test/layout/Test.java>>url:http://rtsys.informatik.uni-kiel.de/fisheye/browse/kieler/standalone/LayoutTest/src/test/layout/Test.java||shape="rect"]].
61 )))
62 )))