From 495307540ff757b8b4f6f756e456b0bed90801a0 Mon Sep 17 00:00:00 2001 From: TEC Date: Wed, 8 Jul 2020 19:26:07 +0800 Subject: [PATCH 2/8] Add new org-plot argument, transpose By modifying `org-plot/add-options-to-plist' and `org-plot/gnuplot' now #+PLOT recognises a transpose:{yes,y,t,*} argument which performs a basic transposition of the table data prior to processing. This is rather useful in some plot types like radar charts. --- lisp/org-plot.el | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/lisp/org-plot.el b/lisp/org-plot.el index b211e0403..25a0f605b 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -50,19 +50,21 @@ "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))) + (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) + ("trans" . :transpose) + ("transpose" . :transpose))) (multiples '("set" "line")) (regexp ":\\([\"][^\"]+?[\"]\\|[(][^)]+?[)]\\|[^ \t\n\r;,.]*\\)") (start 0)) @@ -289,7 +291,18 @@ line directly before or after the table." (setf params (plist-put params (car pair) (cdr pair))))) ;; collect table and table information (let* ((data-file (make-temp-file "org-plot")) - (table (org-table-to-lisp)) + (table (let ((tbl (org-table-to-lisp))) + (when (pcase (plist-get params :transpose) + ('y t) + ('yes t) + ('t t)) + (if (memq 'hline tbl) + (setq tbl (apply #'cl-mapcar #'list tbl)) + ;; When present, remove hlines as they can't (currentily) be easily transposed. + (setq tbl (apply #'cl-mapcar #'list + (remove 'hline tbl))) + (push 'hline (cdr tbl)))) + tbl)) (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table) (nth 0 table))))) (run-with-idle-timer 0.1 nil #'delete-file data-file) -- 2.27.0