static PartialLayoutForm()
 {
     SubGraphLayouts[LayoutIncremental] = new HierarchicLayout();
     SubGraphLayouts[LayoutOrganic]     = new OrganicLayout();
     SubGraphLayouts[LayoutOrthogonal]  = new OrthogonalLayout();
     SubGraphLayouts[LayoutCircular]    = new CircularLayout();
     SubGraphLayouts[LayoutUnchanged]   = null;
 }
Exemple #2
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 #3
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);
        }
        ///<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;
        }
        /// <inheritdoc />
        protected override ILayoutAlgorithm CreateConfiguredLayout(GraphControl graphControl)
        {
            var layout        = new CircularLayout();
            var balloonLayout = layout.BalloonLayout;

            layout.LayoutStyle       = LayoutStyleItem;
            layout.EdgeRoutingPolicy = EdgeRoutingPolicyItem;
            layout.ExteriorEdgeLayoutDescriptor.CircleDistance       = CircleDistanceItem;
            layout.ExteriorEdgeLayoutDescriptor.EdgeToEdgeDistance   = EdgeToEdgeDistanceItem;
            layout.ExteriorEdgeLayoutDescriptor.PreferredAngle       = PreferredAngleItem;
            layout.ExteriorEdgeLayoutDescriptor.PreferredCurveLength = PreferredCurveLengthItem;
            layout.ExteriorEdgeLayoutDescriptor.Smoothness           = SmoothnessItem;
            layout.SubgraphLayoutEnabled = ActOnSelectionOnlyItem;
            layout.MaximumDeviationAngle = MaximumDeviationAngleItem;
            layout.FromSketchMode        = FromSketchItem;
            layout.ConsiderNodeLabels    = HandleNodeLabelsItem;

            layout.PartitionStyle = PartitionStyleItem;

            layout.SingleCycleLayout.MinimumNodeDistance = MinimumNodeDistanceItem;
            layout.SingleCycleLayout.AutomaticRadius     = ChooseRadiusAutomaticallyItem;
            layout.SingleCycleLayout.FixedRadius         = FixedRadiusItem;

            balloonLayout.PreferredChildWedge  = PreferredChildWedgeItem;
            balloonLayout.MinimumEdgeLength    = MinimumEdgeLengthItem;
            balloonLayout.CompactnessFactor    = CompactnessFactorItem;
            balloonLayout.AllowOverlaps        = AllowOverlapsItem;
            layout.PlaceChildrenOnCommonRadius = PlaceChildrenOnCommonRadiusItem;
            balloonLayout.MinimumNodeDistance  = MinimumTreeNodeDistanceItem;

            if (EdgeLabelingItem)
            {
                var genericLabeling = new GenericLabeling();
                genericLabeling.PlaceEdgeLabels = true;
                genericLabeling.PlaceNodeLabels = false;
                genericLabeling.ReduceAmbiguity = ReduceAmbiguityItem;
                layout.LabelingEnabled          = true;
                layout.Labeling = genericLabeling;
            }

            var ebc = layout.EdgeBundling;
            var bundlingDescriptor = new EdgeBundleDescriptor();

            bundlingDescriptor.Bundled  = EdgeBundlingItem;
            ebc.BundlingStrength        = EdgeBundlingStrengthItem;
            ebc.DefaultBundleDescriptor = bundlingDescriptor;

            AddPreferredPlacementDescriptor(graphControl.Graph, LabelPlacementAlongEdgeItem, LabelPlacementSideOfEdgeItem, LabelPlacementOrientationItem, LabelPlacementDistanceItem);

            return(layout);
        }
 /// <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;
 }
        ///<inheritdoc/>
        protected override void SetupHandler()
        {
            CircularLayout layout     = new CircularLayout();
            BalloonLayout  treeLayout = layout.BalloonLayout;

            OptionGroup generalGroup = Handler.AddGroup(GENERAL);
            var         styleItem    = generalGroup.AddList(LAYOUT_STYLE, globalLayoutStyles.Keys, BCC_COMPACT);

            generalGroup.AddBool(ACT_ON_SELECTION_ONLY, false);
            generalGroup.AddBool(FROM_SKETCH, false);
            generalGroup.AddBool(HANDLE_NODE_LABELS, false);

            OptionGroup cycleGroup = Handler.AddGroup(CYCLE);

            cycleGroup.AddList(PARTITION_LAYOUT_STYLE, partitionLayoutStyles.Keys, PARTITION_LAYOUTSTYLE_CYCLIC);
            IOptionItem minDistItem     = cycleGroup.AddInt(MINIMAL_NODE_DISTANCE, 30, 0, int.MaxValue);
            IOptionItem autoRadiusItem  = cycleGroup.AddBool(CHOOSE_RADIUS_AUTOMATICALLY, true);
            IOptionItem fixedRadiusItem = cycleGroup.AddInt(FIXED_RADIUS, 200, 1, int.MaxValue);

            ConstraintManager cm = new ConstraintManager(Handler);

            cm.SetEnabledOnValueEquals(autoRadiusItem, true, minDistItem);
            cm.SetEnabledOnValueEquals(autoRadiusItem, false, fixedRadiusItem);

            OptionGroup bundlingGroup    = Handler.AddGroup(EDGE_BUNDLING);
            IOptionItem bundlingEnabled  = bundlingGroup.AddBool(EDGE_BUNDLING_ENABLED, false);
            IOptionItem bundlingStrength = bundlingGroup.AddDouble(EDGE_BUNDLING_STRENGTH, 0.95, 0, 1);

            cm.SetEnabledOnValueEquals(bundlingEnabled, true, bundlingStrength);

            OptionGroup treeGroup = Handler.AddGroup(TREE);

            treeGroup.AddInt(PREFERRED_CHILD_WEDGE, treeLayout.PreferredChildWedge, 1, 360);
            treeGroup.AddInt(MINIMAL_EDGE_LENGTH, treeLayout.MinimumEdgeLength, 1, int.MaxValue);
            treeGroup.AddInt(MAXIMAL_DEVIATION_ANGLE, layout.MaximumDeviationAngle, 1, 360);
            treeGroup.AddDouble(COMPACTNESS_FACTOR, treeLayout.CompactnessFactor, 0.1, 0.9);
            treeGroup.AddInt(MINIMAL_TREE_NODE_DISTANCE, treeLayout.MinimumNodeDistance, 0, int.MaxValue);
            treeGroup.AddBool(ALLOW_OVERLAPS, treeLayout.AllowOverlaps);
            treeGroup.AddBool(PLACE_CHILDREN_ON_COMMON_RADIUS, true);

            cm.SetEnabledOnCondition(ConstraintManager.LogicalCondition.Not(cm.CreateValueEqualsCondition(styleItem, SINGLE_CYCLE)), treeGroup);
        }
Exemple #8
0
        /// <summary>
        /// Creates and configures the <see cref="CircularLayout"/> and the <see cref="CircularLayoutData"/>
        /// such that node types are considered.
        /// </summary>
        private Sample CreateCircularSample()
        {
            // create a circular layout and specify the NodeTypeAwareSequencer as sequencer responsible
            // for the ordering on the circle - this is necessary to support node types
            var layout = new CircularLayout {
                SingleCycleLayout = { NodeSequencer = new NodeTypeAwareSequencer() }
            };

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

            return(new Sample {
                Name = "Circular",
                File = "circular",
                Layout = layout,
                LayoutData = layoutData,
                IsDirected = false
            });
        }
        /// <summary>
        /// Setup default values for various configuration parameters.
        /// </summary>
        public CircularLayoutConfig()
        {
            var layout     = new CircularLayout();
            var treeLayout = layout.BalloonLayout;

            LayoutStyleItem        = LayoutStyle.BccCompact;
            ActOnSelectionOnlyItem = false;
            FromSketchItem         = false;
            HandleNodeLabelsItem   = false;

            PartitionStyleItem            = PartitionStyle.Cycle;
            MinimumNodeDistanceItem       = 30;
            ChooseRadiusAutomaticallyItem = true;
            FixedRadiusItem = 200;

            EdgeRoutingPolicyItem    = EdgeRoutingPolicy.Interior;
            CircleDistanceItem       = 20;
            EdgeToEdgeDistanceItem   = 10;
            PreferredCurveLengthItem = 20;
            PreferredAngleItem       = 10;
            SmoothnessItem           = 0.7;

            EdgeBundlingItem         = false;
            EdgeBundlingStrengthItem = 0.95;

            PreferredChildWedgeItem         = treeLayout.PreferredChildWedge;
            MinimumEdgeLengthItem           = treeLayout.MinimumEdgeLength;
            MaximumDeviationAngleItem       = layout.MaximumDeviationAngle;
            CompactnessFactorItem           = treeLayout.CompactnessFactor;
            MinimumTreeNodeDistanceItem     = treeLayout.MinimumNodeDistance;
            AllowOverlapsItem               = treeLayout.AllowOverlaps;
            PlaceChildrenOnCommonRadiusItem = true;

            EdgeLabelingItem              = false;
            LabelPlacementAlongEdgeItem   = EnumLabelPlacementAlongEdge.Centered;
            LabelPlacementSideOfEdgeItem  = EnumLabelPlacementSideOfEdge.OnEdge;
            LabelPlacementOrientationItem = EnumLabelPlacementOrientation.Horizontal;
            LabelPlacementDistanceItem    = 10;
        }
Exemple #10
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);
        }
        ///<inheritdoc/>
        protected override void ConfigureLayout()
        {
            CircularLayout layout = new CircularLayout();

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

            BalloonLayout treeLayout = layout.BalloonLayout;

            layout.LayoutStyle           = globalLayoutStyles[(string)Handler.GetValue(GENERAL, LAYOUT_STYLE)];
            layout.SubgraphLayoutEnabled = (bool)Handler.GetValue(GENERAL, ACT_ON_SELECTION_ONLY);
            layout.MaximumDeviationAngle = (int)Handler.GetValue(TREE, MAXIMAL_DEVIATION_ANGLE);
            layout.FromSketchMode        = (bool)Handler.GetValue(GENERAL, FROM_SKETCH);
            layout.ConsiderNodeLabels    = (bool)Handler.GetValue(GENERAL, HANDLE_NODE_LABELS);

            layout.PartitionStyle = partitionLayoutStyles[(string)Handler.GetValue(CYCLE, PARTITION_LAYOUT_STYLE)];

            layout.SingleCycleLayout.MinimumNodeDistance = (int)Handler.GetValue(CYCLE, MINIMAL_NODE_DISTANCE);
            layout.SingleCycleLayout.AutomaticRadius     = (bool)Handler.GetValue(CYCLE, CHOOSE_RADIUS_AUTOMATICALLY);
            layout.SingleCycleLayout.FixedRadius         = (int)Handler.GetValue(CYCLE, FIXED_RADIUS);

            treeLayout.PreferredChildWedge     = ((int)Handler.GetValue(TREE, PREFERRED_CHILD_WEDGE));
            treeLayout.MinimumEdgeLength       = (int)Handler.GetValue(TREE, MINIMAL_EDGE_LENGTH);
            treeLayout.CompactnessFactor       = (double)Handler.GetValue(TREE, COMPACTNESS_FACTOR);
            treeLayout.AllowOverlaps           = (bool)Handler.GetValue(TREE, ALLOW_OVERLAPS);
            layout.PlaceChildrenOnCommonRadius = (bool)Handler.GetValue(TREE, PLACE_CHILDREN_ON_COMMON_RADIUS);
            treeLayout.MinimumNodeDistance     = (int)Handler.GetValue(TREE, MINIMAL_TREE_NODE_DISTANCE);

            // Edge Bundling
            EdgeBundling         ebc        = layout.EdgeBundling;
            EdgeBundleDescriptor descriptor = new EdgeBundleDescriptor();

            descriptor.Bundled          = (bool)Handler.GetValue(EDGE_BUNDLING, EDGE_BUNDLING_ENABLED);
            ebc.DefaultBundleDescriptor = descriptor;
            ebc.BundlingStrength        = (double)Handler.GetValue(EDGE_BUNDLING, EDGE_BUNDLING_STRENGTH);

            LayoutAlgorithm = layout;
        }
        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 #13
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);
        }
Exemple #14
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 #15
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();
            }
        }