Skip to content

Commit af4a2ce

Browse files
committed
only set container's size to 100% when responsive:true
This change will prevent any existing applications from breaking. Anyway setting the container's size to 100% was only useful for responsiveness in modern CSS layouts.
1 parent 9f7a8e7 commit af4a2ce

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

src/plot_api/plot_config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ module.exports = {
5757
*/
5858
autosizable: false,
5959

60-
// responsive: determines whether to change the layout size when window is resized
60+
/*
61+
* responsive: determines whether to change the layout size when window is resized.
62+
* In v2, this option will be removed and will always be true.
63+
*/
6164
responsive: false,
6265

6366
// set the length of the undo/redo queue

src/plot_api/subroutines.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function lsInner(gd) {
5454
var i, subplot, plotinfo, xa, ya;
5555

5656
fullLayout._paperdiv.style({
57-
width: (fullLayout.autosize && !gd._context._hasZeroWidth && !gd.layout.width) ? '100%' : fullLayout.width + 'px',
58-
height: (fullLayout.autosize && !gd._context._hasZeroHeight && !gd.layout.height) ? '100%' : fullLayout.height + 'px'
57+
width: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroWidth && !gd.layout.width) ? '100%' : fullLayout.width + 'px',
58+
height: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroHeight && !gd.layout.height) ? '100%' : fullLayout.height + 'px'
5959
})
6060
.selectAll('.main-svg')
6161
.call(Drawing.setSize, fullLayout.width, fullLayout.height);

test/jasmine/tests/config_test.js

+45-38
Original file line numberDiff line numberDiff line change
@@ -174,44 +174,6 @@ describe('config argument', function() {
174174
.then(done);
175175
});
176176

177-
it('should provide a fixed non-zero width/height when autosize: true and container\' size is zero', function(done) {
178-
gd.style.display = 'inline-block';
179-
Plotly.plot(gd, data, {autosize: true})
180-
.then(function() {
181-
checkLayoutSize(700, 450);
182-
expect(gd.clientWidth).toBe(700);
183-
expect(gd.clientHeight).toBe(450);
184-
})
185-
.then(function() {
186-
return Plotly.newPlot(gd, data, {autosize: true});
187-
})
188-
// It is important to test newPlot to make sure an initially zero size container
189-
// is still considered to have zero size after a plot is drawn into it.
190-
.then(function() {
191-
checkLayoutSize(700, 450);
192-
expect(gd.clientWidth).toBe(700);
193-
expect(gd.clientHeight).toBe(450);
194-
})
195-
.catch(failTest)
196-
.then(done);
197-
});
198-
199-
// The following test is to guarantee we're not breaking the existing behaviour which may not be ideal.
200-
// In a future version, one may prefer autosize:true winning over an explicit width/height when embedded in a webpage.
201-
it('should use the explicitly provided width/height even if autosize:true', function(done) {
202-
gd.style.width = '1000px';
203-
gd.style.height = '500px';
204-
Plotly.plot(gd, data, {autosize: true, width: 1200, height: 700})
205-
.then(function() {
206-
expect(gd.clientWidth).toBe(1000);
207-
expect(gd.clientHeight).toBe(500);
208-
// The plot should overflow the container!
209-
checkLayoutSize(1200, 700);
210-
})
211-
.catch(failTest)
212-
.then(done);
213-
});
214-
215177
it('should respect attribute autosizable: false', function(done) {
216178
var autosize = false;
217179
var config = {
@@ -743,5 +705,50 @@ describe('config argument', function() {
743705
.then(testResponsive)
744706
.then(done);
745707
});
708+
709+
it('should provide a fixed non-zero width/height when autosize/responsive: true and container\' size is zero', function(done) {
710+
fillParent(1, 1, function() {
711+
this.style.display = 'inline-block';
712+
this.style.width = null;
713+
this.style.height = null;
714+
});
715+
Plotly.plot(gd, data, {autosize: true}, {responsive: true})
716+
.then(function() {
717+
checkLayoutSize(700, 450);
718+
expect(gd.clientWidth).toBe(700);
719+
expect(gd.clientHeight).toBe(450);
720+
})
721+
.then(function() {
722+
return Plotly.newPlot(gd, data, {autosize: true}, {responsive: true});
723+
})
724+
// It is important to test newPlot to make sure an initially zero size container
725+
// is still considered to have zero size after a plot is drawn into it.
726+
.then(function() {
727+
checkLayoutSize(700, 450);
728+
expect(gd.clientWidth).toBe(700);
729+
expect(gd.clientHeight).toBe(450);
730+
})
731+
.catch(failTest)
732+
.then(done);
733+
});
734+
735+
// The following test is to guarantee we're not breaking the existing (although maybe not ideal) behaviour.
736+
// In a future version, one may prefer responsive/autosize:true winning over an explicit width/height when embedded in a webpage.
737+
it('should use the explicitly provided width/height even if autosize/responsive:true', function(done) {
738+
fillParent(1, 1, function() {
739+
this.style.width = '1000px';
740+
this.style.height = '500px';
741+
});
742+
743+
Plotly.plot(gd, data, {autosize: true, width: 1200, height: 700}, {responsive: true})
744+
.then(function() {
745+
expect(gd.clientWidth).toBe(1000);
746+
expect(gd.clientHeight).toBe(500);
747+
// The plot should overflow the container!
748+
checkLayoutSize(1200, 700);
749+
})
750+
.catch(failTest)
751+
.then(done);
752+
});
746753
});
747754
});

0 commit comments

Comments
 (0)