diff --git a/src/lib/index.js b/src/lib/index.js index 56f61d66668..895dfde0bb9 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -394,7 +394,9 @@ lib.getPlotDiv = function(el) { lib.isPlotDiv = function(el) { var el3 = d3.select(el); - return el3.size() && el3.classed('js-plotly-plot'); + return el3.node() instanceof HTMLElement && + el3.size() && + el3.classed('js-plotly-plot'); }; lib.removeElement = function(el) { diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index c576d1c46ba..a5b7cdaabe8 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -422,10 +422,6 @@ function plotPolar(gd, data, layout) { if(layout) gd.layout = layout; Polar.manager.fillLayout(gd); - if(gd._fullLayout.autosize === 'initial' && gd._context.autosizable) { - plotAutoSize(gd, {}); - gd._fullLayout.autosize = layout.autosize = true; - } // resize canvas paperDiv.style({ width: gd._fullLayout.width + 'px', @@ -1778,8 +1774,6 @@ function _relayout(gd, aobj) { var redoit = {}, undoit = {}; - var hw = ['height', 'width']; - // for attrs that interact (like scales & autoscales), save the // old vals before making the change // val=undefined will not set a value, just record what the value was. @@ -1827,13 +1821,14 @@ function _relayout(gd, aobj) { // op and has no flag. undoit[ai] = (pleaf === 'reverse') ? vi : p.get(); - // check autosize or autorange vs size and range - if(hw.indexOf(ai) !== -1) { - doextra('autosize', false); - } - else if(ai === 'autosize') { - doextra(hw, undefined); + // Setting width or height to null must reset the graph's width / height + // back to its initial value as computed during the first pass in Plots.plotAutoSize. + // + // To do so, we must manually set them back here using the _initialAutoSize cache. + if(['width', 'height'].indexOf(ai) !== -1 && vi === null) { + gd._fullLayout[ai] = gd._initialAutoSize[ai]; } + // check autorange vs range else if(pleafPlus.match(/^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/)) { doextra(ptrunk + '.autorange', false); } @@ -2017,10 +2012,21 @@ function _relayout(gd, aobj) { } } - // calculate autosizing - if size hasn't changed, - // will remove h&w so we don't need to redraw - if(aobj.autosize) aobj = plotAutoSize(gd, aobj); - if(aobj.height || aobj.width || aobj.autosize) flags.docalc = true; + var oldWidth = gd._fullLayout.width, + oldHeight = gd._fullLayout.height; + + // coerce the updated layout + Plots.supplyDefaults(gd); + + // calculate autosizing + if(gd.layout.autosize) Plots.plotAutoSize(gd, gd.layout, gd._fullLayout); + + // avoid unnecessary redraws + var hasSizechanged = aobj.height || aobj.width || + (gd._fullLayout.width !== oldWidth) || + (gd._fullLayout.height !== oldHeight); + + if(hasSizechanged) flags.docalc = true; if(flags.doplot || flags.docalc) { flags.layoutReplot = true; @@ -2616,86 +2622,6 @@ Plotly.purge = function purge(gd) { return gd; }; -/** - * Reduce all reserved margin objects to a single required margin reservation. - * - * @param {Object} margins - * @returns {{left: number, right: number, bottom: number, top: number}} - */ -function calculateReservedMargins(margins) { - var resultingMargin = {left: 0, right: 0, bottom: 0, top: 0}, - marginName; - - if(margins) { - for(marginName in margins) { - if(margins.hasOwnProperty(marginName)) { - resultingMargin.left += margins[marginName].left || 0; - resultingMargin.right += margins[marginName].right || 0; - resultingMargin.bottom += margins[marginName].bottom || 0; - resultingMargin.top += margins[marginName].top || 0; - } - } - } - return resultingMargin; -} - -function plotAutoSize(gd, aobj) { - var fullLayout = gd._fullLayout, - context = gd._context, - computedStyle; - - var newHeight, newWidth; - - gd.emit('plotly_autosize'); - - // embedded in an iframe - just take the full iframe size - // if we get to this point, with no aspect ratio restrictions - if(gd._context.fillFrame) { - newWidth = window.innerWidth; - newHeight = window.innerHeight; - - // somehow we get a few extra px height sometimes... - // just hide it - document.body.style.overflow = 'hidden'; - } - else if(isNumeric(context.frameMargins) && context.frameMargins > 0) { - var reservedMargins = calculateReservedMargins(gd._boundingBoxMargins), - reservedWidth = reservedMargins.left + reservedMargins.right, - reservedHeight = reservedMargins.bottom + reservedMargins.top, - gdBB = fullLayout._container.node().getBoundingClientRect(), - factor = 1 - 2 * context.frameMargins; - - newWidth = Math.round(factor * (gdBB.width - reservedWidth)); - newHeight = Math.round(factor * (gdBB.height - reservedHeight)); - } - else { - // plotly.js - let the developers do what they want, either - // provide height and width for the container div, - // specify size in layout, or take the defaults, - // but don't enforce any ratio restrictions - computedStyle = window.getComputedStyle(gd); - newHeight = parseFloat(computedStyle.height) || fullLayout.height; - newWidth = parseFloat(computedStyle.width) || fullLayout.width; - } - - if(Math.abs(fullLayout.width - newWidth) > 1 || - Math.abs(fullLayout.height - newHeight) > 1) { - fullLayout.height = gd.layout.height = newHeight; - fullLayout.width = gd.layout.width = newWidth; - } - // if there's no size change, update layout but - // delete the autosize attr so we don't redraw - // but can't call layoutStyles for initial autosize - else if(fullLayout.autosize !== 'initial') { - delete(aobj.autosize); - fullLayout.autosize = gd.layout.autosize = true; - } - - Plots.sanitizeMargins(fullLayout); - - return aobj; -} - // ------------------------------------------------------- // makePlotFramework: Create the plot container and axes // ------------------------------------------------------- @@ -2715,13 +2641,6 @@ function makePlotFramework(gd) { .classed('svg-container', true) .style('position', 'relative'); - // Initial autosize - if(fullLayout.autosize === 'initial') { - plotAutoSize(gd, {}); - fullLayout.autosize = true; - gd.layout.autosize = true; - } - // Make the graph containers // start fresh each time we get here, so we know the order comes out // right, rather than enter/exit which can muck up the order diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 107d2800d97..07fa832976e 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -26,12 +26,13 @@ module.exports = { // we can edit titles, move annotations, etc editable: false, + // DO autosize once regardless of layout.autosize + // (use default width or height values otherwise) + autosizable: false, + // set the length of the undo/redo queue queueLength: 0, - // plot will respect layout.autosize=true and infer its container size - autosizable: false, - // if we DO autosize, do we fill the container or the screen? fillFrame: false, diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index 44e051ee539..ced39429096 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -43,13 +43,17 @@ module.exports = { description: 'Sets the title font.' }), autosize: { - valType: 'enumerated', + valType: 'boolean', role: 'info', - // TODO: better handling of 'initial' - values: [true, false, 'initial'], + dflt: false, description: [ - 'Determines whether or not the dimensions of the figure are', - 'computed as a function of the display size.' + 'Determines whether or not a layout width or height', + 'that has been left undefined by the user', + 'is initialized on each relayout.', + + 'Note that, regardless of this attribute,', + 'an undefined layout width or height', + 'is always initialized on the first call to plot.' ].join(' ') }, width: { diff --git a/src/plots/plots.js b/src/plots/plots.js index 33e499cc443..46015e17d33 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -190,17 +190,25 @@ plots.resize = function(gd) { if(gd._redrawTimer) clearTimeout(gd._redrawTimer); gd._redrawTimer = setTimeout(function() { - if((gd._fullLayout || {}).autosize) { - // autosizing doesn't count as a change that needs saving - var oldchanged = gd.changed; + // return if there is nothing to resize + if(gd.layout.width && gd.layout.height) { + resolve(gd); + return; + } + + delete gd.layout.width; + delete gd.layout.height; + + // autosizing doesn't count as a change that needs saving + var oldchanged = gd.changed; - // nor should it be included in the undo queue - gd.autoplay = true; + // nor should it be included in the undo queue + gd.autoplay = true; - Plotly.relayout(gd, { autosize: true }); + Plotly.relayout(gd, { autosize: true }).then(function() { gd.changed = oldchanged; resolve(gd); - } + }); }, 100); }); }; @@ -305,6 +313,7 @@ function positionPlayWithData(gd, container) { }); } } + plots.sendDataToCloud = function(gd) { gd.emit('plotly_beforeexport'); @@ -368,7 +377,39 @@ plots.supplyDefaults = function(gd) { // first fill in what we can of layout without looking at data // because fullData needs a few things from layout - plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout); + + if(oldFullLayout._initialAutoSizeIsDone) { + + // coerce the updated layout while preserving width and height + var oldWidth = oldFullLayout.width, + oldHeight = oldFullLayout.height; + + plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout); + + if(!newLayout.width) newFullLayout.width = oldWidth; + if(!newLayout.height) newFullLayout.height = oldHeight; + } + else { + + // coerce the updated layout and autosize if needed + plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout); + + var missingWidthOrHeight = (!newLayout.width || !newLayout.height), + autosize = newFullLayout.autosize, + autosizable = gd._context && gd._context.autosizable, + initialAutoSize = missingWidthOrHeight && (autosize || autosizable); + + if(initialAutoSize) plots.plotAutoSize(gd, newLayout, newFullLayout); + else if(missingWidthOrHeight) plots.sanitizeMargins(gd); + + // for backwards-compatibility with Plotly v1.x.x + if(!autosize && missingWidthOrHeight) { + newLayout.width = newFullLayout.width; + newLayout.height = newFullLayout.height; + } + } + + newFullLayout._initialAutoSizeIsDone = true; // keep track of how many traces are inputted newFullLayout._dataLength = newData.length; @@ -414,6 +455,7 @@ plots.supplyDefaults = function(gd) { // relink functions and _ attributes to promote consistency between plots relinkPrivateKeys(newFullLayout, oldFullLayout); + // TODO may return a promise plots.doAutoMargin(gd); // can't quite figure out how to get rid of this... each axis needs @@ -866,11 +908,19 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { color: globalFont.color }); - var autosize = coerce('autosize', - (layoutIn.width && layoutIn.height) ? false : 'initial'); + // Make sure that autosize is defaulted to *true* + // on layouts with no set width and height for backward compatibly, + // in particular https://plot.ly/javascript/responsive-fluid-layout/ + // + // Before https://github.com/plotly/plotly.js/pull/635 , + // layouts with no set width and height were set temporary set to 'initial' + // to pass through the autosize routine + // + // This behavior is subject to change in v2. + coerce('autosize', !(layoutIn.width && layoutIn.height)); + coerce('width'); coerce('height'); - coerce('margin.l'); coerce('margin.r'); coerce('margin.t'); @@ -878,8 +928,7 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { coerce('margin.pad'); coerce('margin.autoexpand'); - // called in plotAutoSize otherwise - if(autosize !== 'initial') plots.sanitizeMargins(layoutOut); + if(layoutIn.width && layoutIn.height) plots.sanitizeMargins(layoutOut); coerce('paper_bgcolor'); @@ -888,6 +937,99 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { coerce('smith'); }; +plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) { + var context = gd._context || {}, + frameMargins = context.frameMargins, + newWidth, + newHeight; + + var isPlotDiv = Lib.isPlotDiv(gd); + + if(isPlotDiv) gd.emit('plotly_autosize'); + + // embedded in an iframe - just take the full iframe size + // if we get to this point, with no aspect ratio restrictions + if(context.fillFrame) { + newWidth = window.innerWidth; + newHeight = window.innerHeight; + + // somehow we get a few extra px height sometimes... + // just hide it + document.body.style.overflow = 'hidden'; + } + else if(isNumeric(frameMargins) && frameMargins > 0) { + var reservedMargins = calculateReservedMargins(gd._boundingBoxMargins), + reservedWidth = reservedMargins.left + reservedMargins.right, + reservedHeight = reservedMargins.bottom + reservedMargins.top, + factor = 1 - 2 * frameMargins; + + var gdBB = fullLayout._container && fullLayout._container.node ? + fullLayout._container.node().getBoundingClientRect() : { + width: fullLayout.width, + height: fullLayout.height + }; + + newWidth = Math.round(factor * (gdBB.width - reservedWidth)); + newHeight = Math.round(factor * (gdBB.height - reservedHeight)); + } + else { + // plotly.js - let the developers do what they want, either + // provide height and width for the container div, + // specify size in layout, or take the defaults, + // but don't enforce any ratio restrictions + var computedStyle = isPlotDiv ? window.getComputedStyle(gd) : {}; + + newWidth = parseFloat(computedStyle.width) || fullLayout.width; + newHeight = parseFloat(computedStyle.height) || fullLayout.height; + } + + var minWidth = plots.layoutAttributes.width.min, + minHeight = plots.layoutAttributes.height.min; + if(newWidth < minWidth) newWidth = minWidth; + if(newHeight < minHeight) newHeight = minHeight; + + var widthHasChanged = !layout.width && + (Math.abs(fullLayout.width - newWidth) > 1), + heightHasChanged = !layout.height && + (Math.abs(fullLayout.height - newHeight) > 1); + + if(heightHasChanged || widthHasChanged) { + if(widthHasChanged) fullLayout.width = newWidth; + if(heightHasChanged) fullLayout.height = newHeight; + } + + // cache initial autosize value, used in relayout when + // width or height values are set to null + if(!gd._initialAutoSize) { + gd._initialAutoSize = { width: newWidth, height: newHeight }; + } + + plots.sanitizeMargins(fullLayout); +}; + +/** + * Reduce all reserved margin objects to a single required margin reservation. + * + * @param {Object} margins + * @returns {{left: number, right: number, bottom: number, top: number}} + */ +function calculateReservedMargins(margins) { + var resultingMargin = {left: 0, right: 0, bottom: 0, top: 0}, + marginName; + + if(margins) { + for(marginName in margins) { + if(margins.hasOwnProperty(marginName)) { + resultingMargin.left += margins[marginName].left || 0; + resultingMargin.right += margins[marginName].right || 0; + resultingMargin.bottom += margins[marginName].bottom || 0; + resultingMargin.top += margins[marginName].top || 0; + } + } + } + return resultingMargin; +} + plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) { var i, _module; @@ -981,6 +1123,7 @@ plots.purge = function(gd) { delete gd._lastHoverTime; delete gd._transitionData; delete gd._transitioning; + delete gd._initialAutoSize; // remove all event listeners if(gd.removeAllListeners) gd.removeAllListeners(); diff --git a/test/image/baselines/ternary_simple.png b/test/image/baselines/ternary_simple.png index c6d5869de40..111ead3bf5f 100644 Binary files a/test/image/baselines/ternary_simple.png and b/test/image/baselines/ternary_simple.png differ diff --git a/test/image/mocks/ternary_simple.json b/test/image/mocks/ternary_simple.json index 62bc4574a66..a23ed822b95 100644 --- a/test/image/mocks/ternary_simple.json +++ b/test/image/mocks/ternary_simple.json @@ -45,7 +45,6 @@ "bgcolor": "#eee" }, "height": 450, - "width": 700, - "autosize": true + "width": 700 } } diff --git a/test/jasmine/tests/config_test.js b/test/jasmine/tests/config_test.js index eeda25ab966..f066d4a1f07 100644 --- a/test/jasmine/tests/config_test.js +++ b/test/jasmine/tests/config_test.js @@ -1,10 +1,147 @@ var Plotly = require('@lib/index'); +var Plots = Plotly.Plots; var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); describe('config argument', function() { + describe('attribute layout.autosize', function() { + var layoutWidth = 1111, + relayoutWidth = 555, + containerWidthBeforePlot = 888, + containerWidthBeforeRelayout = 666, + containerHeightBeforePlot = 543, + containerHeightBeforeRelayout = 321, + data = [], + gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + function checkLayoutSize(width, height) { + expect(gd._fullLayout.width).toBe(width); + expect(gd._fullLayout.height).toBe(height); + + var svg = document.getElementsByClassName('main-svg')[0]; + expect(+svg.getAttribute('width')).toBe(width); + expect(+svg.getAttribute('height')).toBe(height); + } + + function compareLayoutAndFullLayout(gd) { + expect(gd.layout.width).toBe(gd._fullLayout.width); + expect(gd.layout.height).toBe(gd._fullLayout.height); + } + + function testAutosize(autosize, config, layoutHeight, relayoutHeight, done) { + var layout = { + autosize: autosize, + width: layoutWidth + + }, + relayout = { + width: relayoutWidth + }; + + var container = document.getElementById('graph'); + container.style.width = containerWidthBeforePlot + 'px'; + container.style.height = containerHeightBeforePlot + 'px'; + + Plotly.plot(gd, data, layout, config).then(function() { + checkLayoutSize(layoutWidth, layoutHeight); + if(!autosize) compareLayoutAndFullLayout(gd); + + container.style.width = containerWidthBeforeRelayout + 'px'; + container.style.height = containerHeightBeforeRelayout + 'px'; + + Plotly.relayout(gd, relayout).then(function() { + checkLayoutSize(relayoutWidth, relayoutHeight); + if(!autosize) compareLayoutAndFullLayout(gd); + done(); + }); + }); + } + + it('should fill the frame when autosize: false, fillFrame: true, frameMargins: undefined', function(done) { + var autosize = false, + config = { + autosizable: true, + fillFrame: true + }, + layoutHeight = window.innerHeight, + relayoutHeight = layoutHeight; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should fill the frame when autosize: true, fillFrame: true and frameMargins: undefined', function(done) { + var autosize = true, + config = { + fillFrame: true + }, + layoutHeight = window.innerHeight, + relayoutHeight = window.innerHeight; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should fill the container when autosize: false, fillFrame: false and frameMargins: undefined', function(done) { + var autosize = false, + config = { + autosizable: true, + fillFrame: false + }, + layoutHeight = containerHeightBeforePlot, + relayoutHeight = layoutHeight; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should fill the container when autosize: true, fillFrame: false and frameMargins: undefined', function(done) { + var autosize = true, + config = { + fillFrame: false + }, + layoutHeight = containerHeightBeforePlot, + relayoutHeight = containerHeightBeforeRelayout; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should fill the container when autosize: false, fillFrame: false and frameMargins: 0.1', function(done) { + var autosize = false, + config = { + autosizable: true, + fillFrame: false, + frameMargins: 0.1 + }, + layoutHeight = 360, + relayoutHeight = layoutHeight; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should fill the container when autosize: true, fillFrame: false and frameMargins: 0.1', function(done) { + var autosize = true, + config = { + fillFrame: false, + frameMargins: 0.1 + }, + layoutHeight = 360, + relayoutHeight = 288; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + + it('should respect attribute autosizable: false', function(done) { + var autosize = false, + config = { + autosizable: false, + fillFrame: true + }, + layoutHeight = Plots.layoutAttributes.height.dflt, + relayoutHeight = layoutHeight; + testAutosize(autosize, config, layoutHeight, relayoutHeight, done); + }); + }); + describe('showLink attribute', function() { var gd; diff --git a/test/jasmine/tests/lib_test.js b/test/jasmine/tests/lib_test.js index 09707dac9aa..f57d5c2fc17 100644 --- a/test/jasmine/tests/lib_test.js +++ b/test/jasmine/tests/lib_test.js @@ -1520,6 +1520,12 @@ describe('Test lib.js:', function() { }).toThrowError('Separator string required for formatting!'); }); }); + + describe('isPlotDiv', function() { + it('should work on plain objects', function() { + expect(Lib.isPlotDiv({})).toBe(false); + }); + }); }); describe('Queue', function() { diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 723a8f5f581..033f4247f1b 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -1026,6 +1026,37 @@ describe('Test plot api', function() { }); }); + describe('Plotly.newPlot', function() { + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + it('should respect layout.width and layout.height', function(done) { + + // See issue https://github.com/plotly/plotly.js/issues/537 + var data = [{ + x: [1, 2], + y: [1, 2] + }]; + + Plotly.plot(gd, data).then(function() { + var height = 50; + + Plotly.newPlot(gd, data, { height: height }).then(function() { + var fullLayout = gd._fullLayout, + svg = document.getElementsByClassName('main-svg')[0]; + + expect(fullLayout.height).toBe(height); + expect(+svg.getAttribute('height')).toBe(height); + }).then(done); + }); + }); + }); + describe('Plotly.update should', function() { var gd, data, layout, calcdata; diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 31260334cb0..0ffbae73480 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -9,7 +9,21 @@ describe('Test Plots', function() { describe('Plots.supplyDefaults', function() { - var gd; + it('should not throw an error when gd is a plain object', function() { + var height = 100, + gd = { + layout: { + height: height + } + }; + + Plots.supplyDefaults(gd); + expect(gd.layout.height).toBe(height); + expect(gd._fullLayout).toBeDefined(); + expect(gd._fullLayout.height).toBe(height); + expect(gd._fullLayout.width).toBe(Plots.layoutAttributes.width.dflt); + expect(gd._fullData).toBeDefined(); + }); it('should relink private keys', function() { var oldFullData = [{ @@ -41,7 +55,7 @@ describe('Test Plots', function() { annotations: [{}, {}, {}] }; - gd = { + var gd = { _fullData: oldFullData, _fullLayout: oldFullLayout, data: newData, @@ -91,6 +105,45 @@ describe('Test Plots', function() { expect(gd._fullData[0]._expandedInput).toBe(gd._fullData[0]); expect(gd._fullData[1]._expandedInput).toBe(gd._fullData[1]); }); + + function testSanitizeMarginsHasBeenCalledOnlyOnce(gd) { + spyOn(Plots, 'sanitizeMargins').and.callThrough(); + Plots.supplyDefaults(gd); + expect(Plots.sanitizeMargins).toHaveBeenCalledTimes(1); + } + + it('should call sanitizeMargins only once when both width and height are defined', function() { + var gd = { + layout: { + width: 100, + height: 100 + } + }; + + testSanitizeMarginsHasBeenCalledOnlyOnce(gd); + }); + + it('should call sanitizeMargins only once when autosize is false', function() { + var gd = { + layout: { + autosize: false, + height: 100 + } + }; + + testSanitizeMarginsHasBeenCalledOnlyOnce(gd); + }); + + it('should call sanitizeMargins only once when autosize is true', function() { + var gd = { + layout: { + autosize: true, + height: 100 + } + }; + + testSanitizeMarginsHasBeenCalledOnlyOnce(gd); + }); }); describe('Plots.supplyLayoutGlobalDefaults should', function() { @@ -278,7 +331,7 @@ describe('Test Plots', function() { beforeAll(function(done) { gd = createGraphDiv(); - Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {}) + Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }]) .then(function() { gd.style.width = '400px'; gd.style.height = '400px'; diff --git a/test/jasmine/tests/toimage_test.js b/test/jasmine/tests/toimage_test.js index 26fc91f872b..6cde6567067 100644 --- a/test/jasmine/tests/toimage_test.js +++ b/test/jasmine/tests/toimage_test.js @@ -78,6 +78,8 @@ describe('Plotly.toImage', function() { subplotMock.layout.width = 700; Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function(gd) { + expect(gd.layout.height).toBe(600); + expect(gd.layout.width).toBe(700); return Plotly.toImage(gd); }).then(function(url) { return new Promise(function(resolve) {