[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 align not working when adding new repos

Kasper (Mar 14, 2023, 11:21 AM +0100) e61d6423 07f98dc3

+41 -7
+41 -7
src/routes/chart.ts
··· 24 24 export interface Line extends LineBase { 25 25 instance: ISeriesApi<'Area'> 26 26 deleted: boolean 27 + lastChartSeriesDate?: BusinessDay 27 28 hidden?: boolean 28 29 } 29 30 ··· 158 159 }, 159 160 }) 160 161 162 + const line: Line = { 163 + ...lineJson, 164 + instance: series, 165 + deleted: false, 166 + } 161 167 if (lineJson.data.length >= 1) { 162 168 const start = lineJson.data[0] 163 169 const end = lineJson.final ?? lineJson.data[lineJson.data.length - 1] ··· 167 173 if (chart.align) { 168 174 chartSeries = alignChartSeries(chartSeries) 169 175 } 176 + line.lastChartSeriesDate = chartSeries[chartSeries.length - 1].time 170 177 series.setData(chartSeries) 171 - } 172 - const line: Line = { 173 - ...lineJson, 174 - instance: series, 175 - deleted: false, 176 178 } 177 179 chart.lines.push(line) 178 180 updateFiller(chart.lines) ··· 195 197 const chartSeries = toChartSeries(line.data, start, end) 196 198 const alignedChartSeries = alignChartSeries(chartSeries) 197 199 line.instance.setData(alignedChartSeries) 200 + line.lastChartSeriesDate = alignedChartSeries[alignedChartSeries.length - 1].time 198 201 } 199 202 const startDate = new Date(2001, 0) 200 203 const day = 1000 * 3600 * 24 ··· 245 248 const end = line.data[line.data.length - 1] 246 249 const chartSeries = toChartSeries(line.data, start, end) 247 250 line.instance.setData(chartSeries) 251 + line.lastChartSeriesDate = chartSeries[chartSeries.length - 1].time 248 252 } 249 253 setDefaultFormatting() 250 254 set(chart) ··· 268 272 set(chart) 269 273 }, 270 274 275 + _appendAlignedChartData(line: Line, data: DataPoint[]) { 276 + if (data.length === 0) { 277 + return 278 + } 279 + const start = data[0] 280 + const end = data[data.length - 1] 281 + const chartSeries = toChartSeries(data, start, end) 282 + const fresh = line.data.length === 0 283 + if (fresh) { 284 + const alignedChartSeries = alignChartSeries(chartSeries) 285 + line.instance.setData(alignedChartSeries) 286 + line.lastChartSeriesDate = alignedChartSeries[alignedChartSeries.length - 1].time 287 + } else { 288 + const startDay = line.lastChartSeriesDate 289 + if (!startDay) { 290 + throw new Error('no lastChartSeriesDate') 291 + } 292 + const startDate = new Date(startDay.year, startDay.month - 1, startDay.day) 293 + const alignedChartSeries = alignChartSeries(chartSeries, startDate) 294 + line.lastChartSeriesDate = alignedChartSeries[alignedChartSeries.length - 1].time 295 + 296 + for (const dataPoint of alignedChartSeries) { 297 + line.instance.update(dataPoint) 298 + } 299 + } 300 + }, 301 + 271 302 _appendChartData(line: Line, data: DataPoint[]) { 272 303 if (data.length === 0) { 273 304 return 305 + } else if (chart.align) { 306 + return this._appendAlignedChartData(line, data) 274 307 } 275 308 const start = line.data[line.data.length - 1] ?? data[0] 276 309 const end = line.final ?? data[data.length - 1] 277 310 const chartSeries = toChartSeries(data, start, end) 311 + line.lastChartSeriesDate = chartSeries[chartSeries.length - 1].time 278 312 const fresh = line.data.length === 0 279 313 280 314 if (fresh) { ··· 436 470 }) 437 471 } 438 472 439 - function alignChartSeries(chartSeries: ChartSeries[]): ChartSeries[] { 440 - const date = new Date(2001, 0) 473 + function alignChartSeries(chartSeries: ChartSeries[], start = new Date(2001, 0)): ChartSeries[] { 474 + const date = start 441 475 return chartSeries.map((seriesPoint): ChartSeries => { 442 476 const alignedSeriesPoint: ChartSeries = { 443 477 time: {