1 ! Copyright (C) 2011 Alex Vondrak.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: graphviz graphviz.attributes help.markup help.syntax
4 kernel present sequences ;
7 { add-edge [add-edge -- ~-- [-- } related-words
8 { add-edge [add-edge -> ~-> [-> } related-words
10 [add-node [add-edge [-- [-> [node [edge [graph ];
15 { "graph" { $or graph subgraph } }
18 { "graph'" { $or graph subgraph } }
20 { $description "Shorthand for " { $link add-edge } ". Makes undirected " { $link graph } "s read more like graphs in the DOT language." }
29 "it looks better to write"
36 "Compare this with the DOT language, where you'd write"
49 { "graph" { $or graph subgraph } }
52 { "graph'" { $or graph subgraph } }
54 { $description "Shorthand for " { $link add-edge } ". Makes directed " { $link graph } "s read more like digraphs in the DOT language." }
63 "it looks better to write"
70 "Compare this with the DOT language, where you'd write"
87 { $description "Shorthand for " { $link <edge> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that undirected " { $link graph } "s read more like graphs in the DOT language." }
92 " 1 2 <edge> \"red\" =color add"
94 "it looks better to write"
97 " 1 2 [-- \"red\" =color ];"
99 "Compare this with the DOT language, where you'd write"
102 " 1 -- 2 [ color=\"red\" ];"
114 { $description "Shorthand for " { $link <edge> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that directed " { $link graph } "s read more like digraphs in the DOT language." }
119 " 1 2 <edge> \"red\" =color add"
121 "it looks better to write"
124 " 1 2 [-> \"red\" =color ];"
126 "Compare this with the DOT language, where you'd write"
129 " 1 -> 2 [ color=\"red\" ];"
137 { "graph" { $or graph subgraph } }
138 { "statement" object }
139 { "graph'" { $or graph subgraph } }
141 { $description "Synonym for " { $link add } " meant to be the \"other half\" of various " { $vocab-link "graphviz.notation" } " words like " { $links [add-edge [add-node [graph } ", etc." }
142 { $examples "Refer to the documentation for the complementary words listed below." }
151 { $description "Shorthand for " { $link <edge> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that setting an " { $link edge } "'s " { $slot "attributes" } " reads more like the equivalent in the DOT language." }
156 " 1 2 <edge> \"red\" =color add"
158 "it looks better to write"
161 " 1 2 [add-edge \"red\" =color ];"
163 "Compare this with the DOT language, where you'd write"
166 " 1 -- 2 [ color=\"red\" ];"
170 "This has the advantage over " { $link [-- } " and " { $link [-> } " of reading nicely for both directed " { $emphasis "and" } " undirected " { $link graph } "s."
179 { $description "Shorthand for " { $link <node> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that setting a " { $link node } "'s " { $slot "attributes" } " reads more like the equivalent in the DOT language." }
184 " \"foo\" <node> \"red\" =color add"
186 "it looks better to write"
189 " \"foo\" [add-node \"red\" =color ];"
191 "Compare this with the DOT language, where you'd write"
194 " foo [ color=\"red\" ];"
202 { "attrs" edge-attributes }
204 { $description "Shorthand for " { $link <edge-attributes> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that adding " { $link edge-attributes } " to a " { $link graph } " or " { $link subgraph } " reads more like the equivalent in the DOT language." }
209 " <edge-attributes> \"red\" =color add"
211 "it looks better to write"
214 " [edge \"red\" =color ];"
216 "Compare this with the DOT language, where you'd write"
219 " [edge color=\"red\" ];"
227 { "attrs" graph-attributes }
229 { $description "Shorthand for " { $link <graph-attributes> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that adding " { $link graph-attributes } " to a " { $link graph } " or " { $link subgraph } " reads more like the equivalent in the DOT language." }
230 { $notes "This word is rendered redundant by the " { $link graph } " and " { $link subgraph } " methods defined by " { $vocab-link "graphviz.notation" } " for setting attributes. Sometimes it still might look better to delineate certain attribute-setting code." }
235 " <graph-attributes> \"LR\" =rankdir \"blah\" =label add"
237 "it looks better to write"
240 " [graph \"LR\" =rankdir \"blah\" =label ];"
242 "Compare this with the DOT language, where you'd write"
245 " [graph rankdir=\"LR\" label=\"blah\" ];"
249 "Of course, you could just write"
255 "Similarly, in the DOT language you could just write"
267 { "attrs" node-attributes }
269 { $description "Shorthand for " { $link <node-attributes> } " to be used with " { $link ]; } " and attribute-setting generic words (see " { $link { "graphviz.notation" "=attrs" } } ") so that adding " { $link node-attributes } " to a " { $link graph } " or " { $link subgraph } " reads more like the equivalent in the DOT language." }
274 " <node-attributes> \"red\" =color add"
276 "it looks better to write"
279 " [node \"red\" =color ];"
281 "Compare this with the DOT language, where you'd write"
284 " [node color=\"red\" ];"
292 { "graph" { $or graph subgraph } }
294 { "graph'" { $or graph subgraph } }
296 { $description "Shorthand for " { $link add-path } ". Meant to be a Factor replacement for the DOT language's more verbose path notation." }
310 "whereas in the DOT language you'd write"
321 { "graph" { $or graph subgraph } }
323 { "graph'" { $or graph subgraph } }
325 { $description "Shorthand for " { $link add-path } ". Meant to be a Factor replacement for the DOT language's more verbose path notation." }
339 "whereas in the DOT language you'd write"
348 ARTICLE: { "graphviz.notation" "=attrs" } "Notation for setting Graphviz attributes"
349 "The " { $vocab-link "graphviz.notation" } " vocabulary provides words for setting Graphviz attributes in a way that looks similar to the DOT language (see " { $url "https://graphviz.org/content/dot-language" } ")."
351 "For every slot named, say, " { $snippet "attr" } " in the " { $link node-attributes } ", " { $link edge-attributes } ", and " { $link graph-attributes } " tuples, a generic word named " { $snippet "=attr" } " is defined with the stack effect " { $snippet "( graphviz-obj val -- graphviz-obj' )" } "."
353 "In each such " { $snippet "=attr" } " word, " { $snippet "val" } " must be an object supported by the " { $link present } " word, which is always called on " { $snippet "val" } " before it's stored in a slot."
355 "These generics will \"do the right thing\" in setting the corresponding attribute of " { $snippet "graphviz-obj" } "."
357 "For example, since " { $link graph-attributes } " has a " { $slot "label" } " slot, the generic " { $link =label } " is defined, along with methods so that if " { $snippet "graphviz-obj" } " is a..."
359 { "..." { $link graph } " or " { $link subgraph } ", a new " { $link graph-attributes } " instance is created, has its " { $slot "label" } " slot set to " { $snippet "val" } ", and is " { $link add } "ed to " { $snippet "graphviz-obj" } "." }
360 { "..." { $link graph-attributes } " instance, its " { $slot "label" } " slot is set to " { $snippet "val" } "." }
363 "Since " { $link edge-attributes } " has a " { $slot "label" } " slot, further methods are defined so that if " { $snippet "graphviz-obj" } " is an..."
365 { "..." { $link edge } ", its " { $slot "attributes" } " slot has its " { $slot "label" } " slot set to " { $snippet "val" } "." }
366 { "..." { $link edge-attributes } " instance, its " { $slot "label" } " slot is set to " { $snippet "val" } "." }
369 "Finally, since " { $link node-attributes } " has a " { $slot "label" } " slot, still more methods are defined so that if " { $snippet "graphviz-obj" } " is a..."
371 { "..." { $link node } ", its " { $slot "attributes" } " slot has its " { $slot "label" } " slot set to " { $snippet "val" } "." }
372 { "..." { $link node-attributes } " instance, its " { $slot "label" } " slot is set to " { $snippet "val" } "." }
378 " <graph-attributes>"
379 " \"Bad-ass graph\" >>label"
381 " 1 2 <edge> dup attributes>>"
382 " \"This edge is dumb\" swap label<<"
384 " 3 <node> dup attributes>>"
385 " \"This node is cool\" swap label<<"
388 "you can simply write"
391 " \"Bad-ass graph\" =label"
393 " \"This edge is dumb\" =label"
396 " \"This node is cool\" =label"
400 "However, since the slot " { $slot "labelloc" } " only exists in " { $link graph-attributes } " and " { $link node-attributes } ", there won't be a method for " { $link edge } " or " { $link edge-attributes } " objects:"
402 "USING: continuations graphviz graphviz.notation io kernel ;"
408 " [ 1 2 <edge> \"b\" =labelloc add ]"
409 " [ drop \"not for edges!\" write ] recover drop"
413 "For the full list of attribute-setting words, consult the list of generic words for the " { $vocab-link "graphviz.notation" } " vocabulary."
416 ARTICLE: { "graphviz.notation" "synonyms" } "Aliases that resemble DOT code"
417 "The " { $vocab-link "graphviz.notation" } " vocabulary provides aliases for words defined in the " { $vocab-link "graphviz" } " and " { $vocab-link "graphviz.attributes" } " vocabularies. These will make Factor code read more like DOT code (see " { $url "https://graphviz.org/content/dot-language" } ")."
419 "Notation for edges without attributes:"
426 "Notation for nodes/edges with local attributes:"
433 "Notation for global attributes:"
439 "Word to \"close off\" notation for attributes:"
445 ARTICLE: "graphviz.notation" "Graphviz notation"
446 "The " { $vocab-link "graphviz.notation" } " vocabulary provides words for building " { $link graph } "s in a way that looks similar to the DOT language (see " { $url "https://graphviz.org/content/dot-language" } ")."
448 "The " { $vocab-link "graphviz" } " vocabulary alone already follows the general structure of the DOT language: " { $link graph } "s and " { $link subgraph } "s consist of an ordered sequence of " { $slot "statements" } "; each statement will " { $link add } " either a " { $link node } ", an " { $link edge } ", or some attribute declaration (" { $links graph-attributes node-attributes edge-attributes } "); and " { $slot "attributes" } " may be set on individual " { $link node } "s and " { $link edge } "s. Even some DOT niceties are already supported, like being able to have an " { $link edge } " between anonymous " { $link subgraph } "s. For instance, compare"
451 " { 1 2 3 } { 4 5 6 } add-edge"
456 " { 1 2 3 } -> { 4 5 6 }"
460 "However, there are some rough points that this vocabulary addresses:"
462 { "graphviz.notation" "=attrs" }
463 { "graphviz.notation" "synonyms" }
467 ABOUT: "graphviz.notation"