示例#1
0
        /// <summary>
        /// Creates a new <see cref="FilteredGraphWrapper"/> that shows the currently visible original nodes.
        /// </summary>
        /// <remarks>
        /// Nodes without currently visible edges are also filtered out.
        /// </remarks>
        private FilteredGraphWrapper CreateFilteredView()
        {
            // create a new FilteredGraphWrapper that filters the original graph and shows only the currently visible nodes
            var filteredGraph = new FilteredGraphWrapper(OriginalGraph,
                                                         node => {
                node = aggregationHelper.GetPlaceholder(node);
                if (!AggregateGraph.Contains(node))
                {
                    return(false);
                }
                // also filter nodes without edges
                return(AggregateGraph.EdgesAt(node).Count(edge => !aggregationHelper.IsHierarchyEdge(edge)) > 0);
            });

            // set the node layouts for a smooth transition
            foreach (var node in filteredGraph.Nodes)
            {
                filteredGraph.SetNodeLayout(node, aggregationHelper.GetPlaceholder(node).Layout.ToRectD());
            }

            // reset any rotated labels
            foreach (var label in filteredGraph.Labels)
            {
                filteredGraph.SetLabelLayoutParameter(label, FreeNodeLabelModel.Instance.CreateDefaultParameter());
            }

            return(filteredGraph);
        }
        /// <summary>
        /// Replaces original edges adjacent to a placeholder node with aggregation edges when source and target are
        /// currently visible.
        /// </summary>
        private void ReplaceEdges(INode node)
        {
            INode originalNode;

            if (node.Tag is AggregationNodeInfo aggregationInfo)
            {
                originalNode = aggregationInfo.Aggregate.Node;
            }
            else
            {
                originalNode = node;
            }

            if (originalNode == null)
            {
                return;
            }

            foreach (var edge in AggregateGraph.WrappedGraph.EdgesAt(originalNode).ToList())
            {
                if (edge.TargetPort.Owner == originalNode)
                {
                    var sourceNode = (INode)edge.SourcePort.Owner;
                    if (AggregateGraph.Contains(sourceNode))
                    {
                        CreateReplacementEdge(sourceNode, node, edge);
                    }
                    else if (placeholderMap.TryGetValue(sourceNode, out var placeholderSource) &&
                             AggregateGraph.Contains(placeholderSource))
                    {
                        CreateReplacementEdge(placeholderSource, node, edge);
                    }
                }
                else
                {
                    var targetNode = (INode)edge.TargetPort.Owner;
                    if (AggregateGraph.Contains(targetNode))
                    {
                        CreateReplacementEdge(node, targetNode, edge);
                    }
                    else if (placeholderMap.TryGetValue(targetNode, out var placeholderTarget) &&
                             AggregateGraph.Contains(placeholderTarget))
                    {
                        CreateReplacementEdge(node, placeholderTarget, edge);
                    }
                }
            }
        }