diff --git a/notebooks/intro/visualization.clj b/notebooks/intro/visualization.clj index ce39ce1..ef34d7f 100644 --- a/notebooks/intro/visualization.clj +++ b/notebooks/intro/visualization.clj @@ -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. diff --git a/src/scicloj/noj/v1/vis.clj b/src/scicloj/noj/v1/vis.clj index dc0a549..6fae7fc 100644 --- a/src/scicloj/noj/v1/vis.clj +++ b/src/scicloj/noj/v1/vis.clj @@ -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 @@ -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