function strip(res, focus = meta.focus) {
const d = models.map((m) => {
const se = res.ses[m.key];
return {model: width < 640 ? m.short : m.label, est: pct(res.est, res.baseRate),
lo: pct(res.est - Z * se, res.baseRate), hi: pct(res.est + Z * se, res.baseRate),
mde: pct(mde(se), res.baseRate)};
});
const lim = Math.max(100, ...d.map((r) => Math.max(Math.abs(r.lo), Math.abs(r.hi)))) * 1.05;
return Plot.plot({
height: 230, marginTop: 22, marginLeft: width < 640 ? 90 : 310, width: Math.min(width, 900),
ariaLabel: `Normal reference bands for the ${focus}–peer gap change under four illustrative noise summaries`,
x: {domain: [-lim, lim], label: `Change in ${focus}–peer gap, % of focal baseline rate`, grid: true},
y: {label: null, domain: d.map((r) => r.model)},
marks: [
Plot.ruleX([0], {stroke: "#1f2a30", strokeDasharray: "3,3"}),
Plot.ruleY(d, {y: "model", x1: "lo", x2: "hi", stroke: teal, strokeWidth: 6, strokeOpacity: 0.55}),
Plot.dot(d, {y: "model", x: "est", fill: coral, r: 5}),
Plot.tip(d, Plot.pointerY({y: "model", x: "est",
title: (r) => `${r.model}\nNormal reference band: ${fp(r.lo)} to ${fp(r.hi)}\nApproximate 80%-power magnitude: ±${Math.abs(r.mde).toFixed(0)}%`}))
]
});
}
function pathPlot(res, focus) {
const d = eventPath(res.g, meta.event).filter((r) => r.rel >= -48);
return Plot.plot({
height: 280, width: Math.min(width, 560),
x: {label: "Months relative to Jan 2026"},
y: {label: `${focus} minus peers (per 100k/month)`, grid: true},
marks: [
Plot.ruleY([0], {stroke: grey}),
Plot.ruleX([-0.5], {stroke: "#1f2a30", strokeDasharray: "3,3"}),
Plot.line(d, {x: "rel", y: "effect", stroke: teal}),
Plot.dot(d.filter((r) => r.rel >= 0), {x: "rel", y: "effect", fill: coral, r: 3}),
Plot.tip(d, Plot.pointerX({x: "rel", y: "effect", title: (r) => `${r.month.slice(0, 7)}: ${f2(r.effect)}`}))
]
});
}
function permPlot(res, focus) {
return Plot.plot({
height: Math.max(300, 16 * res.isp.length), marginLeft: 130, width: Math.min(width, 520),
x: {label: "Post-period gap ÷ pre-period noise (RMSPE ratio)", grid: true},
y: {label: null},
marks: [
Plot.barX(res.isp, {y: "city", x: "ratio", fill: (d) => d.city === focus ? coral : grey,
sort: {y: "x", reverse: true}}),
Plot.tip(res.isp, Plot.pointerY({y: "city", x: "ratio", title: (d) => `${d.city}: ${d.ratio.toFixed(2)}`}))
]
});
}