Beispiel #1
0
        /// <summary>
        /// Creates and configures the <see cref="TreeLayout"/> and the <see cref="TreeLayoutData"/>
        /// such that node types are considered.
        /// </summary>
        private Sample CreateTreeSample()
        {
            // create a tree layout including a reduction stage to support non-tree graphs too
            var layout = new TreeLayout {
                DefaultNodePlacer = new CompactNodePlacer()
            };
            var edgeRouter = new EdgeRouter {
                Scope = Scope.RouteAffectedEdges
            };
            var reductionStage = new TreeReductionStage {
                NonTreeEdgeRouter = edgeRouter, NonTreeEdgeSelectionKey = edgeRouter.AffectedEdgesDpKey
            };

            layout.PrependStage(reductionStage);

            // the node types are specified as delegate on the nodeTypes property of the layout data
            var layoutData = new TreeLayoutData {
                NodeTypes = { Delegate = node => GetNodeType(node) }
            };

            return(new Sample {
                Name = "Tree",
                File = "tree",
                Layout = layout,
                LayoutData = layoutData,
                IsDirected = true
            });
        }
Beispiel #2
0
        private static LayoutData CreateLayoutData(IGraph tree, INode centerNode)
        {
            var data = new TreeLayoutData
            {
                NodePlacers = { Delegate              = delegate(INode node) {
                                    var employee      = node.Tag as XmlElement;
                                    if (tree.OutDegree(node) == 0 || employee == null)
                                    {
                                        return(null);
                                    }
                                    var layout        = employee.GetAttribute("layout");
                                    switch (layout)
                                    {
                                    case "rightHanging":
                                        return(new AssistantNodePlacer()
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.VerticalToRight, RootAlignment.LeadingOnBus, 30, 30)
                                {
                                    RoutingStyle      = RoutingStyle.ForkAtRoot
                                }
                            });

                                    case "leftHanging":
                                        return(new AssistantNodePlacer()
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.VerticalToLeft, RootAlignment.LeadingOnBus, 30, 30)
                                {
                                    RoutingStyle      = RoutingStyle.ForkAtRoot
                                }
                            });

                                    case "bothHanging":
                                        return(new AssistantNodePlacer()
                            {
                                ChildNodePlacer       = new LeftRightNodePlacer()
                                {
                                    PlaceLastOnBottom = false
                                }
                            });

                                    default:
                                        return(new AssistantNodePlacer()
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.HorizontalDownward, RootAlignment.Median, 30, 30)
                            });
                                    }
                                } },
                AssistantNodes = { Delegate          = delegate(INode node) {
                                       var employee  = node.Tag as XmlElement;
                                       var assistant = employee != null ? employee.Attributes["assistant"] : null;
                                       return(assistant != null && assistant.Value == "true");
                                   } }
            };

            return(data.CombineWith(new FixNodeLayoutData {
                FixedNodes = { Item = centerNode }
            }));
        }
        protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout)
        {
            LayoutData layoutData;

            if (NodePlacerItem == EnumNodePlacer.HV)
            {
                layoutData = CreateLayoutDataHorizontalVertical(graphControl);
            }
            else if (NodePlacerItem == EnumNodePlacer.DelegatingLayered)
            {
                layoutData = CreateLayoutDataDelegatingPlacer(graphControl);
            }
            else
            {
                var graph = graphControl.Graph;
                layoutData = new TreeLayoutData {
                    GridNodePlacerRowIndices =
                    {
                        Delegate             = node => {
                            var predecessors = graph.Predecessors(node);
                            var parent       = predecessors.FirstOrDefault();
                            if (parent != null)
                            {
                                var siblings = graph.Successors(parent).ToList();
                                return(siblings.IndexOf(node) % (int)Math.Round(Math.Sqrt(siblings.Count)));
                            }
                            return(0);
                        }
                    },
                    LeftRightNodePlacerLeftNodes =
                    {
                        Delegate             = node => {
                            var predecessors = graph.Predecessors(node);
                            var parent       = predecessors.FirstOrDefault();
                            if (parent != null)
                            {
                                var siblings = graph.Successors(parent).ToList();
                                return(siblings.IndexOf(node) % 2 != 0);
                            }
                            return(false);
                        }
                    },
                    CompactNodePlacerStrategyMementos = new DictionaryMapper <INode, object>(),
                    // AssistantNodes = {Delegate = node => node.Tag != null ? node.Tag.Assistant : null}
                };
            }

            return(layoutData.CombineWith(
                       CreateLabelingLayoutData(
                           graphControl.Graph,
                           LabelPlacementAlongEdgeItem,
                           LabelPlacementSideOfEdgeItem,
                           LabelPlacementOrientationItem,
                           LabelPlacementDistanceItem
                           )
                       ));
        }
        private TreeLayoutData CreateLayoutDataDelegatingPlacer(GraphControl graphComponent)
        {
            var graph = graphComponent.Graph;
            //half the subtrees are delegated to the left placer and half to the right placer
            var leftNodes = new HashSet <INode>();
            var root      = graph.Nodes.First(node => graph.InDegree(node) == 0);
            var left      = true;

            foreach (var successor in graph.Successors(root))
            {
                var stack = new List <INode> {
                    successor
                };
                while (stack.Count > 0)
                {
                    var child = stack[stack.Count - 1];
                    stack.RemoveAt(stack.Count - 1);
                    if (left)
                    {
                        leftNodes.Add(child);
                    } // else: right node
                    //push successors on stack -> whole subtree is either left or right
                    stack.AddRange(graph.Successors(child));
                }
                left = !left;
            }

            var layoutData = new TreeLayoutData {
                DelegatingNodePlacerPrimaryNodes = { Delegate = node => leftNodes.Contains(node) },
                // tells the layout which node placer to use for a node
                NodePlacers =
                {
                    Delegate = node => {
                        if (node == root)
                        {
                            return(delegatingRootPlacer);
                        }
                        if (leftNodes.Contains(node))
                        {
                            return(delegatingLeftPlacer);
                        }
                        return(delegatingRightPlacer);
                    }
                }
            };

            layoutData.TreeRoot.Item = root;
            return(layoutData);
        }
        private static LayoutData CreateLayoutData(IGraph tree, INode centerNode)
        {
            var data = new TreeLayoutData
            {
                NodePlacers =
                {
                    Delegate                          = delegate(INode node) {
                        var employee                  = node.Tag as Employee;
                        if (tree.OutDegree(node) == 0 || employee == null)
                        {
                            return(null);
                        }
                        var layout                    = employee.Layout;
                        switch (layout)
                        {
                        case EmployeeLayout.RightHanging:
                            return(new AssistantNodePlacer
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.VerticalToRight, RootAlignment.LeadingOnBus, 30, 30)
                                {
                                    RoutingStyle      = RoutingStyle.ForkAtRoot
                                }
                            });

                        case EmployeeLayout.LeftHanging:
                            return(new AssistantNodePlacer
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.VerticalToLeft, RootAlignment.LeadingOnBus, 30, 30)
                                {
                                    RoutingStyle      = RoutingStyle.ForkAtRoot
                                }
                            });

                        case EmployeeLayout.BothHanging:
                            return(new AssistantNodePlacer
                            {
                                ChildNodePlacer       = new LeftRightNodePlacer()
                                {
                                    PlaceLastOnBottom = false
                                }
                            });

                        default:
                            return(new AssistantNodePlacer
                            {
                                ChildNodePlacer       = new DefaultNodePlacer(ChildPlacement.HorizontalDownward, RootAlignment.Median, 30, 30)
                            });
                        }
                    }
                },
                AssistantNodes =
                {
                    Delegate         = delegate(INode node) {
                        var employee = node.Tag as Employee;
                        return(employee != null && employee.Assistant);
                    }
                }
            };

            return(data.CombineWith(new FixNodeLayoutData {
                FixedNodes = { Item = centerNode }
            }));
        }