Ejemplo n.º 1
0
        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);

            // add a label to one node
            var nodeLabelLayoutModel = new DiscreteNodeLabelLayoutModel(DiscreteNodeLabelPositions.InternalMask, 4);
            var labelLayoutFactory   = LayoutGraphUtilities.GetLabelFactory(graph);

            labelLayoutFactory.AddLabelLayout(v1, labelLayoutFactory.CreateLabelLayout(v1,
                                                                                       new YOrientedRectangle(0, 0, 80, 20), nodeLabelLayoutModel));

            Edge e1 = graph.CreateEdge(v1, v2);
            Edge e2 = graph.CreateEdge(v1, v3);

            // add a label to an edge
            var edgeLabelLayoutModel = new SliderEdgeLabelLayoutModel(SliderMode.Side);

            labelLayoutFactory.AddLabelLayout(e1, labelLayoutFactory.CreateLabelLayout(e1,
                                                                                       new YOrientedRectangle(0, 0, 80, 20), edgeLabelLayoutModel,
                                                                                       PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.LeftOfEdge)));

            //optionally setup some port constraints for HierarchicLayout
            IEdgeMap spc = graph.CreateEdgeMap();
            IEdgeMap tpc = graph.CreateEdgeMap();

            //e1 shall leave and enter the node on the right side
            spc.Set(e1, PortConstraint.Create(PortSide.East, false));
            //additionally set a strong port constraint on the target side.
            tpc.Set(e1, PortConstraint.Create(PortSide.East, true));
            //ports with strong port constraints will not be reset by the
            //layout algorithm.  So we specify the target port right now to connect
            //to the upper left corner of the node
            graph.SetTargetPointRel(e1, new YPoint(15, -15));

            //e2 shall leave and enter the node on the top side
            spc.Set(e2, PortConstraint.Create(PortSide.North, false));
            tpc.Set(e2, PortConstraint.Create(PortSide.North, false));

            graph.AddDataProvider(PortConstraintKeys.SourcePortConstraintDpKey, spc);
            graph.AddDataProvider(PortConstraintKeys.TargetPortConstraintDpKey, tpc);

            HierarchicLayout layout = new HierarchicLayout();

            layout.IntegratedEdgeLabeling = true;
            layout.ConsiderNodeLabels     = true;
            layout.LayoutMode             = LayoutMode.FromScratch;

            new BufferedLayout(layout).ApplyLayout(graph);

            Console.WriteLine("\n\nGRAPH LAID OUT HIERARCHICALLY FROM SCRATCH");
            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("e1 path = " + graph.GetPath(e1));
            Console.WriteLine("e2 path = " + graph.GetPath(e2));

            //display the graph in a simple viewer
            GraphViewer gv = new GraphViewer();

            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Before Addition");

            // now add a node and two edges incrementally...
            Node v4 = graph.CreateNode();

            graph.SetSize(v4, 30, 30);

            Edge e4 = graph.CreateEdge(v4, v2);
            Edge e3 = graph.CreateEdge(v1, v4);

            //mark elements as newly added so that the layout algorithm can place
            //them nicely.
            IIncrementalHintsFactory ihf = layout.CreateIncrementalHintsFactory();
            IDataMap map = Maps.CreateHashedDataMap();

            map.Set(v4, ihf.CreateLayerIncrementallyHint(v4));
            map.Set(e3, ihf.CreateSequenceIncrementallyHint(e3));
            map.Set(e4, ihf.CreateSequenceIncrementallyHint(e4));
            graph.AddDataProvider(HierarchicLayout.IncrementalHintsDpKey, map);
            layout.LayoutMode = LayoutMode.Incremental;

            new BufferedLayout(layout).ApplyLayout(graph);

            Console.WriteLine("\n\nGRAPH AFTER ELEMENTS HAVE BEEN ADDED INCREMENTALLY");
            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("e4 path = " + graph.GetPath(e4));

            //clean up data maps
            graph.RemoveDataProvider(HierarchicLayout.IncrementalHintsDpKey);

            //display the graph in a simple viewer
            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "After Addition");
            Application.Run(gv);
        }
        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);
        }
        /// <summary>
        /// Creates a small graph and applies a hierarchic group layout to it.
        /// The output of the calculated coordinates will be displayed in the
        /// console.
        /// </summary>
        public void Run()
        {
            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);

            Node groupNode = graph.CreateNode();

            graph.SetSize(groupNode, 100, 100);

            Edge e1 = graph.CreateEdge(v1, v2);
            Edge e2 = graph.CreateEdge(v4, groupNode);
            Edge e3 = graph.CreateEdge(v1, v3);
            Edge e4 = graph.CreateEdge(v1, v1);
            Edge e5 = graph.CreateEdge(v2, groupNode);
            Edge e6 = graph.CreateEdge(groupNode, v2);

            //optionally setup some edge groups
            IEdgeMap spg = graph.CreateEdgeMap();
            IEdgeMap tpg = graph.CreateEdgeMap();

            graph.AddDataProvider(PortConstraintKeys.SourceGroupIdDpKey, spg);
            graph.AddDataProvider(PortConstraintKeys.TargetGroupIdDpKey, tpg);

            spg.Set(e1, "SGroup1");
            spg.Set(e3, "SGroup1");
            tpg.Set(e1, "TGroup1");
            tpg.Set(e3, "TGroup1");

            //optionally setup the node grouping
            INodeMap nodeId       = graph.CreateNodeMap();
            INodeMap parentNodeId = graph.CreateNodeMap();
            INodeMap groupKey     = graph.CreateNodeMap();

            graph.AddDataProvider(GroupingKeys.NodeIdDpKey, nodeId);
            graph.AddDataProvider(GroupingKeys.ParentNodeIdDpKey, parentNodeId);
            graph.AddDataProvider(GroupingKeys.GroupDpKey, groupKey);

            //mark a node as a group node
            groupKey.SetBool(groupNode, true);

            // add ids for each node
            nodeId.Set(v1, "v1");
            nodeId.Set(v2, "v2");
            nodeId.Set(v3, "v3");
            nodeId.Set(v4, "v4");
            nodeId.Set(groupNode, "groupNode");

            // set the parent for each grouped node
            parentNodeId.Set(v2, "groupNode");
            parentNodeId.Set(v3, "groupNode");

            HierarchicLayout layout = new HierarchicLayout();

            layout.MinimumLayerDistance = 0;
            layout.EdgeLayoutDescriptor.MinimumDistance = 10;

            new BufferedLayout(layout).ApplyLayout(graph);

            Console.WriteLine("\n\nGRAPH LAID OUT USING HIERARCHICLAYOUT");
            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("group center position = " + graph.GetCenter(groupNode));
            Console.WriteLine("group size = " + graph.GetSize(groupNode));
            Console.WriteLine("e1 path = " + graph.GetPath(e1));
            Console.WriteLine("e2 path = " + graph.GetPath(e2));
            Console.WriteLine("e3 path = " + graph.GetPath(e3));
            Console.WriteLine("e4 path = " + graph.GetPath(e4));
            Console.WriteLine("e5 path = " + graph.GetPath(e5));
            Console.WriteLine("e6 path = " + graph.GetPath(e4));

            //display the result in a simple viewer
            var viewer = new GraphViewer();

            viewer.AddLayoutGraph(graph, "Hierarchical Group Layout");
            var application = new System.Windows.Application();

            application.Run(viewer);
        }
Ejemplo n.º 4
0
        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);

            Edge e1 = graph.CreateEdge(v1, v2);
            Edge e2 = graph.CreateEdge(v2, v3);
            Edge e3 = graph.CreateEdge(v1, v3);

            //optionally setup some port constraints for HierarchicLayout
            IEdgeMap spc = graph.CreateEdgeMap();
            IEdgeMap tpc = graph.CreateEdgeMap();

            //e1 shall leave and enter the node on the right side
            spc.Set(e1, PortConstraint.Create(PortSide.East));
            //additionally set a strong port constraint on the target side.
            tpc.Set(e1, PortConstraint.Create(PortSide.East, true));
            //ports with strong port constraints will not be reset by the
            //layout algorithm.  So we specify the target port right now to connect
            //to the upper left corner of the node
            graph.SetTargetPointRel(e1, new YPoint(15, -15));

            //e2 shall leave and enter the node on the top side
            spc.Set(e2, PortConstraint.Create(PortSide.North));
            tpc.Set(e2, PortConstraint.Create(PortSide.North));
            //e3 uses no port constraints, i.e. layout will choose best side
            graph.AddDataProvider(PortConstraintKeys.SourcePortConstraintDpKey, spc);
            graph.AddDataProvider(PortConstraintKeys.TargetPortConstraintDpKey, tpc);

            //setup two edge labels for edge e1. The size of the edge labels will be set to
            //80x20. Usually the size of the labels will be determined by
            //calculaing the bounding box of a piece text that is displayed
            //with a specific font.

            var labelFactory = LayoutGraphUtilities.GetLabelFactory(graph);

            graph.SetLabelLayout(e1, new[]
            {
                CreateEdgeLabelLayout(labelFactory, e1,
                                      new SliderEdgeLabelLayoutModel(SliderMode.Center),
                                      PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.AtCenter)),
                CreateEdgeLabelLayout(labelFactory, e1,
                                      new SliderEdgeLabelLayoutModel(SliderMode.Side),
                                      PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.LeftOfEdge))
            });

            var layout = new HierarchicLayout();

            layout.LabelingEnabled = true;
            layout.Labeling        = new GenericLabeling();

            new BufferedLayout(layout).ApplyLayout(graph);

            Console.WriteLine("\n\nGRAPH LAID OUT USING GENERIC EDGE LABELING");
            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("e1 path = " + graph.GetPath(e1));
            Console.WriteLine("e2 path = " + graph.GetPath(e2));
            Console.WriteLine("e3 path = " + graph.GetPath(e3));
            Console.WriteLine("ell1 upper left location = " + GetEdgeLabelLocation(graph, e1, CreateEdgeLabelLayout(labelFactory, e1,
                                                                                                                    new SliderEdgeLabelLayoutModel(SliderMode.Center),
                                                                                                                    PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.AtCenter))));
            Console.WriteLine("ell2 upper left location = " + GetEdgeLabelLocation(graph, e1, graph.GetLabelLayout(e1)[1]));

            GraphViewer gv = new GraphViewer();

            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Layout with Generic Labeling");

            var freeModel = new FreeEdgeLabelLayoutModel();

            graph.SetLabelLayout(e1, new[]
            {
                CreateEdgeLabelLayout(labelFactory, e1, freeModel,
                                      PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.AtCenter)),
                CreateEdgeLabelLayout(labelFactory, e1, freeModel,
                                      PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.LeftOfEdge))
            });

            layout.LabelingEnabled = true;
            layout.Labeling        = new LabelLayoutTranslator();

            new BufferedLayout(layout).ApplyLayout(graph);

            Console.WriteLine("\n\nGRAPH LAID OUT USING HIERACHIC LAYOUT SPECIFIC EDGE LABELING");
            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("e1 path = " + graph.GetPath(e1));
            Console.WriteLine("e2 path = " + graph.GetPath(e2));
            Console.WriteLine("e3 path = " + graph.GetPath(e3));
            Console.WriteLine("ell1 upper left location = " + GetEdgeLabelLocation(graph, e1, CreateEdgeLabelLayout(labelFactory, e1,
                                                                                                                    new SliderEdgeLabelLayoutModel(SliderMode.Center),
                                                                                                                    PreferredPlacementDescriptor.NewSharedInstance(LabelPlacements.AtCenter))));
            Console.WriteLine("ell2 upper left location = " + GetEdgeLabelLocation(graph, e1, graph.GetLabelLayout(e1)[1]));

            //display the result in a simple viewer
            gv.AddLayoutGraph(graph, "Layout with Integrated Labeling");
            var application = new System.Windows.Application();

            application.Run(gv);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            DefaultLayoutGraph graph = new DefaultLayoutGraph();

            //construct graph and assign sizes to its nodes
            Node[] nodes = new Node[16];
            for (int i = 0; i < 16; i++)
            {
                nodes[i] = graph.CreateNode();
                graph.SetSize(nodes[i], 30, 30);
            }
            graph.CreateEdge(nodes[0], nodes[1]);
            graph.CreateEdge(nodes[0], nodes[2]);
            graph.CreateEdge(nodes[0], nodes[3]);
            graph.CreateEdge(nodes[0], nodes[14]);
            graph.CreateEdge(nodes[2], nodes[4]);
            graph.CreateEdge(nodes[3], nodes[5]);
            graph.CreateEdge(nodes[3], nodes[6]);
            graph.CreateEdge(nodes[3], nodes[9]);
            graph.CreateEdge(nodes[4], nodes[7]);
            graph.CreateEdge(nodes[4], nodes[8]);
            graph.CreateEdge(nodes[5], nodes[9]);
            graph.CreateEdge(nodes[6], nodes[10]);
            graph.CreateEdge(nodes[7], nodes[11]);
            graph.CreateEdge(nodes[8], nodes[12]);
            graph.CreateEdge(nodes[8], nodes[15]);
            graph.CreateEdge(nodes[9], nodes[13]);
            graph.CreateEdge(nodes[10], nodes[13]);
            graph.CreateEdge(nodes[10], nodes[14]);
            graph.CreateEdge(nodes[12], nodes[15]);

            GraphViewer gv = new GraphViewer();

            //using organic layout style
            OrganicLayout organic = new OrganicLayout();

            organic.QualityTimeRatio    = 1.0;
            organic.NodeOverlapsAllowed = false;
            organic.MinimumNodeDistance = 10;
            organic.PreferredEdgeLength = 40;
            new BufferedLayout(organic).ApplyLayout(graph);
            LayoutGraphUtilities.ClipEdgesOnBounds(graph);
            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Organic Layout Style");

            //using orthogonal edge router (node positions stay fixed)
            EdgeRouter router = new EdgeRouter();

            new BufferedLayout(router).ApplyLayout(graph);
            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Polyline Edge Router");


            //using orthogonal layout style
            OrthogonalLayout orthogonal = new OrthogonalLayout();

            orthogonal.GridSpacing            = 15;
            orthogonal.OptimizePerceivedBends = true;
            new BufferedLayout(orthogonal).ApplyLayout(graph);
            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Orthogonal Layout Style");


            //using circular layout style
            CircularLayout circular = new CircularLayout();

            circular.BalloonLayout.MinimumEdgeLength = 20;
            circular.BalloonLayout.CompactnessFactor = 0.1;
            new BufferedLayout(circular).ApplyLayout(graph);
            LayoutGraphUtilities.ClipEdgesOnBounds(graph);
            gv.AddLayoutGraph(new CopiedLayoutGraph(graph), "Circular Layout Style");

            //using hierarchical layout style
            var hierarchic = new HierarchicLayout();

            new BufferedLayout(hierarchic).ApplyLayout(graph);
            gv.AddLayoutGraph(graph, "Hierarchical Layout Style");

            var application = new System.Windows.Application();

            application.Run(gv);
        }