Created
May 4, 2015 18:38
-
-
Save hiredman/87474665c8fb9f2f22c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def margin 30) | |
(def data | |
'(1 0 0 0 0 0 0 0 1 0 1 3 1 4 6 10 11 13 13 20 22 23 23 24 24 20)) | |
(let [x (range (count data)) | |
s (apply min x) | |
e (apply max x)] | |
(def x-min (- s 1)) | |
(def x-max (+ e 1))) | |
(let [y data | |
s (apply min y) | |
e (apply max y)] | |
(def y-min (- s 1)) | |
(def y-max (+ e 1))) | |
(def x (boot/linear-scale | |
:domain [x-min x-max] | |
:range [(+ 0 margin) (- 900 margin)])) | |
(def y (boot/linear-scale | |
:domain [y-min y-max] | |
:range [(- 690 margin) (+ 0 margin)])) | |
(set! (.-innerHTML boot/pad) | |
(boot/svg [:svg | |
boot/svg-prelude | |
(map-indexed | |
(fn [i d] | |
(if (zero? d) | |
[:cirlce {:cx "0" :cy "0"}] | |
[:circle | |
{:cx (x i) | |
:cy (y d) | |
:r "3" | |
:stroke "steelblue" | |
:stroke-width "2" | |
:fill "steelblue"}])) | |
data) | |
[:path | |
{:d (boot/axis x y | |
[x-min y-min] | |
[x-max y-max]) | |
:fill "none" | |
:stroke "black" | |
:stroke-width "1"}] | |
[:path | |
{:d (apply str (interpose " " | |
(for [t ((boot/ticks x) 6)] | |
(str "M " (x t) " " (y y-min) " " | |
"L " (x t) " " (+ (y y-min) 5))))) | |
:fill "none" | |
:stroke "black" | |
:stroke-width "1"}] | |
[:path | |
{:d (apply str (interpose " " | |
(for [t ((boot/ticks y) 6)] | |
(str "M " (x x-min) " " (y t) " " | |
"L " (- (x x-min) 5) " " (y t))))) | |
:fill "none" | |
:stroke "black" | |
:stroke-width "1"}] | |
(for [t ((boot/ticks x) 6)] | |
[:text {:x (- (x t) 4) | |
:y (+ (y y-min) 15) | |
:font-size "10" | |
:fill "black"} | |
(str t)]) | |
(for [t ((boot/ticks y) 6)] | |
[:text {:x (- (x x-min) 25) | |
:y (+ (y t) 4) | |
:font-size "10" | |
:fill "black"} | |
(str t)]) | |
])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment