From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: org-babel-execute:dot -- why doesn't this work? Date: Wed, 23 Sep 2015 21:29:31 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b41411eb0014e052074292e Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZevLp-0003zt-H2 for emacs-orgmode@gnu.org; Wed, 23 Sep 2015 21:29:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZevLo-00022T-1C for emacs-orgmode@gnu.org; Wed, 23 Sep 2015 21:29:33 -0400 Received: from mail-ig0-x236.google.com ([2607:f8b0:4001:c05::236]:34936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZevLn-00022K-R4 for emacs-orgmode@gnu.org; Wed, 23 Sep 2015 21:29:31 -0400 Received: by igbkq10 with SMTP id kq10so111568761igb.0 for ; Wed, 23 Sep 2015 18:29:31 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --047d7b41411eb0014e052074292e Content-Type: text/plain; charset=UTF-8 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 --047d7b41411eb0014e052074292e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I'm trying to draw some silly diagrams with dot, based on cod= e stolen from tutorials here:
http://irreal.org/blog/?p=3D2866
and here:
http://orgmode.org/worg/org-tutorial= s/org-dot-diagrams.html

The code won't work, though I can generate the dia= gram using a somewhat clumsier method from here:
http://orgmode.org= /worg/org-contrib/babel/languages/ob-doc-dot.html

<= span style=3D"font-family:monospace,monospace">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*=C2=A0= =C2=A0 | *shape* | *fillcolor* |
|--------+-----------+---------+-------= ------|
| a=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | Omar=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 | ellipse | green=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |
| b=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | Hindia=C2=A0=C2=A0=C2=A0 | ellipse | orange=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 |
| c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | Yuvrai= =C2=A0=C2=A0=C2=A0 | ellipse | purple=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |
#+name: students-graph
| a | b |
| a | c |
| b | c |

I can generate my = table using these two code blocks:

#+name: make-dot
#+BEGIN_SRC e= macs-lisp :var table=3Dstudents-table graph=3Dstudents-graph :results outpu= t :exports none
=C2=A0 (mapcar #'(lambda (x)
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (princ (format= "%s [label=3D\"%s\" shape=3D%s style=3D\"filled\"= fillcolor=3D\"%s\"];\n"
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (car x) (se= cond x) (nth 2 x) (nth 3 x) ))) table)
=C2=A0 (mapcar #'(lambda (x)<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (princ (format "%s -- %s;\n"
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (firs= t x) (second x)))) graph)


#+END_SRC

#+BEGIN_SRC dot :file= Images/test-dot.png :var input=3Dmake-dot :exports results
graph {
r= ankdir=3DTB
$input
}
#+END_SRC



I would, however, like to avoid the clumsy i= ntermediate step and use something like this instead:
#+name: graph-from= -tables
#+HEADER: :var nodes=3Dstudents-table graph=3Dstudents-graph hor= iz=3D't
#+BEGIN_SRC emacs-lisp :file ~/example-diagram.png :colnames= yes :exports results
=C2=A0 (org-babel-execute:dot
=C2=A0=C2=A0 (con= cat
=C2=A0=C2=A0=C2=A0 "graph {\n"
=C2=A0=C2=A0=C2=A0 (when= horiz "rankdir=3DLR;\n")=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;up= -down or left-right
=C2=A0=C2=A0=C2=A0 (mapconcat
=C2=A0=C2=A0=C2=A0= =C2=A0 (lambda (x)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (format "%s= [label=3D\"%s\" shape=3D%s style=3D\"filled\" fillcolo= r=3D\"%s\"]"
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (car x)
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (nth 1 x)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (if (string=3D "" (nth 2 x)) "box" (nth 2 = x))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (if (string=3D "" (nth 3 x)) "none" = (nth 3 x))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 )) nodes "\n")
=C2=A0=C2=A0=C2=A0 &qu= ot;\n"
=C2=A0=C2=A0=C2=A0 (mapconcat
=C2=A0=C2=A0=C2=A0 (lambda = (x)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (format "%s -- %s;"
=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (car x) (nth 1 x) )) graph "\n")
=C2=A0=C2=A0=C2=A0 "}\n= ") params)=C2=A0=C2=A0=C2=A0
#+END_SRC


However, this just create= s a file ~/example-diagram.png whose content is "nil%".=C2=A0 I&#= 39;m not sure how to debug the problem.=C2=A0 Any suggestions? Does this co= de work for you guys? I am using an uptodate arch linux, emacs 25, and a re= cent graphviz.=C2=A0

thanks as always for the help.

Also -- WISHLIST= : instead of a manually-entered list of edges, I'd like to randomly cre= ate a=C2=A0 random set of connections between the nodes. I can easily creat= e a list of nodes:

=C2=A0(let ((names () ))
=C2=A0=C2=A0 (dolist = (x nodes)
=C2=A0=C2=A0=C2=A0=C2=A0 (push (nth 1 x ) names)
=C2=A0=C2= =A0=C2=A0=C2=A0 )
=C2=A0=C2=A0=C2=A0 ... 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
--047d7b41411eb0014e052074292e--