Skip to content

Commit

Permalink
computeTreeWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 19, 2023
1 parent 5fa55f0 commit 57dd13b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/what-is-d3.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const paths = computed(() => {
return paths;
});

// https://github.com/observablehq/plot/issues/1703
function computeTreeWidth(paths) {
const root = d3.tree().nodeSize([1, 1])(d3.stratify().path((d) => d.path)(paths));
const [x1, x2] = d3.extent(root, (d) => d.x);
return x2 - x1;
}

</script>

# What is D3?
Expand Down Expand Up @@ -55,7 +62,7 @@ What all’s in the D3 toolbox? We recommend exploring the documentation and exa

<PlotRender :options='{
axis: null,
height: 1000,
height: computeTreeWidth(paths) * 12,
marginTop: 4,
marginBottom: 4,
marginRight: 120,
Expand Down

0 comments on commit 57dd13b

Please sign in to comment.