{"spec_id":"icicle-basic","library":"muix","language":"javascript","code":"// anyplot.ai\n// icicle-basic: Basic Icicle Chart\n// Library: muix 9.16.0 | JavaScript 22.23.3\n// Quality: 83/100 | Updated: 2026-10-24\n\nimport { ChartsContainer } from \"@mui/x-charts/ChartsContainer\";\nimport { useDrawingArea } from \"@mui/x-charts/hooks\";\nimport { getLuminance } from \"@mui/material/styles\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst FONT = '\"Plus Jakarta Sans\", \"Inter\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst MONO = '\"JetBrains Mono\", \"SFMono-Regular\", Menlo, monospace';\nconst ROOT_FILL = \"#6E6A61\";\nconst FIXED_DARK_TEXT = \"#1A1A17\";\nconst FIXED_LIGHT_TEXT = \"#FAF8F1\";\nconst TINT_STEP = 0.24;\nconst ROW_GUTTER = 5;\nconst COL_GUTTER = 2;\nconst LABEL_FONT_SIZE = [20, 16, 15, 14];\nconst SUBLABEL_FONT_SIZE = 14;\nconst CHAR_WIDTH_RATIO = 0.56;\n\n// Columns: set these to your data's column names\nconst ID = \"Node path\"; // role: id\nconst NAME = \"Node name\"; // role: name\nconst PARENT = \"Parent path\"; // role: parent\nconst VALUE = \"Size (KB)\"; // role: value\n\n// Data: replace this block with your own records\nconst data: Array<{\n  [ID]: string;\n  [NAME]: string;\n  [PARENT]: string;\n  [VALUE]: number;\n}> = [\n  { [ID]: \"repo/\", [NAME]: \"repo/\", [PARENT]: \"\", [VALUE]: 0 },\n  // Top-level directories\n  { [ID]: \"repo/dist/\", [NAME]: \"dist/\", [PARENT]: \"repo/\", [VALUE]: 0 },\n  { [ID]: \"repo/src/\", [NAME]: \"src/\", [PARENT]: \"repo/\", [VALUE]: 0 },\n  { [ID]: \"repo/tests/\", [NAME]: \"tests/\", [PARENT]: \"repo/\", [VALUE]: 0 },\n  { [ID]: \"repo/docs/\", [NAME]: \"docs/\", [PARENT]: \"repo/\", [VALUE]: 0 },\n  // Subdirectories under dist/ (build output)\n  { [ID]: \"repo/dist/js/\", [NAME]: \"js/\", [PARENT]: \"repo/dist/\", [VALUE]: 0 },\n  { [ID]: \"repo/dist/assets/\", [NAME]: \"assets/\", [PARENT]: \"repo/dist/\", [VALUE]: 0 },\n  { [ID]: \"repo/dist/fonts/\", [NAME]: \"fonts/\", [PARENT]: \"repo/dist/\", [VALUE]: 0 },\n  { [ID]: \"repo/dist/css/\", [NAME]: \"css/\", [PARENT]: \"repo/dist/\", [VALUE]: 0 },\n  // Subdirectories under src/\n  { [ID]: \"repo/src/components/\", [NAME]: \"components/\", [PARENT]: \"repo/src/\", [VALUE]: 0 },\n  { [ID]: \"repo/src/utils/\", [NAME]: \"utils/\", [PARENT]: \"repo/src/\", [VALUE]: 0 },\n  { [ID]: \"repo/src/styles/\", [NAME]: \"styles/\", [PARENT]: \"repo/src/\", [VALUE]: 0 },\n  // Subdirectories under tests/\n  { [ID]: \"repo/tests/unit/\", [NAME]: \"unit/\", [PARENT]: \"repo/tests/\", [VALUE]: 0 },\n  { [ID]: \"repo/tests/integration/\", [NAME]: \"integration/\", [PARENT]: \"repo/tests/\", [VALUE]: 0 },\n  // Subdirectories under docs/\n  { [ID]: \"repo/docs/guides/\", [NAME]: \"guides/\", [PARENT]: \"repo/docs/\", [VALUE]: 0 },\n  { [ID]: \"repo/docs/reference/\", [NAME]: \"reference/\", [PARENT]: \"repo/docs/\", [VALUE]: 0 },\n  // Files under js/\n  { [ID]: \"repo/dist/js/vendor.js\", [NAME]: \"vendor.js\", [PARENT]: \"repo/dist/js/\", [VALUE]: 180 },\n  { [ID]: \"repo/dist/js/polyfills.js\", [NAME]: \"polyfills.js\", [PARENT]: \"repo/dist/js/\", [VALUE]: 60 },\n  { [ID]: \"repo/dist/js/main.js\", [NAME]: \"main.js\", [PARENT]: \"repo/dist/js/\", [VALUE]: 80 },\n  // Files under assets/\n  { [ID]: \"repo/dist/assets/hero.webp\", [NAME]: \"hero.webp\", [PARENT]: \"repo/dist/assets/\", [VALUE]: 140 },\n  { [ID]: \"repo/dist/assets/logo.png\", [NAME]: \"logo.png\", [PARENT]: \"repo/dist/assets/\", [VALUE]: 90 },\n  { [ID]: \"repo/dist/assets/icons.svg\", [NAME]: \"icons.svg\", [PARENT]: \"repo/dist/assets/\", [VALUE]: 50 },\n  // Files under fonts/\n  { [ID]: \"repo/dist/fonts/inter.woff2\", [NAME]: \"inter.woff2\", [PARENT]: \"repo/dist/fonts/\", [VALUE]: 120 },\n  { [ID]: \"repo/dist/fonts/jakarta.woff2\", [NAME]: \"jakarta.woff2\", [PARENT]: \"repo/dist/fonts/\", [VALUE]: 70 },\n  { [ID]: \"repo/dist/fonts/mono.woff2\", [NAME]: \"mono.woff2\", [PARENT]: \"repo/dist/fonts/\", [VALUE]: 60 },\n  // Files under css/\n  { [ID]: \"repo/dist/css/main.css\", [NAME]: \"main.css\", [PARENT]: \"repo/dist/css/\", [VALUE]: 55 },\n  { [ID]: \"repo/dist/css/vendor.css\", [NAME]: \"vendor.css\", [PARENT]: \"repo/dist/css/\", [VALUE]: 45 },\n  // Files under components/\n  { [ID]: \"repo/src/components/Button.tsx\", [NAME]: \"Button.tsx\", [PARENT]: \"repo/src/components/\", [VALUE]: 90 },\n  { [ID]: \"repo/src/components/Modal.tsx\", [NAME]: \"Modal.tsx\", [PARENT]: \"repo/src/components/\", [VALUE]: 110 },\n  { [ID]: \"repo/src/components/Chart.tsx\", [NAME]: \"Chart.tsx\", [PARENT]: \"repo/src/components/\", [VALUE]: 80 },\n  // Files under utils/\n  { [ID]: \"repo/src/utils/format.ts\", [NAME]: \"format.ts\", [PARENT]: \"repo/src/utils/\", [VALUE]: 100 },\n  { [ID]: \"repo/src/utils/api.ts\", [NAME]: \"api.ts\", [PARENT]: \"repo/src/utils/\", [VALUE]: 90 },\n  // Files under styles/\n  { [ID]: \"repo/src/styles/theme.css\", [NAME]: \"theme.css\", [PARENT]: \"repo/src/styles/\", [VALUE]: 75 },\n  { [ID]: \"repo/src/styles/globals.css\", [NAME]: \"globals.css\", [PARENT]: \"repo/src/styles/\", [VALUE]: 55 },\n  // Files under unit/\n  { [ID]: \"repo/tests/unit/button.test.ts\", [NAME]: \"button.test.ts\", [PARENT]: \"repo/tests/unit/\", [VALUE]: 100 },\n  { [ID]: \"repo/tests/unit/utils.test.ts\", [NAME]: \"utils.test.ts\", [PARENT]: \"repo/tests/unit/\", [VALUE]: 90 },\n  // Files under integration/\n  { [ID]: \"repo/tests/integration/api.test.ts\", [NAME]: \"api.test.ts\", [PARENT]: \"repo/tests/integration/\", [VALUE]: 85 },\n  { [ID]: \"repo/tests/integration/flow.test.ts\", [NAME]: \"flow.test.ts\", [PARENT]: \"repo/tests/integration/\", [VALUE]: 75 },\n  // Files under guides/\n  { [ID]: \"repo/docs/guides/getting-started.md\", [NAME]: \"getting-started.md\", [PARENT]: \"repo/docs/guides/\", [VALUE]: 70 },\n  { [ID]: \"repo/docs/guides/deployment.md\", [NAME]: \"deployment.md\", [PARENT]: \"repo/docs/guides/\", [VALUE]: 60 },\n  // Files under reference/\n  { [ID]: \"repo/docs/reference/api-reference.md\", [NAME]: \"api-reference.md\", [PARENT]: \"repo/docs/reference/\", [VALUE]: 70 },\n];\n\n// Plot: reads only data and the constants above\nconst unitMatch = VALUE.match(/\\(([^)]+)\\)/);\nconst valueUnit = unitMatch ? unitMatch[1] : \"\";\nconst unitSuffix = valueUnit ? ` ${valueUnit}` : \"\";\n\ninterface IcicleNode {\n  id: string;\n  name: string;\n  parentId: string;\n  value: number;\n  depth: number;\n  childrenIds: string[];\n  branchColor: string;\n  x0Norm: number;\n  x1Norm: number;\n  fill: string;\n  textFill: string;\n  parentValue: number;\n}\n\nconst nodeById = new Map<string, IcicleNode>();\nfor (let i = 0; i < data.length; i += 1) {\n  const row = data[i];\n  nodeById.set(row[ID], {\n    id: row[ID],\n    name: row[NAME],\n    parentId: row[PARENT],\n    value: row[VALUE],\n    depth: 0,\n    childrenIds: [],\n    branchColor: ROOT_FILL,\n    x0Norm: 0,\n    x1Norm: 1,\n    fill: ROOT_FILL,\n    textFill: FIXED_LIGHT_TEXT,\n    parentValue: 0,\n  });\n}\n\nlet rootId = \"\";\nfor (let i = 0; i < data.length; i += 1) {\n  const row = data[i];\n  const node = nodeById.get(row[ID])!;\n  if (!node.parentId) {\n    rootId = node.id;\n  } else {\n    const parent = nodeById.get(node.parentId);\n    if (parent) parent.childrenIds.push(node.id);\n  }\n}\n\n// Topological BFS order from root\nconst bfsOrder: IcicleNode[] = [];\nconst queue: string[] = [rootId];\nwhile (queue.length > 0) {\n  const curId = queue.shift()!;\n  const cur = nodeById.get(curId)!;\n  bfsOrder.push(cur);\n  for (let c = 0; c < cur.childrenIds.length; c += 1) {\n    const child = nodeById.get(cur.childrenIds[c])!;\n    child.depth = cur.depth + 1;\n    queue.push(child.id);\n  }\n}\n\n// Bottom-up sum of leaf sizes\nfor (let i = bfsOrder.length - 1; i >= 0; i -= 1) {\n  const node = bfsOrder[i];\n  if (node.childrenIds.length > 0) {\n    let sum = 0;\n    for (let c = 0; c < node.childrenIds.length; c += 1) {\n      sum += nodeById.get(node.childrenIds[c])!.value;\n    }\n    node.value = sum;\n  }\n}\n\n// Top-down branch color assignment and normalized [0, 1] partition\nconst rootNode = nodeById.get(rootId)!;\nconst topDirs = rootNode.childrenIds.map((id, idx) => {\n  const dir = nodeById.get(id)!;\n  dir.branchColor = t.palette[idx];\n  return dir;\n});\n\nfor (let i = 0; i < bfsOrder.length; i += 1) {\n  const node = bfsOrder[i];\n  if (node.depth >= 2) {\n    const parent = nodeById.get(node.parentId)!;\n    node.branchColor = parent.branchColor;\n  }\n  if (node.parentId) {\n    node.parentValue = nodeById.get(node.parentId)!.value;\n  } else {\n    node.parentValue = node.value;\n  }\n\n  let cx = node.x0Norm;\n  const span = node.x1Norm - node.x0Norm;\n  for (let c = 0; c < node.childrenIds.length; c += 1) {\n    const child = nodeById.get(node.childrenIds[c])!;\n    const w = node.value > 0 ? (child.value / node.value) * span : 0;\n    child.x0Norm = cx;\n    child.x1Norm = cx + w;\n    cx += w;\n  }\n\n  // Tint the branch hue toward the warm paper per depth; label ink by luminance\n  const hex = node.depth === 0 ? ROOT_FILL : node.branchColor;\n  const hexInt = parseInt(hex.slice(1), 16);\n  const baseR = (hexInt >> 16) & 255;\n  const baseG = (hexInt >> 8) & 255;\n  const baseB = hexInt & 255;\n  const tintFactor = node.depth === 0 ? 0 : (node.depth - 1) * TINT_STEP;\n  const r = Math.round(baseR + (248 - baseR) * tintFactor);\n  const g = Math.round(baseG + (246 - baseG) * tintFactor);\n  const b = Math.round(baseB + (238 - baseB) * tintFactor);\n  node.fill = `rgb(${r}, ${g}, ${b})`;\n  node.textFill = getLuminance(node.fill) > 0.18 ? FIXED_DARK_TEXT : FIXED_LIGHT_TEXT;\n}\n\nconst maxDepth = Math.max(...bfsOrder.map((n) => n.depth));\nconst DEPTH_COUNT = maxDepth + 1;\nconst leafCount = bfsOrder.filter((n) => n.childrenIds.length === 0).length;\n\nfunction IcicleLayer() {\n  const { left, top, width, height } = useDrawingArea();\n  const rowH = height / DEPTH_COUNT;\n\n  return (\n    <g>\n      {bfsOrder.map((node) => {\n        const x = left + node.x0Norm * width + COL_GUTTER / 2;\n        const w = Math.max(0, (node.x1Norm - node.x0Norm) * width - COL_GUTTER);\n        const y = top + node.depth * rowH + ROW_GUTTER / 2;\n        const h = rowH - ROW_GUTTER;\n        const fontSize =\n          LABEL_FONT_SIZE[\n            Math.min(node.depth, LABEL_FONT_SIZE.length - 1)\n          ];\n\n        const labelText =\n          node.depth === 0\n            ? `${node.name} · ${node.value.toLocaleString()}${unitSuffix} total`\n            : node.name;\n        const subText =\n          node.depth === 0 ? \"\" : `${node.value.toLocaleString()}${unitSuffix}`;\n        const pct =\n          node.parentValue > 0\n            ? ((node.value / node.parentValue) * 100).toFixed(0)\n            : \"100\";\n\n        const showLabel =\n          w - 12 >= labelText.length * fontSize * CHAR_WIDTH_RATIO &&\n          h >= fontSize + 6;\n        const showSub =\n          showLabel &&\n          subText.length > 0 &&\n          h >= fontSize + SUBLABEL_FONT_SIZE + 12 &&\n          w - 12 >= subText.length * SUBLABEL_FONT_SIZE * CHAR_WIDTH_RATIO;\n\n        return (\n          <g key={node.id}>\n            <rect\n              x={x}\n              y={y}\n              width={w}\n              height={h}\n              fill={node.fill}\n              stroke={t.pageBg}\n              strokeWidth={1.5}\n              rx={2}\n            >\n              <title>\n                {node.id}: {node.value.toLocaleString()}\n                {unitSuffix} ({pct}% of parent)\n              </title>\n            </rect>\n            {showLabel && (\n              <text\n                x={x + 8}\n                y={y + fontSize + 5}\n                fontSize={fontSize}\n                fontWeight={showSub || node.depth <= 1 ? 600 : 500}\n                fill={node.textFill}\n                pointerEvents=\"none\"\n              >\n                {labelText}\n              </text>\n            )}\n            {showSub && (\n              <text\n                x={x + 8}\n                y={y + fontSize + SUBLABEL_FONT_SIZE + 9}\n                fontSize={SUBLABEL_FONT_SIZE}\n                fontFamily={MONO}\n                fill={node.textFill}\n                opacity={0.88}\n                pointerEvents=\"none\"\n              >\n                {subText}\n              </text>\n            )}\n          </g>\n        );\n      })}\n    </g>\n  );\n}\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n  const headerHeight = 84;\n  const chartHeight = height - headerHeight;\n\n  return (\n    <div\n      style={{\n        width,\n        height,\n        background: t.pageBg,\n        color: t.ink,\n        fontFamily: FONT,\n        display: \"flex\",\n        flexDirection: \"column\",\n        boxSizing: \"border-box\",\n      }}\n    >\n      <div\n        style={{\n          height: headerHeight,\n          padding: \"14px 28px 4px 28px\",\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"space-between\",\n          boxSizing: \"border-box\",\n        }}\n      >\n        <div>\n          <div\n            style={{\n              fontSize: 22,\n              fontWeight: 700,\n              color: t.ink,\n              lineHeight: 1.2,\n            }}\n          >\n            icicle-basic · javascript · muix · anyplot.ai\n          </div>\n          <div\n            style={{\n              fontSize: 14,\n              color: t.inkSoft,\n              marginTop: 4,\n              fontFamily: MONO,\n            }}\n          >\n            {DEPTH_COUNT} levels · {leafCount} leaves ·{\" \"}\n            {rootNode.value.toLocaleString()}\n            {unitSuffix} total · width ∝ {VALUE}\n          </div>\n        </div>\n\n        <div\n          style={{\n            display: \"flex\",\n            alignItems: \"center\",\n            gap: 20,\n            fontSize: 14,\n            color: t.ink,\n          }}\n        >\n          {topDirs.map((dir) => (\n            <div\n              key={dir.id}\n              style={{ display: \"flex\", alignItems: \"center\", gap: 8 }}\n            >\n              <span\n                style={{\n                  width: 14,\n                  height: 14,\n                  borderRadius: 3,\n                  background: dir.branchColor,\n                  display: \"inline-block\",\n                }}\n              />\n              <span>\n                <strong style={{ fontWeight: 600 }}>{dir.name}</strong>{\" \"}\n                <span style={{ color: t.inkSoft, fontFamily: MONO }}>\n                  ({dir.value.toLocaleString()}\n                  {unitSuffix})\n                </span>\n              </span>\n            </div>\n          ))}\n        </div>\n      </div>\n\n      <ChartsContainer\n        width={width}\n        height={chartHeight}\n        series={[]}\n        xAxis={[{ position: \"none\" }]}\n        yAxis={[{ position: \"none\" }]}\n        margin={{ top: 8, right: 24, bottom: 20, left: 24 }}\n        skipAnimation\n      >\n        <IcicleLayer />\n      </ChartsContainer>\n    </div>\n  );\n}\n"}