all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG] org--plot/sensible-tick-num when range is a power of 10
@ 2024-07-09 16:34 Brice Waegenire
  2024-07-11 11:43 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Brice Waegenire @ 2024-07-09 16:34 UTC (permalink / raw)
  To: emacs-orgmode

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


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

* Re: [BUG] org--plot/sensible-tick-num when range is a power of 10
  2024-07-09 16:34 [BUG] org--plot/sensible-tick-num when range is a power of 10 Brice Waegenire
@ 2024-07-11 11:43 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-07-11 11:43 UTC (permalink / raw)
  To: Brice Waegenire, orgmode; +Cc: emacs-orgmode

Brice Waegenire <brice.wge@gmail.com> writes:

> 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=.

Confirmed.
I am completely lost in the intended logic of how the tics are
determined.
CCing the author.

Timothy, I feel that the logic is pretty much off for ranges with powers
of 10 and for single value column.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2024-07-11 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-09 16:34 [BUG] org--plot/sensible-tick-num when range is a power of 10 Brice Waegenire
2024-07-11 11:43 ` 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.