Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pie chart): fix overlapping labels #2599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/arcs/src/arc_link_labels/compute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { positionFromAngle } from '@nivo/core'
import { positionFromAngle, radiansToDegrees } from '@nivo/core'
import { Arc, Point } from '../types'
import { getNormalizedAngle } from '../utils'
import { ArcLink } from './types'
Expand Down Expand Up @@ -37,8 +37,14 @@ export const computeArcLink = (
const centerAngle = getNormalizedAngle(
arc.startAngle + (arc.endAngle - arc.startAngle) / 2 - Math.PI / 2
)

const absSin = Math.abs(Math.sin(centerAngle))
const offsetReducer = Math.abs(arc.endAngle - arc.startAngle) < (Math.PI / 10) ? 1 : 2
const baseOffset = radiansToDegrees(Math.asin(absSin)) / offsetReducer
const linkDiagonalLengthOffset = baseOffset * absSin

const point0: Point = positionFromAngle(centerAngle, arc.outerRadius + offset)
const point1: Point = positionFromAngle(centerAngle, arc.outerRadius + offset + diagonalLength)
const point1: Point = positionFromAngle(centerAngle, arc.outerRadius + offset + diagonalLength + linkDiagonalLengthOffset)

let side: ArcLink['side']
let point2: Point
Expand Down