all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* org-babel-execute:dot -- why doesn't this work?
@ 2015-09-24  1:29 Matt Price
  2015-09-24  4:00 ` Nick Dokos
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Price @ 2015-09-24  1:29 UTC (permalink / raw)
  To: Org Mode

[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-23 20:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-24  1:29 org-babel-execute:dot -- why doesn't this work? Matt Price
2015-09-24  4:00 ` 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

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.