Function: org--plot/nice-frequency-pick

org--plot/nice-frequency-pick is a byte-compiled function defined in org-plot.el.gz.

Signature

(org--plot/nice-frequency-pick FREQUENCIES)

Documentation

From a list of FREQUENCIES, try to sensibly pick a sample of the most frequent.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-plot.el.gz
(defun org--plot/nice-frequency-pick (frequencies)
  "From a list of FREQUENCIES, try to sensibly pick a sample of the most frequent."
  ;; TODO this mosly works decently, but could do with some tweaking to work more consistently.
  (cl-case (length frequencies)
    (1 (list (car (nth 0 frequencies))))
    (2 (if (<= 3 (/ (cdr (nth 0 frequencies))
		    (cdr (nth 1 frequencies))))
	   (make-list 2
		      (car (nth 0 frequencies)))
	 (list (car (nth 0 frequencies))
	       (car (nth 1 frequencies)))))
    (t
     (let* ((total-count (apply #'+ (mapcar #'cdr frequencies)))
	    (n-freq (mapcar (lambda (freq) `(,(car freq) . ,(/ (float (cdr freq)) total-count))) frequencies))
	    (f-pick (list (car (car n-freq))))
	    (1-2-ratio (/ (cdr (nth 0 n-freq))
			  (cdr (nth 1 n-freq))))
	    (2-3-ratio (/ (cdr (nth 1 n-freq))
			  (cdr (nth 2 n-freq))))
	    (1-3-ratio (* 1-2-ratio 2-3-ratio))
	    (1-val (car (nth 0 n-freq)))
	    (2-val (car (nth 1 n-freq)))
	    (3-val (car (nth 2 n-freq))))
       (when (> 1-2-ratio 4) (push 1-val f-pick))
       (when (and (< 1-2-ratio 2-val)
		  (< (* (apply #'* f-pick) 2-val) 30))
	 (push 2-val f-pick))
       (when (and (< 1-3-ratio 3-val)
		  (< (* (apply #'* f-pick) 3-val) 30))
	 (push 3-val f-pick))
       f-pick))))