/// <summary> /// Creates a new instance and installs it on the given <see cref="GraphControl"/>. /// </summary> /// <param name="graphControl">The control to install the z-order support on.</param> public ZOrderSupport(GraphControl graphControl) { GraphControl = graphControl; // make this ZOrderSupport available via lookup of the view graph and master graph AddZOrderSupportLookup(graphControl.Graph, this); FoldingView = graphControl.Graph.GetFoldingView(); MasterGraph = FoldingView.Manager.MasterGraph; MasterGroupingSupport = MasterGraph.GetGroupingSupport(); AddZOrderSupportLookup(MasterGraph, this); // use this ZOrderSupport as node comparer for the visualization graphControl.GraphModelManager = new ZOrderGraphModelManager(graphControl, this); // keep labels at their owners for this demo graphControl.GraphModelManager.LabelLayerPolicy = LabelLayerPolicy.AtOwner; // set a custom GraphMLIOHandler that supports writing and parsing node z-orders to/from GraphML graphControl.GraphMLIOHandler = new ZOrderGraphMLIOHandler(); // use a custom edit mode to keep z-order consistent during grouping/folding/reparenting gestures graphControl.InputMode = new ZOrderGraphEditorInputMode(this); graphControl.Graph.GetDecorator().NodeDecorator.PositionHandlerDecorator.SetFactory(node => new ZOrderNodePositionHandler(node)); // use a custom clipboard that transfers the relative z-order of copied/cut nodes graphControl.Clipboard = new ZOrderGraphClipboard(this); // listen for new nodes to assign an initial z-order MasterGraph.NodeCreated += OnNodeCreated; AddZOrderForNewNodes = true; }
public LayoutGraphPanel(LayoutGraph graph) { if (!GroupingSupport.IsFlat(graph)) { grouping = new GroupingSupport(graph); } this.BackColor = Color.White; this.BorderStyle = BorderStyle.Fixed3D; this.AutoScroll = true; global::yWorks.Algorithms.Geometry.Rectangle2D rect = LayoutGraphUtilities.GetBoundingBox(graph, graph.GetNodeCursor(), graph.GetEdgeCursor()); this.HScroll = true; this.VScroll = true; this.layoutGraph = graph; this.edgePen = new Pen(Brushes.Black, 1); this.nodeBorderPen = new Pen(Brushes.DarkGray, 1); this.labelBorderPen = new Pen(Brushes.Red, 1); this.nodeFillBrush = new SolidBrush(nodeFillColor); this.labelBrush = Brushes.Black; this.labelFont = new Font("sansserif", 6); this.MouseDown += new MouseEventHandler(LayoutGraphPanel_MouseDown); SetWorldRect(rect.X - insets, rect.Y - insets, rect.Width + insets * 2, rect.Height + insets * 2); }
public GraphCanvas(LayoutGraph graph) { this.RenderTransform = new TranslateTransform(_padding, _padding); var grouping = new GroupingSupport(graph); // Add all edges foreach (var edge in graph.Edges) { IEdgeLayout el = graph.GetLayout(edge); var l = new Polyline(); l.Stroke = Brushes.Black; l.Points.Add(new Point(graph.GetSourcePointAbs(edge).X, graph.GetSourcePointAbs(edge).Y)); for (int i = 0; i < el.PointCount(); i++) { Point p = new Point(el.GetPoint(i).X, el.GetPoint(i).Y); l.Points.Add(p); } l.Points.Add(new Point(graph.GetTargetPointAbs(edge).X, graph.GetTargetPointAbs(edge).Y)); this.Children.Add(l); // edge labels var edgeLabelLayout = graph.GetLabelLayout(edge); foreach (var labelLayout in edgeLabelLayout) { var orientedRectangle = labelLayout.LabelModel.GetLabelPlacement( labelLayout.BoundingBox, graph.GetLayout(edge), graph.GetLayout(edge.Source), graph.GetLayout(edge.Target), labelLayout.ModelParameter); this.Children.Add(GetPolygon(orientedRectangle)); } } // add all nodes foreach (var node in graph.Nodes) { INodeLayout nl = graph.GetLayout(node); Color color = grouping.IsGroupNode(node) ? Color.FromArgb(60, 255, 60, 0) : Color.FromArgb(255, 255, 255, 0); var rect = new Rectangle(); this.Children.Add(rect); rect.Stroke = new SolidColorBrush() { Color = Colors.Black }; rect.Fill = new SolidColorBrush() { Color = color }; rect.Width = nl.Width; rect.Height = nl.Height; Canvas.SetTop(rect, nl.Y); Canvas.SetLeft(rect, nl.X); // display the node index var text = new TextBlock() { Text = String.Empty + node.Index, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; this.Children.Add(text); text.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Canvas.SetTop(text, nl.Y + nl.Height / 2 - text.DesiredSize.Height / 2); Canvas.SetLeft(text, nl.X + nl.Width / 2 - text.DesiredSize.Width / 2); } }