{"spec_id":"line-arrhenius","library":"muix","language":"javascript","code":"// anyplot.ai\n// line-arrhenius: Arrhenius Plot for Reaction Kinetics\n// Library: muix 7.29.1 | JavaScript 22.22.3\n// Quality: 88/100 | Created: 2026-06-24\n//# anyplot-orientation: landscape\n// anyplot.ai\n// line-arrhenius: Arrhenius Plot for Reaction Kinetics\n// Library: MUI X Charts | React | Node 22\n// License: @mui/x-charts — MIT (community). Pro/Premium are out of scope.\n// Quality: pending | Created: 2026-06-24\n\nimport { LineChart } from \"@mui/x-charts/LineChart\";\nimport Box from \"@mui/material/Box\";\nimport Typography from \"@mui/material/Typography\";\n\nconst t = window.ANYPLOT_TOKENS;\nconst sz = window.ANYPLOT_SIZE;\n\n// LCG for deterministic noise (no Math.random — banned in workflow)\nlet lcgSeed = 42;\nfunction nextLcg() {\n  lcgSeed = (Math.imul(lcgSeed, 1664525) + 1013904223) >>> 0;\n  return lcgSeed / 4294967296;\n}\n\n// Synthetic Arrhenius data — NO₂ thermal decomposition (2NO₂ → 2NO + O₂)\nconst R_GAS = 8.314;    // J/(mol·K)\nconst Ea_true = 111000; // J/mol (~111 kJ/mol — literature value)\nconst lnA = 28.55;      // ln(2.5 × 10¹² s⁻¹) pre-exponential factor\n\nconst temps_K = [310, 330, 350, 370, 390, 410, 430, 450, 470, 490, 510];\nconst xData = temps_K.map((T) => parseFloat((1000 / T).toFixed(4)));\nconst yData = temps_K.map((T) => {\n  const lnK_true = lnA - Ea_true / (R_GAS * T);\n  return parseFloat((lnK_true + (nextLcg() - 0.5) * 0.3).toFixed(4));\n});\n\n// Linear regression: ln(k) = intercept + slope × (1000/T)\nconst n = xData.length;\nconst sumX = xData.reduce((a, b) => a + b, 0);\nconst sumY = yData.reduce((a, b) => a + b, 0);\nconst sumXY = xData.reduce((s, x, i) => s + x * yData[i], 0);\nconst sumX2 = xData.reduce((s, x) => s + x * x, 0);\nconst slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);\nconst intercept = (sumY - slope * sumX) / n;\n\nconst yMean = sumY / n;\nconst ssRes = yData.reduce(\n  (s, y, i) => s + (y - (slope * xData[i] + intercept)) ** 2,\n  0\n);\nconst ssTot = yData.reduce((s, y) => s + (y - yMean) ** 2, 0);\nconst r2 = 1 - ssRes / ssTot;\n\n// slope = -Ea / (R × 1000)  →  Ea = -slope × R × 1000\nconst Ea_kJ = (-slope * R_GAS).toFixed(1);   // kJ/mol\nconst EaR_K = (-slope * 1000).toFixed(0);     // Ea/R in K\n\nconst regData = xData.map((x) =>\n  parseFloat((slope * x + intercept).toFixed(4))\n);\n\nexport default function Chart() {\n  return (\n    <Box sx={{ position: \"relative\", width: sz.width, height: sz.height }}>\n      {/* Chart title */}\n      <Typography\n        sx={{\n          position: \"absolute\",\n          top: 14,\n          left: 0,\n          right: 0,\n          textAlign: \"center\",\n          color: t.ink,\n          fontSize: 22,\n          fontWeight: 600,\n          zIndex: 1,\n          pointerEvents: \"none\",\n        }}\n      >\n        line-arrhenius · javascript · muix · anyplot.ai\n      </Typography>\n\n      <LineChart\n        width={sz.width}\n        height={sz.height}\n        skipAnimation\n        margin={{ top: 110, bottom: 110, left: 110, right: 60 }}\n        colors={[t.palette[0], t.palette[1]]}\n        grid={{ horizontal: true }}\n        xAxis={[\n          {\n            id: \"invT\",\n            data: xData,\n            label: \"1000 / T  (K⁻¹)\",\n            valueFormatter: (v) => v.toFixed(2),\n            scaleType: \"linear\",\n            position: \"bottom\",\n            tickNumber: 7,\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n          {\n            id: \"tempK\",\n            data: xData,\n            label: \"Temperature (K)\",\n            valueFormatter: (v) => `${Math.round(1000 / v)}`,\n            scaleType: \"linear\",\n            position: \"top\",\n            tickNumber: 5,\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        yAxis={[\n          {\n            id: \"lnk\",\n            label: \"ln(k)\",\n            labelStyle: { fontSize: 18, fill: t.ink },\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n          },\n        ]}\n        series={[\n          {\n            id: \"experimental\",\n            data: yData,\n            label: \"Experimental ln(k)\",\n            showMark: true,\n            curve: \"linear\",\n            xAxisKey: \"invT\",\n          },\n          {\n            id: \"regression\",\n            data: regData,\n            label: \"Linear regression\",\n            showMark: false,\n            curve: \"linear\",\n            xAxisKey: \"invT\",\n          },\n        ]}\n        topAxis=\"tempK\"\n        bottomAxis=\"invT\"\n        leftAxis=\"lnk\"\n        rightAxis={null}\n        slotProps={{\n          legend: {\n            position: { vertical: \"bottom\", horizontal: \"middle\" },\n            direction: \"row\",\n            itemMarkWidth: 18,\n            itemMarkHeight: 3,\n            itemGap: 28,\n            labelStyle: { fontSize: 14, fill: t.inkSoft },\n          },\n        }}\n      />\n\n      {/* Regression statistics annotation */}\n      <Box\n        sx={{\n          position: \"absolute\",\n          top: \"18%\",\n          right: \"5%\",\n          bgcolor: t.elevatedBg,\n          px: 2,\n          py: 1.5,\n          borderRadius: 1.5,\n          border: `1px solid ${t.inkSoft}55`,\n          zIndex: 2,\n        }}\n      >\n        <Typography\n          sx={{ color: t.ink, fontSize: 15, fontFamily: \"monospace\", lineHeight: 1.9 }}\n        >\n          R² = {r2.toFixed(4)}\n        </Typography>\n        <Typography\n          sx={{ color: t.ink, fontSize: 15, fontFamily: \"monospace\", lineHeight: 1.9 }}\n        >\n          Eₐ / R = {EaR_K} K\n        </Typography>\n        <Typography\n          sx={{ color: t.ink, fontSize: 15, fontFamily: \"monospace\", lineHeight: 1.9 }}\n        >\n          Eₐ = {Ea_kJ} kJ mol⁻¹\n        </Typography>\n      </Box>\n    </Box>\n  );\n}\n"}