The graph implementation in package
y.view
is provided
by class Graph2D.
It enhances the graph structure with support for the visual presentation of
graph elements inside graphical user interface (GUI) components.
Indispensible basis for nearly all visualization aspects is positional and
dimensional information which is added by the graph structure implementation
in package
y.layout
.
Abstract class LayoutGraph
provides
positional and dimensional information for all graph elements.
In particular, this means width and height for a node and also coordinates for
its center and upper left corner.
For edges, more precisely edge paths, positional information means coordinates
for both starting point and end point, as well as the control points in-between
these two.
Figure 6.2, “Hierarchy of graph structure implementations” depicts the hierarchy of the yFiles graph
structure classes.
Class Graph2D
is one of the main
contributors to the model part of the MVC pattern present in package y.view.
It offers a variety of methods to conveniently modify the state of single graph
elements or arbitrary collections thereof.
The other major contributors to the model part besides Graph2D, classes
NodeRealizer
and
EdgeRealizer
hold and manage all
necessary graph element state information, and are therefore mandatory to
guarantee the proper working of the user experience/the visual aspects of the
graph structure.
By means of Graph2D's "default realizer" mechanism, any created graph element is automatically bound to a fresh instance of its respective realizer type. The actual default node realizer and edge realizer classes that are used for this mechanism can be set in advance. Alternatively, realizers can also be associated explicitly with single graph elements, thus resetting the automatic binding.
Initially, classes ShapeNodeRealizer
and
PolyLineEdgeRealizer
are used as the default
node respectively edge realizers for the "default realizer" mechanism of class
Graph2D.
Node realizers and edge realizers are described in all detail in the section called “Bringing Graph Elements to Life: The Realizer Concept”. There, both alternatives for associating realizers to graph elements are described, and the methods listed in API Excerpt 6.1, “Realizer-related methods from class Graph2D” are also explained.
API Excerpt 6.1. Realizer-related methods from class Graph2D
// Getter and setter methods for the default realizer mechanism. EdgeRealizer getDefaultEdgeRealizer() NodeRealizer getDefaultNodeRealizer() void setDefaultEdgeRealizer(EdgeRealizer er) void setDefaultNodeRealizer(NodeRealizer nr) // Getter and setter methods for explicit realizers. EdgeRealizer getRealizer(Edge e) NodeRealizer getRealizer(Node v) void setRealizer(Edge e, EdgeRealizer er) void setRealizer(Node v, NodeRealizer nr)
To link the view part and the model, Graph2D naturally provides methods to
register view objects with it, and to manage all registered views.
The methods for view handling are presented in
API Excerpt 6.2, “View-related methods from class Graph2D”.
Most prominently, method
updateViews()
is used to inform
all registered views to update themselves, i.e., to repaint the representation
of the graph.
The generic mechanism for copying a graph structure as described in the section called “Copying a Graph” can also be used to copy Graph2D objects. Instead of a GraphCopyFactory instance, however, other copy factory implementations, which are capable of copying the node realizers and edge realizers associated with a Graph2D, need to be used.
Classes Graph2DCopyFactory
and
Graph2DCopyFactory.HierarchicGraph2DCopyFactory
are predefined copy factories that handle realizers.
The latter class is returned when calling the getGraphCopyFactory
method on a Graph2D.
It is a hierarchy-aware graph copy factory that wraps a Graph2DCopyFactory
instance and in addition to the services provided by its delegate also
automatically copies all hierarchy information.
Example 6.1, “Creating a GraphCopier for a "flat" Graph2D” shows how to create a GraphCopier that uses the graph copy factory for "flat" graphs instead of the default hierarchy-aware one.
|
Copyright ©2004-2008, yWorks GmbH. All rights reserved. |