예제 #1
0
        private void InitializeDecoration()
        {
            nodeDecorationInstaller = new NodeStyleDecorationInstaller
            {
                NodeStyle = new ShapeNodeStyle {
                    Shape = ShapeNodeShape.Rectangle, Pen = Pens.DeepSkyBlue, Brush = Brushes.Transparent
                },
                Margins = new InsetsD(10.0)
            };
            edgeDecorationInstaller = new EdgeStyleDecorationInstaller
            {
                EdgeStyle = new PolylineEdgeStyle {
                    Pen = new Pen(Brushes.DeepSkyBlue, 3)
                }
            };
            labelDecorationInstaller = new LabelStyleDecorationInstaller
            {
                LabelStyle = new NodeStyleLabelStyleAdapter(
                    new ShapeNodeStyle {
                    Shape = ShapeNodeShape.RoundRectangle, Pen = Pens.DeepSkyBlue, Brush = Brushes.Transparent
                },
                    VoidLabelStyle.Instance),
                Margins = new InsetsD(5.0)
            };

            styleDecorationZoomPolicies = new[]
            {
                StyleDecorationZoomPolicy.Mixed,
                StyleDecorationZoomPolicy.WorldCoordinates,
                StyleDecorationZoomPolicy.ViewCoordinates
            };
            zoomModeComboBox.ComboBox.DataSource = styleDecorationZoomPolicies;
            zoomModeComboBox.SelectedIndex       = 0;
        }
        private void InitializeGraph()
        {
            var graph = graphControl.Graph;

            // Enable undo support
            graph.SetUndoEngineEnabled(true);

            // set some nice defaults
            // use a node style renderer which highlights the node based on its tag.
            graph.NodeDefaults.Style = new ShapeNodeStyle(new AnalysisShapeNodeStyleRenderer())
            {
                Shape = ShapeNodeShape.Ellipse
            };
            // use an ede style renderer which highlights the edge based on its tag.
            graph.EdgeDefaults.Style = new PolylineEdgeStyle(new AnalysisPolylineEdgeStyleRenderer());

            // use a special decorator for selection
            var selectionInstaller = new NodeStyleDecorationInstaller {
                NodeStyle = new ShapeNodeStyle
                {
                    Shape = ShapeNodeShape.Ellipse, Pen = (Pen) new Pen(Brushes.Gray, 5).GetAsFrozen(), Brush = null
                }
            };

            // use a special decorator for focus
            var focusIndicatorInstaller = new NodeStyleDecorationInstaller {
                NodeStyle = new ShapeNodeStyle {
                    Shape = ShapeNodeShape.Ellipse,
                    Pen   = (Pen) new Pen(Brushes.LightGray, 3)
                    {
                        DashStyle = DashStyles.Dash
                    }.GetAsFrozen(),
                Brush = null
                }
            };
            var decorator = graph.GetDecorator();

            decorator.NodeDecorator.SelectionDecorator.SetImplementation(selectionInstaller);
            decorator.NodeDecorator.FocusIndicatorDecorator.SetImplementation(focusIndicatorInstaller);

            graph.EdgeDefaults.Labels.LayoutParameter = FreeEdgeLabelModel.Instance.CreateDefaultParameter();

            graph.EdgeDefaults.Labels.Style = new DefaultLabelStyle {
                TextSize        = 10,
                BackgroundBrush = Brushes.AliceBlue,
                BackgroundPen   = (Pen) new Pen(Brushes.LightSkyBlue, 2).GetAsFrozen(),
                AutoFlip        = false
            };
        }
        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);
        }