コード例 #1
0
 /// <summary>
 /// Initializes the styles to use for the graph.
 /// </summary>
 private void InitializeStyles()
 {
     defaultNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.DarkOrange
     };
     sourceNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.LimeGreen
     };
     targetNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.OrangeRed
     };
     sourceAndTargetNodeStyle = new ShinyPlateNodeStyle
     {
         Brush = new LinearGradientBrush
         {
             GradientStops = new GradientStopCollection
             {
                 new GradientStop {
                     Color = Colors.Green, Offset = 0.49
                 },
                 new GradientStop {
                     Color = Colors.Red, Offset = 0.51
                 }
             },
             SpreadMethod = GradientSpreadMethod.Pad,
         }
     };
     defaultEdgeStyle = new PolylineEdgeStyle {
         TargetArrow = directed ? Arrows.Default : Arrows.None
     };
     pathEdgeStyle = new PolylineEdgeStyle {
         Pen = new Pen(Brushes.Red, 4.0f), TargetArrow = directed ? Arrows.Default : Arrows.None
     };
 }
コード例 #2
0
        /// <summary>
        /// Sets up default styles for graph elements.
        /// </summary>
        /// <remarks>
        /// Default styles apply only to elements created after the default style has been set,
        /// so typically, you'd set these as early as possible in your application.
        /// </remarks>
        private void SetDefaultStyles()
        {
            ///////////////// New in this Sample /////////////////

            #region Default Node Style
            // Sets the default style for nodes
            // Creates a nice ShinyPlateNodeStyle instance, using an orange Brush.
            INodeStyle defaultNodeStyle = new ShinyPlateNodeStyle {
                Brush = new SolidBrush(Color.FromArgb(255, 255, 140, 0))
            };

            // Sets this style as the default for all nodes that don't have another
            // style assigned explicitly
            Graph.NodeDefaults.Style = defaultNodeStyle;

            #endregion

            #region Default Edge Style
            // Sets the default style for edges:
            // Creates an edge style that will apply a gray pen with thickness 1
            // to the entire line using PolyLineEdgeStyle,
            // which draws a polyline determined by the edge's control points (bends)
            var defaultEdgeStyle = new PolylineEdgeStyle {
                Pen = Pens.Gray
            };

            // Sets the source and target arrows on the edge style instance
            // (Actually: no source arrow)
            // Note that IEdgeStyle itself does not have these properties
            // Also note that by default there are no arrows
            defaultEdgeStyle.TargetArrow = Arrows.Default;

            // Sets the defined edge style as the default for all edges that don't have
            // another style assigned explicitly:
            Graph.EdgeDefaults.Style = defaultEdgeStyle;
            #endregion

            #region Default Label Styles
            // Sets the default style for labels
            // Creates a label style with the label text color set to dark red
            ILabelStyle defaultLabelStyle = new DefaultLabelStyle {
                Font = new Font("Tahoma", 12), TextBrush = Brushes.DarkRed
            };

            // Sets the defined style as the default for both edge and node labels:
            Graph.EdgeDefaults.Labels.Style = Graph.NodeDefaults.Labels.Style = defaultLabelStyle;

            #endregion

            #region Default Node size
            // Sets the default size explicitly to 40x40
            Graph.NodeDefaults.Size = new SizeD(40, 40);

            #endregion

            ///////////////////////////////////////////////////
        }
コード例 #3
0
        /// <summary>
        /// Creates and configures the graph that is used for the placer configuration preview.
        /// </summary>
        private void SetupPreview()
        {
            IGraph graph = previewControl.Graph;
            DictionaryMapper <INode, bool> assistantMap =
                graph.MapperRegistry.CreateMapper <INode, bool>(AssistantNodePlacer.AssistantNodeDpKey);

            graph.NodeDefaults.Size  = new SizeD(40, 30);
            graph.NodeDefaults.Style = new ShinyPlateNodeStyle
            {
                Brush      = Brushes.LightGray,
                Insets     = new InsetsD(5),
                DrawShadow = false,
                Pen        = Pens.Black
            };
            var rootStyle = new ShinyPlateNodeStyle
            {
                Brush      = Brushes.Red,
                Insets     = new InsetsD(5),
                Pen        = Pens.Black,
                DrawShadow = false
            };
            var assistantStyle = new ShinyPlateNodeStyle
            {
                Brush  = Brushes.LightGray,
                Insets = new InsetsD(5),
                Pen    = new Pen(Brushes.Black, 1)
                {
                    DashStyle = DashStyles.Dash
                },
                DrawShadow = false
            };
            INode root = graph.CreateNode();

            graph.SetStyle(root, rootStyle);
            INode n1 = graph.CreateNode();

            graph.SetStyle(n1, assistantStyle);
            assistantMap[n1] = true;
            INode n2 = graph.CreateNode();
            INode n3 = graph.CreateNode();
            INode n4 = graph.CreateNode();
            INode n5 = graph.CreateNode(new RectD(0, 0, 60, 30));

            graph.CreateEdge(root, n1);
            graph.CreateEdge(root, n2);
            graph.CreateEdge(root, n3);
            graph.CreateEdge(root, n4);
            graph.CreateEdge(root, n5);
            previewLayout = new TreeLayout();
        }
コード例 #4
0
        ///<summary>
        /// Create a sample graph: a simple tree with SimpleNodePlacers assigned to each node.
        /// This implementation creates three layers with three children each.
        ///</summary>
        private void CreateSampleGraph(IGraph graph)
        {
            graph.Clear();
            INode root  = graph.CreateNode();
            var   style = new ShinyPlateNodeStyle {
                Brush = NodePlacerPanel.LayerBrushes[0]
            };

            graph.SetStyle(root, style);
            var placer = new DefaultNodePlacer
            {
                ChildPlacement = ChildPlacement.VerticalToRight
            };

            placers[root] = placer;
            CreateSubTree(graph, root, 1, 2);
        }
 /// <summary>
 /// Initializes the styles to use for the graph.
 /// </summary>
 private void InitializeStyles()
 {
     defaultNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.DarkOrange
     };
     sourceNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.LimeGreen
     };
     targetNodeStyle = new ShinyPlateNodeStyle {
         Brush = Brushes.OrangeRed
     };
     sourceAndTargetNodeStyle = new ShinyPlateNodeStyle {
         Brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.LimeGreen, Color.OrangeRed)
     };
     defaultEdgeStyle = new PolylineEdgeStyle {
         Pen = Pens.Black, TargetArrow = directed ? Arrows.Default : Arrows.None
     };
     pathEdgeStyle = new PolylineEdgeStyle {
         Pen = new Pen(Color.Red, 4.0f), TargetArrow = directed ? Arrows.Default : Arrows.None
     };
 }
コード例 #6
0
        /// <summary>
        /// Creates the sample graph of the given color with two nodes and a single edge.
        /// </summary>
        private static IEdge CreateSubgraph(IGraph graph, Color color, double yOffset, bool createPorts)
        {
            var brush = new SolidColorBrush(color);
            // Create two nodes
            var nodeStyle = new ShinyPlateNodeStyle {
                Brush = brush
            };
            var n1 = graph.CreateNode(new RectD(110, 100 + yOffset, 40, 40), nodeStyle, color);
            var n2 = graph.CreateNode(new RectD(450, 130 + yOffset, 40, 40), nodeStyle, color);

            // Create an edge, either between the two nodes or between the nodes's ports
            IEdge edge;

            if (!createPorts)
            {
                edge = graph.CreateEdge(n1, n2, new PolylineEdgeStyle {
                    Pen = new Pen(brush, 1)
                }, color);
            }
            else
            {
                var p1 = CreateSamplePorts(graph, n1, true);
                var p2 = CreateSamplePorts(graph, n2, false);
                edge = graph.CreateEdge(p1[1], p2[2], new PolylineEdgeStyle {
                    Pen = new Pen(brush, 1)
                }, color);
            }

            // Add bends that create a veredge.SourcePort.Locationtical segment in the middle of the edge
            var sourcePortLocation = edge.SourcePort.GetLocation();
            var targetPortLocation = edge.TargetPort.GetLocation();
            var x = (sourcePortLocation.X + targetPortLocation.X) / 2;

            graph.AddBend(edge, new PointD(x, sourcePortLocation.Y));
            graph.AddBend(edge, new PointD(x, targetPortLocation.Y));

            return(edge);
        }