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

TightenLayout() resets custom layout options #449

Closed
ismdiego opened this issue Jun 4, 2020 · 9 comments
Closed

TightenLayout() resets custom layout options #449

ismdiego opened this issue Jun 4, 2020 · 9 comments

Comments

@ismdiego
Copy link

ismdiego commented Jun 4, 2020

I am using ScottPlot.WinForms 4.0.34, and I have found that if you customize the layout (for instance, changing the xScaleHeight), then when you move or zoom the plot with the mouse, the layout is reset. Other typical use case is when you use long tick labels and a rotation. When the layout is reset you cannot read the full label anymore.

I think I have found the "culprit" in FormsPlot.cs. Both in PbPlot_MouseUp and PbPlot_MouseWheel methods the Render method is called with recalculateLayout: true (hardcoded).

I think that this should be better suited with a configuration setting, like "enableResetLayout" (bool).

Anyway, many thanks for this fantastic library.

@swharden
Copy link
Member

swharden commented Jun 4, 2020

Thanks for the descriptive suggestion @ismdiego!

Like you suggested, I think the problem boils down to this getting called on MouseUp events:
https://github.com/swharden/ScottPlot/blob/01a2621d5e19b9dfad6f9768199f3dcf07d5509f/src/ScottPlot.WinForms/FormsPlot.cs#L99-L100

A good solution would be to ensure this "tightening" respects user-defined padding.

I'll take a closer look this weekend! Thanks again for the suggestion, and I'm happy to hear you enjoy this library 👍

@swharden swharden changed the title Keep layout settings when moving or zooming TightenLayout() resets custom layout options Jun 4, 2020
@swharden
Copy link
Member

swharden commented Jun 9, 2020

doh! I already implemented this and I forgot. You can do this:

formsPlot1.plt.Layout(yLabelWidth: 100, xScaleHeight: 50);
formsPlot1.Configure(recalculateLayoutOnMouseUp: false);

The whole layout system will get refactored to make this easier in the future, but for now this should do the trick! Good luck! 👍

@swharden swharden closed this as completed Jun 9, 2020
@swharden
Copy link
Member

swharden commented Jun 9, 2020

somehow I got confused which version this was in... I just published it on NuGet and that code should work in version 4.0.35 and up

@ismdiego
Copy link
Author

Thank you very much, I confirm that it works as described in 4.0.35 😄

@ismdiego
Copy link
Author

ismdiego commented Jun 10, 2020

By the way, just a quick not-related question, can I lock the Y axis origin when doing zoom when x axis is locked? I mean, not allow Y axis min to be < 0... only >=0. It will be enough if you can point me to one sample or similar and I will investigate further on. I am not asking for a long answer.

Sorry about asking this here... I did not found a community forum or similar. If you prefer I can create a new issue with this content as a feature request or suggestion. Many thanks.

@swharden

This comment has been minimized.

@swharden
Copy link
Member

Hey @ismdiego, sorry about my last post - I accidentally answered a question in #451 in this thread.

can I lock the Y axis origin when doing zoom when x axis is locked?
I mean, not allow Y axis min to be < 0... only >=0

Yeah, I think you can do this with something like (#349)

formsPlot1.plt.AxisBounds(0, 50, -1, 1);

Let me know if that's what you were looking for.

@ismdiego
Copy link
Author

No problem @swharden, I have just tested what you suggested and it works perfectly 😃

Thanks again

@swharden
Copy link
Member

Great to hear! Glad you're enjoying ScottPlot 👍

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

No branches or pull requests

2 participants