{"spec_id":"scatter-basic","library":"muix","language":"javascript","code":"// anyplot.ai\n// scatter-basic: Basic Scatter Plot\n// Library: muix 9.17.0 | JavaScript 22.23.4\n// Quality: 84/100 | Updated: 2026-11-08\n\nimport { ScatterChart } from \"@mui/x-charts/ScatterChart\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst PAD_SHARE = 0.05; // axis padding on each side as a share of the data span\nconst POINT_ALPHA = 0.7; // moderate transparency so overlapping points read darker\n\n// Columns: set these to your data's column names\nconst HOURS = \"Weekly study hours (h)\"; // role: x\nconst SCORE = \"Final exam score (%)\"; // role: y\n\n// Data: replace this block with your own records, one object per row\n// 120 university students: self-logged weekly study hours against their final exam score.\nconst data = (() => {\n  let seed = 42;\n  const lcg = () => {\n    seed = (1664525 * seed + 1013904223) >>> 0;\n    return seed / 4294967296;\n  };\n  const randn = () => Math.sqrt(-2 * Math.log(lcg() + 1e-15)) * Math.cos(2 * Math.PI * lcg());\n  return Array.from({ length: 120 }, () => {\n    const hours = 2 + lcg() * 36;\n    const score = 28 + (hours / 40) * 58 + randn() * 11;\n    return {\n      [HOURS]: Math.round(hours * 10) / 10,\n      [SCORE]: Math.min(98, Math.max(12, Math.round(score * 10) / 10)),\n    };\n  });\n})();\n\n// Plot: reads only data and the constants above\nconst xs = data.map((d) => d[HOURS]);\nconst ys = data.map((d) => d[SCORE]);\nconst xPad = (Math.max(...xs) - Math.min(...xs)) * PAD_SHARE;\nconst yPad = (Math.max(...ys) - Math.min(...ys)) * PAD_SHARE;\n\nconst TITLE = \"scatter-basic · javascript · muix · anyplot.ai\";\nconst HEADER_HEIGHT = 64;\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n  return (\n    <div style={{ width, height, background: t.pageBg, display: \"flex\", flexDirection: \"column\" }}>\n      <div\n        style={{\n          height: HEADER_HEIGHT,\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n          fontSize: 22,\n          fontWeight: 600,\n          color: t.ink,\n        }}\n      >\n        {TITLE}\n      </div>\n      <ScatterChart\n        width={width}\n        height={height - HEADER_HEIGHT}\n        skipAnimation\n        hideLegend\n        grid={{ horizontal: true, vertical: true }}\n        margin={{ top: 16, right: 48, bottom: 16, left: 24 }}\n        series={[\n          {\n            id: \"observations\",\n            label: SCORE,\n            color: t.palette[0],\n            markerSize: 7,\n            data: data.map((d, i) => ({ id: i, x: d[HOURS], y: d[SCORE] })),\n            valueFormatter: (v) => (v ? `${HOURS}: ${v.x} · ${SCORE}: ${v.y}` : \"\"),\n          },\n        ]}\n        xAxis={[\n          {\n            min: Math.min(...xs) - xPad,\n            max: Math.max(...xs) + xPad,\n            label: HOURS,\n            tickNumber: 8,\n            height: 72,\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        yAxis={[\n          {\n            min: Math.min(...ys) - yPad,\n            max: Math.max(...ys) + yPad,\n            label: SCORE,\n            tickNumber: 6,\n            width: 76,\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        sx={{\n          \"& .MuiScatterChart-marker\": { fillOpacity: POINT_ALPHA },\n          \"& .MuiChartsGrid-line\": { stroke: t.grid, strokeWidth: 1 },\n          \"& .MuiChartsAxis-line\": { stroke: t.inkSoft },\n          \"& .MuiChartsAxis-tick\": { stroke: t.inkSoft },\n        }}\n      />\n    </div>\n  );\n}\n"}