Skip to content

Commit e15da90

Browse files
committed
optimize customVal function
1 parent d584520 commit e15da90

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/components/fx/hover.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,10 @@ 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 isGrouped = (fullLayout.boxmode === 'group' || fullLayout.violinmode === 'group');
654653

655654
findHoverPoints(
656-
customVal('x', winningPoint, isGrouped),
657-
customVal('y', winningPoint, isGrouped)
655+
customVal('x', winningPoint, fullLayout),
656+
customVal('y', winningPoint, fullLayout)
658657
);
659658

660659
// Remove duplicated hoverData points
@@ -1898,15 +1897,21 @@ function orderPeriod(hoverData, hovermode) {
18981897
hoverData = first.concat(last);
18991898
}
19001899

1901-
function customVal(axLetter, winningPoint, isGrouped) {
1902-
var cd0 = winningPoint.cd[winningPoint.index];
1900+
function customVal(axLetter, winningPoint, fullLayout) {
19031901
var ax = winningPoint[axLetter + 'a'];
19041902
var val = winningPoint[axLetter + 'Val'];
19051903

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;
1904+
if(ax.type === 'category') return ax._categoriesMap[val];
1905+
if(ax.type === 'date') return ax.d2c(val);
1906+
1907+
var cd0 = winningPoint.cd[winningPoint.index];
1908+
if(cd0 && cd0.t && cd0.t.posLetter === ax._id) {
1909+
if(
1910+
fullLayout.boxmode === 'group' ||
1911+
fullLayout.violinmode === 'group'
1912+
) {
1913+
val += cd0.t.dPos;
1914+
}
19101915
}
19111916

19121917
return val;

0 commit comments

Comments
 (0)