To enable automatic graph layout, the basic graph structure is enriched with information for two-dimensional placement of its elements. Furthermore, the basis for layout algorithms to access this information is laid, too.
The graph implementation in package y.layout is provided by abstract class LayoutGraph. It enhances the graph structure with support for positional and dimensional information for all graph elements.
In particular, this means width and height for a node and also coordinates for its 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.
Both positional and dimensional information are indispensible for calculating the layout for a graph. Accordingly, these two are also called the "layout information" for a graph and its elements. Figure 5.1, “Graph structure classes” depicts the hierarchy of the yFiles graph structure classes as present in package y.layout.
Abstract class LayoutGraph implements interface GraphLayout, which defines the basis for layout information on graph elements. Class DefaultLayoutGraph, the default implementation for LayoutGraph, presents the main graph class of package y.layout that can be used for all graph layout tasks.
Figure 5.2, “Class hierarchy for class DefaultLayoutGraph” shows the class hierarchy for class DefaultLayoutGraph.
The following method from abstract class LayoutGraph returns graph-level layout information:
Rectangle getBoundingBox() |
|
Description | Getter method for the graph's dimension. |
Interface NodeLayout and its default implementation, class DefaultNodeLayout, are used to add the layout information to a node. This information consists of the coordinates for the upper left corner of the node, and its width and height.
Figure 5.3, “NodeLayout” shows the class hierarchy for interface NodeLayout. Note that abstract class NodeRealizer from package y.view also implements this interface to hold a node's layout information.
The following convenience methods defined by abstract class LayoutGraph can be used to control the layout information for nodes:
YPoint getCenter(Node v) YPoint getLocation(Node v) double getHeight(Node v) double getWidth(Node v) |
|
Description | Getter methods for nodes. |
void setCenter(Node v, YPoint position) void setLocation(Node v, YPoint position) void setSize(Node v, double w, double h) |
|
Description | Setter methods for nodes. |
Interface EdgeLayout and its default implementation, class DefaultEdgeLayout, are used to add the layout information to an edge. This information consists of the coordinates for both starting point and end point of the edge path, as well as the coordinates for the control points in-between these two.
The coordinates for the edge's end points are relative to the center coordinates of the edge's source node and target node, respectively. The coordinates for the control points, in contrast, are absolute.
Figure 5.4, “EdgeLayout” shows the class hierarchy for interface EdgeLayout. Note that abstract class EdgeRealizer from package y.view also implements this interface to hold an edge's layout information.
The following convenience methods defined by abstract class LayoutGraph can be used to control the layout information for edges. Note that the path list for an edge includes its source port, all control points, and also its target port. The point list, though, holds only the edge's control points.
Control points are also known as "bends." This other term is especially used with the visual representation of an edge, i.e., most notably in relation with package y.view.
YList getPathList(Edge edge) YList getPointList(Edge edge) YPoint getSourcePointAbs(Edge edge) YPoint getTargetPointAbs(Edge edge) |
|
Description | Getter methods for edges. |
void setPath(Edge edge, YList path) void setPoints(Edge edge, YList points) void setSourcePointAbs(Edge edge, YPoint point) void setTargetPointAbs(Edge edge, YPoint point) |
|
Description | Setter methods for edges. |
The generic mechanism for copying a graph structure as described in the section called “Copying a Graph” can also be used to copy implementations of abstract class LayoutGraph. Instead of a GraphCopyFactory instance, however, other copy factory implementations, which are capable of copying the information associated with the elements of a LayoutGraph, need to be used. Specifically, this means that node layout and edge layout data as well as node labels and edge labels need to be handled properly by such implementations.
Classes LayoutGraphCopyFactory and LayoutGraphCopyFactory.HierarchicGraphCopyFactory are predefined copy factories that handle both layout data as well as labels. The latter class is returned when calling the getGraphCopyFactory method on a DefaultLayoutGraph, the default LayoutGraph implementation. It is a hierarchy-aware graph copy factory that wraps a LayoutGraphCopyFactory instance and in addition to the services provided by its delegate also automatically copies the contents of all GroupingKeys data providers registered with the LayoutGraph.
Example 5.1, “Creating a GraphCopier for a "flat" LayoutGraph” shows how to create a GraphCopier that uses the graph copy factory for "flat" graphs instead of the default hierarchy-aware one.
All graph layout algorithms in yFiles implement interface Layouter. This interface declares methods for testing if a given input graph of type LayoutGraph can be handled, and also for actually assigning a layout to such a graph.
The calculated new layout information that results from a Layouter invocation supersedes that of the given LayoutGraph object. Figure 5.5, “Layouter dependencies” shows the dependencies for interface Layouter.
Example 5.2, “Invoking a layout algorithm” demonstrates how to invoke a graph layout algorithm on a graph of type DefaultLayoutGraph.
Copyright ©2004-2012, yWorks GmbH. All rights reserved. |