Skip to content

Commit

Permalink
Merge pull request #1300 from plotly/gl2d-not-visible-optimization
Browse files Browse the repository at this point in the history
gl2d non-visible traces improvements
  • Loading branch information
etpinard committed Jan 18, 2017
2 parents 6f00ec7 + a587f8d commit e2105d2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ function LineWithMarkers(scene, uid) {
this.scatter._trace = this;
this.fancyScatter = createFancyScatter(scene.glplot, this.scatterOptions);
this.fancyScatter._trace = this;

this.isVisible = false;
}

var proto = LineWithMarkers.prototype;
Expand Down Expand Up @@ -232,12 +234,14 @@ function _convertColor(colors, opacities, count) {
*/
proto.update = function(options) {
if(options.visible !== true) {
this.isVisible = false;
this.hasLines = false;
this.hasErrorX = false;
this.hasErrorY = false;
this.hasMarkers = false;
}
else {
this.isVisible = true;
this.hasLines = subTypes.hasLines(options);
this.hasErrorX = options.error_x.visible === true;
this.hasErrorY = options.error_y.visible === true;
Expand All @@ -250,7 +254,10 @@ proto.update = function(options) {
this.bounds = [Infinity, Infinity, -Infinity, -Infinity];
this.connectgaps = !!options.connectgaps;

if(this.isFancy(options)) {
if(!this.isVisible) {
this.clear();
}
else if(this.isFancy(options)) {
this.updateFancy(options);
}
else {
Expand Down Expand Up @@ -285,6 +292,22 @@ function allFastTypesLikely(a) {
return true;
}

proto.clear = function() {
this.lineOptions.positions = new Float64Array(0);
this.line.update(this.lineOptions);

this.errorXOptions.positions = new Float64Array(0);
this.errorX.update(this.errorXOptions);

this.errorYOptions.positions = new Float64Array(0);
this.errorY.update(this.errorYOptions);

this.scatterOptions.positions = new Float64Array(0);
this.scatterOptions.glyphs = [];
this.scatter.update(this.scatterOptions);
this.fancyScatter.update(this.scatterOptions);
};

proto.updateFast = function(options) {
var x = this.xData = this.pickXData = options.x;
var y = this.yData = this.pickYData = options.y;
Expand Down
30 changes: 29 additions & 1 deletion test/image/mocks/gl2d_scatter-marker-line-colorscales.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@
}
},
"uid": "0a4533"
},
{
"type": "scattergl",
"x": [],
"y": []
},
{
"type": "scattergl",
"y": []
},
{
"type": "scattergl",
"x": []
},
{
"type": "scattergl"
},
{
"type": "scattergl",
"x": [1,2,3],
"y": [2,1,2],
"visible": false
},
{
"type": "scattergl",
"x": [1,2,3],
"y": [2,1,2],
"visible": "legendonly"
}
],
"layout": {
Expand All @@ -201,4 +229,4 @@
"autosize": true,
"showlegend": false
}
}
}
33 changes: 33 additions & 0 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,39 @@ describe('Test gl plot interactions', function() {

}, MODEBAR_DELAY);
});

it('should be able to toggle visibility', function(done) {
var OBJECT_PER_TRACE = 5;

var objects = function() {
return gd._fullLayout._plots.xy._scene2d.glplot.objects;
};

expect(objects().length).toEqual(OBJECT_PER_TRACE);

Plotly.restyle(gd, 'visible', 'legendonly').then(function() {
expect(objects().length).toEqual(OBJECT_PER_TRACE);
expect(objects()[0].data.length).toEqual(0);

return Plotly.restyle(gd, 'visible', true);
})
.then(function() {
expect(objects().length).toEqual(OBJECT_PER_TRACE);
expect(objects()[0].data.length).not.toEqual(0);

return Plotly.restyle(gd, 'visible', false);
})
.then(function() {
expect(gd._fullLayout._plots.xy._scene2d).toBeUndefined();

return Plotly.restyle(gd, 'visible', true);
})
.then(function() {
expect(objects().length).toEqual(OBJECT_PER_TRACE);
expect(objects()[0].data.length).not.toEqual(0);
})
.then(done);
});
});

describe('gl3d event handlers', function() {
Expand Down

0 comments on commit e2105d2

Please sign in to comment.