Where to Find Up-to-date yFiles Information

This page is from the outdated yFiles for Java 2.13 documentation. You can find the most up-to-date documentation for all yFiles products on the yFiles documentation overview page.

Please see the following links for more information about the yFiles product family of diagramming programming libraries and corresponding yFiles products for modern web apps, for cross-platform Java(FX) applications, and for applications for the Microsoft .NET environment.

More about the yFiles product family Close X

Layout Architecture

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.

Graph Structure Enhancements

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.

Figure 5.1. Graph structure classes

Graph structure classes.

Positional and Dimensional Information

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.

Figure 5.2. Class hierarchy for class DefaultLayoutGraph

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.

Figure 5.3. NodeLayout

NodeLayout.

The following convenience methods defined by abstract class LayoutGraph can be used to control the layout information 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.

Important

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.

Figure 5.4. EdgeLayout

EdgeLayout.

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.

Note

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.

Advanced Topics

Copying a LayoutGraph

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.

Example 5.1. Creating a GraphCopier for a "flat" LayoutGraph

// 'graph' is of type y.layout.DefaultLayoutGraph.

// Create a new GraphCopier that uses a graph copy factory for "flat" graphs.
GraphCopier gc = new GraphCopier(new LayoutGraphCopyFactory());

Layout Infrastructure

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.

Figure 5.5. Layouter dependencies

Layouter dependencies.

Example 5.2, “Invoking a layout algorithm” demonstrates how to invoke a graph layout algorithm on a graph of type DefaultLayoutGraph.

Example 5.2. Invoking a layout algorithm

// 'graph' is of type y.layout.DefaultLayoutGraph. 

// Run a hierarchical layout on the given graph. 
Layouter ihl = new IncrementalHierarchicLayouter();
ihl.doLayout(graph);