Skip to content

Commit

Permalink
fix legend.traceorder when all traces are legendonly
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Sep 24, 2018
1 parent c5cb42c commit e066bb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,10 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
}

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

Expand Down
12 changes: 12 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ describe('bar visibility toggling:', function() {
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();

_assert('base', [0.5, 3.5], [-2.222, 2.222], 0);
expect(gd._fullLayout.legend.traceorder).toBe('normal');
return Plotly.restyle(gd, 'visible', false, [1]);
})
.then(function() {
Expand All @@ -1369,6 +1370,11 @@ describe('bar visibility toggling:', function() {
})
.then(function() {
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
expect(gd._fullLayout.legend.traceorder).toBe('normal');
return Plotly.restyle(gd, 'visible', true, [1]);
})
.then(function() {
Expand All @@ -1391,6 +1397,7 @@ describe('bar visibility toggling:', function() {
spyOn(gd._fullData[0]._module, 'crossTraceCalc').and.callThrough();

_assert('base', [0.5, 3.5], [0, 5.263], 0);
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
return Plotly.restyle(gd, 'visible', false, [1]);
})
.then(function() {
Expand All @@ -1399,6 +1406,11 @@ describe('bar visibility toggling:', function() {
})
.then(function() {
_assert('both invisible', [0.5, 3.5], [0, 2.105], 0);
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
_assert('both legendonly', [0.5, 3.5], [0, 2.105], 0);
expect(gd._fullLayout.legend.traceorder).toBe('reversed');
return Plotly.restyle(gd, 'visible', true, [1]);
})
.then(function() {
Expand Down

0 comments on commit e066bb9

Please sign in to comment.