Exemple #1
0
        /// <summary>
        /// sets the global layout options.
        /// </summary>
        /// <param name="orthogonal"></param>
        private void SetGlobalOptions(OrthogonalLayout orthogonal)
        {
            OptionGroup layoutGroup = Handler.GetGroupByName(LAYOUT);
            OptionGroup edgeGroup   = Handler.GetGroupByName(EDGES);

            orthogonal.LayoutStyle = styles[(string)layoutGroup[STYLE].Value];

            if ((bool)edgeGroup[DRAW_SELECTED_EDGES_UPWARDS].Value)
            {
                var    ol = (OrientationLayout)orthogonal.OrientationLayout;
                string orientationChoice = (string)edgeGroup[ORIENTATION].Value;
                ol.Orientation = orientEnum[orientationChoice];
            }

            orthogonal.GridSpacing            = ((int)layoutGroup[GRID].Value);
            orthogonal.EdgeLengthReduction    = ((bool)layoutGroup[LENGTH_REDUCTION].Value);
            orthogonal.OptimizePerceivedBends = ((bool)layoutGroup[PERCEIVED_BENDS_POSTPROCESSING].Value);
            orthogonal.CrossingReduction      =
                (bool)layoutGroup[CROSSING_POSTPROCESSING].Value;
            orthogonal.Randomization    = (bool)layoutGroup[USE_RANDOMIZATION].Value;
            orthogonal.FaceMaximization = (bool)layoutGroup[USE_FACE_MAXIMIZATION].Value;
            orthogonal.FromSketchMode   = (bool)layoutGroup[USE_EXISTING_DRAWING_AS_SKETCH].Value;
            orthogonal.EdgeLayoutDescriptor.MinimumFirstSegmentLength = (double)edgeGroup[MINIMUM_FIRST_SEGMENT_LENGTH].Value;
            orthogonal.EdgeLayoutDescriptor.MinimumLastSegmentLength  = (double)edgeGroup[MINIMUM_LAST_SEGMENT_LENGTH].Value;
            orthogonal.EdgeLayoutDescriptor.MinimumSegmentLength      = (double)edgeGroup[MINIMUM_SEGMENT_LENGTH].Value;
        }
Exemple #2
0
        private void ApplyOptions(OrthogonalLayout layout)
        {
            OptionGroup topLevelGroup = Handler.GetGroupByName(TOP_LEVEL);
            IOptionItem styleItem     = topLevelGroup.GetItemByName(ORTHOGONAL_LAYOUT_STYLE);

            layout.LayoutStyle = styles[(string)styleItem.Value];
        }
        /// <inheritdoc />
        protected override ILayoutAlgorithm CreateConfiguredLayout(GraphControl graphControl)
        {
            var layout = new OrthogonalLayout();

            if (GroupLayoutPolicyItem == EnumGroupPolicy.FixGroups)
            {
                var fgl = new FixGroupLayoutStage {
                    InterEdgeRoutingStyle = InterEdgeRoutingStyle.Orthogonal
                };
                layout.PrependStage(fgl);
            }
            else if (GroupLayoutPolicyItem == EnumGroupPolicy.IgnoreGroups)
            {
                layout.HideGroupsStageEnabled = true;
            }

            layout.LayoutStyle            = StyleItem;
            layout.GridSpacing            = GridSpacingItem;
            layout.EdgeLengthReduction    = EdgeLengthReductionItem;
            layout.OptimizePerceivedBends = PerceivedBendsPostprocessingItem;
            layout.UniformPortAssignment  = UniformPortAssignmentItem;
            layout.CrossingReduction      = CrossingReductionItem;
            layout.Randomization          = UseRandomizationItem;
            layout.FaceMaximization       = UseFaceMaximizationItem;
            layout.FromSketchMode         = UseExistingDrawingAsSketchItem;
            layout.EdgeLayoutDescriptor.MinimumFirstSegmentLength = MinimumFirstSegmentLengthItem;
            layout.EdgeLayoutDescriptor.MinimumLastSegmentLength  = MinimumLastSegmentLengthItem;
            layout.EdgeLayoutDescriptor.MinimumSegmentLength      = MinimumSegmentLengthItem;

            //set edge labeling options
            var normalStyle = layout.LayoutStyle == LayoutStyle.Normal;

            layout.IntegratedEdgeLabeling = EdgeLabelingItem == EnumEdgeLabeling.Integrated && normalStyle;
            layout.ConsiderNodeLabels     = ConsiderNodeLabelsItem && normalStyle;

            if (EdgeLabelingItem == EnumEdgeLabeling.Generic ||
                (EdgeLabelingItem == EnumEdgeLabeling.Integrated && normalStyle))
            {
                layout.LabelingEnabled = true;
                if (EdgeLabelingItem == EnumEdgeLabeling.Generic)
                {
                    ((GenericLabeling)layout.Labeling).ReduceAmbiguity = ReduceAmbiguityItem;
                }
            }
            else if (!ConsiderNodeLabelsItem || !normalStyle)
            {
                layout.LabelingEnabled = false;
            }

            layout.ChainStyle      = ChainSubstructureStyleItem;
            layout.ChainSize       = ChainSubstructureSizeItem;
            layout.CycleStyle      = CycleSubstructureStyleItem;
            layout.CycleSize       = CycleSubstructureSizeItem;
            layout.TreeStyle       = TreeSubstructureStyleItem;
            layout.TreeSize        = TreeSubstructureSizeItem;
            layout.TreeOrientation = TreeSubstructureOrientationItem;

            return(layout);
        }
 static PartialLayoutForm()
 {
     SubGraphLayouts[LayoutIncremental] = new HierarchicLayout();
     SubGraphLayouts[LayoutOrganic]     = new OrganicLayout();
     SubGraphLayouts[LayoutOrthogonal]  = new OrthogonalLayout();
     SubGraphLayouts[LayoutCircular]    = new CircularLayout();
     SubGraphLayouts[LayoutUnchanged]   = null;
 }
Exemple #5
0
        /// <summary>
        /// Gets the layout algorithm selected by the user.
        /// </summary>
        /// <returns></returns>
        private ILayoutAlgorithm GetLayoutAlgorithm()
        {
            var graph               = graphControl.Graph;
            var item                = layoutChooserBox.SelectedItem as ComboBoxItem;
            var layoutName          = item != null ? item.Tag as String: null;
            ILayoutAlgorithm layout = new HierarchicLayout();

            if (layoutName != null)
            {
                if (layoutName == "hierarchic")
                {
                    layout = new HierarchicLayout();
                }
                else if (layoutName == "organic")
                {
                    layout = new OrganicLayout {
                        PreferredEdgeLength = 1.5 * Math.Max(graph.NodeDefaults.Size.Width, graph.NodeDefaults.Size.Height)
                    };
                }
                else if (layoutName == "orthogonal")
                {
                    layout = new OrthogonalLayout();
                }
                else if (layoutName == "circular")
                {
                    layout = new CircularLayout();
                }
                else if (layoutName == "tree")
                {
                    layout = new TreeReductionStage(new TreeLayout())
                    {
                        NonTreeEdgeRouter = new OrganicEdgeRouter()
                    };
                }
                else if (layoutName == "balloon")
                {
                    layout = new TreeReductionStage(new BalloonLayout())
                    {
                        NonTreeEdgeRouter = new OrganicEdgeRouter()
                    };
                }
                else if (layoutName == "radial")
                {
                    layout = new RadialLayout();
                }
                else if (layoutName == "router-polyline")
                {
                    layout = new EdgeRouter();
                }
                else if (layoutName == "router-organic")
                {
                    layout = new OrganicEdgeRouter {
                        EdgeNodeOverlapAllowed = false
                    };
                }
            }
            return(layout);
        }
Exemple #6
0
        /// <summary>
        /// Gets the layout algorithm selected by the user.
        /// </summary>
        /// <returns></returns>
        private ILayoutAlgorithm GetLayoutAlgorithm()
        {
            var graph               = graphControl.Graph;
            var layoutName          = layoutBox.SelectedItem as string;
            ILayoutAlgorithm layout = new HierarchicLayout();

            if (layoutName != null)
            {
                if (layoutName == "Layout: Hierarchic")
                {
                    layout = new HierarchicLayout();
                }
                else if (layoutName == "Layout: Organic")
                {
                    layout = new OrganicLayout {
                        PreferredEdgeLength = 1.5 * Math.Max(graph.NodeDefaults.Size.Width, graph.NodeDefaults.Size.Height)
                    };
                }
                else if (layoutName == "Layout: Orthogonal")
                {
                    layout = new OrthogonalLayout();
                }
                else if (layoutName == "Layout: Circular")
                {
                    layout = new CircularLayout();
                }
                else if (layoutName == "Layout: Tree")
                {
                    layout = new TreeReductionStage(new TreeLayout())
                    {
                        NonTreeEdgeRouter = new OrganicEdgeRouter()
                    };
                }
                else if (layoutName == "Layout: Balloon")
                {
                    layout = new TreeReductionStage(new BalloonLayout())
                    {
                        NonTreeEdgeRouter = new OrganicEdgeRouter()
                    };
                }
                else if (layoutName == "Layout: Radial")
                {
                    layout = new RadialLayout();
                }
                else if (layoutName == "Routing: Polyline")
                {
                    layout = new EdgeRouter();
                }
                else if (layoutName == "Routing: Organic")
                {
                    layout = new OrganicEdgeRouter {
                        EdgeNodeOverlapAllowed = false
                    };
                }
            }
            return(layout);
        }
Exemple #7
0
        private static ILayoutAlgorithm CreateOrthogonalLayout()
        {
            var orthogonalLayout = new OrthogonalLayout {
                IntegratedEdgeLabeling = true
            };

            DisableAutoFlipping(orthogonalLayout);
            return(orthogonalLayout);
        }
        /// <summary>
        /// Populates the layout combo box.
        /// </summary>
        private void PopulateLayoutComboBox()
        {
            layouts["Hierarchic Layout"] = new HierarchicLayout();
            layouts["Organic Layout"]    = new OrganicLayout {
                MinimumNodeDistance = 40
            };
            layouts["Orthogonal Layout"] = new OrthogonalLayout();

            layoutComboBox.Items.AddRange(layouts.Keys.ToArray());
        }
        ///<inheritdoc/>
        protected override void ConfigureLayout()
        {
            OptionGroup layoutGroup   = Handler.GetGroupByName(GENERAL);
            var         partialLayout = new PartialLayout
            {
                MinimumNodeDistance   = (int)layoutGroup[MIN_NODE_DIST].Value,
                ConsiderNodeAlignment = (bool)layoutGroup[CONSIDER_SNAPLINES].Value,
                SubgraphPlacement     =
                    subgraphPlacementStrategies[
                        (string)layoutGroup[SUBGRAPH_POSITION_STRATEGY].Value]
            };

            string componentAssignmentStr = (string)layoutGroup[MODE_COMPONENT_ASSIGNMENT].Value;

            partialLayout.ComponentAssignmentStrategy =
                componentAssignment[componentAssignmentStr];

            partialLayout.LayoutOrientation =
                layoutOrientation[(string)layoutGroup[ORIENTATION_MAIN_GRAPH].Value];

            partialLayout.EdgeRoutingStrategy =
                routingStrategies[(string)layoutGroup[ROUTING_TO_SUBGRAPH].Value];

            ILayoutAlgorithm subgraphLayout = null;

            if (componentAssignmentStr != MODE_COMPONENT_SINGLE)
            {
                var subGraphLayoutStr = (string)layoutGroup[SUBGRAPH_LAYOUT].Value;
                switch (subGraphLayoutStr)
                {
                case SUBGRAPH_LAYOUT_IHL:
                    subgraphLayout = new HierarchicLayout();
                    break;

                case SUBGRAPH_LAYOUT_ORGANIC:
                    subgraphLayout = new OrganicLayout();
                    break;

                case SUBGRAPH_LAYOUT_CIRCULAR:
                    subgraphLayout = new CircularLayout();
                    break;

                case SUBGRAPH_LAYOUT_ORTHOGONAL:
                    subgraphLayout = new OrthogonalLayout();
                    break;

                default:
                    break;
                }
            }
            partialLayout.CoreLayout = subgraphLayout;

            LayoutAlgorithm = partialLayout;
        }
Exemple #10
0
        /// <summary>
        /// configures the layout algorithm according to the settings of the option handler.
        /// </summary>
        protected override void ConfigureLayout()
        {
            OrthogonalLayout orthogonal = new OrthogonalLayout();

            ((ComponentLayout)orthogonal.ComponentLayout).Style = ComponentArrangementStyles.MultiRows;

            SetGlobalOptions(orthogonal);
            SetEdgeLabelingOptions(orthogonal);

            LayoutAlgorithm = orthogonal;
        }
 /// <summary>
 /// Creates the core layouts and populates the layouts box
 /// </summary>
 private void InitializeCoreLayouts()
 {
     coreLayouts = new Dictionary <string, ILayoutAlgorithm>();
     coreLayouts["Hierarchic"] = new HierarchicLayout {
         ConsiderNodeLabels = true, IntegratedEdgeLabeling = true, OrthogonalRouting = true
     };
     coreLayouts["Circular"]           = new CircularLayout();
     coreLayouts["Compact Orthogonal"] = new CompactOrthogonalLayout();
     coreLayouts["Organic"]            = new OrganicLayout {
         MinimumNodeDistance = 10, Deterministic = true
     };
     coreLayouts["Orthogonal"]        = new OrthogonalLayout();
     coreLayoutComboBox.ItemsSource   = coreLayouts.Keys;
     coreLayoutComboBox.SelectedIndex = 0;
 }
Exemple #12
0
        private void SetupLayouts()
        {
            // create TreeLayout
            var treeLayout = new TreeLayout {
                LayoutOrientation = LayoutOrientation.LeftToRight
            };

            treeLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(treeLayout);
            layoutMapper["Tree"] = treeLayout;
            layoutComboBox.Items.Add("Tree");

            // create BalloonLayout
            var balloonLayout = new BalloonLayout
            {
                FromSketchMode    = true,
                CompactnessFactor = 1.0,
                AllowOverlaps     = true
            };

            balloonLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(balloonLayout);
            layoutMapper["Balloon"] = balloonLayout;
            layoutComboBox.Items.Add("Balloon");

            // create OrganicLayout
            var organicLayout = new OrganicLayout {
                MinimumNodeDistance = 40,
                Deterministic       = true
            };

            organicLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(organicLayout);
            layoutMapper["Organic"] = organicLayout;
            layoutComboBox.Items.Add("Organic");

            // create OrthogonalLayout
            var orthogonalLayout = new OrthogonalLayout();

            orthogonalLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(orthogonalLayout);
            layoutMapper["Orthogonal"] = orthogonalLayout;
            layoutComboBox.Items.Add("Orthogonal");

            // set it as initial value
            currentLayout = treeLayout;
            layoutComboBox.SelectedIndex = 0;
        }
Exemple #13
0
        /// <summary>
        /// sets the options for edge labeling.
        /// </summary>
        /// <param name="orthogonal"></param>
        private void SetEdgeLabelingOptions(OrthogonalLayout orthogonal)
        {
            String edgeLabelingName = (String)Handler.GetValue(LABELING, EDGE_LABELING);

            bool normalStyle = (orthogonal.LayoutStyle == LayoutStyle.Normal);

            orthogonal.IntegratedEdgeLabeling = (edgeLabelingName == INTEGRATED && normalStyle);
            bool considerNodeLabels = (bool)Handler.GetValue(LABELING, CONSIDER_NODE_LABELS);

            orthogonal.ConsiderNodeLabels = considerNodeLabels && normalStyle;

            if (edgeLabelingName == GENERIC || (edgeLabelingName == INTEGRATED && normalStyle))
            {
                orthogonal.LabelingEnabled = true;
            }
            else if (!considerNodeLabels || !normalStyle)
            {
                orthogonal.LabelingEnabled = false;
            }
        }
Exemple #14
0
        /// <inheritdoc />
        protected override ILayoutAlgorithm CreateConfiguredLayout(GraphControl graphControl)
        {
            var layout = new PartialLayout();

            layout.ConsiderNodeAlignment       = AlignNodesItem;
            layout.MinimumNodeDistance         = MinimumNodeDistanceItem;
            layout.SubgraphPlacement           = SubgraphPlacementItem;
            layout.ComponentAssignmentStrategy = ComponentAssignmentStrategyItem;
            layout.LayoutOrientation           = OrientationItem;
            layout.EdgeRoutingStrategy         = RoutingToSubgraphItem;
            layout.AllowMovingFixedElements    = MoveFixedElementsItem;

            ILayoutAlgorithm subgraphLayout = null;

            if (ComponentAssignmentStrategyItem != ComponentAssignmentStrategy.Single)
            {
                switch (SubgraphLayoutItem)
                {
                case EnumSubgraphLayouts.Hierarchic:
                    subgraphLayout = new HierarchicLayout();
                    break;

                case EnumSubgraphLayouts.Organic:
                    subgraphLayout = new OrganicLayout();
                    break;

                case EnumSubgraphLayouts.Circular:
                    subgraphLayout = new CircularLayout();
                    break;

                case EnumSubgraphLayouts.Orthogonal:
                    subgraphLayout = new OrthogonalLayout();
                    break;
                }
            }
            layout.CoreLayout = subgraphLayout;

            return(layout);
        }
        /// <summary>
        /// sets up the option handler for specifying the layout parameters.
        /// </summary>
        protected override void SetupHandler()
        {
            // use an instance of the layout as a defaults provider
            CompactOrthogonalLayout layout = new CompactOrthogonalLayout();
            var topLevelGroup = Handler.AddGroup(TOP_LEVEL);

            topLevelGroup.SetAttribute(TableEditorFactory.RENDERING_HINTS_ATTRIBUTE,
                                       (int)TableEditorFactory.RenderingHints.Invisible);
            topLevelGroup.SetAttribute(DefaultEditorFactory.RENDERING_HINTS_ATTRIBUTE,
                                       (int)DefaultEditorFactory.RenderingHints.Invisible);

            OrthogonalLayout cl = (OrthogonalLayout)layout.CoreLayout;

            topLevelGroup.AddList(ORTHOGONAL_LAYOUT_STYLE, new [] { NORMAL, NORMAL_TREE, FIXED_BOX_NODES, FIXED_MIXED }, str2styles[cl.LayoutStyle]);

            topLevelGroup.AddList(PLACEMENT_STRATEGY, new[] { STYLE_ROWS, STYLE_PACKED_COMPACT_RECTANGLE }, str2componentStyles[ComponentArrangementStyles.PackedCompactRectangle]);

            topLevelGroup.AddDouble(ASPECT_RATIO, layout.AspectRatio);
            topLevelGroup.AddInt(GRID, layout.GridSpacing, 1, int.MaxValue);

            OrthogonalPatternEdgeRouter oper = new OrthogonalPatternEdgeRouter();

            IOptionItem bendCostOptionItem         = topLevelGroup.AddDouble(BEND_COST, oper.BendCost);
            IOptionItem nodeCrossingCostOptionItem = topLevelGroup.AddDouble(NODE_CROSSING_COST, oper.NodeCrossingCost);
            IOptionItem edgeCrossingCostOptionItem = topLevelGroup.AddDouble(EDGE_CROSSING_COST, oper.EdgeCrossingCost);
            IOptionItem minimumDistanceOptionItem  = topLevelGroup.AddDouble(MINIMUM_DISTANCE, oper.MinimumDistance);

            IOptionItem pathFinderOptionItem = topLevelGroup.AddList(PATH_FINDER, PATH_FINDER_ENUM, ORTHOGONAL_SHORTESTPATH_PATH_FINDER);

            ConstraintManager cm = new ConstraintManager(Handler);

            cm.SetEnabledOnValueEquals(pathFinderOptionItem, ORTHOGONAL_PATTERN_PATH_FINDER, bendCostOptionItem);
            cm.SetEnabledOnValueEquals(pathFinderOptionItem, ORTHOGONAL_PATTERN_PATH_FINDER, nodeCrossingCostOptionItem);
            cm.SetEnabledOnValueEquals(pathFinderOptionItem, ORTHOGONAL_PATTERN_PATH_FINDER, edgeCrossingCostOptionItem);
            cm.SetEnabledOnValueEquals(pathFinderOptionItem, ORTHOGONAL_PATTERN_PATH_FINDER, minimumDistanceOptionItem);

            topLevelGroup.AddBool(ROUTE_ALL_EDGES, !layout.InterEdgeRouter.RouteInterEdgesOnly);
        }
Exemple #16
0
        public void ExecuteLayout(Type type, bool resize)
        {
            bool suspend = this.Suspended;

            if (!suspend)
            {
                this.SuspendEvents = true;
                this.Suspend();
            }

            // Create Layout Graph
            Graph graph = new Graph();

            graph.AddDiagram(this);

            //
            Layout layout = null;

            if (type == typeof(TreeLayout))
            {
                TreeLayout treeLayout = new TreeLayout();
                treeLayout.Direction             = TreeLayoutSettings.Default.Direction;
                treeLayout.LevelDistance         = TreeLayoutSettings.Default.LevelDistance;
                treeLayout.OrthogonalLayoutStyle = TreeLayoutSettings.Default.OrthogonalLayoutStyle;
                treeLayout.RootSelection         = TreeLayoutSettings.Default.RootSelection;
                treeLayout.SiblingDistance       = TreeLayoutSettings.Default.SiblingDistance;
                treeLayout.SubtreeDistance       = TreeLayoutSettings.Default.SubtreeDistance;
                treeLayout.TreeDistance          = TreeLayoutSettings.Default.TreeDistance;
                layout = treeLayout;
            }
            else if (type == typeof(OrthogonalLayout))
            {
                OrthogonalLayout orthogonalLayout = new OrthogonalLayout();
                orthogonalLayout.ConnectedComponentDistance = OrthogonalLayoutSettings.Default.ConnectedComponentDistance;
                orthogonalLayout.CrossingQuality            = OrthogonalLayoutSettings.Default.CrossingQuality;
                orthogonalLayout.Distance = OrthogonalLayoutSettings.Default.Distance;
                orthogonalLayout.Overhang = OrthogonalLayoutSettings.Default.Overhang;
                layout = orthogonalLayout;
            }
            else if (type == typeof(HierarchicalLayout))
            {
                HierarchicalLayout hierarchicalLayout = new HierarchicalLayout();
                hierarchicalLayout.ConnectedComponentDistance = HierarchicalLayoutSettings.Default.ConnectedComponentDistance;
                hierarchicalLayout.Direction      = HierarchicalLayoutSettings.Default.Direction;
                hierarchicalLayout.LayerDistance  = HierarchicalLayoutSettings.Default.LayerDistance;
                hierarchicalLayout.ObjectDistance = HierarchicalLayoutSettings.Default.ObjectDistance;
                hierarchicalLayout.RespectLayer   = HierarchicalLayoutSettings.Default.RespectLayer;
                layout = hierarchicalLayout;
            }
            else if (type == typeof(ForceDirectedLayout))
            {
                ForceDirectedLayout forceDirectedLayout = new ForceDirectedLayout();
                forceDirectedLayout.ConnectedComponentDistance = ForcedDirectLayoutSettings.Default.ConnectedComponentDistance;
                forceDirectedLayout.Quality = ForcedDirectLayoutSettings.Default.Quality;
                forceDirectedLayout.Tuning  = ForcedDirectLayoutSettings.Default.TuningType;
                layout = forceDirectedLayout;
            }
            else if (type == typeof(CircularLayout))
            {
                CircularLayout circularLayout = new CircularLayout();
                circularLayout.CircleDistance             = CircularLayoutSettings.Default.CircleDistance;
                circularLayout.ConnectedComponentDistance = CircularLayoutSettings.Default.ConnectedComponentDistance;
                circularLayout.LayerDistance  = CircularLayoutSettings.Default.LayerDistance;
                circularLayout.ObjectDistance = CircularLayoutSettings.Default.ObjectDistance;
                layout = circularLayout;
            }

            //
            if (layout != null)
            {
                // Do Layout
                layout.DoLayout(graph);

                // Apply if Layout Succeeded
                if (layout.Status == LayoutStatus.Success)
                {
                    // Resize Diagram
                    RectangleF rectangle = graph.TotalArea();
                    rectangle.Inflate(50, 50);
                    if (resize)
                    {
                        this.DiagramSize = rectangle.Size.ToSize();
                    }
                    graph.ScaleToFit(this.DiagramSize);

                    // Apply Layout
                    graph.Apply(this);
                }
            }

            if (!suspend)
            {
                this.Resume();
                this.SuspendEvents = false;
                this.Refresh();
            }
        }
Exemple #17
0
        private void SetupLayouts()
        {
            //using hierarchical layout style
            HierarchicLayout hierarchicLayout = new HierarchicLayout();

            hierarchicLayout.EdgeLayoutDescriptor.RoutingStyle = new yWorks.Layout.Hierarchic.RoutingStyle(
                yWorks.Layout.Hierarchic.EdgeRoutingStyle.Orthogonal);

            CurrentLayout = hierarchicLayout;
            layouts.Add("Hierarchic", hierarchicLayout);

            //using organic layout style
            OrganicLayout organic = new OrganicLayout
            {
                QualityTimeRatio       = 1.0,
                NodeOverlapsAllowed    = false,
                NodeEdgeOverlapAvoided = true,
                MinimumNodeDistance    = 10,
                PreferredEdgeLength    = 50,
            };

            layouts.Add("Organic", organic);

            //using orthogonal layout style
            OrthogonalLayout orthogonal = new OrthogonalLayout
            {
                GridSpacing            = 15,
                OptimizePerceivedBends = true
            };

            layouts.Add("Orthogonal", orthogonal);

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

            circular.BalloonLayout.MinimumEdgeLength = 50;
            circular.BalloonLayout.CompactnessFactor = 0.1;
            layouts.Add("Circular", circular);

            // a tree layout algorithm
            TreeLayout treeLayout = new TreeLayout {
                ConsiderNodeLabels = true
            };

            treeLayout.AppendStage(new TreeReductionStage()
            {
                NonTreeEdgeRouter       = new OrganicEdgeRouter(),
                NonTreeEdgeSelectionKey = OrganicEdgeRouter.AffectedEdgesDpKey,
            });
            layouts.Add("Tree", treeLayout);

            //using Polyline Router
            var polylineRouter = new EdgeRouter
            {
                Grid            = new Grid(0, 0, 10),
                PolylineRouting = true,
                Rerouting       = true
            };

            polylineRouter.DefaultEdgeLayoutDescriptor.PenaltySettings.BendPenalty         = 3;
            polylineRouter.DefaultEdgeLayoutDescriptor.PenaltySettings.EdgeCrossingPenalty = 5;
            layouts.Add("Polyline Edge Router", polylineRouter);
        }
Exemple #18
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);
        }
        public void ExecuteLayout(Type type, bool resize) {
            bool suspend = this.Suspended;
            if (!suspend) {
                this.SuspendEvents = true;
                this.Suspend();
            }

            // Create Layout Graph
            Graph graph = new Graph();
            graph.AddDiagram(this);

            //
            Layout layout = null;

            if (type == typeof(TreeLayout)) {
                TreeLayout treeLayout = new TreeLayout();
                treeLayout.Direction = TreeLayoutSettings.Default.Direction;
                treeLayout.LevelDistance = TreeLayoutSettings.Default.LevelDistance;
                treeLayout.OrthogonalLayoutStyle = TreeLayoutSettings.Default.OrthogonalLayoutStyle;
                treeLayout.RootSelection = TreeLayoutSettings.Default.RootSelection;
                treeLayout.SiblingDistance = TreeLayoutSettings.Default.SiblingDistance;
                treeLayout.SubtreeDistance = TreeLayoutSettings.Default.SubtreeDistance;
                treeLayout.TreeDistance = TreeLayoutSettings.Default.TreeDistance;
                layout = treeLayout;
            }
            else if (type == typeof(OrthogonalLayout)) {
                OrthogonalLayout orthogonalLayout = new OrthogonalLayout();
                orthogonalLayout.ConnectedComponentDistance = OrthogonalLayoutSettings.Default.ConnectedComponentDistance;
                orthogonalLayout.CrossingQuality = OrthogonalLayoutSettings.Default.CrossingQuality;
                orthogonalLayout.Distance = OrthogonalLayoutSettings.Default.Distance;
                orthogonalLayout.Overhang = OrthogonalLayoutSettings.Default.Overhang;
                layout = orthogonalLayout;
            }
            else if (type == typeof(HierarchicalLayout)) {
                HierarchicalLayout hierarchicalLayout = new HierarchicalLayout();
                hierarchicalLayout.ConnectedComponentDistance = HierarchicalLayoutSettings.Default.ConnectedComponentDistance;
                hierarchicalLayout.Direction = HierarchicalLayoutSettings.Default.Direction;
                hierarchicalLayout.LayerDistance = HierarchicalLayoutSettings.Default.LayerDistance;
                hierarchicalLayout.ObjectDistance = HierarchicalLayoutSettings.Default.ObjectDistance;
                hierarchicalLayout.RespectLayer = HierarchicalLayoutSettings.Default.RespectLayer;
                layout = hierarchicalLayout;
            }
            else if (type == typeof(ForceDirectedLayout)) {
                ForceDirectedLayout forceDirectedLayout = new ForceDirectedLayout();
                forceDirectedLayout.ConnectedComponentDistance = ForcedDirectLayoutSettings.Default.ConnectedComponentDistance;
                forceDirectedLayout.Quality = ForcedDirectLayoutSettings.Default.Quality;
                forceDirectedLayout.Tuning = ForcedDirectLayoutSettings.Default.TuningType;
                layout = forceDirectedLayout;
            }
            else if (type == typeof(CircularLayout)) {
                CircularLayout circularLayout = new CircularLayout();
                circularLayout.CircleDistance = CircularLayoutSettings.Default.CircleDistance;
                circularLayout.ConnectedComponentDistance = CircularLayoutSettings.Default.ConnectedComponentDistance;
                circularLayout.LayerDistance = CircularLayoutSettings.Default.LayerDistance;
                circularLayout.ObjectDistance = CircularLayoutSettings.Default.ObjectDistance;
                layout = circularLayout;
            }

            //
            if (layout != null) {
                // Do Layout
                layout.DoLayout(graph);

                // Apply if Layout Succeeded
                if (layout.Status == LayoutStatus.Success) {
                    // Resize Diagram
                    RectangleF rectangle = graph.TotalArea();
                    rectangle.Inflate(50, 50);
                    if (resize) {
                        this.DiagramSize = rectangle.Size.ToSize();
                    }
                    graph.ScaleToFit(this.DiagramSize);

                    // Apply Layout
                    graph.Apply(this);
                }
            }

            if (!suspend) {
                this.Resume();
                this.SuspendEvents = false;
                this.Refresh();
            }
        }