[READ-ONLY] Mirror of https://github.com/probablykasper/starchart. GitHub star history graph starchart.kasper.space
chart github github-api github-star graph history star star-history stargazers stars
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix extra star counted

Closes #5

Kasper (Jun 24, 2026, 12:34 PM +0200) ef412206 ee28993b

+16 -10
+16 -10
src/routes/chart.ts
··· 39 39 } 40 40 41 41 /** Used to invalidate old localStorage */ 42 - const json_type_version = 3 42 + const json_type_version = 4 43 43 type Json = { 44 44 lines: LineJson[] 45 45 align: boolean ··· 211 211 deleted: false, 212 212 } 213 213 if (new_line.data.length >= 1) { 214 - let chart_series = to_chart_series(new_line.data) 214 + let chart_series = to_chart_series(new_line.data, new_line.final) 215 215 216 216 if (chart.align) { 217 217 chart_series = align_chart_series(chart_series) ··· 234 234 if (line.deleted || line.data.length === 0) { 235 235 continue 236 236 } 237 - const chart_series = to_chart_series(line.data) 237 + const chart_series = to_chart_series(line.data, line.final) 238 238 const aligned_chart_series = align_chart_series(chart_series) 239 239 line.instance.setData(aligned_chart_series) 240 240 line.lastChartSeriesDate = aligned_chart_series[aligned_chart_series.length - 1].time ··· 251 251 if (line.deleted || line.data.length === 0) { 252 252 continue 253 253 } 254 - const chart_series = to_chart_series(line.data) 254 + const chart_series = to_chart_series(line.data, line.final) 255 255 line.instance.setData(chart_series) 256 256 line.lastChartSeriesDate = chart_series[chart_series.length - 1].time 257 257 } ··· 281 281 if (line.data.length === 0) { 282 282 return 283 283 } 284 - const chart_series = to_chart_series(line.data) 284 + const chart_series = to_chart_series(line.data, line.final) 285 285 const fresh = line.data.length === 0 286 286 if (fresh) { 287 287 const aligned_chart_series = align_chart_series(chart_series) ··· 306 306 } else if (chart.align) { 307 307 return this._appendAlignedChartData(line) 308 308 } 309 - const chart_series = to_chart_series(line.data) 309 + const chart_series = to_chart_series(line.data, line.final) 310 310 line.lastChartSeriesDate = chart_series[chart_series.length - 1].time 311 311 const fresh = line.data.length === 0 312 312 if (fresh) { ··· 328 328 }, 329 329 330 330 addFinal(line: Line, data: DataPoint) { 331 - line.data.push(data) 331 + // Don't add it to line.data, that would mess up localStorage. 332 + // Instead, we add it directly to the chart later 332 333 store._appendChartData(line) 333 - line.final = line.data[line.data.length - 1] 334 + line.final = data 334 335 update_filler(chart.lines) 335 336 set(chart) 336 337 }, ··· 424 425 } 425 426 value: number 426 427 } 427 - function to_chart_series(data: DataPoint[]): ChartSeries[] { 428 + function to_chart_series(data: DataPoint[], final?: DataPoint): ChartSeries[] { 428 429 const data_points: { date: Date; value: number }[] = [] 429 430 data.sort((a, b) => a.t - b.t) 430 431 431 - for (const data_point of data) { 432 + for (let i = 0; i < data.length + Number(!!final); i++) { 433 + let data_point = data[i] 434 + if (i === data.length) { 435 + if (!final) throw new Error('final is undefined') 436 + data_point = final 437 + } 432 438 const dt = new Date(data_point.t * 1000) 433 439 const date = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) 434 440