Ejemplo n.º 1
0
        public static Bitmap GraphSpeeds(HistoryDiff diff, int width, int height, Color incoming, Color outgoing, Color background, float thickness)
        {
            Bitmap img = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            GC.Collect();
            Graphics g = Graphics.FromImage(img);

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode  = InterpolationMode.High;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.Clear(background);
            if (diff.Count <= 1)
            {
                return(img);
            }
            Pen    incomingPen = new Pen(incoming, thickness);
            Pen    outgoingPen = new Pen(outgoing, thickness);
            double maxr        = (diff.OrderByDescending(hdi => hdi.Received)).First().Received;
            double maxs        = (diff.OrderByDescending(hdi => hdi.Sent)).First().Sent;
            double max         = Math.Max(maxr, maxs);

            if (max <= 0)
            {
                return(img);
            }
            List <PointF> pointsR = new List <PointF>(0);
            List <PointF> pointsS = new List <PointF>(0);

            diff.Sort();
            foreach (HistoryDiffItem hdi in diff)
            {
                float x  = (float)(((hdi.Time.TotalSeconds + (diff.Span - diff.Current.Time.TotalSeconds)) / diff.Span) * width);
                float yR = (float)(height - ((hdi.Received / max) * (height * 0.8)));
                pointsR.Add(new PointF(x, yR));
                float yS = (float)(height - ((hdi.Sent / max) * (height * 0.8)));
                pointsS.Add(new PointF(x, yS));
            }
            g.DrawLines(incomingPen, pointsR.ToArray());
            g.DrawLines(outgoingPen, pointsS.ToArray());
            incomingPen.Dispose();
            outgoingPen.Dispose();
            g.Dispose();
            return(img);
        }
Ejemplo n.º 2
0
        public void DisplayData(string header, History history)
        {
            HistoryDiff diff = history.Diff();

            displayLabelHeader.Text   = header;
            displayLabelIncoming.Text = MainClass.FormatSizestr(diff.Empty ? 0 : diff.Current.Received) + "/s";
            displayLabelOutgoing.Text = MainClass.FormatSizestr(diff.Empty ? 0 : diff.Current.Sent) + "/s";
            double maxr = diff.Empty ? 0 : (diff.OrderByDescending(hdi => hdi.Received)).First().Received;
            double maxs = diff.Empty ? 0 : (diff.OrderByDescending(hdi => hdi.Sent)).First().Sent;
            string str  = "Peak in:  " + MainClass.FormatSizestr(maxr) + "/s\n";

            str += "Peak out: " + MainClass.FormatSizestr(maxs) + "/s\n\n";
            str += "Received: " + MainClass.FormatSizestr(history.Empty ? 0 : history.Current.Received) + "\n";
            str += "Sent:     " + MainClass.FormatSizestr(history.Empty ? 0 : history.Current.Sent);
            displayLabelFooter.Text = str;
            Image i = displayImage.Image;

            displayImage.Image = Graph.GraphSpeeds(diff, (int)(SCALE * (displayImage.Width - 10)), (int)(SCALE * (displayImage.Height - 10)), Color.LimeGreen, Color.Red, Color.Black, 3);
            i.Dispose();
        }