   (did-mount [_]
              (let [{:keys [comm parsets-agg]} (om/get-state owner)
                    parsets-div (om/get-node owner "parsets-div")
-                   card-width (.-offsetWidth parsets-div)
-                   get-svg #(new-svg "#parsets" card-width height)
+                   card-width #(.-offsetWidth parsets-div)
+                   get-svg #(new-svg {:id "#parsets" :height height :width (card-width) :width-fn card-width})
                    chart #(make-parsets-chart
-                           {:height height :width card-width
+                           {:height height :width (card-width) :width-fn card-width
                             :get-parsets-agg (fn [_] (:parsets-agg (om/get-state owner)))})]
                (.attach js/Waves (om/get-node owner "parsets-div") "waves-yellow")
                (go (while (:continue? (om/get-state owner))

  (if (= 0 (count steps))
    (merge prefix {current-step (:key bucket) :value (get-in bucket value-path)})
    (let [prefix (merge prefix {current-step (:key bucket)})]
      (walk-buckets <-buckets bucket prefix steps value-path))))

(defn- agg->parsets [agg-result all-steps value-path]
  (vec (flatten (walk-buckets <-buckets agg-result {} all-steps value-path))))

(defn- new-svg [graph-id w h]
  (-> js/d3 (.select graph-id) (.append "svg") (.attr "width" w) (.attr "height" h)))

(defn- ->query
  [{:keys [agg-terms sub-aggs filters default-filter]}]
  (let [agg-query (build-parsets-agg (reverse agg-terms) sub-aggs)
        agg-query (filtered-agg (merge {:body agg-query}
                                 (merge {:filter default-filter}
                                        (:combined-query filters))))]
    agg-query))

(defn- do-parsets-agg
  [owner]
  (let [{:keys [continue? comm url get-agg-terms make-agg-query value-path]} (om/get-state owner)
        {es-settings :es-settings} (om/get-shared owner)]
    (when continue?
      (go (.log js/console "# running parsets aggregation:" (pr-str (get-agg-terms)))
          (let [{agg-result :aggregations} (<! (es-agg (or url (:url-agg (es-settings))) (make-agg-query)))]
            (>! comm (agg->parsets agg-result (get-agg-terms) value-path)))))))

(defn- update-agg-terms-with-label
  [owner label-string]

  [terms sub-aggs]
  (reduce (fn [agg-query a-term]
            {:aggs (merge
                    {(keyword a-term)
                     (merge {:terms
                             (merge {:field a-term}
                                    (sort-sub sub-aggs))}
                            agg-query)}
                    sub-aggs)})
          (build-sub-aggs sub-aggs) terms))

(defn- build-terms-agg [prefix terms sub-aggs]
  (let [terms-aggs (for [term terms]
                     {(str prefix (name term)) (merge {:terms (merge {:field (name term)}
                                                                     (sort-sub sub-aggs))}
                                                      (build-sub-aggs sub-aggs))})
        terms-aggs (reduce merge terms-aggs)]
    terms-aggs))

(defn- walk-buckets [de-buck bucket prefix steps value-path]
  (map #(de-buck % de-buck prefix (first steps) (rest steps) value-path)
