diff --git a/src/traces/surface/defaults.js b/src/traces/surface/defaults.js index 8c1307f5bf3..8c0d8c6b967 100644 --- a/src/traces/surface/defaults.js +++ b/src/traces/surface/defaults.js @@ -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; diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index 77e713bc719..a44fc0e8eb8 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -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', diff --git a/test/jasmine/tests/surface_test.js b/test/jasmine/tests/surface_test.js index 00cfe59ff05..d0a02db942d 100644 --- a/test/jasmine/tests/surface_test.js +++ b/test/jasmine/tests/surface_test.js @@ -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'); @@ -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); + }); + }); });