# Calculate D3 Graphviz height and width before rendering

**URL:** <https://forum.graphviz.org/t/calculate-d3-graphviz-height-and-width-before-rendering/3267>\
**Category:** d3-graphviz\
**Created:** [January 22, 2026, 4:53am UTC](https://forum.graphviz.org/t/calculate-d3-graphviz-height-and-width-before-rendering/3267 "2026-01-22T04:53:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bananaapache](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@bananaapache](https://forum.graphviz.org/u/bananaapache)\
**Post date:** [January 22, 2026, 4:53am UTC](https://forum.graphviz.org/t/calculate-d3-graphviz-height-and-width-before-rendering/3267/1 "2026-01-22T04:53:09Z")

</div>

I am fairly new to using GraphViz so I apologize if the answer to this seems obvious. For some background, I am working on a website where users can display varying sizes of graphs using d3 graphviz.

I am having issues where graphs with a small number of nodes, say 3 or 4, is right in the users’ face, since graphviz sets initial zoom to fit. But, for bigger graphs, the initial zoom setting to fit is no problem.

I had already tried using the minimum size attribute `size="500!,500!"`, but it did not seem to work (maybe I’m using it wrong).

My initial thought was to try to compare the graph’s width to the user’s viewport width, but am having trouble finding a function to compute the graph’s width before rendering.

So is there a way that I’m completely missing to limit the maximum scale of the initial fit zoom so that small graphs maintain a reasonable, readable size on the screen, while still allowing large graphs to scale down and fit within the container?

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [January 23, 2026, 1:41am UTC](https://forum.graphviz.org/t/calculate-d3-graphviz-height-and-width-before-rendering/3267/2 "2026-01-23T01:41:32Z")

</div>

**size** uses _inches_ for [units](https://www.graphviz.org/docs/attrs/size/), a much smaller value would work better

Additionally, both the **svg** and the **dot** output formats provide dimensions of the resulting graph (width & height for **svg** , bb for **dot** ). You could produce either format and then make desired adjustments before actually displaying the result (yes, you would have to rerun if you produced **dot** at first)
