Beispiel #1
0
        /// <summary>
        /// draws the main graph section
        /// </summary>
        private void DrawGraph(DrawingContext drawingContext)
        {
            if (NetworkFrames.Count <= 1)
            {
                return;
            }

            RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
            int    x      = (int)ActualWidth - 1;
            double yMin   = ActualHeight - 1;
            double yRange = yMin - 3;

            DesiredNetworkBufferSize = x;

            NetworkFrame[] frames = NetworkFrames.Take(x).ToArray();
            double[]       up     = new double[Math.Min(x, frames.Length)];
            double[]       down   = new double[Math.Min(x, frames.Length)];
            double         range  = 0;

            if (RenderMode == RenderingMode.Average && up.Length > c_rollingAveragingRange)
            {
                int i = 0;
                DropOutStack <double> upStack   = new DropOutStack <double>(c_rollingAveragingRange);
                DropOutStack <double> downStack = new DropOutStack <double>(c_rollingAveragingRange);
                foreach (NetworkFrame frame in frames)
                {
                    if (i > up.Length)
                    {
                        break;
                    }

                    upStack.Push(frame.Upload);
                    downStack.Push(frame.Download);
                    up[i]   = Math.Max(frame.Upload, CalculateRollingAverage(upStack));
                    down[i] = Math.Max(frame.Download, CalculateRollingAverage(downStack));

                    range = Math.Max(up[i], Math.Max(down[i], range));
                    i++;
                }
            }
            else if (RenderMode == RenderingMode.AverageMoving && up.Length > c_movingAveragingRange)
            {
                int i = 0;
                DropOutStack <double> upStack   = new DropOutStack <double>(c_movingAveragingRange);
                DropOutStack <double> downStack = new DropOutStack <double>(c_movingAveragingRange);
                foreach (NetworkFrame frame in frames)
                {
                    if (i > up.Length)
                    {
                        break;
                    }

                    upStack.Push(frame.Upload);
                    downStack.Push(frame.Download);
                    up[i]   = Math.Max(frame.Upload, CalculateMovingAverage(upStack));
                    down[i] = Math.Max(frame.Download, CalculateMovingAverage(downStack));

                    range = Math.Max(up[i], Math.Max(down[i], range));
                    i++;
                }
            }
            else if (RenderMode == RenderingMode.Smart && up.Length > c_movingAveragingRange && up.Length > c_rollingAveragingRange)
            { // Combine both average and moving average
                int i = 0;
                DropOutStack <double> upStack   = new DropOutStack <double>(Math.Max(c_movingAveragingRange, c_rollingAveragingRange));
                DropOutStack <double> downStack = new DropOutStack <double>(Math.Max(c_movingAveragingRange, c_rollingAveragingRange));
                foreach (NetworkFrame frame in frames)
                {
                    if (i > up.Length)
                    {
                        break;
                    }

                    upStack.Push(frame.Upload);
                    downStack.Push(frame.Download);

                    up[i]   = Math.Max(CalculateRollingAverage(upStack), CalculateMovingAverage(upStack));
                    down[i] = Math.Max(CalculateRollingAverage(downStack), CalculateMovingAverage(downStack));

                    range = Math.Max(up[i], Math.Max(down[i], range));
                    i++;
                }
            }
            else if (RenderMode == RenderingMode.Thick && up.Length > c_maxedAveragingRange)
            {
                int i = 0;
                DropOutStack <double> upStack   = new DropOutStack <double>(c_maxedAveragingRange);
                DropOutStack <double> downStack = new DropOutStack <double>(c_maxedAveragingRange);
                foreach (NetworkFrame frame in frames)
                {
                    if (i >= up.Length)
                    {
                        break;
                    }

                    upStack.Push(frame.Upload);
                    downStack.Push(frame.Download);
                    up[i]   = upStack.Max();
                    down[i] = downStack.Max();

                    range = Math.Max(up[i], Math.Max(down[i], range));
                    i++;
                }
            }
            else // RenderMode == RenderingMode.Direct
            {
                int i = 0;
                foreach (NetworkFrame frame in frames)
                {
                    if (i > up.Length)
                    {
                        break;
                    }

                    up[i]   = frame.Upload;
                    down[i] = frame.Download;

                    range = Math.Max(up[i], Math.Max(down[i], range));
                    i++;
                }
            }

            for (int i = 0; i < up.Length - 1; i++)
            {
                double barRange = down[i] / range;
                drawingContext.DrawLine(m_downloadPen, new Point(x, yMin), new Point(x, yMin - (yRange * barRange)));

                barRange = up[i] / range;
                drawingContext.DrawLine(m_uploadPen, new Point(x, yMin), new Point(x, yMin - (yRange * barRange)));

                x -= 1;
            }

            RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
        }