mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PlotLegend: Memoize for better performance (#56123)
This commit is contained in:
parent
08ffcfdf16
commit
e819ed0f51
@ -9,8 +9,8 @@ export interface Props extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
gradient?: string;
|
gradient?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SeriesIcon = React.forwardRef<HTMLDivElement, Props>(
|
export const SeriesIcon = React.memo(
|
||||||
({ color, className, gradient, ...restProps }, ref) => {
|
React.forwardRef<HTMLDivElement, Props>(({ color, className, gradient, ...restProps }, ref) => {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
let cssColor: string;
|
let cssColor: string;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export const SeriesIcon = React.forwardRef<HTMLDivElement, Props>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
return <div data-testid="series-icon" ref={ref} className={className} style={styles} {...restProps} />;
|
return <div data-testid="series-icon" ref={ref} className={className} style={styles} {...restProps} />;
|
||||||
}
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
SeriesIcon.displayName = 'SeriesIcon';
|
SeriesIcon.displayName = 'SeriesIcon';
|
||||||
|
@ -110,4 +110,4 @@ export function VizLegend<T>({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VizLegend.displayName = 'Legend';
|
VizLegend.displayName = 'VizLegend';
|
||||||
|
@ -15,7 +15,7 @@ interface Props {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const VizLegendSeriesIcon: React.FunctionComponent<Props> = ({ seriesName, color, gradient, readonly }) => {
|
export const VizLegendSeriesIcon = React.memo(({ seriesName, color, gradient, readonly }: Props) => {
|
||||||
const { onSeriesColorChange } = usePanelContext();
|
const { onSeriesColorChange } = usePanelContext();
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(color: string) => {
|
(color: string) => {
|
||||||
@ -40,6 +40,6 @@ export const VizLegendSeriesIcon: React.FunctionComponent<Props> = ({ seriesName
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <SeriesIcon color={color} gradient={gradient} />;
|
return <SeriesIcon color={color} gradient={gradient} />;
|
||||||
};
|
});
|
||||||
|
|
||||||
VizLegendSeriesIcon.displayName = 'VizLegendSeriesIcon';
|
VizLegendSeriesIcon.displayName = 'VizLegendSeriesIcon';
|
||||||
|
@ -27,14 +27,8 @@ interface PlotLegendProps extends VizLegendOptions, Omit<VizLayoutLegendProps, '
|
|||||||
config: UPlotConfigBuilder;
|
config: UPlotConfigBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PlotLegend: React.FC<PlotLegendProps> = ({
|
export const PlotLegend: React.FC<PlotLegendProps> = React.memo(
|
||||||
data,
|
({ data, config, placement, calcs, displayMode, ...vizLayoutLegendProps }) => {
|
||||||
config,
|
|
||||||
placement,
|
|
||||||
calcs,
|
|
||||||
displayMode,
|
|
||||||
...vizLayoutLegendProps
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
const legendItems = config
|
const legendItems = config
|
||||||
.getSeries()
|
.getSeries()
|
||||||
@ -136,6 +130,7 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
|
|||||||
/>
|
/>
|
||||||
</VizLayout.Legend>
|
</VizLayout.Legend>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
PlotLegend.displayName = 'PlotLegend';
|
PlotLegend.displayName = 'PlotLegend';
|
||||||
|
Loading…
Reference in New Issue
Block a user