Ejemplo n.º 1
0
        /// <summary>
        /// Display tweets for the word the user is hovering over.
        /// If a tweet popup is currently displayed, move popup window until the mouse is over a different word.
        /// </summary>
        protected void OnMouseMove(object sender, MouseEventArgs args)
        {
            var   hits      = wordNodeMap.Where(w => w.Value.Region.Contains(args.Location));
            Point windowPos = PointToScreen(args.Location);

            windowPos.Offset(50, 70);

            if (hits.Count() > 0)
            {
                string   word = hits.First().Key;
                TextNode node = hits.First().Value;

                if (mouseWord == word)
                {
                    tweetForm.Location = windowPos;
                }
                else
                {
                    if (tweetForm == null)
                    {
                        tweetForm          = new TweetForm();
                        tweetForm.Location = windowPos;
                        tweetForm.Show();
                        tweetForm.TopMost = true;
                    }

                    // We have a new word.
                    tweetForm.tbTweets.Clear();
                    ShowTweets(word);
                    mouseWord = word;
                }
            }
            else
            {
                // Just move the window.
                if (tweetForm != null)
                {
                    tweetForm.Location = windowPos;
                    tweetForm.TopMost  = true;
                }
            }
        }
Ejemplo n.º 2
0
        protected void Setup()
        {
            diagram = new Diagram(this);
            rnd     = new Random();
            bool overrun = false;

            diagram.Arrange();

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000 / 20;                         // 20 times a second, in milliseconds.
            timer.Tick    += (sender, args) => pnlCloud.Invalidate(true);

            pnlCloud.Paint += (sender, args) =>
            {
                Graphics gr = args.Graphics;
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                ++paintIteration;
                // ReduceCounts();

                if (!overrun)
                {
                    overrun = true;
                    int maxTweets = 20;

                    // We assume here that we can parse the data faster than the incoming stream hands it to us.
                    // But we put in a safety check to handle only 20 tweets.
                    while (tweetQueue.Count > 0 && (--maxTweets > 0))
                    {
                        string tweet;

                        lock (this)
                        {
                            tweet = tweetQueue.Dequeue();
                        }

                        SynchronousUpdate(tweet);
                    }

                    // gr.Clear(Color.White);
                    diagram.Iterate(Diagram.DEFAULT_DAMPING, Diagram.DEFAULT_SPRING_LENGTH, Diagram.DEFAULT_MAX_ITERATIONS);
                    diagram.Draw(gr, Rectangle.FromLTRB(12, 24, pnlCloud.Width - 12, pnlCloud.Height - 36));

                    // gr.DrawString(paintIteration.ToString() + "  " + diagram.Nodes.Count.ToString() + "  " + tweetQueue.Count.ToString() + "  " + diagram.layout.Count.ToString(), font, brushBlack, new Point(3, 3));

                    overrun = false;
                }
                else
                {
                    gr.DrawString("overrun", font, brushBlack, new Point(3, 3));
                }
            };

            pnlCloud.MouseMove  += OnMouseMove;
            pnlCloud.MouseLeave += (sender, args) =>
            {
                if (tweetForm != null)
                {
                    tweetForm.Close();
                    tweetForm = null;
                    mouseWord = String.Empty;
                }
            };

            timer.Start();

            Node node = new SpotNode(Color.Black);

            rootNode = node;
            diagram.AddNode(node);
        }