mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 18:45:36 +01:00
fix: skip realtime chart animation when data unchanged
This commit is contained in:
parent
a19b92a5cb
commit
f5b5f159ec
1 changed files with 11 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ export function RealtimeChart({ data, unit, ...props }: RealtimeChartProps) {
|
||||||
const endDate = startOfMinute(new Date());
|
const endDate = startOfMinute(new Date());
|
||||||
const startDate = subMinutes(endDate, REALTIME_RANGE);
|
const startDate = subMinutes(endDate, REALTIME_RANGE);
|
||||||
const prevEndDate = useRef(endDate);
|
const prevEndDate = useRef(endDate);
|
||||||
|
const prevData = useRef<string | null>(null);
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
@ -28,14 +29,22 @@ export function RealtimeChart({ data, unit, ...props }: RealtimeChartProps) {
|
||||||
};
|
};
|
||||||
}, [data, startDate, endDate, unit]);
|
}, [data, startDate, endDate, unit]);
|
||||||
|
|
||||||
// Don't animate the bars shifting over because it looks weird
|
|
||||||
const animationDuration = useMemo(() => {
|
const animationDuration = useMemo(() => {
|
||||||
|
// Don't animate the bars shifting over because it looks weird
|
||||||
if (isBefore(prevEndDate.current, endDate)) {
|
if (isBefore(prevEndDate.current, endDate)) {
|
||||||
prevEndDate.current = endDate;
|
prevEndDate.current = endDate;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't animate when data hasn't changed
|
||||||
|
const serialized = JSON.stringify(chartData);
|
||||||
|
if (prevData.current === serialized) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
prevData.current = serialized;
|
||||||
|
|
||||||
return DEFAULT_ANIMATION_DURATION;
|
return DEFAULT_ANIMATION_DURATION;
|
||||||
}, [endDate]);
|
}, [endDate, chartData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageviewsChart
|
<PageviewsChart
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue