-
-
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 all commits
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 | ||
---|---|---|---|---|
|
@@ -8,7 +8,8 @@ | |||
|
||||
'use strict'; | ||||
|
||||
var Color = require('../../components/color'); | ||||
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText; | ||||
var opacity = require('../../components/color').opacity; | ||||
var hoverOnBars = require('../bar/hover').hoverOnBars; | ||||
|
||||
var DIRSYMBOL = { | ||||
|
@@ -22,28 +23,35 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { | |||
|
||||
var cd = point.cd; | ||||
var trace = cd[0].trace; | ||||
var isHorizontal = (trace.orientation === 'h'); | ||||
|
||||
var vAxis = isHorizontal ? pointData.xa : pointData.ya; | ||||
|
||||
function formatNumber(a) { | ||||
return hoverLabelText(vAxis, a); | ||||
} | ||||
|
||||
// the closest data point | ||||
var index = point.index; | ||||
var di = cd[index]; | ||||
|
||||
var sizeLetter = (trace.orientation === 'h') ? 'x' : 'y'; | ||||
var sizeLetter = isHorizontal ? 'x' : 'y'; | ||||
|
||||
var size = (di.isSum) ? di.b + di.s : di.rawS; | ||||
|
||||
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); | ||||
|
@@ -56,6 +64,6 @@ function getTraceColor(trace, di) { | |||
var mc = cont.color; | ||||
var mlc = cont.line.color; | ||||
var mlw = cont.line.width; | ||||
if(Color.opacity(mc)) return mc; | ||||
else if(Color.opacity(mlc) && mlw) return mlc; | ||||
if(opacity(mc)) return mc; | ||||
else if(opacity(mlc) && mlw) return mlc; | ||||
} |
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.