Skip to content

Commit 431c564

Browse files
committed
fix & 🔒 scattergl text visible toggles
1 parent 959a555 commit 431c564

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/traces/scattergl/index.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function sceneUpdate(gd, subplot) {
242242
if(scene.error2d) scene.error2d.update(opts.concat(opts));
243243
if(scene.select2d) scene.select2d.update(opts);
244244
if(scene.glText) {
245-
for(i = 0; i < scene.glText.length; i++) {
245+
for(i = 0; i < scene.count; i++) {
246246
scene.glText[i].update(opts[i]);
247247
}
248248
}
@@ -273,6 +273,9 @@ function sceneUpdate(gd, subplot) {
273273
// traces in no-selection mode
274274
scene.scatter2d.draw(i);
275275
}
276+
if(scene.glText[i] && scene.textOptions[i]) {
277+
scene.glText[i].render();
278+
}
276279
}
277280

278281
// draw traces in selection mode
@@ -281,12 +284,6 @@ function sceneUpdate(gd, subplot) {
281284
scene.scatter2d.draw(scene.unselectBatch);
282285
}
283286

284-
if(scene.glText.length) {
285-
scene.glText.forEach(function(text) {
286-
text.render();
287-
});
288-
}
289-
290287
scene.dirty = false;
291288
};
292289

@@ -333,9 +330,7 @@ function sceneUpdate(gd, subplot) {
333330
if(scene.line2d) scene.line2d.destroy();
334331
if(scene.select2d) scene.select2d.destroy();
335332
if(scene.glText) {
336-
scene.glText.forEach(function(text) {
337-
text.destroy();
338-
});
333+
scene.glText.forEach(function(text) { text.destroy(); });
339334
}
340335

341336
scene.lineOptions = null;
@@ -409,15 +404,15 @@ function plot(gd, subplot, cdata) {
409404
scene.fill2d = createLine(regl);
410405
}
411406
if(scene.glText === true) {
412-
scene.glText = [];
413-
for(i = 0; i < scene.textOptions.length; i++) {
407+
scene.glText = new Array(scene.count);
408+
for(i = 0; i < scene.count; i++) {
414409
scene.glText[i] = new Text(regl);
415410
}
416411
}
417412

418413
// update main marker options
419414
if(scene.glText) {
420-
for(i = 0; i < scene.textOptions.length; i++) {
415+
for(i = 0; i < scene.count; i++) {
421416
scene.glText[i].update(scene.textOptions[i]);
422417
}
423418
}

test/jasmine/tests/gl2d_plot_interact_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ describe('@gl Test gl2d plots', function() {
389389
Plotly.newPlot(gd, [{
390390
// a trace with all regl2d objects
391391
type: 'scattergl',
392+
mode: 'lines+markers+text',
392393
y: [1, 2, 1],
394+
text: ['a', 'b', 'c'],
393395
error_x: {value: 10},
394396
error_y: {value: 10},
395397
fill: 'tozeroy'
@@ -404,6 +406,7 @@ describe('@gl Test gl2d plots', function() {
404406
spyOn(scene.line2d, 'draw');
405407
spyOn(scene.error2d, 'draw');
406408
spyOn(scene.scatter2d, 'draw');
409+
spyOn(scene.glText[0], 'render');
407410

408411
return Plotly.restyle(gd, 'visible', 'legendonly', [0]);
409412
})
@@ -412,6 +415,7 @@ describe('@gl Test gl2d plots', function() {
412415
expect(scene.fill2d.draw).toHaveBeenCalledTimes(0);
413416
expect(scene.line2d.draw).toHaveBeenCalledTimes(0);
414417
expect(scene.error2d.draw).toHaveBeenCalledTimes(0);
418+
expect(scene.glText[0].render).toHaveBeenCalledTimes(0);
415419
expect(scene.scatter2d.draw).toHaveBeenCalledTimes(1);
416420

417421
return Plotly.restyle(gd, 'visible', true, [0]);
@@ -421,6 +425,7 @@ describe('@gl Test gl2d plots', function() {
421425
expect(scene.fill2d.draw).toHaveBeenCalledTimes(1);
422426
expect(scene.line2d.draw).toHaveBeenCalledTimes(1);
423427
expect(scene.error2d.draw).toHaveBeenCalledTimes(2, 'twice for x AND y');
428+
expect(scene.glText[0].render).toHaveBeenCalledTimes(1);
424429
expect(scene.scatter2d.draw).toHaveBeenCalledTimes(3, 'both traces have markers');
425430
})
426431
.catch(failTest)

0 commit comments

Comments
 (0)