{"spec_id":"chessboard-basic","library":"muix","language":"javascript","code":"// anyplot.ai\n// chessboard-basic: Chess Board Grid Visualization\n// Library: muix 9.16.0 | JavaScript 22.23.3\n// Quality: 79/100 | Updated: 2026-10-24\n//# anyplot-orientation: square\nimport { ChartsContainer } from \"@mui/x-charts/ChartsContainer\";\nimport { ChartsXAxis } from \"@mui/x-charts/ChartsXAxis\";\nimport { ChartsYAxis } from \"@mui/x-charts/ChartsYAxis\";\nimport { useDrawingArea, useXScale, useYScale } from \"@mui/x-charts/hooks\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst HEADER_H = 96;\nconst AXIS_SIZE = 48;\nconst PAD = 20;\nconst SQUARE_COLOR = { light: t.amber, dark: t.palette[3] }; // light and dark wood\n\n// Data: board size, files are labelled a, b, c, … and ranks 1, 2, 3, …\nconst N_FILES = 8;\nconst N_RANKS = 8;\n\n// Plot: reads only the parameters and the constants above\nconst files = Array.from({ length: N_FILES }, (_, i) => String.fromCharCode(97 + i));\nconst ranksTopToBottom = Array.from({ length: N_RANKS }, (_, i) => String(N_RANKS - i));\n\n// a1 is dark, so a square is light when file index + rank is even (h1 and a8 light)\nconst squares = ranksTopToBottom.flatMap((rank) =>\n  files.map((file, fIdx) => ({\n    id: `${file}${rank}`,\n    file,\n    rank,\n    fill: (fIdx + Number(rank)) % 2 === 0 ? SQUARE_COLOR.light : SQUARE_COLOR.dark,\n  })),\n);\n\nconst TITLE = \"chessboard-basic · javascript · muix · anyplot.ai\";\nconst SUBTITLE = `${squares.length} squares (${files.length}×${ranksTopToBottom.length}) · Algebraic notation (${files[0]}–${files[files.length - 1]}, ${ranksTopToBottom[ranksTopToBottom.length - 1]}–${ranksTopToBottom[0]})`;\n\nfunction BoardLayer() {\n  const xScale = useXScale(\"file\");\n  const yScale = useYScale(\"rank\");\n  const { left, top, width, height } = useDrawingArea();\n  const cellW = xScale.bandwidth();\n  const cellH = yScale.bandwidth();\n\n  return (\n    <g>\n      {squares.map((sq) => (\n        <rect\n          key={sq.id}\n          x={xScale(sq.file)}\n          y={yScale(sq.rank)}\n          width={cellW}\n          height={cellH}\n          fill={sq.fill}\n          stroke={t.pageBg}\n          strokeWidth={1.5}\n        />\n      ))}\n      <rect\n        x={left}\n        y={top}\n        width={width}\n        height={height}\n        fill=\"none\"\n        stroke={t.ink}\n        strokeWidth={3}\n      />\n    </g>\n  );\n}\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n  const availH = height - HEADER_H;\n  const containerSide = Math.min(width, availH);\n\n  return (\n    <div\n      style={{\n        width,\n        height,\n        background: t.pageBg,\n        fontFamily: \"Inter, system-ui, sans-serif\",\n        display: \"flex\",\n        flexDirection: \"column\",\n        alignItems: \"center\",\n      }}\n    >\n      <div\n        style={{\n          height: HEADER_H,\n          display: \"flex\",\n          flexDirection: \"column\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n          gap: 6,\n          paddingTop: 6,\n        }}\n      >\n        <div style={{ fontSize: 22, fontWeight: 600, color: t.ink }}>\n          {TITLE}\n        </div>\n        <div style={{ fontSize: 15, color: t.inkSoft }}>{SUBTITLE}</div>\n      </div>\n\n      <ChartsContainer\n        width={containerSide}\n        height={containerSide}\n        margin={{ top: PAD, right: PAD, bottom: PAD, left: PAD }}\n        skipAnimation\n        series={[]}\n        xAxis={[\n          {\n            id: \"file\",\n            scaleType: \"band\",\n            data: files,\n            categoryGapRatio: 0,\n            height: AXIS_SIZE,\n            disableLine: true,\n            disableTicks: true,\n            tickLabelStyle: {\n              fontSize: 16,\n              fontWeight: 600,\n              fill: t.inkSoft,\n            },\n          },\n        ]}\n        yAxis={[\n          {\n            id: \"rank\",\n            scaleType: \"band\",\n            data: ranksTopToBottom,\n            categoryGapRatio: 0,\n            width: AXIS_SIZE,\n            disableLine: true,\n            disableTicks: true,\n            tickLabelStyle: {\n              fontSize: 16,\n              fontWeight: 600,\n              fill: t.inkSoft,\n            },\n          },\n        ]}\n      >\n        <BoardLayer />\n        <ChartsXAxis axisId=\"file\" />\n        <ChartsYAxis axisId=\"rank\" />\n      </ChartsContainer>\n    </div>\n  );\n}\n"}