40 KiB
40 KiB
In [1]:
(require '[clojupyter.misc.display :as display]
'[hiccup.core :as hiccup]
'[cheshire.core :as cheshire]
'[clojure.repl :refer :all]) ;; to have all the repl goodiesIn [2]:
(display/make-html (hiccup/html [:script {:src "https://code.highcharts.com/highcharts.js"}]))Out [2]:
In [5]:
(defn plot-highchart [highchart-json]
(let [id (str (java.util.UUID/randomUUID))
code (format "Highcharts.chart('%s', %s );" id, (cheshire/encode highchart-json))
html [:div [:div {:id id :style {:background-color "red"}}]
[:script code]]]
(-> html hiccup/html display/make-html)))Out [5]:
#'user/plot-highchart
In [6]:
(def raw-data (map #(+ (* 22 (+ % (Math/random)) 78)) (range)))
(def data-1 (take 1000 raw-data))
(def data-2 (take 1000 (drop 1000 raw-data)))
(plot-highchart {:chart {:type "line"}
:title {:text "Plot of random data"}
:series [{:data data-1} {:data data-2}]})Out [6]:
In [8]:
(println "should print some text")
(let [html [:h1 "hello world"]]
(-> html hiccup/html display/make-html))Out [8]:
should print some text
hello world
In [9]:
(println "should show a svg")
;; <svg width="100" height="100">
;; <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
;; </svg>
(let [html [:svg {:height 100 :width 100}
[:circle {:cx 50 :cy 40 :r 40 :fill "yellow"}]]]
(-> html hiccup/html display/make-html))Out [9]:
should show a svg
In [ ]: