Comparison between y.base.Graph and yWorks.yFiles.UI.Model.IGraph

Questions & Answers

Summary

This article explains the differences between y.base.Graph and yWorks.yFiles.UI.Model.IGraph (and derived classes) in yFiles.NET/yFiles WPF and above.

This article was written for an older version. It is only online as a reference for customers using this old version. The information it contains is probably out of date.

The latest information can be found in the yFiles documentation

Description

yFiles.NET 3.0 and yFiles WPF 1.0 and higher provide also graph viewing and editing capabilities in addition to the layout and analysis functionality already present. To accomodate for the new capabilities, a new graph model has been introduced. The graph implementations in the yFiles.NET viewer part implement yWorks.yFiles.UI.Model.IGraph instead of extending y.base.Graph. In constrast, the layout and analysis algorithms still use the old class hierarchy that descends from y.base.Graph.

Which graph implementation should I use?

  • To use the layout and analysis algorithms present in the y.algo and y.layout.* namespaces, use classes derived from y.base.Graph, such as y.layout.LayoutGraph.
  • To use the viewer functionality present in all yFile.* namespaces, use classes implementing yWorks.yFiles.UI.Model.IGraph, such as yWorks.yFiles.UI.Model.DefaultGraph.
  • When you need both viewer and layout/analysis functionality, it is usually better to use yWorks.yFiles.UI.Model.DefaultGraph as your main graph model, since there exist adapter classes to the y.base.Graph class hierarchy, but not the other way round.

How do I use layout algorithms together with the yFiles.NET viewer graph model?

To use the automatic layout algorithms present in y.layout.*, you can use adapter class yWorks.yFiles.UI.Model.CopiedLayoutIGraph:

//your layouter:
Layouter layouter = ...

//your viewer graph instance
IGraph myGraph;

//use adapter to calculate and apply layout
CopiedLayoutIGraph copy = new CopiedLayoutIGraph(myGraph);
layouter.doLayout(copy);
copy.commitLayoutToOriginalGraph();

To use layout morphing, use class yWorks.yFiles.UI.Animation.LayoutMorpherWrapper:

//your layouter:
Layouter layouter = ...

//your viewer graph instance
IGraph myGraph = graphControl.Graph;

//use adapter to calculate and apply layout
CopiedLayoutIGraph copy = new CopiedLayoutIGraph(myGraph);
layouter.doLayout(copy);
LayoutMorpherWrapper wrapper = new LayoutMorpherWrapper(myGraph, copy, 500);
 wrapper.Run(graphControl);

How do I use analysis algorithms together with the yFiles.NET/yFiles WPF viewer graph model?

Basically, class yWorks.yFiles.UI.Model.CopiedLayoutIGraph can also serve as input for the analysis algorithms in y.algo that require a y.base.Graph instance. However, since most algorithms store their result either as y.base.Node/EdgeLists, or in y.base.Node/EdgeMap instances, you need to do some backward mapping, such as shown in the following snippet that creates a IEnumerable<INode> from a y.base.NodeList:

public IEnumerable<INode> CreateNodeList(CopiedLayoutIGraph g, NodeList nl) {
      IList<INode> retval = new List<INode>(nl.size());
      for (NodeCursor nc = nl.nodes(); nc.ok(); nc.next()) {
        retval.Add((INode)g.getOriginalNode(nc.node()));
      }
      return retval;
 }

Similar code can be used to transfer values from a NodeMap to an IMapper instance etc.

Categories this article belongs to:
yFiles.NET > yFiles.NET Viewer > Using yFiles Layout Functionality From yFiles.NET Viewer
yFiles WPF > yFiles WPF Viewer > Using yFiles Layout Functionality From yFiles WPF Viewer
Applies to:
yFiles.NET: 3.0, 3.1
yFiles WPF: 1.0
Keywords:
yFiles.NET - analysis - layout - adapter - CopiedLayoutIGraph - yFiles WPF - WPF