Skip to content

Commit e066bb9

Browse files
committed
fix legend.traceorder when all traces are legendonly
1 parent c5cb42c commit e066bb9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/plots/plots.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,10 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
14821482
}
14831483

14841484
// trace module layout defaults
1485-
var modules = layoutOut._visibleModules;
1485+
// use _modules rather than _visibleModules so that even
1486+
// legendonly traces can include settings - eg barmode, which affects
1487+
// legend.traceorder default value.
1488+
var modules = layoutOut._modules;
14861489
for(i = 0; i < modules.length; i++) {
14871490
_module = modules[i];
14881491

test/jasmine/tests/bar_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ describe('bar visibility toggling:', function() {
13611361
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();
13621362

13631363
_assert('base', [0.5, 3.5], [-2.222, 2.222], 0);
1364+
expect(gd._fullLayout.legend.traceorder).toBe('normal');
13641365
return Plotly.restyle(gd, 'visible', false, [1]);
13651366
})
13661367
.then(function() {
@@ -1369,6 +1370,11 @@ describe('bar visibility toggling:', function() {
13691370
})
13701371
.then(function() {
13711372
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
1373+
return Plotly.restyle(gd, 'visible', 'legendonly');
1374+
})
1375+
.then(function() {
1376+
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
1377+
expect(gd._fullLayout.legend.traceorder).toBe('normal');
13721378
return Plotly.restyle(gd, 'visible', true, [1]);
13731379
})
13741380
.then(function() {
@@ -1391,6 +1397,7 @@ describe('bar visibility toggling:', function() {
13911397
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();
13921398

13931399
_assert('base', [0.5, 3.5], [0, 5.263], 0);
1400+
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
13941401
return Plotly.restyle(gd, 'visible', false, [1]);
13951402
})
13961403
.then(function() {
@@ -1399,6 +1406,11 @@ describe('bar visibility toggling:', function() {
13991406
})
14001407
.then(function() {
14011408
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
1409+
return Plotly.restyle(gd, 'visible', 'legendonly');
1410+
})
1411+
.then(function() {
1412+
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
1413+
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
14021414
return Plotly.restyle(gd, 'visible', true, [1]);
14031415
})
14041416
.then(function() {

0 commit comments

Comments
 (0)