      :dropdown-hover false
      :dropdown-active false})
   (will-mount [_]
-    (bus/listen-on owner [:result-loaded query-idx col-idx id]
-      #(om/update! term :result (select-keys % [:visit-count-by-study-event]))))
+    (bus/listen-on owner (result-loaded opts id)
+      #(om/update! term :result (select-keys % [:visit-count-by-study-event])))
+    (bus/listen-on owner [:term-loaded query-idx col-idx id]
+      (fn [new-term] (om/transact! term #(merge-into-term % new-term)))))
   (will-unmount [_]
     (bus/unlisten-all owner))
+  (did-update [_ _ _]
+    (when-let [result (:result term)]
+      (clear-chart (cell-id opts id))
+      (draw-query-result (cell-id opts id) result)))
   (render-state [_ {:keys [hover dropdown-hover dropdown-active]}]
     (d/div {:class "query-cell"
             :on-mouse-enter #(om/set-state! owner :hover true)

                              :params {:expr expr}
                              :snapshot (util/get-most-recent-snapshot-id owner)
                              :loaded-topic result-topic}))

;; ---- Headline --------------------------------------------------------------


            [goog.dom :as dom]
            [lens.util :as util]
            [lens.event-bus :as bus]
            [lens.alert :refer [alert!]]
            [lens.schema :as s]))

;; Local history of all versions of the current workbook
(defonce version-history (atom []))
