diff --git a/src/components/annotations/convert_coords.js b/src/components/annotations/convert_coords.js index ba3441f0b2f..22b258c3d3d 100644 --- a/src/components/annotations/convert_coords.js +++ b/src/components/annotations/convert_coords.js @@ -26,6 +26,8 @@ var toLogRange = require('../../lib/to_log_range'); * same relayout call should override this conversion. */ module.exports = function convertCoords(gd, ax, newType, doExtra) { + ax = ax || {}; + var toLog = (newType === 'log') && (ax.type === 'linear'), fromLog = (newType === 'linear') && (ax.type === 'log'); diff --git a/src/components/images/convert_coords.js b/src/components/images/convert_coords.js index a2dd2a8608e..d35c6c0b694 100644 --- a/src/components/images/convert_coords.js +++ b/src/components/images/convert_coords.js @@ -31,6 +31,8 @@ var toLogRange = require('../../lib/to_log_range'); * same relayout call should override this conversion. */ module.exports = function convertCoords(gd, ax, newType, doExtra) { + ax = ax || {}; + var toLog = (newType === 'log') && (ax.type === 'linear'), fromLog = (newType === 'linear') && (ax.type === 'log'); diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index 0d05b8813ca..bf35acc3902 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -714,6 +714,7 @@ proto.setConvert = function() { for(var i = 0; i < 3; ++i) { var ax = this.fullSceneLayout[axisProperties[i]]; Axes.setConvert(ax, this.fullLayout); + ax.setScale = Lib.noop; } }; diff --git a/test/jasmine/tests/gl_plot_interact_test.js b/test/jasmine/tests/gl_plot_interact_test.js index e09bfb84c60..c9f4f0ae299 100644 --- a/test/jasmine/tests/gl_plot_interact_test.js +++ b/test/jasmine/tests/gl_plot_interact_test.js @@ -7,6 +7,7 @@ var Drawing = require('@src/components/drawing'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); +var fail = require('../assets/fail_test'); var mouseEvent = require('../assets/mouse_event'); var selectButton = require('../assets/modebar_button'); var customMatchers = require('../assets/custom_matchers'); @@ -631,6 +632,72 @@ describe('Test gl3d drag and wheel interactions', function() { }); }); +describe('Test gl3d relayout calls', function() { + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(function() { + Plotly.purge(gd); + destroyGraphDiv(); + }); + + it('should be able to adjust margins', function(done) { + var w = 500; + var h = 500; + + function assertMargins(t, l, b, r) { + var div3d = document.getElementById('scene'); + expect(parseFloat(div3d.style.top)).toEqual(t, 'top'); + expect(parseFloat(div3d.style.left)).toEqual(l, 'left'); + expect(h - parseFloat(div3d.style.height) - t).toEqual(b, 'bottom'); + expect(w - parseFloat(div3d.style.width) - l).toEqual(r, 'right'); + } + + Plotly.newPlot(gd, [{ + type: 'scatter3d', + x: [1, 2, 3], + y: [1, 2, 3], + z: [1, 2, 1] + }], { + width: w, + height: h + }) + .then(function() { + assertMargins(100, 80, 80, 80); + + return Plotly.relayout(gd, 'margin', { + l: 0, t: 0, r: 0, b: 0 + }); + }) + .then(function() { + assertMargins(0, 0, 0, 0); + }) + .catch(fail) + .then(done); + }); + + it('should skip root-level axis objects', function(done) { + Plotly.newPlot(gd, [{ + type: 'scatter3d', + x: [1, 2, 3], + y: [1, 2, 3], + z: [1, 2, 1] + }]) + .then(function() { + return Plotly.relayout(gd, { + xaxis: {}, + yaxis: {}, + zaxis: {} + }); + }) + .catch(fail) + .then(done); + }); +}); + describe('Test gl2d plots', function() { var gd; diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index beb2805dc99..d768f3b99b4 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -237,6 +237,21 @@ describe('Test plot api', function() { }) .then(done); }); + + it('should skip empty axis objects', function(done) { + Plotly.plot(gd, [{ + x: [1, 2, 3], + y: [1, 2, 1] + }], { + xaxis: { title: 'x title' }, + yaxis: { title: 'y title' } + }) + .then(function() { + return Plotly.relayout(gd, { zaxis: {} }); + }) + .catch(fail) + .then(done); + }); }); describe('Plotly.restyle', function() {