emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/org/org-plot.el,v


From: Carsten Dominik
Subject: [Emacs-diffs] Changes to emacs/lisp/org/org-plot.el,v
Date: Wed, 12 Nov 2008 08:01:19 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Carsten Dominik <cdominik>      08/11/12 08:01:10

Index: org-plot.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/org/org-plot.el,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- org-plot.el 25 Oct 2008 21:32:49 -0000      1.4
+++ org-plot.el 12 Nov 2008 08:01:09 -0000      1.5
@@ -5,7 +5,7 @@
 ;; Author: Eric Schulte <schulte dot eric at gmail dot com>
 ;; Keywords: tables, plotting
 ;; Homepage: http://orgmode.org
-;; Version: 6.10c
+;; Version: 6.12a
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -46,6 +46,8 @@
     (:ind . 0))
   "Default options to gnuplot used by `org-plot/gnuplot'")
 
+(defvar org-plot-timestamp-fmt nil)
+
 (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."
@@ -61,7 +63,8 @@
                  ("with"   . :with)
                  ("file"   . :file)
                  ("labels" . :labels)
-                 ("map"    . :map)))
+                 ("map"     . :map)
+                  ("timefmt" . :timefmt)))
            (multiples '("set" "line"))
            (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)")
            (start 0)
@@ -101,16 +104,27 @@
        (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)))
+
 (defun org-plot-quote-tsv-field (s)
   "Quote field S for export to gnuplot."
   (if (string-match org-table-number-regexp s) s
-    (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")))
+    (if (string-match org-ts-regexp3 s)
+        (org-plot-quote-timestamp-field s)
+      (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\""))))
 
 (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
-      data-file (insert (orgtbl-to-generic
+      data-file 
+    (make-local-variable 'org-plot-timestamp-fmt)
+    (setq org-plot-timestamp-fmt (or
+                                  (plist-get params :timefmt)
+                                  "%Y-%m-%d-%H:%M:%S"))
+    (insert (orgtbl-to-generic
                         table
                         (org-combine-plists
                          '(:sep "\t" :fmt org-plot-quote-tsv-field)
@@ -180,6 +194,8 @@
         (title (plist-get params :title))
         (file (plist-get params :file))
         (ind (plist-get params :ind))
+         (time-ind (plist-get params :timeind))
+         (timefmt (plist-get params :timefmt))
         (text-ind (plist-get params :textind))
         (deps (if (plist-member params :deps) (plist-get params :deps)))
         (col-labels (plist-get params :labels))
@@ -217,6 +233,11 @@
                 (mapconcat (lambda (pair)
                              (format "\"%s\" %d" (cdr pair) (car pair)))
                            y-labels ", "))))
+      (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") "\"")))
       (case type ;; plot command
        ('2d (dotimes (col num-cols)
               (unless (and (equal type '2d)
@@ -284,16 +305,24 @@
        ('grid (let ((y-labels (org-plot/gnuplot-to-grid-data
                                table data-file params)))
                 (when y-labels (plist-put params :ylabels y-labels)))))
-      ;; check for text ind column
+      ;; check for timestamp ind column
       (let ((ind (- (plist-get params :ind) 1)))
        (when (and (>= ind 0) (equal '2d (plist-get params :plot-type)))
+          (if (= (length
+                  (delq 0 (mapcar
+                          (lambda (el)
+                            (if (string-match org-ts-regexp3 el)
+                                0 1))
+                          (mapcar (lambda (row) (nth ind row)) table)))) 0)
+             (plist-put params :timeind t)
+            ;; check for text ind column
          (if (> (length
                  (delq 0 (mapcar
                           (lambda (el)
                             (if (string-match org-table-number-regexp el)
                                 0 1))
                           (mapcar (lambda (row) (nth ind row)) table)))) 0)
-             (plist-put params :textind t))))
+                (plist-put params :textind t)))))
       ;; write script
       (with-temp-buffer
        (if (plist-get params :script) ;; user script
@@ -307,7 +336,8 @@
        (gnuplot-mode)
        (gnuplot-send-buffer-to-gnuplot))
       ;; cleanup
-      (bury-buffer (get-buffer "*gnuplot*"))(delete-file data-file))))
+      (bury-buffer (get-buffer "*gnuplot*"))
+      (delete-file data-file))))
 
 (provide 'org-plot)
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]