-
-
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
Format numbers in waterfall hover #3711
Conversation
@@ -34,16 +38,16 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | |||
if(!di.isSum) { | |||
// format delta numbers: | |||
if(size > 0) { | |||
point.extraText = size + ' ' + DIRSYMBOL.increasing; | |||
point.extraText = formatNumber(size) + ' ' + DIRSYMBOL.increasing; |
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.
Use Axes.hoverLabelText
, it's made specifically for this purpose:
plotly.js/src/traces/box/hover.js
Line 170 in c657348
pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val); |
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 review @alexcjohnson.
Revised in 07b6c9c.
} else { | ||
point[sizeLetter + 'LabelVal'] = size; | ||
point[sizeLetter + 'LabelVal'] = formatNumber(size); |
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.
not quite sure where this would break down, but in principle *LabelVal
should be a number, and *Label
should be the string you want to use to display that number.
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.
Perhaps non-default separators, or tickprefix/suffix, would break this as is
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.
In bar
traces we use a similar pattern:
plotly.js/src/traces/bar/hover.js
Line 138 in 07b6c9c
pointData[sizeLetter + 'LabelVal'] = size; |
Do you think there would be a problem there?
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.
Bar uses *LabelVal
correctly, it's a number. I'm guessing that if there's no *Label
then later on *LabelVal
gets converted to a string using hoverLabelText
but I don't know. If so, perhaps you can just leave this one as a number too.
Whew, the hover system is certainly ripe for refactoring... or at least documenting.
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.
Whew, the hover system is certainly ripe for refactoring... or at least documenting.
🙏
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.
Bar uses
*LabelVal
correctly, it's a number. I'm guessing that if there's no*Label
then later on*LabelVal
gets converted to a string usinghoverLabelText
but I don't know. If so, perhaps you can just leave this one as a number too.
OK. Let's keep this as it is in this PR.
Nice fix. Good enough to be released in 1.46.1 💃 |
Fix #3710 by rounding 10 digits then parsing as float.
Codepen.
@plotly/plotly_js