🎥 Make videos programmatically with React
Add line chart and SVG path animation rules
Igor Samokhovets3f81bda5c4b9
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.mdindex 3d28fd1869..90154b9123 100644--- a/packages/skills/skills/remotion/SKILL.md+++ b/packages/skills/skills/remotion/SKILL.md@@ -23,7 +23,7 @@ Read individual rule files for detailed explanations and code examples:- [rules/audio.md](rules/audio.md) - Using audio and sound in Remotion - importing, trimming, volume, speed, pitch- [rules/calculate-metadata.md](rules/calculate-metadata.md) - Dynamically set composition duration, dimensions, and props- [rules/can-decode.md](rules/can-decode.md) - Check if a video can be decoded by the browser using Mediabunny-- [rules/charts.md](rules/charts.md) - Chart and data visualization patterns for Remotion+- [rules/charts.md](rules/charts.md) - Chart and data visualization patterns for Remotion (bar, pie, line, stock charts, SVG path animation)- [rules/compositions.md](rules/compositions.md) - Defining compositions, stills, folders, default props and dynamic metadata- [rules/extract-frames.md](rules/extract-frames.md) - Extract frames from videos at specific timestamps using Mediabunny- [rules/fonts.md](rules/fonts.md) - Loading Google Fonts and local fonts in Remotiondiff --git a/packages/skills/skills/remotion/rules/charts.md b/packages/skills/skills/remotion/rules/charts.mdindex a402ed530e..f036485892 100644--- a/packages/skills/skills/remotion/rules/charts.md+++ b/packages/skills/skills/remotion/rules/charts.md@@ -1,58 +1,120 @@---name: charts-description: Chart and data visualization patterns for Remotion. Use when creating bar charts, pie charts, histograms, progress bars, or any data-driven animations.+description: Chart and data visualization patterns for Remotion. Use when creating bar charts, pie charts, line charts, stock graphs, or any data-driven animations.metadata:- tags: charts, data, visualization, bar-chart, pie-chart, graphs+ tags: charts, data, visualization, bar-chart, pie-chart, line-chart, stock-chart, svg-paths, graphs---# Charts in Remotion-You can create bar charts in Remotion by using regular React code - HTML and SVG is allowed, as well as D3.js.+Create charts using React code - HTML, SVG, and D3.js are all supported.-## No animations not powered by `useCurrentFrame()`+Disable all animations from third party libraries - they cause flickering.+Drive all animations from `useCurrentFrame()`.-Disable all animations by third party libraries.-They will cause flickering during rendering.-Instead, drive all animations from `useCurrentFrame()`.--## Bar Chart Animations--See [Bar Chart Example](assets/charts/bar-chart.tsx) for a basic example implmentation.--### Staggered Bars--You can animate the height of the bars and stagger them like this:+## Bar Chart```tsxconst STAGGER_DELAY = 5;const frame = useCurrentFrame();-const {fps} = useVideoConfig();+const { fps } = useVideoConfig();const bars = data.map((item, i) => {- const delay = i * STAGGER_DELAY;const height = spring({frame,fps,- delay,- config: {damping: 200},+ delay: i * STAGGER_DELAY,+ config: { damping: 200 },});- return <div style={{height: height * item.value}} />;+ return <div style={{ height: height * item.value }} />;});```-## Pie Chart Animation+## Pie Chart-Animate segments using stroke-dashoffset, starting from 12 o'clock.+Animate segments using stroke-dashoffset, starting from 12 o'clock:```tsx-const frame = useCurrentFrame();-const {fps} = useVideoConfig();-const progress = interpolate(frame, [0, 100], [0, 1]);-const circumference = 2 * Math.PI * radius;const segmentLength = (value / total) * circumference;const offset = interpolate(progress, [0, 1], [segmentLength, 0]);-<circle r={radius} cx={center} cy={center} fill="none" stroke={color} strokeWidth={strokeWidth} strokeDasharray={`${segmentLength} ${circumference}`} strokeDashoffset={offset} transform={`rotate(-90 ${center} ${center})`} />;+<circle+ r={radius}+ cx={center}+ cy={center}+ fill="none"+ stroke={color}+ strokeWidth={strokeWidth}+ strokeDasharray={`${segmentLength} ${circumference}`}+ strokeDashoffset={offset}+ transform={`rotate(-90 ${center} ${center})`}+/>;+```++## Line Chart / Path Animation++Use `@remotion/paths` for animating SVG paths (line charts, stock graphs, signatures).++Install: `npx remotion add @remotion/paths`+Docs: https://remotion.dev/docs/paths.md++### Convert data points to SVG path++```tsx+type Point = { x: number; y: number };++const generateLinePath = (points: Point[]): string => {+ if (points.length < 2) return "";+ return points.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" ");+};+```++### Draw path with animation++```tsx+import { evolvePath } from "@remotion/paths";++const path = "M 100 200 L 200 150 L 300 180 L 400 100";+const progress = interpolate(frame, [0, 2 * fps], [0, 1], {+ extrapolateLeft: "clamp",+ extrapolateRight: "clamp",+ easing: Easing.out(Easing.quad),+});++const { strokeDasharray, strokeDashoffset } = evolvePath(progress, path);++<path+ d={path}+ fill="none"+ stroke="#FF3232"+ strokeWidth={4}+ strokeDasharray={strokeDasharray}+ strokeDashoffset={strokeDashoffset}+/>;+```++### Follow path with marker/arrow++```tsx+import {+ getLength,+ getPointAtLength,+ getTangentAtLength,+} from "@remotion/paths";++const pathLength = getLength(path);+const point = getPointAtLength(path, progress * pathLength);+const tangent = getTangentAtLength(path, progress * pathLength);+const angle = Math.atan2(tangent.y, tangent.x);++<g+ style={{+ transform: `translate(${point.x}px, ${point.y}px) rotate(${angle}rad)`,+ transformOrigin: "0 0",+ }}+>+ <polygon points="0,0 -20,-10 -20,10" fill="#FF3232" />+</g>;```