private void OnDisplayGraphChanged(object oldValue, object newValue) { StartTimer(); var oldSelectedVertex = SelectedVertex; // Clear selection highlights, otherwise they will not be reapplied properly after the Graph has changed UpdateSelectionHighlights(SelectedVertexControl, null); // Workaround for XamlParseException when binding directly to Graph property https://stackoverflow.com/questions/13007129/method-or-operation-not-implemented-error-on-binding var newGraph = newValue as _IDisplayGraph; IsBusy = newGraph?.VertexCount > 0; ApplyLightUpdate(newGraph); Graph = newGraph; if (oldSelectedVertex != null && VertexControls.TryGetValue(oldSelectedVertex, out var newSelectionTarget)) { SelectedVertexControl = newSelectionTarget; UpdateSelectionHighlights(null, SelectedVertexControl); } else { SelectedVertexControl = null; } #pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs - measuring low-level timing information Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)CompleteTimer); #pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs }
protected virtual void InitializePosition(TVertex vertex) { VertexControl presenter = VertexControls[vertex]; //initialize position if (Graph.ContainsVertex(vertex) && Graph.Degree(vertex) > 0) { var pos = new Point(); int count = 0; foreach (var neighbour in Graph.GetNeighbours(vertex)) { VertexControl neighbourControl; if (VertexControls.TryGetValue(neighbour, out neighbourControl)) { double x = GetX(neighbourControl); double y = GetY(neighbourControl); pos.X += double.IsNaN(x) ? 0.0 : x; pos.Y += double.IsNaN(y) ? 0.0 : y; count++; } } if (count > 0) { pos.X /= count; pos.Y /= count; SetX(presenter, pos.X); SetY(presenter, pos.Y); } } }
public VertexControl GetVertexControl(TVertex vertex) { VertexControl vc; VertexControls.TryGetValue(vertex, out vc); return(vc); }
protected virtual void RemoveVertexControl(Vertex vertex) { var vc = VertexControls[vertex]; VertexControls.Remove(vertex); InternalChildren.Remove(vc); }
private void OnMutableGraphVertexRemoved(TVertex vertex) { if (VertexControls.ContainsKey(vertex)) { _verticesRemoved.Enqueue(vertex); DoNotificationLayout(); } }
protected VertexControl GetOrCreateVertexControl(TVertex vertex) { if (!VertexControls.ContainsKey(vertex)) { CreateVertexControl(vertex); } return(VertexControls[vertex]); }
public void RemoveSemiHighlightFromVertex(TVertex vertex) { _semiHighlightedVertices.Remove(vertex); VertexControl vc; if (VertexControls.TryGetValue(vertex, out vc)) { GraphElementBehavior.SetIsSemiHighlighted(vc, false); GraphElementBehavior.SetSemiHighlightInfo(vc, null); } }
public void HighlightVertex(TVertex vertex, object highlightInfo) { _highlightedVertices[vertex] = highlightInfo; VertexControl vc; if (VertexControls.TryGetValue(vertex, out vc)) { GraphElementBehaviour.SetIsHighlighted(vc, true); GraphElementBehaviour.SetHighlightInfo(vc, highlightInfo); } }
public void SemiHighlightVertex(TVertex vertex, object semiHighlightInfo) { _semiHighlightedVertices[vertex] = semiHighlightInfo; VertexControl vc; if (VertexControls.TryGetValue(vertex, out vc)) { GraphElementBehavior.SetIsSemiHighlighted(vc, true); GraphElementBehavior.SetSemiHighlightInfo(vc, semiHighlightInfo); } }
protected void RemoveAllGraphElement() { foreach (var vertex in VertexControls.Keys.ToArray()) { RemoveVertexControl(vertex); } foreach (var edge in EdgeControls.Keys.ToArray()) { RemoveEdgeControl(edge); } VertexControls.Clear(); EdgeControls.Clear(); }
protected virtual void CreateVertexControl(Vertex vertex) { var vertexControl = new VertexControl { Vertex = vertex, DataContext = vertex, RootHyperGraphCanvas = this }; if (VertexControls.TryAdd(vertex, vertexControl) is false) { VertexControls[vertex] = vertexControl; } // Children.Add(vertexControl); InternalChildren.Add(vertexControl); vertexControl.InvalidateMeasure(); }
protected void RecreateGraphElements(bool keepControls) { if (Graph is null) { RemoveAllGraphElements(); } else { if (keepControls) { foreach (var(edge, _) in HyperEdgeControls .Where(pair => !Graph.HyperEdges.Contains(pair.Key))) { RemoveEdgeControl(edge); } foreach (var(vertex, _) in VertexControls .Where(pair => !Graph.Vertices.Contains(pair.Key))) { RemoveVertexControl(vertex); } } else { RemoveAllGraphElements(); } foreach (var vertex in Graph.Vertices.Where(vertex => !VertexControls.ContainsKey(vertex))) { CreateVertexControl(vertex); } foreach (var edge in Graph.HyperEdges.Where(edge => !HyperEdgeControls.ContainsKey(edge))) { CreateHyperEdgeControl(edge); } } CachedActualVertexSizes = null; }
protected virtual void InitializePosition(Vertex vertex) { var vertexControl = VertexControls[vertex]; if (Graph.Vertices.Contains(vertex) is false || vertex.HyperEdges.Count == 0) { return; } var pos = new Point(); var count = 0; foreach (var neighbour in vertex.GetNeighbours()) { if (neighbour is null) { continue; } if (VertexControls.TryGetValue(neighbour, out var neighbourControl)) { var x = GetX(neighbourControl); var y = GetY(neighbourControl); pos.X += double.IsNaN(x) ? 0.0 : x; pos.Y += double.IsNaN(y) ? 0.0 : y; count++; } } if (count == 0) { return; } pos.X /= count; pos.Y /= count; SetX(vertexControl, pos.X); SetY(vertexControl, pos.Y); }
/// <summary> /// If the graph has been changed, the elements will be regenerated. /// </summary> protected void RecreateGraphElements(bool tryKeepControls) { if (Graph == null) { RemoveAllGraphElement(); } else { if (tryKeepControls && !IsCompoundMode) { //remove the old graph elements foreach (var kvp in EdgeControls.ToList()) { bool remove = false; try { remove = !Graph.ContainsEdge(kvp.Key.Source, kvp.Key.Target) || !Graph.ContainsEdge(kvp.Key); } catch { } if (remove) { RemoveEdgeControl(kvp.Key); } } foreach (var kvp in VertexControls.ToList()) { if (!Graph.ContainsVertex(kvp.Key)) { RemoveVertexControl(kvp.Key); } } } else { RemoveAllGraphElement(); } // // Presenters for vertices // foreach (var vertex in Graph.Vertices) { if (!VertexControls.ContainsKey(vertex)) { CreateVertexControl(vertex); } } // // Presenters for edges // foreach (var edge in Graph.Edges) { if (!EdgeControls.ContainsKey(edge)) { CreateEdgeControl(edge); } } // // subscribe to events of the Graph mutations // if (!IsCompoundMode) { var mutableGraph = Graph as IMutableBidirectionalGraph <TVertex, TEdge>; if (mutableGraph != null) { mutableGraph.VertexAdded += OnMutableGraphVertexAdded; mutableGraph.VertexRemoved += OnMutableGraphVertexRemoved; mutableGraph.EdgeAdded += OnMutableGraphEdgeAdded; mutableGraph.EdgeRemoved += OnMutableGraphEdgeRemoved; } } } Sizes = null; }
public VertexControl?GetVertexControl(Vertex vertex) { VertexControls.TryGetValue(vertex, out var vc); return(vc); }
protected virtual void RemoveVertexControl(TVertex vertex) { RunDestructionTransition(VertexControls[vertex], false); VertexControls.Remove(vertex); }
private IDictionary <Vertex, Point> GetRelativeVertexPositions() => VertexControls.ToDictionary( pair => pair.Key, pair => GetRelativePosition(pair.Value));
private void OnSelectedVertexChanged(DisplayNode?oldValue, DisplayNode?newValue) { SelectedVertexControl = newValue != null?VertexControls.GetOrDefault(newValue) : null; }