Skip to content

Instantly share code, notes, and snippets.

@err
Created July 20, 2016 18:55
Show Gist options
  • Save err/c8be7d0fea3dc228b4ece5309ef5cf61 to your computer and use it in GitHub Desktop.
Save err/c8be7d0fea3dc228b4ece5309ef5cf61 to your computer and use it in GitHub Desktop.
(defn render-squares
[component props]
(let [svg (-> js/d3 (.select (dom/node component)))
data (clj->js (:squares props))
selection (-> svg
(.selectAll "rect")
(.data data (fn [d] (.-id d))))]
(-> (.enter selection)
(.append "rect")
(.style "fill" (fn [d] (.-color d)))
(.attr "x" "0")
(.attr "y" "0")
.transition
(.attr "x" (fn [d] (.-x d)))
(.attr "y" (fn [d] (.-y d)))
(.attr "width" (fn [d] (.-size d)))
(.attr "height" (fn [d] (.-size d))))
(-> selection
.exit
.transition
(.style "opacity" "0")
.remove)
false))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment