Notation for setting Graphviz attributes
Graphviz notation

Next:Aliases that resemble DOT code


The graphviz.notation vocabulary provides words for setting Graphviz attributes in a way that looks similar to the DOT language (see http://graphviz.org/content/dot-language).

For every slot named, say, attr in the node-attributes, edge-attributes, and graph-attributes tuples, a generic word named =attr is defined with the stack effect ( graphviz-obj val -- graphviz-obj' ).

In each such =attr word, val must be an object supported by the present word, which is always called on val before it's stored in a slot.

These generics will "do the right thing" in setting the corresponding attribute of graphviz-obj.

For example, since graph-attributes has a label slot, the generic =label is defined, along with methods so that if graphviz-obj is a...
...graph or subgraph, a new graph-attributes instance is created, has its label slot set to val, and is added to graphviz-obj.
...graph-attributes instance, its label slot is set to val.


Since edge-attributes has a label slot, further methods are defined so that if graphviz-obj is an...
...edge, its attributes slot has its label slot set to val.
...edge-attributes instance, its label slot is set to val.


Finally, since node-attributes has a label slot, still more methods are defined so that if graphviz-obj is a...
...node, its attributes slot has its label slot set to val.
...node-attributes instance, its label slot is set to val.


Thus, instead of
<graph> <graph-attributes> "Bad-ass graph" >>label add 1 2 <edge> dup attributes>> "This edge is dumb" swap label<< add 3 <node> dup attributes>> "This node is cool" swap label<< add

you can simply write
<graph> "Bad-ass graph" =label 1 2 <edge> "This edge is dumb" =label add 3 <node> "This node is cool" =label add


However, since the slot labelloc only exists in graph-attributes and node-attributes, there won't be a method for edge or edge-attributes objects:
USING: continuations graphviz graphviz.notation io kernel ; <graph> ! This is OK: "t" =labelloc ! This is not OK: [ 1 2 <edge> "b" =labelloc add ] [ drop "not for edges!" write ] recover drop
not for edges!


For the full list of attribute-setting words, consult the list of generic words for the graphviz.notation vocabulary.