-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fixup hoverinfo & hovertemplate initial, delta and final flags for waterfalls #3963
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
2c60ebb
8ed6474
8cca543
8432d8f
0a58836
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
eventDataKeys: [ | ||
'initial', | ||
'delta', | ||
'final' | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function eventData(out, pt /* , trace, cd, pointNumber */) { | ||
// standard cartesian event data | ||
out.x = 'xVal' in pt ? pt.xVal : pt.x; | ||
out.y = 'yVal' in pt ? pt.yVal : pt.y; | ||
|
||
// for funnel | ||
if('initial' in pt) out.initial = pt.initial; | ||
if('delta' in pt) out.delta = pt.delta; | ||
if('final' in pt) out.final = pt.final; | ||
|
||
if(pt.xa) out.xaxis = pt.xa; | ||
if(pt.ya) out.yaxis = pt.ya; | ||
|
||
return out; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1379,13 +1379,72 @@ describe('waterfall hover', function() { | |
.then(done); | ||
}); | ||
|
||
it('should turn off percentages with hoveinfo none or skip', function(done) { | ||
gd = createGraphDiv(); | ||
|
||
var mock = Lib.extendDeep({}, require('@mocks/text_chart_arrays')); | ||
mock.data.forEach(function(t, i) { | ||
t.type = 'waterfall'; | ||
if(i === 0) { | ||
t.hoverinfo = 'none'; | ||
} else { | ||
t.hoverinfo = 'skip'; | ||
} | ||
}); | ||
|
||
function _hover() { | ||
var evt = { xpx: 125, ypx: 150 }; | ||
Fx.hover('graph', evt, 'xy'); | ||
} | ||
|
||
Plotly.plot(gd, mock) | ||
.then(_hover) | ||
.then(function() { | ||
expect(d3.selectAll('g.hovertext').size()).toBe(0); | ||
}) | ||
.catch(failTest) | ||
.then(done); | ||
}); | ||
|
||
it('should turn on percentages with hoveinfo all', function(done) { | ||
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. Looks like a 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. Good eye! It was 2/3am. |
||
gd = createGraphDiv(); | ||
|
||
var mock = Lib.extendDeep({}, require('@mocks/text_chart_arrays')); | ||
mock.data.forEach(function(t) { | ||
t.type = 'waterfall'; | ||
t.base = 1000; | ||
t.hoverinfo = 'all'; | ||
}); | ||
|
||
function _hover() { | ||
var evt = { xpx: 125, ypx: 150 }; | ||
Fx.hover('graph', evt, 'xy'); | ||
} | ||
|
||
Plotly.plot(gd, mock) | ||
.then(_hover) | ||
.then(function() { | ||
assertHoverLabelContent({ | ||
nums: [ | ||
'1001\nHover text A\nFinal: 1001\n1 ▲\nInitial: 1000', | ||
'1002\nHover text G\nFinal: 1002\n2 ▲\nInitial: 1000', | ||
'1,001.5\na (hover)\nFinal: 1,001.5\n1.5 ▲\nInitial: 1000' | ||
], | ||
name: ['Lines, Marke...', 'Lines and Text', 'missing text'], | ||
axis: '0' | ||
}); | ||
}) | ||
.catch(failTest) | ||
.then(done); | ||
}); | ||
|
||
it('should use hovertemplate if specified', function(done) { | ||
gd = createGraphDiv(); | ||
|
||
var mock = Lib.extendDeep({}, require('@mocks/text_chart_arrays')); | ||
mock.data.forEach(function(t) { | ||
t.type = 'waterfall'; | ||
t.hovertemplate = '%{y}<extra></extra>'; | ||
t.hovertemplate = t.hovertemplate = 'Value: %{y}<br>SUM: %{final}<br>START: %{initial}<br>DIFF: %{delta}<extra></extra>'; | ||
}); | ||
|
||
function _hover() { | ||
|
@@ -1397,11 +1456,14 @@ describe('waterfall hover', function() { | |
.then(_hover) | ||
.then(function() { | ||
assertHoverLabelContent({ | ||
nums: ['1', '2', '1.5'], | ||
nums: [ | ||
'Value: 1\nSUM: 1\nSTART: 0\nDIFF: 1', | ||
'Value: 2\nSUM: 2\nSTART: 0\nDIFF: 2', | ||
'Value: 1.5\nSUM: 1.5\nSTART: 0\nDIFF: 1.5' | ||
], | ||
name: ['', '', ''], | ||
axis: '0' | ||
}); | ||
// return Plotly.restyle(gd, 'text', ['APPLE', 'BANANA', 'ORANGE']); | ||
}) | ||
.catch(failTest) | ||
.then(done); | ||
|
@@ -1424,7 +1486,7 @@ describe('waterfall hover', function() { | |
}) | ||
.then(function() { | ||
assertHoverLabelContent({ | ||
nums: '2.2\n4.4 ▲\nInitial: −2.2', | ||
nums: '2.2\nFinal: 2.2\n4.4 ▲\nInitial: −2.2', | ||
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. Hmm. So wait 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. Yes. 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. Was this a requirement anywhere? 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. No. And we could possibly drop that. |
||
name: '', | ||
axis: 'E' | ||
}); | ||
|
@@ -1460,31 +1522,31 @@ describe('waterfall hover', function() { | |
.then(function() { | ||
var out = _hover(gd, 0, 1000.5, 'closest'); | ||
expect(out.yLabelVal).toEqual(1002.201); | ||
expect(out.extraText).toEqual(undefined); | ||
expect(out.extraText).toEqual('Final: $1,002.201m<br>$2.2m ▲<br>Initial: $1,000.001m'); | ||
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. Why did these expectations change? 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. We did not fill any extra text for blue bars (totals). But it is pretty useful to display this info for them for example when there is a 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, but what does initial and final refer to for total bars? 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. The base and top of the bar. 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 don't think base/top here represent inital and final values. 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. Could be displayed in codepen after. 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 agree that initial and final don't make sense in 'total' cases |
||
expect(out.style).toEqual([0, '#4499FF', 0, 1002.201]); | ||
}) | ||
.then(function() { | ||
var out = _hover(gd, 1, 1000.5, 'closest'); | ||
expect(out.yLabelVal).toEqual(1001.101); | ||
expect(out.extraText).toEqual('($1.1m) ▼<br>Initial: $1,002.201m'); | ||
expect(out.extraText).toEqual('Final: $1,001.101m<br>($1.1m) ▼<br>Initial: $1,002.201m'); | ||
expect(out.style).toEqual([1, '#FF4136', 1, 1001.101]); | ||
}) | ||
.then(function() { | ||
var out = _hover(gd, 2, 1000.5, 'closest'); | ||
expect(out.yLabelVal).toEqual(1001.101); | ||
expect(out.extraText).toEqual(undefined); | ||
expect(out.extraText).toEqual('Final: $1,001.101m<br>$1.1m ▲<br>Initial: $1,000.001m'); | ||
expect(out.style).toEqual([2, '#4499FF', 2, 1001.101]); | ||
}) | ||
.then(function() { | ||
var out = _hover(gd, 3, 1000.5, 'closest'); | ||
expect(out.yLabelVal).toEqual(1004.401); | ||
expect(out.extraText).toEqual('$3.3m ▲<br>Initial: $1,001.101m'); | ||
expect(out.extraText).toEqual('Final: $1,004.401m<br>$3.3m ▲<br>Initial: $1,001.101m'); | ||
expect(out.style).toEqual([3, '#3D9970', 3, 1004.401]); | ||
}) | ||
.then(function() { | ||
var out = _hover(gd, 4, 1000.5, 'closest'); | ||
expect(out.yLabelVal).toEqual(1004.401); | ||
expect(out.extraText).toEqual(undefined); | ||
expect(out.extraText).toEqual('Final: $1,004.401m<br>$4.4m ▲<br>Initial: $1,000.001m'); | ||
expect(out.style).toEqual([4, '#4499FF', 4, 1004.401]); | ||
}) | ||
.catch(failTest) | ||
|
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.
this here should be the
deltaLabel
value so thatand
render the same.
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.
As for
Final:
andInitial:
prefixes, they should not be part offinalLabel
/initalLabel
.See example:
https://codepen.io/etpinard/pen/ewJNVJ
In fact, those prefixes should only be there when there are more than 1 of 'initial', 'delta' and 'final' flags.
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 brief,
xLabel
should have the default-formatted label text forx
.I'd argue that the
(v)
around negative deltas should be considered formatting, but theDIRSMBOL
suffixes should not.So in brief,