Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
label: PropTypes.string.isRequired,
fill: PropTypes.string.isRequired,
})
).isRequired,
*/
}
export const PieDefaultProps = {
sortByValue: false,
innerRadius: 0,
padAngle: 0,
cornerRadius: 0,
// layout
startAngle: 0,
endAngle: radiansToDegrees(Math.PI * 2),
fit: true,
// border
borderWidth: 0,
borderColor: {
from: 'color',
modifiers: [['darker', 1]],
},
// radial labels
enableRadialLabels: true,
radialLabel: 'id',
radialLabelsTextColor: { theme: 'labels.text.fill' },
radialLabelsLinkColor: { theme: 'axis.ticks.line.stroke' },
// slices labels
label: PropTypes.string.isRequired,
fill: PropTypes.string.isRequired,
})
).isRequired,
*/
}
export const PieDefaultProps = {
sortByValue: false,
innerRadius: 0,
padAngle: 0,
cornerRadius: 0,
// layout
startAngle: 0,
endAngle: radiansToDegrees(Math.PI * 2),
fit: true,
// border
borderWidth: 0,
borderColor: 'inherit:darker(1)',
// radial labels
enableRadialLabels: true,
radialLabel: 'id',
radialLabelsTextColor: 'theme',
radialLabelsLinkColor: 'theme',
// slices labels
enableSlicesLabels: true,
sliceLabel: 'value',
slicesLabelsTextColor: 'theme',
const textAnchorFromAngle = _angle => {
const angle = radiansToDegrees(_angle) + 90
if (angle <= 10 || angle >= 350 || (angle >= 170 && angle <= 190)) return 'middle'
if (angle > 180) return 'end'
return 'start'
}
arcs: pie(data).map(arc => {
const angle = Math.abs(arc.endAngle - arc.startAngle)
return {
...arc,
angle,
angleDeg: radiansToDegrees(angle),
}
}),
})),
.map(arc => {
const angle = absoluteAngleRadians(midAngle(arc) - Math.PI / 2)
const positionA = positionFromAngle(angle, radius + linkOffset)
const positionB = positionFromAngle(angle, radius + linkOffset + linkDiagonalLength)
let positionC
let labelPosition
let textAlign
if (
absoluteAngleDegrees(radiansToDegrees(angle)) < 90 ||
absoluteAngleDegrees(radiansToDegrees(angle)) >= 270
) {
positionC = { x: positionB.x + linkHorizontalLength, y: positionB.y }
labelPosition = {
x: positionB.x + linkHorizontalLength + textXOffset,
y: positionB.y,
}
textAlign = 'left'
} else {
positionC = { x: positionB.x - linkHorizontalLength, y: positionB.y }
labelPosition = {
x: positionB.x - linkHorizontalLength - textXOffset,
y: positionB.y,
}
textAlign = 'right'
}
const labels = indices.map((index, i) => {
const position = positionFromAngle(angles[i], radius + labelOffset)
const textAnchor = textAnchorFromAngle(angles[i])
return {
id: index,
angle: radiansToDegrees(angles[i]),
anchor: textAnchor,
...position,
}
})
const textAnchorFromAngle = _angle => {
const angle = radiansToDegrees(_angle) + 90
if (angle <= 10 || angle >= 350 || (angle >= 170 && angle <= 190)) return 'middle'
if (angle > 180) return 'end'
return 'start'
}
export const getLinkAngle = (sourceX, sourceY, targetX, targetY) => {
const angle = Math.atan2(targetY - sourceY, targetX - sourceX)
return absoluteAngleDegrees(radiansToDegrees(angle))
}