Add safety checks for traffic graph scale calculation

This commit is contained in:
Graham McIntire 2026-01-05 13:44:02 -06:00
parent 527e28736a
commit 13ca70da40
No known key found for this signature in database

View file

@ -107,12 +107,16 @@ const SensorChart = {
// Find max absolute value to make symmetric scale
let maxAbsValue = 0
datasets.forEach(dataset => {
dataset.data.forEach(point => {
maxAbsValue = Math.max(maxAbsValue, Math.abs(point.y))
})
if (dataset.data && dataset.data.length > 0) {
dataset.data.forEach(point => {
if (point && typeof point.y === 'number') {
maxAbsValue = Math.max(maxAbsValue, Math.abs(point.y))
}
})
}
})
// Add 10% padding
maxAbsValue = maxAbsValue * 1.1
// Add 10% padding, ensure minimum of 1000 (1 Kbps)
maxAbsValue = Math.max(maxAbsValue * 1.1, 1000)
yAxisConfig = {
min: -maxAbsValue,