Skip to content

Commit

Permalink
keep waterfall totals hover as is - dont add delta for totals
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jun 17, 2019
1 parent 8cca543 commit 8432d8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
42 changes: 20 additions & 22 deletions src/traces/waterfall/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var vAxis = isHorizontal ? pointData.xa : pointData.ya;

function formatNumber(a) {
return (a === undefined) ? '' : hoverLabelText(vAxis, a);
return hoverLabelText(vAxis, a);
}

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

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

if(di.isSum) {
point.final = undefined;
point.initial = undefined;
point.delta = size - di.b;
} else {
if(!di.isSum) {
point.initial = di.b + di.s - size;
point.delta = size;
point.final = point.initial + point.delta;
}

var v = formatNumber(Math.abs(point.delta));
point.deltaLabel = size < 0 ? '(' + v + ')' : v;
point.finalLabel = formatNumber(point.final);
point.initialLabel = formatNumber(point.initial);
var v = formatNumber(Math.abs(point.delta));
point.deltaLabel = size < 0 ? '(' + v + ')' : v;
point.finalLabel = formatNumber(point.final);
point.initialLabel = formatNumber(point.initial);
}

var hoverinfo = di.hi || trace.hoverinfo;
var text = [];
Expand All @@ -60,18 +56,20 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {

var hasFlag = function(flag) { return isAll || parts.indexOf(flag) !== -1; };

if(hasFlag('final') && point.finalLabel !== '') {
text.push(point.finalLabel);
}
if(hasFlag('delta') && point.deltaLabel !== '') {
if(size < 0) {
text.push(point.deltaLabel + ' ' + DIRSYMBOL.decreasing);
} else {
text.push(point.deltaLabel + ' ' + DIRSYMBOL.increasing);
if(!di.isSum) {
if(hasFlag('final')) {
text.push(point.finalLabel);
}
if(hasFlag('delta')) {
if(size < 0) {
text.push(point.deltaLabel + ' ' + DIRSYMBOL.decreasing);
} else {
text.push(point.deltaLabel + ' ' + DIRSYMBOL.increasing);
}
}
if(hasFlag('initial')) {
text.push('Initial: ' + point.initialLabel);
}
}
if(hasFlag('initial') && point.initialLabel !== '') {
text.push('Initial: ' + point.initialLabel);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/jasmine/tests/waterfall_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ describe('waterfall hover', function() {
.then(function() {
var out = _hover(gd, 0, 1000.5, 'closest');
expect(out.yLabelVal).toEqual(1002.201);
expect(out.extraText).toEqual('$2.2m ▲');
expect(out.extraText).toEqual(undefined);
expect(out.style).toEqual([0, '#4499FF', 0, 1002.201]);
})
.then(function() {
Expand All @@ -1534,7 +1534,7 @@ describe('waterfall hover', function() {
.then(function() {
var out = _hover(gd, 2, 1000.5, 'closest');
expect(out.yLabelVal).toEqual(1001.101);
expect(out.extraText).toEqual('$1.1m ▲');
expect(out.extraText).toEqual(undefined);
expect(out.style).toEqual([2, '#4499FF', 2, 1001.101]);
})
.then(function() {
Expand All @@ -1546,7 +1546,7 @@ describe('waterfall hover', function() {
.then(function() {
var out = _hover(gd, 4, 1000.5, 'closest');
expect(out.yLabelVal).toEqual(1004.401);
expect(out.extraText).toEqual('$4.4m ▲');
expect(out.extraText).toEqual(undefined);
expect(out.style).toEqual([4, '#4499FF', 4, 1004.401]);
})
.catch(failTest)
Expand Down

0 comments on commit 8432d8f

Please sign in to comment.