Skip to content

Instantly share code, notes, and snippets.

@FaKod
Created May 9, 2014 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FaKod/e6724675e4ebaf9f8fa4 to your computer and use it in GitHub Desktop.
Save FaKod/e6724675e4ebaf9f8fa4 to your computer and use it in GitHub Desktop.
D3.js 0 fill null values with d3 series data. See http://stackoverflow.com/a/17057231/436937
function insertValues(data, value, dimension, metric, domain) {
var defaults = {};
domain.forEach(function(item) {
var v = {};
v[dimension] = item;
v[metric] = value;
defaults[item] = v;
});
_.each(data, function(item) {
var vals = _.groupBy(item.values, function(i) {
return i[dimension];
});
vals = _.flatten(_.values(_.defaults(vals, defaults)));
vals = _.sortBy(vals, dimension);
item.values = vals;
});
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment