コード例 #1
0
        private void CreateSampleGraph()
        {
            INodeStyle nodeStyle = new ShapeNodeStyle
            {
                Shape = ShapeNodeShape.RoundRectangle,
                Pen   = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0x24, 0x9A, 0xE7)), 1),
                Brush = new LinearGradientBrush(Color.FromArgb(0xFF, 0xCC, 0xFF, 0xFF), Color.FromArgb(0xFF, 0x24, 0x9A, 0xE7), 90.0)
            };

            var node1  = CreateNode(new PointD(0, 0), new NodeStyleDecorator(nodeStyle, "Resources/internet.png"), "Root");
            var node2  = CreateNode(new PointD(120, -50), new NodeStyleDecorator(nodeStyle, "Resources/switch.png"), "Switch");
            var node3  = CreateNode(new PointD(-130, 60), new NodeStyleDecorator(nodeStyle, "Resources/switch.png"), "Switch");
            var node4  = CreateNode(new PointD(95, -180), new NodeStyleDecorator(nodeStyle, "Resources/scanner.png"), "Scanner");
            var node5  = CreateNode(new PointD(240, -110), new NodeStyleDecorator(nodeStyle, "Resources/printer.png"), "Printer");
            var node6  = CreateNode(new PointD(200, 50), new NodeStyleDecorator(nodeStyle, "Resources/computer.png"), "Workstation");
            var node7  = CreateNode(new PointD(-160, -60), new NodeStyleDecorator(nodeStyle, "Resources/printer.png"), "Printer");
            var node8  = CreateNode(new PointD(-260, 40), new NodeStyleDecorator(nodeStyle, "Resources/scanner.png"), "Scanner");
            var node9  = CreateNode(new PointD(-200, 170), new NodeStyleDecorator(nodeStyle, "Resources/computer.png"), "Workstation");
            var node10 = CreateNode(new PointD(-50, 160), new NodeStyleDecorator(nodeStyle, "Resources/computer.png"), "Workstation");

            Graph.CreateEdge(node1, node2, Graph.EdgeDefaults.Style, TrafficLoad.VeryHigh);
            Graph.CreateEdge(node1, node3, Graph.EdgeDefaults.Style, TrafficLoad.High);
            Graph.CreateEdge(node2, node4, Graph.EdgeDefaults.Style, TrafficLoad.High);
            Graph.CreateEdge(node2, node5, Graph.EdgeDefaults.Style, TrafficLoad.Normal);
            Graph.CreateEdge(node2, node6, Graph.EdgeDefaults.Style, TrafficLoad.High);
            Graph.CreateEdge(node3, node7, Graph.EdgeDefaults.Style, TrafficLoad.Low);
            Graph.CreateEdge(node3, node8, Graph.EdgeDefaults.Style, TrafficLoad.Low);
            Graph.CreateEdge(node3, node9, Graph.EdgeDefaults.Style, TrafficLoad.Normal);
            Graph.CreateEdge(node3, node10, Graph.EdgeDefaults.Style, TrafficLoad.Low);
        }
 public FlowChartNodeStyle()
 {
     NodeStyle = new ShapeNodeStyle
     {
         Brush = new LinearGradientBrush(new PointF(0, 0), new PointF(1, 1), Color.FromArgb(255, 221, 136), Color.FromArgb(255, 153, 0)),
         Pen   = new Pen(new SolidBrush(Color.FromArgb(255, 153, 0)))
     };
     PortStyle = new CirclePortStyle();
 }
コード例 #3
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            IGraph graph = graphControl.Graph;

            // initialize graph defaults
            var adaptedStyle = new ShapeNodeStyle {
                Brush = Brushes.Green, Pen = Pens.Transparent
            };

            graph.NodeDefaults.Ports.Style = new NodeStylePortStyleAdapter(adaptedStyle)
            {
                RenderSize = new SizeD(7, 7)
            };
            // each port needs its own style instance to have its own render size
            graph.NodeDefaults.Ports.ShareStyleInstance = false;
            // disable removing ports when all attached edges have been removed
            graph.NodeDefaults.Ports.AutoCleanUp = false;

            graph.EdgeDefaults.Style = new PolylineEdgeStyle {
                Pen = new Pen(Brushes.Black, 3)
            };

            // create a default editor input mode
            GraphEditorInputMode geim = new GraphEditorInputMode();

            // ports are preferred for clicks
            geim.ClickHitTestOrder = new [] {
                GraphItemTypes.Port,
                GraphItemTypes.PortLabel,
                GraphItemTypes.Bend,
                GraphItemTypes.EdgeLabel,
                GraphItemTypes.Edge,
                GraphItemTypes.Node,
                GraphItemTypes.NodeLabel,
            };
            // enable orthogonal edge editing
            geim.OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext();

            // PortReshapeHandlerProvider considers pressed Ctrl keys. Whenever Ctrl is pressed or released,
            // we force GraphEditorInputMode to requery the handles of selected items
            graphControl.KeyDown += UpdateHandles;
            graphControl.KeyUp   += UpdateHandles;

            // finally, set the input mode to the graph control.
            graphControl.InputMode = geim;

            // register the reshape handle provider for ports
            RegisterReshapeHandleProvider();

            // read initial graph from embedded resource
            graphControl.ImportFromGraphML("Resources\\defaultGraph.graphml");
        }
コード例 #4
0
        private void InitializeHighlightStyles()
        {
            // we want to create a non-default nice highlight styling
            // for the hover highlight, create semi transparent orange stroke first
            var orangeRed = Colors.OrangeRed;
            var orangePen = new Pen(new SolidColorBrush(Color.FromArgb(220, orangeRed.R, orangeRed.G, orangeRed.B)), 3);

            // freeze it for slightly improved performance
            orangePen.Freeze();

            // now decorate the nodes and edges with custom hover highlight styles
            var decorator = graphControl.Graph.GetDecorator();

            // nodes should be given a rectangular orange rectangle highlight shape
            var highlightShape = new ShapeNodeStyle {
                Shape = ShapeNodeShape.RoundRectangle,
                Pen   = orangePen,
                Brush = null
            };

            var nodeStyleHighlight = new NodeStyleDecorationInstaller {
                NodeStyle = highlightShape,
                // that should be slightly larger than the real node
                Margins = new InsetsD(5),
                // but have a fixed size in the view coordinates
                ZoomPolicy = StyleDecorationZoomPolicy.ViewCoordinates
            };

            // register it as the default implementation for all nodes
            decorator.NodeDecorator.HighlightDecorator.SetImplementation(nodeStyleHighlight);

            // a similar style for the edges, however cropped by the highlight's insets
            var dummyCroppingArrow = new Arrow {
                Type       = ArrowType.None,
                CropLength = 5
            };
            var edgeStyle = new PolylineEdgeStyle {
                Pen         = orangePen,
                TargetArrow = dummyCroppingArrow,
                SourceArrow = dummyCroppingArrow
            };
            var edgeStyleHighlight = new EdgeStyleDecorationInstaller {
                EdgeStyle  = edgeStyle,
                ZoomPolicy = StyleDecorationZoomPolicy.ViewCoordinates
            };

            decorator.EdgeDecorator.HighlightDecorator.SetImplementation(edgeStyleHighlight);
        }
コード例 #5
0
 public FlowChartNodeStyle()
 {
     NodeStyle = new ShapeNodeStyle()
     {
         Brush = new LinearGradientBrush
         {
             StartPoint    = new PointD(0, 0),
             EndPoint      = new PointD(1, 1),
             GradientStops = new GradientStopCollection
             {
                 new GradientStop(Color.FromRgb(255, 221, 136), 0.3),
                 new GradientStop(Color.FromRgb(255, 153, 0), 0.6)
             }
         },
         Pen = new Pen(new SolidColorBrush(Color.FromRgb(255, 153, 0)), 1),
     };
     PortStyle = new CirclePortStyle();
 }
コード例 #6
0
        /// <summary>
        /// Creates a sample graph and introduces all important graph elements present in
        /// yFiles.NET. Additionally, this method now overrides the label placement for some specific labels.
        /// </summary>
        private void PopulateGraph()
        {
            #region Sample Graph creation

            //////////// Sample node creation ///////////////////

            // Creates two nodes with the default node size
            // The location is specified for the _center_
            INode node1 = Graph.CreateNode(new PointD(50, 50));
            INode node2 = Graph.CreateNode(new PointD(150, 50));
            // Creates a third node with a different size of 80x40
            // In this case, the location of (360,380) describes the _upper left_
            // corner of the node bounds
            INode node3 = Graph.CreateNode(new RectD(360, 380, 80, 40));

            /////////////////////////////////////////////////////

            //////////// Sample edge creation ///////////////////

            // Creates some edges between the nodes
            IEdge edge1 = Graph.CreateEdge(node1, node2);
            IEdge edge2 = Graph.CreateEdge(node2, node3);

            /////////////////////////////////////////////////////

            //////////// Using Bends ////////////////////////////

            // Creates the first bend for edge2 at (400, 50)
            IBend bend1 = Graph.AddBend(edge2, new PointD(400, 50));

            /////////////////////////////////////////////////////

            //////////// Using Ports ////////////////////////////

            // Actually, edges connect "ports", not nodes directly.
            // If necessary, you can manually create ports at nodes
            // and let the edges connect to these.
            // Creates a port in the center of the node layout
            IPort port1AtNode1 = Graph.AddPort(node1, FreeNodePortLocationModel.NodeCenterAnchored);

            // Creates a port at the middle of the left border
            // Note to use absolute locations when placing ports using PointD.
            IPort port1AtNode3 = Graph.AddPort(node3, new PointD(node3.Layout.X, node3.Layout.GetCenter().Y));

            // Creates an edge that connects these specific ports
            IEdge edgeAtPorts = Graph.CreateEdge(port1AtNode1, port1AtNode3);

            /////////////////////////////////////////////////////

            //////////// Sample label creation ///////////////////

            // Adds labels to several graph elements
            Graph.AddLabel(node1, "N 1");
            Graph.AddLabel(node2, "N 2");
            Graph.AddLabel(node3, "N 3");
            var edgeLabel = Graph.AddLabel(edgeAtPorts, "Edge at Ports");

            /////////////////////////////////////////////////////
            /////////////////////////////////////////////////////

            #endregion

            ///////////////// New in this Sample /////////////////

            // Override default styles

            // Changes the style for the second node
            // Creates a new node style, this time a ShapeNodeStyle:
            ShapeNodeStyle sns = new ShapeNodeStyle {
                Shape = ShapeNodeShape.Ellipse, Pen = Pens.Black, Brush = Brushes.OrangeRed
            };

            // Sets the node's style property to the new style through its owning graph,
            // since you can't set the style property of an INode directly
            // (you'll set most other graph object properties this way as well)
            Graph.SetStyle(node2, sns);

            // Creates a different style for the label with black text and a red border
            // and intransparent white background
            DefaultLabelStyle sls = new DefaultLabelStyle {
                Font = new Font("Arial Black", 12), TextBrush = Brushes.Black
            };
            sls.BackgroundPen   = Pens.Red;
            sls.BackgroundBrush = Brushes.White;

            // And sets the style for the edge label, again through its owning graph.
            Graph.SetStyle(edgeLabel, sls);

            // Override the style for the "Edge at Ports" edge:
            // Uses a dashed red Pen with thickness 2.
            Pen defaultPen = new Pen(Brushes.Red, 2)
            {
                DashStyle = DashStyle.Dash
            };
            // Creates an edge style that will apply the new default pen
            // to the entire line using PolyLineEdgeStyle,
            // which draws a polyline determined by the edge's control points (bends)
            var edgeStyle = new PolylineEdgeStyle {
                Pen = defaultPen
            };

            // Sets the source and target arrows on the edge style instance
            // Note that IEdgeStyle itself does not have these properties
            // also note: by default the arrows have a default brush and pen
            edgeStyle.SourceArrow = Arrows.Circle;
            // set color and size to match the thick red line
            edgeStyle.TargetArrow = new Arrow(Color.Red)
            {
                Type = ArrowType.Short, Scale = 2
            };

            // Sets the style for the "Edge at Ports" edge, again through its owning graph.
            Graph.SetStyle(edge2, edgeStyle);

            //////////////////////////////////////////////////////
        }