Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07b6c9c

Browse files
committed
apply hoverLabelText in waterfall hover
1 parent ebec807 commit 07b6c9c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/traces/waterfall/hover.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,34 @@
88

99
'use strict';
1010

11-
var Color = require('../../components/color');
11+
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText;
12+
var opacity = require('../../components/color').opacity;
1213
var hoverOnBars = require('../bar/hover').hoverOnBars;
1314

1415
var DIRSYMBOL = {
1516
increasing: '▲',
1617
decreasing: '▼'
1718
};
1819

19-
function formatNumber(a) {
20-
return parseFloat(a.toPrecision(10));
21-
}
22-
2320
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
2421
var point = hoverOnBars(pointData, xval, yval, hovermode);
2522
if(!point) return;
2623

2724
var cd = point.cd;
2825
var trace = cd[0].trace;
26+
var isHorizontal = (trace.orientation === 'h');
27+
28+
var vAxis = isHorizontal ? pointData.xa : pointData.ya;
29+
30+
function formatNumber(a) {
31+
return hoverLabelText(vAxis, a);
32+
}
2933

3034
// the closest data point
3135
var index = point.index;
3236
var di = cd[index];
3337

34-
var sizeLetter = (trace.orientation === 'h') ? 'x' : 'y';
38+
var sizeLetter = isHorizontal ? 'x' : 'y';
3539

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

@@ -60,6 +64,6 @@ function getTraceColor(trace, di) {
6064
var mc = cont.color;
6165
var mlc = cont.line.color;
6266
var mlw = cont.line.width;
63-
if(Color.opacity(mc)) return mc;
64-
else if(Color.opacity(mlc) && mlw) return mlc;
67+
if(opacity(mc)) return mc;
68+
else if(opacity(mlc) && mlw) return mlc;
6569
}

test/jasmine/tests/waterfall_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ describe('waterfall hover', function() {
12961296

12971297
Plotly.plot(gd, {
12981298
data: [{
1299-
x: [1, 2, 3, 4, 5],
1299+
x: ['A', 'B', 'C', 'D', 'E'],
13001300
y: [0, -1.1, 2.2, -3.3, 4.4],
13011301
type: 'waterfall'
13021302
}],
@@ -1308,9 +1308,9 @@ describe('waterfall hover', function() {
13081308
})
13091309
.then(function() {
13101310
assertHoverLabelContent({
1311-
nums: '2.2\n4.4 ▲\nInitial: -2.2',
1311+
nums: '2.2\n4.4 ▲\nInitial: 2.2',
13121312
name: '',
1313-
axis: '5'
1313+
axis: 'E'
13141314
});
13151315
})
13161316
.catch(failTest)

0 commit comments

Comments
 (0)