Skip to content

Surface additional checks for handling empty z arrays and minimum number of rows and columns #3365

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

Merged
merged 4 commits into from
Dec 21, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var x = coerce('x');
var y = coerce('y');

var z = coerce('z');
if(!z) {
if(!z || !z.length ||
(x ? (x.length < 1) : false) ||
(y ? (y.length < 1) : false)
) {
traceOut.visible = false;
return;
}

var x = coerce('x');
coerce('y');

traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;
traceOut._ylength = z.length;

Expand Down
2 changes: 0 additions & 2 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,11 @@ describe('Test gl3d plots', function() {
.then(done);
});


it('@gl should avoid passing blank texts to webgl', function(done) {
function assertIsFilled(msg) {
var fullLayout = gd._fullLayout;
expect(fullLayout.scene._scene.glplot.objects[0].glyphBuffer.length).not.toBe(0, msg);
}

Plotly.plot(gd, [{
type: 'scatter3d',
mode: 'text',
Expand Down
117 changes: 117 additions & 0 deletions test/jasmine/tests/surface_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
var Surface = require('@src/traces/surface');
var Plotly = require('@lib/index');
var failTest = require('../assets/fail_test');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

var Lib = require('@src/lib');

Expand Down Expand Up @@ -178,5 +182,118 @@ describe('Test surface', function() {
expect(traceOut.ycalendar).toBe('ethiopian');
expect(traceOut.zcalendar).toBe('mayan');
});

});

describe('Test dimension and expected visibility tests', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});

function assertVisibility(exp, msg) {
expect(gd._fullData[0]).not.toBe(undefined, 'no visibility!');
expect(gd._fullData[0].visible).toBe(exp, msg);
}

it('@gl surface should be invisible when the z array is empty', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'z': []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be invisible when the x array is defined but is empty', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'x': [],
'y': [0, 1],
'z': []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be invisible when the y array is defined but is empty', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'x': [0, 1],
'y': [],
'z': []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be invisible when the x array is defined and has at least one item', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'x': [0],
'y': [0, 1],
'z': [[1], [2]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be invisible when the y array is defined and has at least one item', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'x': [0, 1],
'y': [0],
'z': [[1, 2]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be visible when the x and y are not provided; but z array is provided', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'z': [[1, 2], [3, 4]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.catch(failTest)
.then(done);
});

it('@gl surface should be invisible when the x and y are provided; but z array is not provided', function(done) {
Plotly.plot(gd, [{
'type': 'surface',
'x': [0, 1],
'y': [0, 1]
}])
.then(function() {
assertVisibility(false, 'to be invisible');
})
.catch(failTest)
.then(done);
});

});
});