{"spec_id":"scatter-color-mapped","library":"muix","language":"javascript","code":"// anyplot.ai\n// scatter-color-mapped: Color-Mapped Scatter Plot\n// Library: muix 9.16.0 | JavaScript 22.23.3\n// Quality: 87/100 | Updated: 2026-10-23\n\nimport Box from \"@mui/material/Box\";\nimport Typography from \"@mui/material/Typography\";\nimport { ScatterChart } from \"@mui/x-charts/ScatterChart\";\nimport { ContinuousColorLegend } from \"@mui/x-charts/ChartsLegend\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Columns: set these to your data's column names\nconst X = \"Longitude (°E)\"; // role: x\nconst Y = \"Latitude (°N)\"; // role: y\nconst COLOR = \"Sea-surface temperature (°C)\"; // role: color\n\n// Data: replace this block with your own records, one object per row\n// Ocean buoy network: sea-surface temperature sampled across an open North\n// Atlantic survey box. A warm-core eddy near (30°W, 36°N) fades outward.\nconst data = (() => {\n  let seed = 42;\n  const nextRandom = () => {\n    seed = (Math.imul(seed, 1103515245) + 12345) & 0x7fffffff;\n    return seed / 0x7fffffff;\n  };\n\n  const stationCount = 160;\n  const rows: { [X]: number; [Y]: number; [COLOR]: number }[] = [];\n  for (let i = 0; i < stationCount; i += 1) {\n    const longitude = -40 + nextRandom() * 20;\n    const latitude = 25 + nextRandom() * 25;\n    const distanceFromCore = Math.hypot(longitude + 30, latitude - 36);\n    const temperature = 23 - 0.42 * distanceFromCore + (nextRandom() - 0.5) * 2.4;\n    rows.push({\n      [X]: Number(longitude.toFixed(2)),\n      [Y]: Number(latitude.toFixed(2)),\n      [COLOR]: Number(temperature.toFixed(2)),\n    });\n  }\n  return rows;\n})();\n\n// Plot: reads only data and the constants above\nconst buoys = data.map((row, i) => ({\n  id: i,\n  x: row[X],\n  y: row[Y],\n  z: row[COLOR],\n}));\n\nconst temperatures = buoys.map((buoy) => buoy.z);\nconst tempMin = Math.floor(Math.min(...temperatures) * 10) / 10;\nconst tempMax = Math.ceil(Math.max(...temperatures) * 10) / 10;\nconst legendLabel = ({ value }: { value: number | Date }) => `${Number(value).toFixed(1)}°C`;\n\nconst MARKER_ALPHA_HEX = \"E0\"; // ~0.88 opacity\n\nconst TITLE = \"scatter-color-mapped · javascript · muix · anyplot.ai\";\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n  const titleHeight = 64;\n\n  return (\n    <Box sx={{ width, height, bgcolor: t.pageBg, display: \"flex\", flexDirection: \"column\" }}>\n      <Typography\n        sx={{\n          color: t.ink,\n          fontSize: 22,\n          fontWeight: 600,\n          textAlign: \"center\",\n          lineHeight: 1.2,\n          pt: \"18px\",\n          height: titleHeight,\n          fontFamily: \"inherit\",\n        }}\n      >\n        {TITLE}\n      </Typography>\n      <Box sx={{ flex: 1, display: \"flex\", alignItems: \"center\", pr: \"32px\" }}>\n        <ScatterChart\n          width={width - 140}\n          height={height - titleHeight}\n          skipAnimation\n          disableHitArea\n          grid={{ horizontal: true, vertical: true }}\n          margin={{ top: 24, right: 24, bottom: 24, left: 40 }}\n          xAxis={[\n            {\n              id: \"longitude\",\n              height: 68,\n              label: X,\n              labelStyle: { fontSize: 18, fill: t.ink },\n              tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n              valueFormatter: (value: number) => `${value}°`,\n            },\n          ]}\n          yAxis={[\n            {\n              id: \"latitude\",\n              width: 84,\n              label: Y,\n              labelStyle: { fontSize: 18, fill: t.ink },\n              tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n              valueFormatter: (value: number) => `${value}°`,\n            },\n          ]}\n          zAxis={[\n            {\n              id: \"temperature\",\n              min: tempMin,\n              max: tempMax,\n              valueFormatter: (v: number) => `${Number(v).toFixed(1)}°C`,\n              colorMap: {\n                type: \"continuous\",\n                min: tempMin,\n                max: tempMax,\n                color: [`${t.seq[0]}${MARKER_ALPHA_HEX}`, `${t.seq[1]}${MARKER_ALPHA_HEX}`],\n              },\n            },\n          ]}\n          series={[\n            {\n              id: \"buoys\",\n              label: \"Ocean buoys\",\n              data: buoys,\n              markerSize: 9,\n              zAxisId: \"temperature\",\n              color: t.palette[0],\n            },\n          ]}\n          slots={{ legend: ContinuousColorLegend }}\n          slotProps={{\n            legend: {\n              axisId: \"temperature\",\n              axisDirection: \"z\",\n              direction: \"vertical\",\n              position: { vertical: \"middle\", horizontal: \"end\" },\n              thickness: 18,\n              minLabel: legendLabel,\n              maxLabel: legendLabel,\n              sx: {\n                height: \"65%\",\n                color: t.inkSoft,\n                fontSize: 15,\n                fontFamily: \"inherit\",\n              },\n            } as any,\n          }}\n          sx={{\n            \"& .MuiChartsGrid-line\": { stroke: t.grid, strokeWidth: 1 },\n            \"& .MuiChartsAxis-line\": { stroke: t.inkSoft },\n            \"& .MuiChartsAxis-tick\": { stroke: t.inkSoft },\n          }}\n        />\n        <Typography\n          sx={{\n            writingMode: \"vertical-rl\",\n            transform: \"rotate(180deg)\",\n            color: t.ink,\n            fontSize: 16,\n            fontWeight: 500,\n            ml: \"8px\",\n            fontFamily: \"inherit\",\n          }}\n        >\n          {COLOR}\n        </Typography>\n      </Box>\n    </Box>\n  );\n}\n"}