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

Chore: adjust pie sector key value #4009

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/polar/Pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ export class Pie extends PureComponent<Props, State> {
renderSectorsStatically(sectors: PieSectorDataItem[]) {
const { activeShape, blendStroke, inactiveShape: inactiveShapeProp } = this.props;
return sectors.map((entry, i) => {
if (entry?.startAngle === 0 && entry?.endAngle === 0 && sectors.length !== 1) return null;
ckifer marked this conversation as resolved.
Show resolved Hide resolved
const isActive = this.isActiveIndex(i);
const inactiveShape = inactiveShapeProp && this.hasActiveIndex() ? inactiveShapeProp : null;
const sectorOptions = isActive ? activeShape : inactiveShape;
Expand All @@ -497,8 +498,7 @@ export class Pie extends PureComponent<Props, State> {
tabIndex={-1}
className="recharts-pie-sector"
{...adaptEventsOfChild(this.props, entry, i)}
// eslint-disable-next-line react/no-array-index-key
key={`sector-${i}`}
key={`sector-${entry?.startAngle}-${entry?.endAngle}-${entry.midAngle}`}
>
<Shape option={sectorOptions} isActive={isActive} shapeType="sector" {...sectorProps} />
</Layer>
Expand Down
33 changes: 22 additions & 11 deletions test/chart/PieChart.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { vi, Mock } from 'vitest';
import { PieChart, Pie, Legend, Cell, Tooltip, Sector, SectorProps } from '../../src';

describe('<PieChart />', () => {
const data = [
{ name: 'Group A', value: 400 },
{ name: 'Group B', value: 300 },
{ name: 'Group C', value: 300 },
{ name: 'Group D', value: 200 },
{ name: 'Group E', value: 278 },
{ name: 'Group F', value: 189 },
{ name: 'Group A', value: 400, v: 89 },
{ name: 'Group B', value: 300, v: 100 },
{ name: 'Group C', value: 200, v: 200 },
{ name: 'Group D', value: 200, v: 20 },
{ name: 'Group E', value: 278, v: 40 },
{ name: 'Group F', value: 189, v: 60 },
];

test('Renders 6 sectors circles in simple PieChart', () => {
test('Renders 1 sector with animation, simple PieChart', () => {
const { container } = render(
<PieChart width={800} height={400}>
<Pie
dataKey="value"
isAnimationActive={false}
data={data}
isAnimationActive
data={[data[0]]}
cx={200}
cy={200}
outerRadius={80}
Expand All @@ -30,7 +30,18 @@ describe('<PieChart />', () => {
</PieChart>,
);

expect(container.querySelectorAll('.recharts-pie-sector')).toHaveLength(data.length);
expect(container.querySelectorAll('.recharts-pie-sector')).toHaveLength(1);
});
test('Renders 6 sectors circles in simple PieChart', () => {
const { container } = render(
<PieChart width={800} height={400}>
<Pie dataKey="value" isAnimationActive data={data} cx={200} cy={200} outerRadius={80} fill="#ff7300" label />
</PieChart>,
);

waitFor(() => {
expect(container.querySelectorAll('.recharts-pie-sector')).toHaveLength(data.length);
});
});

test('Renders 6 sectors circles in simple PieChart with animation', () => {
Expand Down