in src/PieChart.js [217:244]
renderSliceLabel(value, slice, center, radius, index) {
const {
getPieSliceLabel,
pieSliceLabelStyle,
pieSliceLabelDistance,
} = this.props;
const labelPercent = (slice.end - slice.start) / 2 + slice.start;
const style = {
textAnchor: 'middle',
dominantBaseline: 'central',
};
if (pieSliceLabelStyle) {
Object.assign(style, getValue(pieSliceLabelStyle, value));
}
const r = pieSliceLabelDistance
? radius + getValue(pieSliceLabelDistance, value)
: radius;
const x = center.x + Math.sin((2 * Math.PI) / (1 / labelPercent)) * r;
const y = center.y - Math.cos((2 * Math.PI) / (1 / labelPercent)) * r;
return (
<text key={index} x={x} y={y} style={style}>
{getPieSliceLabel(value)}
</text>
);
}