-
Notifications
You must be signed in to change notification settings - Fork 981
Description
Issue: (Describe the bug here)
When FillY is enabled with a non-zero FillYValue, the area to be filled is filled twice. When alpha is < 1.0, the result is two shades of the fill color.
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
This code was put into the Form1 constructor in the Sandbox.Winforms:
double[] xs = { 2, 200, 2000, 20000 };
double[] ys = { -50, 10, -80, -100 };
// add log-scaled data to the plot
var sp = formsPlot1.Plot.Add.Scatter(xs, ys);
sp.LineWidth = 2;
sp.FillY = true;
sp.FillYColor = Colors.Blue.WithAlpha(0.5);
sp.FillYValue = -200;And the resulting output is as shown. Note that alpha is 0.5, so filling it twice changes the apparent color.
Inside Scatter.cs, there is the following around line 135:
ScottPlot/src/ScottPlot5/ScottPlot5/Plottables/Scatter.cs
Lines 134 to 162 in 6cc3bbb
| if (FillY) | |
| { | |
| FillStyle fs = new() { IsVisible = true }; | |
| PixelRect rect = new(linePixels); | |
| float yValuePixel = Axes.YAxis.GetPixel(FillYValue, rp.DataRect); | |
| using SKPath fillPath = new(path); | |
| fillPath.LineTo(rect.Right, yValuePixel); | |
| fillPath.LineTo(rect.Left, yValuePixel); | |
| PixelRect rectAbove = new(rp.DataRect.Left, rp.DataRect.Right, yValuePixel, rect.Top); | |
| rp.CanvasState.Save(); | |
| 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.Save(); | |
| rp.CanvasState.Clip(rectBelow); | |
| fs.Color = FillYBelowColor; | |
| Drawing.DrawPath(rp.Canvas, paint, fillPath, fs, rectBelow); | |
| rp.CanvasState.Restore(); | |
| } | |
| Drawing.DrawLines(rp.Canvas, paint, path, LineStyle); | |
| Drawing.DrawMarkers(rp.Canvas, paint, markerPixels, MarkerStyle); | |
| } |
Note that rectAbove and rectBelow are both drawn. If the 5 lines for rect below are commented out, then the fill is as expected (shown below). So, at first glance, it seems either one or the other should be selected, based on the FillY value being positive or negative. However, there are a lot of considerations here, and I don't understand the breadth of the code base enough to know if such a simple change might have impacts elsewhere.

