From c62e817b04dfbe624ee8b2090ebcde257bbd3f23 Mon Sep 17 00:00:00 2001 From: TEC Date: Wed, 8 Jul 2020 19:26:07 +0800 Subject: [PATCH 02/11] org-plot.el: add new option :transpose * lisp/org-plot.el (org-plot/add-options-to-plist, org-plot/add-options-to-plist): Add a new option :transpose, and a shorter alias :trans. Transposition is performed if the argument is yes, y, or t. This treats the table as a matrix and performs matrix transposition on it. If an hline is present, it is assumed that it is a marks a separation from a first header row. The first row is then treated as the new header by inserting a hline in the transposed data. This is quite useful for some plots, where across multiple categories, there are a large number of data points. Without this, the data points would be columns and the table can spread irritatingly wide. --- lisp/org-plot.el | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/lisp/org-plot.el b/lisp/org-plot.el index c08bc144e..6ff633130 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,8 +291,20 @@ 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-collapse-header (org-table-to-lisp))) - (num-cols (length (car table)))) + (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) (when (eq (cadr table) 'hline) (setf params -- 2.28.0