Skip to content
10 changes: 8 additions & 2 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function plot(options = {}) {
}

function Dimensions(
{y, fy, fx},
scales,
{
x: {axis: xAxis} = {},
y: {axis: yAxis} = {},
Expand All @@ -107,7 +107,7 @@ function Dimensions(
},
{
width = 640,
height = y || fy ? 396 : fx ? 90 : 60,
height = autoHeight(scales),
facet: {
marginTop: facetMarginTop = fxAxis === "top" ? 30 : 0,
marginRight: facetMarginRight = fyAxis === "right" ? 40 : 0,
Expand Down Expand Up @@ -137,3 +137,9 @@ function Dimensions(
function ScaleFunctions(scales) {
return Object.fromEntries(Object.entries(scales).map(([name, {scale}]) => [name, scale]));
}

function autoHeight({y, fy, fx}) {
const nfy = fy ? fy.scale.domain().length : 1;
const ny = y && y.type === "ordinal" ? y.scale.domain().length : Math.max(7, 17 / nfy);
return !!(y || fy) * Math.max(1, Math.min(60, ny * nfy)) * 20 + !!fx * 30 + 60;
}
512 changes: 256 additions & 256 deletions test/output/aaplCandlestick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,568 changes: 1,284 additions & 1,284 deletions test/output/aaplChangeVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions test/output/aaplClose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
398 changes: 199 additions & 199 deletions test/output/aaplMonthly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 27 additions & 27 deletions test/output/aaplVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 48 additions & 48 deletions test/output/athletesNationality.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading