mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
lazy load charts and disable chart animations
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from 'recharts'
|
||||
|
||||
import { ChartContainer, ChartTooltip, ChartTooltipContent } from '@/components/ui/chart'
|
||||
import { chartTimeData, formatShortDate, useYaxisWidth } from '@/lib/utils'
|
||||
import { chartTimeData, cn, formatShortDate, useYaxisWidth } from '@/lib/utils'
|
||||
import { useMemo, useRef } from 'react'
|
||||
import Spinner from '../spinner'
|
||||
// import Spinner from '../spinner'
|
||||
import { useStore } from '@nanostores/react'
|
||||
import { $chartTime } from '@/lib/stores'
|
||||
import { SystemStatsRecord } from '@/types'
|
||||
@@ -19,18 +19,26 @@ export default function MemChart({
|
||||
const chartRef = useRef<HTMLDivElement>(null)
|
||||
const yAxisWidth = useYaxisWidth(chartRef)
|
||||
|
||||
const yAxisSet = useMemo(() => yAxisWidth !== 180, [yAxisWidth])
|
||||
|
||||
const totalMem = useMemo(() => {
|
||||
const maxMem = Math.ceil(systemData[0]?.stats.m)
|
||||
return maxMem > 2 && maxMem % 2 !== 0 ? maxMem + 1 : maxMem
|
||||
}, [systemData])
|
||||
|
||||
if (!systemData.length || !ticks.length) {
|
||||
return <Spinner />
|
||||
}
|
||||
// if (!systemData.length || !ticks.length) {
|
||||
// return <Spinner />
|
||||
// }
|
||||
|
||||
return (
|
||||
<div ref={chartRef}>
|
||||
<ChartContainer config={{}} className="h-full w-full absolute aspect-auto">
|
||||
{/* {!yAxisSet && <Spinner />} */}
|
||||
<ChartContainer
|
||||
config={{}}
|
||||
className={cn('h-full w-full absolute aspect-auto bg-card opacity-0 transition-opacity', {
|
||||
'opacity-100': yAxisSet,
|
||||
})}
|
||||
>
|
||||
<AreaChart
|
||||
accessibilityLayer
|
||||
data={systemData}
|
||||
@@ -80,7 +88,8 @@ export default function MemChart({
|
||||
fillOpacity={0.4}
|
||||
stroke="hsl(var(--chart-2))"
|
||||
stackId="a"
|
||||
animationDuration={1200}
|
||||
// animationDuration={1200}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
<Area
|
||||
dataKey="stats.mb"
|
||||
@@ -91,7 +100,8 @@ export default function MemChart({
|
||||
strokeOpacity={0.3}
|
||||
stroke="hsl(var(--chart-2))"
|
||||
stackId="a"
|
||||
animationDuration={1200}
|
||||
// animationDuration={1200}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
|
Reference in New Issue
Block a user