A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.
fix: match native Beszel chart colors and hover points (#7159)
Thomasba5afbe8b4b1
diff --git a/packages/widgets/src/beszel/_shared/chart.module.css b/packages/widgets/src/beszel/_shared/chart.module.cssnew file mode 100644index 000000000..f2aa70dc3--- /dev/null+++ b/packages/widgets/src/beszel/_shared/chart.module.css@@ -0,0 +1,83 @@+.chart {+ --mantine-scale: 1;+ --beszel-chart-saturation: 65%;+ --beszel-chart-lightness: 50%;+ --beszel-chart-background: hsl(30 0% 100%);+ --beszel-tooltip-background: hsl(30 8% 98%);+ --beszel-chart-foreground: hsl(30 0% 10%);+ --beszel-chart-muted: hsl(24 2.79% 35.1%);+ --beszel-chart-border: hsl(30 8.11% 85.49%);++ background: var(--beszel-chart-background);++ @mixin dark {+ --beszel-chart-saturation: 60%;+ --beszel-chart-lightness: 55%;+ --beszel-chart-background: hsl(220 5.5% 10.5%);+ --beszel-tooltip-background: hsl(220 5.5% 9%);+ --beszel-chart-foreground: hsl(220 2% 97%);+ --beszel-chart-muted: hsl(220 4% 67%);+ --beszel-chart-border: hsl(220 3% 17%);+ }+}++.tooltip {+ display: grid;+ gap: 6px;+ min-width: 112px;+ padding: 6px 10px;+ border: 1px solid color-mix(in srgb, var(--beszel-chart-border) 50%, transparent);+ border-radius: 12.8px;+ background: var(--beszel-tooltip-background);+ color: var(--beszel-chart-foreground);+ box-shadow:+ 0 20px 25px -5px rgb(0 0 0 / 0.1),+ 0 8px 10px -6px rgb(0 0 0 / 0.1);+ font-size: 12px;+ line-height: 18px;+ pointer-events: none;+}++.tooltipHeader,+.tooltipValue {+ font-weight: 500;+ white-space: nowrap;+}++.tooltipRows {+ display: grid;+ gap: 6px;+}++.tooltipRow {+ display: flex;+ align-items: center;+ gap: 8px;+ line-height: 12px;+}++.tooltipIndicator {+ width: 4px;+ align-self: stretch;+ border-radius: 2px;+ flex-shrink: 0;+}++.tooltipName {+ flex: 1;+ max-width: 160px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ color: var(--beszel-chart-muted);+}++.tooltipTotal {+ display: flex;+ gap: 8px;+ line-height: 12px;+ border-top: 1px solid var(--beszel-chart-border);+ margin-top: 2px;+ padding-top: 4px;+ padding-inline-start: 12px;+}diff --git a/packages/widgets/src/beszel/_shared/chart.tsx b/packages/widgets/src/beszel/_shared/chart.tsxindex b0f63c62e..75c9387ff 100644--- a/packages/widgets/src/beszel/_shared/chart.tsx+++ b/packages/widgets/src/beszel/_shared/chart.tsx@@ -9,6 +9,8 @@ import dayjs from "dayjs";import type { BeszelContainerStatsRecord, BeszelGPUData, BeszelSystemStatsRecord } from "@homarr/integrations/types";import { formatLocalizedDate } from "../../common/locale";+import { containerChartColor } from "./colors";+import classes from "./chart.module.css";export type BeszelTimePeriod = "1m" | "1h" | "12h" | "24h" | "1w" | "30d";@@ -90,11 +92,18 @@ export function padLiveTimeGrid(data: Record<string, unknown>[], pointCount = 60const yAxisBase = {tickMargin: 0,- tick: { fontSize: "var(--mantine-font-size-xs)" },+ tick: { fontSize: 12, fill: "var(--beszel-chart-muted)" },+} as const;+const chartStyle = {+ minWidth: 0,+ minHeight: 1,+ flexGrow: 1,+ flexShrink: 0,+ // Recharts measures pixels; keep points, axes and tooltips readable on a scaled board.+ zoom: "var(--board-canvas-inverse-scale, 1)",} as const;-const chartStyle = { minWidth: 0, minHeight: 1, flexGrow: 1, flexShrink: 0 } as const;const panelStyle = { minWidth: 0 } as const;-const chartMargin = { top: 0, right: 0, bottom: 0, left: 0 } as const;+const chartMargin = { top: 12, right: 5, bottom: 0, left: 0 } as const;export const CPU_Y_AXIS_DOMAIN: [number, string] = [0, "auto"];interface BeszelChartPanelProps {@@ -133,11 +142,14 @@ const BeszelAreaChart = memo(xAxisProps: xAxisPropsOverride,areaChartProps: areaChartPropsOverride,type = "default",+ fillOpacity = 0.4,...props}: BeszelAreaChartProps) => {const mergedXAxis = useMemo(() => ({interval: "preserveEnd" as const,+ minTickGap: 50,+ tick: { fontSize: 12, fill: "var(--beszel-chart-muted)" },...xAxisPropsOverride,}),[xAxisPropsOverride],@@ -158,14 +170,25 @@ const BeszelAreaChart = memo(return (<AreaChart+ // Recharts keeps registration order when keyed areas move; reset it when ranks change.+ key={JSON.stringify(props.series.map(({ name }) => name))}+ className={classes.chart}dataKey="time"curveType="monotone"withGradient={false}connectNulls={false}withDots={false}+ areaProps={({ color }) => ({+ fill: color,+ fillOpacity,+ activeDot: { r: 4, fill: color, stroke: "transparent", strokeWidth: 2 },+ })}type={type}strokeWidth={1}- fillOpacity={0.2}+ fillOpacity={fillOpacity}+ strokeDasharray="0"+ gridColor="color-mix(in srgb, var(--beszel-chart-border) 50%, transparent)"+ textColor="var(--beszel-chart-muted)"withXAxis={withXAxis}withYAxisw="100%"@@ -196,7 +219,7 @@ export const useSystemChartData = (return padTimeGrid(mapped, timePeriod, locale);}, [systemStats, mapFn, timePeriod, locale]);-export const useContainerNames = (containerStats: BeszelContainerStatsRecord[] | undefined, max = 15) => {+export const useContainerNames = (containerStats: BeszelContainerStatsRecord[] | undefined) => {const prevRef = useRef<string[]>([]);return useMemo(() => {if (!containerStats?.length) {@@ -205,17 +228,18 @@ export const useContainerNames = (containerStats: BeszelContainerStatsRecord[] |return prevRef.current;}const names = new Set<string>();- for (const record of containerStats) {+ // Native processes history chronologically; first appearance breaks equal-usage ties.+ for (const record of containerStats.toSorted((a, b) => a.created.localeCompare(b.created))) {for (const c of record.stats) {names.add(c.n);}}- const next = [...names].slice(0, max);+ const next = [...names];const prev = prevRef.current;if (prev.length === next.length && prev.every((n, i) => n === next[i])) return prev;prevRef.current = next;return next;- }, [containerStats, max]);+ }, [containerStats]);};type ContainerExtractor = (container: BeszelContainerStatsRecord["stats"][number] | undefined) => number;@@ -229,12 +253,30 @@ export const normalizeBeszelByteRate = (legacyMebibytesPerSecond: number | undefined,): number => bytesPerSecond ?? (legacyMebibytesPerSecond ?? 0) * MEBIBYTE;-const defaultContainerExtractors: Record<string, ContainerExtractor> = {+const defaultContainerExtractors: Record<"cpu" | "memory" | "network", ContainerExtractor> = {cpu: (c) => c?.c ?? 0,- memory: (c) => (c?.m ?? 0) * MEBIBYTE,+ memory: (c) => c?.m ?? 0,network: (c) => normalizeBeszelByteRate(c?.b?.[0], c?.ns) + normalizeBeszelByteRate(c?.b?.[1], c?.nr),};+export const useContainerSeries = (+ records: BeszelContainerStatsRecord[] | undefined,+ names: string[],+ metric: "cpu" | "memory" | "network",+) =>+ useMemo(() => {+ const totals = new Map(names.map((name) => [name, 0]));+ const extract = defaultContainerExtractors[metric];+ for (const record of records ?? []) {+ for (const container of record.stats) {+ totals.set(container.n, (totals.get(container.n) ?? 0) + extract(container));+ }+ }+ return [...totals]+ .toSorted(([, a], [, b]) => b - a)+ .map(([name], rank) => ({ name, color: containerChartColor(rank, totals.size) }));+ }, [records, names, metric]);+export const useDiskChartData = (systemStats: BeszelSystemStatsRecord[] | undefined,efsPaths: string[],@@ -318,7 +360,9 @@ export const useDockerChartData = (const point: Record<string, unknown> = { time: fmt(record.created), rawTime: record.created };const byName = new Map(record.stats.map((c) => [c.n, c]));for (const name of containerNames) {- point[name] = extract(byName.get(name));+ const container = byName.get(name);+ point[name] = null;+ if (container) point[name] = extract(container);}return point;});diff --git a/packages/widgets/src/beszel/_shared/colors.ts b/packages/widgets/src/beszel/_shared/colors.tsindex 22e1e663b..4c5e72ad9 100644--- a/packages/widgets/src/beszel/_shared/colors.ts+++ b/packages/widgets/src/beszel/_shared/colors.ts@@ -20,17 +20,15 @@ export const statusColorMap: Record<BeszelSystemStatus, string> = {pending: "yellow",};-export const containerColors = [- "red.6",- "orange.6",- "yellow.6",- "lime.6",- "green.6",- "teal.6",- "cyan.6",- "blue.6",- "indigo.6",- "violet.6",- "grape.6",- "pink.6",-];+// Beszel 0.21.0 (ec96c134), internal/site/src/index.css and components/charts/hooks.ts.+export const beszelChartColors = {+ cpu: "hsl(220 70% 50%)",+ memory: "hsl(160 60% 45%)",+ cache: "hsl(160 60% 45% / 0.5)",+ disk: "hsl(280 65% 60%)",+ write: "hsl(30 80% 55%)",+ sent: "hsl(340 75% 55%)",+};++export const containerChartColor = (rank: number, count: number) =>+ `hsl(${(rank * 360) / count} var(--beszel-chart-saturation) var(--beszel-chart-lightness))`;diff --git a/packages/widgets/src/beszel/_shared/format.ts b/packages/widgets/src/beszel/_shared/format.tsindex e792a74cd..897cc2860 100644--- a/packages/widgets/src/beszel/_shared/format.ts+++ b/packages/widgets/src/beszel/_shared/format.ts@@ -22,6 +22,36 @@ export const formatPercent = (value: number): string => `${value.toFixed(1)}%`;export const formatWatts = (value: number): string => `${value.toFixed(1)} W`;+// Native Beszel uses binary byte divisors with B/KB/MB/GB labels and two tooltip decimals.+// Keep this contract local to its charts; dashboard-wide byte preferences remain independent.+export const createBeszelChartFormatters = (locale: string) => {+ const decimal = new Intl.NumberFormat(locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 });+ const compact = new Intl.NumberFormat(locale, { maximumFractionDigits: 1 });+ const units = ["B", "KB", "MB", "GB", "TB"];+ const bytes = (value: number, axis = false) => {+ let unit = 0;+ if (value >= 100) unit = 1;+ while (unit < units.length - 1 && value >= 1000 * 1024 ** unit) unit++;+ const scaled = value / 1024 ** unit;+ if (axis) {+ let rounded = scaled;+ if (scaled >= 10) rounded = Math.round(scaled);+ return `${compact.format(rounded)} ${units[unit]}`;+ }+ return `${decimal.format(scaled)} ${units[unit]}`;+ };+ return {+ bytes: (value: number) => bytes(value),+ bytesAxis: (value: number) => bytes(value, true),+ memory: (mebibytes: number) => bytes(mebibytes * 1024 ** 2),+ memoryAxis: (mebibytes: number) => bytes(mebibytes * 1024 ** 2, true),+ rate: (value: number) => `${bytes(value)}/s`,+ rateAxis: (value: number) => `${bytes(value, true)}/s`,+ percent: (value: number) => `${decimal.format(value)}%`,+ watts: (value: number) => `${decimal.format(value)}W`,+ };+};+export const getProgressTrackSize = (size: "xs" | "sm"): number => (size === "xs" ? 6 : 9);export const formatUptime = (seconds: number): string => dayjs.duration(seconds, "seconds").humanize();diff --git a/packages/widgets/src/beszel/_shared/stats-view.tsx b/packages/widgets/src/beszel/_shared/stats-view.tsxindex 1c761e808..a82d3c488 100644--- a/packages/widgets/src/beszel/_shared/stats-view.tsx+++ b/packages/widgets/src/beszel/_shared/stats-view.tsx@@ -7,13 +7,12 @@ import { IconPlugConnectedX, IconServerOff } from "@tabler/icons-react";import { clientApi } from "@homarr/api/client";import { invariantTechnicalLabels } from "@homarr/definitions";import type { BeszelContainerStatsRecord, BeszelSystemStatsRecord } from "@homarr/integrations/types";-import { useByteFormatter } from "@homarr/settings";import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";import { zoomCompensatedSize } from "@homarr/ui";import { getUsableWidgetQueryData } from "../../common/query-state";import { WidgetQueryLoadingState } from "../../common/query-state-indicator";-import { containerColors } from "./colors";+import { beszelChartColors } from "./colors";import type { BeszelTimePeriod } from "./chart";import {BeszelChartPanel,@@ -21,6 +20,7 @@ import {hasGpuMetric,normalizeBeszelByteRate,useContainerNames,+ useContainerSeries,useDiskChartData,useDiskIOChartData,useDockerChartData,@@ -28,7 +28,7 @@ import {useGpuDevices,useSystemChartData,} from "./chart";-import { createByteChartAxisFormatters, formatPercent, formatWatts } from "./format";+import { createBeszelChartFormatters, formatPercent } from "./format";import { makeTooltipProps } from "./tooltip";import { useLiveStats } from "./use-live-stats";import { useDemoReadOnly } from "../../demo-read-only";@@ -77,21 +77,17 @@ export function BeszelStatsView({const t = useI18n("widget.beszelSystemStats");const tBeszel = useI18n("widget.beszel");const locale = useCurrentIntlLocale();- const { formatByteRate, formatBytes } = useByteFormatter();- const byteAxisFormatters = useMemo(- () => createByteChartAxisFormatters(formatBytes, formatByteRate),- [formatByteRate, formatBytes],- );+ const formatters = useMemo(() => createBeszelChartFormatters(locale), [locale]);const tooltips = useMemo(() => ({- percent: makeTooltipProps(formatPercent),- bytes: makeTooltipProps(formatBytes, true),- rate: makeTooltipProps(formatByteRate, true),- percentTotal: makeTooltipProps(formatPercent, true),- bytesTotal: makeTooltipProps(formatBytes, true),- watts: makeTooltipProps(formatWatts),+ percent: makeTooltipProps(formatters.percent),+ bytes: makeTooltipProps(formatters.bytes, true),+ rate: makeTooltipProps(formatters.rate, true),+ percentTotal: makeTooltipProps(formatters.percent, true),+ memory: makeTooltipProps(formatters.memory, true),+ watts: makeTooltipProps(formatters.watts),}),- [formatByteRate, formatBytes],+ [formatters],);const showDocker = visibility.dockerCpu || visibility.dockerMemory || visibility.dockerNetwork;const isLive = timePeriod === "1m";@@ -125,14 +121,14 @@ export function BeszelStatsView({const series = useMemo(() => ({- cpu: [{ name: invariantTechnicalLabels.cpu, color: "teal.6" }],+ cpu: [{ name: invariantTechnicalLabels.cpu, color: beszelChartColors.cpu }],memory: [- { name: t("chart.memory.series"), color: "teal.5" },- { name: t("chart.memory.cache"), color: "teal.8" },+ { name: t("chart.memory.series"), color: beszelChartColors.memory },+ { name: t("chart.memory.cache"), color: beszelChartColors.cache },],network: [- { name: t("chart.network.sent"), color: "blue.6" },- { name: t("chart.network.recv"), color: "teal.6" },+ { name: t("chart.network.sent"), color: beszelChartColors.sent },+ { name: t("chart.network.recv"), color: beszelChartColors.memory },],}),[t],@@ -157,14 +153,28 @@ export function BeszelStatsView({const gpuDevices = useGpuDevices(whenVisible(visibility.gpuUsage || visibility.gpuMemory || visibility.gpuPower, systemStats),);- const gpuSeries = useMemo(- () =>- gpuDevices.map((device, index) => ({- name: device.seriesName,- color: containerColors[index % containerColors.length] as string,- })),+ const gpuUsageSeries = useMemo(+ () => gpuDevices.map((device) => ({ name: device.seriesName, color: beszelChartColors.cpu })),+ [gpuDevices],+ );+ const gpuMemorySeries = useMemo(+ () => gpuDevices.map((device) => ({ name: device.seriesName, color: beszelChartColors.memory })),[gpuDevices],);+ const gpuPowerSeries = useMemo(() => {+ const totals = new Map(gpuDevices.map((device) => [device.id, 0]));+ for (const record of systemStats ?? []) {+ for (const [id, device] of Object.entries(record.stats.g ?? {})) {+ totals.set(id, (totals.get(id) ?? 0) + (device.p ?? 0));+ }+ }+ return gpuDevices+ .toSorted((a, b) => (totals.get(b.id) ?? 0) - (totals.get(a.id) ?? 0))+ .map((device, index) => ({+ name: device.seriesName,+ color: `hsl(${226 + (index * 360) / gpuDevices.length} 65% 52%)`,+ }));+ }, [gpuDevices, systemStats]);const gpuUsageData = useGpuChartData(whenVisible(visibility.gpuUsage, systemStats),gpuDevices,@@ -220,26 +230,26 @@ export function BeszelStatsView({);const diskSeries = useMemo(() => [- { name: rootSeriesName, color: "grape.6" },- ...efsPaths.map((path, index) => ({+ { name: rootSeriesName, color: beszelChartColors.disk },+ ...efsPaths.map((path) => ({name: path,- color: containerColors[(index + 1) % containerColors.length] as string,+ color: beszelChartColors.disk,})),],[efsPaths, rootSeriesName],);const diskIOSeries = useMemo(() => [- { name: rootWriteSeriesName, color: "orange.6" },- { name: rootReadSeriesName, color: "blue.6" },- ...efsPaths.flatMap((path, index) => [+ { name: rootWriteSeriesName, color: beszelChartColors.write },+ { name: rootReadSeriesName, color: beszelChartColors.cpu },+ ...efsPaths.flatMap((path) => [{name: `${path} ${writeLabel}`,- color: containerColors[(index * 2 + 2) % containerColors.length] as string,+ color: beszelChartColors.write,},{name: `${path} ${readLabel}`,- color: containerColors[(index * 2 + 3) % containerColors.length] as string,+ color: beszelChartColors.cpu,},]),],@@ -247,11 +257,9 @@ export function BeszelStatsView({);const containerNames = useContainerNames(whenVisible(showDocker, containerStats));- const containerSeries = useMemo(- () =>- containerNames.map((name, index) => ({ name, color: containerColors[index % containerColors.length] as string })),- [containerNames],- );+ const containerCpuSeries = useContainerSeries(containerStats, containerNames, "cpu");+ const containerMemorySeries = useContainerSeries(containerStats, containerNames, "memory");+ const containerNetworkSeries = useContainerSeries(containerStats, containerNames, "network");const dockerCpuData = useDockerChartData(whenVisible(visibility.dockerCpu, containerStats),containerNames,@@ -315,10 +323,10 @@ export function BeszelStatsView({(visibility.disk && diskData.length > 0 ? 1 : 0) +(visibility.diskIO && diskIOData.length > 0 ? 1 : 0) +(visibility.network && networkData.length > 0 ? 1 : 0) +- (visibility.gpuUsage && gpuSeries.length > 0 && gpuUsageData.length > 0 ? 1 : 0) ++ (visibility.gpuUsage && gpuDevices.length > 0 && gpuUsageData.length > 0 ? 1 : 0) +(visibility.gpuMemory && hasGpuMemory && gpuMemoryData.length > 0 ? 1 : 0) +(visibility.gpuPower && hasGpuPower && gpuPowerData.length > 0 ? 1 : 0) +- (showDocker && containerSeries.length > 0+ (showDocker && containerNames.length > 0? (visibility.dockerCpu && dockerCpuData.length > 0 ? 1 : 0) +(visibility.dockerMemory && dockerMemoryData.length > 0 ? 1 : 0) +(visibility.dockerNetwork && dockerNetworkData.length > 0 ? 1 : 0)@@ -354,7 +362,7 @@ export function BeszelStatsView({data: memoryData,type: "stacked",series: series.memory,- yAxisFormatter: byteAxisFormatters.bytes,+ yAxisFormatter: formatters.bytesAxis,tooltipProps: tooltips.bytes,}}/>@@ -369,7 +377,7 @@ export function BeszelStatsView({data: diskData,type: "stacked",series: diskSeries,- yAxisFormatter: byteAxisFormatters.bytes,+ yAxisFormatter: formatters.bytesAxis,tooltipProps: tooltips.bytes,}}/>@@ -383,7 +391,8 @@ export function BeszelStatsView({withXAxis: showXAxis,data: diskIOData,series: diskIOSeries,- yAxisFormatter: byteAxisFormatters.rate,+ fillOpacity: 0.3,+ yAxisFormatter: formatters.rateAxis,tooltipProps: tooltips.rate,}}/>@@ -397,12 +406,13 @@ export function BeszelStatsView({withXAxis: showXAxis,data: networkData,series: series.network,- yAxisFormatter: byteAxisFormatters.rate,+ fillOpacity: 0.2,+ yAxisFormatter: formatters.rateAxis,tooltipProps: tooltips.rate,}}/>)}- {gpuSeries.length > 0 && (+ {gpuDevices.length > 0 && (<>{visibility.gpuUsage && gpuUsageData.length > 0 && (<BeszelChartPanel@@ -412,7 +422,8 @@ export function BeszelStatsView({h: CHART_HEIGHT,withXAxis: showXAxis,data: gpuUsageData,- series: gpuSeries,+ series: gpuUsageSeries,+ fillOpacity: 0.35,yAxisFormatter: formatPercent,yAxisDomain: CPU_Y_AXIS_DOMAIN,tooltipProps: tooltips.percent,@@ -427,9 +438,10 @@ export function BeszelStatsView({h: CHART_HEIGHT,withXAxis: showXAxis,data: gpuMemoryData,- series: gpuSeries,- yAxisFormatter: byteAxisFormatters.bytes,- tooltipProps: tooltips.bytesTotal,+ series: gpuMemorySeries,+ fillOpacity: 0.25,+ yAxisFormatter: formatters.bytesAxis,+ tooltipProps: tooltips.bytes,}}/>)}@@ -441,15 +453,16 @@ export function BeszelStatsView({h: CHART_HEIGHT,withXAxis: showXAxis,data: gpuPowerData,- series: gpuSeries,- yAxisFormatter: formatWatts,+ series: gpuPowerSeries,+ fillOpacity: 0,+ yAxisFormatter: formatters.watts,tooltipProps: tooltips.watts,}}/>)}</>)}- {showDocker && containerSeries.length > 0 && (+ {showDocker && containerNames.length > 0 && (<>{visibility.dockerCpu && dockerCpuData.length > 0 && (<BeszelChartPanel@@ -460,7 +473,8 @@ export function BeszelStatsView({withXAxis: showXAxis,data: dockerCpuData,type: "stacked",- series: containerSeries,+ series: containerCpuSeries,+ areaChartProps: { reverseStackOrder: true },yAxisFormatter: formatPercent,tooltipProps: tooltips.percentTotal,}}@@ -475,9 +489,10 @@ export function BeszelStatsView({withXAxis: showXAxis,data: dockerMemoryData,type: "stacked",- series: containerSeries,- yAxisFormatter: byteAxisFormatters.bytes,- tooltipProps: tooltips.bytesTotal,+ series: containerMemorySeries,+ areaChartProps: { reverseStackOrder: true },+ yAxisFormatter: formatters.memoryAxis,+ tooltipProps: tooltips.memory,}}/>)}@@ -489,8 +504,10 @@ export function BeszelStatsView({h: CHART_HEIGHT,withXAxis: showXAxis,data: dockerNetworkData,- series: containerSeries,- yAxisFormatter: byteAxisFormatters.rate,+ series: containerNetworkSeries,+ type: "stacked",+ areaChartProps: { reverseStackOrder: true },+ yAxisFormatter: formatters.rateAxis,tooltipProps: tooltips.rate,}}/>diff --git a/packages/widgets/src/beszel/_shared/tooltip.tsx b/packages/widgets/src/beszel/_shared/tooltip.tsxindex 8e420fca6..185aa38e6 100644--- a/packages/widgets/src/beszel/_shared/tooltip.tsx+++ b/packages/widgets/src/beszel/_shared/tooltip.tsx@@ -1,40 +1,11 @@"use client";-import type { CSSProperties } from "react";+import type { TooltipContentProps } from "recharts";+import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";import { formatLocalizedDate } from "../../common/locale";--const styles: Record<string, CSSProperties> = {- wrapper: {- background: "var(--mantine-color-dark-7)",- border: "1px solid var(--mantine-color-dark-4)",- borderRadius: 6,- padding: "6px 10px",- fontSize: "var(--mantine-font-size-xs)",- lineHeight: 1.5,- pointerEvents: "none",- overflowX: "hidden",- },- header: { marginBottom: 4, fontWeight: 550, color: "var(--mantine-color-gray-2)" },- row: { display: "flex", alignItems: "center", gap: 6, padding: "1px 0" },- indicator: { width: 5, height: 14, borderRadius: 5, flexShrink: 0 },- name: {- flex: 1,- color: "var(--mantine-color-gray-3)",- whiteSpace: "nowrap",- overflow: "hidden",- textOverflow: "ellipsis",- maxWidth: 140,- },- value: {- fontWeight: 700,- color: "var(--mantine-color-gray-1)",- whiteSpace: "nowrap",- fontVariantNumeric: "tabular-nums",- },- separator: { borderTop: "1px solid var(--mantine-color-dark-4)", marginTop: 3, paddingTop: 3 },-};+import classes from "./chart.module.css";export interface TooltipPayloadItem {name: string;@@ -47,7 +18,7 @@ export interface TooltipPayloadItem {interface BeszelTooltipProps {active?: boolean;label?: string;- payload?: TooltipPayloadItem[];+ payload?: TooltipContentProps<number, string>["payload"];formatter: (value: number) => string;showTotal?: boolean;}@@ -55,54 +26,69 @@ interface BeszelTooltipProps {const BeszelTooltipContent = ({ active, label, payload, formatter, showTotal }: BeszelTooltipProps) => {const locale = useCurrentIntlLocale();const t = useI18n("common");- const isActive = active && (payload?.length ?? 0) > 0;- if (!isActive) return null;+ if (!active || !payload?.length) return null;const deduped = new Map<string, TooltipPayloadItem>();- for (const item of (payload ?? []).filter((entry) => entry.value > 0)) {- if (!deduped.has(item.dataKey)) deduped.set(item.dataKey, item);+ for (const item of payload) {+ if (typeof item.value !== "number" || !Number.isFinite(item.value) || typeof item.dataKey !== "string") continue;+ if (!deduped.has(item.dataKey)) {+ deduped.set(item.dataKey, {+ name: String(item.name ?? item.dataKey),+ value: item.value,+ color: item.color ?? "currentColor",+ dataKey: item.dataKey,+ payload: item.payload,+ });+ }}const sorted = [...deduped.values()].toSorted((a, b) => b.value - a.value);-if (!sorted.length) return null;- const rawTime = sorted[0]?.payload?.rawTime as string | undefined;- const tooltipLabel = rawTime- ? formatLocalizedDate(rawTime, locale, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" })- : label;- const total = sorted.reduce((sum, p) => sum + p.value, 0);+ const rawTime = sorted[0]?.payload?.rawTime;+ let tooltipLabel = label;+ if (typeof rawTime === "string") {+ tooltipLabel = formatLocalizedDate(rawTime, locale, {+ month: "short",+ day: "numeric",+ hour: "numeric",+ minute: "2-digit",+ });+ }+ const total = sorted.reduce((sum, item) => sum + item.value, 0);return (- <div style={styles.wrapper}>- <div style={styles.header}>{tooltipLabel}</div>- {sorted.map((item) => (- <div key={item.dataKey} style={styles.row}>- <div style={{ ...styles.indicator, background: item.color }} />- <span style={styles.name}>{item.name}</span>- <span style={styles.value}>{formatter(item.value)}</span>- </div>- ))}- {showTotal && sorted.length > 1 && (- <div style={{ ...styles.row, ...styles.separator }}>- <span style={styles.name}>{t("total")}</span>- <span style={styles.value}>{formatter(total)}</span>- </div>- )}+ <div className={classes.tooltip}>+ <div className={classes.tooltipHeader}>{tooltipLabel}</div>+ <div className={classes.tooltipRows}>+ {sorted.map((item) => (+ <div key={item.dataKey} className={classes.tooltipRow}>+ <div className={classes.tooltipIndicator} style={{ background: item.color }} />+ <span className={classes.tooltipName}>{item.name}</span>+ <span className={classes.tooltipValue}>{formatter(item.value)}</span>+ </div>+ ))}+ {showTotal && (+ <div className={classes.tooltipTotal}>+ <span className={classes.tooltipName}>{t("total")}</span>+ <span className={classes.tooltipValue}>{formatter(total)}</span>+ </div>+ )}+ </div></div>);};-// eslint-disable-next-line @typescript-eslint/no-explicit-any-export const makeTooltipProps = (formatter: (v: number) => string, showTotal = false) => ({- content: (props: any) => (+export const makeTooltipProps = (formatter: (value: number) => string, showTotal = false) => ({+ content: (props: TooltipContentProps<number, string>) => (<BeszelTooltipContentactive={props.active}- label={props.label != null ? String(props.label) : undefined}+ label={props.label?.toString()}payload={props.payload}formatter={formatter}showTotal={showTotal}/>),- wrapperStyle: { pointerEvents: "none" as const },+ cursor: { stroke: "var(--beszel-chart-border)", strokeWidth: 1, strokeDasharray: "0" },+ wrapperStyle: { pointerEvents: "none" as const, zIndex: 3 },isAnimationActive: false,});