Table of Contents
This chapter presents the layout graph structure, i.e., the underlying graph model that the layout algorithms are tailored to. This graph structure implementation is an enhancement of the basic algorithms graph structure, and is also referred to as the "LayoutGraph API" in Chapter 5, Automatic Graph Layout.
This chapter can be easily skipped when using the IGraph API, the graph structure implementation of yFiles FLEX. See also the section called “Using yFiles Layout Functionality” and Chapter 3, Using yFiles FLEX Client Layout Extension Functionality.
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 com.yworks.yfiles.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 8.1, “Graph structure classes” depicts the hierarchy of the yFiles graph structure classes as present in package com.yworks.yfiles.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 com.yworks.yfiles.layout that can be used for all graph layout tasks.
Figure 8.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:
getBoundingBox():Rectangle |
|
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 8.3, “NodeLayout” shows the class hierarchy for interface NodeLayout.
The following convenience methods defined by abstract class LayoutGraph can be used to control the layout information for nodes:
getCenter(v:Node):YPoint getLocation(v:Node):YPoint getHeight(v:Node):Number getWidth(v:Node):Number |
|
Description | Getter methods for nodes. |
setCenter2(v:Node, position:YPoint):void setLocationToPoint(v:Node, position:YPoint):void setSize(v:Node, w:Number, h:Number):void |
|
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. Figure 8.4, “EdgeLayout” shows the class hierarchy for interface EdgeLayout.
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.
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."
getPathList(edge:Edge):YList getPointList(edge:Edge):YList getSourcePointAbs(edge:Edge):YPoint getTargetPointAbs(edge:Edge):YPoint |
|
Description | Getter methods for edges. |
setPath(edge:Edge, path:YList):void setPointsFromList(edge:Edge, points:YList):void setSourcePointAbs(edge:Edge, point:YPoint):void setTargetPointAbs(edge:Edge, point:YPoint):void |
|
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 8.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.
Copyright ©2010-2015, yWorks GmbH. All rights reserved. |