From 133b989698b6d64f343e6aa014895caf59e40f34 Mon Sep 17 00:00:00 2001
From: Anay Dhawan
Date: Thu, 26 Nov 2026 18:08:10 +0530
Subject: [PATCH] Stats: list the higher series first in the traffic tooltip
The tooltip listed visitors above page views, the reverse of the chart where the
page views line sits above the visitors line. Rows are now sorted by value, so
the order always matches the lines. Adds a test that fails without the change.
---
src/app/stats/page.test.tsx | 16 ++++++++++++++++
src/components/traffic/traffic-chart.tsx | 3 ++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/app/stats/page.test.tsx b/src/app/stats/page.test.tsx
index 24638b1..1b78447 100644
--- a/src/app/stats/page.test.tsx
+++ b/src/app/stats/page.test.tsx
@@ -236,4 +236,20 @@ describe("Stats page, Visitors view", () => {
fireEvent.blur(month);
});
+
+ it("lists the higher series first in the tooltip, like the lines on the chart", () => {
+ openVisitors();
+
+ const month = screen.getByRole("img", { name: /November 2026: 1,743 visitors/ });
+ fireEvent.focus(month);
+ const chart = screen.getByRole("group", { name: "Visitors and page views per month" });
+ const tooltip = chart.querySelector('[aria-hidden="true"].bg-popover');
+ expect(tooltip).not.toBeNull();
+ const text = tooltip!.textContent ?? "";
+ // Page views are always at least visitors, so they come first and visitors sit below.
+ expect(text.indexOf("Page views")).toBeGreaterThan(-1);
+ expect(text.indexOf("Page views")).toBeLessThan(text.indexOf("Visitors"));
+
+ fireEvent.blur(month);
+ });
});
diff --git a/src/components/traffic/traffic-chart.tsx b/src/components/traffic/traffic-chart.tsx
index 65f4933..a18d3bc 100644
--- a/src/components/traffic/traffic-chart.tsx
+++ b/src/components/traffic/traffic-chart.tsx
@@ -398,7 +398,8 @@ export function TrafficChart({ rows, metrics, kind, valueLabel }: TrafficChartPr
{valueLabel ? `, ${valueLabel.toLowerCase()}` : ""}
- {series.map((s) => (
+ {/* Highest value first, so the rows sit in the same order as the lines on the chart. */}
+ {[...series].sort((a, b) => activeRow[b.key] - activeRow[a.key]).map((s) => (