Martin Kavalar / Apr 20 2020
Vega + Plotly
(defn play-data [& names]
(for [n names
i (range 20)]
{:time i
:item n
:quantity (+ (Math/pow (* i (count n)) 0.8) (rand-int (count n)))}))
{:nextjournal/viewer "vega-lite"}
{:data {:values (play-data "monkey" "slipper" "broom")}
:encoding {:x {:field "time"}
:y {:field "quantity"}
:color {:field "item" :type "nominal"}}
:mark "line"}
1.4s
Clojure
(defn get-coordinates [y]
{:x (0 10 20 30 40)
:y (take 5 (repeatedly (rand-int y)))
:type "scatter"
:text ["one" "two" "three"]})
{:nextjournal/viewer :plotly}
{:data [(conj (get-coordinates 35) {:name "The Federation"})
(conj (get-coordinates 35) {:name "The Empire"})]
:layout {:autosize false :width 600 :height 500
:xaxis1 {:title "year"}
:yaxis1 {:title "revenue"}}}
0.4s
Clojure