mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 02:36:17 +01:00
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
import { Area, AreaChart, CartesianGrid, YAxis } from "recharts"
|
|
|
|
import { ChartContainer, ChartTooltip, ChartTooltipContent, xAxis } from "@/components/ui/chart"
|
|
import {
|
|
useYAxisWidth,
|
|
cn,
|
|
formatShortDate,
|
|
toFixedWithoutTrailingZeros,
|
|
decimalString,
|
|
chartMargin,
|
|
} from "@/lib/utils"
|
|
import { ChartData } from "@/types"
|
|
import { memo } from "react"
|
|
import { useTranslation } from "react-i18next"
|
|
|
|
export default memo(function SwapChart({ chartData }: { chartData: ChartData }) {
|
|
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
|
|
const { t } = useTranslation()
|
|
|
|
if (chartData.systemStats.length === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<ChartContainer
|
|
className={cn("h-full w-full absolute aspect-auto bg-card opacity-0 transition-opacity", {
|
|
"opacity-100": yAxisWidth,
|
|
})}
|
|
>
|
|
<AreaChart accessibilityLayer data={chartData.systemStats} margin={chartMargin}>
|
|
<CartesianGrid vertical={false} />
|
|
<YAxis
|
|
className="tracking-tighter"
|
|
domain={[0, () => toFixedWithoutTrailingZeros(chartData.systemStats.at(-1)?.stats.s ?? 0.04, 2)]}
|
|
width={yAxisWidth}
|
|
tickLine={false}
|
|
axisLine={false}
|
|
tickFormatter={(value) => updateYAxisWidth(value + " GB")}
|
|
/>
|
|
{xAxis(chartData)}
|
|
<ChartTooltip
|
|
animationEasing="ease-out"
|
|
animationDuration={150}
|
|
content={
|
|
<ChartTooltipContent
|
|
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
|
|
contentFormatter={(item) => decimalString(item.value) + " GB"}
|
|
// indicator="line"
|
|
/>
|
|
}
|
|
/>
|
|
<Area
|
|
dataKey="stats.su"
|
|
name={t("monitor.used")}
|
|
type="monotoneX"
|
|
fill="hsl(var(--chart-2))"
|
|
fillOpacity={0.4}
|
|
stroke="hsl(var(--chart-2))"
|
|
isAnimationActive={false}
|
|
/>
|
|
</AreaChart>
|
|
</ChartContainer>
|
|
</div>
|
|
)
|
|
})
|