From 1a2da6ae831556ecfc9db6a75c5cbe2ed6c7cc4b Mon Sep 17 00:00:00 2001 From: David Straub Date: Sun, 15 Oct 2023 21:06:29 +0200 Subject: [PATCH] Fix yOffset in tree chart --- src/charts/TreeChart.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/charts/TreeChart.js b/src/charts/TreeChart.js index 5acd7401..725c50b7 100644 --- a/src/charts/TreeChart.js +++ b/src/charts/TreeChart.js @@ -21,7 +21,7 @@ function getMinMaxX(descendants) { const xValues = descendants.map(d => d.x) const maxX = max(xValues) const minX = min(xValues) - return maxX - minX + return [minX, maxX] } export function TreeChart( @@ -68,8 +68,9 @@ export function TreeChart( // Use the required curve if (typeof curve !== 'function') throw new Error('Unsupported curve') const width = trueDepth * boxWidth + (trueDepth - 1) * gapX + 2 * padding - const height = getMinMaxX(descendants) + boxHeight - const yOffset = -height / 2 + const [minX, maxX] = getMinMaxX(descendants) + const height = maxX - minX + boxHeight + const yOffset = minX - boxHeight / 2 const svg = create('svg') .attr('viewBox', [-boxWidth / 2 - padding, yOffset, width, height])