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

Clean up automargin pipeline a bit #3323

Merged
merged 7 commits into from
Dec 11, 2018
Merged

Conversation

alexcjohnson
Copy link
Collaborator

@etpinard I based this branch off multicategory (including commits from this morning) because we were both working in axis drawing code.

The main goal was to get plots.doAutoMargin out of supplyDefaults - because that can lead to a full redraw of the plot if margins have changed, which is completely inappropriate for supplyDefaults - somehow it never caused explicit problems before, but with big enough changes in Plotly.react, ie #3255, it does.

It turned out the biggest challenge with this was rangesliders. The main thing I did to fix this was to combine rangeslider and axis automargins to happen together - note though that in principle both can contribute independently to the margins, if you have a rangeslider (on the bottom) and a top axis with long labels (oh right, I meant to add a test for that case - I'll add that)

One baseline image, range_slider_rangemode, changed in this PR b2a4b76 - just a little bit, but I believe it was in fact wrong before, as you can see by interacting with this mock on master: start dragging the range and the box expands vertically a little bit, to match what's in the new baseline. On this branch there's no such jump. Not quite sure what in this PR fixed it 😅 but it's fixed.
range_slider_rangemode

@alexcjohnson alexcjohnson added the bug something broken label Dec 11, 2018
// Figure out which subplot to draw ticks, labels, & axis lines on
// do this as a separate loop so we already have all the
// _mainAxis and _anchorAxis links set
ax._mainSubplot = findMainSubplot(ax, fullLayout);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved this into plots.linkSubplots, which is both a more obvious place for it and happens earlier (in supplyDefaults) so _mainSubplot is available sooner.

};

function findMainSubplot(ax, fullLayout) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is moving findMainSubplot from lsInner to supplyDefaults necessary? I suspect this will make supplyDefaults for large splom traces significantly slower.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Something or other failed with it in lsInner, though I don't recall what. I'll take a look at 🐎 for large sploms, I'm sure there's a shortcut we can take there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure there's a shortcut we can take there.

Yeah, I would be nice to leave findMainSubplot in supplyDefaults and add a fullLayout._hasOnlyLargeSploms condition to bypass the loop-over-subplot-for-all-axes loops.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Large sploms usually avoid the subplot loop there - the first try based on _anchorAxis works unless the labels are unanchored - upper half with lower labels, or both halves with no diagonal.

Anyway I added an extra collection of counteraxes and subplots per axis in f55e769, which means we don't have to search the full subplot list anymore here (and in fact Axes.getSubplots is completely unused within plotly.js, but we still have it in streambed ATM). So even when splom does go through this loop, it now only takes 0.3ms at 20 dimensions - ~2ms at 50 dimensions if it's O(n^2).

Copy link
Contributor

Choose a reason for hiding this comment

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

works unless the labels are unanchored - upper half with lower labels, or both halves with no diagonal.

Ha right, I remember making that happen 3 or 4 splom-perf PRs ago.

So even when splom does go through this loop, it now only takes 0.3ms at 20 dimensions - ~2ms at 50 dimensions if it's O(n^2).

Beautiful 🐎

@etpinard
Copy link
Contributor

The main goal was to get plots.doAutoMargin out of supplyDefaults - because that can lead to a full redraw of the plot if margins have changed, which is completely inappropriate for supplyDefaults

This is fantastic 🎉

but I believe it was in fact wrong before, as you can see by interacting with this mock on master: start dragging the range and the box expands vertically a little bit, to match what's in the new baseline.

Yeah, I agree. The current baseline appears wrong. 👌

@etpinard etpinard added this to the v1.43.0 milestone Dec 11, 2018
this means Axes.getSubplots and Axes.findSubplotsWithAxis are
essentially unused internally, but we have some outside callers
using getSubplots
@alexcjohnson
Copy link
Collaborator Author

note though that in principle both can contribute independently to the margins, if you have a rangeslider (on the bottom) and a top axis with long labels (oh right, I meant to add a test for that case - I'll add that)

Working on this has uncovered some more bugs - will address those in a separate bugfix PR.

@etpinard
Copy link
Contributor

💃 let's get this in #3300

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.

2 participants