{"spec_id":"line-arrhenius","library":"echarts","language":"javascript","code":"// anyplot.ai\n// line-arrhenius: Arrhenius Plot for Reaction Kinetics\n// Library: echarts 5.5.1 | JavaScript 22.22.3\n// Quality: 90/100 | Created: 2026-06-24\n//# anyplot-orientation: landscape\n\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data (deterministic, in-memory) ----------------------------------------\n// First-order thermal decomposition of hydrogen peroxide (H₂O₂ → H₂O + ½O₂)\nconst temps_K = [300, 325, 350, 375, 400, 425, 450, 475, 500, 525, 550];\nconst R_GAS = 8.314;    // J/(mol·K)\nconst EA_TRUE = 95000;  // J/mol — activation energy\nconst LN_A = 27.0;      // ln(A) where A is the pre-exponential factor in s⁻¹\n\n// Deterministic perturbations to simulate experimental measurement scatter\nconst noise = [0.12, -0.08, 0.15, -0.11, 0.09, 0.07, -0.13, 0.10, -0.06, 0.14, -0.09];\nconst inv_T = temps_K.map(T => 1 / T);\nconst ln_k = temps_K.map((T, i) => LN_A - EA_TRUE / (R_GAS * T) + noise[i]);\n\n// Linear regression: ln(k) = slope * (1/T) + intercept  (slope = -Ea/R)\nconst n = inv_T.length;\nconst sx = inv_T.reduce((a, b) => a + b, 0);\nconst sy = ln_k.reduce((a, b) => a + b, 0);\nconst sxy = inv_T.reduce((a, xi, i) => a + xi * ln_k[i], 0);\nconst sx2 = inv_T.reduce((a, xi) => a + xi * xi, 0);\nconst slope = (n * sxy - sx * sy) / (n * sx2 - sx * sx);\nconst intercept = (sy - slope * sx) / n;\n\n// R² coefficient of determination\nconst y_mean = sy / n;\nconst ss_res = ln_k.reduce((a, yi, i) => a + (yi - (slope * inv_T[i] + intercept)) ** 2, 0);\nconst ss_tot = ln_k.reduce((a, yi) => a + (yi - y_mean) ** 2, 0);\nconst r_sq = (1 - ss_res / ss_tot).toFixed(4);\n\n// Extracted activation energy from Arrhenius slope: slope = -Ea/R\nconst Ea_kJ = (-slope * R_GAS / 1000).toFixed(1);\nconst Ea_over_R = (-slope).toFixed(0);\n\n// Regression line (51 points for smooth rendering, extended beyond data range)\nconst x_lo = Math.min(...inv_T) * 0.995;\nconst x_hi = Math.max(...inv_T) * 1.005;\nconst line_data = Array.from({ length: 51 }, (_, i) => {\n  const x = x_lo + (x_hi - x_lo) * i / 50;\n  return [x, slope * x + intercept];\n});\n\n// --- Init -------------------------------------------------------------------\nconst chart = echarts.init(document.getElementById(\"container\"));\n\n// --- Option -----------------------------------------------------------------\nchart.setOption({\n  animation: false,\n  color: t.palette,\n  backgroundColor: \"transparent\",\n  title: {\n    text: \"line-arrhenius · javascript · echarts · anyplot.ai\",\n    left: \"center\",\n    top: 22,\n    textStyle: { color: t.ink, fontSize: 22, fontWeight: \"bold\" }\n  },\n  legend: {\n    data: [\"Experimental data\", \"Arrhenius fit\"],\n    top: 60,\n    textStyle: { color: t.inkSoft, fontSize: 14 },\n    itemWidth: 22,\n    itemHeight: 14\n  },\n  tooltip: {\n    trigger: \"item\",\n    backgroundColor: t.elevatedBg,\n    borderColor: t.inkSoft,\n    textStyle: { color: t.ink, fontSize: 13 },\n    formatter: function(params) {\n      if (params.seriesType === \"scatter\") {\n        const T = Math.round(1 / params.data[0]);\n        return (\n          \"T = \" + T + \" K<br>\" +\n          \"1/T = \" + (params.data[0] * 1000).toFixed(3) + \" ×10⁻³ K⁻¹<br>\" +\n          \"ln(k) = \" + params.data[1].toFixed(3)\n        );\n      }\n      return \"\";\n    }\n  },\n  grid: { left: 90, right: 224, top: 102, bottom: 115 },\n  xAxis: {\n    type: \"value\",\n    name: \"1/T  (×10⁻³ K⁻¹)\",\n    nameLocation: \"middle\",\n    nameGap: 65,\n    nameTextStyle: { color: t.inkSoft, fontSize: 14 },\n    min: x_lo,\n    max: x_hi,\n    axisLabel: {\n      color: t.inkSoft,\n      fontSize: 14,\n      formatter: function(val) {\n        return (val * 1000).toFixed(2) + \"\\n(\" + Math.round(1 / val) + \" K)\";\n      }\n    },\n    axisLine: { lineStyle: { color: t.inkSoft } },\n    splitLine: { show: false },\n    axisTick: { lineStyle: { color: t.inkSoft } }\n  },\n  yAxis: {\n    type: \"value\",\n    name: \"ln(k)\",\n    nameLocation: \"middle\",\n    nameGap: 56,\n    nameTextStyle: { color: t.inkSoft, fontSize: 14 },\n    axisLabel: { color: t.inkSoft, fontSize: 13 },\n    axisLine: { lineStyle: { color: t.inkSoft } },\n    splitLine: { lineStyle: { color: t.grid } },\n    axisTick: { lineStyle: { color: t.inkSoft } }\n  },\n  series: [\n    {\n      name: \"Experimental data\",\n      type: \"scatter\",\n      symbolSize: 14,\n      data: inv_T.map((x, i) => [x, ln_k[i]]),\n      itemStyle: {\n        color: t.palette[0],\n        borderColor: t.pageBg,\n        borderWidth: 2\n      },\n      z: 10\n    },\n    {\n      name: \"Arrhenius fit\",\n      type: \"line\",\n      data: line_data,\n      lineStyle: { color: t.palette[1], width: 3 },\n      itemStyle: { color: t.palette[1] },\n      symbol: \"none\",\n      smooth: false,\n      z: 5\n    }\n  ],\n  graphic: [\n    {\n      type: \"group\",\n      x: 1390,\n      y: 108,\n      children: [\n        {\n          type: \"rect\",\n          shape: { x: 0, y: 0, width: 186, height: 116, r: 5 },\n          style: {\n            fill: t.elevatedBg,\n            stroke: t.inkSoft,\n            lineWidth: 0.8\n          }\n        },\n        {\n          type: \"text\",\n          x: 14,\n          y: 18,\n          style: {\n            text: \"Kinetics Summary\",\n            fill: t.ink,\n            fontSize: 13,\n            fontWeight: \"bold\"\n          }\n        },\n        {\n          type: \"text\",\n          x: 14,\n          y: 46,\n          style: {\n            text: \"R² = \" + r_sq,\n            fill: t.inkSoft,\n            fontSize: 13\n          }\n        },\n        {\n          type: \"text\",\n          x: 14,\n          y: 70,\n          style: {\n            text: \"Ea = \" + Ea_kJ + \" kJ/mol\",\n            fill: t.inkSoft,\n            fontSize: 13\n          }\n        },\n        {\n          type: \"text\",\n          x: 14,\n          y: 94,\n          style: {\n            text: \"Ea/R = \" + Ea_over_R + \" K\",\n            fill: t.inkSoft,\n            fontSize: 13\n          }\n        }\n      ]\n    }\n  ]\n});\n"}