mirror of
https://github.com/gauvainboiche/ketapk.git
synced 2026-09-02 11:13:11 +02:00
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import { CLINICAL_THRESHOLDS } from './pkCore.js';
|
|
import { t } from './i18n.js';
|
|
|
|
// Les couleurs de zone sont volontairement fixes (indépendantes du thème d'interface) :
|
|
// elles reproduisent le dégradé de référence de l'outil KetaPK original. Seul le texte
|
|
// (zone.textHex) est choisi pour rester lisible sur cette couleur de fond opaque.
|
|
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',
|
|
drawTime: 'beforeDraw',
|
|
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);
|
|
} |