View Implementations

The default view for presenting graphs, class GraphCanvasComponent, is hierarchy-aware by default. All application-level features described in the section called “Class GraphCanvasComponent”, like, e.g., clipboard functionality or Undo/Redo are available for hierarchically organized graphs out-of-the-box.

Class HierarchyTreeView

HierarchyTreeView helps in presenting the tree-like hierarchy modeled by an INodeHierarchy implementation in a mx.controls.Tree.

Example 3.8, “Setting up a HierarchyTreeView” presents the setup of a HierarchyTreeView for displaying the hierarchical organization of a grouped graph.

Example 3.8. Setting up a HierarchyTreeView

// 'graph' is of type com.yworks.graph.model.IGraph.

// Retrieve the hierarchy of nodes.
var hierarchy:INodeHierarchy = graph.lookup(INodeHierarchy) as INodeHierarchy;

// Display the hierarchy in a Tree control.
if (hierarchy != null) {
  // 'treeView' is a mx.controls.Tree.
  new HierarchyTreeView(treeView, hierarchy);
}

Alternatively, the HierarchyTreeView can be set directly as data provider for a Tree control. Example 3.9, “Setting up a HierarchyTreeView in MXML” demonstrates the use of a HierarchyTreeView in MXML syntax.

Example 3.9. Setting up a HierarchyTreeView in MXML

<!-- 'graphCanvas' is the GraphCanvasComponent which displays the graph. -->
<mx:Tree>
  <mx:dataProvider>
    <yworks:HierarchyTreeView id="htv" graphCanvasComponent="{graphCanvas}"/>
  </mx:dataProvider>
</mx:Tree>

HierarchyTreeView adds the nodes of the hierarchy to the Tree and uses the first node label as the descriptive text to be displayed. Figure 3.11, “Graph view provided by HierarchyTreeView” shows a Tree placed on the left side inside an application's window that displays the hierarchical organization of a grouped graph.

Figure 3.11. Graph view provided by HierarchyTreeView

Graph view provided by HierarchyTreeView.

In tutorial demo application GroupingDemo further aspects of presenting a graph in a Tree can be observed.