Using GraphViz inside of Scribble?

48 views
Skip to first unread message

Tim Meehan

unread,
Jan 28, 2021, 12:23:12 AM1/28/21
to Racket Users
IMHO, Racket's documentation is the gold standard. I tell everyone I work with that we should document things this well.
Until now, I haven't seen any room for potential improvements.

Now, I like ASCII art as much as the next person, but when I was reading the documentation for the GUI class hierarchy, I remembered that there was a graphviz package for Racket now.
I'm no good with Scribble, but I bet that someone clever could add some automatic graphs to it without much trouble.

I'm not much good at GraphViz either, but here is my take on the first two ASCII art diagrams. I just used "dot -Tpdf" to make the tests.
hierarchy_2.dot
hierarchy_1.dot

Sorawee Porncharoenwase

unread,
Jan 28, 2021, 12:38:06 AM1/28/21
to Tim Meehan, Racket Users

Here’s how to add graphviz to Pollen. The same technique can be used for Scribble, but you would want to use image as the tag function. You might also need to use define-runtime-path.


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CACgrOxKkeVxdMq9-94%2BX87oCmBKaY0XHg-Sq4yj-fPLy%2B6MYyg%40mail.gmail.com.

William J. Bowman

unread,
Jan 28, 2021, 12:42:21 AM1/28/21
to Sorawee Porncharoenwase, Tim Meehan, Racket Users
I've been using graphviz inside Scribble for a bit.
I found the package a bit inflexible and didn't produce output to my liking, so
I just rolled my own 'dot->svg' for HTML output:

> (require (only-in xml cdata)
> scribble/html-properties)
> (define (dot->svg . rest)
> (elem #:style
> (style #f
> (list
> (xexpr-property
> (cdata #f #f (apply string-append (drop (port->lines (run-dot (apply string-append rest) "svg")) 3)))
> (cdata #f #f ""))))))

Example:
> @dot->svg{
> digraph {
>
> node [ shape="box" ]
>
> /* The Languages */
>
> L0 [label="x64"];
> L1 [label="elf64"];
>
> /* The Passes */
>
> edge [fontname="Courier"]
>
> L0 -> L1 [label="nasm"];
> }
> }

--
William J. Bowman

On Wed, Jan 27, 2021 at 09:37:51PM -0800, Sorawee Porncharoenwase wrote:
> Here’s how to add graphviz to Pollen
> <https://github.com/mbutterick/pollen-users/issues/46>. The same technique
> can be used for Scribble, but you would want to use image
> <https://docs.racket-lang.org/scribble/base.html?q=image#%28def._%28%28lib._scribble%2Fbase..rkt%29._image%29%29>
> as the tag function. You might also need to use define-runtime-path
> <https://docs.racket-lang.org/reference/Filesystem.html?q=define-runtime-path#%28form._%28%28lib._racket%2Fruntime-path..rkt%29._define-runtime-path%29%29>
> .
>
> On Wed, Jan 27, 2021 at 9:23 PM Tim Meehan <btme...@gmail.com> wrote:
>
> > IMHO, Racket's documentation is the gold standard. I tell everyone I work
> > with that we should document things this well.
> > Until now, I haven't seen any room for potential improvements.
> >
> > Now, I like ASCII art as much as the next person, but when I was reading
> > the documentation for the GUI class hierarchy, I remembered that there was
> > a graphviz <https://github.com/pykello/racket-graphviz> package for
> > Racket now.
> > I'm no good with Scribble, but I bet that someone clever could add some
> > automatic graphs to it without much trouble.
> >
> > I'm not much good at GraphViz either, but here is my take on the first two
> > ASCII art diagrams. I just used "dot -Tpdf" to make the tests.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/racket-users/CACgrOxKkeVxdMq9-94%2BX87oCmBKaY0XHg-Sq4yj-fPLy%2B6MYyg%40mail.gmail.com
> > <https://groups.google.com/d/msgid/racket-users/CACgrOxKkeVxdMq9-94%2BX87oCmBKaY0XHg-Sq4yj-fPLy%2B6MYyg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> > .
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CADcuegstUJsYGjcm5C7_Hniw_%3DTvb69FyQa820JN4vP0kChD%2BA%40mail.gmail.com.

Tim Meehan

unread,
Jan 28, 2021, 7:28:22 PM1/28/21
to Racket Users
Thanks for the ideas 😳

William J. Bowman

unread,
Jan 28, 2021, 7:29:59 PM1/28/21
to Sorawee Porncharoenwase, Tim Meehan, Racket Users
I realized I forgot to include this stub:

> (define (run-dot str format)
> (define cmd (string-append "dot -y -T" format))
> (match (process cmd)
> [(list stdout stdin pid stderr ctl)
> (write-string str stdin)
> (newline stdin)
> (close-output-port stdin)
> (cond [(eq? (ctl 'status) 'done-error) (error (port->string stderr))]
> [else stdout])]))
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/YBJOuMD2v2n29%2BpY%40williamjbowman.com.
Reply all
Reply to author
Forward
0 new messages