Created
June 12, 2016 19:23
-
-
Save petebrowne/bea9acab8f8c2dfe243a8ae0daf1c5e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Slice extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {isHovered: false}; | |
this.onMouseOver = this.onMouseOver.bind(this); | |
this.onMouseOut = this.onMouseOut.bind(this); | |
} | |
onMouseOver() { | |
this.setState({isHovered: true}); | |
} | |
onMouseOut() { | |
this.setState({isHovered: false}); | |
} | |
render() { | |
let {value, label, fill, innerRadius = 0, outerRadius, cornerRadius, padAngle, ...props} = this.props; | |
if (this.state.isHovered) { | |
outerRadius *= 1.1; | |
} | |
let arc = d3.svg.arc() | |
.innerRadius(innerRadius) | |
.outerRadius(outerRadius) | |
.cornerRadius(cornerRadius) | |
.padAngle(padAngle); | |
return ( | |
<g onMouseOver={this.onMouseOver} | |
onMouseOut={this.onMouseOut} | |
{...props}> | |
<path d={arc(value)} fill={fill} /> | |
<text transform={translate(...arc.centroid(value))} | |
dy=".35em" | |
className="label"> | |
{label} | |
</text> | |
</g> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment