Add safety checks for traffic graph scale calculation
This commit is contained in:
parent
527e28736a
commit
13ca70da40
1 changed files with 9 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue