Skip to content

Commit a073a1e

Browse files
committed
autoHeight factors in the auto and manual margins. See https://observablehq.com/@observablehq/plot-band-scale-bug-1045
fixes #1045
1 parent 6a6eda8 commit a073a1e

File tree

4 files changed

+109
-111
lines changed

4 files changed

+109
-111
lines changed

src/dimensions.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ export function Dimensions(
66
{x: {axis: xAxis} = {}, y: {axis: yAxis} = {}, fx: {axis: fxAxis} = {}, fy: {axis: fyAxis} = {}},
77
{
88
width = 640,
9-
height = autoHeight(scales),
109
facet: {
1110
margin: facetMargin,
1211
marginTop: facetMarginTop = facetMargin !== undefined ? facetMargin : fxAxis === "top" ? 30 : 0,
1312
marginRight: facetMarginRight = facetMargin !== undefined ? facetMargin : fyAxis === "right" ? 40 : 0,
1413
marginBottom: facetMarginBottom = facetMargin !== undefined ? facetMargin : fxAxis === "bottom" ? 30 : 0,
1514
marginLeft: facetMarginLeft = facetMargin !== undefined ? facetMargin : fyAxis === "left" ? 40 : 0
1615
} = {},
16+
marginTopAuto = Math.max((xAxis === "top" ? 30 : 0) + facetMarginTop, yAxis || fyAxis ? 20 : 0.5 - offset),
17+
marginBottomAuto = Math.max((xAxis === "bottom" ? 30 : 0) + facetMarginBottom, yAxis || fyAxis ? 20 : 0.5 + offset),
1718
margin,
18-
marginTop = margin !== undefined
19-
? margin
20-
: Math.max((xAxis === "top" ? 30 : 0) + facetMarginTop, yAxis || fyAxis ? 20 : 0.5 - offset),
19+
marginTop = margin !== undefined ? margin : marginTopAuto,
2120
marginRight = margin !== undefined
2221
? margin
2322
: Math.max((yAxis === "right" ? 40 : 0) + facetMarginRight, xAxis || fxAxis ? 20 : 0.5 + offset),
24-
marginBottom = margin !== undefined
25-
? margin
26-
: Math.max((xAxis === "bottom" ? 30 : 0) + facetMarginBottom, yAxis || fyAxis ? 20 : 0.5 + offset),
23+
marginBottom = margin !== undefined ? margin : marginBottomAuto,
2724
marginLeft = margin !== undefined
2825
? margin
29-
: Math.max((yAxis === "left" ? 40 : 0) + facetMarginLeft, xAxis || fxAxis ? 20 : 0.5 - offset)
26+
: Math.max((yAxis === "left" ? 40 : 0) + facetMarginLeft, xAxis || fxAxis ? 20 : 0.5 - offset),
27+
height = autoHeight(scales, marginTop - marginTopAuto + marginBottom - marginBottomAuto)
3028
} = {}
3129
) {
3230
return {
@@ -43,8 +41,8 @@ export function Dimensions(
4341
};
4442
}
4543

46-
function autoHeight({y, fy, fx}) {
44+
function autoHeight({y, fy, fx}, add) {
4745
const nfy = fy ? fy.scale.domain().length : 1;
4846
const ny = y ? (isOrdinalScale(y) ? y.scale.domain().length : Math.max(7, 17 / nfy)) : 1;
49-
return !!(y || fy) * Math.max(1, Math.min(60, ny * nfy)) * 20 + !!fx * 30 + 60;
47+
return !!(y || fy) * Math.max(1, Math.min(60, ny * nfy)) * 20 + !!fx * 30 + 60 + Math.max(0, add);
5048
}

test/output/downloadsOrdinal.svg

Lines changed: 67 additions & 67 deletions
Loading

0 commit comments

Comments
 (0)