コード例 #1
0
        public void RemoveVertex(LayoutVertexBase vertex)
        {
            var layerIndex = GetLayerIndex(vertex);

            _layers[layerIndex].Remove(vertex);
            _vertexToLayerIndexMap.Remove(vertex);
        }
コード例 #2
0
 private void RemoveFromLayers(LayoutVertexBase vertex)
 {
     if (ProperLayoutGraph.ContainsVertex(vertex))
     {
         _layers.RemoveVertex(vertex);
     }
 }
コード例 #3
0
        public void AddVertex(LayoutVertexBase vertex, RelativeLocation targetLocation)
        {
            var layer = EnsureLayerExists(targetLocation.LayerIndex);

            _vertexToLayerIndexMap.Set(vertex, targetLocation.LayerIndex);

            layer.Add(vertex, targetLocation.IndexInLayer);
        }
コード例 #4
0
        private int CalculateInsertionIndexBasedOnSiblings(LayoutVertexBase vertex,
                                                           LayoutVertexBase[] siblingsInLayer, IReadOnlyLayoutVertexLayers layers)
        {
            var followingSiblingInLayer = siblingsInLayer.FirstOrDefault(i => Precedes(vertex, i));

            return(followingSiblingInLayer != null
                ? layers.GetIndexInLayer(followingSiblingInLayer)
                : layers.GetIndexInLayer(siblingsInLayer.Last()) + 1);
        }
コード例 #5
0
        private void RemoveGap(LayoutVertexBase vertex, double layerRight)
        {
            var gap = Left(vertex) - _horizontalGap - layerRight;

            if (gap > 0)
            {
                ShiftLeftNeighbors(vertex, gap);
            }
        }
コード例 #6
0
        private void RemoveOverlap(LayoutVertexBase vertex, double layerRight)
        {
            var overlap = layerRight + _horizontalGap - Left(vertex);

            if (overlap > 0)
            {
                ShiftWithRightNeighborsRecursive(vertex, overlap);
            }
        }
コード例 #7
0
        private void ShiftLeftNeighbors(LayoutVertexBase vertex, double shiftBy)
        {
            var layer        = Layers.GetLayer(vertex);
            var indexInLayer = layer.IndexOf(vertex);

            var affectedVertices = layer.Take(indexInLayer).Reverse()
                                   .TakeWhile(i => !ProperLayoutGraph.HasPrimaryChildren(i)).ToArray();

            affectedVertices.ForEach(i => _vertexCenterXPositions[i] += shiftBy);
        }
コード例 #8
0
        private void SetLocation(LayoutVertexBase vertex)
        {
            if (!ProperLayoutGraph.ContainsVertex(vertex))
            {
                return;
            }

            var targetLocation = _locationCalculator.GetTargetLocation(vertex);

            _layers.AddVertex(vertex, targetLocation);
        }
コード例 #9
0
        private GeneralLayoutEdge[] SplitEdge(GeneralLayoutEdge edgeToSplit, LayoutVertexBase interimVertex)
        {
            var newEdge1 = new GeneralLayoutEdge(edgeToSplit.Source, interimVertex, edgeToSplit.DiagramConnector);
            var newEdge2 = new GeneralLayoutEdge(interimVertex, edgeToSplit.Target, edgeToSplit.DiagramConnector);

            _properGraph.RemoveEdge(edgeToSplit);
            _properGraph.AddVertex(interimVertex);
            _properGraph.AddEdge(newEdge1);
            _properGraph.AddEdge(newEdge2);

            return(new[] { newEdge1, newEdge2 });
        }
コード例 #10
0
        private RelativeLocation GetTargetLocation(LayoutVertexBase vertex, IReadOnlyLayoutVertexLayers layers)
        {
            if (layers.HasLocation(vertex))
            {
                throw new InvalidOperationException($"Vertex {vertex} already has a relative location.");
            }

            var toLayerIndex   = _properLayoutGraph.GetLayerIndex(vertex);
            var toIndexInLayer = DetermineIndexInLayer(vertex, toLayerIndex, layers);

            return(new RelativeLocation(toLayerIndex, toIndexInLayer));
        }
コード例 #11
0
        private void ShiftWithRightNeighborsRecursive(LayoutVertexBase vertex, double shiftBy)
        {
            var layer        = Layers.GetLayer(vertex);
            var indexInLayer = layer.IndexOf(vertex);

            var affectedVertices = layer.Skip(indexInLayer).Where(_vertexCenterXPositions.ContainsKey).ToArray();

            affectedVertices.ForEach(i => _vertexCenterXPositions[i] += shiftBy);

            var nextLayerChildren = affectedVertices.SelectMany(ProperLayoutGraph.GetPrimaryChildren).ToArray();

            if (nextLayerChildren.Any())
            {
                ShiftWithRightNeighborsRecursive(nextLayerChildren.MinBy(Left).First(), shiftBy);
            }
        }
コード例 #12
0
        private int CalculateInsertionIndexBasedOnParent(int targetLayer, LayoutVertexBase parentVertex,
                                                         IReadOnlyLayoutVertexLayers layers)
        {
            var parentLayer        = layers.GetLayer(parentVertex);
            var parentIndexInLayer = layers.GetIndexInLayer(parentVertex);

            var followingParent = GetFollowingParent(parentLayer, parentIndexInLayer, layers);

            if (followingParent == null)
            {
                return(layers.GetLayer(targetLayer).Count);
            }

            var firstChildOfFollowingParent = _properLayoutGraph.GetPrimaryChildren(followingParent)
                                              .Where(layers.HasLocation).OrderBy(layers.GetIndexInLayer).First();

            return(layers.GetIndexInLayer(firstChildOfFollowingParent));
        }
コード例 #13
0
        private int DetermineIndexInLayer(LayoutVertexBase vertex, int layerIndex, IReadOnlyLayoutVertexLayers layers)
        {
            var layer = layers.GetLayer(layerIndex);

            var parentVertex = _properLayoutGraph.GetPrimaryParent(vertex);

            if (parentVertex == null)
            {
                return(layer.Count);
            }

            var siblingsInLayer = GetPrimarySiblingsInLayer(vertex, layerIndex, layers)
                                  .OrderBy(layer.IndexOf).ToArray();

            if (siblingsInLayer.Any())
            {
                return(CalculateInsertionIndexBasedOnSiblings(vertex, siblingsInLayer, layers));
            }

            return(CalculateInsertionIndexBasedOnParent(layerIndex, parentVertex, layers));
        }
コード例 #14
0
 public int GetIndexInLayer(LayoutVertexBase vertex)
 {
     return(GetLayer(vertex).IndexOf(vertex));
 }
コード例 #15
0
 public bool HasLocation(LayoutVertexBase vertex)
 {
     return(_vertexToLayerIndexMap.Contains(vertex));
 }
コード例 #16
0
 public RelativeLocation GetTargetLocation(LayoutVertexBase vertex)
 {
     return(GetTargetLocation(vertex, _layoutVertexLayers));
 }
コード例 #17
0
 public void Add(LayoutVertexBase vertex, int index)
 {
     _items.Insert(index, vertex);
 }
コード例 #18
0
 private bool Precedes(LayoutVertexBase vertex1, LayoutVertexBase vertex2)
 {
     return(_siblingsComparer.Compare(vertex1, vertex2) < 0);
 }
コード例 #19
0
 public RelativeLocation GetLocation(LayoutVertexBase vertex)
 {
     return(new RelativeLocation(GetLayerIndex(vertex), GetIndexInLayer(vertex)));
 }
コード例 #20
0
        public IReadOnlyLayoutVertexLayer GetLayer(LayoutVertexBase vertex)
        {
            var layerIndex = GetLayerIndex(vertex);

            return(Layers.ElementAt(layerIndex));
        }
コード例 #21
0
 public void Remove(LayoutVertexBase vertex)
 {
     _items.Remove(vertex);
 }
コード例 #22
0
 public int GetLayerIndex(LayoutVertexBase vertex)
 {
     return(_vertexToLayerIndexMap.Get(vertex));
 }
コード例 #23
0
 private IEnumerable <LayoutVertexBase> GetPrimarySiblingsInLayer(
     LayoutVertexBase vertex, int layerIndex, IReadOnlyLayoutVertexLayers layers)
 {
     return(_properLayoutGraph.GetPrimarySiblings(vertex)
            .Where(i => layers.HasLocation(i) && layers.GetLayerIndex(i) == layerIndex));
 }
コード例 #24
0
 protected GeneralLayoutEdge CreateLayoutEdge(LayoutVertexBase source, LayoutVertexBase target)
 {
     return(new GeneralLayoutEdge(source, target, null));
 }
コード例 #25
0
 public int IndexOf(LayoutVertexBase vertex) => Items.IndexOf(vertex);
コード例 #26
0
 private double Left(LayoutVertexBase vertex)
 {
     return(_vertexCenterXPositions[vertex] - vertex.Width / 2);
 }
コード例 #27
0
 private void AssertLocation(LayoutVertexBase vertex, RelativeLocation to)
 {
     Layers.GetLocation(vertex).Should().Be(to);
 }