Skip to content

Commit b81c45f

Browse files
committed
add isVisible state field for scattergl
- to optimize 'visible' toggling - and fix a few bugs with data-less scattergl traces
1 parent 7ef3235 commit b81c45f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
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;

0 commit comments

Comments
 (0)