{"spec_id":"point-basic","library":"muix","language":"javascript","code":"// anyplot.ai\n// point-basic: Point Estimate Plot\n// Library: muix 9.16.0 | JavaScript 22.23.3\n// Quality: 86/100 | Updated: 2026-10-24\n\nimport { ChartsContainer } from \"@mui/x-charts/ChartsContainer\";\nimport { ChartsXAxis } from \"@mui/x-charts/ChartsXAxis\";\nimport { ChartsYAxis } from \"@mui/x-charts/ChartsYAxis\";\nimport { ChartsGrid } from \"@mui/x-charts/ChartsGrid\";\nimport { ChartsReferenceLine } from \"@mui/x-charts/ChartsReferenceLine\";\nimport { useXScale, useYScale } from \"@mui/x-charts/hooks\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst TITLE = \"point-basic · javascript · muix · anyplot.ai\";\nconst NULL_VALUE = 0;\nconst NULL_LABEL = \"No effect\";\nconst X_PAD_SHARE = 0.1;\nconst TITLE_HEIGHT = 68;\nconst CAP_BAND_SHARE = 0.22;\nconst MARKER_RADIUS = 10;\n\n// Columns: set these to your data's column names\nconst SITE = \"Pilot Site\"; // role: category\nconst ESTIMATE = \"Effect Size (Cohen's d)\"; // role: value\nconst LOWER = \"Lower 95% CI\"; // role: low\nconst UPPER = \"Upper 95% CI\"; // role: high\n\n// Data: replace this block with your own records\nconst data: Array<Record<string, string | number>> = [\n  { [SITE]: \"Denver\", [ESTIMATE]: 0.55, [LOWER]: 0.3, [UPPER]: 0.8 },\n  { [SITE]: \"Portland\", [ESTIMATE]: 0.45, [LOWER]: 0.22, [UPPER]: 0.68 },\n  { [SITE]: \"Boston\", [ESTIMATE]: 0.42, [LOWER]: 0.18, [UPPER]: 0.66 },\n  { [SITE]: \"Austin\", [ESTIMATE]: 0.38, [LOWER]: 0.15, [UPPER]: 0.61 },\n  { [SITE]: \"Chicago\", [ESTIMATE]: 0.31, [LOWER]: 0.05, [UPPER]: 0.57 },\n  { [SITE]: \"Seattle\", [ESTIMATE]: 0.28, [LOWER]: 0.02, [UPPER]: 0.54 },\n  { [SITE]: \"Atlanta\", [ESTIMATE]: 0.12, [LOWER]: -0.1, [UPPER]: 0.34 },\n  { [SITE]: \"Miami\", [ESTIMATE]: -0.05, [LOWER]: -0.28, [UPPER]: 0.18 },\n];\n\n// Plot: reads only data and the constants above\nconst sortedSites = [...data].sort((a, b) => Number(b[ESTIMATE]) - Number(a[ESTIMATE]));\nconst siteNames = sortedSites.map((row) => String(row[SITE]));\nconst allBounds = sortedSites.flatMap((row) => [\n  Number(row[LOWER]),\n  Number(row[UPPER]),\n  NULL_VALUE,\n]);\nconst rawMin = Math.min(...allBounds);\nconst rawMax = Math.max(...allBounds);\nconst span = rawMax - rawMin;\nconst xMin = rawMin - span * X_PAD_SHARE;\nconst xMax = rawMax + span * X_PAD_SHARE;\n\nfunction PointEstimates() {\n  const xScale = useXScale(\"effect-size\") as unknown as (v: number) => number;\n  const yScale = useYScale(\"site\") as unknown as ((s: string) => number) & {\n    bandwidth: () => number;\n  };\n  const bandwidth = yScale.bandwidth();\n  const capHalf = bandwidth * CAP_BAND_SHARE;\n\n  return (\n    <g>\n      {sortedSites.map((row) => {\n        const siteLabel = String(row[SITE]);\n        const y = yScale(siteLabel) + bandwidth / 2;\n        const xLow = xScale(Number(row[LOWER]));\n        const xHigh = xScale(Number(row[UPPER]));\n        const xEst = xScale(Number(row[ESTIMATE]));\n        return (\n          <g key={siteLabel}>\n            <line\n              x1={xLow}\n              x2={xHigh}\n              y1={y}\n              y2={y}\n              stroke={t.palette[0]}\n              strokeWidth={3}\n              strokeLinecap=\"round\"\n            />\n            <line\n              x1={xLow}\n              x2={xLow}\n              y1={y - capHalf}\n              y2={y + capHalf}\n              stroke={t.palette[0]}\n              strokeWidth={3}\n            />\n            <line\n              x1={xHigh}\n              x2={xHigh}\n              y1={y - capHalf}\n              y2={y + capHalf}\n              stroke={t.palette[0]}\n              strokeWidth={3}\n            />\n            <circle\n              cx={xEst}\n              cy={y}\n              r={MARKER_RADIUS}\n              fill={t.palette[0]}\n              stroke={t.pageBg}\n              strokeWidth={2.5}\n            />\n          </g>\n        );\n      })}\n    </g>\n  );\n}\n\nexport default function Chart() {\n  const chartHeight = window.ANYPLOT_SIZE.height - TITLE_HEIGHT;\n\n  return (\n    <div\n      style={{\n        width: window.ANYPLOT_SIZE.width,\n        height: window.ANYPLOT_SIZE.height,\n        backgroundColor: t.pageBg,\n      }}\n    >\n      <div\n        style={{\n          height: TITLE_HEIGHT,\n          display: \"flex\",\n          alignItems: \"center\",\n          paddingLeft: 24,\n          fontSize: 22,\n          fontWeight: 600,\n          color: t.ink,\n          fontFamily: \"inherit\",\n        }}\n      >\n        {TITLE}\n      </div>\n      <ChartsContainer\n        width={window.ANYPLOT_SIZE.width}\n        height={chartHeight}\n        series={[]}\n        skipAnimation\n        margin={{ top: 20, bottom: 16, left: 28, right: 40 }}\n        xAxis={[\n          {\n            id: \"effect-size\",\n            scaleType: \"linear\",\n            min: xMin,\n            max: xMax,\n            height: 56,\n            label: ESTIMATE,\n            labelStyle: { fontSize: 15, fill: t.ink },\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n          },\n        ]}\n        yAxis={[\n          {\n            id: \"site\",\n            scaleType: \"band\",\n            data: siteNames,\n            width: 130,\n            label: SITE,\n            labelStyle: { fontSize: 15, fill: t.ink },\n            tickLabelStyle: { fontSize: 14, fill: t.ink },\n          },\n        ]}\n      >\n        <ChartsGrid vertical />\n        <ChartsReferenceLine\n          x={NULL_VALUE}\n          label={NULL_LABEL}\n          labelAlign=\"end\"\n          lineStyle={{ stroke: t.inkSoft, strokeDasharray: \"6 4\", strokeWidth: 1.5 }}\n          labelStyle={{ fontSize: 14, fill: t.inkSoft }}\n        />\n        <PointEstimates />\n        <ChartsXAxis axisId=\"effect-size\" />\n        <ChartsYAxis axisId=\"site\" disableTicks />\n      </ChartsContainer>\n    </div>\n  );\n}\n"}