Skip to content

Commit ed6b3fd

Browse files
committed
feat: Add zoom, scroll and hover values to the monitoring charts
The DQM time series and distribution charts were static SVG with no way to read exact values, and the time series joined every window length into one line. - Time series: plot one window length at a time (the one picked in View, or daily when View is the baseline) and keep the baseline row off the line. - Time series and distribution: hover shows exact values, drag to zoom, zoom in/out/reset buttons, and sideways scrolling through all the data while zoomed in. - Distribution: leave room above the plot so the top axis label is not cut off. Signed-off-by: Chaitany Patel <patelchaitany93@gmail.com>
1 parent 72013d3 commit ed6b3fd

5 files changed

Lines changed: 1274 additions & 327 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import React from "react";
2+
import { EuiProvider } from "@elastic/eui";
3+
import { QueryClient, QueryClientProvider } from "react-query";
4+
import { MemoryRouter, Route, Routes } from "react-router-dom";
5+
import { http, HttpResponse } from "msw";
6+
import { setupServer } from "msw/node";
7+
import { fireEvent, render, screen } from "@testing-library/react";
8+
9+
import DataModeContext from "../../contexts/DataModeContext";
10+
import FeatureMetricsDetail from "./FeatureMetricsDetail";
11+
import type { FeatureMetric } from "../../queries/useMonitoringApi";
12+
13+
const row = (
14+
metric_date: string,
15+
granularity: string,
16+
mean: number,
17+
): FeatureMetric => ({
18+
project_id: "demo",
19+
feature_view_name: "driver_stats",
20+
feature_name: "conv_rate",
21+
metric_date,
22+
granularity,
23+
data_source_type: "batch",
24+
computed_at: "2026-10-31T00:00:00Z",
25+
max_event_timestamp: null,
26+
is_baseline: granularity === "baseline",
27+
feature_type: "numeric",
28+
row_count: 100,
29+
null_count: 0,
30+
null_rate: 0,
31+
mean,
32+
stddev: 0.1,
33+
min_val: 0,
34+
max_val: 1,
35+
p50: 0.5,
36+
p75: null,
37+
p90: null,
38+
p95: 0.9,
39+
p99: null,
40+
histogram: null,
41+
});
42+
43+
const daily = Array.from({ length: 30 }, (_, i) =>
44+
row(`2026-10-${String(i + 1).padStart(2, "0")}`, "daily", (i + 1) / 100),
45+
);
46+
const monthly = row("2026-09-01", "monthly", 0.3);
47+
const baseline: FeatureMetric = {
48+
...row("2026-10-31", "baseline", 0.47),
49+
histogram: {
50+
bins: [0, 0.1, 0.2, 0.3, 0.4],
51+
counts: [60, 30, 10, 4, 1],
52+
bin_width: 0.1,
53+
},
54+
};
55+
56+
const server = setupServer(
57+
http.get("/api/v1/monitoring/metrics/features", () =>
58+
HttpResponse.json([...daily, monthly, baseline]),
59+
),
60+
http.get("/api/v1/monitoring/metrics/baseline", () =>
61+
HttpResponse.json([baseline]),
62+
),
63+
);
64+
65+
beforeAll(() => server.listen());
66+
afterAll(() => server.close());
67+
68+
test("monitoring charts show values on hover and zoom", async () => {
69+
render(
70+
<QueryClientProvider
71+
client={
72+
new QueryClient({ defaultOptions: { queries: { retry: false } } })
73+
}
74+
>
75+
<DataModeContext.Provider value={{}}>
76+
<EuiProvider>
77+
<MemoryRouter
78+
initialEntries={[
79+
"/p/demo/monitoring/feature/driver_stats/conv_rate",
80+
]}
81+
>
82+
<Routes>
83+
<Route
84+
path="/p/:projectName/monitoring/feature/:featureViewName/:featureName"
85+
element={<FeatureMetricsDetail />}
86+
/>
87+
</Routes>
88+
</MemoryRouter>
89+
</EuiProvider>
90+
</DataModeContext.Provider>
91+
</QueryClientProvider>,
92+
);
93+
94+
// Only daily windows: the monthly row (09-01) and the baseline (10-31)
95+
// would stretch the range if they were plotted.
96+
expect(
97+
await screen.findByText(/Showing daily windows 2026-10-01 – 2026-10-30\./),
98+
).toBeInTheDocument();
99+
// Axis labels are calendar days, with no time-zone hour added.
100+
expect(screen.getAllByText("10-01").length).toBeGreaterThan(0);
101+
expect(screen.queryByText(/\d{2}-\d{2} \d{2}:\d{2}/)).toBeNull();
102+
103+
// Hovering a distribution bar shows its range and count. The compact
104+
// chart puts 5 bars of 92 px from x 54, so x 340 is the fourth bar.
105+
const histogram = screen.getByRole("img", { name: "Histogram" });
106+
fireEvent.mouseMove(histogram, { clientX: 340 });
107+
const tooltip = screen.getByRole("tooltip");
108+
expect(tooltip).toHaveTextContent("0.30 – 0.40");
109+
expect(tooltip).toHaveTextContent("Count4");
110+
fireEvent.mouseLeave(histogram);
111+
112+
// Drag across the left half of the plot (x 60 to 450 of 780 wide).
113+
const [drift] = screen.getAllByTestId("time-series-chart");
114+
fireEvent.mouseDown(drift, { clientX: 60, button: 0 });
115+
fireEvent.mouseMove(drift, { clientX: 450 });
116+
fireEvent.mouseUp(drift, { clientX: 450 });
117+
expect(
118+
screen.getByText(/Showing daily windows 2026-10-01 – 2026-10-15\./),
119+
).toBeInTheDocument();
120+
121+
// Hovering the first point shows its date and mean.
122+
fireEvent.mouseMove(drift, { clientX: 60 });
123+
expect(screen.getByText("2026-10-01")).toBeInTheDocument();
124+
expect(screen.getByText("0.01")).toBeInTheDocument();
125+
126+
// Zoomed in, scrolling sideways moves through the rest of the data.
127+
// 780 px is one plot width, so the window moves on by its own length.
128+
const [scroller] = screen.getAllByTestId("time-series-scroll");
129+
scroller.scrollLeft = 780;
130+
fireEvent.scroll(scroller);
131+
expect(
132+
screen.getByText(/Showing daily windows 2026-10-15 – 2026-10-30\./),
133+
).toBeInTheDocument();
134+
135+
fireEvent.doubleClick(drift);
136+
expect(
137+
screen.getByText(/Showing daily windows 2026-10-01 – 2026-10-30\./),
138+
).toBeInTheDocument();
139+
});

‎ui/src/pages/monitoring/FeatureMetricsDetail.tsx‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ const GRANULARITY_LABELS: Record<string, string> = {
4040
[BASELINE_KEY]: "Baseline",
4141
};
4242

43+
// Window lengths the time series can plot, shortest first. The baseline
44+
// covers all data at once, so it is never a point on the line.
45+
const SERIES_GRANULARITIES = [
46+
"daily",
47+
"weekly",
48+
"biweekly",
49+
"monthly",
50+
"quarterly",
51+
];
52+
4353
const FeatureMetricsDetail = () => {
4454
const { projectName, featureViewName, featureName } = useParams();
4555
const navigate = useNavigate();
@@ -113,6 +123,19 @@ const FeatureMetricsDetail = () => {
113123
return matching.reduce((a, b) => (a.metric_date > b.metric_date ? a : b));
114124
}, [metrics, effectiveGranularity, baselineMetric]);
115125

126+
// Plot one window length at a time: the one picked in View, or the
127+
// shortest one with data when View is the baseline.
128+
const seriesGranularity =
129+
SERIES_GRANULARITIES.includes(effectiveGranularity) &&
130+
availableGranularities.includes(effectiveGranularity)
131+
? effectiveGranularity
132+
: SERIES_GRANULARITIES.find((g) => availableGranularities.includes(g));
133+
134+
const seriesMetrics = useMemo(
135+
() => (metrics ?? []).filter((m) => m.granularity === seriesGranularity),
136+
[metrics, seriesGranularity],
137+
);
138+
116139
const breadcrumbs = [
117140
{
118141
text: "Monitoring",
@@ -242,12 +265,13 @@ const FeatureMetricsDetail = () => {
242265
</EuiFlexItem>
243266
</EuiFlexGroup>
244267

245-
{metrics && metrics.length > 1 && (
268+
{seriesGranularity && seriesMetrics.length > 0 && (
246269
<>
247270
<EuiSpacer size="xl" />
248271
<TimeSeriesAnalysis
249-
metrics={metrics}
272+
metrics={seriesMetrics}
250273
featureType={activeMetric.feature_type}
274+
granularityLabel={GRANULARITY_LABELS[seriesGranularity]}
251275
/>
252276
</>
253277
)}

0 commit comments

Comments
 (0)