Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save pcn/a1c27022579117f106b0 to your computer and use it in GitHub Desktop.

Select an option

Save pcn/a1c27022579117f106b0 to your computer and use it in GitHub Desktop.
Does this look right? Translating from javascript to clojurescript
(defn- build-map [svg topo-obj]
(let [subunits (.-subunits (.-objects topo-obj))
geo (.-geo js/d3)
feature (.-feature js/topojson)
mercator (.-mercator geo)]
(.. svg
(append "path")
(datum (feature topo-obj subunits))
(attr "d"
(.. geo
(path)
(projection (mercator)))))))
// From http://bost.ocks.org/mike/map/
d3.json("uk.json", function(error, uk) {
if (error) return console.error(error);
svg.append("path")
.datum(topojson.feature(uk, uk.objects.subunits))
.attr("d", d3.geo.path().projection(d3.geo.mercator()));
});
// I'm not sure this looks correct -t he calls to e.g. feature turning into feature.call with the first arg being null is unexpected.
map_brazil.core.build_map = (function build_map(svg,topo_obj){
var subunits = topo_obj.objects.subunits;
var geo = d3.geo;
var feature = topojson.feature;
var mercator = geo.mercator;
return svg.append("path").datum(feature.call(null,topo_obj,subunits)).attr("d",geo.path().projection(mercator.call(null)));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment