From: Matt Price <moptop99@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: org-babel-execute:dot -- why doesn't this work?
Date: Wed, 23 Sep 2015 21:29:31 -0400 [thread overview]
Message-ID: <CAN_Dec_0vU8W+f59bTLwznE_OPSFe8-i9DY=mMdD2DZ-eAS-ag@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]
I'm trying to draw some silly diagrams with dot, based on code stolen from
tutorials here:
http://irreal.org/blog/?p=2866
and here:
http://orgmode.org/worg/org-tutorials/org-dot-diagrams.html
The code won't work, though I can generate the diagram using a somewhat
clumsier method from here:
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-dot.html
Here are my two tables, one for nodes and one for edges (the real ones are
longer, with something like 30 or 40 nodes):
#+name: students-table
| *node* | *label* | *shape* | *fillcolor* |
|--------+-----------+---------+-------------|
| a | Omar | ellipse | green |
| b | Hindia | ellipse | orange |
| c | Yuvrai | ellipse | purple |
#+name: students-graph
| a | b |
| a | c |
| b | c |
I can generate my table using these two code blocks:
#+name: make-dot
#+BEGIN_SRC emacs-lisp :var table=students-table graph=students-graph
:results output :exports none
(mapcar #'(lambda (x)
(princ (format "%s [label=\"%s\" shape=%s style=\"filled\"
fillcolor=\"%s\"];\n"
(car x) (second x) (nth 2 x) (nth 3 x) )))
table)
(mapcar #'(lambda (x)
(princ (format "%s -- %s;\n"
(first x) (second x)))) graph)
#+END_SRC
#+BEGIN_SRC dot :file Images/test-dot.png :var input=make-dot :exports
results
graph {
rankdir=TB
$input
}
#+END_SRC
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
However, this just creates a file ~/example-diagram.png whose content is
"nil%". I'm not sure how to debug the problem. Any suggestions? Does this
code work for you guys? I am using an uptodate arch linux, emacs 25, and a
recent graphviz.
thanks as always for the help.
Also -- WISHLIST: instead of a manually-entered list of edges, I'd like to
randomly create a random set of connections between the nodes. I can
easily create a list of nodes:
(let ((names () ))
(dolist (x nodes)
(push (nth 1 x ) names)
)
... do some stuff here)
but generating a list of unique edges -- that is, node pairs where
(a . b) and (b . a) are considered equivalent -- is somewhat beyond me.
Again, many thanks,
Matt
[-- Attachment #2: Type: text/html, Size: 4877 bytes --]
next reply other threads:[~2015-09-24 1:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-24 1:29 Matt Price [this message]
2015-09-24 4:00 ` org-babel-execute:dot -- why doesn't this work? Nick Dokos
2015-09-24 11:10 ` Matt Price
2015-09-24 12:46 ` Matt Price
2015-10-23 12:27 ` Éibhear
2015-10-23 17:43 ` Matt Price
2015-10-23 20:48 ` Éibhear
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAN_Dec_0vU8W+f59bTLwznE_OPSFe8-i9DY=mMdD2DZ-eAS-ag@mail.gmail.com' \
--to=moptop99@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.