Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: change font for the whole graph?

Tags:

graphviz

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?

like image 453
pirkil Avatar asked Jun 04 '12 09:06

pirkil


People also ask

How to set default font in GraphViz file?

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"]; ... }

Is it possible to use bold text in GraphViz labels?

I need to convert to png. You may use HTML-like labels in graphviz and define labels with partially bold text: Note the restriction ... "In addition, all of these markups are currently only available via the cairo and svg renderers."

What does the GraphViz module do?

The graphviz module provides two classes: Graph and Digraph. They create graph descriptions in the DOT language for undirected and directed graphs respectively.

What is the difference between graph and digraph in GraphViz?

The graphviz package provides two main classes: graphviz.Graph and graphviz.Digraph. They create graph descriptions in the DOT language for undirected and directed graphs respectively. They have the same API. Graph and Digraph produce different DOT syntax and have different values for directed.


2 Answers

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"];  ... } 
like image 118
marapet Avatar answered Oct 07 '22 16:10

marapet


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 
like image 42
JJ Geewax Avatar answered Oct 07 '22 18:10

JJ Geewax