documentationfor yFiles for HTML 3.0.0.1

Grouping in the LayoutGraph

The changes described in this chapter only affect users who work directly with the LayoutGraph API, such as when writing custom layout algorithms.

The grouping on the LayoutGraph is no longer defined by using data keys (GroupingKeys class in yFiles for HTML 2.6). Grouping information is now directly accessible by using methods on the graph instance itself:

Basic changes to the grouping can also be implemented using the graph and the following methods:

LayoutGraphGrouping

The LayoutGraphGrouping class replaces the (Layout)GroupingSupport class from yFiles for HTML 2.6 and offers more advanced grouping operations. You can create it using different factory methods, depending on whether you need a read-only or a writable instance. Additionally, it provides convenient methods such as checking if a graph is grouped at all (isGrouped).

When you need to query a lot of grouping information in performance-critical code, this approach is more efficient than accessing it through the graph instance.

In previous yFiles versions, you had to manually modify the data registered with the keys of GroupingKeys. Now, LayoutGraphGrouping offers methods to replace or hide the grouping structure. These operations can (and usually should) be undone later.

Replacing the current grouping
// given three nodes n1, n2, n3; n1 should be a group node that contains n2 and n3
// with this code we completely replace any previously defined grouping and define new relations
const grouping = LayoutGraphGrouping.replaceGrouping(graph)
grouping.setIsGroupNode(n1, true)
grouping.setParent(n2, n1)
grouping.setParent(n3, n1)

// ... other code

// finally, the replacement can be undone again
grouping.restore()

Removing the current grouping
// hide the grouping so that the graph appears to contain no grouping at all
const hiddenGrouping = LayoutGraphGrouping.hideGrouping(graph)

// ... other code

// now, make it visible again
hiddenGrouping.restore()