我正在试验/学习 ClojureScript。以下代码片段与优秀的 d3.js 库接口以显示一些圆圈。发现它有点冗长,不求助于宏,有没有办法优化/最小化它?
(def rdata (atom (array 3 10 12 16 19)))
(defn update []
(let [em (.selectAll (.select js/d3 "svg") "circle")
data (.data em @rdata d3/String)
enter (.append (.enter data) "circle")
yscale (.linear (. js/d3 -scale))
xscale (.linear (. js/d3 -scale))
rscale (.linear (. js/d3 -scale))
]
(-> yscale
(.domain (array 0 20))
(.range (array 100 200)))
(-> xscale
(.domain (array 0 20))
(.range (array 100 800)))
(-> rscale
(.domain (array 0 20))
(.range (array 50 100)))
(-> enter
(.attr "cx" xscale)
(.attr "cy" yscale)
(.attr "r" rscale)
(.style "fill" "steelblue")
(.style "stroke" "black")
(.style "stroke-width" "2")
)
)
(.info js/console "rdata: " @rdata)
)
谢谢