diff --git a/.changeset/alert-above-threshold-highlight.md b/.changeset/alert-above-threshold-highlight.md
new file mode 100644
index 0000000000..4779178469
--- /dev/null
+++ b/.changeset/alert-above-threshold-highlight.md
@@ -0,0 +1,5 @@
+---
+'@hyperdx/app': patch
+---
+
+Fix the alert preview chart highlighting the region below the threshold for "above" alerts. Recharts v3 flipped the default edge for open-ended reference areas, so "above" and "not between" alerts shaded the wrong side of the threshold line.
diff --git a/packages/app/src/components/Alerts.tsx b/packages/app/src/components/Alerts.tsx
index 360d797fb8..725a64f6e8 100644
--- a/packages/app/src/components/Alerts.tsx
+++ b/packages/app/src/components/Alerts.tsx
@@ -194,7 +194,7 @@ export const getAlertReferenceLines = ({
return [
,
+
+
+
+ {getAlertReferenceLines({ threshold, thresholdMax, thresholdType })}
+
+ {thresholdMax != null ? : null}
+ ,
+ );
+
+ const rects = Array.from(
+ container.querySelectorAll('.recharts-reference-area-rect'),
+ ).map(r => {
+ const top = Number(r.getAttribute('y'));
+ return { top, bottom: top + Number(r.getAttribute('height')) };
+ });
+ const lineYs = Array.from(
+ container.querySelectorAll('.recharts-reference-line-line'),
+ ).map(l => Number(l.getAttribute('y1')));
+
+ return {
+ rects,
+ thresholdY: lineYs[0],
+ thresholdMaxY: lineYs[1],
+ };
+}
+
+const EPS = 1;
+
+describe('getAlertReferenceLines shading', () => {
+ it.each([AlertThresholdType.ABOVE, AlertThresholdType.ABOVE_EXCLUSIVE])(
+ 'shades above the threshold line for %s',
+ thresholdType => {
+ const { rects, thresholdY } = renderAreas(thresholdType, 50);
+ expect(rects).toHaveLength(1);
+ expect(rects[0].top).toBeLessThan(thresholdY);
+ expect(rects[0].bottom).toBeLessThanOrEqual(thresholdY + EPS);
+ },
+ );
+
+ it.each([AlertThresholdType.BELOW, AlertThresholdType.BELOW_OR_EQUAL])(
+ 'shades below the threshold line for %s',
+ thresholdType => {
+ const { rects, thresholdY } = renderAreas(thresholdType, 50);
+ expect(rects).toHaveLength(1);
+ expect(rects[0].top).toBeGreaterThanOrEqual(thresholdY - EPS);
+ expect(rects[0].bottom).toBeGreaterThan(thresholdY);
+ },
+ );
+
+ it('shades the band between the two thresholds for BETWEEN', () => {
+ const { rects, thresholdY, thresholdMaxY } = renderAreas(
+ AlertThresholdType.BETWEEN,
+ 30,
+ 70,
+ );
+ expect(rects).toHaveLength(1);
+ expect(thresholdMaxY).toBeDefined();
+ expect(rects[0].top).toBeCloseTo(thresholdMaxY!, 0);
+ expect(rects[0].bottom).toBeCloseTo(thresholdY, 0);
+ });
+
+ it('shades below the lower bound and above the upper bound for NOT_BETWEEN', () => {
+ const { rects, thresholdY, thresholdMaxY } = renderAreas(
+ AlertThresholdType.NOT_BETWEEN,
+ 30,
+ 70,
+ );
+ expect(rects).toHaveLength(2);
+ expect(thresholdMaxY).toBeDefined();
+
+ const lower = rects.find(r => r.bottom > thresholdY)!;
+ const upper = rects.find(r => r.top < thresholdMaxY!)!;
+ // Lower firing region: from the lower threshold line downward.
+ expect(lower.top).toBeCloseTo(thresholdY, 0);
+ // Upper firing region: from the upper threshold line upward.
+ expect(upper.bottom).toBeCloseTo(thresholdMaxY!, 0);
+ });
+});