import { CLINICAL_THRESHOLDS } from './pkCore.js'; import { t } from './i18n.js'; // Le texte des zones cliniques (zone.textHex) est calibré pour un fond sombre. // Sur le thème clair, il faut un texte foncé pour rester lisible sur le même fond pastel. const LIGHT_THEME_ZONE_TEXT = { inactive: '#854d0e', anti_hyperalgesic: '#3f6212', analgesia: '#92400e', psychedelic: '#9d174d', emergence: '#075985', narcosis: '#1e3a8a', excessive: '#7f1d1d' }; export function updateChartAnnotations(chart, mode, currentYMax) { const thresholds = CLINICAL_THRESHOLDS[mode]; const theme = document.documentElement.getAttribute('data-theme') || 'dark'; 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: theme === 'light' ? (LIGHT_THEME_ZONE_TEXT[zone.zoneKey] || '#1e293b') : zone.textHex, font: { size: 11, weight: 'bold' }, position: 'center' } }; } }); chart.options.plugins.annotation.annotations = annotations; } export function adjustChartYScale(chart, mode, datasets) { let highestValue = 0; // Recherche de la valeur maximale atteinte parmi tous les modèles affichés datasets.forEach(ds => { ds.data.forEach(val => { if (val > highestValue) highestValue = val; }); }); // Ajustement dynamique à 110 % de la valeur pic (ou plancher à 50 ng/mL si vide) let targetYMax = highestValue > 0 ? Math.ceil(highestValue * 1.1) : 50; chart.options.scales.y.max = targetYMax; updateChartAnnotations(chart, mode, targetYMax); }