Skip to content

Instantly share code, notes, and snippets.

@petebrowne
Created June 12, 2016 19:23
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 petebrowne/bea9acab8f8c2dfe243a8ae0daf1c5e4 to your computer and use it in GitHub Desktop.
Save petebrowne/bea9acab8f8c2dfe243a8ae0daf1c5e4 to your computer and use it in GitHub Desktop.
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