diff options
Diffstat (limited to 'lisp/org/org-plot.el')
| -rw-r--r-- | lisp/org/org-plot.el | 116 |
1 files changed, 59 insertions, 57 deletions
diff --git a/lisp/org/org-plot.el b/lisp/org/org-plot.el index f44694fa781..48d72ac2810 100644 --- a/lisp/org/org-plot.el +++ b/lisp/org/org-plot.el | |||
| @@ -144,7 +144,8 @@ and dependant variables." | |||
| 144 | (dotimes (col (length (first table))) | 144 | (dotimes (col (length (first table))) |
| 145 | (setf collector (cons col collector))) | 145 | (setf collector (cons col collector))) |
| 146 | collector))) | 146 | collector))) |
| 147 | row-vals (counter 0)) | 147 | (counter 0) |
| 148 | row-vals) | ||
| 148 | (when (>= ind 0) ;; collect values of ind col | 149 | (when (>= ind 0) ;; collect values of ind col |
| 149 | (setf row-vals (mapcar (lambda (row) (setf counter (+ 1 counter)) | 150 | (setf row-vals (mapcar (lambda (row) (setf counter (+ 1 counter)) |
| 150 | (cons counter (nth ind row))) table))) | 151 | (cons counter (nth ind row))) table))) |
| @@ -159,26 +160,26 @@ and dependant variables." | |||
| 159 | ;; write table to gnuplot grid datafile format | 160 | ;; write table to gnuplot grid datafile format |
| 160 | (with-temp-file data-file | 161 | (with-temp-file data-file |
| 161 | (let ((num-rows (length table)) (num-cols (length (first table))) | 162 | (let ((num-rows (length table)) (num-cols (length (first table))) |
| 163 | (gnuplot-row (lambda (col row value) | ||
| 164 | (setf col (+ 1 col)) (setf row (+ 1 row)) | ||
| 165 | (format "%f %f %f\n%f %f %f\n" | ||
| 166 | col (- row 0.5) value ;; lower edge | ||
| 167 | col (+ row 0.5) value))) ;; upper edge | ||
| 162 | front-edge back-edge) | 168 | front-edge back-edge) |
| 163 | (flet ((gnuplot-row (col row value) | 169 | (dotimes (col num-cols) |
| 164 | (setf col (+ 1 col)) (setf row (+ 1 row)) | 170 | (dotimes (row num-rows) |
| 165 | (format "%f %f %f\n%f %f %f\n" | 171 | (setf back-edge |
| 166 | col (- row 0.5) value ;; lower edge | 172 | (concat back-edge |
| 167 | col (+ row 0.5) value))) ;; upper edge | 173 | (funcall gnuplot-row (- col 1) row |
| 168 | (dotimes (col num-cols) | 174 | (string-to-number (nth col (nth row table)))))) |
| 169 | (dotimes (row num-rows) | 175 | (setf front-edge |
| 170 | (setf back-edge | 176 | (concat front-edge |
| 171 | (concat back-edge | 177 | (funcall gnuplot-row col row |
| 172 | (gnuplot-row (- col 1) row (string-to-number | 178 | (string-to-number (nth col (nth row table))))))) |
| 173 | (nth col (nth row table)))))) | 179 | ;; only insert once per row |
| 174 | (setf front-edge | 180 | (insert back-edge) (insert "\n") ;; back edge |
| 175 | (concat front-edge | 181 | (insert front-edge) (insert "\n") ;; front edge |
| 176 | (gnuplot-row col row (string-to-number | 182 | (setf back-edge "") (setf front-edge "")))) |
| 177 | (nth col (nth row table))))))) | ||
| 178 | ;; only insert once per row | ||
| 179 | (insert back-edge) (insert "\n") ;; back edge | ||
| 180 | (insert front-edge) (insert "\n") ;; front edge | ||
| 181 | (setf back-edge "") (setf front-edge ""))))) | ||
| 182 | row-vals)) | 183 | row-vals)) |
| 183 | 184 | ||
| 184 | (defun org-plot/gnuplot-script (data-file num-cols params &optional preface) | 185 | (defun org-plot/gnuplot-script (data-file num-cols params &optional preface) |
| @@ -208,40 +209,41 @@ manner suitable for prepending to a user-specified script." | |||
| 208 | ('2d "plot") | 209 | ('2d "plot") |
| 209 | ('3d "splot") | 210 | ('3d "splot") |
| 210 | ('grid "splot"))) | 211 | ('grid "splot"))) |
| 211 | (script "reset") plot-lines) | 212 | (script "reset") |
| 212 | (flet ((add-to-script (line) (setf script (format "%s\n%s" script line)))) | 213 | ; ats = add-to-script |
| 213 | (when file ;; output file | 214 | (ats (lambda (line) (setf script (format "%s\n%s" script line)))) |
| 214 | (add-to-script (format "set term %s" (file-name-extension file))) | 215 | plot-lines) |
| 215 | (add-to-script (format "set output '%s'" file))) | 216 | (when file ;; output file |
| 216 | (case type ;; type | 217 | (funcall ats (format "set term %s" (file-name-extension file))) |
| 217 | ('2d ()) | 218 | (funcall ats (format "set output '%s'" file))) |
| 218 | ('3d (if map (add-to-script "set map"))) | 219 | (case type ;; type |
| 219 | ('grid (if map | 220 | ('2d ()) |
| 220 | (add-to-script "set pm3d map") | 221 | ('3d (if map (funcall ats "set map"))) |
| 221 | (add-to-script "set pm3d")))) | 222 | ('grid (if map (funcall ats "set pm3d map") |
| 222 | (when title (add-to-script (format "set title '%s'" title))) ;; title | 223 | (funcall ats "set pm3d")))) |
| 223 | (when lines (mapc (lambda (el) (add-to-script el)) lines)) ;; line | 224 | (when title (funcall ats (format "set title '%s'" title))) ;; title |
| 224 | (when sets ;; set | 225 | (when lines (mapc (lambda (el) (funcall ats el)) lines)) ;; line |
| 225 | (mapc (lambda (el) (add-to-script (format "set %s" el))) sets)) | 226 | (when sets ;; set |
| 226 | (when x-labels ;; x labels (xtics) | 227 | (mapc (lambda (el) (funcall ats (format "set %s" el))) sets)) |
| 227 | (add-to-script | 228 | (when x-labels ;; x labels (xtics) |
| 228 | (format "set xtics (%s)" | 229 | (funcall ats |
| 229 | (mapconcat (lambda (pair) | 230 | (format "set xtics (%s)" |
| 230 | (format "\"%s\" %d" (cdr pair) (car pair))) | 231 | (mapconcat (lambda (pair) |
| 231 | x-labels ", ")))) | 232 | (format "\"%s\" %d" (cdr pair) (car pair))) |
| 232 | (when y-labels ;; y labels (ytics) | 233 | x-labels ", ")))) |
| 233 | (add-to-script | 234 | (when y-labels ;; y labels (ytics) |
| 234 | (format "set ytics (%s)" | 235 | (funcall ats |
| 235 | (mapconcat (lambda (pair) | 236 | (format "set ytics (%s)" |
| 236 | (format "\"%s\" %d" (cdr pair) (car pair))) | 237 | (mapconcat (lambda (pair) |
| 237 | y-labels ", ")))) | 238 | (format "\"%s\" %d" (cdr pair) (car pair))) |
| 238 | (when time-ind ;; timestamp index | 239 | y-labels ", ")))) |
| 239 | (add-to-script "set xdata time") | 240 | (when time-ind ;; timestamp index |
| 240 | (add-to-script (concat "set timefmt \"" | 241 | (funcall ats "set xdata time") |
| 241 | (or timefmt ;; timefmt passed to gnuplot | 242 | (funcall ats (concat "set timefmt \"" |
| 242 | "%Y-%m-%d-%H:%M:%S") "\""))) | 243 | (or timefmt ;; timefmt passed to gnuplot |
| 243 | (unless preface | 244 | "%Y-%m-%d-%H:%M:%S") "\""))) |
| 244 | (case type ;; plot command | 245 | (unless preface |
| 246 | (case type ;; plot command | ||
| 245 | ('2d (dotimes (col num-cols) | 247 | ('2d (dotimes (col num-cols) |
| 246 | (unless (and (equal type '2d) | 248 | (unless (and (equal type '2d) |
| 247 | (or (and ind (equal (+ 1 col) ind)) | 249 | (or (and ind (equal (+ 1 col) ind)) |
| @@ -263,9 +265,9 @@ manner suitable for prepending to a user-specified script." | |||
| 263 | ('grid | 265 | ('grid |
| 264 | (setq plot-lines (list (format "'%s' with %s title ''" | 266 | (setq plot-lines (list (format "'%s' with %s title ''" |
| 265 | data-file with))))) | 267 | data-file with))))) |
| 266 | (add-to-script | 268 | (funcall ats |
| 267 | (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n ")))) | 269 | (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n ")))) |
| 268 | script))) | 270 | script)) |
| 269 | 271 | ||
| 270 | ;;----------------------------------------------------------------------------- | 272 | ;;----------------------------------------------------------------------------- |
| 271 | ;; facade functions | 273 | ;; facade functions |