Graphviz generating huge canvas

I’m running Graphviz in a docker, Alpine Linux.

Then installed PyGraphviz, with custom parameters given Graphviz on Alpine linux seems to install on a different location.

Anyways, when I run graphviz, it generated HUGE canvas.

Example dot:

digraph G {
compound=true;
subgraph cluster0 {
a -> b;
a -> c;
b -> d;
c -> d;
}
subgraph cluster1 {
e -> g;
e -> f;
}
b -> f [lhead=cluster1];
d -> e;
c -> g [ltail=cluster0,
lhead=cluster1];
c -> e [ltail=cluster0];
d -> h;
}

Then on command line:

dot -Tsvg test2.dot > test2.svg

This is the SVG:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 9.0.0 (20230911.1827)
 -->
<!-- Title: G Pages: 1 -->
<svg width="272pt" height="116514pt"
 viewBox="0.00 0.00 272.21 116514.19" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 116510.19)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-116510.19 268.21,-116510.19 268.21,4 -4,4"/>
<g id="clust1" class="cluster">
<title>cluster0</title>
<polygon fill="none" stroke="black" points="64,-152 64,-116498.19 206,-116498.19 206,-152 64,-152"/>
</g>
<g id="clust2" class="cluster">
<title>cluster1</title>
<polygon fill="none" stroke="black" points="64,-8 64,-132 206,-132 206,-8 64,-8"/>
</g>
<!-- a -->
<g id="node1" class="node">
<title>a</title>
<ellipse fill="none" stroke="black" cx="135" cy="-116472.19" rx="27" ry="18"/>
<text text-anchor="middle" x="135" y="-116464.14" font-family="Times,serif" font-size="14.00">a</text>
</g>
<!-- b -->
<g id="node2" class="node">
<title>b</title>
<ellipse fill="none" stroke="black" cx="99" cy="-58328.05" rx="27" ry="58090.14"/>
<text text-anchor="middle" x="99" y="-99386.69" font-family="Times,serif" font-size="14.00">b</text>
</g>
<!-- a&#45;&gt;b -->
<g id="edge1" class="edge">
<title>a&#45;&gt;b</title>
<path fill="none" stroke="black" d="M134.99,-116453.83C134.69,-115972 128.22,-105527.98 120.85,-93623.18"/>
<polygon fill="black" stroke="black" points="124.35,-93623.24 120.85,-93613.24 117.35,-93623.24 124.35,-93623.24"/>
</g>
<!-- c -->
<g id="node3" class="node">
<title>c</title>
<ellipse fill="none" stroke="black" cx="171" cy="-58328.05" rx="27" ry="18"/>
<text text-anchor="middle" x="171" y="-58314.75" font-family="Times,serif" font-size="14.00">c</text>
</g>
<!-- a&#45;&gt;c -->
<g id="edge2" class="edge">
<title>a&#45;&gt;c</title>
<path fill="none" stroke="black" d="M135.01,-116453.83C135.71,-115327.91 170.09,-59804.78 170.98,-58357.83"/>
<polygon fill="black" stroke="black" points="174.48,-58358 170.99,-58348 167.48,-58357.99 174.48,-58358"/>
</g>
<!-- d -->
<g id="node4" class="node">
<title>d</title>
<ellipse fill="none" stroke="black" cx="99" cy="-180.95" rx="27" ry="20.95"/>
<text text-anchor="middle" x="99" y="-178.47" font-family="Times,serif" font-size="14.00">d</text>
</g>
<!-- b&#45;&gt;d -->
<g id="edge3" class="edge">
<title>b&#45;&gt;d</title>
<path fill="none" stroke="black" d="M99,-237.45C99,-228.5 99,-220.61 99,-213.81"/>
<polygon fill="black" stroke="black" points="102.5,-213.91 99,-203.91 95.5,-213.91 102.5,-213.91"/>
</g>
<!-- f -->
<g id="node7" class="node">
<title>f</title>
<ellipse fill="none" stroke="black" cx="99" cy="-34" rx="27" ry="18"/>
<text text-anchor="middle" x="99" y="-25.95" font-family="Times,serif" font-size="14.00">f</text>
</g>
<!-- b&#45;&gt;f -->
<g id="edge7" class="edge">
<title>b&#45;&gt;f</title>
<path fill="none" stroke="black" d="M122.09,-26783.55C127.43,-18163.91 132.33,-8823.26 135,-201.91 135.01,-176.22 138.84,-159.73 140.67,-143.39"/>
<polygon fill="black" stroke="black" points="144.15,-143.74 141.43,-133.51 137.17,-143.21 144.15,-143.74"/>
</g>
<!-- c&#45;&gt;d -->
<g id="edge4" class="edge">
<title>c&#45;&gt;d</title>
<path fill="none" stroke="black" d="M171.06,-58309.94C174.8,-57185.29 360.46,-1004.15 135,-237.91 131.89,-227.33 126.09,-216.86 120.04,-207.89"/>
<polygon fill="black" stroke="black" points="123.07,-206.1 114.38,-200.03 117.39,-210.19 123.07,-206.1"/>
</g>
<!-- e -->
<g id="node5" class="node">
<title>e</title>
<ellipse fill="none" stroke="black" cx="99" cy="-106" rx="27" ry="18"/>
<text text-anchor="middle" x="99" y="-97.95" font-family="Times,serif" font-size="14.00">e</text>
</g>
<!-- c&#45;&gt;e -->
<g id="edge10" class="edge">
<title>c&#45;&gt;e</title>
<path fill="none" stroke="black" d="M171.07,-58309.91C175.59,-57183.35 400.01,-906.73 135,-152"/>
<polygon fill="black" stroke="black" points="123.85,-128.87 115.4,-122.48 118.02,-132.75 123.85,-128.87"/>
</g>
<!-- g -->
<g id="node6" class="node">
<title>g</title>
<ellipse fill="none" stroke="black" cx="171" cy="-34" rx="27" ry="18"/>
<text text-anchor="middle" x="171" y="-25.95" font-family="Times,serif" font-size="14.00">g</text>
</g>
<!-- c&#45;&gt;g -->
<g id="edge9" class="edge">
<title>c&#45;&gt;g</title>
<path fill="none" stroke="black" d="M171,-152C171,-149.05 171,-146.15 171,-143.3"/>
<polygon fill="black" stroke="black" points="174.5,-143.51 171,-133.51 167.5,-143.51 174.5,-143.51"/>
</g>
<!-- d&#45;&gt;e -->
<g id="edge8" class="edge">
<title>d&#45;&gt;e</title>
<path fill="none" stroke="black" d="M99,-159.63C99,-152.24 99,-143.74 99,-135.76"/>
<polygon fill="black" stroke="black" points="102.5,-135.76 99,-125.76 95.5,-135.76 102.5,-135.76"/>
</g>
<!-- h -->
<g id="node8" class="node">
<title>h</title>
<ellipse fill="none" stroke="black" cx="27" cy="-106" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-97.95" font-family="Times,serif" font-size="14.00">h</text>
</g>
<!-- d&#45;&gt;h -->
<g id="edge11" class="edge">
<title>d&#45;&gt;h</title>
<path fill="none" stroke="black" d="M83.02,-163.76C73.12,-153.73 60.25,-140.69 49.34,-129.64"/>
<polygon fill="black" stroke="black" points="52.05,-127.4 42.53,-122.74 47.06,-132.31 52.05,-127.4"/>
</g>
<!-- e&#45;&gt;g -->
<g id="edge5" class="edge">
<title>e&#45;&gt;g</title>
<path fill="none" stroke="black" d="M113.92,-90.5C123.77,-80.92 136.86,-68.19 148.03,-57.34"/>
<polygon fill="black" stroke="black" points="150.29,-60.02 155.02,-50.54 145.41,-55 150.29,-60.02"/>
</g>
<!-- e&#45;&gt;f -->
<g id="edge6" class="edge">
<title>e&#45;&gt;f</title>
<path fill="none" stroke="black" d="M99,-87.7C99,-80.41 99,-71.73 99,-63.54"/>
<polygon fill="black" stroke="black" points="102.5,-63.62 99,-53.62 95.5,-63.62 102.5,-63.62"/>
</g>
</g>
</svg>

I assume there is an issue with my Graphviz config? Not sure what to do / how to get it work / what config is off.

For PNG the same result.

Quick possibility: others have reported font problems on docker/Alpine systems. see Cannot build cluster example as SVG, the graphical size is huge (#2440) · Issues · graphviz / graphviz · GitLab

1 Like

You were absolutely right!

“apk add fontconfig ttf-freefont” solved the problem.