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

Fix rangeslider titles with stacked y axes #2451

Merged
merged 4 commits into from
Mar 7, 2018

Conversation

alexcjohnson
Copy link
Collaborator

Fixes #2443 - this was actually two issues in one:

  • rangeslider positioning didn't take into account all linked y axes, just the main one.
  • the default anchors for cartesian axes were chosen prior to sorting the axis lists - so if y2 showed up in the data before y, then y2 became the default.

I also noticed while working on this that titles with xaxis.side = 'top' was mangled. I simplified the whole business by having the rangeslider itself draw the (bottom) title and bailing out of title drawing in Axes.doTicks.

cc @etpinard

we were sorting too late, so if 'y2' was referenced before 'y' in gd.data,
it would become the default anchor for x axes.
@alexcjohnson alexcjohnson added bug something broken regression this used to work labels Mar 7, 2018
y: y + opts._height + opts._offsetShift + 10 + 1.5 * axisOpts.titlefont.size,
'text-anchor': 'middle'
}
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Where to put this Titles.draw call totally confused me. First I put it after Plots.automargin below... that failed, calling Titles.draw twice: first with the adjusted margins and THEN with the un-adjusted margins - the reason being that Plots.autoMargin invokes a whole new Plotly.plot call, and in that one we get the adjusted margin, but then after that we come back here and draw the title with the original margin. Instead, I had to put it here, so that the draw with the original margin happens before we adjust the margins, then the draw with the adjusted margin happens inside Plots.autoMargin. Or I suppose I could have added some MathJax so Plots.autoMargin would be async, that would have fixed it too 🙄

@etpinard this is what got me thinking about altering our plotting pipeline with some intermediate step that's just concerned with arranging all the components but doesn't draw anything other than prerendering and stashing all the text we need sizes for.

Also, I started trying to pull out the 10 + 1.5 * axisOpts.titlefont.size that's repeated from Axes.doTicks into some sort of Titles.offset function (that's why I started changing the structure in titles/index), but gave up for now as there's too much logic concerning side and other axis attributes in doTicks.

Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

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

Thanks for diving in there. It feels like there's still a lot of unexplored territories within the range sliders attribute space (cc #2364), but looks like things are getting more robust in every release we make ⛏️

// title goes next to range slider instead of tick labels, so
// just take it over and draw it from here
if(axisOpts.side === 'bottom') {
Titles.draw(gd, axisOpts._id + 'title', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution!

placeholder: fullLayout._dfltTitle.x,
attributes: {
x: axisOpts._offset + axisOpts._length / 2,
y: y + opts._height + opts._offsetShift + 10 + 1.5 * axisOpts.titlefont.size,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, that 10 px offset comes from eyeballing it?

Copy link
Contributor

Choose a reason for hiding this comment

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

... or is there a similar offset for range-slider-less axes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

copied from doTicks

var titleStandoff = 10 + fontSize * offsetBase +

That's what made me start to try and abstract this out, before deciding the logic was a little too convoluted to want to tackle it right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great. Thanks!

@@ -1390,6 +1385,11 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
Cartesian.finalizeSubplots(layoutIn, layoutOut);
}

// sort subplot lists
for(var subplotType in layoutOut._subplots) {
layoutOut._subplots[subplotType].sort(Lib.subplotSort);
Copy link
Contributor

Choose a reason for hiding this comment

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

So, if I get this right, PR #2227 (which got merged in 1.32.0) is the culprit for #2443 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think so, at least that was the main part of it.

"rangeslider": {}
"rangeslider": {},
"title": "X",
"side": "top"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice touch 🥇

"layout": {
"xaxis": {"rangeslider": {}, "title": "x"},
"yaxis": {"title": "y", "domain": [0, 0.25]},
"yaxis2": {"title": "y2", "domain": [ 0.3, 1]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Referencing #2172 and more specifically #2172 (comment) - so if I understand correctly, the baseline for this mock is wrong as the desired behavior would be replicate the stacked y-axes in the range slider?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, most likely this mock will change with #2172. Though reconciling #2172 with #2364 may be a bit of a challenge...

var tickHeight = (axisOpts._boundingBox || {}).height || 0;

var oppBottom = Infinity;
var subplotData = Axes.getSubplots(gd, axisOpts);
Copy link
Contributor

Choose a reason for hiding this comment

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

... I hope these patched lines won't conflict with #2364

@etpinard
Copy link
Contributor

etpinard commented Mar 7, 2018

Great. Looks like all my questions have been answered 💃 (or maybe wait until #2364 is merged - your call)

@alexcjohnson alexcjohnson merged commit 2ff1c85 into master Mar 7, 2018
@alexcjohnson alexcjohnson deleted the rangeslider-stacked-y branch March 7, 2018 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken regression this used to work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants