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.
This commit is contained in:
TEC 2020-07-08 19:26:07 +08:00 committed by Bastien
parent a64aa25fa5
commit 8d5122fc5e
1 changed files with 29 additions and 15 deletions

View File

@ -51,19 +51,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))
@ -290,8 +292,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