[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 tooltip showing off-by-one value

The tooltip star values showed the values from the next day (might depend on the user's local timezone)

Kasper (Mar 3, 2023, 6:19 AM +0100) bface838 46883982

+19 -5
+9 -3
src/routes/Tooltip.svelte
··· 1 1 <script lang="ts"> 2 - import type { MouseEventParams, UTCTimestamp } from 'lightweight-charts' 2 + import type { BusinessDay, MouseEventParams, UTCTimestamp } from 'lightweight-charts' 3 3 import { onDestroy } from 'svelte' 4 4 import type { Chart, DataPoint, Line } from './chart' 5 5 import { hexColors } from './color' ··· 67 67 return 68 68 } 69 69 // time is in the same format that we supplied to setData 70 - const time = param.time as UTCTimestamp 70 + if (typeof param.time !== 'object') { 71 + console.error('time is not a BusinessDay:', param.time) 72 + return 73 + } 74 + const time = param.time as BusinessDay 71 75 72 76 for (const line of $chart.lines) { 73 - const dataPoint = findDayEndDataPoint(line.data, time) 77 + const maxDate = new Date(time.year, time.month - 1, time.day, 23, 59, 59, 999) 78 + const maxTimestamp = (maxDate.getTime() / 1000) as UTCTimestamp 79 + const dataPoint = findDayEndDataPoint(line.data, maxTimestamp) 74 80 if (dataPoint) { 75 81 values.push({ 76 82 line: line,
+10 -2
src/routes/chart.ts
··· 190 190 } 191 191 return dates.map((date) => { 192 192 return { 193 - time: (date.getTime() / 1000) as UTCTimestamp, 193 + time: { 194 + year: date.getFullYear(), 195 + month: date.getMonth() + 1, 196 + day: date.getDate(), 197 + }, 194 198 } 195 199 }) 196 200 } ··· 248 252 249 253 return dataPoints.map((dataPoint) => { 250 254 return { 251 - time: (dataPoint.date.getTime() / 1000) as UTCTimestamp, 255 + time: { 256 + year: dataPoint.date.getFullYear(), 257 + month: dataPoint.date.getMonth() + 1, 258 + day: dataPoint.date.getDate(), 259 + }, 252 260 value: dataPoint.value, 253 261 } satisfies SingleValueData 254 262 })