Bug fix: avoid NaN in helper

This commit is contained in:
Rob Watson 2022-01-25 20:06:15 +01:00
parent 5af8f0c319
commit 48c84a7efa
1 changed files with 6 additions and 1 deletions

View File

@ -109,7 +109,12 @@ export const Waveform: React.FC<Props> = ({
// helpers // helpers
const frameToCanvasX = (frame: number): number => { const frameToCanvasX = (frame: number): number => {
const pixelsPerFrame = CanvasLogicalWidth / (viewport.end - viewport.start); const numFrames = viewport.end - viewport.start;
if (numFrames == 0) {
return 0;
}
const pixelsPerFrame = CanvasLogicalWidth / numFrames;
return Math.round((frame - viewport.start) * pixelsPerFrame); return Math.round((frame - viewport.start) * pixelsPerFrame);
}; };