2

ビュー ライブラリとして使用するre-framecljs フレームワークを使用しています。サブスクリプションの更新時に更新したいグラフ コンポーネントがreagentあります。nvd3

残念ながら、 への最初の呼び出しの後、グラフが更新されることはありません:component-did-mount:component-will-update最初のレンダリング後に再度呼び出されることはありません。

サブスクリプションがリッスンしているデータが変更されたことをコンポーネントに通知すると、グラフが更新されるようにします。

グラフコンテナコンポーネントは次のとおりです。

(defn weight-graph-container
  []
  (let [weight  (subscribe [:weight-change])
        bodyfat (subscribe [:bodyfat-change])
        weight-amount (reaction (get @weight :amount))
        weight-unit   (reaction (get @weight :unit))
        bf-percentage (reaction (get @bodyfat :percentage))
        lbm           (reaction (lib/lbm @weight-amount @bf-percentage))
        fat-mass      (reaction (- @weight-amount @lbm))]
    (reagent/create-class {:reagent-render weight-graph
                           :component-did-mount (draw-weight-graph @lbm @fat-mass "lb")
                           :display-name "weight-graph"
                           :component-did-update (draw-weight-graph @lbm @fat-mass "lb")})))

グラフ コンポーネントは次のとおりです。

(defn draw-weight-graph [lbm fat-mass unit]
  (.addGraph js/nv (fn []
                     (let [chart (.. js/nv -models pieChart
                                     (x #(.-label %))
                                     (y #(.-value %))
                                     (showLabels true))]
                       (let [weight-data [{:label "LBM" :value lbm} {:label "Fat Mass" :value fat-mass}]]
                         (.. js/d3 (select "#weight-graph svg")
                                   (datum (clj->js weight-data))
                                   (call chart)))))))

最後に、グラフがレンダリングされるコンポーネントは次のとおりです。

(defn weight-graph []
  [:section#weight-graph
   [:svg]])

私は何が欠けていますか?助けてくれてありがとう。

4

1 に答える 1