Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for other formats in loom.io/view #94

Merged
merged 1 commit into from
Feb 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/loom/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@
(open tmp)))

(defn render-to-bytes
"Renders the graph g in the PNG format using GraphViz and returns PNG data
"Renders the graph g in the image format using GraphViz and returns data
as a byte array.
Requires GraphViz's 'dot' (or a specified algorithm) to be installed in
the shell's path. Possible algorithms include :dot, :neato, :fdp, :sfdp,
:twopi, and :circo"
[g & {:keys [alg] :or {alg "dot"} :as opts}]
:twopi, and :circo. Possible formats include :png, :ps, :pdf, and :svg."
[g & {:keys [alg fmt] :or {alg "dot" fmt :png} :as opts}]
(let [dot (apply dot-str g (apply concat opts))
{png :out} (sh (name alg) "-Tpng" :in dot :out-enc :bytes)]
png))
{:keys [out]} (sh (name alg) (str "-T" (name fmt)) :in dot :out-enc :bytes)]
out))

(defn view
"Converts graph g to a temporary PNG file using GraphViz and opens it
in the current desktop environment's default viewer for PNG files.
"Converts graph g to a temporary image file using GraphViz and opens it
in the current desktop environment's default viewer for said files.
Requires GraphViz's 'dot' (or a specified algorithm) to be installed in
the shell's path. Possible algorithms include :dot, :neato, :fdp, :sfdp,
:twopi, and :circo"
[g & opts]
(open-data (apply render-to-bytes g opts) :png))
:twopi, and :circo. Possible formats include :png, :ps, :pdf, and :svg."
[g & {:keys [fmt] :or {fmt :png} :as opts}]
(open-data (apply render-to-bytes g opts) fmt))