Skip to content

Commit 88c7a86

Browse files
authored
Merge pull request #5664 from plotly/revisit-hover
Use an object to pass various optional arguments into hoverPoints methods of modules
2 parents d0e1bef + 639d4bb commit 88c7a86

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

src/components/fx/hover.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ function _hover(gd, evt, subplot, noHoverEvent) {
490490
// Now if there is range to look in, find the points to hover.
491491
if(hoverdistance !== 0) {
492492
if(trace._module && trace._module.hoverPoints) {
493-
var newPoints = trace._module.hoverPoints(pointData, xval, yval, mode, fullLayout._hoverlayer);
493+
var newPoints = trace._module.hoverPoints(pointData, xval, yval, mode, {
494+
hoverLayer: fullLayout._hoverlayer
495+
});
496+
494497
if(newPoints) {
495498
var newPoint;
496499
for(var newPointNum = 0; newPointNum < newPoints.length; newPointNum++) {
@@ -519,7 +522,9 @@ function _hover(gd, evt, subplot, noHoverEvent) {
519522
if(hoverData.length === 0) {
520523
pointData.distance = spikedistance;
521524
pointData.index = false;
522-
var closestPoints = trace._module.hoverPoints(pointData, xval, yval, 'closest', fullLayout._hoverlayer);
525+
var closestPoints = trace._module.hoverPoints(pointData, xval, yval, 'closest', {
526+
hoverLayer: fullLayout._hoverlayer
527+
});
523528
if(closestPoints) {
524529
closestPoints = closestPoints.filter(function(point) {
525530
// some hover points, like scatter fills, do not allow spikes,

src/traces/contour/hover.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ var Color = require('../../components/color');
44

55
var heatmapHoverPoints = require('../heatmap/hover');
66

7-
module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {
8-
var hoverData = heatmapHoverPoints(pointData, xval, yval, hovermode, hoverLayer, true);
7+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
8+
if(!opts) opts = {};
9+
opts.isContour = true;
10+
11+
var hoverData = heatmapHoverPoints(pointData, xval, yval, hovermode, opts);
912

1013
if(hoverData) {
1114
hoverData.forEach(function(hoverPt) {

src/traces/heatmap/hover.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var Lib = require('../../lib');
55
var Axes = require('../../plots/cartesian/axes');
66
var extractOpts = require('../../components/colorscale').extractOpts;
77

8-
module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {
8+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
9+
if(!opts) opts = {};
10+
var isContour = opts.isContour;
11+
912
var cd0 = pointData.cd[0];
1013
var trace = cd0.trace;
1114
var xa = pointData.xa;
@@ -38,7 +41,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
3841
Fx.inbox(yval - y[0], yval - y[y.length - 1], 0) > 0) {
3942
return;
4043
} else {
41-
if(contour) {
44+
if(isContour) {
4245
var i2;
4346
x2 = [2 * x[0] - x[1]];
4447

@@ -63,7 +66,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
6366
var y1 = ya.c2p(y[ny + 1]);
6467

6568
var _x, _y;
66-
if(contour) {
69+
if(isContour) {
6770
_x = cd0.orig_x || x;
6871
_y = cd0.orig_y || y;
6972

src/traces/histogram2d/hover.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
var heatmapHover = require('../heatmap/hover');
44
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText;
55

6-
module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {
7-
var pts = heatmapHover(pointData, xval, yval, hovermode, hoverLayer, contour);
6+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
7+
var pts = heatmapHover(pointData, xval, yval, hovermode, opts);
88

99
if(!pts) return;
1010

src/traces/violin/hover.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var Axes = require('../../plots/cartesian/axes');
55
var boxHoverPoints = require('../box/hover');
66
var helpers = require('./helpers');
77

8-
module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {
8+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
9+
if(!opts) opts = {};
10+
var hoverLayer = opts.hoverLayer;
11+
912
var cd = pointData.cd;
1013
var trace = cd[0].trace;
1114
var hoveron = trace.hoveron;

0 commit comments

Comments
 (0)