Skip to content

Commit c5a2ff8

Browse files
author
Robert Paskowitz
committed
Move DBLCLICKDELAY and make clicked series detection cleaner
1 parent afcf4f4 commit c5a2ff8

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/components/legend/draw.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var helpers = require('./helpers');
2828
var anchorUtils = require('./anchor_utils');
2929

3030
var SHOWISOLATETIP = true;
31+
var DBLCLICKDELAY = interactConstants.DBLCLICKDELAY;
3132

3233
module.exports = function draw(gd) {
3334
var fullLayout = gd._fullLayout;
@@ -335,18 +336,15 @@ module.exports = function draw(gd) {
335336
} else {
336337
var traces = [],
337338
clickedTrace;
338-
fullLayout._infolayer.selectAll('g.traces').each(function() { d3.select(this).call(function() { traces.push(this); }); });
339-
for(var i = 0; i < traces.length; i++) {
340-
var tracei = traces[i];
341-
var p = tracei[0][0].getBoundingClientRect();
342-
if(e.clientX >= p.left && e.clientX <= p.right && e.clientY >= p.top && e.clientY <= p.bottom) {
343-
clickedTrace = tracei;
344-
break;
345-
}
346-
}
347-
if(clickedTrace) {
339+
traces = fullLayout._infolayer.selectAll('g.traces').filter(function() {
340+
var bbox = this.getBoundingClientRect();
341+
return (e.clientX >= bbox.left && e.clientX <= bbox.right &&
342+
e.clientY >= bbox.top && e.clientY <= bbox.bottom);
343+
})[0];
344+
if(traces.length > 0) {
345+
clickedTrace = d3.select(traces[0]);
348346
if(numClicks === 1) {
349-
legend._clickTimeout = setTimeout(function() { handleClick(clickedTrace, gd, numClicks); }, 300);
347+
legend._clickTimeout = setTimeout(function() { handleClick(clickedTrace, gd, numClicks); }, DBLCLICKDELAY);
350348
} else if(numClicks === 2) {
351349
if(legend._clickTimeout) {
352350
clearTimeout(legend._clickTimeout);
@@ -422,8 +420,7 @@ function drawTexts(g, gd) {
422420

423421
function setupTraceToggle(g, gd) {
424422
var newMouseDownTime,
425-
numClicks = 1,
426-
DBLCLICKDELAY = interactConstants.DBLCLICKDELAY;
423+
numClicks = 1;
427424

428425
var traceToggle = g.selectAll('rect')
429426
.data([0]);

0 commit comments

Comments
 (0)