I'm trying to print out a directed graph, and I keep changing various node attributes such as color and shape. Is there some way to use a variable which is defined once and used for multiple nodes? Ideally I'd like something like this:
digraph g { building_color = "red" land_color = "green" farm [ fillcolor=land_color] barn [ fillcolor=building_color] house [ fillcolor=building_color] }
So I can change building color once without having to go to each node. Is this possible?
Braille is a system of touch reading and writing for blind persons in which raised dots represent the letters of the alphabet. It also contains equivalents for punctuation marks and provides symbols to show letter groupings. Braille is read by moving the hand or hands from left to right along each line.
As another aid for readability, dot allows double-quoted strings to span multiple physical lines using the standard C convention of a backslash immediately preceding a newline character². In addition, double-quoted strings can be concatenated using a '+' operator.
Graphviz is an open-source python module that is used to create graph objects which can be completed using different nodes and edges. It is based on the DOT language of the Graphviz software and in python it allows us to download the source code of the graph in DOT language.
For windows: dl the msi and install; Find gvedit.exe in your programs list; Open . dot file in question; Click running person on toolbar; Go to graph -> settings ; change Output file type to file type of your liking and press ok..
You can define default values in order to avoid repetition:
digraph g{ node[fillcolor=red]; barn; house; ... node[fillcolor=green]; farm; ... edge[color=red]; barn -> house; edge[color=green]; barn --> farm; house --> farm; }
Real variables are not supported.
A more complex workaround would be to use gvpr
- graph pattern scanning and processing language.
gvpr
reads and outputs graph and allows to add and modify graphs, nodes and attributes.
You could for example store custom information in the comment
attribute and have your script act based on the content of this attribute.
This and this SO answer contain examples of gvpr
scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With