Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7773_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix stale `scattergl` error bars after toggling traces with mixed error bar visibility [[#7773](https://github.com/plotly/plotly.js/issues/7773)]
5 changes: 4 additions & 1 deletion src/traces/scattergl/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ var exports = module.exports = function plot(gd, subplot, cdata) {
scene.line2d.update(scene.lineOptions);
}
if(scene.error2d) {
var errorBatch = (scene.errorXOptions || []).concat(scene.errorYOptions || []);
var errorBatch = (scene.errorXOptions || []).concat(scene.errorYOptions || [])
.map(function(errorOptions) {
return errorOptions || {positions: [], errors: []};
});
scene.error2d.update(errorBatch);
}
if(scene.scatter2d) {
Expand Down
71 changes: 71 additions & 0 deletions test/jasmine/tests/scattergl_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,77 @@ describe('end-to-end scattergl tests', function() {
.then(done, done.fail);
});

it('@gl should clear error bars when toggling traces with mixed error bars', function(done) {
function assertNoStaleErrorGroups(scene, msg) {
scene.error2d.groups.forEach(function(group, i) {
var hasSceneOptions = i < scene.count ?
scene.errorXOptions[i] :
scene.errorYOptions[i - scene.count];

if(!hasSceneOptions && group) {
expect(group.count).toBe(0, msg + ': group ' + i);
}
});
}

function assertVisibleErrorBars(msg, exp) {
var scene = gd._fullLayout._plots.xy._scene;
var countSceneErrorYOptions = scene.errorYOptions.filter(function(opts) { return opts; }).length;
var countDrawableErrorGroups = scene.error2d.groups.filter(function(group) { return group && group.count; }).length;

expect(countSceneErrorYOptions).toBe(exp, msg + ' scene options');
expect(countDrawableErrorGroups).toBe(exp, msg + ' renderer groups');
assertNoStaleErrorGroups(scene, msg);
}

Plotly.newPlot(gd, [{
type: 'scattergl',
mode: 'lines',
name: 'no error 1',
x: [0, 1, 2],
y: [0, 1, 0]
}, {
type: 'scattergl',
mode: 'lines',
name: 'my',
x: [0, 1, 2],
y: [1, 2, 1],
error_y: {value: 0.2}
}, {
type: 'scattergl',
mode: 'lines',
name: 'no error 2',
x: [0, 1, 2],
y: [2, 3, 2]
}, {
type: 'scattergl',
mode: 'lines',
name: 'mz',
x: [0, 1, 2],
y: [3, 4, 3],
error_y: {value: 0.2}
}])
.then(function() {
assertVisibleErrorBars('base', 2);

return Plotly.restyle(gd, 'visible', 'legendonly', [3]);
})
.then(function() {
assertVisibleErrorBars('after hiding last error trace', 1);

return Plotly.restyle(gd, 'visible', true, [3]);
})
.then(function() {
assertVisibleErrorBars('after showing last error trace', 2);

return Plotly.restyle(gd, 'visible', 'legendonly', [1]);
})
.then(function() {
assertVisibleErrorBars('after hiding first error trace', 1);
})
.then(done, done.fail);
});

it('@gl should change plot type with incomplete data', function(done) {
Plotly.newPlot(gd, [{}])
.then(function() {
Expand Down