SP5 Signal: fix horizontal line rendering issue#2935
SP5 Signal: fix horizontal line rendering issue#2935swharden merged 12 commits intoScottPlot:mainfrom
Conversation
demonstrates issue ScottPlot#2933
a data structure designed to replace "indexed vertical bars"
|
Hi @StendProg, thanks for this fix! I identified a rendering issue that caused downward sloping lines to appear too thick. I figured out it was because I'll merge this in now and we can create a new PR to improve or refine this code if needed 👍 BeforeAfter |
|
Hi @swharden, Yes, it does look better with your extra fix. But we can find a counterexample for it too. For example, when neighboring pixel columns do not overlap by Y, then they will be unconnected. If we continue these improvements, we can do what SignalXY draws for a single column:
The blue color indicates the original signal. |
|
Thanks for the feedback @StendProg!
I'm having trouble demonstrating this with code... do you have a similar code example I can use to check that the issue is present and confirm when it has been fixed? Here's my attempt so far: [Test]
public void Test_Signal_VerticalGap()
{
double[] data = Generate.Sin(10_000, oscillations: 100);
for (int i = (int)(data.Length * .3); i < (int)(data.Length * .7); i++)
{
data[i] = data[i] + 10;
}
ScottPlot.Plot plt = new();
var sig = plt.Add.Signal(data);
sig.LineStyle.AntiAlias = false;
plt.Grids.Clear();
plt.SaveTestImage();
} |
|
In theory the artifact you describe with the green squares makes sense, but in practice it's pretty hard to demonstrate using ScottPlot;
using ScottPlot.WinForms;
double[] data = Generate.Sin(10_000, oscillations: 100);
for (int i = (int)(data.Length * .3); i < (int)(data.Length * .7); i++)
data[i] = data[i] + 10;
Plot plot = new();
plot.Add.Signal(data);
Form form = new()
{
Width = 600,
Height = 400,
StartPosition = FormStartPosition.CenterScreen
};
FormsPlot formsPlot1 = new()
{
Dock = DockStyle.Fill
};
formsPlot1.Reset(plot);
formsPlot1.Refresh();
form.Controls.Add(formsPlot1);
form.ShowDialog(); |
This is probably the best solution, and it would be nice to share code between I'll work on that in a new issue/PR #2949 |
|
I was able to get this on the latest version: I think the code will need a lot of reworking, but you're right that it should be a separate task. You failed to reproduce the effect I described earlier because the X ranges for the pixel columns overlap (which should not be the case) and the data points can be included in both columns. ScottPlot/src/ScottPlot5/ScottPlot5/Plottables/Signal.cs Lines 43 to 45 in c61bb77 When iterating, we rounded the width, but when calculating the density of points per pixel, we didn't: |






Purpose:
Fix for #2933.
The problem was this line:
ScottPlot/src/ScottPlot5/ScottPlot5/Plottables/Signal.cs
Line 142 in 5d37702
In the case of identical
y's in the entire pixel column, we draw a line from (x,y) to the same (x, y). The graphics library probably tries to optimize this and draws absolutely nothing, thus we lose the line thickness.In this PR the drawing of unconnected vertical lines is changed to drawing a connected path along all vertical columns, which eliminates the effect described in #2933.
In the process of working on PR it turned out that this bug is always present and was even useful for drawing areas outside the signal. In fact, the same single point lines are always drawn there that were not displayed. Switching to path drawing started to display those invisible lines as well.
As a result, it had to be significantly redesigned, in particular to filter out pixel columns that lie outside the signal.