public override StateController LeftMouseDownAt(Point point, int times) { var(closestEllipse, distanceEllipse) = GraphVisual.ClosestEllipseFrom(point); var(closestLine, distanceLine) = GraphVisual.ClosestLineFrom(point); var minDistance = Math.Min(distanceLine, distanceEllipse); var valueRange = new Range(GraphVisual.NodeWidth / 2.0, GraphVisual.CanvasWidth - GraphVisual.NodeWidth / 2.0); if (valueRange.Contains(point.X) && valueRange.Contains(point.Y)) { if (times == 2 && minDistance > GraphVisual.NodeWidth) { var nodeValue = Enumerable.Range(1, int.MaxValue).First(x => !GraphVisual.Nodes.ContainsKey(x)); GraphVisual.AddNode(nodeValue, point); return(this); } } if (times == 1 && distanceEllipse < GraphVisual.NodeWidth) { return(StartedLineState.Create(GraphVisual, closestEllipse, point)); } return(this); }
private void SetGraph(GraphEmbedding graphEmbedding) { PauseButton_Click(null, null); this.RunAlgorithmButton.IsEnabled = true; this.StaticGraphCanvas.Children.Clear(); this.GraphVisual = GraphVisual.Create(StaticGraphCanvas, NodeBrush, NumBrush, LineBrush, PenLineCap); foreach (var node in graphEmbedding.Graph.Nodes) { GraphVisual.AddNode(node, graphEmbedding.Embedding[node]); } foreach (var edge in graphEmbedding.Graph.Edges) { GraphVisual.AddEdge(edge); } var scaleViewStackPanel = new StackPanel(); this.ScaleViewViewer.Content = scaleViewStackPanel; WeightsHandler.Create(scaleViewStackPanel, NodeBrush, LineBrush, GraphVisual.NodeWidth, GraphVisual.MinLineThickness, GraphVisual.MaxLineThickness, GraphVisual.MinWeight, GraphVisual.MaxWeight); var edges = EdgesHandler.Create(this.WeightsViewer); foreach (var edge in graphEmbedding.Graph.Edges) { edges.AddEdge(edge, active: false); } }