{"spec_id":"eye-diagram-basic","library":"highcharts","language":"javascript","code":"// anyplot.ai\n// eye-diagram-basic: Signal Integrity Eye Diagram\n// Library: highcharts 12.6.0 | JavaScript 22.22.3\n// Quality: 90/100 | Created: 2026-06-18\n\n//# anyplot-orientation: landscape\nconst t = window.ANYPLOT_TOKENS;\n\n// Deterministic LCG RNG (seed = 42)\nlet _seed = 42;\nfunction rand() {\n  _seed = (_seed * 1664525 + 1013904223) >>> 0;\n  return _seed / 4294967296;\n}\nfunction randn() {\n  const u1 = rand() + 1e-10;\n  const u2 = rand();\n  return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);\n}\n\n// NRZ signal parameters: high-speed serial link (PCIe-style) simulation\nconst V_HIGH = 0.85;\nconst V_LOW = 0.15;\nconst RISE_K = 14;         // sigmoid steepness (~0.1 UI rise/fall time)\nconst NOISE_SIGMA = 0.04;  // Gaussian noise amplitude (V)\nconst JITTER_SIGMA = 0.03; // edge jitter std dev (UI)\nconst SAMPLES = 100;\nconst TRACES_PER_PATTERN = 20; // 8 patterns × 20 = 160 traces\n\n// Build one trace for the 3-bit NRZ pattern [b0 → b1 → b2]\n// Time window is [0, 2] UI: first transition at t≈0, second at t≈1\nconst allSeries = [];\nfor (let pattern = 0; pattern < 8; pattern++) {\n  const b0 = (pattern >> 2) & 1;\n  const b1 = (pattern >> 1) & 1;\n  const b2 = pattern & 1;\n  const v0 = b0 ? V_HIGH : V_LOW;\n  const v1 = b1 ? V_HIGH : V_LOW;\n  const v2 = b2 ? V_HIGH : V_LOW;\n\n  for (let k = 0; k < TRACES_PER_PATTERN; k++) {\n    const j0 = randn() * JITTER_SIGMA;\n    const j1 = randn() * JITTER_SIGMA;\n    const data = [];\n\n    for (let i = 0; i < SAMPLES; i++) {\n      const time = (i / (SAMPLES - 1)) * 2;\n      const s0 = 1 / (1 + Math.exp(-RISE_K * (time - j0)));\n      const s1 = 1 / (1 + Math.exp(-RISE_K * (time - 1 - j1)));\n      let voltage = v0 + (v1 - v0) * s0 + (v2 - v1) * s1 + randn() * NOISE_SIGMA;\n      data.push([Math.round(time * 1000) / 1000, Math.round(voltage * 10000) / 10000]);\n    }\n\n    allSeries.push({\n      type: \"line\",\n      data,\n      lineWidth: 1.5,\n      color: t.palette[0], // Imprint palette pos 1 — brand green #009E73\n      opacity: 0.09,       // low opacity: 160 overlapping traces build density\n      showInLegend: false,\n    });\n  }\n}\n\nHighcharts.chart(\"container\", {\n  chart: {\n    backgroundColor: \"transparent\",\n    animation: false,\n    style: { fontFamily: \"inherit\" },\n  },\n  credits: { enabled: false },\n  colors: t.palette,\n  title: {\n    text: \"eye-diagram-basic · javascript · highcharts · anyplot.ai\",\n    style: { color: t.ink, fontSize: \"22px\", fontWeight: \"600\" },\n  },\n  xAxis: {\n    title: {\n      text: \"Time (UI)\",\n      style: { color: t.inkSoft, fontSize: \"16px\" },\n    },\n    min: 0,\n    max: 2,\n    tickInterval: 0.5,\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineColor: t.grid,\n    gridLineWidth: 1,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n  },\n  yAxis: {\n    title: {\n      text: \"Voltage (V)\",\n      style: { color: t.inkSoft, fontSize: \"16px\" },\n    },\n    min: -0.1,\n    max: 1.1,\n    tickInterval: 0.25,\n    gridLineColor: t.grid,\n    lineColor: t.inkSoft,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n    plotLines: [{\n      value: 0.5,\n      color: t.inkSoft,\n      width: 1.5,\n      dashStyle: \"Dash\",\n      label: {\n        text: \"Decision level\",\n        style: { color: t.inkSoft, fontSize: \"12px\" },\n        align: \"right\",\n        x: -8,\n        y: -6,\n      },\n    }],\n  },\n  legend: { enabled: false },\n  plotOptions: {\n    series: {\n      animation: false,\n      turboThreshold: 0,\n      enableMouseTracking: false,\n      states: {\n        hover: { enabled: false },\n        inactive: { opacity: 1 },\n      },\n    },\n    line: {\n      marker: { enabled: false },\n    },\n  },\n  series: allSeries,\n});\n"}