Skip to content

Commit 1b7fba1

Browse files
committed
bring parts of the previous logic - use (x|y)End instead of pEnd etc.
1 parent 2c07925 commit 1b7fba1

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

src/components/fx/hover.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1993,14 +1993,13 @@ function getCoord(axLetter, winningPoint, fullLayout) {
19931993
var ax = winningPoint[axLetter + 'a'];
19941994
var val = winningPoint[axLetter + 'Val'];
19951995

1996-
var trace = winningPoint.trace;
1997-
var cd = winningPoint.cd;
1998-
var d = cd[winningPoint.index];
1996+
var cd0 = winningPoint.cd[0];
19991997

20001998
if(ax.type === 'category') val = ax._categoriesMap[val];
20011999
else if(ax.type === 'date') {
2002-
var periodalignment = trace[axLetter + 'periodalignment'];
2000+
var periodalignment = winningPoint.trace[axLetter + 'periodalignment'];
20032001
if(periodalignment) {
2002+
var d = winningPoint.cd[winningPoint.index];
20042003
var start = d[axLetter + 'Start'];
20052004
var end = d[axLetter + 'End'];
20062005
var diff = end - start;
@@ -2014,7 +2013,6 @@ function getCoord(axLetter, winningPoint, fullLayout) {
20142013
val = ax.d2c(val);
20152014
}
20162015

2017-
var cd0 = cd[0];
20182016
if(cd0 && cd0.t && cd0.t.posLetter === ax._id) {
20192017
if(
20202018
fullLayout.boxmode === 'group' ||

src/traces/bar/calc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var calcSelection = require('../scatter/calc_selection');
1010
module.exports = function calc(gd, trace) {
1111
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
1212
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
13-
var size, pos, origPos, pObj, hasPeriod;
13+
var size, pos, origPos, pObj, hasPeriod, pLetter;
1414

1515
var sizeOpts = {
1616
msUTC: !!(trace.base || trace.base === 0)
@@ -21,11 +21,13 @@ module.exports = function calc(gd, trace) {
2121
origPos = ya.makeCalcdata(trace, 'y');
2222
pObj = alignPeriod(trace, ya, 'y', origPos);
2323
hasPeriod = !!trace.yperiodalignment;
24+
pLetter = 'y';
2425
} else {
2526
size = ya.makeCalcdata(trace, 'y', sizeOpts);
2627
origPos = xa.makeCalcdata(trace, 'x');
2728
pObj = alignPeriod(trace, xa, 'x', origPos);
2829
hasPeriod = !!trace.xperiodalignment;
30+
pLetter = 'x';
2931
}
3032
pos = pObj.vals;
3133

@@ -39,8 +41,8 @@ module.exports = function calc(gd, trace) {
3941

4042
if(hasPeriod) {
4143
cd[i].orig_p = origPos[i]; // used by hover
42-
cd[i].pEnd = pObj.ends[i];
43-
cd[i].pStart = pObj.starts[i];
44+
cd[i][pLetter + 'End'] = pObj.ends[i];
45+
cd[i][pLetter + 'Start'] = pObj.starts[i];
4446
}
4547

4648
if(trace.ids) {

src/traces/bar/cross_trace_calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ function setBarCenterAndWidth(pa, sieve) {
448448

449449
if(isPeriod) {
450450
calcBar.wPeriod =
451-
calcBar.pEnd - calcBar.pStart;
451+
calcBar[pLetter + 'End'] - calcBar[pLetter + 'Start'];
452452
}
453453
}
454454
}

src/traces/bar/hover.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
6363
return di[posLetter] + sgn * w / 2;
6464
}
6565

66+
function periodLength(di) {
67+
return di[posLetter + 'End'] - di[posLetter + 'Start'];
68+
}
69+
6670
var minPos = isClosest ?
6771
thisBarMinPos : period ?
6872
function(di) {
69-
var diff = di.pEnd - di.pStart;
70-
return di.p + diff / 2 - di.wPeriod;
73+
return di.p + periodLength(di) / 2 - di.wPeriod;
7174
} :
7275
function(di) {
7376
/*
@@ -88,8 +91,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
8891
var maxPos = isClosest ?
8992
thisBarMaxPos : period ?
9093
function(di) {
91-
var diff = di.pEnd - di.pStart;
92-
return di.p + diff / 2;
94+
return di.p + periodLength(di) / 2;
9395
} :
9496
function(di) {
9597
return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2);

src/traces/funnel/calc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ var BADNUM = require('../../constants/numerical').BADNUM;
99
module.exports = function calc(gd, trace) {
1010
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
1111
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
12-
var size, pos, origPos, pObj, hasPeriod, i, cdi;
12+
var size, pos, origPos, pObj, hasPeriod, pLetter, i, cdi;
1313

1414
if(trace.orientation === 'h') {
1515
size = xa.makeCalcdata(trace, 'x');
1616
origPos = ya.makeCalcdata(trace, 'y');
1717
pObj = alignPeriod(trace, ya, 'y', origPos);
1818
hasPeriod = !!trace.yperiodalignment;
19+
pLetter = 'y';
1920
} else {
2021
size = ya.makeCalcdata(trace, 'y');
2122
origPos = xa.makeCalcdata(trace, 'x');
2223
pObj = alignPeriod(trace, xa, 'x', origPos);
2324
hasPeriod = !!trace.xperiodalignment;
25+
pLetter = 'x';
2426
}
2527
pos = pObj.vals;
2628

@@ -55,8 +57,8 @@ module.exports = function calc(gd, trace) {
5557

5658
if(hasPeriod) {
5759
cd[i].orig_p = origPos[i]; // used by hover
58-
cd[i].pEnd = pObj.ends[i];
59-
cd[i].pStart = pObj.starts[i];
60+
cd[i][pLetter + 'End'] = pObj.ends[i];
61+
cd[i][pLetter + 'Start'] = pObj.starts[i];
6062
}
6163

6264
if(trace.ids) {

src/traces/waterfall/calc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ function isTotal(a) {
1717
module.exports = function calc(gd, trace) {
1818
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
1919
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
20-
var size, pos, origPos, pObj, hasPeriod;
20+
var size, pos, origPos, pObj, hasPeriod, pLetter;
2121

2222
if(trace.orientation === 'h') {
2323
size = xa.makeCalcdata(trace, 'x');
2424
origPos = ya.makeCalcdata(trace, 'y');
2525
pObj = alignPeriod(trace, ya, 'y', origPos);
2626
hasPeriod = !!trace.yperiodalignment;
27+
pLetter = 'y';
2728
} else {
2829
size = ya.makeCalcdata(trace, 'y');
2930
origPos = xa.makeCalcdata(trace, 'x');
3031
pObj = alignPeriod(trace, xa, 'x', origPos);
3132
hasPeriod = !!trace.xperiodalignment;
33+
pLetter = 'x';
3234
}
3335
pos = pObj.vals;
3436

@@ -85,8 +87,8 @@ module.exports = function calc(gd, trace) {
8587

8688
if(hasPeriod) {
8789
cd[i].orig_p = origPos[i]; // used by hover
88-
cd[i].pEnd = pObj.ends[i];
89-
cd[i].pStart = pObj.starts[i];
90+
cd[i][pLetter + 'End'] = pObj.ends[i];
91+
cd[i][pLetter + 'Start'] = pObj.starts[i];
9092
}
9193

9294
if(trace.ids) {

0 commit comments

Comments
 (0)