Skip to content

Commit

Permalink
#3134: Autosize vertically
Browse files Browse the repository at this point in the history
  • Loading branch information
VassilIordanov committed Aug 10, 2020
1 parent 37ca952 commit 3e5ae0c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions client/src/components/graphs/OrganizationalChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,25 @@ const OrganizationalChart = ({
return
}

setHeight(1000)
}, [data, height, width, root])
const boundingBox = root.descendants().reduce(
(box, nodeArg) => {
const size = getSize(nodeArg.data, getScale(nodeArg.data))
return {
xmin: Math.min(box.xmin, nodeArg.x || 0),
xmax: Math.max(box.xmax, nodeArg.x + size[0] || 0),
ymin: Math.min(box.ymin, nodeArg.y || 0),
ymax: Math.max(box.ymax, nodeArg.y + size[1] || 0)
}
},
{
xmin: Number.MAX_SAFE_INTEGER,
xmax: Number.MIN_SAFE_INTEGER,
ymin: Number.MAX_SAFE_INTEGER,
ymax: Number.MIN_SAFE_INTEGER
}
)
setHeight(boundingBox.ymax - boundingBox.ymin + 50)
}, [data, width, root, getSize, getScale])

return (
<>
Expand Down

0 comments on commit 3e5ae0c

Please sign in to comment.