-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 logic for hiding zero lines when they conflict with axis lines #2936
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic was quite a bit more complicated than just switching ax -> counterAxis..
I had the same feeling when looking at #2874 - it's nice to finally look the behavior down in those tests you wrote.
}) | ||
.then(function() { | ||
// x axis still has a zero line on xy2, and y on x2y | ||
// all the others have disappeared now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the 📚
extraSubplot = (!ya._anchorAxis || subplot !== xa._mainSubplot); | ||
if(extraSubplot && ya.ticks && ya.mirror === 'allticks') { | ||
extraSubplot = (!ya._anchorAxis || subplot !== ya._mainSubplot); | ||
if(extraSubplot && (ya.mirror === 'allticks' || ya.mirror === 'all')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find! Is there a test 🔒 ing this down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, there was a test (the subplot case) locking down the changes but not the parts that remained -> added these in 545ad47
} | ||
} | ||
|
||
function anyCounterAxLineAtZero(counterAxis, rng) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice function name.
src/plots/cartesian/axes.js
Outdated
0 : ax._length | ||
); | ||
|
||
var counterLetterAxes = axes.list(gd, counterLetter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would nice to avoid looping over all axes here.
Can we skip this loop when fullLayout._plots[counterAxis._mainSubplot].overlays
is empty, and only check lineNearZero(counterAxis, zeroPosition)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to hear it was that easy. 💯
var rng = Lib.simpleMap(ax.range, ax.r2l), | ||
showZl = (rng[0] * rng[1] <= 0) && ax.zeroline && | ||
var rng = Lib.simpleMap(ax.range, ax.r2l); | ||
var zlData = {x: 0, id: axid}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need this do in this PR (opening a new issue would be fine), but we'll need to propagate these changes to large-sploms' regl-based grid line logic:
plotly.js/src/traces/splom/base_plot.js
Lines 171 to 183 in b5f8b23
// just like in Axes.doTicks but without the loop over traces | |
function showZeroLine(ax) { | |
var rng = Lib.simpleMap(ax.range, ax.r2l); | |
var p0 = ax.l2p(0); | |
return ( | |
ax.zeroline && | |
ax._vals && ax._vals.length && | |
(rng[0] * rng[1] <= 0) && | |
(ax.type === 'linear' || ax.type === '-') && | |
((p0 > 1 && p0 < ax._length - 1) || !ax.showline) | |
); | |
} |
where I didn't just reuse the axes.js
logic because I wanted to avoid looping over the traces (to compute that hasBarsOrFill
boolean). Thinking about this again, looping over traces isn't really a performance hit for sploms (I can't really imagine a user wanting to plot more 10 splom traces on the same graph).
So it would be worth trying to expose and ♻️ this logic here for large-sploms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for pointing that out! #2938
Great! 💃 Thanks for including that perf fix and opening an issue for the splom case. 🎸 |
Fixes #2874
The logic was quite a bit more complicated than just switching
ax
->counterAxis
... but seems to work in all cases now.cc @etpinard