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

Format numbers in waterfall hover #3711

Merged
merged 2 commits into from
Apr 2, 2019

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Apr 2, 2019

Fix #3710 by rounding 10 digits then parsing as float.
Codepen.
@plotly/plotly_js

@@ -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;
Copy link
Collaborator

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:

pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val);

Copy link
Contributor Author

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.

@etpinard etpinard added the bug something broken label Apr 2, 2019
} else {
point[sizeLetter + 'LabelVal'] = size;
point[sizeLetter + 'LabelVal'] = formatNumber(size);
Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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:

pointData[sizeLetter + 'LabelVal'] = size;
.
Do you think there would be a problem there?

Copy link
Collaborator

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.

Copy link
Contributor

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.

🙏

Copy link
Contributor Author

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.

OK. Let's keep this as it is in this PR.

@etpinard
Copy link
Contributor

etpinard commented Apr 2, 2019

Nice fix. Good enough to be released in 1.46.1 💃

@archmoj archmoj merged commit e8b9009 into master Apr 2, 2019
@archmoj archmoj deleted the fix3710-format-numbers-waterfall-hover branch April 2, 2019 16:33
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.

None yet

3 participants