Skip to content

Commit b215a04

Browse files
committed
fix(client): restore negative score display when offset is null
Show score points (including red dots for negative scores) even when offset data is missing, matching original JavaScript behavior. Previously the TypeScript rewrite filtered out all entries with null offset, removing score data that should still be displayed. Reported-by: Anssi Johansson <https://miuku.net>
1 parent 818b786 commit b215a04

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

client/src/charts/server-chart.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ export function createServerChart(
4242
...options
4343
} as Required<ServerChartOptions>;
4444

45-
// Process history data with type safety - filter out points with missing offset data
46-
const history: ServerHistoryPoint[] = data.history
47-
.filter(d => d.offset != null)
48-
.map(d => ({
49-
...d,
50-
date: parseTimestamp(d.ts),
51-
offset: parseFloat(d.offset.toString())
52-
}));
53-
54-
// Calculate offset bounds
55-
let yOffsetMax = d3.max(history, d => d.offset) ?? 0;
56-
let yOffsetMin = d3.min(history, d => d.offset) ?? 0;
45+
// Process history data with type safety - convert all entries
46+
const history: ServerHistoryPoint[] = data.history.map(d => ({
47+
...d,
48+
date: parseTimestamp(d.ts),
49+
offset: d.offset != null ? parseFloat(d.offset.toString()) : 0
50+
}));
51+
52+
// Calculate offset bounds only from entries with valid offset data (include offset = 0, exclude null)
53+
const validOffsetHistory = history.filter(d => d.offset != null);
54+
let yOffsetMax = d3.max(validOffsetHistory, d => d.offset!) ?? 0;
55+
let yOffsetMin = d3.min(validOffsetHistory, d => d.offset!) ?? 0;
5756

5857
// Clamp offset values to reasonable bounds
5958
if (yOffsetMax > THRESHOLDS.offset.max) yOffsetMax = THRESHOLDS.offset.max;
@@ -272,11 +271,13 @@ function drawDataPoints(
272271
yOffsetScale: PowerScale,
273272
yScoreScale: PowerScale
274273
): void {
275-
const monitorData = history.filter(d => d.monitor_id !== null);
274+
// Filter data separately for scores and offsets
275+
const scoreData = history.filter(d => d.monitor_id !== null);
276+
const offsetData = history.filter(d => d.monitor_id !== null && d.offset != null);
276277

277-
// Draw score points
278+
// Draw score points (all monitor data, regardless of offset)
278279
g.selectAll<SVGCircleElement, ServerHistoryPoint>('circle.scores')
279-
.data(monitorData)
280+
.data(scoreData)
280281
.enter().append('circle')
281282
.attr('class', 'scores monitor-data')
282283
.attr('r', 2)
@@ -290,9 +291,9 @@ function drawDataPoints(
290291
fadeOtherMonitors(g, null, 1);
291292
});
292293

293-
// Draw offset points
294+
// Draw offset points (only data with valid offset values)
294295
g.selectAll<SVGCircleElement, ServerHistoryPoint>('circle.offsets')
295-
.data(monitorData)
296+
.data(offsetData)
296297
.enter().append('circle')
297298
.attr('class', 'offsets monitor-data')
298299
.attr('r', 1.5)

0 commit comments

Comments
 (0)