Files
ketapk/frontend/js/chartManager.js
T
2026-08-02 17:28:06 +02:00

47 lines
1.4 KiB
JavaScript

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) {
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);
}