Mercurial > emacs
comparison lisp/org/org-plot.el @ 100458:ba23e35d3eaf
2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
* Fix typos in comments and docstrings throughout Org-mode.
* org.el (org-get-outline-path): Fix bug if level is not given.
* org-agenda.el (org-finalize-agenda): Fix typo with variable
name.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Wed, 17 Dec 2008 12:34:50 +0000 |
parents | cea079b68b76 |
children | 0d3c634e0bd9 |
comparison
equal
deleted
inserted
replaced
100457:022a6a6d35ab | 100458:ba23e35d3eaf |
---|---|
3 ;; Copyright (C) 2008 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2008 Free Software Foundation, Inc. |
4 ;; | 4 ;; |
5 ;; Author: Eric Schulte <schulte dot eric at gmail dot com> | 5 ;; Author: Eric Schulte <schulte dot eric at gmail dot com> |
6 ;; Keywords: tables, plotting | 6 ;; Keywords: tables, plotting |
7 ;; Homepage: http://orgmode.org | 7 ;; Homepage: http://orgmode.org |
8 ;; Version: 6.15a | 8 ;; Version: 6.15d |
9 ;; | 9 ;; |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 ;; | 11 ;; |
12 ;; GNU Emacs is free software: you can redistribute it and/or modify | 12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
13 ;; it under the terms of the GNU General Public License as published by | 13 ;; it under the terms of the GNU General Public License as published by |
62 ("deps" . :deps) | 62 ("deps" . :deps) |
63 ("with" . :with) | 63 ("with" . :with) |
64 ("file" . :file) | 64 ("file" . :file) |
65 ("labels" . :labels) | 65 ("labels" . :labels) |
66 ("map" . :map) | 66 ("map" . :map) |
67 ("timefmt" . :timefmt))) | 67 ("timefmt" . :timefmt))) |
68 (multiples '("set" "line")) | 68 (multiples '("set" "line")) |
69 (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)") | 69 (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)") |
70 (start 0) | 70 (start 0) |
71 o) | 71 o) |
72 (while (setq o (pop op)) | 72 (while (setq o (pop op)) |
110 | 110 |
111 (defun org-plot-quote-tsv-field (s) | 111 (defun org-plot-quote-tsv-field (s) |
112 "Quote field S for export to gnuplot." | 112 "Quote field S for export to gnuplot." |
113 (if (string-match org-table-number-regexp s) s | 113 (if (string-match org-table-number-regexp s) s |
114 (if (string-match org-ts-regexp3 s) | 114 (if (string-match org-ts-regexp3 s) |
115 (org-plot-quote-timestamp-field s) | 115 (org-plot-quote-timestamp-field s) |
116 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")))) | 116 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")))) |
117 | 117 |
118 (defun org-plot/gnuplot-to-data (table data-file params) | 118 (defun org-plot/gnuplot-to-data (table data-file params) |
119 "Export TABLE to DATA-FILE in a format readable by gnuplot. | 119 "Export TABLE to DATA-FILE in a format readable by gnuplot. |
120 Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE." | 120 Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE." |
121 (with-temp-file | 121 (with-temp-file |
122 data-file | 122 data-file |
123 (make-local-variable 'org-plot-timestamp-fmt) | 123 (make-local-variable 'org-plot-timestamp-fmt) |
124 (setq org-plot-timestamp-fmt (or | 124 (setq org-plot-timestamp-fmt (or |
125 (plist-get params :timefmt) | 125 (plist-get params :timefmt) |
126 "%Y-%m-%d-%H:%M:%S")) | 126 "%Y-%m-%d-%H:%M:%S")) |
127 (insert (orgtbl-to-generic | 127 (insert (orgtbl-to-generic |
128 table | 128 table |
129 (org-combine-plists | 129 (org-combine-plists |
130 '(:sep "\t" :fmt org-plot-quote-tsv-field) | 130 '(:sep "\t" :fmt org-plot-quote-tsv-field) |
131 params)))) | 131 params)))) |
132 nil) | 132 nil) |
133 | 133 |
134 (defun org-plot/gnuplot-to-grid-data (table data-file params) | 134 (defun org-plot/gnuplot-to-grid-data (table data-file params) |
135 "Export the data in TABLE to DATA-FILE for gnuplot. | 135 "Export the data in TABLE to DATA-FILE for gnuplot. |
136 This means, in a format appropriate for grid plotting by gnuplot. | 136 This means, in a format appropriate for grid plotting by gnuplot. |
137 PARAMS specifies which columns of TABLE should be plotted as independant | 137 PARAMS specifies which columns of TABLE should be plotted as independent |
138 and dependant variables." | 138 and dependant variables." |
139 (interactive) | 139 (interactive) |
140 (let* ((ind (- (plist-get params :ind) 1)) | 140 (let* ((ind (- (plist-get params :ind) 1)) |
141 (deps (if (plist-member params :deps) | 141 (deps (if (plist-member params :deps) |
142 (mapcar (lambda (val) (- val 1)) (plist-get params :deps)) | 142 (mapcar (lambda (val) (- val 1)) (plist-get params :deps)) |
192 (lines (plist-get params :line)) | 192 (lines (plist-get params :line)) |
193 (map (plist-get params :map)) | 193 (map (plist-get params :map)) |
194 (title (plist-get params :title)) | 194 (title (plist-get params :title)) |
195 (file (plist-get params :file)) | 195 (file (plist-get params :file)) |
196 (ind (plist-get params :ind)) | 196 (ind (plist-get params :ind)) |
197 (time-ind (plist-get params :timeind)) | 197 (time-ind (plist-get params :timeind)) |
198 (timefmt (plist-get params :timefmt)) | 198 (timefmt (plist-get params :timefmt)) |
199 (text-ind (plist-get params :textind)) | 199 (text-ind (plist-get params :textind)) |
200 (deps (if (plist-member params :deps) (plist-get params :deps))) | 200 (deps (if (plist-member params :deps) (plist-get params :deps))) |
201 (col-labels (plist-get params :labels)) | 201 (col-labels (plist-get params :labels)) |
202 (x-labels (plist-get params :xlabels)) | 202 (x-labels (plist-get params :xlabels)) |
203 (y-labels (plist-get params :ylabels)) | 203 (y-labels (plist-get params :ylabels)) |
232 (format "set ytics (%s)" | 232 (format "set ytics (%s)" |
233 (mapconcat (lambda (pair) | 233 (mapconcat (lambda (pair) |
234 (format "\"%s\" %d" (cdr pair) (car pair))) | 234 (format "\"%s\" %d" (cdr pair) (car pair))) |
235 y-labels ", ")))) | 235 y-labels ", ")))) |
236 (when time-ind ;; timestamp index | 236 (when time-ind ;; timestamp index |
237 (add-to-script "set xdata time") | 237 (add-to-script "set xdata time") |
238 (add-to-script (concat "set timefmt \"" | 238 (add-to-script (concat "set timefmt \"" |
239 (or timefmt ;; timefmt passed to gnuplot | 239 (or timefmt ;; timefmt passed to gnuplot |
240 "%Y-%m-%d-%H:%M:%S") "\""))) | 240 "%Y-%m-%d-%H:%M:%S") "\""))) |
241 (case type ;; plot command | 241 (case type ;; plot command |
242 ('2d (dotimes (col num-cols) | 242 ('2d (dotimes (col num-cols) |
243 (unless (and (equal type '2d) | 243 (unless (and (equal type '2d) |
244 (or (and ind (equal (+ 1 col) ind)) | 244 (or (and ind (equal (+ 1 col) ind)) |
245 (and deps (not (member (+ 1 col) deps))))) | 245 (and deps (not (member (+ 1 col) deps))))) |
305 ('grid (let ((y-labels (org-plot/gnuplot-to-grid-data | 305 ('grid (let ((y-labels (org-plot/gnuplot-to-grid-data |
306 table data-file params))) | 306 table data-file params))) |
307 (when y-labels (plist-put params :ylabels y-labels))))) | 307 (when y-labels (plist-put params :ylabels y-labels))))) |
308 ;; check for timestamp ind column | 308 ;; check for timestamp ind column |
309 (let ((ind (- (plist-get params :ind) 1))) | 309 (let ((ind (- (plist-get params :ind) 1))) |
310 (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) | 310 (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) |
311 (if (= (length | 311 (if (= (length |
312 (delq 0 (mapcar | 312 (delq 0 (mapcar |
313 (lambda (el) | 313 (lambda (el) |
314 (if (string-match org-ts-regexp3 el) | 314 (if (string-match org-ts-regexp3 el) |
315 0 1)) | 315 0 1)) |
316 (mapcar (lambda (row) (nth ind row)) table)))) 0) | 316 (mapcar (lambda (row) (nth ind row)) table)))) 0) |
317 (plist-put params :timeind t) | 317 (plist-put params :timeind t) |
318 ;; check for text ind column | 318 ;; check for text ind column |
319 (if (> (length | 319 (if (> (length |
320 (delq 0 (mapcar | 320 (delq 0 (mapcar |
321 (lambda (el) | 321 (lambda (el) |
322 (if (string-match org-table-number-regexp el) | 322 (if (string-match org-table-number-regexp el) |
323 0 1)) | 323 0 1)) |
324 (mapcar (lambda (row) (nth ind row)) table)))) 0) | 324 (mapcar (lambda (row) (nth ind row)) table)))) 0) |
325 (plist-put params :textind t))))) | 325 (plist-put params :textind t))))) |
326 ;; write script | 326 ;; write script |
327 (with-temp-buffer | 327 (with-temp-buffer |
328 (if (plist-get params :script) ;; user script | 328 (if (plist-get params :script) ;; user script |
329 (progn (insert-file-contents (plist-get params :script)) | 329 (progn (insert-file-contents (plist-get params :script)) |
330 (goto-char (point-min)) | 330 (goto-char (point-min)) |