Skip to content

Commit 82d263c

Browse files
feat: Add zoom, scroll and hover values to the monitoring charts (#7090)
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 a4e7d12 commit 82d263c

5 files changed

Lines changed: 1296 additions & 362 deletions

File tree

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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 histogram = {
44+
bins: [0, 0.1, 0.2, 0.3, 0.4],
45+
counts: [60, 30, 10, 4, 1],
46+
bin_width: 0.1,
47+
};
48+
const daily = Array.from({ length: 30 }, (_, i) =>
49+
row(`2026-10-${String(i + 1).padStart(2, "0")}`, "daily", (i + 1) / 100),
50+
);
51+
// The newest daily window is the one the page shows.
52+
daily[29] = { ...daily[29], histogram };
53+
const monthly = row("2026-09-01", "monthly", 0.3);
54+
const baseline: FeatureMetric = {
55+
...row("2026-10-31", "baseline", 0.47),
56+
histogram,
57+
};
58+
59+
const server = setupServer(
60+
http.get("/api/v1/monitoring/metrics/features", () =>
61+
HttpResponse.json([...daily, monthly, baseline]),
62+
),
63+
http.get("/api/v1/monitoring/metrics/baseline", () =>
64+
HttpResponse.json([baseline]),
65+
),
66+
);
67+
68+
beforeAll(() => server.listen());
69+
afterAll(() => server.close());
70+
71+
test("monitoring charts show values on hover and zoom", async () => {
72+
render(
73+
<QueryClientProvider
74+
client={
75+
new QueryClient({ defaultOptions: { queries: { retry: false } } })
76+
}
77+
>
78+
<DataModeContext.Provider value={{}}>
79+
<EuiProvider>
80+
<MemoryRouter
81+
initialEntries={[
82+
"/p/demo/monitoring/feature/driver_stats/conv_rate",
83+
]}
84+
>
85+
<Routes>
86+
<Route
87+
path="/p/:projectName/monitoring/feature/:featureViewName/:featureName"
88+
element={<FeatureMetricsDetail />}
89+
/>
90+
</Routes>
91+
</MemoryRouter>
92+
</EuiProvider>
93+
</DataModeContext.Provider>
94+
</QueryClientProvider>,
95+
);
96+
97+
// Only daily windows: the monthly row (09-01) and the baseline (10-31)
98+
// would stretch the range if they were plotted.
99+
expect(
100+
await screen.findByText(/Showing daily windows 2026-10-01 – 2026-10-30\./),
101+
).toBeInTheDocument();
102+
// Axis labels are calendar days, with no time-zone hour added.
103+
expect(screen.getAllByText("10-01").length).toBeGreaterThan(0);
104+
expect(screen.queryByText(/\d{2}-\d{2} \d{2}:\d{2}/)).toBeNull();
105+
106+
// Hovering a distribution bar shows its range and count. The compact
107+
// chart puts 5 bars of 92 px from x 54, so x 340 is the fourth bar.
108+
const histogram = screen.getByRole("img", { name: "Histogram" });
109+
fireEvent.mouseMove(histogram, { clientX: 340 });
110+
const tooltip = screen.getByRole("tooltip");
111+
expect(tooltip).toHaveTextContent("0.30 – 0.40");
112+
expect(tooltip).toHaveTextContent("Count4");
113+
fireEvent.mouseLeave(histogram);
114+
115+
// Drag across the left half of the plot (x 60 to 450 of 780 wide).
116+
const [drift] = screen.getAllByTestId("time-series-chart");
117+
fireEvent.mouseDown(drift, { clientX: 60, button: 0 });
118+
fireEvent.mouseMove(drift, { clientX: 450 });
119+
fireEvent.mouseUp(drift, { clientX: 450 });
120+
expect(
121+
screen.getByText(/Showing daily windows 2026-10-01 – 2026-10-15\./),
122+
).toBeInTheDocument();
123+
124+
// Hovering the first point shows its date and mean.
125+
fireEvent.mouseMove(drift, { clientX: 60 });
126+
expect(screen.getByText("2026-10-01")).toBeInTheDocument();
127+
expect(screen.getByText("0.01")).toBeInTheDocument();
128+
129+
// Zoomed in, scrolling sideways moves through the rest of the data.
130+
// 780 px is one plot width, so the window moves on by its own length.
131+
const [scroller] = screen.getAllByTestId("time-series-scroll");
132+
scroller.scrollLeft = 780;
133+
fireEvent.scroll(scroller);
134+
expect(
135+
screen.getByText(/Showing daily windows 2026-10-15 – 2026-10-30\./),
136+
).toBeInTheDocument();
137+
138+
fireEvent.doubleClick(drift);
139+
expect(
140+
screen.getByText(/Showing daily windows 2026-10-01 – 2026-10-30\./),
141+
).toBeInTheDocument();
142+
});

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

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

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

132+
// Plot one window length at a time: the one picked in View, or the
133+
// shortest one with data when View is the baseline.
134+
const seriesGranularity =
135+
SERIES_GRANULARITIES.includes(effectiveGranularity) &&
136+
availableGranularities.includes(effectiveGranularity)
137+
? effectiveGranularity
138+
: SERIES_GRANULARITIES.find((g) => availableGranularities.includes(g));
139+
140+
const seriesMetrics = useMemo(
141+
() =>
142+
(metrics ?? []).filter(
143+
(m) => !isBaselineMetricRow(m) && m.granularity === seriesGranularity,
144+
),
145+
[metrics, seriesGranularity],
146+
);
147+
122148
const breadcrumbs = [
123149
{
124150
text: "Monitoring",
@@ -248,41 +274,19 @@ const FeatureMetricsDetail = () => {
248274
</EuiFlexItem>
249275
</EuiFlexGroup>
250276

251-
{metrics && effectiveGranularity !== BASELINE_KEY && (
252-
<TimeSeriesSection
253-
metrics={metrics}
254-
granularity={effectiveGranularity}
255-
featureType={activeMetric.feature_type}
256-
/>
277+
{seriesGranularity && seriesMetrics.length > 0 && (
278+
<>
279+
<EuiSpacer size="xl" />
280+
<TimeSeriesAnalysis
281+
metrics={seriesMetrics}
282+
featureType={activeMetric.feature_type}
283+
granularityLabel={GRANULARITY_LABELS[seriesGranularity]}
284+
/>
285+
</>
257286
)}
258287
</EuiPageTemplate.Section>
259288
</EuiPageTemplate>
260289
);
261290
};
262291

263-
/**
264-
* One window length at a time: plotting every granularity (and the baseline)
265-
* by metric_date mixes spans, so the "drift" line has no meaning (#7054).
266-
*/
267-
const TimeSeriesSection = ({
268-
metrics,
269-
granularity,
270-
featureType,
271-
}: {
272-
metrics: NonNullable<ReturnType<typeof useFeatureMetrics>["data"]>;
273-
granularity: string;
274-
featureType: string;
275-
}) => {
276-
const windowRows = metrics.filter(
277-
(m) => !isBaselineMetricRow(m) && m.granularity === granularity,
278-
);
279-
if (windowRows.length === 0) return null;
280-
return (
281-
<>
282-
<EuiSpacer size="xl" />
283-
<TimeSeriesAnalysis metrics={windowRows} featureType={featureType} />
284-
</>
285-
);
286-
};
287-
288292
export default FeatureMetricsDetail;

0 commit comments

Comments
 (0)