== graphviz
Some Graphviz abstractions
[[toc:]]
=== {{default-width}}
default-width → 1600
Default width for graphs
(define default-width (make-parameter 1600))
=== {{default-height}}
default-height → 900
Default width for graphs
(define default-height (make-parameter 900))
=== {{default-font-size}}
default-font-size → 48.0
Default font-size for graphs
(define default-font-size (make-parameter 48.0))
=== {{default-node-attributes}}
default-node-attributes → (quote ())
Default node attributes
(define default-node-attributes (make-parameter '()))
==== Examples
Creating default node attributes
(default-node-attributes '((font . monospace)))
=== {{default-edge-attributes}}
default-edge-attributes → (quote ())
Default edge attributes
(define default-edge-attributes (make-parameter '()))
==== Examples
Creating default edge attributes
(default-edge-attributes '((dir . none)))
=== {{default-graph-attributes}}
default-graph-attributes → (quote ())
Default graph attributes
(define default-graph-attributes (make-parameter '()))
==== Examples
Creating default graph attributes
(default-graph-attributes '((splines . true)))
=== {{write-graph-preamble}}
(write-graph-preamble) → unspecified
(write-graph-preamble graph-attributes) → unspecified
(write-graph-preamble graph-attributes width height font-size) → unspecified
Write a graph preamble.
; {{graph-attributes}} : Attributes of the graph
; {{width}} : Width in pixels
; {{height}} : Height in pixels
; {{font-size}} : Font-size in pt
(define write-graph-preamble
(case-lambda
(() (write-graph-preamble '()))
((graph-attributes)
(write-graph-preamble
graph-attributes
(default-width)
(default-height)
(default-font-size)))
((graph-attributes width height font-size)
(display "digraph G {")
(unless
(null? graph-attributes)
(format #t "graph [~a];" (attributes->string graph-attributes)))
(unless
(null? (default-graph-attributes))
(format
#t
"graph [~a];"
(attributes->string (default-graph-attributes))))
(unless
(null? (default-node-attributes))
(format #t "node [~a];" (attributes->string (default-node-attributes))))
(unless
(null? (default-edge-attributes))
(format #t "edge [~a];" (attributes->string (default-edge-attributes))))
(if (and width height)
(begin
(format #t "graph [fontsize=~a, ratio=fill];" font-size)
(let ((width-in-inches (px->in width))
(height-in-inches (px->in height)))
(format
#t
"graph [viewport=\"~a,~a\", size=\"~a,~a!\"];"
(in->dot width-in-inches)
(in->dot height-in-inches)
width-in-inches
height-in-inches)))))))
==== Examples
A trivial graph
(write-graph-preamble '((splines . true)))
(write-node a '((label . "Big bang")))
(write-node b '((label . "Today")))
(write-edge a b '((label . "Entropy gradient")))
(write-graph-postamble)
=== {{write-graph-postamble}}
(write-graph-postamble) → unspecified
Write the graph postamble.
(define (write-graph-postamble) (display "}"))
=== {{pos}}
(pos x y) → unspecified
For placing nodes at specific positions in a unit graph using the {{pos}}
attribute, apply a linear scaling.
; {{x}} : The x position
; {{y}} : The y position
(define (pos x y) (format "~a,~a" (* x (linear-scale)) (* y (linear-scale))))
=== {{write-node}}
(write-node label) → unspecified
(write-node label attributes) → unspecified
Write a node
; {{label}} : The node's label
; {{attributes}} : Attributes of the node
(define write-node
(case-lambda
((label) (write-node label '()))
((label attributes)
(format #t "~a [~a];" label (attributes->string attributes)))))
=== {{write-edge}}
(write-edge whence whither) → unspecified
(write-edge whence whither attributes) → unspecified
Write an edge
; {{whence}} : The label whence
; {{whither}} : The lable whither
; {{attributes}} : Attributes of the edge
(define write-edge
(case-lambda
((whence whither) (write-edge whence whither '()))
((whence whither attributes)
(format
#t
"~a -> ~a [~a];"
whence
whither
(attributes->string attributes)))))
=== About this egg
==== Author
[[/users/klutometis|Peter Danenberg]]
==== Repository
[[https://github.com/klutometis/graphviz]]
==== License
BSD
==== Dependencies
* [[(hahn 0.9.3)]]
* [[matchable]]
* [[setup-helper]]
==== Colophon
Documented by [[/egg/hahn|hahn]].