import React from 'react'; export interface ConditionBar { label: string; actual: number | null; standard: number | null; unit: string; /** Optional note shown under the bar, e.g. why a standard is absent. */ note?: string; } export interface InsightConditionChartProps { bars: ConditionBar[]; title?: string; emptyLabel?: string; } const AKTUAL = '#dc2626'; const STANDAR = '#3b82f6'; const fmt = (value: number, unit: string) => `${Number(value).toLocaleString('id-ID', { maximumFractionDigits: 1 })}${unit ? ` ${unit}` : ''}`; /** * Current readings against their CP 707 standard, one row per metric. * * The IoT panel has no per-day history — only a live snapshot — so there is no * trend to draw. Paired bars still answer the question the reader actually has: * is each reading above or below where the book says it should be. Each bar is * directly labelled, so the comparison never rests on colour alone. */ const InsightConditionChart: React.FC = ({ bars, title, emptyLabel = 'Belum ada pembacaan sensor untuk digambarkan.', }) => { const usable = bars.filter((bar) => bar.actual !== null || bar.standard !== null); if (usable.length === 0) { return (
{emptyLabel}
); } return (
{title &&

{title}

}
Aktual Standar CP 707
{usable.map((bar) => { // Scale each metric against its own max: units differ per row, so a // shared axis would make ammonia invisible next to CO2. const max = Math.max(bar.actual ?? 0, bar.standard ?? 0, 1); const pct = (value: number | null) => value === null ? 0 : Math.max(2, Math.round((value / max) * 100)); return (
{bar.label} {bar.actual === null ? 'data tidak tersedia' : fmt(bar.actual, bar.unit)} {bar.standard !== null && ( · standar {fmt(bar.standard, bar.unit)} )}
{bar.actual !== null && (
)}
{bar.standard !== null && (
)}
{bar.note &&

{bar.note}

}
); })}
); }; export default InsightConditionChart;