prevent undefined/null values breaking graphs or scales

This commit is contained in:
Nick Krecklow 2020-06-12 18:59:59 -05:00
parent 5b6d65e1c9
commit 7313971871
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
3 changed files with 12 additions and 7 deletions

@ -26,7 +26,7 @@ export class RelativeScale {
} }
static scaleMatrix (data, tickCount, maxFactor) { static scaleMatrix (data, tickCount, maxFactor) {
const max = Math.max(...data.flat()) const max = Math.max(...data.flat().filter(val => val !== null))
return RelativeScale.scale([0, RelativeScale.isFiniteOrZero(max)], tickCount, maxFactor) return RelativeScale.scale([0, RelativeScale.isFiniteOrZero(max)], tickCount, maxFactor)
} }
@ -46,8 +46,8 @@ export class RelativeScale {
max: 0 max: 0
} }
} else { } else {
const min = Math.min(...data) const min = Math.min(...data.filter(val => val !== null))
const max = Math.max(...data) const max = Math.max(...data.filter(val => val !== null))
return { return {
min: RelativeScale.isFiniteOrZero(min), min: RelativeScale.isFiniteOrZero(min),

@ -1,3 +1,8 @@
**5.5.2** *(June 12 2020)*
- Fixed ping errors causing server graphs (or the historical graph) to sometimes disappear.
- Fixed ping errors causing server graphs to reset their Y scale minimum to 0.
- Improved zoomed detection and updating of the historical graph with recommendations by [@leeoniya](https://github.com/leeoniya).
**5.5.1** *(June 10 2020)* **5.5.1** *(June 10 2020)*
- New tooltip hover design on the historical graph. It will highlight the server closest to your cursor. - New tooltip hover design on the historical graph. It will highlight the server closest to your cursor.
- Historical graph is now limited to 10,000 increments on the Y axis. This prevents servers with over 100,000 players forcing the graph into 100,000 increments. - Historical graph is now limited to 10,000 increments on the Y axis. This prevents servers with over 100,000 players forcing the graph into 100,000 increments.

@ -45,6 +45,10 @@ class ServerRegistration {
getUpdate (timestamp, resp, err, version) { getUpdate (timestamp, resp, err, version) {
const update = {} const update = {}
// Always append a playerCount value
// When resp is undefined (due to an error), playerCount will be null
update.playerCount = getPlayerCountOrNull(resp)
if (resp) { if (resp) {
if (resp.version && this.updateProtocolVersionCompat(resp.version, version.protocolId, version.protocolIndex)) { if (resp.version && this.updateProtocolVersionCompat(resp.version, version.protocolId, version.protocolIndex)) {
// Append an updated version listing // Append an updated version listing
@ -65,10 +69,6 @@ class ServerRegistration {
update.favicon = this.getFaviconUrl() update.favicon = this.getFaviconUrl()
} }
// Append a result object
// This filters out unwanted data from resp
update.playerCount = resp.players.online
if (config.logToDatabase) { if (config.logToDatabase) {
// Update calculated graph peak regardless if the graph is being updated // Update calculated graph peak regardless if the graph is being updated
// This can cause a (harmless) desync between live and stored data, but it allows it to be more accurate for long surviving processes // This can cause a (harmless) desync between live and stored data, but it allows it to be more accurate for long surviving processes