Skip to content

Commit efe0030

Browse files
Filmbostock
andauthored
automatic height (#337)
* automatic height closes #323 * fix tests * if y is not ordinal, give it some more space as if it were or cardinality 6 * - use the computed domain - y is always either ordinal or quantitative - fy is always ordinal * tidy * tweak autoHeight * fix non-ordinal autoHeight * automatic height closes #323 * rebase * rebase more * plot outputs * (auto-height:) with vertical facets, the base height for a cell is half that of a usual plot * tweak autoHeight Co-authored-by: Mike Bostock <[email protected]>
1 parent 12af477 commit efe0030

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+13926
-13866
lines changed

src/plot.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function plot(options = {}) {
9898
}
9999

100100
function Dimensions(
101-
{y, fy, fx},
101+
scales,
102102
{
103103
x: {axis: xAxis} = {},
104104
y: {axis: yAxis} = {},
@@ -107,7 +107,7 @@ function Dimensions(
107107
},
108108
{
109109
width = 640,
110-
height = y || fy ? 396 : fx ? 90 : 60,
110+
height = autoHeight(scales),
111111
facet: {
112112
marginTop: facetMarginTop = fxAxis === "top" ? 30 : 0,
113113
marginRight: facetMarginRight = fyAxis === "right" ? 40 : 0,
@@ -137,3 +137,9 @@ function Dimensions(
137137
function ScaleFunctions(scales) {
138138
return Object.fromEntries(Object.entries(scales).map(([name, {scale}]) => [name, scale]));
139139
}
140+
141+
function autoHeight({y, fy, fx}) {
142+
const nfy = fy ? fy.scale.domain().length : 1;
143+
const ny = y && y.type === "ordinal" ? y.scale.domain().length : Math.max(7, 17 / nfy);
144+
return !!(y || fy) * Math.max(1, Math.min(60, ny * nfy)) * 20 + !!fx * 30 + 60;
145+
}

test/output/aaplCandlestick.svg

Lines changed: 256 additions & 256 deletions
Loading

test/output/aaplChangeVolume.svg

Lines changed: 1284 additions & 1284 deletions
Loading

test/output/aaplClose.svg

Lines changed: 15 additions & 15 deletions
Loading

test/output/aaplMonthly.svg

Lines changed: 199 additions & 199 deletions
Loading

test/output/aaplVolume.svg

Lines changed: 27 additions & 27 deletions
Loading

test/output/athletesNationality.svg

Lines changed: 48 additions & 48 deletions
Loading

0 commit comments

Comments
 (0)