{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "bar-grow",
  "type": "block",
  "title": "Bar grow",
  "summary": "Bars grow with a short overshoot as the camera passes low along the chart; the winner takes the accent and its number counts up.",
  "tags": [
    "block",
    "data",
    "chart",
    "bars",
    "growth"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "title",
      "type": "string",
      "default": "Renders per week",
      "description": "title",
      "group": "main",
      "control": "text"
    },
    {
      "name": "winner",
      "type": "number",
      "default": 6,
      "description": "which bar (0-based) takes the accent",
      "group": "main"
    },
    {
      "name": "format",
      "type": "enum",
      "default": "1920x1080",
      "options": [
        "1920x1080",
        "1080x1920",
        "1080x1080"
      ],
      "description": "output size; the layout recomposes for each",
      "group": "main",
      "control": "segmented"
    }
  ],
  "install": {
    "kind": "scene"
  },
  "files": [
    {
      "path": "pieces/bar-grow/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>bar-grow</title>\n<!--\n  Data · bar grow (5.5 s). A bar chart stands in space. The baseline draws, the bars grow one after another with a\n  short overshoot, and the one that matters takes the accent while its number counts up above it. The camera passes\n  along the chart at a low angle and comes round to face the winner, close.\n  Arrive 0–0.8 s · Baseline 0.5–1.0 s · Bars 0.9–2.4 s · Winner 2.5 s · Hold to 5.5 s.\n  Vertical/square: the chart takes most of the frame width (square: a deeper card; vertical: a tall card with tall\n  bars), type is floored from the short side, and the same pass-and-land camera is re-aimed for the taller plot.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #chart { position: absolute; box-sizing: border-box; }\n  #plot { position: absolute; display: flex; align-items: flex-end; }\n  .col { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }\n  .bar { width: 62%; transform-origin: 50% 100%; }\n  .val { position: absolute; white-space: nowrap; }\n  .lab { position: absolute; bottom: -2.2em; white-space: nowrap; }\n  .grid { position: absolute; left: 0; right: 0; height: 1px; }\n  #base { position: absolute; left: 0; right: 0; height: 2px; transform-origin: 0 50%; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"chart\"><div id=\"title\"></div><div id=\"plot\"><div id=\"base\"></div></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { blurIn } from 'paper-motion/moves';\nimport { camera } from 'paper-motion/kit';\nimport { loadBrand } from 'paper-motion/brand';\n\nconst CONFIG = {\n  background: null,                      // a shader-set id, or null for the brand's first entry\n  title: 'Renders per week',\n  bars: [['W1', 120], ['W2', 180], ['W3', 160], ['W4', 260], ['W5', 310], ['W6', 290], ['W7', 540]],\n  winner: 6,                             // which bar (0-based) takes the accent\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.5;\nconst s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });\nconst bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;\nif (bgId) B.shader(s, '#bg', bgId);\ndocument.querySelector('#bg').style.opacity = 0.35;\nconst $ = (id) => document.getElementById(id);\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst wide = W / H > 1.2, tall = H > W;\nconst chart = $('chart'), cw = wide ? W * 0.7 * K : W * (tall ? 0.86 : 0.84) * K, ch = cw * (wide ? 0.5 : tall ? 1.55 : 0.66), R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nconst ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');\nObject.assign(chart.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: B.surface(0.16), border: `1.5px solid ${muted}44`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${wide ? cw * 0.016 : SHORT * K * 0.024}px` });\nconst title = B.style($('title'), 'title', { short: SHORT * K, color: 'figure' });\nObject.assign(title.style, { position: 'absolute', left: `${cw * 0.05}px`, top: `${ch * 0.07}px`, fontSize: `${wide ? ch * 0.065 : SHORT * K * 0.05}px` });\ntitle.textContent = CONFIG.title;\nconst plot = $('plot'), px = cw * 0.06, pw = cw * 0.88, py = ch * (wide ? 0.27 : tall ? 0.17 : 0.25), ph = ch * (wide ? 0.56 : tall ? 0.72 : 0.6);\nObject.assign(plot.style, { left: `${px}px`, top: `${py}px`, width: `${pw}px`, height: `${ph}px`, gap: `${pw * 0.015}px` });\nconst max = Math.max(...CONFIG.bars.map(([, v]) => v)) * 1.12;\nfor (let g = 1; g <= 3; g++) { const l = document.createElement('div'); l.className = 'grid'; l.style.bottom = `${(g / 3) * 100}%`; l.style.background = `${muted}22`; plot.append(l); }\n$('base').style.bottom = '0'; $('base').style.background = `${muted}88`;\nconst cols = CONFIG.bars.map(([lab, v], i) => {\n  const c = document.createElement('div'); c.className = 'col';\n  const win = i === CONFIG.winner;\n  c.innerHTML = `<div class=\"val\" style=\"font:500 1.15em ${B.font('mono')};color:${win ? accent : muted}\"></div><div class=\"bar\" style=\"height:${(v / max) * 100}%;border-radius:${R * 0.4}px ${R * 0.4}px 0 0;background:${win ? `${muted}55` : `${muted}55`}\"></div><div class=\"lab\" style=\"font:400 0.95em ${B.font('mono')};color:${muted}\">${lab}</div>`;\n  plot.append(c);\n  return { c, bar: c.querySelector('.bar'), val: c.querySelector('.val'), v, win };\n});\ncam.place(chart, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\nconst T = { base: [0.5, 1.0], bars: 0.9, each: 0.16, win: 2.5 };\nconst wi = CONFIG.winner, wx = px + (pw / CONFIG.bars.length) * (wi + 0.5) - cw / 2;\nconst wTop = py + ph * (1 - CONFIG.bars[wi][1] / max) - ch / 2;\ns.update((t) => {\n  $('base').style.transform = `scaleX(${progress(t, ...T.base, ease.inOutCubic)})`;\n  blurIn(title, t, { start: 0.4, duration: 0.6 });\n  cols.forEach(({ bar, val, v, win }, i) => {\n    const a = T.bars + i * T.each, g = t >= a ? spring(t - a, { stiffness: 150, damping: 11 }) : 0;\n    bar.style.transform = `scaleY(${Math.max(0, g)})`;\n    // the winner turns to the accent and grows a glow; its number counts up; the others show theirs quietly\n    const w = win ? progress(t, T.win, T.win + 0.5, ease.outCubic) : 0;\n    bar.style.background = win && w ? accent : `${muted}55`;\n    bar.style.opacity = win ? String(0.75 + 0.25 * w) : String(1 - 0.35 * progress(t, T.win, T.win + 0.5));\n    bar.style.boxShadow = w ? `0 0 ${SHORT * 0.06 * w}px ${accent}55` : 'none';\n    const shown = win ? Math.round(v * progress(Math.round(t * 30) / 30, T.win, T.win + 0.9, ease.outCubic)) : v;   // one value per frame\n    val.textContent = String(shown);\n    const vin = win ? progress(t, T.win, T.win + 0.3) : progress(t, a + 0.25, a + 0.5) * (1 - 0.5 * progress(t, T.win, T.win + 0.5));\n    val.style.opacity = String(vin);\n    val.style.bottom = `calc(${(v / max) * 100 * Math.max(0, Math.min(1.05, g))}% + 0.6em)`;\n    if (win) val.style.fontSize = `${1.15 + 1.4 * w}em`;\n  });\n  // the camera: low and from the side, travelling along the chart, then round to face the winner, close\n  const arrive = progress(t, 0, 0.8, ease.outCubic), pass = progress(t, 0.3, T.win + 0.2, ease.inOutCubic), land = progress(t, T.win - 0.4, D - 0.4, ease.inOutCubic);\n  if (!wide) {\n    // the same pass at a low angle, re-aimed: the land frames the winner's bar and its number, close\n    const wMid = py + ph * (1 - CONFIG.bars[wi][1] / max * 0.5) - ch / 2;\n    cam.at({\n      x: -cw * 0.3 + (wx * 0.75 + cw * 0.3) * pass,\n      y: ch * 0.1 * (1 - pass) + (tall ? (wTop * 0.15 + wMid * 0.85) : wTop * 0.55) * land,\n      z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.12 * pass - SHORT * (tall ? 0.42 : 0.45) * land,\n      yaw: -24 * (1 - pass) + 4 * (1 - land) * pass, pitch: -10 * (1 - pass) - 2 * pass,\n    });\n  } else\n  cam.at({\n    x: -cw * 0.3 + (wx * 0.82 + cw * 0.3) * pass,\n    y: ch * 0.12 * (1 - pass) + (wTop * 0.55) * land,\n    z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.15 * pass - SHORT * 0.5 * land,\n    yaw: -26 * (1 - pass) + 4 * (1 - land) * pass, pitch: -10 * (1 - pass) - 2 * pass,\n  });\n  chart.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.bars); B.cue(s, 'land', T.win);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/bar-grow/brief.md",
      "content": "# Bar grow\n\nBlock: bar-grow (5.5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nBars grow with a short overshoot as the camera passes low along the chart; the winner takes the accent and its number counts up.\n\nA block is one ready-made moment. Edit `CONFIG` (its words, numbers and format: 16:9, 9:16 or 1:1, the layout recomposes for each); check `npx paper-motion still` at 0.8 and 1 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add bar-grow --name my-bar-grow\n# edit CONFIG in pieces/my-bar-grow/scene.html, then:\nnpx paper-motion render pieces/my-bar-grow/scene.html --motion-blur 5",
  "notes": [
    "Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work) and, for the field, a shader-set entry.",
    "Recomposes for 16:9, 9:16 and 1:1: set `format` and the layout and camera follow."
  ],
  "related": [
    "line-draw",
    "stat-row"
  ],
  "preview": {
    "video": "previews/bar-grow.webm",
    "poster": "previews/bar-grow.jpg",
    "at": 5.2,
    "values": {}
  },
  "mood": [
    "bold"
  ],
  "duration": 5.5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.8,
      "what": "arrive"
    },
    {
      "name": "Baseline",
      "from": 0.5,
      "to": 1,
      "what": "baseline"
    },
    {
      "name": "Bars",
      "from": 0.9,
      "to": 2.4,
      "what": "bars"
    },
    {
      "name": "Winner",
      "from": 2.5,
      "to": 3.1,
      "what": "winner"
    },
    {
      "name": "Hold",
      "from": 3.1,
      "to": 5.5,
      "what": "hold"
    }
  ],
  "when": [
    "growth over time",
    "one standout number"
  ],
  "needs": [
    {
      "kind": "series",
      "fill": {
        "title": "$title",
        "bars": "$points",
        "winner": {
          "$argmax": "points"
        }
      }
    }
  ]
}