|
41 | 41 | $: stretchFactor = timeProgressionSpeed === 'soundedSpeedTime'
|
42 | 42 | ? soundedSpeed
|
43 | 43 | : 1;
|
| 44 | +
|
44 | 45 | // TODO technically this is not correct, because the grid and the current output marker
|
45 | 46 | // (https://github.com/WofWca/jumpcutter/blob/5e09bf841e9c94ed5f5da03dfaea862dda269788/src/popup/Chart.svelte#L424-L455)
|
46 | 47 | // are still drawn in media intrinsic time, not in (media intrinsic time / soundedSpeed),
|
47 | 48 | // so it's more like changing `popupChartLengthInSeconds`, like it's not respected.
|
48 | 49 | $: millisPerPixel = stretchFactor * lengthSeconds * 1000 / widthPx;
|
49 |
| - $: { |
50 |
| - if (smoothie) { |
51 |
| - smoothie.options.millisPerPixel = millisPerPixel; |
| 50 | + let millisPerPixelCurrValue: number | undefined; |
| 51 | + let millisPerPixelPrevValue = 0; |
| 52 | + let millisPerPixelLastUpdatedAt = 0; |
| 53 | + function getTweenedMillisPerPixel() { |
| 54 | + const millisPerPixelTweeningDuration = 50; |
| 55 | + const tweeningPhase = 1 - Math.min( |
| 56 | + 1, |
| 57 | + (Date.now() - millisPerPixelLastUpdatedAt) / millisPerPixelTweeningDuration |
| 58 | + ); |
| 59 | + const diff = millisPerPixelCurrValue! - millisPerPixelPrevValue; |
| 60 | + return millisPerPixelCurrValue! - diff * tweeningPhase; |
| 61 | + } |
| 62 | + function onMillisPerPixelUpdate(newVal: number) { |
| 63 | + if (!millisPerPixelCurrValue) { |
| 64 | + millisPerPixelCurrValue = millisPerPixel; |
52 | 65 | }
|
53 |
| - }; |
| 66 | + millisPerPixelPrevValue = getTweenedMillisPerPixel(); |
| 67 | + millisPerPixelCurrValue = millisPerPixel; |
| 68 | + millisPerPixelLastUpdatedAt = Date.now(); |
| 69 | + } |
| 70 | + $: onMillisPerPixelUpdate(millisPerPixel); |
| 71 | +
|
54 | 72 | $: jumpPeriodMs = jumpPeriod / 100 * widthPx * millisPerPixel;
|
55 | 73 | let onJumpPeriodChange: undefined | ((prevStretchFactor: number) => void);
|
56 | 74 | let prevStretchFactor = stretchFactor;
|
|
485 | 503 | // In theory this could also be rewritten with `maybeInsertExtrapolatedData`, but it's fine now.
|
486 | 504 | (volumeThresholdSeries as any).data[1][0] = timeAtChartEdge;
|
487 | 505 |
|
| 506 | + smoothie.options.millisPerPixel = getTweenedMillisPerPixel(); |
| 507 | +
|
488 | 508 | const renderTimeBefore = (smoothie as SmoothieChartWithPrivateFields).lastRenderTimeMillis;
|
489 | 509 | smoothie.render(canvasEl, timeAtChartEdge);
|
490 | 510 | const renderTimeAfter = (smoothie as SmoothieChartWithPrivateFields).lastRenderTimeMillis;
|
|
0 commit comments