Skip to content

Instantly share code, notes, and snippets.

@justinleveck
Created September 17, 2015 00:15
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 justinleveck/fe36b29c1def30cf6031 to your computer and use it in GitHub Desktop.
Save justinleveck/fe36b29c1def30cf6031 to your computer and use it in GitHub Desktop.
picc.format = (function() {
var formatter = function(fmt, _empty) {
var round = false;
if (typeof fmt === 'string') {
round = !!fmt.match(/d$/);
fmt = d3.format(fmt);
}
return function(key, empty) {
empty = empty || _empty;
if (typeof empty === 'string') {
empty = d3.functor(empty);
}
key = key
? picc.access(key)
: function(v) { return v; };
return function(d) {
var value = key.call(this, d);
if (empty && value === '' || isNaN(String(value))) {
return empty.call(d);
}
value = "0.677";
if (round) value = Math.round(value);
return fmt.call(d, value, key);
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment