Skip to content

Commit f85f277

Browse files
committed
Fix stale scattergl error bars on legend toggle
1 parent 8965c3d commit f85f277

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

draftlogs/7773_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix stale `scattergl` error bars after toggling traces with mixed error bar visibility [[#7773](https://github.com/plotly/plotly.js/issues/7773)]

src/traces/scattergl/plot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ var exports = module.exports = function plot(gd, subplot, cdata) {
128128
scene.line2d.update(scene.lineOptions);
129129
}
130130
if(scene.error2d) {
131-
var errorBatch = (scene.errorXOptions || []).concat(scene.errorYOptions || []);
131+
var errorBatch = (scene.errorXOptions || []).concat(scene.errorYOptions || [])
132+
.map(function(errorOptions) {
133+
return errorOptions || {positions: [], errors: []};
134+
});
132135
scene.error2d.update(errorBatch);
133136
}
134137
if(scene.scatter2d) {

test/jasmine/tests/scattergl_test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,77 @@ describe('end-to-end scattergl tests', function() {
216216
.then(done, done.fail);
217217
});
218218

219+
it('@gl should clear error bars when toggling traces with mixed error bars', function(done) {
220+
function assertNoStaleErrorGroups(scene, msg) {
221+
scene.error2d.groups.forEach(function(group, i) {
222+
var hasSceneOptions = i < scene.count ?
223+
scene.errorXOptions[i] :
224+
scene.errorYOptions[i - scene.count];
225+
226+
if(!hasSceneOptions && group) {
227+
expect(group.count).toBe(0, msg + ': group ' + i);
228+
}
229+
});
230+
}
231+
232+
function assertVisibleErrorBars(msg, exp) {
233+
var scene = gd._fullLayout._plots.xy._scene;
234+
var countSceneErrorYOptions = scene.errorYOptions.filter(function(opts) { return opts; }).length;
235+
var countDrawableErrorGroups = scene.error2d.groups.filter(function(group) { return group && group.count; }).length;
236+
237+
expect(countSceneErrorYOptions).toBe(exp, msg + ' scene options');
238+
expect(countDrawableErrorGroups).toBe(exp, msg + ' renderer groups');
239+
assertNoStaleErrorGroups(scene, msg);
240+
}
241+
242+
Plotly.newPlot(gd, [{
243+
type: 'scattergl',
244+
mode: 'lines',
245+
name: 'no error 1',
246+
x: [0, 1, 2],
247+
y: [0, 1, 0]
248+
}, {
249+
type: 'scattergl',
250+
mode: 'lines',
251+
name: 'my',
252+
x: [0, 1, 2],
253+
y: [1, 2, 1],
254+
error_y: {value: 0.2}
255+
}, {
256+
type: 'scattergl',
257+
mode: 'lines',
258+
name: 'no error 2',
259+
x: [0, 1, 2],
260+
y: [2, 3, 2]
261+
}, {
262+
type: 'scattergl',
263+
mode: 'lines',
264+
name: 'mz',
265+
x: [0, 1, 2],
266+
y: [3, 4, 3],
267+
error_y: {value: 0.2}
268+
}])
269+
.then(function() {
270+
assertVisibleErrorBars('base', 2);
271+
272+
return Plotly.restyle(gd, 'visible', 'legendonly', [3]);
273+
})
274+
.then(function() {
275+
assertVisibleErrorBars('after hiding last error trace', 1);
276+
277+
return Plotly.restyle(gd, 'visible', true, [3]);
278+
})
279+
.then(function() {
280+
assertVisibleErrorBars('after showing last error trace', 2);
281+
282+
return Plotly.restyle(gd, 'visible', 'legendonly', [1]);
283+
})
284+
.then(function() {
285+
assertVisibleErrorBars('after hiding first error trace', 1);
286+
})
287+
.then(done, done.fail);
288+
});
289+
219290
it('@gl should change plot type with incomplete data', function(done) {
220291
Plotly.newPlot(gd, [{}])
221292
.then(function() {

0 commit comments

Comments
 (0)