* org-plot and timestamps @ 2008-10-27 13:53 Charles Sebold 2008-10-27 15:20 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Charles Sebold @ 2008-10-27 13:53 UTC (permalink / raw) To: emacs-orgmode Has anybody done anything meaningful with timestamps in a table that is being org-plotted? I've got my X axis made up of a table column of org-mode timestamps and I'd like org-plot to send this data to gnuplot as time data (which gnuplot treats in specific ways). If nobody has done this, I'll try to figure something out, and maybe update Worg with a how-to for this or a patch to support this out of the box, but I'm having trouble wrapping my head around gnuplot's syntax at the moment. -- Charles Sebold http://merbc.invigorated.org/ http://triablogue.blogspot.com/ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-27 13:53 org-plot and timestamps Charles Sebold @ 2008-10-27 15:20 ` Eric Schulte 2008-10-27 20:11 ` Charles Sebold 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2008-10-27 15:20 UTC (permalink / raw) To: emacs-orgmode Charles Sebold <csebold@gmail.com> writes: > Has anybody done anything meaningful with timestamps in a table that is > being org-plotted? I've got my X axis made up of a table column of > org-mode timestamps and I'd like org-plot to send this data to gnuplot > as time data (which gnuplot treats in specific ways). > > If nobody has done this, I'll try to figure something out, and maybe > update Worg with a how-to for this or a patch to support this out of the > box, but I'm having trouble wrapping my head around gnuplot's syntax at > the moment. Great idea, please do share if you get anything working. I second that time data can be a pain in gnuplot, but then all the more reason to add support to org-plot to avoid having to deal with gnuplot directly. If you get something working with org-mode dates, I think it would certainly make sense to include it in org-plot, so that it handles timestamps "out of the box". Tally Ho -- Eric ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-27 15:20 ` Eric Schulte @ 2008-10-27 20:11 ` Charles Sebold 2008-10-27 20:51 ` Charles Sebold 0 siblings, 1 reply; 11+ messages in thread From: Charles Sebold @ 2008-10-27 20:11 UTC (permalink / raw) To: emacs-orgmode On 27 Oct 2008, Eric Schulte wrote: > Great idea, please do share if you get anything working. I second > that time data can be a pain in gnuplot, but then all the more reason > to add support to org-plot to avoid having to deal with gnuplot > directly. > > If you get something working with org-mode dates, I think it would > certainly make sense to include it in org-plot, so that it handles > timestamps "out of the box". How's this for a first pass? Not a git user before I started with org-mode so any pointers on how to generate these would be appreciated. Changes in origin/HEAD Modified lisp/org-plot.el diff --git a/lisp/org-plot.el b/lisp/org-plot.el index db67257..74ad817 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -101,10 +101,16 @@ will be added. Returns the resulting property list." (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 "%Y-%m-%d-%H:%M:%S" (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. @@ -180,6 +186,7 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (title (plist-get params :title)) (file (plist-get params :file)) (ind (plist-get params :ind)) + (time-ind (plist-get params :timeind)) (text-ind (plist-get params :textind)) (deps (if (plist-member params :deps) (plist-get params :deps))) (col-labels (plist-get params :labels)) @@ -217,6 +224,9 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (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 "set timefmt \"%Y-%m-%d-%H-%M-%S\"")) (case type ;; plot command ('2d (dotimes (col num-cols) (unless (and (equal type '2d) @@ -284,16 +294,24 @@ line directly before or after the table." ('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 + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) + (if (= (length + (delq 0 (mapcar (lambda (el) - (if (string-match org-table-number-regexp el) + (if (string-match org-ts-regexp3 el) 0 1)) (mapcar (lambda (row) (nth ind row)) table)))) 0) - (plist-put params :textind t)))) + (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))))) ;; write script (with-temp-buffer (if (plist-get params :script) ;; user script @@ -307,7 +325,8 @@ line directly before or after the table." (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) -- Charles Sebold http://merbc.invigorated.org/ http://triablogue.blogspot.com/ ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-27 20:11 ` Charles Sebold @ 2008-10-27 20:51 ` Charles Sebold 2008-10-28 16:23 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Charles Sebold @ 2008-10-27 20:51 UTC (permalink / raw) To: emacs-orgmode On 27 Oct 2008, Charles Sebold wrote: > How's this for a first pass? Not a git user before I started with > org-mode so any pointers on how to generate these would be > appreciated. How embarrassing. This is the patch I meant to send: Changes in origin/HEAD Modified lisp/org-plot.el diff --git a/lisp/org-plot.el b/lisp/org-plot.el index db67257..d0d62f6 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -101,10 +101,16 @@ will be added. Returns the resulting property list." (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 "%Y-%m-%d-%H:%M:%S" (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. @@ -180,6 +186,7 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (title (plist-get params :title)) (file (plist-get params :file)) (ind (plist-get params :ind)) + (time-ind (plist-get params :timeind)) (text-ind (plist-get params :textind)) (deps (if (plist-member params :deps) (plist-get params :deps))) (col-labels (plist-get params :labels)) @@ -217,6 +224,9 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (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 "set timefmt \"%Y-%m-%d-%H:%M:%S\"")) (case type ;; plot command ('2d (dotimes (col num-cols) (unless (and (equal type '2d) @@ -284,16 +294,24 @@ line directly before or after the table." ('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 + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) + (if (= (length + (delq 0 (mapcar (lambda (el) - (if (string-match org-table-number-regexp el) + (if (string-match org-ts-regexp3 el) 0 1)) (mapcar (lambda (row) (nth ind row)) table)))) 0) - (plist-put params :textind t)))) + (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))))) ;; write script (with-temp-buffer (if (plist-get params :script) ;; user script @@ -307,7 +325,8 @@ line directly before or after the table." (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) -- Charles Sebold http://merbc.invigorated.org/ http://triablogue.blogspot.com/ ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-27 20:51 ` Charles Sebold @ 2008-10-28 16:23 ` Eric Schulte 2008-10-29 20:36 ` [PATCH] org-plot: Add support for plotting timestamps Bernt Hansen ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Eric Schulte @ 2008-10-28 16:23 UTC (permalink / raw) To: emacs-orgmode > On 27 Oct 2008, Charles Sebold wrote: > >> How's this for a first pass? Not a git user before I started with >> org-mode so any pointers on how to generate these would be >> appreciated. > Hi Charles, The patch looks great, I vote we drop it 'as is' into org-plot.el. The only enhancement that comes to mind would be to expose the `time-ind' variable as a plot option. Allowing users to specify different time formats, but really if they're that sophisticated in their use of gnuplot, then they can do that on their own through the `set:' option. Thanks for the addition! -- Eric > > How embarrassing. This is the patch I meant to send: > > Changes in origin/HEAD > Modified lisp/org-plot.el > diff --git a/lisp/org-plot.el b/lisp/org-plot.el > index db67257..d0d62f6 100644 > --- a/lisp/org-plot.el > +++ b/lisp/org-plot.el > @@ -101,10 +101,16 @@ will be added. Returns the resulting property list." > (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 "%Y-%m-%d-%H:%M:%S" (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. > @@ -180,6 +186,7 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > (title (plist-get params :title)) > (file (plist-get params :file)) > (ind (plist-get params :ind)) > + (time-ind (plist-get params :timeind)) > (text-ind (plist-get params :textind)) > (deps (if (plist-member params :deps) (plist-get params :deps))) > (col-labels (plist-get params :labels)) > @@ -217,6 +224,9 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > (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 "set timefmt \"%Y-%m-%d-%H:%M:%S\"")) > (case type ;; plot command > ('2d (dotimes (col num-cols) > (unless (and (equal type '2d) > @@ -284,16 +294,24 @@ line directly before or after the table." > ('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 > + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) > + (if (= (length > + (delq 0 (mapcar > (lambda (el) > - (if (string-match org-table-number-regexp el) > + (if (string-match org-ts-regexp3 el) > 0 1)) > (mapcar (lambda (row) (nth ind row)) table)))) 0) > - (plist-put params :textind t)))) > + (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))))) > ;; write script > (with-temp-buffer > (if (plist-get params :script) ;; user script > @@ -307,7 +325,8 @@ line directly before or after the table." > (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) ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] org-plot: Add support for plotting timestamps 2008-10-28 16:23 ` Eric Schulte @ 2008-10-29 20:36 ` Bernt Hansen 2008-10-30 12:43 ` org-plot and timestamps Charles Sebold 2008-10-30 15:35 ` Charles Sebold 2 siblings, 0 replies; 11+ messages in thread From: Bernt Hansen @ 2008-10-29 20:36 UTC (permalink / raw) To: Eric Schulte, Carsten Dominik; +Cc: emacs-orgmode From: Charles Sebold <csebold@gmail.com> X-axis is made up of a table column of org-mode timestamps. This sends the data to gnuplot as time data (which gnuplot treats specially) --- "Eric Schulte" <schulte.eric@gmail.com> writes: >> On 27 Oct 2008, Charles Sebold wrote: >> >>> How's this for a first pass? Not a git user before I started with >>> org-mode so any pointers on how to generate these would be >>> appreciated. >> > Hi Charles, > The patch looks great, I vote we drop it 'as is' into org-plot.el. The > only enhancement that comes to mind would be to expose the `time-ind' > variable as a plot option. Allowing users to specify different time > formats, but really if they're that sophisticated in their use of > gnuplot, then they can do that on their own through the `set:' option. > Thanks for the addition! -- Eric I've added this patch to my org-mode repo so Carsten can just grab it if he likes it. git://git.norang.ca/org-mode on the branch cs/org-plot-timestamps -Bernt lisp/org-plot.el | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lisp/org-plot.el b/lisp/org-plot.el index db67257..d0d62f6 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -101,10 +101,16 @@ will be added. Returns the resulting property list." (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 "%Y-%m-%d-%H:%M:%S" (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. @@ -180,6 +186,7 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (title (plist-get params :title)) (file (plist-get params :file)) (ind (plist-get params :ind)) + (time-ind (plist-get params :timeind)) (text-ind (plist-get params :textind)) (deps (if (plist-member params :deps) (plist-get params :deps))) (col-labels (plist-get params :labels)) @@ -217,6 +224,9 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (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 "set timefmt \"%Y-%m-%d-%H:%M:%S\"")) (case type ;; plot command ('2d (dotimes (col num-cols) (unless (and (equal type '2d) @@ -284,16 +294,24 @@ line directly before or after the table." ('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 + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) + (if (= (length + (delq 0 (mapcar (lambda (el) - (if (string-match org-table-number-regexp el) + (if (string-match org-ts-regexp3 el) 0 1)) (mapcar (lambda (row) (nth ind row)) table)))) 0) - (plist-put params :textind t)))) + (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))))) ;; write script (with-temp-buffer (if (plist-get params :script) ;; user script @@ -307,7 +325,8 @@ line directly before or after the table." (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) -- 1.6.0.3.523.g304d0 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-28 16:23 ` Eric Schulte 2008-10-29 20:36 ` [PATCH] org-plot: Add support for plotting timestamps Bernt Hansen @ 2008-10-30 12:43 ` Charles Sebold 2008-10-30 15:35 ` Charles Sebold 2 siblings, 0 replies; 11+ messages in thread From: Charles Sebold @ 2008-10-30 12:43 UTC (permalink / raw) To: emacs-orgmode On 28 Oct 2008, Eric Schulte wrote: > Hi Charles, The patch looks great, I vote we drop it 'as is' into > org-plot.el. The only enhancement that comes to mind would be to > expose the `time-ind' variable as a plot option. Allowing users to > specify different time formats, but really if they're that > sophisticated in their use of gnuplot, then they can do that on their > own through the `set:' option. Thanks for the addition! -- Eric Good idea, I will try to implement that soon. In the meantime I'm waiting on FSF paperwork to reach me, so I can sign it and get it turned around. -- Charles Sebold http://merbc.invigorated.org/ http://triablogue.blogspot.com/ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-28 16:23 ` Eric Schulte 2008-10-29 20:36 ` [PATCH] org-plot: Add support for plotting timestamps Bernt Hansen 2008-10-30 12:43 ` org-plot and timestamps Charles Sebold @ 2008-10-30 15:35 ` Charles Sebold 2008-11-02 7:04 ` Carsten Dominik 2 siblings, 1 reply; 11+ messages in thread From: Charles Sebold @ 2008-10-30 15:35 UTC (permalink / raw) To: emacs-orgmode On 28 Oct 2008, Eric Schulte wrote: > Hi Charles, The patch looks great, I vote we drop it 'as is' into > org-plot.el. The only enhancement that comes to mind would be to > expose the `time-ind' variable as a plot option. Allowing users to > specify different time formats, but really if they're that > sophisticated in their use of gnuplot, then they can do that on their > own through the `set:' option. Thanks for the addition! -- Eric If I understand you correctly, then what we want to expose is the "timefmt" that is put into the data file and then passed to gnuplot. The following patch is a complete one against current which adds this (it works for me, at least), and documents the new +PLOT option behavior. The one thing I'm not sure about is my method of passing the timefmt parameter all the way into the temp file creation function. I made a buffer-local variable there to do it. That seemed the least intrusive way to accomplish this, but it seemed like poor practice. Thoughts? You know, I really ought to allow a person to customize this variable (I mean, using customize). ------------------------------------------------------------------------ Changes in origin/master Modified doc/org.texi diff --git a/doc/org.texi b/doc/org.texi index b675d92..60be4de 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -2345,6 +2345,10 @@ Specify an entire line to be inserted in the gnuplot script. When plotting @code{3d} or @code{grid} types, set this to @code{t} to graph a flat mapping rather than a @code{3d} slope. +@item timefmt +Specify format of org-mode timestamps as they will be parsed by gnuplot. +Defaults to '%Y-%m-%d-%H:%M:%S'. + @item script If you want total control you can specify a script file (place the file name between double quotes) which will be used to plot. Before plotting, every Modified lisp/org-plot.el diff --git a/lisp/org-plot.el b/lisp/org-plot.el index db67257..f69bfc6 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -51,17 +51,18 @@ Returns the resulting property list." (let (o) (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))) + (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) + ("timefmt" . :timefmt))) (multiples '("set" "line")) (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)") (start 0) @@ -101,20 +102,31 @@ will be added. Returns the resulting property list." (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 - table - (org-combine-plists - '(:sep "\t" :fmt org-plot-quote-tsv-field) - params)))) + 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) + params)))) nil) (defun org-plot/gnuplot-to-grid-data (table data-file params) @@ -180,6 +192,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (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 +231,11 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (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 +303,24 @@ line directly before or after the table." ('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 + (when (and (>= ind 0) (equal '2d (plist-get params :plot-type))) + (if (= (length + (delq 0 (mapcar (lambda (el) - (if (string-match org-table-number-regexp el) + (if (string-match org-ts-regexp3 el) 0 1)) (mapcar (lambda (row) (nth ind row)) table)))) 0) - (plist-put params :textind t)))) + (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))))) ;; write script (with-temp-buffer (if (plist-get params :script) ;; user script @@ -307,7 +334,8 @@ line directly before or after the table." (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) -- Charles Sebold http://merbc.invigorated.org/ http://triablogue.blogspot.com/ ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-10-30 15:35 ` Charles Sebold @ 2008-11-02 7:04 ` Carsten Dominik 2008-11-02 13:04 ` Charles Sebold 0 siblings, 1 reply; 11+ messages in thread From: Carsten Dominik @ 2008-11-02 7:04 UTC (permalink / raw) To: Charles Sebold; +Cc: emacs-orgmode Hi Charles, I have now added this patch. Could you also provide a ChangeLog entry? Thanks. - Carsten On Oct 30, 2008, at 4:35 PM, Charles Sebold wrote: > On 28 Oct 2008, Eric Schulte wrote: > >> Hi Charles, The patch looks great, I vote we drop it 'as is' into >> org-plot.el. The only enhancement that comes to mind would be to >> expose the `time-ind' variable as a plot option. Allowing users to >> specify different time formats, but really if they're that >> sophisticated in their use of gnuplot, then they can do that on their >> own through the `set:' option. Thanks for the addition! -- Eric > > If I understand you correctly, then what we want to expose is the > "timefmt" that is put into the data file and then passed to gnuplot. > The following patch is a complete one against current which adds this > (it works for me, at least), and documents the new +PLOT option > behavior. > > The one thing I'm not sure about is my method of passing the timefmt > parameter all the way into the temp file creation function. I made a > buffer-local variable there to do it. That seemed the least intrusive > way to accomplish this, but it seemed like poor practice. Thoughts? > > You know, I really ought to allow a person to customize this > variable (I > mean, using customize). > > ------------------------------------------------------------------------ > Changes in origin/master > Modified doc/org.texi > diff --git a/doc/org.texi b/doc/org.texi > index b675d92..60be4de 100644 > --- a/doc/org.texi > +++ b/doc/org.texi > @@ -2345,6 +2345,10 @@ Specify an entire line to be inserted in the > gnuplot script. > When plotting @code{3d} or @code{grid} types, set this to @code{t} > to graph a > flat mapping rather than a @code{3d} slope. > > +@item timefmt > +Specify format of org-mode timestamps as they will be parsed by > gnuplot. > +Defaults to '%Y-%m-%d-%H:%M:%S'. > + > @item script > If you want total control you can specify a script file (place the > file name > between double quotes) which will be used to plot. Before plotting, > every > Modified lisp/org-plot.el > diff --git a/lisp/org-plot.el b/lisp/org-plot.el > index db67257..f69bfc6 100644 > --- a/lisp/org-plot.el > +++ b/lisp/org-plot.el > @@ -51,17 +51,18 @@ > Returns the resulting property list." > (let (o) > (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))) > + (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) > + ("timefmt" . :timefmt))) > (multiples '("set" "line")) > (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)") > (start 0) > @@ -101,20 +102,31 @@ will be added. Returns the resulting property > list." > (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 > - table > - (org-combine-plists > - '(:sep "\t" :fmt org-plot-quote-tsv-field) > - params)))) > + 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) > + params)))) > nil) > > (defun org-plot/gnuplot-to-grid-data (table data-file params) > @@ -180,6 +192,8 @@ NUM-COLS controls the number of columns plotted > in a 2-d plot." > (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 +231,11 @@ NUM-COLS controls the number of columns plotted > in a 2-d plot." > (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 +303,24 @@ line directly before or after the table." > ('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 > + (when (and (>= ind 0) (equal '2d (plist-get params :plot- > type))) > + (if (= (length > + (delq 0 (mapcar > (lambda (el) > - (if (string-match org-table-number-regexp el) > + (if (string-match org-ts-regexp3 el) > 0 1)) > (mapcar (lambda (row) (nth ind row)) table)))) 0) > - (plist-put params :textind t)))) > + (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))))) > ;; write script > (with-temp-buffer > (if (plist-get params :script) ;; user script > @@ -307,7 +334,8 @@ line directly before or after the table." > (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) > > > > -- > Charles Sebold > http://merbc.invigorated.org/ > http://triablogue.blogspot.com/ > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-11-02 7:04 ` Carsten Dominik @ 2008-11-02 13:04 ` Charles Sebold 2008-11-02 14:25 ` Carsten Dominik 0 siblings, 1 reply; 11+ messages in thread From: Charles Sebold @ 2008-11-02 13:04 UTC (permalink / raw) To: emacs-orgmode On 2 Nov 2008, Carsten Dominik wrote: > Could you also provide a ChangeLog entry? How's this? ------------------------------------------------------------------------ Changes in master Modified doc/ChangeLog diff --git a/doc/ChangeLog b/doc/ChangeLog index f7b6d2f..0b2faca 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-11-02 Charles Sebold <csebold@gmail.com> + + * org.texi (Org Plot): Add documentation for timefmt option. + 2008-10-16 Carsten Dominik <dominik@science.uva.nl> * org.texi (TODO basics): Add documentation for tag triggers. Modified lisp/ChangeLog diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 890bc99..86cb3e3 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2008-11-02 Charles Sebold <csebold@gmail.com> + + * org-plot.el (org-plot/add-options-to-plist): Supports timefmt + property. + (org-plot-quote-timestamp-field): New function. + (org-plot-quote-tsv-field): Call timestamp field function when + necessary rather than just quoting as a string. + (org-plot/gnuplot-to-data): Pass in timefmt property. + (org-plot/gnuplot-script): Supports timefmt property. + (org-plot/gnuplot): Checks for timestamp column before checking + for text index column. + 2008-11-02 Carsten Dominik <dominik@science.uva.nl> * org.el (org-insert-heading): Improve behavior with hidden subtrees. -- Charles Sebold 2nd of November, 2008 GNU Emacs 22.3.1 (i386-mingw-nt5.1.2600) | Gnus v5.11 | org-mode 6.10c ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-plot and timestamps 2008-11-02 13:04 ` Charles Sebold @ 2008-11-02 14:25 ` Carsten Dominik 0 siblings, 0 replies; 11+ messages in thread From: Carsten Dominik @ 2008-11-02 14:25 UTC (permalink / raw) To: Charles Sebold; +Cc: emacs-orgmode [-- Attachment #1.1: Type: text/plain, Size: 1897 bytes --] Perfect, thanks a lot. On Nov 2, 2008, at 2:04 PM, Charles Sebold wrote: > On 2 Nov 2008, Carsten Dominik wrote: > >> Could you also provide a ChangeLog entry? > > How's this? > > ------------------------------------------------------------------------ > Changes in master > Modified doc/ChangeLog > diff --git a/doc/ChangeLog b/doc/ChangeLog > index f7b6d2f..0b2faca 100644 > --- a/doc/ChangeLog > +++ b/doc/ChangeLog > @@ -1,3 +1,7 @@ > +2008-11-02 Charles Sebold <csebold@gmail.com> > + > + * org.texi (Org Plot): Add documentation for timefmt option. > + > 2008-10-16 Carsten Dominik <dominik@science.uva.nl> > > * org.texi (TODO basics): Add documentation for tag triggers. > Modified lisp/ChangeLog > diff --git a/lisp/ChangeLog b/lisp/ChangeLog > index 890bc99..86cb3e3 100755 > --- a/lisp/ChangeLog > +++ b/lisp/ChangeLog > @@ -1,3 +1,15 @@ > +2008-11-02 Charles Sebold <csebold@gmail.com> > + > + * org-plot.el (org-plot/add-options-to-plist): Supports timefmt > + property. > + (org-plot-quote-timestamp-field): New function. > + (org-plot-quote-tsv-field): Call timestamp field function when > + necessary rather than just quoting as a string. > + (org-plot/gnuplot-to-data): Pass in timefmt property. > + (org-plot/gnuplot-script): Supports timefmt property. > + (org-plot/gnuplot): Checks for timestamp column before checking > + for text index column. > + > 2008-11-02 Carsten Dominik <dominik@science.uva.nl> > > * org.el (org-insert-heading): Improve behavior with hidden subtrees. > > > -- > Charles Sebold 2nd of November, > 2008 > GNU Emacs 22.3.1 (i386-mingw-nt5.1.2600) | Gnus v5.11 | org-mode 6.10c > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode [-- Attachment #1.2: Type: text/html, Size: 3538 bytes --] [-- Attachment #2: Type: text/plain, Size: 204 bytes --] _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-11-02 14:26 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-10-27 13:53 org-plot and timestamps Charles Sebold 2008-10-27 15:20 ` Eric Schulte 2008-10-27 20:11 ` Charles Sebold 2008-10-27 20:51 ` Charles Sebold 2008-10-28 16:23 ` Eric Schulte 2008-10-29 20:36 ` [PATCH] org-plot: Add support for plotting timestamps Bernt Hansen 2008-10-30 12:43 ` org-plot and timestamps Charles Sebold 2008-10-30 15:35 ` Charles Sebold 2008-11-02 7:04 ` Carsten Dominik 2008-11-02 13:04 ` Charles Sebold 2008-11-02 14:25 ` Carsten Dominik
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).