{"spec_id":"histogram-epidemic","library":"highcharts","language":"javascript","code":"// anyplot.ai\n// histogram-epidemic: Epidemic Curve (Epi Curve)\n// Library: highcharts 12.6.0 | JavaScript 22.23.2\n// Quality: 91/100 | Created: 2026-08-26\n\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data (in-memory, deterministic LCG — no seeded Math.random in browser) ---\nfunction makeLcg(seed) {\n  let state = seed >>> 0;\n  return function lcg() {\n    state = (state * 1664525 + 1013904223) >>> 0;\n    return state / 4294967296;\n  };\n}\nconst rand = makeLcg(42);\n\nconst DAY_MS = 24 * 3600 * 1000;\nconst outbreakStart = Date.UTC(2024, 0, 1);\nconst numDays = 90;\n\n// Two overlapping gaussian bumps: a sharp point-source wave, followed by a\n// broader propagated wave once mitigation measures loosen.\nfunction gaussian(x, mu, sigma, amplitude) {\n  return amplitude * Math.exp(-((x - mu) ** 2) / (2 * sigma * sigma));\n}\n\nconst confirmedData = [];\nconst probableData = [];\nconst suspectData = [];\nconst cumulativeData = [];\n\nlet runningTotal = 0;\nfor (let day = 0; day < numDays; day++) {\n  const wave1 = gaussian(day, 16, 5.5, 46);\n  const wave2 = gaussian(day, 54, 11, 30);\n  const noise = (rand() - 0.5) * 6;\n  const total = Math.max(0, Math.round(wave1 + wave2 + noise));\n\n  const confirmed = Math.round(total * 0.55);\n  const probable = Math.round(total * 0.3);\n  const suspect = Math.max(0, total - confirmed - probable);\n\n  const date = outbreakStart + day * DAY_MS;\n  confirmedData.push([date, confirmed]);\n  probableData.push([date, probable]);\n  suspectData.push([date, suspect]);\n\n  runningTotal += confirmed + probable + suspect;\n  cumulativeData.push([date, runningTotal]);\n}\n\nconst lockdownDate = outbreakStart + 21 * DAY_MS;\nconst vaccinationDate = outbreakStart + 58 * DAY_MS;\n\n// --- Chart -------------------------------------------------------------------\nHighcharts.chart(\"container\", {\n  chart: {\n    type: \"column\",\n    backgroundColor: \"transparent\",\n    animation: false,\n    style: { fontFamily: \"inherit\" },\n  },\n  credits: { enabled: false },\n  colors: t.palette,\n  title: {\n    text: \"histogram-epidemic · javascript · highcharts · anyplot.ai\",\n    style: { color: t.ink, fontSize: \"22px\", fontWeight: \"600\" },\n  },\n  subtitle: {\n    text: \"Daily symptom-onset counts by case classification\",\n    style: { color: t.inkSoft, fontSize: \"14px\" },\n  },\n  xAxis: {\n    type: \"datetime\",\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineColor: t.grid,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n    title: { text: \"Onset Date\", style: { color: t.inkSoft, fontSize: \"16px\" } },\n    plotBands: [\n      {\n        from: lockdownDate,\n        to: vaccinationDate,\n        color: t.grid,\n        zIndex: 0,\n      },\n    ],\n    plotLines: [\n      {\n        value: lockdownDate,\n        color: t.amber,\n        width: 2,\n        dashStyle: \"Dash\",\n        zIndex: 5,\n        label: {\n          text: \"Lockdown Start\",\n          rotation: 0,\n          y: 20,\n          x: 4,\n          style: { color: t.ink, fontSize: \"14px\" },\n        },\n      },\n      {\n        value: vaccinationDate,\n        color: t.amber,\n        width: 2,\n        dashStyle: \"Dash\",\n        zIndex: 5,\n        label: {\n          text: \"Vaccination Campaign\",\n          rotation: 0,\n          y: 40,\n          x: 4,\n          style: { color: t.ink, fontSize: \"14px\" },\n        },\n      },\n    ],\n  },\n  yAxis: [\n    {\n      title: { text: \"New Cases\", style: { color: t.inkSoft, fontSize: \"16px\" } },\n      gridLineColor: t.grid,\n      labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n      lineColor: t.inkSoft,\n      tickColor: t.inkSoft,\n    },\n    {\n      title: {\n        text: \"Cumulative Cases\",\n        style: { color: t.inkSoft, fontSize: \"16px\" },\n      },\n      labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n      lineColor: t.inkSoft,\n      tickColor: t.inkSoft,\n      gridLineWidth: 0,\n      opposite: true,\n    },\n  ],\n  legend: {\n    itemStyle: { color: t.inkSoft, fontSize: \"14px\" },\n    itemHoverStyle: { color: t.ink },\n  },\n  tooltip: {\n    shared: true,\n    xDateFormat: \"%b %d, %Y\",\n  },\n  plotOptions: {\n    series: { animation: false },\n    column: {\n      stacking: \"normal\",\n      borderWidth: 0,\n      groupPadding: 0.06,\n      pointPadding: 0.02,\n    },\n  },\n  series: [\n    { name: \"Confirmed\", type: \"column\", data: confirmedData, color: t.palette[0] },\n    { name: \"Probable\", type: \"column\", data: probableData, color: t.palette[1] },\n    { name: \"Suspect\", type: \"column\", data: suspectData, color: t.palette[2] },\n    {\n      name: \"Cumulative Cases\",\n      type: \"line\",\n      yAxis: 1,\n      data: cumulativeData,\n      color: t.ink,\n      lineWidth: 2.5,\n      marker: { enabled: false },\n    },\n  ],\n});\n"}