{"spec_id":"bar-horizontal","library":"muix","language":"javascript","code":"// anyplot.ai\n// bar-horizontal: Horizontal Bar Chart\n// Library: muix 9.17.0 | JavaScript 22.23.4\n// Quality: 90/100 | Updated: 2026-11-08\nimport { BarChart } from \"@mui/x-charts/BarChart\";\nimport Box from \"@mui/material/Box\";\nimport Typography from \"@mui/material/Typography\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst TITLE = \"Feature Requests by Customer Votes · bar-horizontal · javascript · muix · anyplot.ai\";\nconst TITLE_H = 84;\nconst PAD_SHARE = 0.08; // room beyond the longest bar for its value label\n// The style guide's muted anchor (other / rest): the bars behind the accented leader\nconst MUTED = t.theme === \"dark\" ? \"#A8A79F\" : \"#6B6A63\";\n\n// Columns: set these to your data's column names\nconst FEATURE_REQUEST = \"Feature request\"; // role: category\nconst VOTES = \"Customer votes\"; // role: value\n\n// Data: replace this block with your own records, one object per row\n// Product roadmap survey: feature requests and the votes each received\nconst data = [\n  { [FEATURE_REQUEST]: \"Dark mode support\", [VOTES]: 842 },\n  { [FEATURE_REQUEST]: \"Offline data sync\", [VOTES]: 715 },\n  { [FEATURE_REQUEST]: \"Advanced search filters\", [VOTES]: 693 },\n  { [FEATURE_REQUEST]: \"Bulk CSV export\", [VOTES]: 588 },\n  { [FEATURE_REQUEST]: \"Customizable dashboards\", [VOTES]: 511 },\n  { [FEATURE_REQUEST]: \"Real-time collaboration\", [VOTES]: 467 },\n  { [FEATURE_REQUEST]: \"Mobile app redesign\", [VOTES]: 398 },\n  { [FEATURE_REQUEST]: \"API rate limit increase\", [VOTES]: 312 },\n];\n\n// Plot: reads only data and the constants above\n// A ranking: most votes first, so the leader sits at the top\nconst rows = data.filter((d) => d[VOTES] != null).sort((a, b) => b[VOTES] - a[VOTES]);\nconst requests = rows.map((d) => d[FEATURE_REQUEST]);\nconst votes = rows.map((d) => d[VOTES]);\nconst maxVotes = Math.max(...votes);\n\n// Accent on the most-voted request; every other bar takes the muted anchor\nconst barColors = votes.map((v) => (v === maxVotes ? t.palette[0] : MUTED));\n\nconst SUBTITLE = [\n  `${rows.length} requests ranked by ${VOTES.toLowerCase()}`,\n  rows.length > 1\n    ? `${requests[0]} leads with ${votes[0]}, ${votes[0] - votes[1]} ahead of ${requests[1]}`\n    : null,\n]\n  .filter(Boolean)\n  .join(\" · \");\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n\n  return (\n    <Box sx={{ width, height, bgcolor: t.pageBg, display: \"flex\", flexDirection: \"column\" }}>\n      <Box sx={{ height: TITLE_H, px: \"40px\", pt: \"18px\", boxSizing: \"border-box\" }}>\n        <Typography sx={{ color: t.ink, fontSize: \"22px\", fontWeight: 600, lineHeight: 1.2 }}>\n          {TITLE}\n        </Typography>\n        <Typography sx={{ color: t.inkSoft, fontSize: \"15px\", lineHeight: 1.2, mt: \"8px\" }}>\n          {SUBTITLE}\n        </Typography>\n      </Box>\n      <BarChart\n        width={width}\n        height={height - TITLE_H}\n        layout=\"horizontal\"\n        skipAnimation\n        hideLegend\n        borderRadius={4}\n        grid={{ vertical: true }}\n        series={[\n          {\n            id: \"votes\",\n            label: VOTES,\n            data: votes,\n            barLabel: \"value\",\n            barLabelPlacement: \"outside\",\n          },\n        ]}\n        xAxis={[\n          {\n            min: 0,\n            max: maxVotes * (1 + PAD_SHARE),\n            label: VOTES,\n            height: 64,\n            tickNumber: 8,\n            disableTicks: true,\n            tickLabelStyle: { fontSize: 15, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        yAxis={[\n          {\n            scaleType: \"band\",\n            data: requests,\n            colorMap: { type: \"ordinal\", values: requests, colors: barColors },\n            width: 240,\n            categoryGapRatio: 0.35,\n            disableTicks: true,\n            tickLabelStyle: { fontSize: 15, fill: t.ink },\n          },\n        ]}\n        margin={{ top: 16, right: 48, bottom: 8, left: 24 }}\n        sx={{\n          \"& .MuiBarChart-label\": { fill: t.ink, fontSize: 15, fontWeight: 600 },\n          \"& .MuiChartsAxis-line\": { stroke: t.inkSoft },\n          \"& .MuiChartsGrid-line\": { stroke: t.grid, strokeWidth: 1 },\n        }}\n      />\n    </Box>\n  );\n}\n"}