import { CLINICAL_THRESHOLDS } from '/pkCore.js'; import { t } from './i18n.js'; export function updateChartAnnotations(chart, mode, currentYMax) { const thresholds = CLINICAL_THRESHOLDS[mode]; const annotations = {}; thresholds.zones.forEach((zone, index) => { if (zone.min < currentYMax) { const zoneMax = zone.max === Infinity ? currentYMax : zone.max; annotations[`zone_${index}`] = { type: 'box', yMin: zone.min, yMax: Math.min(zoneMax, currentYMax), backgroundColor: zone.color, borderWidth: 0, label: { display: true, content: t(`zones.${zone.zoneKey}`), color: zone.textHex, font: { size: 11, weight: 'bold' }, position: 'center' } }; } }); chart.options.plugins.annotation.annotations = annotations; } export function adjustChartYScale(chart, mode, datasets) { const defaultMax = CLINICAL_THRESHOLDS[mode].maxScale; let highestValue = 0; datasets.forEach(ds => { ds.data.forEach(val => { if (val > highestValue) highestValue = val; }); }); let targetYMax = defaultMax; if (highestValue > defaultMax) { targetYMax = Math.ceil(highestValue * 1.1); } chart.options.scales.y.max = targetYMax; updateChartAnnotations(chart, mode, targetYMax); }