Last active
June 11, 2016 17:58
-
-
Save petebrowne/59fdbb9efa7416e56ca23b33d3b98561 to your computer and use it in GitHub Desktop.
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
class Pie extends React.Component { | |
constructor(props) { | |
super(props); | |
// https://github.com/d3/d3/wiki/Ordinal-Scales#category10 | |
this.colorScale = d3.scale.category10(); | |
this.renderSlice = this.renderSlice.bind(this); | |
} | |
render() { | |
let {x, y, data} = this.props; | |
// https://github.com/d3/d3/wiki/Pie-Layout | |
let pie = d3.layout.pie(); | |
return ( | |
<g transform={`translate(${x}, ${y})`}> | |
{/* Render a slice for each data point */} | |
{pie(data).map(this.renderSlice)} | |
</g> | |
); | |
} | |
renderSlice(value, i) { | |
// We'll create this component in a minute | |
return ( | |
<Slice key={i} | |
outerRadius={this.props.radius} | |
value={value} | |
fill={this.colorScale(i)} /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment