Created
December 18, 2012 21:57
-
-
Save seliopou/4332420 to your computer and use it in GitHub Desktop.
A reusable chart combinator for D3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chart = (function() { | |
function copy(o) { | |
return Object.keys(o).reduce(function(no, k) { | |
no[k] = o[k]; | |
return no; | |
}, {}); | |
} | |
return function(defaults, _cstr) { | |
return function() { | |
var attrs = {}; | |
var my = function(selection) { | |
return _cstr(selection, copy(attrs)); | |
}; | |
d3.entries(defaults).forEach(function(e) { | |
my[e.key] = function(value) { | |
if (arguments.length == 0) { return attrs[e.key]; } | |
attrs[e.key] = value; | |
return my; | |
} | |
attrs[e.key] = e.value; | |
}); | |
return my; | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment