Graphviz ignores size attribute (A4 page)

后端 未结 1 886
感动是毒
感动是毒 2021-01-12 11:15

Consider the following minimal example graph that should fit on an A4 page

digraph G{
size="8.3,11.7!" ratio=fill;
foo->bar;
}

C

相关标签:
1条回答
  • 2021-01-12 12:02

    The problem lies in the details about the ratio:

    Note that this is adjusted before the size attribute constraints are enforced. In addition, the calculations usually ignore the node sizes, so the final drawing size may only approximate what is desired.

    It seems that graphviz

    • lays out the nodes as points (ignoring size)
    • adjusts for the ratio of the point nodes (still no size for nodes)
    • applies the graph's size constraints (in our case, upscaling the image): here we have already reached the desired dimensions, but we're not finished...
    • then point nodes become nodes with a real size (by default 0.5 inch high and 0.75 inch wide)
    • and finally the whole output gets the margin added

    The result would be bigger than A4.

    Therefore if we were to make nodes and margin as small as possible, then the output should come relatively close to A4.

    Setting margin to 0 and the node's shape to point as well as their width and height to the minimum values with the following graph:

    digraph G{
     ratio="fill";
     size="8.3,11.7!";
     margin=0;
    
     node[shape=point, height=0.02, width=0.01];
     foo->bar;
    }
    

    neato -Tpdf with this graph results in a PDF with dimensions 211x297mm (using 8.267 inches as width will result in a clean 210x297mm).


    Unfortunately, even knowing how graphviz works in respect to ratio=fill, I don't think there's an easy way to make sure the final result is always A4 when using nodes which actually have a width and height.

    0 讨论(0)
提交回复
热议问题