0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-12 08:10:07 +00:00

added a :file header argument to gnuplot

This commit is contained in:
Eric Schulte 2009-07-20 13:04:40 -06:00
parent 307c7667db
commit c81479b161
2 changed files with 53 additions and 39 deletions

View file

@ -68,6 +68,8 @@ called by `org-babel-execute-src-block'."
(let* ((vars (org-babel-gnuplot-process-vars params)) (let* ((vars (org-babel-gnuplot-process-vars params))
(result-params (split-string (or (cdr (assoc :results params)) ""))) (result-params (split-string (or (cdr (assoc :results params)) "")))
(out-file (cdr (assoc :file params))) (out-file (cdr (assoc :file params)))
(term (or (cdr (assoc :term params))
(when out-file (file-name-extension out-file))))
(cmdline (cdr (assoc :cmdline params))) (cmdline (cdr (assoc :cmdline params)))
(in-file (make-temp-file "org-babel-ditaa")) (in-file (make-temp-file "org-babel-ditaa"))
(title (plist-get params :title)) (title (plist-get params :title))
@ -75,43 +77,47 @@ called by `org-babel-execute-src-block'."
(sets (plist-get params :set)) (sets (plist-get params :set))
(x-labels (plist-get params :xlabels)) (x-labels (plist-get params :xlabels))
(y-labels (plist-get params :ylabels)) (y-labels (plist-get params :ylabels))
(time-ind (plist-get params :timeind))) (timefmt (plist-get params :timefmt))
;; insert variables into code body (time-ind (or (plist-get params :timeind)
(setq body (when timefmt 1))))
(concat (flet ((add-to-body (text)
(mapconcat (setq body (concat text "\n" body))))
(lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) ;; append header argument settings to body
vars "\n") (when title (add-to-body (format "set title '%s'" title))) ;; title
"\n" (when lines (mapc (lambda (el) (add-to-body el)) lines)) ;; line
body)) (when sets
;; append header argument settings to body (mapc (lambda (el) (add-to-body (format "set %s" el))) sets))
(when title (add-to-script (format "set title '%s'" title))) ;; title (when x-labels
(when lines (mapc (lambda (el) (add-to-script el)) lines)) ;; line (add-to-body
(when sets ;; set (format "set xtics (%s)"
(mapc (lambda (el) (add-to-script (format "set %s" el))) sets)) (mapconcat (lambda (pair)
(when x-labels ;; x labels (xtics) (format "\"%s\" %d" (cdr pair) (car pair)))
(add-to-script x-labels ", "))))
(format "set xtics (%s)" (when y-labels
(mapconcat (lambda (pair) (add-to-body
(format "\"%s\" %d" (cdr pair) (car pair))) (format "set ytics (%s)"
x-labels ", ")))) (mapconcat (lambda (pair)
(when y-labels ;; y labels (ytics) (format "\"%s\" %d" (cdr pair) (car pair)))
(add-to-script y-labels ", "))))
(format "set ytics (%s)" (when time-ind
(mapconcat (lambda (pair) (add-to-body "set xdata time")
(format "\"%s\" %d" (cdr pair) (car pair))) (add-to-body (concat "set timefmt \""
y-labels ", ")))) (or timefmt
(when time-ind ;; timestamp index
(add-to-script "set xdata time")
(add-to-script (concat "set timefmt \""
(or timefmt ;; timefmt passed to gnuplot
"%Y-%m-%d-%H:%M:%S") "\""))) "%Y-%m-%d-%H:%M:%S") "\"")))
;; evaluate the code body with gnuplot (when out-file (add-to-body (format "set output \"%s\"" out-file)))
(with-temp-buffer (when term (add-to-body (format "set term %s" term)))
(insert (concat body "\n")) ;; insert variables into code body: this should happen last
(gnuplot-mode) ;; placing the variables at the *top* of the code in case their
(gnuplot-send-buffer-to-gnuplot)) ;; values are used later
out-file)) (add-to-body (mapconcat
(lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
vars "\n"))
;; evaluate the code body with gnuplot
(with-temp-buffer
(insert (concat body "\n"))
(gnuplot-mode)
(gnuplot-send-buffer-to-gnuplot))
out-file)))
(defun org-babel-prep-session:gnuplot (session params) (defun org-babel-prep-session:gnuplot (session params)
"Prepare SESSION according to the header arguments specified in PARAMS." "Prepare SESSION according to the header arguments specified in PARAMS."

View file

@ -2095,7 +2095,7 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
#+resname: implementing-ditaa #+resname: implementing-ditaa
[[file:blue.png][blue.png]] [[file:blue.png][blue.png]]
*** STARTED gnuplot [3/8] *** STARTED gnuplot [4/8]
(see [[* file result types][file result types]]) (see [[* file result types][file result types]])
#+PLOT: title:"Citas" ind:1 deps:(3) type:2d with:histograms set:"yrange [0:]" #+PLOT: title:"Citas" ind:1 deps:(3) type:2d with:histograms set:"yrange [0:]"
@ -2117,7 +2117,7 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
| 1.3 | 0.19615368 | 0.21730748 | | 1.3 | 0.19615368 | 0.21730748 |
#+srcname: implementing-gnuplot #+srcname: implementing-gnuplot
#+begin_src gnuplot :var data=gnuplot-data #+begin_src gnuplot :var data=gnuplot-data :results silent
set title "Implementing Gnuplot" set title "Implementing Gnuplot"
plot data using 1:2 with lines plot data using 1:2 with lines
#+end_src #+end_src
@ -2144,9 +2144,17 @@ This may be walking too close to an entirely prebuilt plotting tool
rather than straight gnuplot code evaluation. For now I think this rather than straight gnuplot code evaluation. For now I think this
can wait. can wait.
**** TODO a =file= header argument **** DONE a =file= header argument
to specify a file holding the results to specify a file holding the results
#+srcname: gnuplot-to-file-implementation
#+begin_src gnuplot :file plot.png :var data=gnuplot-data
plot data using 1:2, data using 1:3 with lines
#+end_src
#+resname:
[[file:plot.png][plot.png]]
**** STARTED helpers from org-plot.el **** STARTED helpers from org-plot.el
there are a variety of helpers in org-plot which can be fit nicely there are a variety of helpers in org-plot which can be fit nicely
into custom gnuplot header arguments into custom gnuplot header arguments