curveNote = (year !== "All (2021–2026)" || sizeTier !== "All sizes" || araFilter !== "All entrants")
? " (Note: daily path curve aggregates across the selected scripless proxy bucket for all years/sizes; scatter, distributions, and table below reflect all active filters.)"
: ""
pathMetric === "BHAR vs IHSG (%)"
? Plot.plot({
title: `Daily BHAR vs IHSG (^JKSE) over trading days t=0..${dailyHorizon} — ${bucket}`,
subtitle: `Gold = selected bucket median (n=${bucketCurve.at(-1)?.n ?? 0} at t+${dailyHorizon}), shaded band = 25th–75th pct, teal dashed = All buckets median${curveNote}`,
style: {background: "transparent", color: "var(--ink)", fontFamily: "Satoshi, Arial, sans-serif"},
width: 780,
height: 360,
grid: true,
x: {label: "Trading days after listing (t=0 is Day-0 close) →", tickFormat: d => `t+${d}`},
y: {label: "↑ Buy-and-Hold Abnormal Return vs IHSG (%)"},
marks: [
Plot.ruleY([0], {stroke: grey, strokeDasharray: "3,3"}),
Plot.areaY(bucketCurve, {x: "t", y1: "bhar_p25_pct", y2: "bhar_p75_pct", fill: gold, fillOpacity: 0.16}),
bucket !== "All buckets" ? Plot.line(allCurve, {x: "t", y: "bhar_median_pct", stroke: teal, strokeWidth: 2, strokeDasharray: "5,4"}) : null,
Plot.line(bucketCurve, {x: "t", y: "bhar_median_pct", stroke: gold, strokeWidth: 2.6}),
Plot.tip(bucketCurve, Plot.pointerX({
x: "t",
y: "bhar_median_pct",
title: d => `Day t+${d.t} (${d.scripless_bucket}, n=${d.n})\nMedian BHAR: ${d.bhar_median_pct >= 0 ? "+" : ""}${d.bhar_median_pct?.toFixed(1)}%\nIQR: ${d.bhar_p25_pct?.toFixed(1)}% to ${d.bhar_p75_pct?.toFixed(1)}%\nMedian peak DD: ${d.dd_median_pct?.toFixed(1)}%`
}))
].filter(Boolean)
})
: Plot.plot({
title: `Daily median running drawdown from post-listing peak (t=0..${dailyHorizon}) — ${bucket}`,
subtitle: `Gold = selected bucket median running peak-to-t drawdown; teal dashed = All buckets median${curveNote}`,
style: {background: "transparent", color: "var(--ink)", fontFamily: "Satoshi, Arial, sans-serif"},
width: 780,
height: 360,
grid: true,
x: {label: "Trading days after listing →", tickFormat: d => `t+${d}`},
y: {label: "↑ Running drawdown from peak (%)", domain: [-70, 5]},
marks: [
Plot.ruleY([0], {stroke: grey, strokeDasharray: "3,3"}),
bucket !== "All buckets" ? Plot.line(allCurve, {x: "t", y: "dd_median_pct", stroke: teal, strokeWidth: 2, strokeDasharray: "5,4"}) : null,
Plot.line(bucketCurve, {x: "t", y: "dd_median_pct", stroke: red, strokeWidth: 2.6}),
Plot.tip(bucketCurve, Plot.pointerX({
x: "t",
y: "dd_median_pct",
title: d => `Day t+${d.t} (${d.scripless_bucket}, n=${d.n})\nMedian running DD: ${d.dd_median_pct?.toFixed(1)}%\nMedian BHAR: ${d.bhar_median_pct >= 0 ? "+" : ""}${d.bhar_median_pct?.toFixed(1)}%`
}))
].filter(Boolean)
})