Skip to content

Commit 55f9c91

Browse files
authored
Merge pull request #6727 from andrej-vasilj/FIX_5350
Fixing issue #5350 by moving the 'false' check
2 parents 1ff17d4 + 6b72540 commit 55f9c91

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

draftlogs/6727_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Addressing issue [[#5350](https://github.com/plotly/plotly.js/issues/5350)] via pull request [[#6727](https://github.com/plotly/plotly.js/pull/6727)]. This small change allows custom plotly_legenddoubleclick handlers to execute even when the default plotly_legendclick event is cancelled (returns false).

src/components/legend/draw.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,9 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
494494
if(Registry.traceIs(trace, 'pie-like')) {
495495
evtData.label = legendItem.datum()[0].label;
496496
}
497-
498497
var clickVal = Events.triggerHandler(gd, 'plotly_legendclick', evtData);
499-
if(clickVal === false) return;
500-
501498
if(numClicks === 1) {
499+
if(clickVal === false) return;
502500
legend._clickTimeout = setTimeout(function() {
503501
if(!gd._fullLayout) return;
504502
handleClick(legendItem, gd, numClicks);
@@ -508,7 +506,8 @@ function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
508506
gd._legendMouseDownTime = 0;
509507

510508
var dblClickVal = Events.triggerHandler(gd, 'plotly_legenddoubleclick', evtData);
511-
if(dblClickVal !== false) handleClick(legendItem, gd, numClicks);
509+
// Activate default double click behaviour only when both single click and double click values are not false
510+
if(dblClickVal !== false && clickVal !== false) handleClick(legendItem, gd, numClicks);
512511
}
513512
}
514513

test/jasmine/tests/legend_test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,38 @@ describe('legend with custom doubleClickDelay', function() {
27422742
.then(_assert('[short] after click + (1.1*t) delay + click', 2, 0))
27432743
.then(done, done.fail);
27442744
}, 3 * jasmine.DEFAULT_TIMEOUT_INTERVAL);
2745+
2746+
it('custom plotly_legenddoubleclick handler should fire even when plotly_legendclick has been cancelled', function(done) {
2747+
var tShort = 0.75 * DBLCLICKDELAY;
2748+
var dblClickCnt = 0;
2749+
var newPlot = function(fig) {
2750+
return Plotly.newPlot(gd, fig).then(function() {
2751+
gd.on('plotly_legendclick', function() { return false; });
2752+
gd.on('plotly_legenddoubleclick', function() { dblClickCnt++; });
2753+
});
2754+
};
2755+
2756+
function _assert(msg, _dblClickCnt) {
2757+
return function() {
2758+
expect(dblClickCnt).toBe(_dblClickCnt, msg + '| dblClickCnt');
2759+
dblClickCnt = 0;
2760+
};
2761+
}
2762+
2763+
newPlot({
2764+
data: [
2765+
{y: [1, 2, 1]},
2766+
{y: [2, 1, 2]}
2767+
],
2768+
layout: {},
2769+
config: {}
2770+
})
2771+
.then(click(0))
2772+
.then(delay(tShort))
2773+
.then(click(0))
2774+
.then(_assert('Double click increases count', 1))
2775+
.then(done);
2776+
}, 3 * jasmine.DEFAULT_TIMEOUT_INTERVAL);
27452777
});
27462778

27472779
describe('legend with custom legendwidth', function() {

0 commit comments

Comments
 (0)