Skip to content

Instantly share code, notes, and snippets.

@petebrowne
Created June 12, 2016 15:15
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/415788b657682b1ef68d33ffc0802b90 to your computer and use it in GitHub Desktop.
Save petebrowne/415788b657682b1ef68d33ffc0802b90 to your computer and use it in GitHub Desktop.
class Slice extends React.Component {
render() {
let {value, label, fill, innerRadius = 0, outerRadius} = this.props;
let arc = d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius);
return (
<g>
<path d={arc(value)} fill={fill} />
{/* https://github.com/d3/d3/wiki/SVG-Shapes#arc_centroid */}
<text transform={`translate(${arc.centroid(value)})`}
dy=".35em"
textAnchor="middle"
fill="white">
{label}
</text>
</g>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment