fix chart legend rendering in production builds

i've no idea why this problem occurs in production builds. maybe
the clojurescript / google closure compiler is miscompiling the
".-datasets" property/field access? munging the name when it shouldn't?
and if so, why did it munge that name and not e.g. ".-labels" which
worked fine?
This commit is contained in:
Gered 2016-06-29 23:49:39 -04:00
parent cf34a72bd8
commit 89112fb19e

View file

@ -30,14 +30,18 @@
(defn- render-vertical-chart-legend (defn- render-vertical-chart-legend
[chart] [chart]
(let [data (-> chart .-data) ;; HACK: usage of aget where '.-' notation *SHOULD* have worked
labels (-> data .-labels) ;; (in practice, it was only not working for 'datasets' in production builds
dataset (-> data .-datasets (aget 0))] ;; even though the js object clearly DID have this field).
;; just changing them all to aget for consistency
(let [data (-> chart (aget "data"))
labels (-> data (aget "labels"))
dataset (-> data (aget "datasets") first)]
(r/render-to-string (r/render-to-string
[:ul {:id (.-id chart)} [:ul {:id (aget chart "id")}
(map-indexed (map-indexed
(fn [idx label] (fn [idx label]
(let [bg-color (-> dataset .-backgroundColor (aget idx))] (let [bg-color (-> dataset (aget "backgroundColor") (aget idx))]
^{:key idx} ^{:key idx}
[:li [:span {:style {:background-color bg-color}}] [:li [:span {:style {:background-color bg-color}}]
label])) label]))