Communitygithub.com

vibe-motion/skills

Create animated financial candlestick charts in Remotion projects. Covers data fetching (Yahoo Finance), plugin architecture (config / timeline / Scene / plugin), Canvas frame-by-frame rendering, dark trading terminal style, and Remotion Studio preview and rendering output. Triggers: K线图, 蜡烛图, candlestick, OHLC, stock animation, financial chart video, Remotion chart.

What is skills?

This skill provides a complete, step-by-step workflow for creating animated financial candlestick charts (K-line / candle charts) within Remotion-based video projects, specifically the vibe-motion-app. It is designed for developers who want to produce high-quality, data-driven animations for stock market visualizations, trading videos, or financial presentations. The skill covers the entire pipeline: fetching historical OHLC data from the Yahoo Finance API (no API key required), setting up a modular plugin architecture with configuration, timeline, and scene files, and rendering frames using HTML5 Canvas for optimal performance. It emphasizes key design principles such as avoiding React state for animation (relying solely on the frame parameter for parallel rendering) and handling high-DPI displays. The resulting animation features a dark trading terminal aesthetic with smooth fade-in and grow-in effects for each candlestick. The skill supports Remotion Studio preview and CLI-based rendering, and includes troubleshooting tips for common issues like CORS and narrow candles.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/vibe-motion/skills/tree/HEAD/remotion-candlestick

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Remotion Candlestick Animation Workflow

This skill documents the complete process of creating an S&P 500 candlestick chart within vibe-motion-app, a Remotion project.

Prerequisites

  • Remotion 4.0.438 project, configured with React 19 + TailwindCSS v4
  • Plugin architecture: motion/ defines scenes, remotion/ handles the Remotion composition pipeline
  • pnpm as the package manager

Step 1: Fetch Financial Data

Yahoo Finance provides free historical OHLC data (no API Key required).

Create scripts/fetch-sp500-data.mjs:

// Core: Call Yahoo Finance Chart API
const url = `https://query1.finance.yahoo.com/v8/finance/chart/%5EGSPC?period1=${PERIOD1}&period2=${PERIOD2}&interval=1wk`;
const resp = await fetch(url);
const json = await resp.json();
const result = json.chart?.result?.[0];
const ts = result.timestamp;
const quote = result.indicators.quote[0];
// Extract { t: timestamp, o: open, h: high, l: low, c: close }

Save to public/data/sp500-weekly.json, to be loaded by Remotion via staticFile().

Parameter Notes:

  • %5EGSPC = Yahoo symbol for S&P 500 (^GSPC URL-encoded)
  • interval=1wk = weekly; alternatives: 1d, 1mo
  • period1 / period2 = Unix timestamps, covering ~40 years (1984-2026)

Step 2: Create Plugin File Structure

Each Remotion plugin requires 4 core files + a render preset:

motion/plugin-name/
  config.js                 → Default parameters
  timeline.js               → Scene context + per-frame animation calculation
  Scene.jsx                 → React component (Canvas drawing)
  plugin.js                 → Plugin registration object
  render-presets/
    default.json            → Render preset

2a. config.js — Default Parameters

export const DEFAULT_LAYOUT_PARAMS = Object.freeze({
  videoWidth: 1920,    // 16:9 landscape
  videoHeight: 1080,
});

export const DEFAULT_ANIMATION_PARAMS = Object.freeze({
  durationSeconds: 28,  // Total animation duration
  title: "S&P 500",
  subtitle: "Past 40 Years · Weekly Candlestick",
});

export const DEFAULT_MOTION_PROPS = Object.freeze({
  ...DEFAULT_LAYOUT_PARAMS,
  ...DEFAULT_ANIMATION_PARAMS,
});

2b. timeline.js — Animation Logic

Must implement three core functions:

// 1. Scene context: Validate + coerce all parameters
const resolveXxxSceneContext = (pluginParams) => { ... }

// 2. Duration calculation: durationSeconds * fps
const getXxxDurationInFrames = ({ fps, sceneContext }) => { ... }

// 3. Per-frame props: Compute progress and other animation values from frame/fps
const buildXxxSceneProps = ({ frame, fps, loop, sceneContext }) => { ... }

Key design principle: All animation state depends solely on the frame parameter, fulfilling Remotion's parallel rendering requirement.

2c. Scene.jsx — Canvas Drawing Component

Use <canvas> instead of extensive DOM elements for better performance.

Data Loading Pattern:

const [dataHandle] = useState(() => delayRender("Loading data"));

useEffect(() => {
  fetch(staticFile("data/xxx.json"))
    .then(r => r.json())
    .then(data => { setData(data); continueRender(dataHandle); })
    .catch(err => cancelRender(err));
}, [dataHandle]);

Core Canvas Drawing Logic:

const draw = useCallback(() => {
  const ctx = canvas.getContext("2d");
  const dpr = window.devicePixelRatio || 1;

  // High-DPI adaptation
  canvas.width = W * dpr;
  canvas.height = H * dpr;
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);

  // 1. Background fill
  // 2. Grid lines + Y-axis price ticks
  // 3. Candlestick drawing (wick + body)
  // 4. X-axis year labels
  // 5. Title / subtitle / statistics
  // 6. Progress bar
}, [data, progress, ...]);

useEffect(() => { draw(); }, [draw]);

Key Candlestick Drawing Parameters:

const CANDLE_GAP_RATIO = 0.28;  // Gap ratio between candlesticks
const CANDLE_FADE_FRAMES = 22;  // Entry animation frames
const MAX_CANDLE_W = 8;         // Maximum candlestick width (after scaling)
const MIN_CANDLE_W = 0.6;       // Minimum candlestick width

// Candlestick width adjusts adaptively with visible count
const slotW = plotWidth / visibleCount;
const bodyW = Math.max(MIN_CANDLE_W, Math.min(MAX_CANDLE_W * scale, slotW * (1 - GAP_RATIO)));

Entry Animation (fade-in + grow from bottom):

const appearFrame = (i / (N - 1)) * revealEndFrame;
const candleAge = currentFrame - appearFrame;
const fadeAlpha = Math.min(1, Math.max(0, candleAge / CANDLE_FADE_FRAMES));

// Grow animation
if (candleAge < CANDLE_FADE_FRAMES && candleAge > 0) {
  const growT = easeOutCubic(candleAge / CANDLE_FADE_FRAMES);
  displayBodyBottom = lerp(lowY, bodyBottom, growT);
}

ctx.globalAlpha = fadeAlpha;
// ... draw wick + body ...
ctx.globalAlpha = 1;

Dark Theme Colors:

const COLORS = {
  bg: "#1a1a19",
  grid: "#2c2c2a",
  upBorder: "#e66767",       // Bullish border (red)
  upFill: "rgba(230,103,103,0.15)",  // Bullish fill (translucent)
  downFill: "#199e70",        // Bearish fill (green)
  textPrimary: "#ffffff",
  textSecondary: "#c3c2b7",
  textMuted: "#898781",
  accent: "#3987e5",
};

2d. plugin.js — Plugin Registration

export const xxxPlugin = Object.freeze({
  id: "pluginID",
  defaultProps: DEFAULT_MOTION_PROPS,
  SceneComponent: XxxScene,
  waitForSceneLayoutReady: true,  // Wait for data loading

  resolveSceneContext: (params) => ...,
  getDurationInFrames: ({ fps, sceneContext }) => ...,
  buildSceneProps: ({ frame, fps, loop, sceneContext }) => ...,
  getLayout: ({ sceneContext }) => sceneContext.layout,
});

waitForSceneLayoutReady: true ensures the Scene component calls onAutoLayoutReady() before frame rendering starts.

2e. render-presets/default.json

{
  "title": "S&P 500",
  "subtitle": "Past 40 Years · Weekly Candlestick",
  "videoWidth": 1920,
  "videoHeight": 1080,
  "durationSeconds": 28
}

Step 3: Register Composition

Modify motion/project.js to switch ACTIVE_COMPOSITION to the new plugin:

import { xxxPlugin } from "./xxx/plugin.js";

export const ACTIVE_COMPOSITION = Object.freeze({
  id: "SP500Kline",
  fps: 30,
  plugin: xxxPlugin,
});

Step 4: Validate and Render

# Validate composition registration
pnpm run remotion:compositions

# Launch Studio preview (supports timeline scrubbing, parameter adjustment)
pnpm run dev

# Render a single frame screenshot
npx remotion still SP500Kline out/frame.png --frame=420

# Render full video
npx remotion render SP500Kline out/output.mp4

# Render using a preset
REMOTION_PROPS_FILE=motion/xxx/render-presets/default.json pnpm run remotion:render

Common Issues

Yahoo Finance API CORS Issue

CORS is not an issue in the Remotion rendering environment (Node.js headless browser). If browser preview encounters CORS, use staticFile() to load pre-fetched local JSON.

Canvas Blurry on High-DPI Displays

Always multiply by devicePixelRatio:

canvas.width = W * dpr;
canvas.height = H * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);

Too Many Candles Making Width Too Small

Set a minimum width of 0.6px; when slotW < 1, reduce the gap ratio or aggregate the data.

Animation Progress Control

Use segmented easing functions:

  • First 3%: quickly establish baseline
  • Middle 90%: linear reveal
  • End: slight deceleration for dramatic effect

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

Related Skills