@template T
| 255 | // =========================================================================== |
| 256 | /** @template T */ |
| 257 | class Chunk { |
| 258 | constructor(index, start, end, items) { |
| 259 | this.index = index; |
| 260 | this.start = start; |
| 261 | this.end = end; |
| 262 | /** @type {T[]} */ |
| 263 | this.items = items; |
| 264 | this.height = 0; |
| 265 | } |
| 266 | |
| 267 | isEmpty() { |
| 268 | return this.items.length === 0; |
| 269 | } |
| 270 | |
| 271 | /** @returns {T} */ |
| 272 | last() { |
| 273 | return this.at(this.size() - 1); |
| 274 | } |
| 275 | |
| 276 | /** @returns {T} */ |
| 277 | first() { |
| 278 | return this.at(0); |
| 279 | } |
| 280 | |
| 281 | /** @returns {T} */ |
| 282 | at(index) { |
| 283 | return this.items[index]; |
| 284 | } |
| 285 | |
| 286 | size() { |
| 287 | return this.items.length; |
| 288 | } |
| 289 | |
| 290 | get length() { |
| 291 | return this.items.length; |
| 292 | } |
| 293 | |
| 294 | /** @param {T} event */ |
| 295 | yOffset(event) { |
| 296 | // items[0] == oldest event, displayed at the top of the chunk |
| 297 | // items[n-1] == youngest event, displayed at the bottom of the chunk |
| 298 | return ((this.indexOf(event) + 0.5) / this.size()) * this.height; |
| 299 | } |
| 300 | |
| 301 | /** @param {T} event */ |
| 302 | indexOf(event) { |
| 303 | return this.items.indexOf(event); |
| 304 | } |
| 305 | |
| 306 | /** @param {T} event */ |
| 307 | has(event) { |
| 308 | if (this.isEmpty()) return false; |
| 309 | return this.first().time <= event.time && event.time <= this.last().time; |
| 310 | } |
| 311 | |
| 312 | /** @param {Chunk<T>[]} chunks */ |
| 313 | next(chunks) { |
| 314 | return this.findChunk(chunks, 1); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…