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

Provide room for large computed margins #5237

Merged
merged 6 commits into from
Nov 4, 2020
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Oct 27, 2020

Fixes #4459 and fixes #4835.

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Oct 27, 2020
@@ -1900,11 +1900,11 @@ plots.autoMargin = function(gd, id, o) {

// if the item is too big, just give it enough automargin to
// make sure you can still grab it and bring it back
if(o.l + o.r > fullLayout.width * 0.5) {
if(o.l + o.r > fullLayout.width) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would mean your automargin can expand so much the plot itself completely disappears. That doesn't seem like a good idea. I'm also concerned about what would happen if you have large margin pushers on opposite sides - tick labels on the left and legend on the right, for example. I suspect that with the 0.5 that was here before you could in principle get right up to the edge of no visible plot but not quite pass it.

Perhaps rather than discarding the constraint, a better solution would be to just limit the end result?

  • First constrain each individual value here (o.l, o.r etc) to no more than half the total size, which I think should ensure there IS a solution to the loop trying to satisfy all these constraints
  • Then once we have candidate margins here we can reduce them as necessary to ensure there's still some visible plot area. Perhaps don't allow the plot area to be smaller than 1/4 the total size? And if a reduction is needed, decrease both margins by the same factor as long as neither becomes less than the input layout.margin value - in that case take more from the other side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson Thanks for the review and pointers.
I added an image test in 09e2339.
Noting that in this example we wanted the lower margin to be greater than half of the size, I still think that to fix this bug we should relax the constraint there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m OK with allowing one margin to be bigger than half the plot, as long as (a) there are no situations where we fail entirely (large margins on both sides from different elements - this will need a test or two) and (b) the plot never becomes too small to be useful (I suggest minimum 1/4 the total size but we could go a little further if you think it important)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(b) the plot never becomes too small to be useful (I suggest minimum 1/4 the total size but we could go a little further if you think it important)
I can imagine of cases where one wants to dedicate 7/8 (or even more) of the plot area to the labels and the graph still look nicely on the remaining 1/8 part.
How about declaring the minimum in pixels? Something like 100px for now which could also be configured later as minwidth & minheight in layout or margin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a) there are no situations where we fail entirely (large margins on both sides from different elements - this will need a test or two)

While testing this with margins on both sides I didn't encounter a major change between before and after behaviour in respect to this change.
In fact the change here basically allows one margin to be bigger than half of the plot not both which is the reported bug.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea - layout.margin.minfinal(width|height) perhaps, with a default of something like 100 (px).

Copy link
Contributor Author

@archmoj archmoj Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Addressed in 28fc880.
And we could expose those constants (also with a relative option) in a separate PR.

@archmoj archmoj force-pushed the fix4459-labels-disappear branch from b21d36c to 28fc880 Compare October 28, 2020 20:00
@archmoj archmoj changed the title Provide more room for large computed margins Provide room for large computed margins Nov 2, 2020
@nicolaskruchten
Copy link
Contributor

I like the idea of this new minfinal attribute in principle although I don't love the name and I don't have a better one.

@archmoj archmoj requested a review from alexcjohnson November 3, 2020 23:31
@archmoj
Copy link
Contributor Author

archmoj commented Nov 3, 2020

I like the idea of this new minfinal attribute in principle although I don't love the name and I don't have a better one.

Thanks for the feedback. We could expose this as a new attribute in a separate PR after fixing this bug.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it - nicely done! 💃

@archmoj archmoj merged commit 96d7511 into master Nov 4, 2020
@archmoj archmoj deleted the fix4459-labels-disappear branch November 4, 2020 12:51
@archmoj archmoj added this to the v1.58.0 milestone Dec 2, 2020
@archmoj
Copy link
Contributor Author

archmoj commented Dec 4, 2020

For reference, pasting slack discussion leading to 565f942 commit:

October30

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

Successfully merging this pull request may close these issues.

Y-axis labels going over y-axis title x-axis label disappears in certain cases
3 participants