Skip to the content.

Group nodes

There are several reasons to group nodes. As network become larger, they get harder to read. Implementation details can clutter the view where an abstract representation would suffice. Providing a grouping operation to the user allows them to create abstractions. This has the additional benefit that the abstraction can potentially be reused by copying the group. Lastly, performance is improved when there are less nodes on the screen.

NodeNetwork has some built-in systems to facilitate node grouping. This article explains how to add basic support for grouping. The CodeGenApp example contains a full implementation of grouping support.

Components

The library uses the following terminology:

Getting started with grouping

To group a set of nodes, create a new NodeGrouper from the NodeNetworkToolkit library. This class has several properties that need to be set before usage.

A simple setup might look like this:

var grouper = new NodeGrouper
{
    GroupNodeFactory = subnet => new NodeViewModel { Name = "Group" },
    EntranceNodeFactory = () => new NodeViewModel { Name = "Entrance" },
    ExitNodeFactory = () => new NodeViewModel { Name = "Exit" },
    SubNetworkFactory = () => new NetworkViewModel(),
    IOBindingFactory = (groupNode, entranceNode, exitNode) =>
        new ValueNodeGroupIOBinding(groupNode, entranceNode, exitNode)
};

The NodeGrouper class provides two methods, MergeIntoGroup(NetworkViewModel network, IEnumerable<NodeViewModel> nodesToGroup) and Ungroup(NodeGroupIOBinding groupInfo), for creating and dissolving groups.

IO Binding

While the NodeGrouper is responsible for moving nodes and connections around to create groups, a NodeGroupIOBinding handles the logic behind the inlets and outlets of the group. A default implementation called ValueNodeGroupIOBinding is available for applications that use the value nodes explained in this chapter. It is likely you will want to subclass this type and override some of its methods.

The IOBinding is responsible for several operations:

More details can be found in the implementation mentioned above.

Extras

The library provides two optional components to navigate and edit groups.

More information on these components can be found in the CodeGenApp example.