Skip to content

Commit 92bf6f5

Browse files
committed
init traceVisibility with true items for notLegendIsolatable traces
- so that is-same comparison during double-click interaction output the correct results - this fixes double click toggles for plots containing carpet traces
1 parent f49df1e commit 92bf6f5

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/components/legend/draw.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ function handleClick(g, gd, numClicks) {
514514
allTraces.push(i);
515515
// Allow the legendonly state through for *all* trace types (including
516516
// carpet for which it's overridden with true/false in supplyDefaults)
517-
traceVisibility.push('legendonly');
517+
traceVisibility.push(
518+
Registry.traceIs(fullData[i], 'notLegendIsolatable') ? true : 'legendonly'
519+
);
518520
}
519521

520522
if(legendgroup === '') {

test/jasmine/tests/legend_test.js

+56
Original file line numberDiff line numberDiff line change
@@ -826,4 +826,60 @@ describe('legend interaction', function() {
826826
});
827827
});
828828
});
829+
830+
describe('carpet plots', function() {
831+
afterAll(destroyGraphDiv);
832+
833+
function _click(index) {
834+
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
835+
return new Promise(function(resolve) {
836+
item.dispatchEvent(new MouseEvent('mousedown'));
837+
item.dispatchEvent(new MouseEvent('mouseup'));
838+
setTimeout(resolve, DBLCLICKDELAY + 20);
839+
});
840+
}
841+
842+
function _dblclick(index) {
843+
var item = d3.selectAll('rect.legendtoggle')[0][index || 0];
844+
return new Promise(function(resolve) {
845+
item.dispatchEvent(new MouseEvent('mousedown'));
846+
item.dispatchEvent(new MouseEvent('mouseup'));
847+
item.dispatchEvent(new MouseEvent('mousedown'));
848+
item.dispatchEvent(new MouseEvent('mouseup'));
849+
setTimeout(resolve, 20);
850+
});
851+
}
852+
853+
function assertVisible(gd, expectation) {
854+
var actual = gd._fullData.map(function(trace) { return trace.visible; });
855+
expect(actual).toEqual(expectation);
856+
}
857+
858+
it('should ignore carpet traces when toggling', function(done) {
859+
var _mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
860+
var gd = createGraphDiv();
861+
862+
Plotly.plot(gd, _mock).then(function() {
863+
assertVisible(gd, [true, true, true, true]);
864+
})
865+
.then(_click)
866+
.then(function() {
867+
assertVisible(gd, [true, 'legendonly', true, true]);
868+
})
869+
.then(_click)
870+
.then(function() {
871+
assertVisible(gd, [true, true, true, true]);
872+
})
873+
.then(_dblclick)
874+
.then(function() {
875+
assertVisible(gd, [true, true, 'legendonly', 'legendonly']);
876+
})
877+
.then(_dblclick)
878+
.then(function() {
879+
assertVisible(gd, [true, true, true, true]);
880+
})
881+
.catch(fail)
882+
.then(done);
883+
});
884+
});
829885
});

0 commit comments

Comments
 (0)