Skip to content

Commit c89784d

Browse files
committed
refactor - make getVal function
1 parent f4a465e commit c89784d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/components/fx/hover.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -650,26 +650,12 @@ function _hover(gd, evt, subplot, noHoverEvent) {
650650
hoverData[0].trace.type !== 'splom' // TODO: add support for splom
651651
) {
652652
var winningPoint = hoverData[0];
653-
var cd0 = winningPoint.cd[winningPoint.index];
654653
var isGrouped = (fullLayout.boxmode === 'group' || fullLayout.violinmode === 'group');
655654

656-
var xVal = winningPoint.xVal;
657-
var ax = winningPoint.xa;
658-
if(ax.type === 'category') xVal = ax._categoriesMap[xVal];
659-
if(ax.type === 'date') xVal = ax.d2c(xVal);
660-
if(cd0 && cd0.t && cd0.t.posLetter === ax._id && isGrouped) {
661-
xVal += cd0.t.dPos;
662-
}
663-
664-
var yVal = winningPoint.yVal;
665-
ax = winningPoint.ya;
666-
if(ax.type === 'category') yVal = ax._categoriesMap[yVal];
667-
if(ax.type === 'date') yVal = ax.d2c(yVal);
668-
if(cd0 && cd0.t && cd0.t.posLetter === ax._id && isGrouped) {
669-
yVal += cd0.t.dPos;
670-
}
671-
672-
findHoverPoints(xVal, yVal);
655+
findHoverPoints(
656+
getVal('x', winningPoint, isGrouped),
657+
getVal('y', winningPoint, isGrouped)
658+
);
673659

674660
// Remove duplicated hoverData points
675661
// note that d3 also filters identical points in the rendering steps
@@ -1911,3 +1897,17 @@ function orderPeriod(hoverData, hovermode) {
19111897

19121898
hoverData = first.concat(last);
19131899
}
1900+
1901+
function getVal(axLetter, winningPoint, isGrouped) {
1902+
var cd0 = winningPoint.cd[winningPoint.index];
1903+
var ax = winningPoint[axLetter + 'a'];
1904+
var val = winningPoint[axLetter + 'Val'];
1905+
1906+
if(ax.type === 'category') val = ax._categoriesMap[val];
1907+
if(ax.type === 'date') val = ax.d2c(val);
1908+
if(cd0 && cd0.t && cd0.t.posLetter === ax._id && isGrouped) {
1909+
val += cd0.t.dPos;
1910+
}
1911+
1912+
return val;
1913+
}

0 commit comments

Comments
 (0)