javascriptd3.jscartogram

Error when creating features in d3.js cartogram


I'm making a simple cartogram with d3.js and I'm stuck with an error drawing the original map. I've written a gist with the example here. The error I'm getting is when I try to create the features like this:

geometries = topology.objects.mex_estados.geometries;
var features = carto.features(topology, geometries)

topology is the object returned by a d3.json call and the error I'm getting is "Uncaught TypeError: topojson.object is not a function", triggered by the call to carto.features.

The variable carto is defined the usual way:

var proj =  d3.geo.mercator()
.center([-97.16, 21.411])
.scale(1000);

var carto = d3.cartogram()
  .projection(proj)
  .properties(function (d) {
    //regresa también las propiedades (valores) de la fuente de dato
    return d.properties;
});

I'm stuck here, I've made cartograms with d3 before but I must be missing something obvious here, any help is appreciated


Solution

  • It turns out I was using the wrong version of cartogram.js, instead of using the version hosted at http://prag.ma/code/d3-cartogram/cartogram.js, I updated the gist with the library version hosted at GitHub and everything worked!