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:
@ -41,6 +41,10 @@ function updateCpsChart(labels, values) {
|
||||
}]
|
||||
};
|
||||
|
||||
const existingMin = cpsChart?.scales.x?.min;
|
||||
const existingMax = cpsChart?.scales.x?.max;
|
||||
const xMin = existingMin ?? labels[0];
|
||||
const xMax = existingMax ?? labels[labels.length - 1];
|
||||
const options = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
@ -61,23 +65,22 @@ function updateCpsChart(labels, values) {
|
||||
}
|
||||
},
|
||||
zoom: {
|
||||
pan: {
|
||||
enabled: true,
|
||||
mode: 'x',
|
||||
modifierKey: null,
|
||||
},
|
||||
zoom: {
|
||||
wheel: { enabled: true },
|
||||
pinch: { enabled: true },
|
||||
drag: { enabled: false },
|
||||
mode: 'x',
|
||||
onZoom: () => { document.getElementById('reset-zoom-cps').style.display = 'inline-block'; }
|
||||
onZoomComplete: () => {
|
||||
document.getElementById('reset-zoom-cps').style.display = 'inline-block';
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'time',
|
||||
min: xMin,
|
||||
max: xMax,
|
||||
time: {
|
||||
tooltipFormat: 'dd/MM HH:mm',
|
||||
displayFormats: { minute: 'HH:mm', hour: 'HH:mm', day: 'dd/MM' }
|
||||
@ -105,6 +108,7 @@ function updateCpsChart(labels, values) {
|
||||
script.src = 'https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js';
|
||||
script.onload = () => {
|
||||
cpsChart = new Chart(ctx, { type: 'line', data: chartData, ...options });
|
||||
enablePan(cpsChart, 'reset-zoom-cps', labels[0], labels[labels.length - 1]);
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user