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

Rendering problem - angled lines appear during mouse interaction #401

Closed
bukkideme opened this issue May 18, 2020 · 6 comments
Closed

Rendering problem - angled lines appear during mouse interaction #401

bukkideme opened this issue May 18, 2020 · 6 comments
Labels
BUG unexpected behavior

Comments

@bukkideme
Copy link
Contributor

Describe the bug
When the docked ScottPlot.FormsPlot is maximized together with the parent Form's window, strange angled lines appear at top right during middle mouse button pushed down. Same artifact happens when we use the right mouse button for zoom.

To Reproduce
VS Community 2019, Version 16.5.5.
ScottPlot 4.0.32 (previous version also has the same bug)

Steps to reproduce:

Create a new Winform project.
Drop a ScottPlot.FormsPlot user control into the Form, and set it as "Dock - Fill".
Run the project.
Maximize the Form window.
Start to use the mouse buttons for the different zoom options.
Bug appears visible.

Another info, if you set the grid line width to value 2 or higher (i did it in the Form's constructor), the bug seems to disappear:
formsPlot1.plt.Grid(lineWidth: 2);

Screenshots
I set the Grid color to red to make the bug more visible!

Scottplot_bug1

@bukkideme bukkideme added the BUG unexpected behavior label May 18, 2020
@Ichibot200
Copy link

I have the same issue.
Unfortunately, I have not taken a closer look at the issue myself yet.

@swharden
Copy link
Member

swharden commented May 18, 2020

This is so frustrating! This is an error in System.Drawing when rendering non-anti-aliased perfectly horizontal lines that touch the edge of the bitmap described in #327

This issue may have re-emerged from recent work on the grid system a63eba9

I'll take a closer look!

strange angled lines appear at top right during middle mouse button pushed down

This is because mouse interactions enable anti-aliasing mode

@swharden

This comment has been minimized.

swharden added a commit that referenced this issue May 18, 2020
This fix forces grid lines to be drawn with anti-aliasing (eliminating artifacts from System.Drawing bug) #401 #327
swharden added a commit that referenced this issue May 18, 2020
swharden added a commit that referenced this issue May 18, 2020
small release that just addresses #401
@swharden
Copy link
Member

This should be fixed in ScottPlot 4.0.33 now on NuGet. I'd appreciate your feedback to confirm it works on your machines!

@swharden
Copy link
Member

swharden commented May 18, 2020

FWIW it's not just System.Drawing, this also happens with System.Drawing.Common in .NET Core 2.0 🤔

var plt = new ScottPlot.Plot(400, 300);
plt.Grid(xSpacing: 2, ySpacing: 2, color: Color.Red);
plt.Axis(-13, 13, -10, 10);
plt.GetSettings(false).misc.antiAliasData = false;
plt.GetSettings(false).misc.correctGridRenderingBug = false;
plt.SaveFig("microsoftPleaseExplain.png");

image

but enabling anti-aliasing fixes it 🙈

plt.GetSettings(false).misc.antiAliasData = true;

image

swharden added a commit that referenced this issue May 18, 2020
swharden added a commit that referenced this issue May 18, 2020
swharden added a commit that referenced this issue May 18, 2020
safely creates pens to control bugs like #401 and #327
swharden added a commit that referenced this issue May 18, 2020
permanently solves #401 and #327
swharden added a commit that referenced this issue May 18, 2020
@swharden
Copy link
Member

SOLVED: Never create a solid Pen.DashPattern (set Pen.DashStyle to Solid instead)

Assigning a dash pattern (even a solid one) automatically switches a pen's DashPattern from Solid to Custom. Custom dash patterns produce rendering artifacts when anti-aliasing is off. They're also less performant.

I searched the code and removed all instances where the DashPattern was manually set.
https://github.com/swharden/ScottPlot/search?q=dashpattern&unscoped_q=dashpattern

I created a helper function to safely make pens:
https://github.com/swharden/ScottPlot/blob/f9c1c8bedc8c0c6da98084867b949178c3036f38/src/ScottPlot/Drawing/GDI.cs#L63-L97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG unexpected behavior
Projects
None yet
Development

No branches or pull requests

3 participants