Skip to content

SP5: Improve Signal line drawing #2949

@swharden

Description

@swharden

Extend work started in #2935 to create code that draws lines more carefully and has features like edge interpolation. It can later be used by SignalXY plots too.

Here is relevant code from ScottPlot4:

PointF[] PointsToDraw = PointBefore.Concat(VisiblePoints).Concat(PointAfter).ToArray();
// Interpolate before displayed point to make it x = -1 (close to visible area)
// this fix extreme zoom in bug
if (PointBefore.Length > 0 && PointsToDraw.Length >= 2 && !StepDisplay)
{
// only extrapolate if points are different (otherwise extrapolated point may be infinity)
if (PointsToDraw[0].X != PointsToDraw[1].X)
{
float x0 = -1 + dims.DataOffsetX;
float y0 = PointsToDraw[1].Y + (PointsToDraw[0].Y - PointsToDraw[1].Y) * (x0 - PointsToDraw[1].X) / (PointsToDraw[0].X - PointsToDraw[1].X);
PointsToDraw[0] = new PointF(x0, y0);
}
}
// Interpolate after displayed point to make it x = datasize.Width(close to visible area)
// this fix extreme zoom in bug
if (PointAfter.Length > 0 && PointsToDraw.Length >= 2 && !StepDisplay)
{
PointF lastPoint = PointsToDraw[PointsToDraw.Length - 2];
PointF afterPoint = PointsToDraw[PointsToDraw.Length - 1];
// only extrapolate if points are different (otherwise extrapolated point may be infinity)
if (afterPoint.X != lastPoint.X)
{
float x1 = dims.DataWidth + dims.DataOffsetX;
float y1 = lastPoint.Y + (afterPoint.Y - lastPoint.Y) * (x1 - lastPoint.X) / (afterPoint.X - lastPoint.X);
PointsToDraw[PointsToDraw.Length - 1] = new PointF(x1, y1);
}
}

EDIT: see #2935 (comment) for more information

SignalExample

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions