{"spec_id":"radar-innovation-timeline","library":"muix","language":"javascript","code":"// anyplot.ai\n// radar-innovation-timeline: Innovation Radar with Time-Horizon Rings\n// Library: muix 9.17.0 | JavaScript 22.23.4\n// Quality: 88/100 | Updated: 2026-11-08\n\nimport { ChartsDataProvider } from \"@mui/x-charts/ChartsDataProvider\";\nimport { ChartsWrapper } from \"@mui/x-charts/ChartsWrapper\";\nimport { ChartsSurface } from \"@mui/x-charts/ChartsSurface\";\nimport { ChartsLegend } from \"@mui/x-charts/ChartsLegend\";\nimport { ScatterPlot } from \"@mui/x-charts/ScatterChart\";\nimport { useXScale, useYScale } from \"@mui/x-charts/hooks\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst SPREAD = 0.28; // several items in one cell sit between this share and its complement of the ring band\nconst ARC_STEPS = 96; // segments per half-circle arc\nconst TITLE_H = 48;\nconst SUBTITLE_H = 28;\nconst LEGEND_H = 44;\nconst HEADER_PX = 52; // room above the outer ring for the sector headers\nconst BASE_PX = 44; // room below the baseline for the ring names\nconst SIDE_PX = 150; // room beside the half circle for the outermost sector headers\nconst MARKER_R = 8;\nconst LABEL_PX = 14; // item label font size\nconst CHAR_PX = 7.6; // approximate width of one label character at LABEL_PX\nconst HEADER_CHAR_PX = 10.6; // approximate width of one sector-header character at 18 px bold\n\n// Columns: set these to your data's column names\nconst NAME = \"Technology\"; // role: name\nconst HORIZON = \"Adoption horizon\"; // role: ring\nconst SECTOR = \"Domain\"; // role: sector\n\n// Data: replace this block with your own records, one object per row\n// Strategic technology planning: 25 technologies by expected adoption horizon (listed nearest first)\n// across four domains; most cells hold one or two items, as real radars cluster\nconst data = [\n  { [NAME]: \"LLM Fine-Tuning\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"AI Coding Assistants\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"Multimodal Agents\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"RAG Pipelines\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"On-Device Inference\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"Autonomous Coding Agents\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"Neuromorphic Chips\", [HORIZON]: \"Future (3+ yr)\", [SECTOR]: \"AI & ML\" },\n  { [NAME]: \"Serverless Functions\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"Edge Computing\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"Platform Engineering\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"WebAssembly Runtimes\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"Confidential Computing\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"Quantum-Safe Networking\", [HORIZON]: \"Future (3+ yr)\", [SECTOR]: \"Cloud Infra\" },\n  { [NAME]: \"Zero Trust Access\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"AI Threat Detection\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"Passwordless Auth\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"Passkeys Everywhere\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"Post-Quantum Crypto\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"Homomorphic Encryption\", [HORIZON]: \"Future (3+ yr)\", [SECTOR]: \"Security\" },\n  { [NAME]: \"Carbon-Aware IT\", [HORIZON]: \"Now (0–6 mo)\", [SECTOR]: \"Green Tech\" },\n  { [NAME]: \"Green Data Centers\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Green Tech\" },\n  { [NAME]: \"Grid-Scale Battery Storage\", [HORIZON]: \"Near-Term (6–18 mo)\", [SECTOR]: \"Green Tech\" },\n  { [NAME]: \"Circular Hardware\", [HORIZON]: \"Mid-Term (18–36 mo)\", [SECTOR]: \"Green Tech\" },\n  { [NAME]: \"Direct Air Capture\", [HORIZON]: \"Future (3+ yr)\", [SECTOR]: \"Green Tech\" },\n  { [NAME]: \"Fusion Energy Pilots\", [HORIZON]: \"Future (3+ yr)\", [SECTOR]: \"Green Tech\" },\n];\n\n// Plot: reads only data and the constants above\n// Rings in order of first appearance, nearest horizon innermost; sectors split the half circle evenly\nconst rings = [...new Set(data.map((d) => d[HORIZON]))];\nconst sectors = [...new Set(data.map((d) => d[SECTOR]))];\nconst sectorSpan = Math.PI / sectors.length;\n\n// Canvas geometry in px: the half circle sits on its baseline, one px-per-ring scale on both axes\nconst { width, height } = window.ANYPLOT_SIZE;\nconst svgH = height - TITLE_H - SUBTITLE_H - LEGEND_H;\nconst radiusPx = Math.min(svgH - HEADER_PX - BASE_PX, width / 2 - SIDE_PX);\nconst unit = radiusPx / rings.length;\nconst below = BASE_PX + (svgH - HEADER_PX - BASE_PX - radiusPx) / 2; // px from the bottom edge to the baseline\nconst cx = width / 2;\nconst cy = svgH - below;\n\n// Inside each (ring, sector) cell, n items fan out over the sector at (k + 1) / (n + 1) of its\n// angle and step outward across the ring band, so no item leaves its own cell. Positions are in\n// ring units: ring i spans radius i to i + 1, angle pi (left) to 0 (right).\nconst cellSize = new Map();\ndata.forEach((d) => {\n  const key = `${rings.indexOf(d[HORIZON])}:${sectors.indexOf(d[SECTOR])}`;\n  cellSize.set(key, (cellSize.get(key) ?? 0) + 1);\n});\nconst cellSeen = new Map();\nconst items = data.map((d) => {\n  const ring = rings.indexOf(d[HORIZON]);\n  const sector = sectors.indexOf(d[SECTOR]);\n  const key = `${ring}:${sector}`;\n  const n = cellSize.get(key);\n  const k = cellSeen.get(key) ?? 0;\n  cellSeen.set(key, k + 1);\n  const angle = Math.PI - (sector + (k + 1) / (n + 1)) * sectorSpan;\n  const radius = ring + (n === 1 ? 0.5 : SPREAD + ((1 - 2 * SPREAD) * k) / (n - 1));\n  const x = radius * Math.cos(angle);\n  const y = radius * Math.sin(angle);\n  return { name: d[NAME], sector, angle, x, y, px: cx + x * unit, py: cy - y * unit };\n});\n\n// Sector headers just outside the outer ring, at each sector's middle angle\nconst headers = sectors.map((sector, i) => {\n  const mid = Math.PI - (i + 0.5) * sectorSpan;\n  const cos = Math.cos(mid);\n  const anchor = cos > 0.25 ? \"start\" : cos < -0.25 ? \"end\" : \"middle\";\n  return { sector, x: cx + (radiusPx + 26) * cos, y: cy - (radiusPx + 26) * Math.sin(mid), anchor };\n});\n\n// Label placement: markers stay on their positions; each label takes, of the slots around its\n// marker (outer side first) that are free of markers, headers, ring names and earlier labels, the\n// first one that stays in its own sector and crosses the fewest ring arcs\nconst spokeAngles = Array.from({ length: sectors.length + 1 }, (_, i) => Math.PI - i * sectorSpan);\nconst obstacles = [\n  ...items.map((it, i) => ({ owner: i, box: [it.px - MARKER_R - 3, it.py - MARKER_R - 3, it.px + MARKER_R + 3, it.py + MARKER_R + 3] })),\n  ...headers.map((h) => {\n    const w = h.sector.length * HEADER_CHAR_PX;\n    const x0 = h.anchor === \"end\" ? h.x - w : h.anchor === \"middle\" ? h.x - w / 2 : h.x;\n    return { owner: -1, box: [x0, h.y - 13, x0 + w, h.y + 13] };\n  }),\n  { owner: -1, box: [0, cy + 6, width, svgH] }, // the ring names below the baseline\n];\nconst labels = items.map((it, i) => {\n  const w = it.name.length * CHAR_PX;\n  const out = Math.cos(it.angle) >= 0 ? 1 : -1;\n  const gap = MARKER_R + 6;\n  const slots = [\n    [out * gap, 0, out],\n    [0, -gap - 4, 0],\n    [0, gap + 4, 0],\n    [out * gap * 0.8, -gap, out],\n    [out * gap * 0.8, gap, out],\n    [-out * gap, 0, -out],\n    [-out * gap * 0.8, -gap, -out],\n    [-out * gap * 0.8, gap, -out],\n    // above and below, shifted outward by a quarter of the label so it clears a nearby spoke\n    [-out * w * 0.25, -gap - 4, out],\n    [-out * w * 0.25, gap + 4, out],\n  ].map(([dx, dy, side]) => {\n    const x0 = side > 0 ? it.px + dx : side < 0 ? it.px + dx - w : it.px - w / 2;\n    const box = [x0, it.py + dy - LABEL_PX / 2 - 2, x0 + w, it.py + dy + LABEL_PX / 2 + 2];\n    const clash = obstacles\n      .filter((o) => o.owner !== i)\n      .reduce((sum, { box: o }) => sum + Math.max(0, Math.min(box[2], o[2]) - Math.max(box[0], o[0])) * Math.max(0, Math.min(box[3], o[3]) - Math.max(box[1], o[1])), 0);\n    // The box corners relative to the centre (y up): a ring arc is crossed when its radius lies\n    // between the box's nearest and farthest point above the baseline, a spoke when the corners\n    // fall on both sides of it within its length\n    const corners = [[box[0], box[1]], [box[2], box[1]], [box[0], box[3]], [box[2], box[3]]].map(([x, y]) => [x - cx, cy - y]);\n    const near = Math.hypot(Math.max(box[0] - cx, 0, cx - box[2]), Math.max(box[1] - cy, 0, cy - box[3]));\n    const far = Math.max(...corners.map(([x, y]) => Math.hypot(x, y)));\n    const above = corners.some(([, y]) => y > 0);\n    const arcCrossings = above ? rings.filter((_, r) => near < (r + 1) * unit && (r + 1) * unit < far).length : 0;\n    const spokeCrossings = spokeAngles.filter((a) => {\n      const across = corners.map(([x, y]) => x * Math.sin(a) - y * Math.cos(a));\n      const along = corners.map(([x, y]) => x * Math.cos(a) + y * Math.sin(a));\n      return Math.min(...across) < 0 && Math.max(...across) > 0 && Math.max(...along) > 0 && Math.min(...along) < radiusPx;\n    }).length;\n    // A label reads as part of the sector its centre lies in, which can differ from its marker's\n    const centre = Math.atan2(cy - (box[1] + box[3]) / 2, (box[0] + box[2]) / 2 - cx);\n    const ownSector = centre <= Math.PI - it.sector * sectorSpan && centre >= Math.PI - (it.sector + 1) * sectorSpan;\n    return { dx, dy, anchor: side > 0 ? \"start\" : side < 0 ? \"end\" : \"middle\", box, clash, ownSector, lines: arcCrossings + spokeCrossings };\n  });\n  // A free slot centred in the marker's own sector always wins; among those, the fewest crossings\n  const free = slots.filter((s) => s.clash === 0);\n  const inSector = free.filter((s) => s.ownSector);\n  const pool = inSector.length > 0 ? inSector : free;\n  const best = pool.length > 0 ? pool.reduce((a, b) => (b.lines < a.lines ? b : a)) : slots.reduce((a, b) => (b.clash < a.clash ? b : a));\n  obstacles.push({ owner: -1, box: best.box });\n  return best;\n});\n\nconst series = sectors.map((s, i) => ({\n  type: \"scatter\",\n  id: `sector-${i}`,\n  label: s,\n  color: t.palette[i],\n  markerSize: MARKER_R,\n  labelMarkType: \"circle\",\n  data: items.filter((it) => it.sector === i).map((it) => ({ x: it.x, y: it.y, id: it.name })),\n}));\n\nconst TITLE = \"radar-innovation-timeline · javascript · muix · anyplot.ai\";\nconst SUBTITLE = `${data.length} items · ${rings.length} rings, nearest horizon at the center · ${sectors.length} sectors`;\n\nfunction RadarFrame() {\n  const xScale = useXScale();\n  const yScale = useYScale();\n  const ox = xScale(0);\n  const oy = yScale(0);\n  const at = (r, a) => [ox + r * Math.cos(a), oy - r * Math.sin(a)];\n  // Each boundary arc as points from the left end (angle pi) to the right end (angle 0)\n  const arcs = Array.from({ length: rings.length + 1 }, (_, i) =>\n    Array.from({ length: ARC_STEPS + 1 }, (_, s) => at(i * unit, Math.PI - (Math.PI * s) / ARC_STEPS)),\n  );\n\n  return (\n    <g>\n      {rings.map((ring, i) => (\n        <path\n          key={`band-${ring}`}\n          d={`M${[...arcs[i + 1], ...[...arcs[i]].reverse()].map((p) => p.join(\",\")).join(\" L\")} Z`}\n          fill={t.inkSoft}\n          fillOpacity={i % 2 === 0 ? 0.05 : 0.1}\n        />\n      ))}\n      {rings.map((ring, i) => (\n        <path\n          key={`ring-${ring}`}\n          d={`M${arcs[i + 1].map((p) => p.join(\",\")).join(\" L\")}`}\n          fill=\"none\"\n          stroke={i === rings.length - 1 ? t.inkSoft : t.grid}\n          strokeWidth={i === rings.length - 1 ? 2 : 1.5}\n        />\n      ))}\n      {Array.from({ length: sectors.length + 1 }, (_, i) => {\n        const [x, y] = at(radiusPx, Math.PI - i * sectorSpan);\n        return <line key={`spoke-${i}`} x1={ox} y1={oy} x2={x} y2={y} stroke={t.grid} strokeWidth={1.5} />;\n      })}\n      <line x1={ox - radiusPx} y1={oy} x2={ox + radiusPx} y2={oy} stroke={t.inkSoft} strokeWidth={2} />\n      {rings.map((ring, i) =>\n        [-1, 1].map((side) => (\n          <text\n            key={`ring-name-${ring}-${side}`}\n            x={ox + side * (i + 0.5) * unit}\n            y={oy + 26}\n            fontSize={14}\n            fontWeight={600}\n            fill={t.inkSoft}\n            textAnchor=\"middle\"\n          >\n            {ring}\n          </text>\n        )),\n      )}\n      {headers.map((h) => (\n        <text key={`header-${h.sector}`} x={h.x} y={h.y} fontSize={18} fontWeight={700} fill={t.ink} textAnchor={h.anchor} dominantBaseline=\"middle\">\n          {h.sector}\n        </text>\n      ))}\n      {items.map((it, i) => (\n        <text\n          key={`label-${it.name}`}\n          x={xScale(it.x) + labels[i].dx}\n          y={yScale(it.y) + labels[i].dy}\n          fontSize={LABEL_PX}\n          fill={t.ink}\n          textAnchor={labels[i].anchor}\n          dominantBaseline=\"central\"\n          stroke={t.pageBg}\n          strokeWidth={4}\n          paintOrder=\"stroke\"\n        >\n          {it.name}\n        </text>\n      ))}\n    </g>\n  );\n}\n\nexport default function Chart() {\n  return (\n    <div style={{ width, height, display: \"flex\", flexDirection: \"column\" }}>\n      <div style={{ height: TITLE_H, display: \"flex\", alignItems: \"flex-end\", justifyContent: \"center\", fontSize: 22, fontWeight: 600, color: t.ink }}>\n        {TITLE}\n      </div>\n      <div style={{ height: SUBTITLE_H, display: \"flex\", alignItems: \"center\", justifyContent: \"center\", fontSize: 15, color: t.inkSoft }}>\n        {SUBTITLE}\n      </div>\n      <ChartsDataProvider\n        width={width}\n        height={svgH}\n        skipAnimation\n        margin={{ top: 0, right: 0, bottom: 0, left: 0 }}\n        series={series}\n        xAxis={[{ scaleType: \"linear\", min: -cx / unit, max: (width - cx) / unit, position: \"none\" }]}\n        yAxis={[{ scaleType: \"linear\", min: -below / unit, max: (svgH - below) / unit, position: \"none\" }]}\n      >\n        <ChartsWrapper legendPosition={{ vertical: \"bottom\", horizontal: \"center\" }} legendDirection=\"horizontal\">\n          <ChartsLegend sx={{ fontSize: 16, color: t.ink, height: LEGEND_H, alignItems: \"center\" }} />\n          <ChartsSurface sx={{ \"& .MuiScatterChart-marker\": { stroke: t.pageBg, strokeWidth: 2 } }}>\n            <RadarFrame />\n            <ScatterPlot />\n          </ChartsSurface>\n        </ChartsWrapper>\n      </ChartsDataProvider>\n    </div>\n  );\n}\n"}