// Drinks bar-chart components — discrete daily units.
// DrinksBars: 14-day mini for the Today card.
// DrinksTrendChart: full panel for the Trends tab.
function DrinksBars({
data, // array of daily unit values, oldest → newest
width = 320, height = 38, fullWidth = false,
threshold = 3, mutedColor, dangerColor,
}) {
const theme = window.HC_THEME.useHCTheme();
const p = theme.palette;
const arr = (data || []).map((v) => Number(v) || 0);
const days = arr.length;
if (days === 0) return null;
const max = Math.max(threshold + 1, ...arr) * 1.05;
const muted = mutedColor || p.text3;
const danger = dangerColor || p.warning;
const padX = 2, padY = 4;
const innerW = width - 2 * padX;
const innerH = height - 2 * padY;
const slot = innerW / days;
const barW = Math.max(2.5, slot * 0.55);
return (
);
}
// Trends panel — uses the drinks series from SeriesContext (via buildSeries).
// Phase overlays + spasm/event markers + dashed 3u threshold, matching the
// hand-rolled SVG styling of TrendChart.
function DrinksTrendChart({
width = 358, height = 100,
range = 'full', windowDays = 60,
phases = [], annotations = [],
threshold = 3,
}) {
const theme = window.HC_THEME.useHCTheme();
const p = theme.palette;
const SERIES = React.useContext(window.SeriesContext);
const s = SERIES && SERIES.drinks;
if (!s) return null;
const total = s.raw.length;
const days = range === '4w' ? Math.min(28, total) : Math.min(windowDays, total);
const offset = total - days;
const data = s.raw.slice(-days);
const max = Math.max(threshold + 1, ...data) * 1.05;
const muted = p.text3;
const danger = p.warning;
const padL = 32, padR = 12, padT = 10, padB = 22;
const innerW = width - padL - padR;
const innerH = height - padT - padB;
const slot = innerW / days;
const barW = Math.max(2, slot * 0.55);
const yBase = padT + innerH;
const y = (v) => padT + ((max - v) / max) * innerH;
const ticks = [0, threshold, Math.ceil(max)];
// X-tick date labels match the other TrendChart panels by reading from
// the shared HC_TREND_DATES array populated by TrendsTab.
const dates = window.HC_TREND_DATES || [];
return (
);
}
window.DrinksBars = DrinksBars;
window.DrinksTrendChart = DrinksTrendChart;