// 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(); }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (_gViewer == null) { return(false); } if (keyData == (Keys.Up | Keys.Control)) { _gViewer.ZoomOutPressed(); } if (keyData == (Keys.Down | Keys.Control)) { _gViewer.ZoomInPressed(); } if (keyData == Keys.P) { if (_selectedNode != null) { _client.GetProfiledGraphFor(_selectedNode.Id); } } if ((keyData & Keys.S) == Keys.S) { //if (_selectedNode != null) // _client.GetProfiledGraphFor(_selectedNode.Id); //_gViewer.SaveButtonPressed(); } if ((keyData & Keys.G) == Keys.G) { if (_selectedNode != null) { _client.GetGraphFor(_selectedNode.Id); } } if (keyData == Keys.PageDown || keyData == Keys.Oemplus) { _gViewer.ZoomInPressed(); } if (keyData == Keys.PageUp || keyData == Keys.OemMinus) { _gViewer.ZoomOutPressed(); } if (keyData == (Keys.Down | Keys.Alt)) { _gViewer.Pan(0, _gViewer.GraphHeight * -.05); } if (keyData == (Keys.Up | Keys.Alt)) { _gViewer.Pan(0, _gViewer.GraphHeight * .05); } if (keyData == (Keys.Left | Keys.Alt)) { _gViewer.Pan(_gViewer.GraphHeight * -.1, 0); } if (keyData == (Keys.Right | Keys.Alt)) { _gViewer.Pan(_gViewer.GraphHeight * .1, 0); } if (keyData == Keys.H || keyData == Keys.Left) { selectNode(direction.left); } if (keyData == Keys.L || keyData == Keys.Right) { selectNode(direction.right); } if (keyData == Keys.K || keyData == Keys.Up) { selectNode(direction.up); } if (keyData == Keys.J || keyData == Keys.Down) { selectNode(direction.down); } if (keyData == Keys.Escape) { Close(); } if (keyData == Keys.Enter || keyData == Keys.Return || keyData == Keys.Space) { if (_selectedNode != null) { MethodFinder_Slow.GotoMethod(_selectedNode.Id, _dte); } Close(); } return(true); }