org-mode/lisp/org-plot.el

349 lines
12 KiB
EmacsLisp
Raw Normal View History

;;; org-plot.el --- Support for Plotting from Org -*- lexical-binding: t; -*-
2008-10-12 13:25:56 +00:00
2020-01-01 18:38:46 +00:00
;; Copyright (C) 2008-2020 Free Software Foundation, Inc.
2008-10-12 13:25:56 +00:00
;;
;; Author: Eric Schulte <schulte dot eric at gmail dot com>
;; Maintainer: TEC <tecosaur@gmail.com>
2008-10-12 13:25:56 +00:00
;; Keywords: tables, plotting
;; Homepage: https://orgmode.org
2008-10-12 13:25:56 +00:00
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2008-10-12 13:25:56 +00:00
;;; Commentary:
;; Borrows ideas and a couple of lines of code from org-exp.el.
;; Thanks to the Org mailing list for testing and implementation and
;; feature suggestions
2008-10-12 13:25:56 +00:00
;;; Code:
(require 'cl-lib)
2008-10-12 13:25:56 +00:00
(require 'org)
(require 'org-table)
(declare-function gnuplot-delchar-or-maybe-eof "ext:gnuplot" (arg))
(declare-function gnuplot-mode "ext:gnuplot" ())
(declare-function gnuplot-send-buffer-to-gnuplot "ext:gnuplot" ())
(defvar org-plot/gnuplot-default-options
'((:plot-type . 2d)
(:with . lines)
(:ind . 0))
"Default options to gnuplot used by `org-plot/gnuplot'.")
2008-10-12 13:25:56 +00:00
(defvar org-plot-timestamp-fmt nil)
2008-10-12 13:25:56 +00:00
(defun org-plot/add-options-to-plist (p options)
"Parse an OPTIONS line and set values in the property list P.
Returns the resulting property list."
(when options
(let ((op '(("type" . :plot-type)
("script" . :script)
("line" . :line)
("set" . :set)
("title" . :title)
("ind" . :ind)
("deps" . :deps)
("with" . :with)
("file" . :file)
("labels" . :labels)
("map" . :map)
("timeind" . :timeind)
("timefmt" . :timefmt)))
(multiples '("set" "line"))
(regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)")
(start 0))
(dolist (o op)
(if (member (car o) multiples) ;; keys with multiple values
(while (string-match
(concat (regexp-quote (car o)) regexp)
options start)
(setq start (match-end 0))
(setq p (plist-put p (cdr o)
(cons (car (read-from-string
(match-string 1 options)))
(plist-get p (cdr o)))))
p)
(if (string-match (concat (regexp-quote (car o)) regexp)
options)
(setq p (plist-put p (cdr o)
(car (read-from-string
(match-string 1 options))))))))))
2008-10-12 13:25:56 +00:00
p)
(defun org-plot/goto-nearest-table ()
"Move the point forward to the beginning of nearest table.
Return value is the point at the beginning of the table."
(interactive) (move-beginning-of-line 1)
(while (not (or (org-at-table-p) (< 0 (forward-line 1)))))
(goto-char (org-table-begin)))
(defun org-plot/collect-options (&optional params)
"Collect options from an org-plot `#+Plot:' line.
2008-10-12 13:25:56 +00:00
Accepts an optional property list PARAMS, to which the options
will be added. Returns the resulting property list."
(interactive)
(let ((line (thing-at-point 'line)))
(if (string-match "#\\+PLOT: +\\(.*\\)$" line)
(org-plot/add-options-to-plist params (match-string 1 line))
params)))
(defun org-plot-quote-timestamp-field (s)
"Convert field S from timestamp to Unix time and export to gnuplot."
(format-time-string org-plot-timestamp-fmt (org-time-string-to-time s)))
2008-10-12 13:25:56 +00:00
(defun org-plot-quote-tsv-field (s)
"Quote field S for export to gnuplot."
(if (string-match org-table-number-regexp s) s
(if (string-match org-ts-regexp3 s)
2008-12-16 16:26:01 +00:00
(org-plot-quote-timestamp-field s)
(concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\""))))
2008-10-12 13:25:56 +00:00
(defun org-plot/gnuplot-to-data (table data-file params)
"Export TABLE to DATA-FILE in a format readable by gnuplot.
Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE."
(with-temp-file
2008-12-04 14:33:43 +00:00
data-file
(setq-local org-plot-timestamp-fmt (or
(plist-get params :timefmt)
"%Y-%m-%d-%H:%M:%S"))
(insert (orgtbl-to-generic
2008-12-16 16:26:01 +00:00
table
(org-combine-plists
'(:sep "\t" :fmt org-plot-quote-tsv-field)
params))))
2008-10-12 13:25:56 +00:00
nil)
(defun org-plot/gnuplot-to-grid-data (table data-file params)
"Export the data in TABLE to DATA-FILE for gnuplot.
This means in a format appropriate for grid plotting by gnuplot.
2008-12-16 16:26:49 +00:00
PARAMS specifies which columns of TABLE should be plotted as independent
2019-11-12 13:44:05 +00:00
and dependent variables."
2008-10-12 13:25:56 +00:00
(interactive)
(let* ((ind (- (plist-get params :ind) 1))
(deps (if (plist-member params :deps)
(mapcar (lambda (val) (- val 1)) (plist-get params :deps))
(let (collector)
Silence byte-compiler * lisp/ob-core.el (org-babel-process-params): Silence byte-compiler. * lisp/ob-groovy.el (org-babel-groovy-evaluate): * lisp/ob-haskell.el (org-babel-execute:haskell): * lisp/ob-io.el (org-babel-io-evaluate): * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): (org-babel-octave-evaluate-session): * lisp/ob-perl.el (org-babel-perl-evaluate): * lisp/ob-python.el (org-babel-python-evaluate-external-process): (org-babel-python-evaluate-session): * lisp/ob-ruby.el (org-babel-ruby-pp-wrapper-method): (org-babel-ruby-evaluate): * lisp/ob-scala.el: * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): * lisp/org-agenda.el (org-agenda-get-category-icon): (org-agenda-todo-yesterday): * lisp/org-bbdb.el (org-bbdb-anniv-extract-date): (org-bbdb-make-anniv-hash): (org-bbdb-anniversaries-future): * lisp/org-bibtex.el (org-bibtex-fleshout): (org-bibtex-read): (org-bibtex-write): * lisp/org-capture.el (org-capture-set-target-location): (org-capture-get-indirect-buffer): (org-mks): * lisp/org-clock.el (org-clock--oldest-date): (org-clock-resolve): (org-clock-sum): (org-clock-special-range): (org-clocktable-steps): * lisp/org-ctags.el (org-ctags-create-tags): * lisp/org-element.el (org-element--interpret-affiliated-keywords): (org-element--cache-shift-positions): (org-element--cache-sync): (org-element--cache-submit-request): * lisp/org-habit.el (org-habit-parse-todo): * lisp/org-inlinetask.el (org-inlinetask-hide-tasks): * lisp/org-lint.el (org-lint--generate-reports): * lisp/org-mouse.el (org-mouse-get-context): * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): (org-plot/gnuplot): * lisp/ox-ascii.el (org-ascii--current-text-width): (org-ascii--current-justification): (org-ascii--build-caption): (org-ascii--checkbox): (org-ascii-item): * lisp/ox-html.el (org-html-footnote-section): * lisp/ox-latex.el (org-latex--make-option-string): * lisp/ox-odt.el (org-odt-toc): (org-odt-add-automatic-style): (org-odt-format-label): (org-odt-link--inline-image): (org-odt--render-image/formula): (org-odt--enumerable-image-p): (org-odt--enumerable-latex-image-p): (org-odt--enumerable-formula-p): (org-odt-do-format-code): (org-odt-table-cell): Silence byte-compiler.
2016-07-25 14:34:48 +00:00
(dotimes (col (length (nth 0 table)))
2008-10-12 13:25:56 +00:00
(setf collector (cons col collector)))
collector)))
(counter 0)
row-vals)
2008-10-12 13:25:56 +00:00
(when (>= ind 0) ;; collect values of ind col
(setf row-vals (mapcar (lambda (row) (setf counter (+ 1 counter))
Tiny formatting fixes * lisp/ox.el (org-export-table-dimensions): * lisp/ox-texinfo.el (org-texinfo-template): * lisp/ox-md.el (org-md-link): * lisp/ox-icalendar.el (org-icalendar-use-UTC-date-time-p): * lisp/ox-ascii.el (org-ascii-fixed-width): * lisp/org.el (org-context): * lisp/org-table.el (org-table-eval-formula) (org-table-export): * lisp/org-refile.el: * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): * lisp/org-num.el (org-num): * lisp/org-mouse.el (org-mouse-popup-global-menu) (org-mouse-context-menu): * lisp/org-macro.el (org-macro): * lisp/org-lint.el (org-lint): * lisp/org-keys.el (org-keys): * lisp/org-duration.el: * lisp/org-clock.el (org-clock-get-last-clock-out-time) (org-clock-update-mode-line, org-find-open-clocks): * lisp/org-agenda.el (org-diary) (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item) (org-agenda-highlight-todo, org-cmp-alpha) (org-agenda-filter-by-category): * lisp/ol.el (org-link-expand-abbrev, ol): * lisp/ol-docview.el (ol-docview): * lisp/ol-bibtex.el (org-execute-file-search-in-bibtex) (org-bibtex, org-bibtex-read): * lisp/ol-bbdb.el (org-bbdb-anniversary-description): * lisp/ob-tangle.el (org-babel-tangle-jump-to-org): * lisp/ob-table.el (org-babel-table-truncate-at-newline): * lisp/ob-stan.el: * lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar): * lisp/ob-sql.el: * lisp/ob-shen.el: * lisp/ob-shell.el (org-babel-prep-session:shell) (org-babel-prep-session:shell): * lisp/ob-sed.el (org-babel-execute:sed) (org-babel-execute:sed): * lisp/ob-screen.el: * lisp/ob-sass.el: * lisp/ob-ruby.el (org-babel-prep-session:ruby) (org-babel-prep-session:ruby): * lisp/ob-ref.el (org-babel-ref-resolve, ob-ref): * lisp/ob-python.el (org-babel-prep-session:python) (org-babel-prep-session:python): * lisp/ob-plantuml.el: * lisp/ob-picolisp.el: * lisp/ob-perl.el: * lisp/ob-org.el: * lisp/ob-octave.el (org-babel-prep-session:octave) (org-babel-prep-session:octave) (org-babel-octave-evaluate-session): * lisp/ob-ocaml.el: * lisp/ob-mscgen.el (org-babel-execute:mscgen) (org-babel-execute:mscgen): * lisp/ob-maxima.el: (ob-maxima): * lisp/ob-matlab.el: * lisp/ob-makefile.el: * lisp/ob-lua.el (org-babel-prep-session:lua) (org-babel-prep-session:lua): * lisp/ob-lisp.el: * lisp/ob-ledger.el: * lisp/ob-latex.el (org-babel-expand-body:latex) (org-babel-expand-body:latex, ob-latex): * lisp/ob-js.el: * lisp/ob-java.el: * lisp/ob-io.el (org-babel-prep-session:io) (org-babel-prep-session:io): * lisp/ob-hledger.el: * lisp/ob-haskell.el: * lisp/ob-groovy.el (org-babel-groovy-wrapper-method) (org-babel-groovy-evaluate): * lisp/ob-gnuplot.el: * lisp/ob-fortran.el (org-babel-expand-body:fortran) (org-babel-expand-body:fortran): * lisp/ob-forth.el (org-babel-forth-session-execute): * lisp/ob-exp.el (ob-exp): * lisp/ob-eval.el: * lisp/ob-emacs-lisp.el: * lisp/ob-ebnf.el: * lisp/ob-dot.el: * lisp/ob-ditaa.el: * lisp/ob-css.el: * lisp/ob-core.el (org-babel-put-rownames): * lisp/ob-coq.el: * lisp/ob-comint.el: * lisp/ob-calc.el: * lisp/ob-awk.el: * lisp/ob-asymptote.el: * lisp/ob-abc.el: * lisp/ob-R.el (org-babel-prep-session:R): Formatting fixes.
2020-02-18 21:57:37 +00:00
(cons counter (nth ind row)))
table)))
2008-10-12 13:25:56 +00:00
(when (or deps (>= ind 0)) ;; remove non-plotting columns
(setf deps (delq ind deps))
(setf table (mapcar (lambda (row)
(dotimes (col (length row))
(unless (memq col deps)
(setf (nth col row) nil)))
(delq nil row))
table)))
;; write table to gnuplot grid datafile format
(with-temp-file data-file
Silence byte-compiler * lisp/ob-core.el (org-babel-process-params): Silence byte-compiler. * lisp/ob-groovy.el (org-babel-groovy-evaluate): * lisp/ob-haskell.el (org-babel-execute:haskell): * lisp/ob-io.el (org-babel-io-evaluate): * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): (org-babel-octave-evaluate-session): * lisp/ob-perl.el (org-babel-perl-evaluate): * lisp/ob-python.el (org-babel-python-evaluate-external-process): (org-babel-python-evaluate-session): * lisp/ob-ruby.el (org-babel-ruby-pp-wrapper-method): (org-babel-ruby-evaluate): * lisp/ob-scala.el: * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): * lisp/org-agenda.el (org-agenda-get-category-icon): (org-agenda-todo-yesterday): * lisp/org-bbdb.el (org-bbdb-anniv-extract-date): (org-bbdb-make-anniv-hash): (org-bbdb-anniversaries-future): * lisp/org-bibtex.el (org-bibtex-fleshout): (org-bibtex-read): (org-bibtex-write): * lisp/org-capture.el (org-capture-set-target-location): (org-capture-get-indirect-buffer): (org-mks): * lisp/org-clock.el (org-clock--oldest-date): (org-clock-resolve): (org-clock-sum): (org-clock-special-range): (org-clocktable-steps): * lisp/org-ctags.el (org-ctags-create-tags): * lisp/org-element.el (org-element--interpret-affiliated-keywords): (org-element--cache-shift-positions): (org-element--cache-sync): (org-element--cache-submit-request): * lisp/org-habit.el (org-habit-parse-todo): * lisp/org-inlinetask.el (org-inlinetask-hide-tasks): * lisp/org-lint.el (org-lint--generate-reports): * lisp/org-mouse.el (org-mouse-get-context): * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): (org-plot/gnuplot): * lisp/ox-ascii.el (org-ascii--current-text-width): (org-ascii--current-justification): (org-ascii--build-caption): (org-ascii--checkbox): (org-ascii-item): * lisp/ox-html.el (org-html-footnote-section): * lisp/ox-latex.el (org-latex--make-option-string): * lisp/ox-odt.el (org-odt-toc): (org-odt-add-automatic-style): (org-odt-format-label): (org-odt-link--inline-image): (org-odt--render-image/formula): (org-odt--enumerable-image-p): (org-odt--enumerable-latex-image-p): (org-odt--enumerable-formula-p): (org-odt-do-format-code): (org-odt-table-cell): Silence byte-compiler.
2016-07-25 14:34:48 +00:00
(let ((num-rows (length table)) (num-cols (length (nth 0 table)))
(gnuplot-row (lambda (col row value)
(setf col (+ 1 col)) (setf row (+ 1 row))
(format "%f %f %f\n%f %f %f\n"
col (- row 0.5) value ;; lower edge
col (+ row 0.5) value))) ;; upper edge
2008-10-12 13:25:56 +00:00
front-edge back-edge)
(dotimes (col num-cols)
(dotimes (row num-rows)
(setf back-edge
(concat back-edge
(funcall gnuplot-row (- col 1) row
(string-to-number (nth col (nth row table))))))
(setf front-edge
(concat front-edge
(funcall gnuplot-row col row
(string-to-number (nth col (nth row table)))))))
;; only insert once per row
(insert back-edge) (insert "\n") ;; back edge
(insert front-edge) (insert "\n") ;; front edge
(setf back-edge "") (setf front-edge ""))))
2008-10-12 13:25:56 +00:00
row-vals))
(defun org-plot/gnuplot-script (data-file num-cols params &optional preface)
2008-10-12 13:25:56 +00:00
"Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
NUM-COLS controls the number of columns plotted in a 2-d plot.
Optional argument PREFACE returns only option parameters in a
manner suitable for prepending to a user-specified script."
2008-10-12 13:25:56 +00:00
(let* ((type (plist-get params :plot-type))
(with (if (eq type 'grid) 'pm3d (plist-get params :with)))
2008-10-12 13:25:56 +00:00
(sets (plist-get params :set))
(lines (plist-get params :line))
(map (plist-get params :map))
(title (plist-get params :title))
(file (plist-get params :file))
(ind (plist-get params :ind))
2008-12-16 16:26:01 +00:00
(time-ind (plist-get params :timeind))
(timefmt (plist-get params :timefmt))
2008-10-12 13:25:56 +00:00
(text-ind (plist-get params :textind))
(deps (if (plist-member params :deps) (plist-get params :deps)))
(col-labels (plist-get params :labels))
(x-labels (plist-get params :xlabels))
(y-labels (plist-get params :ylabels))
(plot-str "'%s' using %s%d%s with %s title '%s'")
(plot-cmd (pcase type
(`2d "plot")
(`3d "splot")
(`grid "splot")))
(script "reset")
;; ats = add-to-script
(ats (lambda (line) (setf script (concat script "\n" line))))
plot-lines)
(when file ; output file
(funcall ats (format "set term %s" (file-name-extension file)))
(funcall ats (format "set output '%s'" file)))
(pcase type ; type
(`2d ())
(`3d (when map (funcall ats "set map")))
(`grid (funcall ats (if map "set pm3d map" "set pm3d"))))
(when title (funcall ats (format "set title '%s'" title))) ; title
(mapc ats lines) ; line
(dolist (el sets) (funcall ats (format "set %s" el))) ; set
;; Unless specified otherwise, values are TAB separated.
Use `string-match-p' instead of `org-string-match-p' * contrib/lisp/org-contacts.el (org-contacts-filter): (org-contacts-complete-group): (org-contacts-complete-tags-props): * contrib/lisp/org-wl.el (org-wl-open): * contrib/lisp/ox-bibtex.el (org-bibtex-merge-contiguous-citations): * lisp/ob-core.el (org-babel-demarcate-block): * lisp/ob-processing.el (org-babel-processing-view-sketch): * lisp/ob-stan.el (org-babel-execute:stan): * lisp/org-agenda.el (org-agenda-get-category-icon): * lisp/org-clock.el (org-clock-into-drawer): * lisp/org-element.el (org-element-link-parser): * lisp/org-lint.el (org-lint-orphaned-affiliated-keywords): (org-lint-invalid-babel-call-block): (org-lint-colon-in-name): * lisp/org-list.el (org-list-item-body-column): * lisp/org-macro.el (org-macro-replace-all): * lisp/org-plot.el (org-plot/gnuplot-script): * lisp/org-table.el (org-table-export): (org-table-align): (org-table-get-range): (org-table-recalculate): (org-table-expand-lhs-ranges): (org-table-formula-substitute-names): (org-table-show-reference): (orgtbl-to-texinfo): (org-table-remote-reference-indirection): * lisp/org.el (org-make-link-string): (org--open-elisp-link): (org-open-at-point): (org-store-log-note): (org-cached-entry-get): (org--valid-property-p): (org-entry-properties): (org-buffer-property-keys): (org-insert-drawer): (org-display-inline-images): (org-in-commented-heading-p): * lisp/ox-ascii.el (org-ascii-keyword): * lisp/ox-beamer.el (org-beamer--format-frame): * lisp/ox-html.el (org-html-keyword): * lisp/ox-latex.el (org-latex--label): (org-latex-headline): (org-latex-item): (org-latex-keyword): (org-latex--inline-image): (org-latex-src-block): * lisp/ox-odt.el (org-odt-styles-dir): (org-odt-keyword): (org-odt--translate-latex-fragments): * lisp/ox-texinfo.el (org-texinfo-template): (org-texinfo-keyword): (org-texinfo-src-block): * lisp/ox.el (org-export-inline-image-p): (org-export-file-uri): * testing/lisp/test-org-table.el (test-org-table/to-generic): (test-org-table/to-latex): (test-org-table/to-html): (test-org-table/named-field): (test-org-table/named-column): (test-org-table/tab-indent): (test-org-table/first-rc): (test-org-table/last-rc): Use `string-match-p' instead of `org-string-match-p'.
2016-07-25 13:21:12 +00:00
(unless (string-match-p "^set datafile separator" script)
(funcall ats "set datafile separator \"\\t\""))
(when x-labels ; x labels (xtics)
(funcall ats
(format "set xtics (%s)"
(mapconcat (lambda (pair)
(format "\"%s\" %d" (cdr pair) (car pair)))
x-labels ", "))))
(when y-labels ; y labels (ytics)
(funcall ats
(format "set ytics (%s)"
(mapconcat (lambda (pair)
(format "\"%s\" %d" (cdr pair) (car pair)))
y-labels ", "))))
(when time-ind ; timestamp index
(funcall ats "set xdata time")
(funcall ats (concat "set timefmt \""
(or timefmt ; timefmt passed to gnuplot
"%Y-%m-%d-%H:%M:%S") "\"")))
(unless preface
(pcase type ; plot command
(`2d (dotimes (col num-cols)
(unless (and (eq type '2d)
(or (and ind (equal (1+ col) ind))
(and deps (not (member (1+ col) deps)))))
(setf plot-lines
(cons
(format plot-str data-file
(or (and ind (> ind 0)
(not text-ind)
(format "%d:" ind)) "")
(1+ col)
(if text-ind (format ":xticlabel(%d)" ind) "")
with
(or (nth col col-labels)
(format "%d" (1+ col))))
plot-lines)))))
(`3d
2008-10-12 13:25:56 +00:00
(setq plot-lines (list (format "'%s' matrix with %s title ''"
data-file with))))
(`grid
2008-10-12 13:25:56 +00:00
(setq plot-lines (list (format "'%s' with %s title ''"
data-file with)))))
(funcall ats
(concat plot-cmd " " (mapconcat #'identity
(reverse plot-lines)
",\\\n "))))
script))
2008-10-12 13:25:56 +00:00
;;-----------------------------------------------------------------------------
;; facade functions
;;;###autoload
(defun org-plot/gnuplot (&optional params)
"Plot table using gnuplot. Gnuplot options can be specified with PARAMS.
2008-10-12 13:25:56 +00:00
If not given options will be taken from the +PLOT
line directly before or after the table."
(interactive)
(require 'gnuplot)
(save-window-excursion
(delete-other-windows)
(when (get-buffer "*gnuplot*") ; reset *gnuplot* if it already running
(with-current-buffer "*gnuplot*"
(goto-char (point-max))))
2008-10-12 13:25:56 +00:00
(org-plot/goto-nearest-table)
;; Set default options.
(dolist (pair org-plot/gnuplot-default-options)
(unless (plist-member params (car pair))
(setf params (plist-put params (car pair) (cdr pair)))))
2008-10-12 13:25:56 +00:00
;; collect table and table information
(let* ((data-file (make-temp-file "org-plot"))
(table (org-table-collapse-header (org-table-to-lisp)))
(num-cols (length (car table))))
(run-with-idle-timer 0.1 nil #'delete-file data-file)
(when (eq (cadr table) 'hline)
Silence byte-compiler * lisp/ob-core.el (org-babel-process-params): Silence byte-compiler. * lisp/ob-groovy.el (org-babel-groovy-evaluate): * lisp/ob-haskell.el (org-babel-execute:haskell): * lisp/ob-io.el (org-babel-io-evaluate): * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): (org-babel-octave-evaluate-session): * lisp/ob-perl.el (org-babel-perl-evaluate): * lisp/ob-python.el (org-babel-python-evaluate-external-process): (org-babel-python-evaluate-session): * lisp/ob-ruby.el (org-babel-ruby-pp-wrapper-method): (org-babel-ruby-evaluate): * lisp/ob-scala.el: * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): * lisp/org-agenda.el (org-agenda-get-category-icon): (org-agenda-todo-yesterday): * lisp/org-bbdb.el (org-bbdb-anniv-extract-date): (org-bbdb-make-anniv-hash): (org-bbdb-anniversaries-future): * lisp/org-bibtex.el (org-bibtex-fleshout): (org-bibtex-read): (org-bibtex-write): * lisp/org-capture.el (org-capture-set-target-location): (org-capture-get-indirect-buffer): (org-mks): * lisp/org-clock.el (org-clock--oldest-date): (org-clock-resolve): (org-clock-sum): (org-clock-special-range): (org-clocktable-steps): * lisp/org-ctags.el (org-ctags-create-tags): * lisp/org-element.el (org-element--interpret-affiliated-keywords): (org-element--cache-shift-positions): (org-element--cache-sync): (org-element--cache-submit-request): * lisp/org-habit.el (org-habit-parse-todo): * lisp/org-inlinetask.el (org-inlinetask-hide-tasks): * lisp/org-lint.el (org-lint--generate-reports): * lisp/org-mouse.el (org-mouse-get-context): * lisp/org-plot.el (org-plot/gnuplot-to-grid-data): (org-plot/gnuplot): * lisp/ox-ascii.el (org-ascii--current-text-width): (org-ascii--current-justification): (org-ascii--build-caption): (org-ascii--checkbox): (org-ascii-item): * lisp/ox-html.el (org-html-footnote-section): * lisp/ox-latex.el (org-latex--make-option-string): * lisp/ox-odt.el (org-odt-toc): (org-odt-add-automatic-style): (org-odt-format-label): (org-odt-link--inline-image): (org-odt--render-image/formula): (org-odt--enumerable-image-p): (org-odt--enumerable-latex-image-p): (org-odt--enumerable-formula-p): (org-odt-do-format-code): (org-odt-table-cell): Silence byte-compiler.
2016-07-25 14:34:48 +00:00
(setf params
(plist-put params :labels (car table))) ; headers to labels
(setf table (delq 'hline (cdr table)))) ; clean non-data from table
;; Collect options.
2008-10-12 13:25:56 +00:00
(save-excursion (while (and (equal 0 (forward-line -1))
(looking-at "[[:space:]]*#\\+"))
2008-10-12 13:25:56 +00:00
(setf params (org-plot/collect-options params))))
;; Dump table to datafile (very different for grid).
(pcase (plist-get params :plot-type)
(`2d (org-plot/gnuplot-to-data table data-file params))
(`3d (org-plot/gnuplot-to-data table data-file params))
(`grid (let ((y-labels (org-plot/gnuplot-to-grid-data
table data-file params)))
(when y-labels (plist-put params :ylabels y-labels)))))
;; Check type of ind column (timestamp? text?)
(when (eq `2d (plist-get params :plot-type))
(let* ((ind (1- (plist-get params :ind)))
(ind-column (mapcar (lambda (row) (nth ind row)) table)))
(cond ((< ind 0) nil) ; ind is implicit
((cl-every (lambda (el)
(string-match org-ts-regexp3 el))
ind-column)
(plist-put params :timeind t)) ; ind holds timestamps
((or (string= (plist-get params :with) "hist")
(cl-notevery (lambda (el)
(string-match org-table-number-regexp el))
ind-column))
(plist-put params :textind t))))) ; ind holds text
;; Write script.
2008-10-12 13:25:56 +00:00
(with-temp-buffer
(if (plist-get params :script) ; user script
(progn (insert
(org-plot/gnuplot-script data-file num-cols params t))
(insert "\n")
(insert-file-contents (plist-get params :script))
(goto-char (point-min))
(while (re-search-forward "\\$datafile" nil t)
(replace-match data-file nil nil)))
(insert (org-plot/gnuplot-script data-file num-cols params)))
;; Graph table.
2008-10-12 13:25:56 +00:00
(gnuplot-mode)
(gnuplot-send-buffer-to-gnuplot))
;; Cleanup.
(bury-buffer (get-buffer "*gnuplot*")))))
2008-10-12 13:25:56 +00:00
(provide 'org-plot)
;; Local variables:
;; generated-autoload-file: "org-loaddefs.el"
;; End:
2008-10-12 13:25:56 +00:00
;;; org-plot.el ends here