Skip to content

Commit

Permalink
[charts] Improve bar chart performances
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Aug 21, 2024
1 parent b217a27 commit 07038c4
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/x-charts/src/BarChart/BarPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const enterStyle = ({ x, width, y, height }: AnimationData) => ({
function BarPlot(props: BarPlotProps) {
const { completedData, masksData } = useAggregatedData();
const { skipAnimation, onItemClick, borderRadius, barLabel, ...other } = props;

const withoutBorderRadius = !borderRadius || borderRadius <= 0;

const transition = useTransition(completedData, {
keys: (bar) => `${bar.seriesId}-${bar.dataIndex}`,
from: leaveStyle,
Expand All @@ -233,7 +236,7 @@ function BarPlot(props: BarPlotProps) {
immediate: skipAnimation,
});

const maskTransition = useTransition(masksData, {
const maskTransition = useTransition(withoutBorderRadius ? [] : masksData, {
keys: (v) => v.id,
from: leaveStyle,
leave: leaveStyle,
Expand All @@ -244,18 +247,19 @@ function BarPlot(props: BarPlotProps) {

return (
<React.Fragment>
{maskTransition((style, { id, hasPositive, hasNegative, layout }) => {
return (
<BarClipPath
maskId={id}
borderRadius={borderRadius}
hasNegative={hasNegative}
hasPositive={hasPositive}
layout={layout}
style={style}
/>
);
})}
{!withoutBorderRadius &&
maskTransition((style, { id, hasPositive, hasNegative, layout }) => {
return (
<BarClipPath
maskId={id}
borderRadius={borderRadius}
hasNegative={hasNegative}
hasPositive={hasPositive}
layout={layout}
style={style}
/>
);
})}
{transition((style, { seriesId, dataIndex, color, maskId }) => {
const barElement = (
<BarElement
Expand All @@ -273,7 +277,7 @@ function BarPlot(props: BarPlotProps) {
/>
);

if (!borderRadius || borderRadius <= 0) {
if (withoutBorderRadius) {
return barElement;
}

Expand Down

0 comments on commit 07038c4

Please sign in to comment.