Skip to content

Commit

Permalink
SignalXY: improve behavior of rotated and inverted plots
Browse files Browse the repository at this point in the history
* Bugfix in end-point interpolation for rotated SignalXY

* Bugfix for lastpoint coordinates in rotated SignalXY plottables
(resolves issue discussed in #3812

* Bug fix for inverted Axes when finding last pixel for SignalXY plots

* Update CHANGELOG.md

---------

Co-authored-by: Scott W Harden <swharden@gmail.com>
  • Loading branch information
BrianAtZetica and swharden committed Jun 10, 2024
1 parent 42bff23 commit c89c357
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ _Not yet on NuGet..._
* Scatter: Added `GetNearestX()` to the data source to help locate the point closest to the cursor's X position (#3807) @MatKinPro
* Controls: Disable middle-click-drag zooming on axes which have no data (#3810, #3897) @MCF
* DataLogger: Create `Add()` overloads which accept fixed-length arrays (#3555) @h25019871990
* SignalXY: Ensure the final point is always drawn in high density mode (#3812)
* SignalXY: Ensure the final point is always drawn in high density mode (#3812, #3812)
* Axes: Improved exception messages when calling `Zoom()` methods with invalid scale factors (#3813) @KennyTK
* WinForms: Exposed `SKControl` so users may bind to its events (#3819) @CD-SailingPerf
* Scatter: Added support for `Scale` and `Offset` properties (#3835) @bukkideme
* Axis Lines: Separated `LegendText` from `LabelText` so items may be configured separately
* Heatmap: Exposed `CellWidth` and `CellHeight` as an alternative sizing strategy to setting `Extent` (#3869) @alexisvrignaud
* ImageRect: New plot type that places an image inside a defined rectangle on the plot (#3870) @sdpenner
* Axis Rules: Improved behavior of snapping rules and improve smoothness of panning rules (#3919, #3547, #3701) @BrianAtZetica
* SignalXY: Improved appearance of rotated plots when low density mode is in use (#3921) @BrianAtZetica

## ScottPlot 5.0.34
_Published on [NuGet](https://www.nuget.org/profiles/ScottPlot) on 2024-05-05_
Expand Down
29 changes: 16 additions & 13 deletions src/ScottPlot5/ScottPlot5/DataSources/SignalXYSourceDoubleArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ private Pixel[] GetPixelsToDrawHorizontally(RenderPack rp, IAxes axes)
.Select(pxColumn => GetColumnPixelsX(pxColumn, visibileRange, rp, axes))
.SelectMany(x => x);

// duplicate the last point to ensure it is always rendered
// https://github.com/ScottPlot/ScottPlot/issues/3812
Pixel lastPoint = axes.GetPixel(new Coordinates(Xs[dataIndexLast], Ys[dataIndexLast]));

Pixel[] leftOutsidePoint = PointBefore, rightOutsidePoint = PointAfter;
if (axes.XAxis.Range.Span < 0)
{
leftOutsidePoint = PointAfter;
rightOutsidePoint = PointBefore;
lastPoint = axes.GetPixel(new Coordinates(Xs[dataIndexFirst], Ys[dataIndexFirst]));
}

// duplicate the last point to ensure it is always rendered
// https://github.com/ScottPlot/ScottPlot/issues/3812
Pixel lastPoint = axes.GetPixel(new Coordinates(Xs[dataIndexLast], Ys[dataIndexLast]));

// combine with one extra point before and after
Pixel[] points = [.. leftOutsidePoint, .. VisiblePoints, .. rightOutsidePoint, lastPoint];

Expand All @@ -93,16 +94,18 @@ private Pixel[] GetPixelsToDrawVertically(RenderPack rp, IAxes axes)
.Select(pxRow => GetColumnPixelsY(pxRow, visibleRange, rp, axes))
.SelectMany(x => x);

// duplicate the last point to ensure it is always rendered
// https://github.com/ScottPlot/ScottPlot/issues/3812
Pixel lastPoint = axes.GetPixel(new Coordinates(Ys[dataIndexLast], Xs[dataIndexLast]));

Pixel[] bottomOutsidePoint = PointBefore, topOutsidePoint = PointAfter;
if (axes.YAxis.Range.Span < 0)
{
bottomOutsidePoint = PointAfter;
topOutsidePoint = PointBefore;
lastPoint = axes.GetPixel(new Coordinates(Ys[dataIndexFirst], Xs[dataIndexFirst]));
}

// duplicate the last point to ensure it is always rendered
// https://github.com/ScottPlot/ScottPlot/issues/3812
Pixel lastPoint = axes.GetPixel(new Coordinates(Xs[dataIndexLast], Ys[dataIndexLast]));

// combine with one extra point before and after
Pixel[] points = [.. bottomOutsidePoint, .. VisiblePoints, .. topOutsidePoint, lastPoint];
Expand Down Expand Up @@ -182,7 +185,7 @@ private IEnumerable<Pixel> GetColumnPixelsX(int pixelColumnIndex, IndexRange rng
yield break;
}

yield return new Pixel(xPixel, axes.GetPixelY(Ys[startIndex] * YScale + YOffset)); // enter
yield return new Pixel(xPixel, axes.GetPixelY(Ys[Math.Min(startIndex, endIndex)] * YScale + YOffset)); // enter

if (pointsInRange > 1)
{
Expand Down Expand Up @@ -215,7 +218,7 @@ private IEnumerable<Pixel> GetColumnPixelsY(int rowColumnIndex, IndexRange rng,
yield break;
}

yield return new Pixel(axes.GetPixelX(Ys[startIndex] + XOffset), yPixel); // enter
yield return new Pixel(axes.GetPixelX(Ys[Math.Min(startIndex,endIndex)] + XOffset), yPixel); // enter

if (pointsInRange > 1)
{
Expand Down Expand Up @@ -258,8 +261,8 @@ private IEnumerable<Pixel> GetColumnPixelsY(int rowColumnIndex, IndexRange rng,

if (firstPointPosition > MinimumIndex)
{
float beforeX = axes.GetPixelX(Xs[firstPointIndex - 1] + XOffset);
float beforeY = axes.GetPixelY(Ys[firstPointIndex - 1] * YScale + YOffset);
float beforeY = axes.GetPixelY(Xs[firstPointIndex - 1] + XOffset);
float beforeX = axes.GetPixelX(Ys[firstPointIndex - 1] * YScale + YOffset);
Pixel beforePoint = new(beforeX, beforeY);
return ([beforePoint], firstPointIndex);
}
Expand Down Expand Up @@ -300,8 +303,8 @@ private IEnumerable<Pixel> GetColumnPixelsY(int rowColumnIndex, IndexRange rng,

if (lastPointPosition <= MaximumIndex)
{
float afterX = axes.GetPixelX(Xs[lastPointIndex] + XOffset);
float afterY = axes.GetPixelY(Ys[lastPointIndex] * YScale + YOffset);
float afterY = axes.GetPixelY(Xs[lastPointIndex] + XOffset);
float afterX = axes.GetPixelX(Ys[lastPointIndex] * YScale + YOffset);
Pixel afterPoint = new(afterX, afterY);
return ([afterPoint], lastPointIndex);
}
Expand Down

0 comments on commit c89c357

Please sign in to comment.