// Menganimasikan query pada graf dengan mengubah warna startNode, goalNode, checkedNode, dan pathNode private void _animateGraph(int startNode, int goalNode) { _initializeGraph(); // zoom in view untuk agar view terfokus ke satu node dan beberapa di sekitarnya // rasio zoom diset viewer.ZoomF = 0.05 * Math.Max(viewer.GraphHeight, viewer.GraphWidth) / viewer.Graph.FindNode("1").Attr.Height; viewer.ZoomInPressed(); // mengubah warna startNode menjadi kuning viewer.Graph.FindNode(startNode.ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Yellow; // set node yang baru diubah warnanya menjadi center dari view viewer.CenterToPoint(viewer.Graph.FindNode(startNode.ToString()).Attr.Pos); graphPanel.Refresh(); var tw = Task.Delay(1000); tw.Wait(); viewer.Graph.FindNode(goalNode.ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; viewer.CenterToPoint(viewer.Graph.FindNode(goalNode.ToString()).Attr.Pos); graphPanel.Refresh(); tw = Task.Delay(1000); tw.Wait(); int CheckedCount = rootedTree.CheckedNode.Count; // set waktu transisi antar node dalam animasi double waitTime = Math.Min((double)1000, 20000.0 / CheckedCount); foreach (int el in rootedTree.CheckedNode) { viewer.Graph.FindNode(el.ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightPink; viewer.CenterToPoint(viewer.Graph.FindNode(el.ToString()).Attr.Pos); graphPanel.Refresh(); tw = Task.Delay((int)waitTime); tw.Wait(); } int[] path = rootedTree.PathNode.ToArray(); for (int i = path.Length - 1; i >= 0; --i) { viewer.Graph.FindNode(path[i].ToString()).Attr.FillColor = Microsoft.Msagl.Drawing.Color.RoyalBlue; } viewer.ZoomOutPressed(); viewer.ZoomOutPressed(); if (Math.Abs(viewer.Graph.FindNode(goalNode.ToString()).Attr.Pos.X - viewer.Graph.FindNode(startNode.ToString()).Attr.Pos.X) > Math.Abs(viewer.Graph.FindNode(goalNode.ToString()).Attr.Pos.Y - viewer.Graph.FindNode(startNode.ToString()).Attr.Pos.Y)) { viewer.ZoomF = viewer.GraphWidth / Math.Abs(viewer.Graph.FindNode(goalNode.ToString()).Attr.Pos.X - viewer.Graph.FindNode(startNode.ToString()).Attr.Pos.X); } else { viewer.ZoomF = viewer.GraphHeight / Math.Abs(viewer.Graph.FindNode(goalNode.ToString()).Attr.Pos.Y - viewer.Graph.FindNode(startNode.ToString()).Attr.Pos.Y); } viewer.ZoomF *= 0.5; var x = new object[2]; x[0] = viewer.Graph.FindNode(goalNode.ToString()); x[1] = viewer.Graph.FindNode(startNode.ToString()); viewer.ZoomInPressed(); viewer.CenterToGroup(x); graphPanel.Refresh(); }
public void InitializeForm() { this.algorithms = new List <Action>(); this.nodePickingCancellationTokenSource = new CancellationTokenSource(); this.nodePickingCancellationToken = this.nodePickingCancellationTokenSource.Token; graph = new Frame.Models.DGraph(ArrowStyle.None); viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); viewer.EdgeInsertButtonVisible = viewer.UndoRedoButtonsVisible = viewer.windowZoomButton.Visible = viewer.NavigationVisible = false; viewer.LayoutAlgorithmSettingsButtonVisible = true; graph.AddVertice("A"); graph.AddVertice("B"); graph.AddVertice("C"); graph.AddVertice("D"); //AddNodesLocations(); graph.AddEdge("C", "B", 234); graph.AddEdge("A", "C", 53); graph.AddEdge("A", "C", 43); viewer.CenterToPoint(new Microsoft.Msagl.Core.Geometry.Point(viewer.Width / 2, viewer.Height / 2)); viewer.Graph = graph; viewer.MouseDown += Viewer_MouseDown; viewer.MouseUp += Viewer_MouseUp; viewer.MouseMove += Viewer_MouseMove; viewer.MouseClick += Viewer_MouseClick; viewer.GraphLoadingEnded += Viewer_GraphLoadingEnded; viewer.GraphChanged += Viewer_GraphChanged; viewer.CustomOpenButtonPressed += Viewer_CustomOpenButtonPressed; viewer.KeyDown += Viewer_KeyDown; //viewer.ObjectUnderMouseCursorChanged += Viewer_ObjectUnderMouseCursorChanged; /*viewer.LayoutEditor.RemoveEdgeDraggingDecorations = null; * viewer.LayoutEditor.RemoveObjDraggingDecorations = null;*/ //viewer.AsyncLayout = true; this.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; this.graphPanel.Controls.Add(viewer); this.ResumeLayout(); }
private void selectNode(string newSelectedNodeID) { //If there is allready a selected node then "deselect" it if (_selectedNode != null) { _selectedNode.Attr.Color = Color.Black; } _selectedNode = _gViewer.Graph.FindNode(newSelectedNodeID); //save new selected node if (_selectedNode != null) { _selectedNode.Attr.Color = Color.Red; //and "select" it } _gViewer.CenterToPoint(_selectedNode.BoundingBox.Center); _gViewer.Invalidate(); }