Fix: add data boundaries to spectrum pan + bump cache versions
The spectrum chart was missing xMin/xMax persistence and data boundary clamping in enablePan(). Align with the background/cps chart patterns. Bump cache versions to force browser refresh. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@ -151,6 +151,10 @@ function updateBackgroundChart(spec) {
|
||||
datasets: datasets,
|
||||
};
|
||||
|
||||
const existingMin = bgChart?.scales.x?.min;
|
||||
const existingMax = bgChart?.scales.x?.max;
|
||||
const xMin = existingMin ?? spec.energy_kev[0];
|
||||
const xMax = existingMax ?? spec.energy_kev[spec.energy_kev.length - 1];
|
||||
const options = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
@ -168,24 +172,22 @@ function updateBackgroundChart(spec) {
|
||||
}
|
||||
},
|
||||
zoom: {
|
||||
pan: {
|
||||
enabled: true,
|
||||
mode: 'x',
|
||||
modifierKey: null,
|
||||
},
|
||||
zoom: {
|
||||
wheel: { enabled: true },
|
||||
pinch: { enabled: true },
|
||||
drag: { enabled: false },
|
||||
mode: 'x',
|
||||
limits: { x: { min: 30, max: 3000 } },
|
||||
onZoom: () => { document.getElementById('reset-zoom-bg').style.display = 'inline-block'; }
|
||||
onZoomComplete: () => {
|
||||
document.getElementById('reset-zoom-bg').style.display = 'inline-block';
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'linear',
|
||||
min: xMin,
|
||||
max: xMax,
|
||||
title: { display: true, text: 'Énergie (keV)', color: '#888' },
|
||||
ticks: { color: '#888', maxTicksLimit: 20 },
|
||||
grid: { color: '#333' },
|
||||
@ -206,6 +208,7 @@ function updateBackgroundChart(spec) {
|
||||
bgChart.update();
|
||||
} else {
|
||||
bgChart = new Chart(ctx, { type: 'line', data: chartData, ...options });
|
||||
enablePan(bgChart, 'reset-zoom-bg', spec.energy_kev[0], spec.energy_kev[spec.energy_kev.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user