是否可以使用graphviz模块在racket框架(GUI)中绘制图形? 如果可以,是否有教程展示如何使用? 谢谢。
system
运行grapviz文件,生成png文件这里有一个例子。您必须安装点程序。
#lang racket
(require graph)
(require racket/gui/base)
(define dot-command "/usr/local/bin/dot -Tpng ~a >~a")
;; Given a graph, use dot to create a png and return the path to the png
(define (make-graphviz-png g)
(let ([dot-string (graphviz g #:colors (coloring/brelaz g))]
[dot-file (make-temporary-file "example~a.dot")]
[png-file (make-temporary-file "example~a.png")])
(display-to-file dot-string dot-file #:exists 'replace)
(system (format dot-command dot-file png-file))
png-file))
;; The graph
(define test-graph (unweighted-graph/directed '((hello world))))
;; Generate the png from the graph
(define bitmap (read-bitmap (make-graphviz-png test-graph)))
;; Display in a frame -- see https://stackoverflow.com/questions/5355251/bitmap-in-dr-racket
(define f (new frame% [label "Your Graph"]))
(new message% [parent f] [label bitmap])
(send f show #t)
(with-output-to-string (lambda () (with-input-from-string dot-string (lambda () ... ))))
中来避免处理临时文件。我们在 https://github.com/fractalide/fractalide/blob/fe5c9d03443e8291b90ccbf1cdf8bf20ced9d233/modules/rkt/rkt-fbp/agents/hyperflow/graph/loader.rkt#L47 中这样做,当我们要求 dot
为我们的图形编辑器布局节点时。 - clacke你可以使用graphviz包。如果你想直接使用dot语言,你可以使用dot->pict函数。另外,你也可以使用digraph->pict函数,它使得dot更加强大,允许使用Racket picts作为节点形状。