|
From: | Matt Price |
Subject: | Re: [O] org-babel-execute:dot -- why doesn't this work? |
Date: | Thu, 24 Sep 2015 07:10:26 -0400 |
Matt Price <address@hidden> writes:
> I would, however, like to avoid the clumsy intermediate step and use something like this instead:
> #+name: graph-from-tables
> #+HEADER: :var nodes=students-table graph=students-graph horiz='t
> #+BEGIN_SRC emacs-lisp :file ~/example-diagram.png :colnames yes :exports results
> (org-babel-execute:dot
> (concat
> "graph {\n"
> (when horiz "rankdir=LR;\n") ;up-down or left-right
> (mapconcat
> (lambda (x)
> (format "%s [label=\"%s\" shape=%s style=\"filled\" fillcolor=\"%s\"]"
> (car x)
> (nth 1 x)
> (if (string= "" (nth 2 x)) "box" (nth 2 x))
> (if (string= "" (nth 3 x)) "none" (nth 3 x))
> )) nodes "\n")
> "\n"
> (mapconcat
> (lambda (x)
> (format "%s -- %s;"
> (car x) (nth 1 x) )) graph "\n")
> "}\n") params)
> #+END_SRC
>
There are a couple of problems, one minor (the :colnames yes part
truncates the graph so you have only two edges), and one major: the
"params" argument is not defined.
When a dot source block is passed to org-babel-execute:dot, the params
argument I get [fn:1] is:
((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline . #1#)
(:noweb . "no") (:tangle . "no") (:exports . "results")
(:results . "file replace") (:session . "none") (:hlines . "no")
(:file . "Images/foobar.png") (:result-type . value)
(:result-params "file" "replace") (:rowname-names) (:colname-names))
So I tried passing it to org-babel-execute:dot and somewhat
to my surprise it worked [fn:2] - try evaluating the following in your
*scratch* buffer (make sure there is an Images subdir under the
current directory of that buffer):
--8<---------------cut here---------------start------------->8---
(org-babel-execute:dot
"graph {
rankdir=LR;
a [label=\"Omar\" shape=ellipse style=\"filled\" fillcolor=\"green\"]
b [label=\"Hindia\" shape=ellipse style=\"filled\" fillcolor=\"orange\"]
c [label=\"Yuvrai\" shape=ellipse style=\"filled\" fillcolor=\"purple\"]
a -- b;
a -- c;
b -- c;
}
"
'((:comments . #1="") (:shebang . #1#) (:cache . "no") (:padline . #1#)
(:noweb . "no") (:tangle . "no") (:exports . "results")
(:results . "file replace") (:session . "none") (:hlines . "no")
(:file . "Images/foobar.png") (:result-type . value)
(:result-params "file" "replace") (:rowname-names) (:colname-names)))
--8<---------------cut here---------------end--------------->8---
But I would hardly call this method less clumsy than your earlier
attempt.
Footnotes:
[fn:1] I made a simple dot source block with your graph
#+BEGIN_SRC dot :file Images/foobar.png
graph {
rankdir=LR;
a [label="Omar" shape=ellipse style="filled" fillcolor="green"]
b [label="Hindia" shape=ellipse style="filled" fillcolor="orange"]
c [label="Yuvrai" shape=ellipse style="filled" fillcolor="purple"]
a -- b;
a -- c;
b -- c;
}
#+END_SRC
and instrumented org-babel-execute:dot under edebug - when I executed the code
block, the debugger kicked in when the function got called and I could
get the "params" argument.
[fn:2] I thought the #1 and #1# constructs (which I don't understand at
all) would make it blow up.
--
Nick
[Prev in Thread] | Current Thread | [Next in Thread] |