Exemple #1
0
        ///<inheritdoc/>
        public override void Redraw(Rect bounds)
        {
            if (CellSize.X == 0 || CellSize.Y == 0)
            {
                throw new Exception($"{nameof(CellSize)} cannot be 0");
            }

            SetDriverColorToGraphColor();

            Move(0, 0);

            // clear all old content
            for (int i = 0; i < Bounds.Height; i++)
            {
                Move(0, i);
                Driver.AddStr(new string (' ', Bounds.Width));
            }

            // If there is no data do not display a graph
            if (!Series.Any() && !Annotations.Any())
            {
                return;
            }

            // Draw 'before' annotations
            foreach (var a in Annotations.Where(a => a.BeforeSeries))
            {
                a.Render(this);
            }

            SetDriverColorToGraphColor();

            AxisY.DrawAxisLine(this);
            AxisX.DrawAxisLine(this);

            AxisY.DrawAxisLabels(this);
            AxisX.DrawAxisLabels(this);

            // Draw a cross where the two axis cross
            var axisIntersection = new Point(AxisY.GetAxisXPosition(this), AxisX.GetAxisYPosition(this));

            if (AxisX.Visible && AxisY.Visible)
            {
                Move(axisIntersection.X, axisIntersection.Y);
                AddRune(axisIntersection.X, axisIntersection.Y, '\u253C');
            }

            SetDriverColorToGraphColor();

            // The drawable area of the graph (anything that isn't in the margins)
            Rect       drawBounds = new Rect((int)MarginLeft, 0, Bounds.Width - ((int)MarginLeft), Bounds.Height - (int)MarginBottom);
            RectangleF graphSpace = ScreenToGraphSpace(drawBounds);

            foreach (var s in Series)
            {
                s.DrawSeries(this, drawBounds, graphSpace);

                // If a series changes the graph color reset it
                SetDriverColorToGraphColor();
            }

            SetDriverColorToGraphColor();

            // Draw 'after' annotations
            foreach (var a in Annotations.Where(a => !a.BeforeSeries))
            {
                a.Render(this);
            }
        }