Skip to content

Instantly share code, notes, and snippets.



Last active Nov 16, 2017
What would you like to do?
Using the functions in graphviz.rkt, we now can do the things in enables.scrbl
@(require "graphviz.rkt")
@(require scriblib/figure)
@graphviz-figure["foo-bar" "Overview of Foo Bar"]{
digraph G {
foo -> bar
bar -> baz
baz -> quux
quux -> foo
As @figure-ref["foo-bar"] clearly shows, the cycle of foo bar is complete.
#lang racket/base
(require racket/file
(require scriblib/figure)
(provide graphviz-figure
;; @graphviz-dot["output"]{ ... }
(define (graphviz-dot #:dir [dir "."] name . lines)
(define tmpfile (make-temporary-file ""))
(with-output-to-file tmpfile
(lambda () (for-each displayln lines))
#:exists 'append)
(define type (if (path-get-extension name)
(subbytes (path-get-extension name) 1)
(system (format "dot -T~a -o ~a ~a"
type (build-path dir name) tmpfile))
(build-path dir name))
(define (graphviz-figure tag caption
#:type [type "svg"] #:dir [dir "."]
. src)
(define filename (string-append tag "." type))
(figure tag
(elem caption)
(image (keyword-apply graphviz-dot
'(#:dir) (list dir)
(cons filename src)))))
@figure["foo-bar" @elem{Overview of the Foo Bar}]{@image[@graphviz-dot["./build/foo-bar.svg"]{
digraph G {
graph [fontsize=10]
center = true
packMode = "graph"
machine -> kafka
kafka -> splunk
kafka -> user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment