Skip to content

Commit 8ed6474

Browse files
committed
revise waterfall hover formats - remove Final
1 parent 2c60ebb commit 8ed6474

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/traces/waterfall/hover.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
2828
var vAxis = isHorizontal ? pointData.xa : pointData.ya;
2929

3030
function formatNumber(a) {
31-
return hoverLabelText(vAxis, a);
31+
return (a === undefined) ? '' : hoverLabelText(vAxis, a);
3232
}
3333

3434
// the closest data point
@@ -37,19 +37,20 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
3737

3838
var size = (di.isSum) ? di.b + di.s : di.rawS;
3939

40-
if(!di.isSum) {
40+
if(di.isSum) {
41+
point.final = undefined;
42+
point.initial = undefined;
43+
point.delta = size - di.b;
44+
} else {
4145
point.initial = di.b + di.s - size;
4246
point.delta = size;
4347
point.final = point.initial + point.delta;
44-
} else {
45-
point.final = size;
46-
point.initial = di.b;
47-
point.delta = point.final - point.initial;
4848
}
4949

50+
var v = formatNumber(Math.abs(point.delta));
51+
point.deltaLabel = size < 0 ? '(' + v + ')' : v;
5052
point.finalLabel = formatNumber(point.final);
51-
point.deltaLabel = formatNumber(Math.abs(point.delta));
52-
point.initialLabel = formatNumber(point.initial, 1);
53+
point.initialLabel = formatNumber(point.initial);
5354

5455
var hoverinfo = di.hi || trace.hoverinfo;
5556
var text = [];
@@ -60,11 +61,11 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
6061
var hasFlag = function(flag) { return isAll || parts.indexOf(flag) !== -1; };
6162

6263
if(hasFlag('final') && point.finalLabel !== '') {
63-
text.push('Final: ' + point.finalLabel);
64+
text.push(point.finalLabel);
6465
}
6566
if(hasFlag('delta') && point.deltaLabel !== '') {
6667
if(size < 0) {
67-
text.push('(' + point.deltaLabel + ') ' + DIRSYMBOL.decreasing);
68+
text.push(point.deltaLabel + ' ' + DIRSYMBOL.decreasing);
6869
} else {
6970
text.push(point.deltaLabel + ' ' + DIRSYMBOL.increasing);
7071
}

test/jasmine/tests/waterfall_test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ describe('waterfall hover', function() {
13791379
.then(done);
13801380
});
13811381

1382-
it('should turn off percentages with hoveinfo none or skip', function(done) {
1382+
it('should turn off hoverinfo flags with hoveinfo none or skip', function(done) {
13831383
gd = createGraphDiv();
13841384

13851385
var mock = Lib.extendDeep({}, require('@mocks/text_chart_arrays'));
@@ -1406,7 +1406,7 @@ describe('waterfall hover', function() {
14061406
.then(done);
14071407
});
14081408

1409-
it('should turn on percentages with hoveinfo all', function(done) {
1409+
it('should turn on hoverinfo flags with hoveinfo all', function(done) {
14101410
gd = createGraphDiv();
14111411

14121412
var mock = Lib.extendDeep({}, require('@mocks/text_chart_arrays'));
@@ -1426,9 +1426,9 @@ describe('waterfall hover', function() {
14261426
.then(function() {
14271427
assertHoverLabelContent({
14281428
nums: [
1429-
'1001\nHover text A\nFinal: 1001\n1 ▲\nInitial: 1000',
1430-
'1002\nHover text G\nFinal: 1002\n2 ▲\nInitial: 1000',
1431-
'1,001.5\na (hover)\nFinal: 1,001.5\n1.5 ▲\nInitial: 1000'
1429+
'1001\nHover text A\n1001\n1 ▲\nInitial: 1000',
1430+
'1002\nHover text G\n1002\n2 ▲\nInitial: 1000',
1431+
'1,001.5\na (hover)\n1,001.5\n1.5 ▲\nInitial: 1000'
14321432
],
14331433
name: ['Lines, Marke...', 'Lines and Text', 'missing text'],
14341434
axis: '0'
@@ -1486,7 +1486,7 @@ describe('waterfall hover', function() {
14861486
})
14871487
.then(function() {
14881488
assertHoverLabelContent({
1489-
nums: '2.2\nFinal: 2.2\n4.4 ▲\nInitial: −2.2',
1489+
nums: '2.2\n2.2\n4.4 ▲\nInitial: −2.2',
14901490
name: '',
14911491
axis: 'E'
14921492
});
@@ -1522,31 +1522,31 @@ describe('waterfall hover', function() {
15221522
.then(function() {
15231523
var out = _hover(gd, 0, 1000.5, 'closest');
15241524
expect(out.yLabelVal).toEqual(1002.201);
1525-
expect(out.extraText).toEqual('Final: $1,002.201m<br>$2.2m ▲<br>Initial: $1,000.001m');
1525+
expect(out.extraText).toEqual('$2.2m ▲');
15261526
expect(out.style).toEqual([0, '#4499FF', 0, 1002.201]);
15271527
})
15281528
.then(function() {
15291529
var out = _hover(gd, 1, 1000.5, 'closest');
15301530
expect(out.yLabelVal).toEqual(1001.101);
1531-
expect(out.extraText).toEqual('Final: $1,001.101m<br>($1.1m) ▼<br>Initial: $1,002.201m');
1531+
expect(out.extraText).toEqual('$1,001.101m<br>($1.1m) ▼<br>Initial: $1,002.201m');
15321532
expect(out.style).toEqual([1, '#FF4136', 1, 1001.101]);
15331533
})
15341534
.then(function() {
15351535
var out = _hover(gd, 2, 1000.5, 'closest');
15361536
expect(out.yLabelVal).toEqual(1001.101);
1537-
expect(out.extraText).toEqual('Final: $1,001.101m<br>$1.1m ▲<br>Initial: $1,000.001m');
1537+
expect(out.extraText).toEqual('$1.1m ▲');
15381538
expect(out.style).toEqual([2, '#4499FF', 2, 1001.101]);
15391539
})
15401540
.then(function() {
15411541
var out = _hover(gd, 3, 1000.5, 'closest');
15421542
expect(out.yLabelVal).toEqual(1004.401);
1543-
expect(out.extraText).toEqual('Final: $1,004.401m<br>$3.3m ▲<br>Initial: $1,001.101m');
1543+
expect(out.extraText).toEqual('$1,004.401m<br>$3.3m ▲<br>Initial: $1,001.101m');
15441544
expect(out.style).toEqual([3, '#3D9970', 3, 1004.401]);
15451545
})
15461546
.then(function() {
15471547
var out = _hover(gd, 4, 1000.5, 'closest');
15481548
expect(out.yLabelVal).toEqual(1004.401);
1549-
expect(out.extraText).toEqual('Final: $1,004.401m<br>$4.4m ▲<br>Initial: $1,000.001m');
1549+
expect(out.extraText).toEqual('$4.4m ▲');
15501550
expect(out.style).toEqual([4, '#4499FF', 4, 1004.401]);
15511551
})
15521552
.catch(failTest)

0 commit comments

Comments
 (0)