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

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

Merged
merged 4 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +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 < 2) : false) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer keeping things consistent with contour traces here. 1-item contour traces are (like 1-item surfaces) ill-defined, but still appear as visible: true in the fullData (see -> https://codepen.io/etpinard/pen/oJZyEO)

To avoid drawing errors, we should handle the 1-item case in surface/convert.js. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The minimum for rows and columns are set to be one.
And it seems we won't get errors for those 1-item cases.

(y ? (y.length < 2) : 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/image/mocks/gl3d_surface-with-no-z-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"data": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we turn these test cases into jasmine tests instead? This surface_test.js block

describe('supplyDefaults', function() {

should be a nice place to test the default logic.

{
"type": "surface",
"x": [],
"y": [],
"z": []
},
{
"type": "surface",
"x": [0],
"y": [0],
"z": [[1]]
},
{
"type": "surface",
"x": [0, 1, 2],
"y": [0],
"z": [[1, 2, 3]]
},
{
"type": "surface",
"x": [0],
"y": [0, 1, 2],
"z": [[1, 2, 3]]
}
],
"layout": {
"title": "Surface traces with rows/columns less than two<br>or with no Z data would be invisible.",
"width": 600,
"height": 400
}
}