/// <summary> /// Removes all edges that are incident to group nodes and passes it to the core layout algorithm. /// </summary> /// <remarks> /// This stage removes some edges from the graph such that no edges incident to group nodes /// exist. Then, it applies the core layout algorithm to the reduced graph. /// After it produces the result, it re-inserts the previously removed edges and routes them. /// </remarks> public override void ApplyLayout(LayoutGraph graph) { var groupingSupport = new yWorks.Layout.Grouping.GroupingSupport(graph); if (!GroupingSupport.IsGrouped(graph)) { ApplyLayoutCore(graph); } else { var hiddenEdgesMap = Maps.CreateHashedEdgeMap(); var edgeHider = new LayoutGraphHider(graph); var existHiddenEdges = false; foreach (var edge in graph.Edges) { if (groupingSupport.IsGroupNode(edge.Source) || groupingSupport.IsGroupNode(edge.Target)) { hiddenEdgesMap.Set(edge, true); edgeHider.Hide(edge); existHiddenEdges = true; } else { hiddenEdgesMap.Set(edge, false); } } ApplyLayoutCore(graph); if (existHiddenEdges) { edgeHider.UnhideAll(); // routes the marked edges RouteMarkedEdges(graph, hiddenEdgesMap); if (ConsiderEdgeLabels) { // all labels of hidden edges should be marked var affectedLabelsDpKey = "affectedLabelsDpKey"; var nonTreeLabelsMap = Maps.CreateHashedDataMap(); foreach (var edge in graph.Edges) { var ell = graph.GetLabelLayout(edge); foreach (var labelLayout in ell) { nonTreeLabelsMap.Set(labelLayout, hiddenEdgesMap.Get(edge)); } } // add selection marker graph.AddDataProvider(affectedLabelsDpKey, nonTreeLabelsMap); // place marked labels var labeling = new GenericLabeling { PlaceNodeLabels = false, PlaceEdgeLabels = true, AffectedLabelsDpKey = affectedLabelsDpKey, }; labeling.ApplyLayout(graph); // dispose selection key graph.RemoveDataProvider(affectedLabelsDpKey); } } } }
public override bool GetBool(object dataHolder) { if (dataHolder is INodeLabelLayout) { var node = layoutGraph.GetOwner((INodeLabelLayout)dataHolder); if (layoutGraph is CopiedLayoutGraph) { bool[] selectedLabels = selectedLabelsAtItemProvider.Get(node) as bool[]; if (selectedLabels != null) { var nodeLabelLayouts = layoutGraph.GetLabelLayout(node); for (int i = 0; i < nodeLabelLayouts.Length; i++) { var nodeLabelLayout = nodeLabelLayouts[i]; if (nodeLabelLayout == dataHolder && selectedLabels.Length > i) { return(selectedLabels[i]); } } } } } else if (dataHolder is IEdgeLabelLayout) { var edge = layoutGraph.GetOwner((IEdgeLabelLayout)dataHolder); if (layoutGraph is CopiedLayoutGraph) { bool[] selectedLabels = selectedLabelsAtItemProvider.Get(edge) as bool[]; if (selectedLabels != null) { var edgeLabelLayouts = layoutGraph.GetLabelLayout(edge); for (int i = 0; i < edgeLabelLayouts.Length; i++) { var edgeLabelLayout = edgeLabelLayouts[i]; if (edgeLabelLayout == dataHolder && selectedLabels.Length > i) { return(selectedLabels[i]); } } } } } return(false); }
/// <summary> /// Copy all labels of the given edge. /// </summary> private void CopyEdgeLabels(LayoutGraph pageLayoutGraph, IGraph pageView, Edge layoutEdge, IEdge copiedEdge, IEdge modelEdge, ILabelDefaults labelDefaults) { IEdgeLabelLayout[] edgeLabels = pageLayoutGraph.GetLabelLayout(layoutEdge); for (int i = 0; i < edgeLabels.Length; i++) { // get the label layout from the layout graph IEdgeLabelLayout edgeLabelLayout = edgeLabels[i]; // get the original label from the model graph ILabel edgeModelLabel = modelEdge.Labels[i]; CopyEdgeLabel(pageView, edgeLabelLayout, edgeModelLabel, copiedEdge, labelDefaults); } }
/// <summary> /// Copy all labels of the given node. /// </summary> private void CopyNodeLabels(LayoutGraph pageLayoutGraph, IGraph pageView, Node layoutNode, INode copiedNode, INode modelNode) { INodeLabelLayout[] nodeLabels = pageLayoutGraph.GetLabelLayout(layoutNode); // for each label for (int i = 0; i < nodeLabels.Length; i++) { // get the layout from the layout graph INodeLabelLayout nodeLabelLayout = nodeLabels[i]; // get the original label from the model graph ILabel nodeModelLabel = modelNode.Labels[i]; CopyNodeLabel(pageView, nodeLabelLayout, nodeModelLabel, layoutNode, copiedNode); } }
public void PaintGraph(Graphics g) { if (this.grouping != null) { for (ListCell cell = this.grouping.GetChildren(this.grouping.Root).FirstCell; cell != null; cell = cell.Succ()) { Node node = (Node)cell.Info; PaintNodeAndChildren(g, layoutGraph, node); } } else { foreach (Node node in layoutGraph.Nodes) { PaintNode(g, layoutGraph, node); INodeLabelLayout[] labels = layoutGraph.GetLabelLayout(node); if (labels != null && labels.Length > 0) { foreach (INodeLabelLayout label in labels) { PaintNodeLabel(g, layoutGraph, node, label); } } } } foreach (Edge edge in layoutGraph.Edges) { PaintEdge(g, layoutGraph, edge); IEdgeLabelLayout[] labels = layoutGraph.GetLabelLayout(edge); if (labels != null && labels.Length > 0) { foreach (IEdgeLabelLayout label in labels) { PaintEdgeLabel(g, layoutGraph, edge, label); } } } }
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); } }