{"spec_id":"alluvial-opinion-flow","library":"muix","language":"javascript","code":"// anyplot.ai\n// alluvial-opinion-flow: Opinion Flow Diagram\n// Library: muix 9.16.0 | JavaScript 22.23.3\n// Quality: 90/100 | Updated: 2026-10-24\nimport * as React from \"react\";\nimport { ChartsContainer } from \"@mui/x-charts/ChartsContainer\";\nimport { ChartsXAxis } from \"@mui/x-charts/ChartsXAxis\";\nimport { useXScale, useYScale } from \"@mui/x-charts/hooks\";\n\nconst t = window.ANYPLOT_TOKENS;\nconst INK_MUTED = window.ANYPLOT_THEME === \"dark\" ? \"#A8A79F\" : \"#6B6A63\";\n\n// Constants\nconst NODE_W = 24;\nconst GAP_SHARE = 0.08; // vertical gap between category blocks as a share of total wave count\n\n// Columns: set these to your data's column names\nconst WAVE = \"Survey wave\"; // role: wave\nconst NEXT_WAVE = \"Next wave\"; // role: extra\nconst SOURCE_CATEGORY = \"Source opinion\"; // role: source_category\nconst TARGET_CATEGORY = \"Target opinion\"; // role: target_category\nconst FLOW_COUNT = \"Respondents\"; // role: flow_count\n\n// Data: replace this block with your own records, one object per row\nconst data = [\n  // Q1 2025 -> Q2 2025\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 110 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 30 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 10 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 60 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 180 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 40 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 15 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 5 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 25 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 35 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 140 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 70 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 30 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 3 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 3 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 20 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 80 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 44 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 10 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 15 },\n  { [WAVE]: \"Q1 2025\", [NEXT_WAVE]: \"Q2 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 71 },\n  // Q2 2025 -> Q3 2025\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 160 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 30 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 10 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 70 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 150 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 20 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 8 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 25 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 15 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 100 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 60 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 20 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 3 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 3 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 20 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 110 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 44 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 10 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 22 },\n  { [WAVE]: \"Q2 2025\", [NEXT_WAVE]: \"Q3 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 114 },\n  // Q3 2025 -> Q4 2025\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 220 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 30 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 10 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 90 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 90 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 12 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 6 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Satisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 8 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 20 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 80 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 40 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Neutral\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 12 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 8 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 15 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 125 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 50 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Satisfied\", [FLOW_COUNT]: 2 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Neutral\", [FLOW_COUNT]: 3 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Dissatisfied\", [FLOW_COUNT]: 19 },\n  { [WAVE]: \"Q3 2025\", [NEXT_WAVE]: \"Q4 2025\", [SOURCE_CATEGORY]: \"Very Dissatisfied\", [TARGET_CATEGORY]: \"Very Dissatisfied\", [FLOW_COUNT]: 156 },\n];\n\n// Plot: reads only data and the constants above\nconst categories = [\n  ...new Set([\n    ...data.map((d) => d[SOURCE_CATEGORY]),\n    ...data.map((d) => d[TARGET_CATEGORY]),\n  ]),\n];\nconst waves = [\n  ...new Set([\n    ...data.map((d) => d[WAVE]),\n    ...data.map((d) => d[NEXT_WAVE]),\n  ]),\n];\n\n// Ordered sentiment ramp: good pole (t.seq[0] = #009E73) -> neutral midpoint (INK_MUTED) -> bad pole (t.div[0] = #AE3030)\nconst posPole = parseInt(t.seq[0].slice(1), 16);\nconst midPole = parseInt(INK_MUTED.slice(1), 16);\nconst negPole = parseInt(t.div[0].slice(1), 16);\nconst categoryColor: Record<string, string> = {};\ncategories.forEach((cat, i) => {\n  const u = categories.length > 1 ? i / (categories.length - 1) : 0;\n  const fromHex = u <= 0.5 ? posPole : midPole;\n  const toHex = u <= 0.5 ? midPole : negPole;\n  const mix = u <= 0.5 ? u * 2 : (u - 0.5) * 2;\n  const hex = [16, 8, 0]\n    .map((shift) => {\n      const a = (fromHex >> shift) & 255;\n      const b = (toHex >> shift) & 255;\n      return Math.round(a + (b - a) * mix)\n        .toString(16)\n        .padStart(2, \"0\");\n    })\n    .join(\"\");\n  categoryColor[cat] = `#${hex}`;\n});\n\nconst populations = waves.map((wave, idx) => {\n  const pop: Record<string, number> = {};\n  categories.forEach((cat) => {\n    if (idx < waves.length - 1) {\n      pop[cat] = data\n        .filter((d) => d[WAVE] === wave && d[SOURCE_CATEGORY] === cat)\n        .reduce((sum, d) => sum + d[FLOW_COUNT], 0);\n    } else {\n      const prevWave = waves[idx - 1];\n      pop[cat] = data\n        .filter((d) => d[WAVE] === prevWave && d[TARGET_CATEGORY] === cat)\n        .reduce((sum, d) => sum + d[FLOW_COUNT], 0);\n    }\n  });\n  return pop;\n});\n\nconst waveTotals = waves.map((wave) =>\n  Math.max(\n    data.filter((d) => d[WAVE] === wave).reduce((sum, d) => sum + d[FLOW_COUNT], 0),\n    data.filter((d) => d[NEXT_WAVE] === wave).reduce((sum, d) => sum + d[FLOW_COUNT], 0),\n  ),\n);\nconst stackTotal = Math.max(...waveTotals);\nconst minWaveTotal = Math.min(...waveTotals);\nconst gapUnits =\n  categories.length > 1\n    ? (stackTotal * GAP_SHARE) / (categories.length - 1)\n    : 0;\nconst domainMax = stackTotal + gapUnits * (categories.length - 1);\n\nconst nodeExtents = populations.map((pop) => {\n  let cursor = domainMax;\n  const extents: Record<string, { top: number; bottom: number; value: number }> = {};\n  categories.forEach((cat) => {\n    const val = pop[cat];\n    const bottom = cursor - val;\n    extents[cat] = { top: cursor, bottom, value: val };\n    cursor = bottom - gapUnits;\n  });\n  return extents;\n});\n\nconst flows: {\n  step: number;\n  source: string;\n  target: string;\n  count: number;\n  stable: boolean;\n  srcTop: number;\n  srcBottom: number;\n  dstTop: number;\n  dstBottom: number;\n}[] = [];\n\nfor (let step = 0; step < waves.length - 1; step += 1) {\n  const w = waves[step];\n  const outCursor: Record<string, number> = {};\n  const inCursor: Record<string, number> = {};\n  categories.forEach((cat) => {\n    outCursor[cat] = nodeExtents[step][cat].top;\n    inCursor[cat] = nodeExtents[step + 1][cat].top;\n  });\n  categories.forEach((from) => {\n    categories.forEach((to) => {\n      const count = data\n        .filter(\n          (d) =>\n            d[WAVE] === w &&\n            d[SOURCE_CATEGORY] === from &&\n            d[TARGET_CATEGORY] === to,\n        )\n        .reduce((s, d) => s + d[FLOW_COUNT], 0);\n      if (count <= 0) return;\n      const srcTop = outCursor[from];\n      const srcBottom = srcTop - count;\n      outCursor[from] = srcBottom;\n      const dstTop = inCursor[to];\n      const dstBottom = dstTop - count;\n      inCursor[to] = dstBottom;\n      flows.push({\n        step,\n        source: from,\n        target: to,\n        count,\n        stable: from === to,\n        srcTop,\n        srcBottom,\n        dstTop,\n        dstBottom,\n      });\n    });\n  });\n}\n\nfunction OpinionFlowLayer() {\n  const xScale = useXScale();\n  const yScale = useYScale();\n  return (\n    <g data-drawing-container>\n      {flows.map((f, i) => {\n        const x1 = xScale(waves[f.step]) + NODE_W / 2;\n        const x2 = xScale(waves[f.step + 1]) - NODE_W / 2;\n        const midX = (x1 + x2) / 2;\n        const ySrcTop = yScale(f.srcTop);\n        const ySrcBottom = yScale(f.srcBottom);\n        const yDstTop = yScale(f.dstTop);\n        const yDstBottom = yScale(f.dstBottom);\n        return (\n          <path\n            key={`flow-${i}`}\n            d={`M ${x1} ${ySrcTop} C ${midX} ${ySrcTop}, ${midX} ${yDstTop}, ${x2} ${yDstTop} L ${x2} ${yDstBottom} C ${midX} ${yDstBottom}, ${midX} ${ySrcBottom}, ${x1} ${ySrcBottom} Z`}\n            fill={categoryColor[f.source]}\n            fillOpacity={f.stable ? 0.58 : 0.18}\n          />\n        );\n      })}\n      {waves.map((wave, wIdx) => {\n        const cx = xScale(wave);\n        const isLast = wIdx === waves.length - 1;\n        return categories.map((cat) => {\n          const ext = nodeExtents[wIdx][cat];\n          if (ext.value <= 0) return null;\n          const yTop = yScale(ext.top);\n          const yBottom = yScale(ext.bottom);\n          const midY = (yTop + yBottom) / 2;\n          const delta = isLast ? ext.value - populations[0][cat] : 0;\n          const lx = cx + NODE_W / 2 + 10;\n          const labelText = `${cat} (${ext.value})`;\n          const pillW = labelText.length * 8.2 + 14;\n          return (\n            <React.Fragment key={`${wave}-${cat}`}>\n              <rect\n                x={cx - NODE_W / 2}\n                y={yTop}\n                width={NODE_W}\n                height={Math.max(2, yBottom - yTop)}\n                fill={categoryColor[cat]}\n                rx={3}\n              />\n              {!isLast && (\n                <rect\n                  x={lx - 6}\n                  y={midY - 12}\n                  width={pillW}\n                  height={22}\n                  rx={4}\n                  fill={t.pageBg}\n                  fillOpacity={0.86}\n                />\n              )}\n              <text\n                x={lx}\n                y={isLast ? midY - 4 : midY + 4}\n                textAnchor=\"start\"\n                fontSize={14}\n                fontWeight={600}\n                fill={t.ink}\n              >\n                {labelText}\n              </text>\n              {isLast && (\n                <text\n                  x={lx}\n                  y={midY + 15}\n                  textAnchor=\"start\"\n                  fontSize={14}\n                  fontWeight={600}\n                  fill={t.inkSoft}\n                >\n                  <tspan fill={categoryColor[cat]}>{delta >= 0 ? \"▲\" : \"▼\"}</tspan>\n                  {delta >= 0 ? ` +${delta} vs ${waves[0]}` : ` ${delta} vs ${waves[0]}`}\n                </text>\n              )}\n            </React.Fragment>\n          );\n        });\n      })}\n    </g>\n  );\n}\n\nconst TITLE = \"alluvial-opinion-flow · javascript · muix · anyplot.ai\";\nconst countText =\n  minWaveTotal === stackTotal\n    ? stackTotal.toLocaleString(\"en-US\")\n    : `${minWaveTotal.toLocaleString(\"en-US\")}–${stackTotal.toLocaleString(\"en-US\")}`;\nconst SUBTITLE = `${FLOW_COUNT}: ${countText} · ${WAVE}: ${waves[0]}–${waves[waves.length - 1]}`;\nconst HEADER_H = 104;\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n\n  return (\n    <div\n      style={{\n        width,\n        height,\n        backgroundColor: t.pageBg,\n        display: \"flex\",\n        flexDirection: \"column\",\n        fontFamily:\n          '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif',\n      }}\n    >\n      <div\n        style={{\n          height: HEADER_H,\n          padding: \"14px 40px 0 40px\",\n          display: \"flex\",\n          flexDirection: \"column\",\n          alignItems: \"center\",\n          boxSizing: \"border-box\",\n        }}\n      >\n        <div\n          style={{\n            fontSize: 22,\n            fontWeight: 600,\n            color: t.ink,\n            lineHeight: 1.25,\n          }}\n        >\n          {TITLE}\n        </div>\n        <div\n          style={{\n            fontSize: 15,\n            color: t.inkSoft,\n            marginTop: 4,\n          }}\n        >\n          {SUBTITLE}\n        </div>\n        <div\n          style={{\n            display: \"flex\",\n            alignItems: \"center\",\n            gap: 18,\n            marginTop: 6,\n            fontSize: 14,\n            color: t.inkSoft,\n          }}\n        >\n          {categories.map((cat) => (\n            <span\n              key={cat}\n              style={{ display: \"inline-flex\", alignItems: \"center\", gap: 6 }}\n            >\n              <span\n                style={{\n                  width: 12,\n                  height: 12,\n                  borderRadius: 3,\n                  backgroundColor: categoryColor[cat],\n                  display: \"inline-block\",\n                }}\n              />\n              <span>{cat}</span>\n            </span>\n          ))}\n          <span style={{ color: INK_MUTED }}>\n            · Bold ribbon = stable · Faint ribbon = changed · ▲▼ = net shift\n          </span>\n        </div>\n      </div>\n      <ChartsContainer\n        width={width}\n        height={height - HEADER_H}\n        series={[]}\n        margin={{ top: 10, right: 230, bottom: 24, left: 60 }}\n        xAxis={[\n          {\n            id: \"wave\",\n            scaleType: \"point\",\n            data: waves,\n            position: \"top\",\n            disableLine: true,\n            disableTicks: true,\n            height: 44,\n            tickLabelStyle: { fontSize: 15, fontWeight: 600, fill: t.inkSoft },\n          },\n        ]}\n        yAxis={[\n          {\n            id: \"count\",\n            scaleType: \"linear\",\n            min: 0,\n            max: domainMax,\n            position: \"none\",\n          },\n        ]}\n        skipAnimation\n      >\n        <ChartsXAxis />\n        <OpinionFlowLayer />\n      </ChartsContainer>\n    </div>\n  );\n}\n"}