Skip to content

Commit 895ba89

Browse files
author
Robert Paskowitz
committed
Trace Isolation PR Feedback
- Show Lib.notify on first single-click toggle - Refactor DBLCLICKDELAY into interaction constants - Double click on the only visible trace (or group) re-enables all traces - Single call to restyle TODO: Tests, fix interaction on editable: true
1 parent afeaf5e commit 895ba89

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

src/components/dragelement/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Plotly = require('../../plotly');
1313
var Lib = require('../../lib');
1414

1515
var constants = require('../../plots/cartesian/constants');
16-
16+
var interactConstants = require('../../constants/interactions');
1717

1818
var dragElement = module.exports = {};
1919

@@ -51,7 +51,7 @@ dragElement.unhoverRaw = unhover.raw;
5151
dragElement.init = function init(options) {
5252
var gd = Lib.getPlotDiv(options.element) || {},
5353
numClicks = 1,
54-
DBLCLICKDELAY = constants.DBLCLICKDELAY,
54+
DBLCLICKDELAY = interactConstants.DBLCLICKDELAY,
5555
startX,
5656
startY,
5757
newMouseDownTime,

src/components/legend/constants.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ module.exports = {
1212
scrollBarWidth: 4,
1313
scrollBarHeight: 20,
1414
scrollBarColor: '#808BA4',
15-
scrollBarMargin: 4,
16-
DBLCLICKDELAY: 300
15+
scrollBarMargin: 4
1716
};

src/components/legend/draw.js

+32-10
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ var Color = require('../color');
2121
var svgTextUtils = require('../../lib/svg_text_utils');
2222

2323
var constants = require('./constants');
24+
var interactConstants = require('../../constants/interactions');
2425
var getLegendData = require('./get_legend_data');
2526
var style = require('./style');
2627
var helpers = require('./helpers');
2728
var anchorUtils = require('./anchor_utils');
2829

30+
var SHOWISOLATETIP = true;
2931

3032
module.exports = function draw(gd) {
3133
var fullLayout = gd._fullLayout;
@@ -399,7 +401,7 @@ function drawTexts(g, gd) {
399401
function setupTraceToggle(g, gd) {
400402
var newMouseDownTime,
401403
numClicks = 1,
402-
DBLCLICKDELAY = constants.DBLCLICKDELAY;
404+
DBLCLICKDELAY = interactConstants.DBLCLICKDELAY;
403405

404406
var traceToggle = g.selectAll('rect')
405407
.data([0]);
@@ -432,7 +434,7 @@ function setupTraceToggle(g, gd) {
432434
}
433435

434436
if(numClicks === 1) {
435-
legend._clickTimeout = setTimeout(function() { handleClick(g, gd, numClicks); }, 300);
437+
legend._clickTimeout = setTimeout(function() { handleClick(g, gd, numClicks); }, DBLCLICKDELAY);
436438
} else if(numClicks === 2) {
437439
if(legend._clickTimeout) {
438440
clearTimeout(legend._clickTimeout);
@@ -455,6 +457,13 @@ function handleClick(g, gd, numClicks) {
455457
tracei,
456458
newVisible;
457459

460+
461+
if(numClicks === 1 && SHOWISOLATETIP && gd.data && gd._context.showTips) {
462+
Lib.notifier('Double click on legend to isolate individual trace', 'long');
463+
SHOWISOLATETIP = false;
464+
} else {
465+
SHOWISOLATETIP = false;
466+
}
458467
if(Registry.traceIs(trace, 'pie')) {
459468
var thisLabel = legendItem.label,
460469
thisLabelIndex = hiddenSlices.indexOf(thisLabel);
@@ -469,37 +478,50 @@ function handleClick(g, gd, numClicks) {
469478
hiddenSlices.push(d.label);
470479
}
471480
});
481+
if(gd._fullLayout.hiddenlabels && gd._fullLayout.hiddenlabels.length === hiddenSlices.length && thisLabelIndex === -1) {
482+
hiddenSlices = [];
483+
}
472484
}
473485

474486
Plotly.relayout(gd, 'hiddenlabels', hiddenSlices);
475487
} else {
476-
var otherTraces = [],
477-
traceIndex,
488+
var allTraces = [],
489+
traceVisibility = [],
478490
i;
479491

480492
for(i = 0; i < fullData.length; i++) {
481-
otherTraces.push(i);
493+
allTraces.push(i);
494+
traceVisibility.push('legendonly');
482495
}
483496

484497
if(legendgroup === '') {
485498
traceIndicesInGroup = [trace.index];
486-
otherTraces.splice(trace.index, 1);
499+
traceVisibility[trace.index] = true;
487500
} else {
488501
for(i = 0; i < fullData.length; i++) {
489502
tracei = fullData[i];
490503
if(tracei.legendgroup === legendgroup) {
491504
traceIndicesInGroup.push(tracei.index);
492-
traceIndex = otherTraces.indexOf(i);
493-
otherTraces.splice(traceIndex, 1);
505+
traceVisibility[allTraces.indexOf(i)] = true;
494506
}
495507
}
496508
}
509+
497510
if(numClicks === 1) {
498511
newVisible = trace.visible === true ? 'legendonly' : true;
499512
Plotly.restyle(gd, 'visible', newVisible, traceIndicesInGroup);
500513
} else if(numClicks === 2) {
501-
Plotly.restyle(gd, 'visible', true, traceIndicesInGroup);
502-
Plotly.restyle(gd, 'visible', 'legendonly', otherTraces);
514+
var sameAsLast = true;
515+
for(i = 0; i < fullData.length; i++) {
516+
if(fullData[i].visible !== traceVisibility[i]) {
517+
sameAsLast = false;
518+
break;
519+
}
520+
}
521+
if(sameAsLast) {
522+
traceVisibility = true;
523+
}
524+
Plotly.restyle(gd, 'visible', traceVisibility, allTraces);
503525
}
504526
}
505527
}

src/constants/interactions.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ module.exports = {
1414
* Timing information for interactive elements
1515
*/
1616
SHOW_PLACEHOLDER: 100,
17-
HIDE_PLACEHOLDER: 1000
17+
HIDE_PLACEHOLDER: 1000,
18+
19+
// ms between first mousedown and 2nd mouseup to constitute dblclick...
20+
// we don't seem to have access to the system setting
21+
DBLCLICKDELAY: 300
1822
};

src/plots/cartesian/constants.js

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ module.exports = {
2929
AX_ID_PATTERN: /^[xyz][0-9]*$/,
3030
AX_NAME_PATTERN: /^[xyz]axis[0-9]*$/,
3131

32-
// ms between first mousedown and 2nd mouseup to constitute dblclick...
33-
// we don't seem to have access to the system setting
34-
DBLCLICKDELAY: 300,
35-
3632
// pixels to move mouse before you stop clamping to starting point
3733
MINDRAG: 8,
3834

0 commit comments

Comments
 (0)