public override void Paint(Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } if (_function == null) { return; } int clientWidth = PlotterControl.ClientRectangle.Width; if (_linesToDraw == null || _linesToDraw.Length != PlotterControl.ClientRectangle.Width) { _linesToDraw = new Point[PlotterControl.ClientRectangle.Width]; } for (int screenX = 0; screenX < clientWidth; screenX++) { double spaceX = PlotterControl.ScreenX2SpaceX(screenX); double spaceY = _function(spaceX); int screenY = PlotterControl.SpaceY2ScreenY(spaceY); _linesToDraw[screenX] = new Point(screenX, screenY); } using (Pen pen = new Pen(ForeColor, LineWidth)) { pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gr.DrawLines(pen, _linesToDraw); } }
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); } }