Skip to content

Commit e2105d2

Browse files
authored
Merge pull request #1300 from plotly/gl2d-not-visible-optimization
gl2d non-visible traces improvements
2 parents 6f00ec7 + a587f8d commit e2105d2

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

src/traces/scattergl/convert.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ function LineWithMarkers(scene, uid) {
104104
this.scatter._trace = this;
105105
this.fancyScatter = createFancyScatter(scene.glplot, this.scatterOptions);
106106
this.fancyScatter._trace = this;
107+
108+
this.isVisible = false;
107109
}
108110

109111
var proto = LineWithMarkers.prototype;
@@ -232,12 +234,14 @@ function _convertColor(colors, opacities, count) {
232234
*/
233235
proto.update = function(options) {
234236
if(options.visible !== true) {
237+
this.isVisible = false;
235238
this.hasLines = false;
236239
this.hasErrorX = false;
237240
this.hasErrorY = false;
238241
this.hasMarkers = false;
239242
}
240243
else {
244+
this.isVisible = true;
241245
this.hasLines = subTypes.hasLines(options);
242246
this.hasErrorX = options.error_x.visible === true;
243247
this.hasErrorY = options.error_y.visible === true;
@@ -250,7 +254,10 @@ proto.update = function(options) {
250254
this.bounds = [Infinity, Infinity, -Infinity, -Infinity];
251255
this.connectgaps = !!options.connectgaps;
252256

253-
if(this.isFancy(options)) {
257+
if(!this.isVisible) {
258+
this.clear();
259+
}
260+
else if(this.isFancy(options)) {
254261
this.updateFancy(options);
255262
}
256263
else {
@@ -285,6 +292,22 @@ function allFastTypesLikely(a) {
285292
return true;
286293
}
287294

295+
proto.clear = function() {
296+
this.lineOptions.positions = new Float64Array(0);
297+
this.line.update(this.lineOptions);
298+
299+
this.errorXOptions.positions = new Float64Array(0);
300+
this.errorX.update(this.errorXOptions);
301+
302+
this.errorYOptions.positions = new Float64Array(0);
303+
this.errorY.update(this.errorYOptions);
304+
305+
this.scatterOptions.positions = new Float64Array(0);
306+
this.scatterOptions.glyphs = [];
307+
this.scatter.update(this.scatterOptions);
308+
this.fancyScatter.update(this.scatterOptions);
309+
};
310+
288311
proto.updateFast = function(options) {
289312
var x = this.xData = this.pickXData = options.x;
290313
var y = this.yData = this.pickYData = options.y;

test/image/mocks/gl2d_scatter-marker-line-colorscales.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@
176176
}
177177
},
178178
"uid": "0a4533"
179+
},
180+
{
181+
"type": "scattergl",
182+
"x": [],
183+
"y": []
184+
},
185+
{
186+
"type": "scattergl",
187+
"y": []
188+
},
189+
{
190+
"type": "scattergl",
191+
"x": []
192+
},
193+
{
194+
"type": "scattergl"
195+
},
196+
{
197+
"type": "scattergl",
198+
"x": [1,2,3],
199+
"y": [2,1,2],
200+
"visible": false
201+
},
202+
{
203+
"type": "scattergl",
204+
"x": [1,2,3],
205+
"y": [2,1,2],
206+
"visible": "legendonly"
179207
}
180208
],
181209
"layout": {
@@ -201,4 +229,4 @@
201229
"autosize": true,
202230
"showlegend": false
203231
}
204-
}
232+
}

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,39 @@ describe('Test gl plot interactions', function() {
331331

332332
}, MODEBAR_DELAY);
333333
});
334+
335+
it('should be able to toggle visibility', function(done) {
336+
var OBJECT_PER_TRACE = 5;
337+
338+
var objects = function() {
339+
return gd._fullLayout._plots.xy._scene2d.glplot.objects;
340+
};
341+
342+
expect(objects().length).toEqual(OBJECT_PER_TRACE);
343+
344+
Plotly.restyle(gd, 'visible', 'legendonly').then(function() {
345+
expect(objects().length).toEqual(OBJECT_PER_TRACE);
346+
expect(objects()[0].data.length).toEqual(0);
347+
348+
return Plotly.restyle(gd, 'visible', true);
349+
})
350+
.then(function() {
351+
expect(objects().length).toEqual(OBJECT_PER_TRACE);
352+
expect(objects()[0].data.length).not.toEqual(0);
353+
354+
return Plotly.restyle(gd, 'visible', false);
355+
})
356+
.then(function() {
357+
expect(gd._fullLayout._plots.xy._scene2d).toBeUndefined();
358+
359+
return Plotly.restyle(gd, 'visible', true);
360+
})
361+
.then(function() {
362+
expect(objects().length).toEqual(OBJECT_PER_TRACE);
363+
expect(objects()[0].data.length).not.toEqual(0);
364+
})
365+
.then(done);
366+
});
334367
});
335368

336369
describe('gl3d event handlers', function() {

0 commit comments

Comments
 (0)