Skip to content

Instantly share code, notes, and snippets.

@mmower
Created August 17, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmower/1a452ec9ac8015c3939f75b94c340ff7 to your computer and use it in GitHub Desktop.
Save mmower/1a452ec9ac8015c3939f75b94c340ff7 to your computer and use it in GitHub Desktop.
(defn axis-label-component [x y label]
(let [dom-data (atom {:width 0 :visibility "hidden"})]
(create-class {:display-name "svg-text"
:reagent-render (fn [x y label]
[:text {:ref (fn [cmp]
(if cmp
(if-let [rect (.getBoundingClientRect cmp)]
(reset! dom-data {:width (double (aget rect "width"))
:visibility "visible"}))))
:x (- x (/ (:width @dom-data) 2))
:y y
:visibility (:visibility @dom-data)
:font-family "Arial"
:font-size 8} label])})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment