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

Local Views

Concept

Local views provide an interactive means to concentrate on "parts of interest" in a diagram. The basic idea is to prepare only a small part of an entire diagram which is directly related to some node or edge of particular interest.

This feature is particularly useful when displaying large and complex graphs. It is possible to "focus" on a node or edge, e.g. by selection. The local view then displays the source and target node of an edge or the neighbors of a node, even if they are out of the display area of the entire graph.

Local views can be considered as multiple views of a common model graph with predefined filters for the most common usecases.

A local view can comprise the following filtered information, for example:

  • all neighbors of a given node (set), i.e., all predecessors and/or all successors up to a specifiable level
  • the ancestor hierarchy/hierarchies of a given node (set)
  • all siblings of a given node set contained in group nodes
  • the end nodes of a given edge set
  • edge grouping structures that a given edge is part of, consisting of all nodes and edges

Figure 6.65. A model graph and its local view

The entire (model) graph.
A local view: predecessors of the node in focus.
The model: the entire graph. Local view: predecessors of "List".

Class LocalViewCreator

Class LocalViewCreator is an abstract class whose implementations create a local view (Graph2D) from a given model graph (Graph2D). Its central method is updateViewGraph() which populates the local view graph, applies an automatic layout and updates the Graph2DView instances which display the local view.

The layouter which will be invoked upon updateViewGraph() can be set using setLayouter(). By default an IncrementalHierarchicLayouter is used.

Creator Implementations

The yFiles API offers a number of predefined implementations for the most common use cases.

Node based view creator implementations:

LocalViewCreator.Neighborhood
Description Creates a local view including all nodes which can be reached within a given distance from the node in focus. Optionally, real end nodes of inter-edges can be shown.
LocalViewCreator.CommonParentGroup
Description Creates a local view including all nodes within the same group. The container can be included in the view.
LocalViewCreator.AncestorGroups
Description Shows the ancestors of the focused node in the hierarchy, i.e. its containing group node and the group node's ancestors.
LocalViewCreator.FolderContents
Description Shows the contents of the focused folder node.

Edge based view creator implementations:

LocalViewCreator.SourceAndTarget
Description Shows the source and target nodes of the focused edge. Optionally, real end nodes of an inter-edge can be shown.
LocalViewCreator.EdgeGroup
Description Shows the source and target nodes of all edges of a given group. An edge group can be defined as all edges with a common source and/or target or by edge groups as defined in the section called “Edge/Port Grouping (Bus-Style Edge Routing)”.

Abstract implementation:

LocalViewCreator.AbstractLocalViewCreator
Description Abstract view creator which offers convenience methods to create local views based on focused graph elements. All other predefined implementations inherit from this class.

Managing Local Views

Class LocalViewCreator offers getters for the model graph as well as for the local view graph. It is up to the implementation to set the graph instances. The above listed predefined implementations set the model graph in the constructor and create the local view themselves. The local view graph then has to be set to the Graph2DView instance which should display the local view as shown in Example 6.48, “Setting up a local view”.

Example 6.48. Setting up a local view

// 'localView' is of type y.view.Graph2DView.
// 'modelGraph' is of type y.view.Graph2D.

AbstractLocalViewCreator creator = new LocalViewCreator.Neighborhood(modelGraph);
localView.setGraph2D(creator.getViewGraph());

AbstractLocalViewCreator and the predefined implementations offer convenience methods to create local views based on one or more graph elements which are focused. After setting the focused element the new view is created by invocation of the method updateViewGraph() as shown in Example 6.49, “Creating a local view”.

Example 6.49. Creating a local view

// 'creator' is of type y.view.LocalViewCreator.AbstractLocalViewCreator.
// 'focusNode' is of type y.base.Node.

creator.clearFocusNodes();
creator.addFocusNode(focusNode);
creator.updateViewGraph();

In addition to creating a new local view programmatically, AbstractLocalViewCreator offers the possibility to let the creation be triggered by hovering over a graph item or by selecting a graph item. A selection trigger can be (de)activated automatically by using the add or remove methods. A hover trigger has to be created by the method createHoverTrigger() and added as view mode to the Graph2DView instance which display the local view.

void addSelectionTrigger()
void removeSelectionTrigger()
ViewMode createHoverTrigger()
Description Managing automatic triggers for hovering/selection.

Mapping Graph Elements between Local View and Model

Technically, the local view graph is not a subset but a copy of the model graph. Thus, the node or edge instance of the local view is different from the instance of the corresponding model. LocalViewCreator therefore offers methods to get the model item for a given view item and vice versa.

Tutorial Demo Code

The tutorial demo application LocalViewDemo.java gives a detailed demonstration on how to use and set up the different predefined LocalViewCreator implementations. It also shows how to create a custom LocalViewCreator implementation based on the class AbstractLocalViewCreator.