Skip to content

Commit

Permalink
echarts added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Nov 14, 2024
1 parent 4ab8328 commit 9f60c98
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 19 deletions.
41 changes: 41 additions & 0 deletions demo/.reval/public/rdocument/demo/notebook/echarts/notebook.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; saved on 2024-11-13 20:46:57
{:content [{:out "",
:id :fa9a6188-36c9-4ef8-8742-8d89aa2890ec,
:code "(ns demo.notebook.echarts\n (:require\n [tablecloth.api :as tc]\n [rtable.plot :as plot]\n [demo.random-bars :refer [random-bar-ds]]\n [demo.env :refer [env]]))",
:ns "demo.notebook.echarts",
:result ^{:dali true}
{:viewer-fn dali.viewer.hiccup/hiccup,
:data [:span
{:style {:color "grey"}}
"nil"]}}
{:out "",
:id :f70b5186-e0e2-4d48-8870-00d000798235,
:code "(plot/echarts\n {:style {:width \"600px\"\n :height \"300px\"}\n :data {:xAxis {:type \"category\"\n :data [\"Mon\" \"Tue\" \"Wed\" \"Thu\" \"Fri\" \"Sat\" \"Sun\"]}\n :yAxis {:type \"value\"}\n :series [{:data [150 230 224 218 135 147 260]\n :type \"line\"}]}})",
:ns "demo.notebook.echarts",
:result ^{:dali true}
{:viewer-fn rtable.viewer.echarts/echarts,
:data {:style {:width "600px",
:height "300px"},
:class nil,
:data {:xAxis {:type "category",
:data ["Mon"
"Tue"
"Wed"
"Thu"
"Fri"
"Sat"
"Sun"]},
:yAxis {:type "value"},
:series [{:data [150
230
224
218
135
147
260],
:type "line"}]}}}}],
:meta {:id :a92696c6-d64a-49ee-8c60-0c0315acd117,
:eval-time "2024-11-14T01:46:57.231455491Z",
:ns "demo.notebook.echarts",
:java "19.0.2",
:clojure "1.11.1"}}
32 changes: 16 additions & 16 deletions demo/.reval/public/rdocument/demo/notebook/highchart/notebook.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; saved on 2024-11-13 20:12:46
; saved on 2024-11-13 20:46:26
{:content [{:out "",
:id :90462a03-7ab2-416d-bd44-b5ccca925e5b,
:id :bf151d4b-ab33-4a9a-ae6c-f70ca07de386,
:code "(ns demo.notebook.highchart\n (:require\n [tablecloth.api :as tc]\n [rtable.plot :as plot]\n [demo.random-bars :refer [random-bar-ds]]\n [demo.env :refer [env]]))",
:ns "demo.notebook.highchart",
:result ^{:dali true}
Expand All @@ -9,16 +9,16 @@
{:style {:color "grey"}}
"nil"]}}
{:out "",
:id :7b4ebe3c-cdae-4657-8073-155cb020ef01,
:id :625b18d6-6ff8-4e5b-bbe7-0ffa97128ee9,
:code "(def ds\n (random-bar-ds 100))",
:ns "demo.notebook.highchart",
:result ^{:dali true}
{:viewer-fn dali.viewer.hiccup/hiccup,
:data [:span
{:style {:color "deeppink"}}
"#'demo.notebook.highchart/ds"]}}
{:out "2024-11-14T01:12:46.765855115Z INFO LOG nuc12 dali.store.file(23,7) - writing .data/public/dali/MIh5U.transit-json\n",
:id :085b427d-07d2-4e01-89cf-1bf2a0d35333,
{:out "2024-11-14T01:46:26.709866991Z INFO LOG nuc12 dali.store.file(23,7) - writing .data/public/dali/gKqZ2.transit-json\n",
:id :0cdd0c08-30dc-49d8-bb04-c825a163d716,
:code "(plot/highstock-ds\n env {:style {:width \"600px\"\n :height \"300px\"}\n :charts [{:close {:type :line}\n :bar {:type :ohlc\n :mode :candle}}\n {:volume :column}]}\n ds)",
:ns "demo.notebook.highchart",
:result ^{:dali true}
Expand All @@ -31,21 +31,21 @@
:bar {:type :ohlc,
:mode :candle}}
{:volume :column}],
:load {:id "MIh5U",
:url "/r/dali/MIh5U.transit-json",
:filename "MIh5U.transit-json",
:load {:id "gKqZ2",
:url "/r/dali/gKqZ2.transit-json",
:filename "gKqZ2.transit-json",
:fmt "transit-json"}}}}
{:out "",
:id :319f226f-1dbd-42b8-a569-0c3a820b22d4,
:id :7a3404b8-c9e6-4e82-a0ac-e43e02a9cbf6,
:code "(def ds-step\n (tc/add-column\n ds\n :ind\n (map-indexed (fn [idx p]\n (cond\n (and (> idx 20) (< idx 40))\n nil\n :else\n (- p 2.5))) (:close ds))))",
:ns "demo.notebook.highchart",
:result ^{:dali true}
{:viewer-fn dali.viewer.hiccup/hiccup,
:data [:span
{:style {:color "deeppink"}}
"#'demo.notebook.highchart/ds-step"]}}
{:out "2024-11-14T01:12:46.771741436Z INFO LOG nuc12 dali.store.file(23,7) - writing .data/public/dali/gUK4_.transit-json\n",
:id :da38af2c-fe86-4967-a5c3-6aa054affdfa,
{:out "2024-11-14T01:46:26.740825069Z INFO LOG nuc12 dali.store.file(23,7) - writing .data/public/dali/rI5TO.transit-json\n",
:id :95db2d03-e983-4d28-9475-a5501544a795,
:code "(plot/highstock-ds\n env {:style {:width \"600px\"\n :height \"300px\"}\n :charts [{:bar {:type :ohlc\n :mode :candle}\n :ind {:type :step\n :color \"red\"}}\n {:volume :column}]}\n ds-step)",
:ns "demo.notebook.highchart",
:result ^{:dali true}
Expand All @@ -59,12 +59,12 @@
:ind {:type :step,
:color "red"}}
{:volume :column}],
:load {:id "gUK4_",
:url "/r/dali/gUK4_.transit-json",
:filename "gUK4_.transit-json",
:load {:id "rI5TO",
:url "/r/dali/rI5TO.transit-json",
:filename "rI5TO.transit-json",
:fmt "transit-json"}}}}],
:meta {:id :d3f16459-5931-4ae4-9002-1ff8314fa2eb,
:eval-time "2024-11-14T01:12:46.773502487Z",
:meta {:id :42638372-eafa-4b3b-87de-d9e303524579,
:eval-time "2024-11-14T01:46:26.744055988Z",
:ns "demo.notebook.highchart",
:java "19.0.2",
:clojure "1.11.1"}}
2 changes: 1 addition & 1 deletion demo/.reval/public/rdocument/notebooks.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:study (), :demo ({:nbns "demo.notebook.highchart", :ext "clj", :path "/home/florian/repo/pink-gorilla/dali-table/demo/src/demo/notebook/highchart.clj"} {:nbns "demo.notebook.highlightjs", :ext "clj"} {:nbns "demo.notebook.ajax", :ext "cljs"} {:nbns "demo.notebook.clojure-edn", :ext "cljs"} {:nbns "demo.notebook.clojure-string", :ext "cljs"} {:nbns "demo.notebook.dialog", :ext "cljs"} {:nbns "demo.notebook.fonts", :ext "cljs"} {:nbns "demo.notebook.frisk", :ext "cljs"} {:nbns "demo.notebook.goog-string", :ext "cljs"} {:nbns "demo.notebook.javelin", :ext "cljs"} {:nbns "demo.notebook.jsinterop", :ext "cljs"} {:nbns "demo.notebook.notify", :ext "cljs"} {:nbns "demo.notebook.page-nav", :ext "cljs"} {:nbns "demo.notebook.pprint", :ext "cljs"} {:nbns "demo.notebook.promesa", :ext "cljs"} {:nbns "demo.notebook.tailwind", :ext "cljs"})}
{:study (), :demo ({:nbns "demo.notebook.echarts", :ext "clj", :path "/home/florian/repo/pink-gorilla/dali-table/demo/src/demo/notebook/echarts.clj"} {:nbns "demo.notebook.highchart", :ext "clj", :path "/home/florian/repo/pink-gorilla/dali-table/demo/src/demo/notebook/highchart.clj"} {:nbns "demo.notebook.highlightjs", :ext "clj"} {:nbns "demo.notebook.ajax", :ext "cljs"} {:nbns "demo.notebook.clojure-edn", :ext "cljs"} {:nbns "demo.notebook.clojure-string", :ext "cljs"} {:nbns "demo.notebook.dialog", :ext "cljs"} {:nbns "demo.notebook.fonts", :ext "cljs"} {:nbns "demo.notebook.frisk", :ext "cljs"} {:nbns "demo.notebook.goog-string", :ext "cljs"} {:nbns "demo.notebook.javelin", :ext "cljs"} {:nbns "demo.notebook.jsinterop", :ext "cljs"} {:nbns "demo.notebook.notify", :ext "cljs"} {:nbns "demo.notebook.page-nav", :ext "cljs"} {:nbns "demo.notebook.pprint", :ext "cljs"} {:nbns "demo.notebook.promesa", :ext "cljs"} {:nbns "demo.notebook.tailwind", :ext "cljs"})}
17 changes: 17 additions & 0 deletions demo/src/demo/notebook/echarts.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns demo.notebook.echarts
(:require
[tablecloth.api :as tc]
[rtable.plot :as plot]
[demo.random-bars :refer [random-bar-ds]]
[demo.env :refer [env]]))


(plot/echarts
{:style {:width "600px"
:height "300px"}
:data {:xAxis {:type "category"
:data ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]}
:yAxis {:type "value"}
:series [{:data [150 230 224 218 135 147 260]
:type "line"}]}})

5 changes: 5 additions & 0 deletions resources/ext/rtable-echarts.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:name "rtabke-echarts"
; build
:lazy true
:cljs-namespace [rtable.viewer.echarts]
:cljs-ns-bindings {'rtable.viewer.echarts {'echarts rtable.viewer.echarts/echarts}}}
2 changes: 2 additions & 0 deletions src/deps.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"pixi.js" "^8.4.1"
"@pixi/ui" "^2.1.5"

"echarts" "^5.5.0"

;vega
"vega" "^5.20.2"
"vega-lite" "^4.17.0"
Expand Down
6 changes: 4 additions & 2 deletions src/rtable/plot.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[rtable.plot.highcharts]
[rtable.plot.pixi]
[rtable.plot.rtable]
[rtable.plot.vega]))
[rtable.plot.vega]
[rtable.plot.echarts]))

(import-vars
rtable.plot.aggrid/aggrid-ds
Expand All @@ -17,5 +18,6 @@
rtable.plot.rtable/rtable
rtable.plot.vega/vegalite
rtable.plot.vega/vegalite-ds
rtable.plot.vega/vega)
rtable.plot.vega/vega
rtable.plot.echarts/echarts)

16 changes: 16 additions & 0 deletions src/rtable/plot/echarts.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns rtable.plot.echarts
(:require
[tech.v3.dataset :as tds]
[tablecloth.api :as tc]
[de.otto.nom.core :as nom]
[dali.spec :refer [create-dali-spec]]
[dali.plot.anomaly :as plot]))

(defn echarts [{:keys [style class data]
:or {style {:width "100%" :height "100%"}}
:as opts}]
(create-dali-spec
{:viewer-fn 'rtable.viewer.echarts/echarts
:data {:style style
:class class
:data data}}))
26 changes: 26 additions & 0 deletions src/rtable/viewer/echarts.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns rtable.viewer.echarts
(:require
["echarts" :as ec]))

(defn echarts
[{:keys [style class data on register-map]
:or {style {:width "100%" :height "100%"}
class ""}}]
(fn []
[:div
{:style style
:class class
:ref (fn [el]
(when el
(when-let [[map-name map-options] register-map]
(.registerMap ec
map-name (clj->js map-options)))
(let [chart (.init ec el)]
(->> data
clj->js
(.setOption chart))
(some->> on
(run! (fn [[event-type f]]
(.on chart
(name event-type)
f)))))))}]))

0 comments on commit 9f60c98

Please sign in to comment.