Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion piechart/src/PieChartBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type * as Components from '@perses-dev/components';
import { render } from '@testing-library/react';

import type { PieChartData } from './PieChartBase';
import { PieChartBase } from './PieChartBase';
import { MIN_SHOW_LABEL_ANGLE, PieChartBase } from './PieChartBase';

const { eChartSpy } = vi.hoisted(() => ({ eChartSpy: vi.fn() }));

Expand All @@ -38,7 +38,9 @@ interface EChartProps {
emphasis: {
scaleSize: number;
};
labelLayout: { hideOverlap: boolean };
left: number;
minShowLabelAngle: number;
radius: string | [string, string];
right: number;
top: number;
Expand Down Expand Up @@ -91,4 +93,20 @@ describe('PieChartBase', () => {
const props = eChartSpy.mock.lastCall?.[0] as EChartProps;
expect(props.option.series[0]?.radius).toEqual(DONUT_RADIUS);
});

it('omits labels that cannot fit in a slice', () => {
render(
<ChartsProvider chartsTheme={testChartsTheme}>
<PieChartBase width={400} height={300} data={EMPTY_DATA} showLabels outerRadius={90} />
Comment on lines +97 to +100

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. The chart component is mocked in this test, so it never lays out slices. Passing a slice under 5% would not show whether its label is drawn. What we own is the option handed to ECharts: minShowLabelAngle of 18 degrees and labelLayout.hideOverlap. ECharts hides the label from those options, including on hover. The slice tooltip stays available.

</ChartsProvider>,
);

const props = eChartSpy.mock.lastCall?.[0] as EChartProps;
expect(props.option.series[0]).toEqual(
expect.objectContaining({
minShowLabelAngle: MIN_SHOW_LABEL_ANGLE,
labelLayout: { hideOverlap: true },
}),
);
});
});
3 changes: 3 additions & 0 deletions piechart/src/PieChartBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const CONTAINER_SX = { overflow: 'auto' };
const EMPHASIS_SHADOW_BLUR = 10;
const EMPHASIS_SCALE_SIZE = 5;
const PIE_INSET = EMPHASIS_SHADOW_BLUR + EMPHASIS_SCALE_SIZE;
export const MIN_SHOW_LABEL_ANGLE = 360 * 0.05;
export interface PieChartData {
id?: string;
name: string;
Expand Down Expand Up @@ -99,6 +100,8 @@ export function PieChartBase(props: PieChartBaseProps): ReactElement {
right: PIE_INSET,
top: PIE_INSET,
bottom: PIE_INSET,
minShowLabelAngle: MIN_SHOW_LABEL_ANGLE,
labelLayout: { hideOverlap: true },
label: {
show: Boolean(showLabels),
position: 'inner',
Expand Down
Loading