Skip to content

Instantly share code, notes, and snippets.

@bltavares
Last active August 29, 2015 14:04
Show Gist options
  • Save bltavares/e5093de92c12c0b2a7bf to your computer and use it in GitHub Desktop.
Save bltavares/e5093de92c12c0b2a7bf to your computer and use it in GitHub Desktop.
Sparklines
(ns sparks.core)
(def ticks '[▁ ▂ ▃ ▄ ▅ ▆ ▇ █])
(defn scale [smallest biggest x]
(inc
(/
(* (dec (count ticks)) (- x smallest))
(max (- biggest smallest) 1))))
(defn scaled-seqence [xs]
(let [smallest (apply min xs)
biggest (apply max xs)]
(map (comp int (partial scale smallest biggest)) xs)))
(defn spark [xs]
(map (comp ticks dec) (scaled-seqence xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment