kartograph / kartograph.js

UNMAINTAINED Open source JavaScript renderer for Kartograph SVG maps
http://kartograph.org
GNU Lesser General Public License v3.0
1.51k stars 228 forks source link

Add fallback to shape data for choropleth API (and others) #19

Closed gka closed 12 years ago

gka commented 12 years ago

Three new use scenarios:

No data injection

If no data is specified at all, the raw shape data will be passed to all callback functions.

var stats = {
  "AL": 8.9,
  "CA": 9.6,
  ...
};

map.choropleth({
   colors: function(d) { return colorscale.getColor(stats[d.code]) };
});

Data injection through callback function

You can simplify your callbacks by setting a data callback function which processes the raw shape data before it will be passed to other callback functions. The raw shape data will be optionally passed as second argument.

map.choropleth({
   data: function(d) { return stats[d.code] },
   colors: function(value) { return colorscale.getColor(value) }
})

Old-school data injection

However, the old-school way of data injection will work, too.

map.choropleth({
   data: stats,
   colors: function(value) { return colorscale.getColor(value) }
})
gka commented 12 years ago

fixed in 9752ac61d5