-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Format numbers in waterfall hover #3711
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 1 commit
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 | ||
---|---|---|---|---|
|
@@ -16,6 +16,10 @@ var DIRSYMBOL = { | |||
decreasing: '▼' | ||||
}; | ||||
|
||||
function formatNumber(a) { | ||||
return parseFloat(a.toPrecision(10)); | ||||
} | ||||
|
||||
module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | ||||
var point = hoverOnBars(pointData, xval, yval, hovermode); | ||||
if(!point) return; | ||||
|
@@ -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; | ||||
} else if(size < 0) { | ||||
point.extraText = '(' + (-size) + ') ' + DIRSYMBOL.decreasing; | ||||
point.extraText = '(' + (formatNumber(-size)) + ') ' + DIRSYMBOL.decreasing; | ||||
} else { | ||||
return; | ||||
} | ||||
// display initial value | ||||
point.extraText += '<br>Initial: ' + (di.b + di.s - size); | ||||
point.extraText += '<br>Initial: ' + formatNumber(di.b + di.s - size); | ||||
} else { | ||||
point[sizeLetter + 'LabelVal'] = size; | ||||
point[sizeLetter + 'LabelVal'] = formatNumber(size); | ||||
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. not quite sure where this would break down, but in principle 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. In plotly.js/src/traces/bar/hover.js Line 138 in 07b6c9c
Do you think there would be a problem there? 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. Bar uses 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
OK. Let's keep this as it is in this PR. |
||||
} | ||||
|
||||
point.color = getTraceColor(trace, di); | ||||
|
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
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.