🎥 Make videos programmatically with React
axes shift
Jonny Burger8a6e12554455
diff --git a/packages/convert/app/components/timing-editor/draw-trajectory.ts b/packages/convert/app/components/timing-editor/draw-trajectory.tsindex e42e02fff3..bf75e93aaa 100644--- a/packages/convert/app/components/timing-editor/draw-trajectory.ts+++ b/packages/convert/app/components/timing-editor/draw-trajectory.ts@@ -15,17 +15,20 @@ const getX = ({i, segmentWidth}: {i: number; segmentWidth: number}) => {const getY = ({canvasHeight,i,+ min,max,springTrajectory,}: {canvasHeight: number;i: number;+ min: number;max: number;springTrajectory: number[];}) => {+ const range = max - min;+ const normalizedValue = range === 0 ? 0.5 : (springTrajectory[i] - min) / range;return (- (canvasHeight - PADDING_TOP - PADDING_BOTTOM) *- (1 - springTrajectory[i] / max) ++ (canvasHeight - PADDING_TOP - PADDING_BOTTOM) * (1 - normalizedValue) +PADDING_TOP);};@@ -36,6 +39,7 @@ export const drawTrajectory = ({canvasWidth,springTrajectory,primary,+ min,max,animate,fps,@@ -45,16 +49,18 @@ export const drawTrajectory = ({canvasWidth: number;canvasHeight: number;springTrajectory: number[];+ min: number;max: number;animate: boolean;fps: number;}) => {const intervalBetweenDraw = 1000 / fps;const segmentWidth =- (canvasWidth - PADDING_LEFT - PADDING_RIGHT) / (springTrajectory.length - 1);+ (canvasWidth - PADDING_LEFT - PADDING_RIGHT) /+ (springTrajectory.length - 1);let lastX = getX({i: 0, segmentWidth});- let lastY = getY({i: 0, canvasHeight, max, springTrajectory});+ let lastY = getY({i: 0, canvasHeight, min, max, springTrajectory});let lastDraw = Date.now();let stopped = false;@@ -82,12 +88,12 @@ export const drawTrajectory = ({gradient,);const x = getX({i, segmentWidth});- const y = getY({canvasHeight, i, max, springTrajectory});+ const y = getY({canvasHeight, i, min, max, springTrajectory});lastX = x;lastY = y;- context.strokeStyle = primary ? color : '#333';+ context.strokeStyle = primary ? color : '#eee';context.lineTo(x, y);context.stroke();context.closePath();diff --git a/packages/convert/app/components/timing-editor/draw.ts b/packages/convert/app/components/timing-editor/draw.tsindex a516381b73..2c8978d0bf 100644--- a/packages/convert/app/components/timing-editor/draw.ts+++ b/packages/convert/app/components/timing-editor/draw.ts@@ -45,43 +45,55 @@ export const draw = ({? getTrajectory(draggedDuration ?? duration, fps, draggedConfig): [];- const max = draggedConfig- ? Math.max(...draggedTrajectory)- : Math.max(...trajectory);+ const activeTrajectory = draggedConfig ? draggedTrajectory : trajectory;+ const max = Math.max(...activeTrajectory);+ const min = Math.min(...activeTrajectory);+ const range = max - min;context.strokeStyle = 'rgba(255, 255, 255, 0.05)';context.lineWidth = LINE_WIDTH * window.devicePixelRatio;context.lineCap = 'round';- // Draw 0 line- const zeroHeight = height - PADDING_BOTTOM;- context.beginPath();- context.moveTo(PADDING_LEFT, zeroHeight);- context.lineTo(+ const getYForValue = (value: number) => {+ const normalizedValue = range === 0 ? 0.5 : (value - min) / range;+ return (+ (height - PADDING_TOP - PADDING_BOTTOM) * (1 - normalizedValue) ++ PADDING_TOP+ );+ };++ const lineEndX =width -- PADDING_RIGHT -- measureText({- fontFamily: 'GTPlanar',- fontSize: 15,- text: labelText,- fontWeight: 'medium',- letterSpacing: undefined,- }).width -- 23 -- 16,- zeroHeight,- );- context.stroke();- context.closePath();+ PADDING_RIGHT -+ measureText({+ fontFamily: 'GTPlanar',+ fontSize: 15,+ text: labelText,+ fontWeight: 'medium',+ letterSpacing: undefined,+ }).width -+ 23 -+ 16;- // Draw 1 line- const oneHeight =- (height - PADDING_TOP - PADDING_BOTTOM) * (1 - 1 / max) + PADDING_TOP;- context.beginPath();- context.moveTo(PADDING_LEFT, oneHeight);- context.lineTo(width - PADDING_RIGHT, oneHeight);- context.stroke();- context.closePath();+ // Draw 0 line (if 0 is within the range)+ if (min <= 0 && max >= 0) {+ const zeroHeight = getYForValue(0);+ context.beginPath();+ context.moveTo(PADDING_LEFT, zeroHeight);+ context.lineTo(lineEndX, zeroHeight);+ context.stroke();+ context.closePath();+ }++ // Draw 1 line (if 1 is within the range)+ if (min <= 1 && max >= 1) {+ const oneHeight = getYForValue(1);+ context.beginPath();+ context.moveTo(PADDING_LEFT, oneHeight);+ context.lineTo(width - PADDING_RIGHT, oneHeight);+ context.stroke();+ context.closePath();+ }const toStop: (() => void)[] = [];@@ -90,6 +102,7 @@ export const draw = ({canvasHeight: height,canvasWidth: width,context,+ min,max,primary: !draggedConfig,animate: !draggedConfig,@@ -104,6 +117,7 @@ export const draw = ({canvasHeight: height,canvasWidth: width,context,+ min,max,primary: true,animate: false,