Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/dashboard/DashboardMonthlySeriesChart.tsx
T

59 lines
2.7 KiB
TypeScript

import { Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
import { useTranslation } from "react-i18next";
import { useLocaleFormatters } from "~/locale/format";
import { formatMonthLabel } from "./dashboardFormatters";
export type DashboardMonthlySeriesChartProps = {
/** `id` is an ISO month (`2026-07`); the label is formatted for the viewer's locale. */
points: readonly { id: string; value: number; comparisonValue?: number }[];
valueFormat: "currency" | "count";
hasComparison: boolean;
};
/**
* Lazily loaded visual enhancement. Columns, not bars: time runs left to right
* (IBCS). The current period is the solid, saturated series and the previous
* year is the lighter one behind it — the only two encodings on the chart, so a
* reader can tell "now" from "then" without decoding a colour key.
*
* The parent card owns the accessible summary and data table, so this SVG is
* hidden from assistive technology.
*/
export default function DashboardMonthlySeriesChart({ points, valueFormat, hasComparison }: DashboardMonthlySeriesChartProps) {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const formatValue = (value: number) =>
valueFormat === "currency"
? formatters.currency(value, "EUR", { maximumFractionDigits: 0 })
: formatters.number(value, { maximumFractionDigits: 0 });
const data = points.map((point) => ({
...point,
label: formatMonthLabel(point.id, formatters.locale),
}));
return (
<div className="h-64 w-full" aria-hidden="true" data-ui-id="ui.dashboard.widget.sales.orderIntake.chart">
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} margin={{ top: 8, right: 8, bottom: 8, left: 8 }}>
<CartesianGrid vertical={false} strokeDasharray="3 3" />
<XAxis dataKey="label" tickLine={false} axisLine={false} interval="preserveStartEnd" minTickGap={8} />
<YAxis
tickLine={false}
axisLine={false}
width={72}
tickFormatter={(value) => formatters.compact(Number(value), { maximumFractionDigits: 1 })}
/>
<Tooltip cursor={{ fill: "rgba(107, 114, 128, 0.08)" }} formatter={(value) => formatValue(Number(value))} />
{hasComparison ? <Legend verticalAlign="top" height={28} /> : null}
{hasComparison ? (
<Bar dataKey="comparisonValue" name={t("app.dashboard.series.previousYear")} fill="#cbd5e1" radius={[4, 4, 0, 0]} maxBarSize={28} />
) : null}
<Bar dataKey="value" name={t("app.dashboard.series.currentPeriod")} fill="#334155" radius={[4, 4, 0, 0]} maxBarSize={28} />
</BarChart>
</ResponsiveContainer>
</div>
);
}