<commit_before>(ns clj-simple-chart.ticks)

; The following code is ported from d3-array:
; Original source: https://github.com/d3/d3-array/blob/master/src/ticks.js

(def e10 (Math/sqrt 50))
(def e5 (Math/sqrt 10))
(def e2 (Math/sqrt 2))
(def ln10 (Math/log 10))

(defn tick-increment [start stop count]
  (let [step (/ (- stop start) (max 0 count))
        power (Math/floor (/ (Math/log step) ln10))
        error (/ step (Math/pow 10 power))]
    (if (>= power 0)
      (* (Math/pow 10 power) (cond (>= error e10) 10
                                   (>= error e5) 5
                                   (>= error e2) 2
                                   :else 1))
      (/ (- (Math/pow 10 (- power))) (cond (>= error e10) 10
                                           (>= error e5) 5
                                           (>= error e2) 2
                                           :else 1)))))

(defn ticks [start stop count]
  (if (< stop start)
    (reverse (ticks stop start count))
    (let [step (tick-increment start stop count)]
      (cond (or (Double/isInfinite step) (= 0 step)) []
            (> step 0)
            (let [sstart (Math/ceil (/ start step))
                  sstop (Math/floor (/ stop step))
                  n (Math/ceil (inc (- sstop sstart)))]
              (mapv #(* (+ start %) step) (range 0 n)))
            :else
            (let [sstart (Math/floor (* start step))
                  sstop (Math/ceil (* stop step))
                  n (Math/ceil (inc (- sstart sstop)))]
              (mapv #(/ (- start %) step) (range 0 n)))))))
<commit_msg>Small bugfix<commit_after>(ns clj-simple-chart.ticks)

; The following code is ported from d3-array:
; Original source: https://github.com/d3/d3-array/blob/master/src/ticks.js

(def e10 (Math/sqrt 50))
(def e5 (Math/sqrt 10))
(def e2 (Math/sqrt 2))
(def ln10 (Math/log 10))

(defn tick-increment [start stop count]
  (let [step (/ (- stop start) (max 0 count))
        power (Math/floor (/ (Math/log step) ln10))
        error (/ step (Math/pow 10 power))]
    (if (>= power 0)
      (* (Math/pow 10 power) (cond (>= error e10) 10
                                   (>= error e5) 5
                                   (>= error e2) 2
                                   :else 1))
      (/ (- (Math/pow 10 (- power))) (cond (>= error e10) 10
                                           (>= error e5) 5
                                           (>= error e2) 2
                                           :else 1)))))

(defn ticks [start stop count]
  (if (< stop start)
    (reverse (ticks stop start count))
    (let [step (tick-increment start stop count)]
      (cond (or (Double/isInfinite step) (= 0 step)) []
            (> step 0)
            (let [sstart (Math/ceil (/ start step))
                  sstop (Math/floor (/ stop step))
                  n (Math/ceil (inc (- sstop sstart)))]
              (mapv #(* (+ sstart %) step) (range 0 n)))
            :else
            (let [sstart (Math/floor (* start step))
                  sstop (Math/ceil (* stop step))
                  n (Math/ceil (inc (- sstart sstop)))]
              (mapv #(/ (- sstart %) step) (range 0 n)))))))

{'fraction_non_alphanumeric': 0.1505511811023622, 'fraction_numerical': 0.030236220472440945, 'mean_word_length': 1.3808095952023989, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6414137', 'n_tokens_mistral': 1039, 'n_tokens_neox': 930, 'n_words': 303}