-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix hover label positioning for bar trace with set width
#1527
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
Changes from 5 commits
7a4154f
c84e2a9
591bd9e
b34d9ef
30bc8c7
06097d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,9 +48,7 @@ module.exports = function plot(gd, plotinfo, cdbar) { | |
var t = d[0].t, | ||
trace = d[0].trace, | ||
poffset = t.poffset, | ||
poffsetIsArray = Array.isArray(poffset), | ||
barwidth = t.barwidth, | ||
barwidthIsArray = Array.isArray(barwidth); | ||
poffsetIsArray = Array.isArray(poffset); | ||
|
||
d3.select(this).selectAll('g.point') | ||
.data(Lib.identity) | ||
|
@@ -61,7 +59,7 @@ module.exports = function plot(gd, plotinfo, cdbar) { | |
// log values go off-screen by plotwidth | ||
// so you see them continue if you drag the plot | ||
var p0 = di.p + ((poffsetIsArray) ? poffset[i] : poffset), | ||
p1 = p0 + ((barwidthIsArray) ? barwidth[i] : barwidth), | ||
p1 = p0 + di.w, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a little follow-on benefit of adding |
||
s0 = di.b, | ||
s1 = s0 + di.s; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,7 @@ function setOffsetAndWidth(gd, pa, sieve) { | |
applyAttributes(sieve); | ||
|
||
// store the bar center in each calcdata item | ||
setBarCenter(gd, pa, sieve); | ||
setBarCenterAndWidth(gd, pa, sieve); | ||
|
||
// update position axes | ||
updatePositionAxis(gd, pa, sieve); | ||
|
@@ -286,7 +286,7 @@ function setOffsetAndWidthInGroupMode(gd, pa, sieve) { | |
applyAttributes(sieve); | ||
|
||
// store the bar center in each calcdata item | ||
setBarCenter(gd, pa, sieve); | ||
setBarCenterAndWidth(gd, pa, sieve); | ||
|
||
// update position axes | ||
updatePositionAxis(gd, pa, sieve, overlap); | ||
|
@@ -377,7 +377,7 @@ function applyAttributes(sieve) { | |
} | ||
|
||
|
||
function setBarCenter(gd, pa, sieve) { | ||
function setBarCenterAndWidth(gd, pa, sieve) { | ||
var calcTraces = sieve.traces, | ||
pLetter = getAxisLetter(pa); | ||
|
||
|
@@ -392,9 +392,11 @@ function setBarCenter(gd, pa, sieve) { | |
for(var j = 0; j < calcTrace.length; j++) { | ||
var calcBar = calcTrace[j]; | ||
|
||
// store the actual bar width and position, for use by hover | ||
var width = calcBar.w = (barwidthIsArray) ? barwidth[j] : barwidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect we could clean up the hover routine quite a bit more if we stopped using |
||
calcBar[pLetter] = calcBar.p + | ||
((poffsetIsArray) ? poffset[j] : poffset) + | ||
((barwidthIsArray) ? barwidth[j] : barwidth) / 2; | ||
width / 2; | ||
|
||
|
||
} | ||
|
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.
fixes the "compare" part of #1317 - at least if the bar is wider than our default. I guess if it's narrower and there are other things on the plot, we could be accepting this point when we shouldn't be... maybe I'll look at that case tomorrow and see if I can trigger it.
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.
Alright, the only case I can see where this pops up is an explicitly narrow (
width<1
) single bar with other things on the plot as well, like:then the hoverable region for the bar is so wide it actually extends past the scatter point. But the scatter point still wins when you'd want it to. So if that's all it is, I don't feel like it's worth addressing this very obscure edge case, it'd be just as likely to cause other problems.
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.
I agree with ⬆️ . Thanks for documenting it!