-
Notifications
You must be signed in to change notification settings - Fork 55
Graph
Note to non-wiki readers: This documentation is generated from the [email protected] wiki - if you have corrections or additions it would be awesome if you could contribute them to the original wiki page.
The Graph component provides a simple, UI-independent graph model. It consists of the single Graph module. There are also a couple of undeployed Graph Examples.
- feature: org.eclipse.gef.graph
- bundle: org.eclipse.gef.graph
The Graph module of Graph provides the single {Root} package, which delivers a generic graph model representation and related utility classes.
- package: org.eclipse.gef.graph
The {Root} package provides a simple graph model and a support class to copy/merge such models.
A Graph
serves as a container for Node
s and Edge
s. Additionally, a Graph
can be nested inside a nesting Node
, so that sub-graphs can be properly represented.
Moreover, arbitrary attributes can be set on Graph
s, Node
s, and Edge
s, as they all implement org.eclipse.gef.common.attributes.IAttributeStore. As all attributes are maintained in observable collections/properties, listeners can be registered to react to changes. The concrete attributes that are used are outside the scope of the Graph component. The DOT importer of the DOT component, e.g. adds DOT-specific attributes to the Graph it creates, the Zest component uses visualization-specific attributes, which determine the concrete visualization.
A Graph
can be easily constructed using a Graph.Builder
:
Graph graph = new Graph.Builder()
.attr(DotAttributes._TYPE__G, DotAttributes._TYPE__G__DIGRAPH)//
.attr("g_attr", "g1").node("n1")//
.attr(DotAttributes.LABEL__GNE, "1")//
.attr(DotAttributes.ID__GNE, "1")//
.node("n2")//
.attr(DotAttributes.LABEL__GNE, "2")//
.attr(DotAttributes.ID__GNE, "2")//
.node("n3")//
.attr(DotAttributes.LABEL__GNE, "3")//
.attr(DotAttributes.ID__GNE, "3")//
.edge("n1", "n2").attr(DotAttributes.LABEL__GNE, "e1")
.edge("n1", "n3").build();
It allows to chain Node.Builder
s, which can be made identifiable through an arbitrary Object key (here "n1", "n2", "n3"), and Edge.Builder
s, which can refer to identifiable Node.Builder
s to build their source and target elements, so even a complex wired graph can be created through a single builder chain. This is very useful when creating a Graph model that wraps a given semantic model (here a Statechart, which comprises States and Transitions):
Graph.Builder builder = new Graph.Builder().attr(ZestProperties.LAYOUT_ALGORITHM__G, new RadialLayoutAlgorithm());
for (State s : statechart.getStates()) {
// use the State as key for the Node builder
builder.node(s).attr(ZestProperties.LABEL__NE, s.getName());
}
for (Transition t : statechart.getTransitions()) {
// build an Edge for each Transition, referring to the Node builders of its source and target States
builder.edge(t.getSource(), t.getTarget()).attr(ZestProperties.LABEL__NE, "");
}
Graph graph = builder.build()
A GraphCopier
is a utility class to copy/merge graphs. It requires an org.eclipse.gef.common.attributes.IAttributeCopier to copy/transfer the attributes of the Graph
, Node
, and Edge
elements that are copied.