Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gl2d non-visible traces improvements #1300

Merged
merged 4 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and one each that has data but visible: false || 'legendonly'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 2563f17

},
{
"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