chickadee » graphviz

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

graphviz

Some Graphviz abstractions

default-width

default-widthparameter

Default width for graphs

(define default-width (make-parameter 1600))

default-height

default-heightparameter

Default width for graphs

(define default-height (make-parameter 900))

default-font-size

default-font-sizeparameter

Default font-size for graphs

(define default-font-size (make-parameter 48.0))

default-node-attributes

default-node-attributesparameter

Default node attributes

(define default-node-attributes (make-parameter '()))

Examples

Creating default node attributes

(default-node-attributes '((font . monospace)))

default-edge-attributes

default-edge-attributesparameter

Default edge attributes

(define default-edge-attributes (make-parameter '()))

Examples

Creating default edge attributes

(default-edge-attributes '((dir . none)))

default-graph-attributes

default-graph-attributesparameter

Default graph attributes

(define default-graph-attributes (make-parameter '()))

Examples

Creating default graph attributes

(default-graph-attributes '((splines . true)))

write-graph-preamble

write-graph-preambleprocedure
write-graph-preamble graph-attributesprocedure
write-graph-preamble graph-attributes width height font-sizeprocedure

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-postambleprocedure

Write the graph postamble.

(define (write-graph-postamble) (display "}"))

pos

pos x yprocedure

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 labelprocedure
write-node label attributesprocedure

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 whitherprocedure
write-edge whence whither attributesprocedure

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

Peter Danenberg

Repository

https://github.com/klutometis/graphviz

License

BSD

Dependencies

Versions

0.2
Add dependencies.
0.3
Get rid of 0.1.
0.4
Abstract out attributes.
0.5
Add test-exit.
0.6
Add attributes to edge.
0.7
Sparser defaults
0.8
Write-graph-preamble, &c.
0.8.1
Use hahn.
0.8.2
Version should be a string.

Colophon

Documented by hahn.

Contents »