Skip to content

Instantly share code, notes, and snippets.

@apg
Last active November 16, 2017 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apg/7d3eda32a2925d8270f2dabef2b968fd to your computer and use it in GitHub Desktop.
Save apg/7d3eda32a2925d8270f2dabef2b968fd to your computer and use it in GitHub Desktop.
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
racket/path
racket/system
scribble/base)
(require scriblib/figure)
(provide graphviz-figure
graphviz-dot)
;; @graphviz-dot["output"]{ ... }
(define (graphviz-dot #:dir [dir "."] name . lines)
(define tmpfile (make-temporary-file "dot~a.dot"))
(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)
#"png"))
(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