Created
February 16, 2015 20:51
-
-
Save vicapow/68e21c4bf83ae87cca5a to your computer and use it in GitHub Desktop.
React + D3 boilerplate
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 D3ReactTemplate = React.createClass({ | |
sel: function() { return d3.select(this.getDOMNode()) }, | |
getDefaultProps: function() { | |
return { | |
valueAccessor: function(d) { return d.value }, | |
width: 400, | |
height: 400 | |
} | |
}, | |
getInitialState: function() { | |
var props = this.props | |
return {} | |
}, | |
render: function() { | |
var props = this.props, data = props.data | |
var wrappedData = data.map(function(d) { | |
return { value: props.valueAccessor(d), d: d } | |
}) | |
return React.DOM.svg(extend({style: style}, props), /* svgElements */) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment