Skip to content

Commit 015ff80

Browse files
authored
Merge pull request #7313 from plotly/bugfix/set-container-height
[Bugfix] Fix Container Height
2 parents f8c7b5d + b79d5d0 commit 015ff80

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ To see all merged commits on the master branch that will be part of the next plo
99

1010
where X.Y.Z is the semver of most recent plotly.js release.
1111

12+
## [2.35.3] -- 2024-12-13
13+
14+
### Fixed
15+
- Set height and width on the `.plotly-container` div to 100% [[#7314](https://github.com/plotly/plotly.js/pull/7314)]
16+
17+
1218
## [3.0.0-rc.1] -- 2024-11-27
1319

1420
### Removed

draftlogs/7313_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Set height and width on the `.plotly-container` div to 100% [[#7313](https://github.com/plotly/plotly.js/pull/7313)]

src/plot_api/plot_api.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,25 @@ function makePlotFramework(gd) {
36713671
fullLayout._container.enter()
36723672
.insert('div', ':first-child')
36733673
.classed('plot-container', true)
3674-
.classed('plotly', true);
3674+
.classed('plotly', true)
3675+
// The plot container should always take the full with the height of its
3676+
// parent (the graph div). This ensures that for responsive plots
3677+
// without a height or width set, the paper div will take up the full
3678+
// height & width of the graph div.
3679+
// So, for responsive plots without a height or width set, if the plot
3680+
// container's height is left to 'auto', its height will be dictated by
3681+
// its childrens' height. (The plot container's only child is the paper
3682+
// div.)
3683+
// In this scenario, the paper div's height will be set to 100%,
3684+
// which will be 100% of the plot container's auto height. That is
3685+
// meaninglesss, so the browser will use the paper div's children to set
3686+
// the height of the plot container instead. However, the paper div's
3687+
// children do not have any height, because they are all positioned
3688+
// absolutely, and therefore take up no space.
3689+
.style({
3690+
width: "100%",
3691+
height: "100%"
3692+
});
36753693

36763694
// Make the svg container
36773695
fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]);

src/plot_api/subroutines.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ function lsInner(gd) {
5252
var axList = Axes.list(gd, '', true);
5353
var i, subplot, plotinfo, ax, xa, ya;
5454

55+
// Set the width and height of the paper div ('.svg-container') in
56+
// accordance with the users configuration and layout.
57+
// If the plot is responsive and the user has not set a width/height, then
58+
// the width/height of the paper div is set to 100% to fill the parent
59+
// container.
60+
// We can't leave the height or width unset because all of the contents of
61+
// the paper div are positioned absolutely (and will therefore not take up
62+
// any space).
5563
fullLayout._paperdiv.style({
5664
width: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroWidth && !gd.layout.width) ? '100%' : fullLayout.width + 'px',
5765
height: (gd._context.responsive && fullLayout.autosize && !gd._context._hasZeroHeight && !gd.layout.height) ? '100%' : fullLayout.height + 'px'

0 commit comments

Comments
 (0)