Exemplo n.º 1
0
        public override void Paint(Graphics gr)
        {
            if (PlotterControl == null)
            {
                throw new InvalidOperationException("PlotterControl is null");
            }
            if (_data.Count < 2)
            {
                return;
            }

            using (Pen pen = new Pen(ForeColor, LineWidth))
            {
                pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                if (_continuousLine)
                {
                    if (_linesToDraw == null || _linesToDraw.Length != _data.Count)
                    {
                        _linesToDraw = new Point[_data.Count];
                    }

                    for (int i = 0; i < _data.Count; i++)
                    {
                        _linesToDraw[i] =
                            LimitPoint(PlotterControl.Space2Screen(_data[i]));
                    }

                    gr.DrawLines(pen, _linesToDraw);
                }
                else
                {
                    for (int i = 1; i < _data.Count; i += 2)
                    {
                        Point p1 =
                            LimitPoint(PlotterControl.Space2Screen(_data[i - 1]));
                        Point p2 =
                            LimitPoint(PlotterControl.Space2Screen(_data[i]));
                        gr.DrawLine(pen, p1, p2);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Paint(System.Drawing.Graphics gr)
        {
            if (PlotterControl == null)
            {
                throw new InvalidOperationException("PlotterControl is null");
            }
            if (_buffer.Count < 2)
            {
                return;
            }

            int linesCount = 0;

            switch (_stepLengthMode)
            {
            case LengthMode.Space:
                linesCount = (int)Math.Ceiling(
                    PlotterControl.VisibleRectangle.Width / _stepLength) + 1;
                break;

            case LengthMode.Screen:
                linesCount = (int)Math.Ceiling(
                    PlotterControl.ClientRectangle.Width / _stepLength) + 1;
                break;
            }
            if (linesCount > _buffer.Count)
            {
                linesCount = _buffer.Count;
            }

            using (Pen pen = new Pen(ForeColor, LineWidth))
            {
                pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                if (_linesToDraw == null || _linesToDraw.Length != linesCount)
                {
                    _linesToDraw = new Point[linesCount];
                }

                float vRectRight = PlotterControl.VisibleRectangle.Right;
                int   cRectWidth = PlotterControl.ClientRectangle.Width;

                for (int i = 0, bufElem = _buffer.Count - 1;
                     i < linesCount && bufElem >= 0;
                     i++, bufElem--)
                {
                    Point chartPoint = Point.Empty;
                    switch (_stepLengthMode)
                    {
                    case LengthMode.Space:
                        chartPoint =
                            PlotterControl.Space2Screen(
                                new PointF(vRectRight - i * _stepLength,
                                           _buffer[bufElem]));
                        break;

                    case LengthMode.Screen:
                        chartPoint = new Point(
                            (int)(cRectWidth - i * _stepLength),
                            PlotterControl.SpaceY2ScreenY(_buffer[bufElem]));
                        break;
                    }

                    _linesToDraw[i] =
                        LimitPoint(chartPoint);
                }

                gr.DrawLines(pen, _linesToDraw);
            }
        }
Exemplo n.º 3
0
        public override void Paint(Graphics gr)
        {
            if (PlotterControl == null)
            {
                throw new InvalidOperationException("PlotterControl is null");
            }

            int   diameter = 2 * PointSize;
            Point origin   = PlotterControl.Space2Screen(new PointF(0.0f, 0.0f));

            using (Pen pen = new Pen(ForeColor, LineWidth))
            {
                foreach (ChartPoint point in _points)
                {
                    /* Point is a structure, so we can afford it. If it were a class,
                     * this would be very memory-consuming. */
                    Point sigPoint = PlotterControl.Space2Screen(point.Coords);
                    pen.Color =
                        (point.Color == Color.Empty) ? ForeColor : point.Color;

                    switch (point.Shape)
                    {
                    case PointShape.Circle:
                        gr.DrawEllipse(pen,
                                       sigPoint.X - _pointSize,
                                       sigPoint.Y - _pointSize,
                                       diameter, diameter);
                        break;

                    case PointShape.Square:
                        gr.DrawRectangle(pen,
                                         sigPoint.X - _pointSize,
                                         sigPoint.Y - _pointSize,
                                         diameter, diameter);
                        break;
                    }

                    if (point.DrawLines)
                    {
                        // Draw the dashed line from the origin to the signal point.
                        pen.DashStyle = DashStyle.Dash;
                        gr.DrawLine(pen, origin, sigPoint);

                        /* Draw the dotted lines from the signal point to the axes.
                         * The line is drawn not strictly from the signal point, but
                         * from the ellipse'point boundary. The Math.Sign method allows
                         * us to support the both axis sides correctly. */
                        pen.DashStyle = DashStyle.Dot;
                        gr.DrawLine(pen,
                                    sigPoint.X,
                                    sigPoint.Y + _pointSize * Math.Sign(point.Coords.Y),
                                    sigPoint.X, origin.Y);
                        gr.DrawLine(pen,
                                    sigPoint.X - _pointSize * Math.Sign(point.Coords.X),
                                    sigPoint.Y,
                                    origin.X, sigPoint.Y);

                        // Restore the original DashStyle settings.
                        pen.DashStyle = DashStyle.Solid;
                    }
                }
            }
        }