Пример #1
0
        // 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();
        }
Пример #2
0
        void SearchButtonClick(object sender, EventArgs e)
        {
            if (GViewer.Graph != null)
            {
                string s = searchTextBox.Text.ToLower();
                if (searchEnumerator == null)
                {
                    searchEnumerator = GraphObjects().GetEnumerator();
                }

                bool textFound = false;
                while (searchEnumerator.MoveNext())
                {
                    object t     = searchEnumerator.Current;
                    var    n     = t as Node;
                    Label  label = n != null ? n.Label : ((Edge)t).Label;

                    if (label != null && label.Text.ToLower().Contains(s))
                    {
                        double x = 0.8 * Math.Min(GViewer.Graph.Width / label.Width, GViewer.Graph.Height / label.Size.Height);
                        if (GViewer.ZoomF < x)
                        {
                            GViewer.ZoomF = x;
                        }
                        GViewer.CenterToGroup(t);
                        searchButton.Text = "Next";
                        textFound         = true;
                        break;
                    }
                }

                if (searchButton.Text == "Search")
                {
                    MessageBox.Show(String.Format("'{0}' not found", s));
                }
                else
                {
                    if (textFound == false)
                    {
                        searchEnumerator  = GraphObjects().GetEnumerator(); //resetting
                        searchButton.Text = "Wrap around and Search";
                    }
                }
            }
        }