function computeLabelPlacement(
pos,
r,
a,
max,
fontSize
) {
let anchor = 'middle'
let dy = fontSize / 3
let distance = (r + dy) / Math.abs(Math.sin(a))
if (Math.abs(distance / Math.sin(a)) > max) {
anchor = Math.cos(a) < 0 ? 'end' : 'start'
dy = fontSize / 3 + Math.sin(a) * fontSize / 3
distance = r
}
pos = [pos[0] + Math.cos(a) * distance, pos[1] + Math.sin(a) * distance]
return { pos, anchor, dy }
}