Hello,

I've found a bug in =org--plot/sensible-tick-num=, when a plot has a
range of a power of 10  (1, 10, 100, ...).

To reproduce, run =org-plot/gnuplot= on the following plot:
#+plot: type:radar min:0 max:10
| Metric  | Value |
|---------+-------|
| alpha   |     2 |
| beta    |     4 |
| gamma   |     6 |
| delta   |     8 |
| epsilon |    10 |

It produce the error: =let*: Wrong type argument: number-or-marker-p, nil=.

A workaround is to fix the =ticks= value for example by appending =ticks:5=
to the plot line.

I'm not really sure how to correctly fix that bug, but the following
function work fine, at least for my use case. When =org-plot/prime-factors=
return =nil=, it returns ='(5)= instead:
#+begin_src elisp
(defun org--plot/sensible-tick-num (table &optional hard-min hard-max)
  "From a the values in a TABLE of data, guess an appropriate number of ticks.
If HARD-MIN and HARD-MAX can be used to fix the ends of the axis."
  (let* ((row-data
      (mapcar (lambda (row) (org--plot/values-stats
                     (mapcar #'string-to-number (cdr row))
                     hard-min
                     hard-max)) table))
     (row-normalised-ranges (mapcar (lambda (r-data)
                      (let ((val (round (*
                                 (plist-get r-data :range-factor)
                                 (plist-get r-data :nice-range)))))
                        (if (= (% val 10) 0) (/ val 10) val)))
                    row-data))
     (range-prime-decomposition (mapcar (lambda (row-normalised-range)
                                              (or
(org--plot/prime-factors row-normalised-range)
                                                  '(5)))
                                            row-normalised-ranges))
     (weighted-factors (sort (apply #'org--plot/merge-alists #'+ 0
                    (mapcar (lambda (factors)
(org--plot/item-frequencies factors t))
                        range-prime-decomposition))
                 (lambda (a b) (> (cdr a) (cdr b))))))
    (apply #'* (org--plot/nice-frequency-pick weighted-factors))))
#+end_src

Cheers,
-- 
bricewge ~ 8929 BBC5 73CD 9206 3DDD  979D 3D36 CAA0 116F 0F99

Reply via email to