{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "(require '[clojupyter.misc.display :as display]\n", " '[hiccup.core :as hiccup]\n", " '[cheshire.core :as cheshire]\n", " '[clojure.repl :refer :all]) ;; to have all the repl goodies" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(display/make-html (hiccup/html [:script {:src \"https://code.highcharts.com/highcharts.js\"}]))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#'user/plot-highchart" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(defn plot-highchart [highchart-json]\n", " (let [id (str (java.util.UUID/randomUUID))\n", " code (format \"Highcharts.chart('%s', %s );\" id, (cheshire/encode highchart-json))\n", " html [:div [:div {:id id :style {:background-color \"red\"}}]\n", " [:script code]]]\n", " (-> html hiccup/html display/make-html)))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(def raw-data (map #(+ (* 22 (+ % (Math/random)) 78)) (range)))\n", "(def data-1 (take 1000 raw-data))\n", "(def data-2 (take 1000 (drop 1000 raw-data)))\n", "\n", "(plot-highchart {:chart {:type \"line\"}\n", " :title {:text \"Plot of random data\"}\n", " :series [{:data data-1} {:data data-2}]})" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "should print some text\n" ] }, { "data": { "text/html": [ "

hello world

" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(println \"should print some text\")\n", "(let [html [:h1 \"hello world\"]]\n", " (-> html hiccup/html display/make-html))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "should show a svg\n" ] }, { "data": { "text/html": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(println \"should show a svg\")\n", "\n", ";; \n", ";; \n", ";; \n", "\n", "(let [html [:svg {:height 100 :width 100}\n", " [:circle {:cx 50 :cy 40 :r 40 :fill \"yellow\"}]]]\n", " (-> html hiccup/html display/make-html))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Lein-Clojure", "language": "clojure", "name": "lein-clojure" }, "language_info": { "file_extension": ".clj", "mimetype": "text/x-clojure", "name": "clojure", "version": "1.9.0-RC1" } }, "nbformat": 4, "nbformat_minor": 2 }