chickadee » graphviz » 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)))))))