Skip to content

Commit

Permalink
version 1-alpha18
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Dec 6, 2023
1 parent 5f5259e commit a6d5838
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
27 changes: 27 additions & 0 deletions notebooks/intro/visualization.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@
{:MSIZE 200})
kind/pprint)

;; We can used Hanami temples from the namespace `[aerial.hanami.templates :as ht]'
;; as well as the additional templates at Noj's `[scicloj.noj.v1.vis.hanami.templates :as vht]`.

(-> datasets/iris
(vis/hanami-plot vht/rule-chart
{:X :sepal-width
:Y :sepal-length
:X2 :petal-width
:Y2 :petal-length
:OPACITY 0.2
:SIZE 3
:COLOR "species"}))

;; ### Grouped datasets

;; Grouped datasets are handled automatically with a table view.

(-> datasets/iris
(tc/group-by [:species])
(vis/hanami-plot vht/rule-chart
{:X :sepal-width
:Y :sepal-length
:X2 :petal-width
:Y2 :petal-length
:OPACITY 0.2
:SIZE 3}))

;; ### Additional Hanami templates

;; The `scicloj.noj.v1.vis.hanami.templates` namespace add Hanami templates to Hanami's own collection.
Expand Down
22 changes: 15 additions & 7 deletions src/scicloj/noj/v1/vis.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[scicloj.kindly.v4.kind :as kind]
[scicloj.noj.v1.paths :as paths]
[scicloj.tempfiles.api :as tempfiles]
[scicloj.noj.v1.stats :as stats]))
[scicloj.noj.v1.stats :as stats]
[tablecloth.api :as tc]))

(defn hanami-data [data]
(when data
Expand All @@ -30,12 +31,19 @@
:else {:DATA data})))

(defn hanami-plot [data template options]
(-> data
hanami-data
(merge options)
(->> (apply concat)
(apply hc/xform template))
kind/vega-lite))
(if (tc/grouped? data)
(-> data
(tc/aggregate {:plot (fn [group-data]
[(-> group-data
(hanami-plot template
options))])})
kind/table)
(-> data
hanami-data
(merge options)
(->> (apply concat)
(apply hc/xform template))
kind/vega-lite)))

(defn hanami-collector [template template-key]
(fn [common-data
Expand Down

0 comments on commit a6d5838

Please sign in to comment.