       (.dimensions (clj->js (map name (get-parsets-agg))))
       (.value (fn [d i] (. d -value)))))
 
-(defn- dim-accessor [sub-agg]
-  (or sub-agg :doc_count))
-
 (defn highlight [data facets]
   (filter #(every? (fn [[k sel]] (or (empty? sel) (contains? sel (k %)))) facets) data))
 

                 :svg nil
                 :parsets-data []
                 :highlighted {}
                 :parsets-cursor (om/root-cursor (atom {:div {:width "90%" :height 200}}))
                 :show-dimensions (get-in opts [:dimensions :show])
                 :show-dimensions? #(:show-dimensions (om/get-state owner))}))
  (will-mount [_]
              (do-parsets-agg owner))
  (render-state [_ {:keys [parsets-agg get-agg-terms agg-prefix-terms parsets-cursor show-dimensions]}]
                (html
                 [:.card {:ref "parsets-card"}
                  [:.card-content

  (vec (flatten (walk-buckets <-buckets agg-result {} steps value-path))))

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

(defn- reset-highlighted [owner]
  (-> js/d3 (.select (om/get-node owner "parsets-dims")) (.selectAll ".mg-bar") (.classed "highlight" false)))

(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)))]
            (let [parsets-data (agg->parsets agg-result (get-agg-terms) value-path)]
              (reset-highlighted owner)
              (om/update-state! owner #(assoc % :parsets-data parsets-data))
