Skip to content

Commit 0b22f1a

Browse files
committed
BulletChart: fix measure sorting & test
1 parent 53d1c07 commit 0b22f1a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/charts/src/components/BulletChart/BulletChart.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('BulletChart', () => {
6464
}),
6565
);
6666

67-
cy.contains('Users').click();
67+
cy.get('[class="recharts-legend-wrapper"]').findByText('Users').realClick();
6868
cy.get('@onLegendClick').should(
6969
'have.been.calledWith',
7070
Cypress.sinon.match({

packages/charts/src/components/BulletChart/BulletChart.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,19 @@ const BulletChart = forwardRef<HTMLDivElement, BulletChartProps>((props, ref) =>
175175
const activePayloadsRef = useRef<ActivePayload[]>(measures);
176176

177177
const sortedMeasures = useMemo(() => {
178-
return measures.sort((measure) => {
179-
if (measure.type === 'comparison') {
178+
return [...measures].sort((a, b) => {
179+
if (a.type === 'primary' && b.type !== 'primary') {
180+
return -1;
181+
}
182+
if (b.type === 'primary' && a.type !== 'primary') {
180183
return 1;
181184
}
182-
183-
if (measure.type === 'primary') {
185+
if (a.type === 'comparison' && b.type !== 'comparison') {
186+
return 1;
187+
}
188+
if (b.type === 'comparison' && a.type !== 'comparison') {
184189
return -1;
185190
}
186-
187191
return 0;
188192
});
189193
}, [measures]);

0 commit comments

Comments
 (0)