Skip to content
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
13 changes: 11 additions & 2 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,15 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
)(layoutIn, layoutOut, coerce);
};

function getComputedSize(attr) {
return (
(typeof attr === 'string') &&
(attr.substr(attr.length - 2) === 'px') &&
parseFloat(attr)
);
}


plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {
var context = gd._context || {};
var frameMargins = context.frameMargins;
Expand All @@ -1592,8 +1601,8 @@ plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {
// but don't enforce any ratio restrictions
var computedStyle = isPlotDiv ? window.getComputedStyle(gd) : {};

newWidth = parseFloat(computedStyle.width) || parseFloat(computedStyle.maxWidth) || fullLayout.width;
newHeight = parseFloat(computedStyle.height) || parseFloat(computedStyle.maxHeight) || fullLayout.height;
newWidth = getComputedSize(computedStyle.width) || getComputedSize(computedStyle.maxWidth) || fullLayout.width;
newHeight = getComputedSize(computedStyle.height) || getComputedSize(computedStyle.maxHeight) || fullLayout.height;

if(isNumeric(frameMargins) && frameMargins > 0) {
var factor = 1 - 2 * frameMargins;
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,33 @@ describe('config argument', function() {

testAutosize(autosize, config, layoutHeight, relayoutHeight, done);
});

[
{display: 'none', dflt: true},
{display: '', dflt: false}
].forEach(function(spec) {
it('ignores percent sizes when container is hidden', function(done) {
gd.style.width = '100%';
gd.style.height = '100%';
gd.style.display = spec.display;

var dfltWidth = Plots.layoutAttributes.width.dflt;
var dfltHeight = Plots.layoutAttributes.height.dflt;

Plotly.plot(gd, data, {autosize: true})
.then(function() {
if(spec.dflt) {
expect(gd._fullLayout.width).toBe(dfltWidth);
expect(gd._fullLayout.height).toBe(dfltHeight);
} else {
expect(gd._fullLayout.width).not.toBe(dfltWidth);
expect(gd._fullLayout.height).not.toBe(dfltHeight);
}
})
.catch(failTest)
.then(done);
});
});
});

describe('showLink attribute', function() {
Expand Down