emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: org-babel-execute:dot -- why doesn't this work?
Date: Thu, 24 Sep 2015 00:00:53 -0400	[thread overview]
Message-ID: <87mvwc1n62.fsf@pierrot.dokosmarshall.org> (raw)
In-Reply-To: CAN_Dec_0vU8W+f59bTLwznE_OPSFe8-i9DY=mMdD2DZ-eAS-ag@mail.gmail.com

Matt Price <moptop99@gmail.com> 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

  reply	other threads:[~2015-09-24  4:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24  1:29 org-babel-execute:dot -- why doesn't this work? Matt Price
2015-09-24  4:00 ` Nick Dokos [this message]
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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvwc1n62.fsf@pierrot.dokosmarshall.org \
    --to=ndokos@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).