public void RemoveVertex(LayoutVertexBase vertex) { var layerIndex = GetLayerIndex(vertex); _layers[layerIndex].Remove(vertex); _vertexToLayerIndexMap.Remove(vertex); }
private void RemoveFromLayers(LayoutVertexBase vertex) { if (ProperLayoutGraph.ContainsVertex(vertex)) { _layers.RemoveVertex(vertex); } }
public void AddVertex(LayoutVertexBase vertex, RelativeLocation targetLocation) { var layer = EnsureLayerExists(targetLocation.LayerIndex); _vertexToLayerIndexMap.Set(vertex, targetLocation.LayerIndex); layer.Add(vertex, targetLocation.IndexInLayer); }
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); }
private void RemoveGap(LayoutVertexBase vertex, double layerRight) { var gap = Left(vertex) - _horizontalGap - layerRight; if (gap > 0) { ShiftLeftNeighbors(vertex, gap); } }
private void RemoveOverlap(LayoutVertexBase vertex, double layerRight) { var overlap = layerRight + _horizontalGap - Left(vertex); if (overlap > 0) { ShiftWithRightNeighborsRecursive(vertex, overlap); } }
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); }
private void SetLocation(LayoutVertexBase vertex) { if (!ProperLayoutGraph.ContainsVertex(vertex)) { return; } var targetLocation = _locationCalculator.GetTargetLocation(vertex); _layers.AddVertex(vertex, targetLocation); }
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 }); }
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)); }
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); } }
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)); }
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)); }
public int GetIndexInLayer(LayoutVertexBase vertex) { return(GetLayer(vertex).IndexOf(vertex)); }
public bool HasLocation(LayoutVertexBase vertex) { return(_vertexToLayerIndexMap.Contains(vertex)); }
public RelativeLocation GetTargetLocation(LayoutVertexBase vertex) { return(GetTargetLocation(vertex, _layoutVertexLayers)); }
public void Add(LayoutVertexBase vertex, int index) { _items.Insert(index, vertex); }
private bool Precedes(LayoutVertexBase vertex1, LayoutVertexBase vertex2) { return(_siblingsComparer.Compare(vertex1, vertex2) < 0); }
public RelativeLocation GetLocation(LayoutVertexBase vertex) { return(new RelativeLocation(GetLayerIndex(vertex), GetIndexInLayer(vertex))); }
public IReadOnlyLayoutVertexLayer GetLayer(LayoutVertexBase vertex) { var layerIndex = GetLayerIndex(vertex); return(Layers.ElementAt(layerIndex)); }
public void Remove(LayoutVertexBase vertex) { _items.Remove(vertex); }
public int GetLayerIndex(LayoutVertexBase vertex) { return(_vertexToLayerIndexMap.Get(vertex)); }
private IEnumerable <LayoutVertexBase> GetPrimarySiblingsInLayer( LayoutVertexBase vertex, int layerIndex, IReadOnlyLayoutVertexLayers layers) { return(_properLayoutGraph.GetPrimarySiblings(vertex) .Where(i => layers.HasLocation(i) && layers.GetLayerIndex(i) == layerIndex)); }
protected GeneralLayoutEdge CreateLayoutEdge(LayoutVertexBase source, LayoutVertexBase target) { return(new GeneralLayoutEdge(source, target, null)); }
public int IndexOf(LayoutVertexBase vertex) => Items.IndexOf(vertex);
private double Left(LayoutVertexBase vertex) { return(_vertexCenterXPositions[vertex] - vertex.Width / 2); }
private void AssertLocation(LayoutVertexBase vertex, RelativeLocation to) { Layers.GetLocation(vertex).Should().Be(to); }