|
50 | 50 | }).format(new Date(value + "T00:00:00Z")); |
51 | 51 | } |
52 | 52 |
|
| 53 | + function dateValue(value) { |
| 54 | + return Date.parse(value + "T00:00:00Z"); |
| 55 | + } |
| 56 | + |
53 | 57 | function formatRating(value) { |
54 | 58 | if (value === null || value === undefined || value === "") return "n/a"; |
55 | 59 | return Number(value).toFixed(1) + " / 5"; |
|
97 | 101 | const exactIndex = daily.findIndex((row) => row.date === date); |
98 | 102 | if (exactIndex !== -1) return exactIndex; |
99 | 103 |
|
100 | | - const target = Date.parse(date + "T00:00:00Z"); |
| 104 | + const target = dateValue(date); |
101 | 105 | const laterIndex = daily.findIndex( |
102 | | - (row) => Date.parse(row.date + "T00:00:00Z") >= target, |
| 106 | + (row) => dateValue(row.date) >= target, |
103 | 107 | ); |
104 | 108 | return laterIndex === -1 ? daily.length - 1 : laterIndex; |
105 | 109 | } |
|
168 | 172 | const reviewMarkers = payload.reviews.map((review) => { |
169 | 173 | const index = indexForDate(daily, review.date); |
170 | 174 | return { |
171 | | - x: index, |
| 175 | + x: dateValue(review.date), |
172 | 176 | y: daily[index].downloads, |
173 | 177 | review, |
174 | 178 | }; |
175 | 179 | }); |
176 | 180 | const releaseMarkers = releaseEvents.map((event) => { |
177 | 181 | const index = indexForDate(daily, event.date); |
178 | 182 | return { |
179 | | - x: index, |
| 183 | + x: dateValue(event.date), |
180 | 184 | y: daily[index].downloads, |
181 | 185 | event, |
182 | 186 | }; |
|
188 | 192 | datasets: [ |
189 | 193 | { |
190 | 194 | label: "Downloads", |
191 | | - data: daily.map((row, index) => ({ |
192 | | - x: index, |
| 195 | + data: daily.map((row) => ({ |
| 196 | + x: dateValue(row.date), |
193 | 197 | y: row.downloads, |
194 | 198 | row, |
195 | 199 | })), |
|
258 | 262 | scales: { |
259 | 263 | x: { |
260 | 264 | type: "linear", |
261 | | - min: 0, |
262 | | - max: daily.length - 1, |
| 265 | + min: dateValue(first.date), |
| 266 | + max: dateValue(latest.date), |
263 | 267 | ticks: { |
264 | 268 | color: colors.muted, |
265 | 269 | maxTicksLimit: 7, |
266 | 270 | callback: (value) => { |
267 | | - const row = daily[Math.round(value)]; |
268 | | - return row ? formatDate(row.date).replace(", ", " ") : ""; |
| 271 | + const date = new Date(Number(value)).toISOString().slice(0, 10); |
| 272 | + return formatDate(date).replace(", ", " "); |
269 | 273 | }, |
270 | 274 | }, |
271 | 275 | grid: { color: colors.grid }, |
|
0 commit comments