{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "line-draw",
  "type": "block",
  "title": "Line draw",
  "summary": "A trend line draws with a dot riding its tip and the camera close on it; at the peak a label pops and the camera pulls back on the climb.",
  "tags": [
    "block",
    "data",
    "chart",
    "line",
    "trend",
    "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": "Brands made with paper-motion",
      "description": "title",
      "group": "main",
      "control": "text"
    },
    {
      "name": "tag",
      "type": "string",
      "default": "+42% this month",
      "description": "tag",
      "group": "main",
      "control": "text"
    },
    {
      "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/line-draw/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>line-draw</title>\n<!--\n  Data · line draw (5.5 s). A trend line draws itself left to right with a dot riding its tip and the area under it\n  filling behind; the camera travels with the tip, close, and when the line reaches its peak a label pops there and\n  the camera eases back to show the whole climb.\n  Arrive 0–0.7 s · Draw 0.6–3.4 s · Peak 3.4 s · Pull back 3.4–5.2 s.\n  Vertical/square: the panel takes most of the frame width and gets deeper (vertical: a tall panel, so the climb is\n  steeper), type is floored from the short side, and the pull-back lands centred with the whole panel in frame.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #panel { position: absolute; box-sizing: border-box; }\n  #svg { position: absolute; left: 0; top: 0; overflow: visible; }\n  #tag { position: absolute; white-space: nowrap; border-radius: 0.5em; padding: 0.35em 0.7em; }\n  .tick { position: absolute; white-space: nowrap; }\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=\"panel\"><div id=\"title\"></div><svg id=\"svg\"><defs><linearGradient id=\"fill\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop id=\"s0\" offset=\"0\"/><stop id=\"s1\" offset=\"1\"/></linearGradient><clipPath id=\"clip\"><rect id=\"clipr\"/></clipPath></defs><g id=\"grid\"></g><path id=\"area\" clip-path=\"url(#clip)\"/><path id=\"guide\"/><path id=\"line\"/><circle id=\"halo\"/><circle id=\"dot\"/></svg><div id=\"tag\"></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: 'Brands made with paper-motion',\n  points: [12, 14, 13, 18, 17, 22, 26, 24, 31, 38, 36, 51],\n  labels: ['Jan', 'Mar', 'May', 'Jul', 'Sep', 'Nov'],\n  tag: '+42% this month',\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);\nconst $ = (id) => document.getElementById(id);\n$('bg').style.opacity = 0.35;\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');\nconst wide = W / H > 1.2, tall = H > W;\nconst panel = $('panel'), cw = wide ? W * 0.72 * K : W * 0.82 * K, ch = cw * (wide ? 0.5 : tall ? 1.3 : 0.72), R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nObject.assign(panel.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.06 : SHORT * K * 0.045}px` });\ntitle.textContent = CONFIG.title;\n// the plot area and the curve through the points (Catmull-Rom as cubic Béziers)\nconst x0 = cw * 0.07, x1 = cw * 0.93, y0 = ch * (tall ? 0.88 : 0.84), y1 = ch * (wide ? 0.26 : tall ? 0.2 : 0.3);\nconst pts = CONFIG.points, max = Math.max(...pts) * 1.05, min = Math.min(...pts) * 0.8;\nconst P = pts.map((v, i) => [x0 + (x1 - x0) * (i / (pts.length - 1)), y0 - (y0 - y1) * ((v - min) / (max - min))]);\nlet d = `M${P[0]}`;\nfor (let i = 0; i < P.length - 1; i++) {\n  const a = P[i - 1] ?? P[i], b = P[i], c = P[i + 1], e = P[i + 2] ?? c;\n  d += ` C${b[0] + (c[0] - a[0]) / 6},${b[1] + (c[1] - a[1]) / 6} ${c[0] - (e[0] - b[0]) / 6},${c[1] - (e[1] - b[1]) / 6} ${c}`;\n}\nconst line = $('line'), area = $('area');\nline.setAttribute('d', d); area.setAttribute('d', `${d} L${x1},${y0} L${x0},${y0} Z`);\nObject.assign(line.style, { fill: 'none', stroke: accent, strokeWidth: `${SHORT * 0.006 * K}`, strokeLinecap: 'round', strokeLinejoin: 'round' });\n$('s0').setAttribute('stop-color', accent); $('s0').setAttribute('stop-opacity', '0.28'); $('s1').setAttribute('stop-color', accent); $('s1').setAttribute('stop-opacity', '0');\narea.style.fill = 'url(#fill)';\nconst clipr = $('clipr'); clipr.setAttribute('y', 0); clipr.setAttribute('height', ch); clipr.setAttribute('x', x0);\nconst grid = $('grid');\nfor (let g = 0; g <= 3; g++) { const y = y0 - (y0 - y1) * (g / 3); grid.insertAdjacentHTML('beforeend', `<line x1=\"${x0}\" x2=\"${x1}\" y1=\"${y}\" y2=\"${y}\" stroke=\"${muted}\" stroke-opacity=\"${g ? 0.15 : 0.5}\" stroke-width=\"1\"/>`); }\nCONFIG.labels.forEach((l, i) => { const t = document.createElement('div'); t.className = 'tick'; t.textContent = l; Object.assign(t.style, { left: `${x0 + (x1 - x0) * (i / (CONFIG.labels.length - 1))}px`, top: `${y0 + ch * 0.03}px`, transform: 'translateX(-50%)', font: `400 0.9em ${B.font('mono')}`, color: muted }); panel.append(t); });\nconst dot = $('dot'), halo = $('halo'), guide = $('guide');\ndot.setAttribute(\"r\", SHORT * 0.009 * K); dot.style.fill = accent;\nhalo.style.fill = 'none'; halo.style.stroke = accent; halo.style.strokeWidth = `${SHORT * 0.003 * K}`;\nconst peak = P[P.length - 1];\nguide.setAttribute('d', `M${x0},${peak[1]} L${peak[0]},${peak[1]}`);\nObject.assign(guide.style, { stroke: accent, strokeOpacity: 0.45, strokeWidth: '1.5', strokeDasharray: '6 8', fill: 'none' });\nconst tag = $('tag'); tag.textContent = CONFIG.tag;\nObject.assign(tag.style, { background: accent, color: ground, font: `500 1.25em ${B.font('mono')}`, boxShadow: `0 ${SHORT * 0.01}px ${SHORT * 0.03}px rgba(0,0,0,0.4)` });\ncam.place(panel, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\nconst L = line.getTotalLength(); line.style.strokeDasharray = `${L}`;\nconst tw = tag.offsetWidth, th = tag.offsetHeight;\nObject.assign(tag.style, { left: `${peak[0] - tw - ch * 0.04}px`, top: `${peak[1] - th - ch * 0.04}px` });\nconst GL = guide.getTotalLength(); guide.style.strokeDashoffset = '0';\n\nconst T = { draw: [0.6, 3.4], peak: 3.4 };\ns.update((t) => {\n  blurIn(title, t, { start: 0.3, duration: 0.6 });\n  const p = progress(t, ...T.draw, ease.inOutSine);\n  line.style.strokeDashoffset = `${L * (1 - p)}`;\n  const tip = line.getPointAtLength(Math.max(0.01, L * p));\n  clipr.setAttribute('width', Math.max(0, tip.x - x0));\n  dot.setAttribute('cx', tip.x); dot.setAttribute('cy', tip.y); dot.style.opacity = String(progress(t, T.draw[0], T.draw[0] + 0.2));\n  // the peak: a ring rings out from the dot, the guide draws back to the axis, the tag pops\n  const ring = progress(t, T.peak, T.peak + 0.9, ease.outCubic);\n  halo.setAttribute('cx', tip.x); halo.setAttribute('cy', tip.y); halo.setAttribute('r', SHORT * K * (0.012 + 0.05 * ring));\n  halo.style.opacity = String(t >= T.peak ? 1 - ring : 0);\n  const g = progress(t, T.peak + 0.1, T.peak + 0.6, ease.outCubic);\n  guide.style.clipPath = `inset(0 0 0 ${(1 - g) * 100}%)`; guide.style.opacity = g ? '1' : '0';\n  const pop = t >= T.peak + 0.15 ? spring(t - T.peak - 0.15, { stiffness: 260, damping: 13 }) : 0;\n  tag.style.transform = `scale(${pop})`; tag.style.transformOrigin = '100% 100%';\n  // the camera: close on the tip as it travels, then back to see the whole climb\n  const arrive = progress(t, 0, 0.7, ease.outCubic), back = progress(t, T.peak, D - 0.3, ease.inOutCubic), follow = progress(t, 0.2, 1.0, ease.inOutCubic) * (1 - back);\n  if (!wide) cam.at({ x: (tip.x - cw / 2) * follow, y: (tip.y - ch / 2) * follow, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * (tall ? 1.2 : 1.3) * follow - SHORT * 0.25 * back, yaw: -6 * (1 - arrive) + 4 * follow, pitch: 2 * follow });\n  else\n  cam.at({ x: (tip.x - cw / 2) * follow + (cw * 0.1) * back, y: (tip.y - ch / 2) * follow + (-ch * 0.02) * back, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * 1.3 * follow - SHORT * 0.4 * back, yaw: -6 * (1 - arrive) + 4 * follow, pitch: 2 * follow });\n  panel.style.opacity = String(progress(t, 0, 0.3));\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.draw[0]); B.cue(s, 'land', T.peak);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/line-draw/brief.md",
      "content": "# Line draw\n\nBlock: line-draw (5.5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA trend line draws with a dot riding its tip and the camera close on it; at the peak a label pops and the camera pulls back on the climb.\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.7 and 3.4 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add line-draw --name my-line-draw\n# edit CONFIG in pieces/my-line-draw/scene.html, then:\nnpx paper-motion render pieces/my-line-draw/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": [
    "bar-grow",
    "donut-fill"
  ],
  "preview": {
    "video": "previews/line-draw.webm",
    "poster": "previews/line-draw.jpg",
    "at": 5.3,
    "values": {}
  },
  "mood": [
    "bold",
    "calm"
  ],
  "duration": 5.5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.7,
      "what": "arrive"
    },
    {
      "name": "Draw",
      "from": 0.6,
      "to": 3.4,
      "what": "draw"
    },
    {
      "name": "Peak",
      "from": 3.4,
      "to": 4,
      "what": "peak"
    },
    {
      "name": "Pull back",
      "from": 3.4,
      "to": 5.2,
      "what": "pull back"
    }
  ],
  "when": [
    "a curve that keeps climbing",
    "momentum"
  ],
  "needs": [
    {
      "kind": "series",
      "fill": {
        "title": "$title",
        "points": {
          "$col": [
            "points",
            1
          ]
        },
        "labels": {
          "$col": [
            "points",
            0
          ]
        },
        "tag": "$tag"
      }
    }
  ]
}