Skip to content

Commit

Permalink
Fix yOffset in tree chart
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Oct 15, 2023
1 parent de858e0 commit 1a2da6a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/charts/TreeChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 1a2da6a

Please sign in to comment.