/// <summary> /// Returns the <see cref="SwimlaneDescriptor.ComputedLaneIndex"/> for <paramref name="node"/>. /// </summary> private static int GetLaneId(Node node, ILayoutDataProvider ldp) { var nodeData = ldp.GetNodeData(node); SwimlaneDescriptor laneDesc = nodeData != null ? nodeData.SwimLaneDescriptor : null; return(laneDesc != null ? laneDesc.ComputedLaneIndex : -1); }
public static void Main() { DefaultLayoutGraph graph = new DefaultLayoutGraph(); //construct graph. assign sizes to nodes Node v1 = graph.CreateNode(); graph.SetSize(v1, 30, 30); Node v2 = graph.CreateNode(); graph.SetSize(v2, 30, 30); Node v3 = graph.CreateNode(); graph.SetSize(v3, 30, 30); Node v4 = graph.CreateNode(); graph.SetSize(v4, 30, 30); // create some edges... Edge e1 = graph.CreateEdge(v1, v2); Edge e2 = graph.CreateEdge(v1, v3); Edge e3 = graph.CreateEdge(v2, v4); // create swim lane descriptors for two lanes var sl1 = new SwimlaneDescriptor(1); var sl2 = new SwimlaneDescriptor(2); // create a map to store the swim lane descriptors INodeMap slMap = graph.CreateNodeMap(); // assign nodes to lanes slMap.Set(v1, sl1); slMap.Set(v2, sl2); slMap.Set(v3, sl2); slMap.Set(v4, sl1); // register the information graph.AddDataProvider(HierarchicLayout.SwimlaneDescriptorDpKey, slMap); // create the layout algorithm HierarchicLayout layout = new HierarchicLayout(); // start the layout new BufferedLayout(layout).ApplyLayout(graph); Console.WriteLine("\n\nGRAPH LAID OUT HIERARCHICALLY IN SWIMLANES"); Console.WriteLine("v1 center position = " + graph.GetCenter(v1)); Console.WriteLine("v2 center position = " + graph.GetCenter(v2)); Console.WriteLine("v3 center position = " + graph.GetCenter(v3)); Console.WriteLine("v4 center position = " + graph.GetCenter(v4)); Console.WriteLine("e1 path = " + graph.GetPath(e1)); Console.WriteLine("e2 path = " + graph.GetPath(e2)); Console.WriteLine("e3 path = " + graph.GetPath(e3)); Console.WriteLine("SwimLane 1 index = " + sl1.ComputedLaneIndex); Console.WriteLine("SwimLane 1 position = " + sl1.ComputedLanePosition); Console.WriteLine("SwimLane 1 width = " + sl1.ComputedLaneWidth); Console.WriteLine("SwimLane 2 index = " + sl2.ComputedLaneIndex); Console.WriteLine("SwimLane 2 position = " + sl2.ComputedLanePosition); Console.WriteLine("SwimLane 2 width = " + sl2.ComputedLaneWidth); //clean up data maps graph.DisposeNodeMap(slMap); graph.RemoveDataProvider(HierarchicLayout.SwimlaneDescriptorDpKey); //display the graph in a simple viewer var viewer = new GraphViewer(); viewer.AddLayoutGraph(graph, "Swimlane Demo"); var application = new System.Windows.Application(); application.Run(viewer); }