all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]
@ 2024-05-24 11:18 Visuwesh
  2024-05-24 12:21 ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Visuwesh @ 2024-05-24 11:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3439 bytes --]


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

     https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.
------------------------------------------------------------------------

Consider the following table, and try to execute the PLOT line

    #+PLOT: ind:1 deps:(3) type:2d with:lp
    | Sede      | Max cites | H-index |
    |-----------+-----------+---------|
    | Chile     |    257.72 |   21.39 |
    | Leeds     |    165.77 |   19.68 |
    | Sao Paolo |     71.00 |   11.50 |
    | Stockholm |    134.19 |   14.33 |
    | Morelia   |    257.56 |   17.67 |

and watch it fail (see the error message in the *gnuplot* buffer).
Although the 2d option in org-plot/preset-plot-types has :check-ind-type
set to a non-nil value, org-plot/gnuplot does not check the value of
:check-ind-type assigned in the 2d type given in the user-option.

Unless I misunderstood the code, the line

      ;; Check type of ind column (timestamp? text?)
      (when (plist-get params :check-ind-type)

should be

      ;; Check type of ind column (timestamp? text?)
      (when (plist-get (cdr type) :check-ind-type)

because (1) org-plot/collect-options only adds a select number of
keywords to the plist and :check-ind-type is not a part of the select
members, and (2) org-plot/gnuplot is never called with a non-nil value
for the optional argument PARAMS in tree.

BTW, the earlier check in the function for :data-dump should also fail
because

    (plist-get (assoc 'grid org-plot/preset-plot-types) :data-dump) ;; => nil

but

    (plist-get (cdr (assoc 'grid org-plot/preset-plot-types)) :data-dump) ;; => non-nil

where type ≡ (assoc 'grid org-plot/preset-plot-types) in
org-plot/gnuplot.

[ I cannot reproduce the grid example in worg's org-plot.org file, but
  even with the fix, I cannot reproduce it; more below.  ]

The other code smell I see is that the function checks for the PLOT line
twice.  Once near the beginning of the function, and once just after the
cleaning up of hline.  Is this simply an oversight?

Coming to the grid example, the doc-string of org-plot/preset-plot-types
options says:

    - :data-dump - Function to dump the table to a datafile for ease of
      use.

      Accepts lambda function.  Default lambda body:
      (org-plot/gnuplot-to-data table data-file params)

but in fact, org-plot/gnuplot passes one more argument to the :data-dump
function:

      ;; Dump table to datafile
      (let ((dump-func (plist-get type :data-dump)))
        (if dump-func
	    (funcall dump-func table data-file num-cols params)
	  (org-plot/gnuplot-to-data table data-file params)))

but here's the catch: the :data-dump function in the grid option expects
the order

    (lambda (table data-file params _num-cols)

which breaks things down the line.  What should be the actual order
here?  I looked at the history of those lines briefly using C-x v h but
I don't have the time to look into it properly to decide on the actual
argument order.

For now, I have attached a patch that fixes all the issues.  With the
patch, i can run the example covered in the bug report.  The grid
example given in worg passes but it doesn't look as expected.  I am not
sure what to blame here.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-plot-fix.diff --]
[-- Type: text/x-diff, Size: 1505 bytes --]

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..3be1b2f 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -679,8 +679,8 @@ (defun org-plot/gnuplot (&optional params)
 		    tbl))
 	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
 			       (nth 0 table))))
-	   (type (assoc (plist-get params :plot-type)
-			org-plot/preset-plot-types))
+	   (type (cdr (assoc (plist-get params :plot-type)
+			     org-plot/preset-plot-types)))
            gnuplot-script)

       (unless type
@@ -691,17 +691,13 @@ (defun org-plot/gnuplot (&optional params)
 	(setf params
 	      (plist-put params :labels (car table))) ; headers to labels
 	(setf table (delq 'hline (cdr table)))) ; clean non-data from table
-      ;; Collect options.
-      (save-excursion (while (and (equal 0 (forward-line -1))
-				  (looking-at "[[:space:]]*#\\+"))
-			(setf params (org-plot/collect-options params))))
       ;; Dump table to datafile
       (let ((dump-func (plist-get type :data-dump)))
         (if dump-func
-	    (funcall dump-func table data-file num-cols params)
+	    (funcall dump-func table data-file params num-cols)
 	  (org-plot/gnuplot-to-data table data-file params)))
       ;; Check type of ind column (timestamp? text?)
-      (when (plist-get params :check-ind-type)
+      (when (plist-get type :check-ind-type)
 	(let* ((ind (1- (plist-get params :ind)))
 	       (ind-column (mapcar (lambda (row) (nth ind row)) table)))
 	  (cond ((< ind 0) nil) ; ind is implicit

[-- Attachment #3: Type: text/plain, Size: 206 bytes --]


Emacs  : GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.0, Xaw scroll bars)
 of 2024-05-07
Package: Org mode version 9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-18 14:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-24 11:18 [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)] Visuwesh
2024-05-24 12:21 ` Ihor Radchenko
2024-05-24 17:19   ` Visuwesh
2024-06-11  5:41     ` Visuwesh
2024-06-12 12:41     ` Ihor Radchenko
2024-06-13  7:04       ` Visuwesh
2024-06-13  7:18         ` Visuwesh
2024-06-15  9:51           ` Ihor Radchenko
2024-06-17  5:06             ` Visuwesh
2024-06-17 17:13               ` Ihor Radchenko
2024-06-18  5:10                 ` Visuwesh
2024-06-18 14:29                   ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.