Graphviz: change font for the whole graph?
GraphvizGraphviz Problem Overview
I am wondering if I can define an alternative font for the whole graph.
...
digraph script_concept {
graph [layout="dot",fontname="helvetica"];
...
According to this [1] older post the fontname atribute can be defined only separately:
> Nodes and edges don't inherit the font of the graph, you need to specify > them separately
Is there any other way, how to define the font globally?
[1]: http://webcache.googleusercontent.com/search?q=cache:cUK902XMrrsJ:https://mailman.research.att.com/pipermail/graphviz-interest/2008q3/005489.html/ "mail archive"
Graphviz Solutions
Solution 1 - Graphviz
No, there is no other way.
As in the forum post you linked, you have to define the default values separately (like the other attributes) at the beginning of your graphviz file:
digraph g {
graph [fontname = "helvetica"];
node [fontname = "helvetica"];
edge [fontname = "helvetica"];
...
}
Solution 2 - Graphviz
Not sure if this is a recent update, but you can change these at the command-line level using the -G
, -E
and -N
attribute flags. That is, the following works for me:
$ dot -Tpng -Nfontname=Roboto -Nfontsize=10 \
-Efontname=Roboto -Efontsize=10 \
tree.dot > tree.png
Solution 3 - Graphviz
However, there's one easy trick, if you are exporting svgs:
sed 's/Times,serif/Helvetica/g' thegraph.svg > thegraph_helvetica.svg
combine this with Make and all the horror will be hidden :) here's an example Makefile:
all: helvetica
svg:
cat thegraph.dot | dot -Tsvg > thegraph.svg
helvetica: svg
sed 's/Times,serif/Helvetica/g' thegraph.svg > thegraph_helvetica.svg