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

Skip to content

Commit 5219cb3

Browse files
committed
move init vars up
1 parent b8a452c commit 5219cb3

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/traces/bar/hover.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,36 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
3737
var cd = pointData.cd;
3838
var trace = cd[0].trace;
3939
var t = cd[0].t;
40+
41+
var posVal, sizeVal, posLetter, sizeLetter, dx, dy;
42+
43+
if(trace.orientation === 'h') {
44+
posVal = yval;
45+
sizeVal = xval;
46+
posLetter = 'y';
47+
sizeLetter = 'x';
48+
dx = sizeFn;
49+
dy = positionFn;
50+
} else {
51+
posVal = xval;
52+
sizeVal = yval;
53+
posLetter = 'x';
54+
sizeLetter = 'y';
55+
dy = sizeFn;
56+
dx = positionFn;
57+
}
58+
59+
var sa = pointData[sizeLetter + 'a'];
60+
var pa = pointData[posLetter + 'a'];
61+
var pRangeCalc = Math.abs(
62+
pa.r2c(pa.range[1]) -
63+
pa.r2c(pa.range[0])
64+
);
65+
4066
var isClosest = (hovermode === 'closest');
4167
var isWaterfall = (trace.type === 'waterfall');
4268
var maxHoverDistance = pointData.maxHoverDistance;
4369

44-
var posVal, sizeVal, posLetter, sizeLetter, dx, dy, pRangeCalc;
45-
4670
function thisBarMinPos(di) { return di[posLetter] - di.w / 2; }
4771
function thisBarMaxPos(di) { return di[posLetter] + di.w / 2; }
4872

@@ -104,27 +128,6 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
104128
return Fx.inbox(b - v, s - v, maxHoverDistance + (s - v) / (s - b) - 1);
105129
}
106130

107-
if(trace.orientation === 'h') {
108-
posVal = yval;
109-
sizeVal = xval;
110-
posLetter = 'y';
111-
sizeLetter = 'x';
112-
dx = sizeFn;
113-
dy = positionFn;
114-
} else {
115-
posVal = xval;
116-
sizeVal = yval;
117-
posLetter = 'x';
118-
sizeLetter = 'y';
119-
dy = sizeFn;
120-
dx = positionFn;
121-
}
122-
123-
var pa = pointData[posLetter + 'a'];
124-
var sa = pointData[sizeLetter + 'a'];
125-
126-
pRangeCalc = Math.abs(pa.r2c(pa.range[1]) - pa.r2c(pa.range[0]));
127-
128131
function dxy(di) { return (dx(di) + dy(di)) / 2; }
129132
var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
130133
Fx.getClosest(cd, distfn, pointData);

0 commit comments

Comments
 (0)