perf(tracks): bound playback rendering work
This commit is contained in:
@@ -16,6 +16,30 @@ export function sampledEventIndex(event: TrackPlaybackEvent, sampledCount: numbe
|
||||
return Math.max(0, Math.min(sampledCount - 1, Math.round(event.index * (sampledCount - 1) / (originalCount - 1))));
|
||||
}
|
||||
|
||||
export function trackPlaybackInterval(speed: number) {
|
||||
return Math.max(55, 300 / Math.max(0.5, speed));
|
||||
}
|
||||
|
||||
export function buildTrackRailSelection(track?: TrackPlaybackResponse) {
|
||||
const pointCount = track?.points.length ?? 0;
|
||||
const stopIndexesByPoint: Array<number[] | undefined> = new Array(pointCount);
|
||||
const eventIndexesByPoint: Array<number[] | undefined> = new Array(pointCount);
|
||||
if (!track || pointCount === 0) return { stopIndexesByPoint, eventIndexesByPoint };
|
||||
|
||||
track.stops.forEach((stop, stopIndex) => {
|
||||
for (let offset = -1; offset <= 1; offset += 1) {
|
||||
const pointIndex = stop.sampledIndex + offset;
|
||||
if (pointIndex < 0 || pointIndex >= pointCount) continue;
|
||||
(stopIndexesByPoint[pointIndex] ??= []).push(stopIndex);
|
||||
}
|
||||
});
|
||||
track.events.forEach((event, eventIndex) => {
|
||||
const pointIndex = sampledEventIndex(event, pointCount, track.summary.pointCount);
|
||||
(eventIndexesByPoint[pointIndex] ??= []).push(eventIndex);
|
||||
});
|
||||
return { stopIndexesByPoint, eventIndexesByPoint };
|
||||
}
|
||||
|
||||
function csvCell(value: unknown) {
|
||||
const text = String(value ?? '');
|
||||
return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
||||
|
||||
Reference in New Issue
Block a user