Skip to content

Commit

Permalink
fix: tooltip stacked sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jan 26, 2023
1 parent 786ea07 commit de262a7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,15 @@ function sortDatumsBySecondaryPx<TDatum>(
datums: Datum<TDatum>[],
secondaryAxes: Axis<TDatum>[]
) {
if (secondaryAxes.every(d => d.stacked)) {
const differingInverts =
secondaryAxes.some(d => d.invert) && secondaryAxes.some(d => !d.invert)

if (!differingInverts) {
return datums
}
}

return [...datums].sort((a, b) => {
const aAxis = secondaryAxes.find(d => d.id === a.secondaryAxisId)
const bAxis = secondaryAxes.find(d => d.id === b.secondaryAxisId)
Expand All @@ -796,14 +805,6 @@ function sortDatumsBySecondaryPx<TDatum>(
const bPx =
bAxis?.scale(bAxis.stacked ? b.stackData?.[1] : b.secondaryValue) ?? NaN

if ((aAxis || bAxis)?.stacked) {
return a.seriesIndex > b.seriesIndex
? 1
: a.seriesIndex < b.seriesIndex
? -1
: 0
}

return aPx > bPx ? 1 : aPx < bPx ? -1 : 0
})
}

0 comments on commit de262a7

Please sign in to comment.