Skip to content

Commit de262a7

Browse files
committed
fix: tooltip stacked sorting
1 parent 786ea07 commit de262a7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/components/Chart.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,15 @@ function sortDatumsBySecondaryPx<TDatum>(
786786
datums: Datum<TDatum>[],
787787
secondaryAxes: Axis<TDatum>[]
788788
) {
789+
if (secondaryAxes.every(d => d.stacked)) {
790+
const differingInverts =
791+
secondaryAxes.some(d => d.invert) && secondaryAxes.some(d => !d.invert)
792+
793+
if (!differingInverts) {
794+
return datums
795+
}
796+
}
797+
789798
return [...datums].sort((a, b) => {
790799
const aAxis = secondaryAxes.find(d => d.id === a.secondaryAxisId)
791800
const bAxis = secondaryAxes.find(d => d.id === b.secondaryAxisId)
@@ -796,14 +805,6 @@ function sortDatumsBySecondaryPx<TDatum>(
796805
const bPx =
797806
bAxis?.scale(bAxis.stacked ? b.stackData?.[1] : b.secondaryValue) ?? NaN
798807

799-
if ((aAxis || bAxis)?.stacked) {
800-
return a.seriesIndex > b.seriesIndex
801-
? 1
802-
: a.seriesIndex < b.seriesIndex
803-
? -1
804-
: 0
805-
}
806-
807808
return aPx > bPx ? 1 : aPx < bPx ? -1 : 0
808809
})
809810
}

0 commit comments

Comments
 (0)