Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scatter plot with fill doesn't clip line #3792

Closed
BendRocks opened this issue May 7, 2024 · 2 comments
Closed

Scatter plot with fill doesn't clip line #3792

BendRocks opened this issue May 7, 2024 · 2 comments
Labels
Help Wanted Scott won't do this soon, but PRs from the community are welcome! ⚠️ HIGH PRIORITY

Comments

@BendRocks
Copy link

Issue: (Describe the bug here)
When FillY is enabled with a scatter plot, the trace lines are not correctly clipped.

ScottPlot Version: (What NuGet package are you using?)

5.0.34.0

I cloned the repo and modified the Sandbox.Winforms.Form1.cs

Code Sample: See http://scottplot.net/faq/repro/ for tips about creating reproducible code samples

The following code was put into the Form1 constructor in the Sandbox.Winforms

  double[] xs = { 1, 10, 100, 1000, 10_000, 100_000 };
  double[] ys = { -50, -50, 10, -50, -80, -80 };

  // add log-scaled data to the plot
  ScottPlot.Plottables.Scatter sp = formsPlot1.Plot.Add.Scatter(xs, ys);
  sp.LineWidth = 5;
  sp.FillY = false;
  sp.FillYValue = -200;
 
  formsPlot1.Plot.Axes.Bottom.Min = 100;
  formsPlot1.Plot.Axes.Bottom.Max = 10000;

The output is as expected, with the trace clipped at the left and right edges of the plot:

image

If the same code is used, with sp.FillY set to true, we see the following output:

image

Notice above that the lines are no longer clipped at the left and right. Note the different shading of the fill is due to the bug #3791. That same block of code in scatter.cs code is likely the culprit since the lines render correctly when FillY is false.

@swharden swharden added ⚠️ HIGH PRIORITY Help Wanted Scott won't do this soon, but PRs from the community are welcome! labels May 7, 2024
@CoderPM2011
Copy link
Contributor

CoderPM2011 commented May 11, 2024

This is because rp.CanvasState.Restore() does not restore the state to what it was before calling rp.CanvasState.Clip().

PixelRect rectAbove = new(rp.DataRect.Left, rp.DataRect.Right, yValuePixel, rect.Top);
rp.CanvasState.Clip(rectAbove);
fs.Color = FillYAboveColor;
Drawing.DrawPath(rp.Canvas, paint, fillPath, fs, rectAbove);
rp.CanvasState.Restore();
PixelRect rectBelow = new(rp.DataRect.Left, rp.DataRect.Right, rect.Bottom, yValuePixel);
rp.CanvasState.Clip(rectBelow);
fs.Color = FillYBelowColor;
Drawing.DrawPath(rp.Canvas, paint, fillPath, fs, rectBelow);
rp.CanvasState.Restore();

Before calling rp.CanvasState.Clip()
image

After calling rp.CanvasState.Clip()
image

After calling rp.CanvasState.Restore()
image


I found that this might be because the rp.CanvasState.Save() function wasn't used.
image

@swharden
Copy link
Member

Fixed in 79e1918 - thanks both of you for your help! This fix will be in the next release 👍 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Scott won't do this soon, but PRs from the community are welcome! ⚠️ HIGH PRIORITY
Projects
None yet
Development

No branches or pull requests

3 participants