Database Reference
In-Depth Information
Getting ready
We'll use the same dependencies and plugins in our project.clj ile as we did in the
Creating scatter plots with NVD3 recipe.
As I just mentioned, we'll use a graph of clusters of US census race data by state. I've already
compiled this, and you can download it from http://www.ericrochester.com/clj-
data-analysis/data/clusters.json . Place it in the resources/data/ directory of
your project and you should be ready.
How to do it…
This recipe will follow the same pattern that we've seen in the last few recipes. We'll deine a
handler, routes, and then the ClojureScript. To do this, perform the following steps:
1.
The handler is similar to what we've seen so far, and it uses the d3-page
function too:
(defn force-layout-plot []
(d3-page "Force-Directed Layout"
"webviz.force.force_layout();"
[:div#force.chart [:svg]]))
2.
The routes are also as we'd expect them to be:
(defroutes
site-routes
(GET "/force" [] (force-layout-plot))
(GET "/force/data.json" []
(redirect "/data/clusters.json"))
(route/resources "/")
(route/not-found "Page not found"))
3.
We'll also need some style. Open resources/css/style.css and add these lines:
#force { width: 650px; height: 500px; }
#force .node { stroke: #fff; stroke-width: 1.5px; }
#force .link { stroke: #999; stroke-opacity: 1; }
4. Now, let's create the ClojureScript ile. Open src-cljs/webviz/force.cljs and
add this for the namespace declaration:
(ns webviz.force)
 
Search WWH ::




Custom Search