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

Graph Structure Enhancements

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.

Figure 6.2. Hierarchy of graph structure implementations

Hierarchy of graph structure implementations.

Class Graph2D

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.

Note

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 following methods are also explained.

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 following list presents the methods from class Graph2D for view handling. Most prominently, method updateViews() is used to inform all registered views to update themselves, i.e., to repaint the representation of the graph.

Advanced Topics

Copying a Graph2D

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 copies all group node-related hierarchy information of a Graph2D, i.e., which nodes are group nodes and also any parent-child relations.

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. Graph2DCopyFactory simply ignores any hierarchy information of a Graph2D.

Example 6.1. Creating a GraphCopier for a "flat" Graph2D

// 'graph' is of type y.view.Graph2D.

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

As an alternative to Graph2DCopyFactory.HierarchicGraph2DCopyFactory, class Graph2DCopyFactory.RecursiveGraph2DCopyFactory can be used to also recursively copy the contents of all folder nodes of a Graph2D together with their corresponding hierarchy information. Example 6.2, “Setting up recursive graph copy behavior to copy folder node contents also” shows how to set up recursive graph copying behavior.

Example 6.2. Setting up recursive graph copy behavior to copy folder node contents also

// 'graph', 'targetGraph' are of type y.view.Graph2D.

// First, get the graph's original copy factory implementation.
GraphCopier.CopyFactory factory = graph.getCopyFactory();

// The recursive copy factory will use it as a delegate.
Graph2DCopyFactory.RecursiveGraph2DCopyFactory recursiveFactory =
  new Graph2DCopyFactory.RecursiveGraph2DCopyFactory(factory);

// Convenience method to recursively copy the graph to another graph.
recursiveFactory.copyRecursively(graph, targetGraph);