/* eslint-disable @typescript-eslint/no-explicit-any */ import type { ReactNode } from "react"; import type { AreaChartSeries } from "@mantine/charts"; import { AreaChart, LineChart } from "@mantine/charts"; import { Card, Center, Group, Stack, Text, useMantineTheme } from "@mantine/core"; import { useElementSize, useHover, useMergedRef } from "@mantine/hooks"; import type { TooltipProps, YAxisProps } from "recharts"; import { useRequiredBoard } from "@homarr/boards/context"; import { zoomCompensatedSize } from "@homarr/ui"; import type { TablerIcon } from "@homarr/ui"; import type { LabelDisplayModeOption } from ".."; export const CommonChart = ({ data, dataKey, series, title, icon: Icon, labelDisplayMode, tooltipProps, yAxisProps, lastValue, chartType = "line", }: { data: Record[]; dataKey: string; series: AreaChartSeries[]; title: ReactNode; icon: TablerIcon; labelDisplayMode: LabelDisplayModeOption; tooltipProps?: TooltipProps; yAxisProps?: Omit; lastValue?: string; chartType?: "line" | "area"; }) => { const { ref: elementSizeRef, height } = useElementSize(); const theme = useMantineTheme(); const board = useRequiredBoard(); const { hovered, ref: hoverRef } = useHover(); const ref = useMergedRef(elementSizeRef, hoverRef); const backgroundColor = "rgb(from var(--mantine-color-primaryColor-filled) r g b / calc(var(--opacity, 1) * 0.12))"; const borderColor = "rgb(from var(--mantine-color-secondaryColor-filled) r g b / calc(var(--opacity, 1) * 0.45))"; const ChartComponent = chartType === "line" ? LineChart : AreaChart; const showIcon = labelDisplayMode === "icon" || labelDisplayMode === "textWithIcon"; const showText = labelDisplayMode === "text" || labelDisplayMode === "textWithIcon"; return ( {data.length > 1 && height > 40 && !hovered && ( {showIcon && 100 ? 20 : 14)} stroke={1.5} />} {showText && ( 100 ? "md" : "xs"} fw={"bold"}> {title} )} {lastValue && ( 100 ? "md" : "xs"} lineClamp={1}> {lastValue} )} )} {data.length > 1 && height > 0 && height <= 40 && lastValue && !hovered && (
{lastValue}
)} {data.length <= 1 ? (
{showIcon && 100 ? 20 : 14)} stroke={1.5} />} {showText && ( 100 ? "md" : "xs"} fw={"bold"} ta="center"> {title} )} {lastValue && ( 100 ? "md" : "xs"} fw={600} ta="center"> {lastValue} )}
) : ( = 64} yAxisProps={yAxisProps} fillOpacity={chartType === "area" ? 0.3 : undefined} /> )}
); };