Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(engineering-analytics): show full run activity range (#71630)

Paul D'Ambrace13f1ccb600
diff --git a/products/engineering_analytics/frontend/components/RunActivityChart.tsx b/products/engineering_analytics/frontend/components/RunActivityChart.tsx
index f85fc262825a..bb2009ccfd79 100644
--- a/products/engineering_analytics/frontend/components/RunActivityChart.tsx
+++ b/products/engineering_analytics/frontend/components/RunActivityChart.tsx
@@ -61,9 +61,8 @@ export const isPlottable = (run: ActivityRun): run is ActivityRun & { startedAt:
export function hasEnoughRunActivity(runs: ActivityRun[]): boolean {
return runs.filter(isPlottable).length >= MIN_POINTS
}
-// The focus lens defaults to the most recent day — the "live" view — over a window that's wider than that.
-// Below this much total span there's nothing to pan over, so the brush is hidden and the chart shows it all.
-const LENS_MS = 24 * 60 * 60 * 1000
+// Below this total span the chart is already readable without a zoom brush.
+const BRUSH_THRESHOLD_MS = 24 * 60 * 60 * 1000
// The lens never narrows below 15 min, so it stays grabbable and the zoomed axis keeps a readable span.
const MIN_LENS_MS = 15 * 60 * 1000
// A run with no final duration counts as in flight up to now, capped here: one that started longer ago
@@ -237,11 +236,11 @@ export function RunActivityChart({
noun = 'run',
className,
}: RunActivityChartProps): JSX.Element | null {
- // The lens sub-range the scatter/band zoom into; null = the default (most recent day). Declared before
+ // The lens sub-range the scatter/band zoom into; null = the full loaded window. Declared before
// the early return so the hook order is stable when there aren't enough points to draw.
const [focus, setFocus] = useState<TimeRange | null>(null)
// Drop a manual pan when the runs change (e.g. the shared window changed and reloaded) so the lens
- // returns to the live default instead of clamping a stale range onto an unrelated slice of new data.
+ // returns to the full window instead of clamping a stale range onto an unrelated slice of new data.
useEffect(() => {
setFocus(null)
}, [runs])
@@ -276,8 +275,8 @@ export function RunActivityChart({
// y (duration) scale and median stay over the full set, so panning never jumps the vertical axis.
const fullMin = Math.min(...intervals.map((iv) => iv.start))
const fullMax = Math.max(...intervals.map((iv) => iv.end))
- const brushable = fullMax - fullMin > LENS_MS
- const view = clampFocus(focus ?? defaultFocus(fullMin, fullMax, LENS_MS), fullMin, fullMax, MIN_LENS_MS)
+ const brushable = fullMax - fullMin > BRUSH_THRESHOLD_MS
+ const view = clampFocus(focus ?? defaultFocus(fullMin, fullMax), fullMin, fullMax, MIN_LENS_MS)
const tMin = view.start
const tMax = view.end
const tSpan = Math.max(1, tMax - tMin)
diff --git a/products/engineering_analytics/frontend/lib/brush.test.ts b/products/engineering_analytics/frontend/lib/brush.test.ts
index 4061aa3c1fc8..e0ed624fe64a 100644
--- a/products/engineering_analytics/frontend/lib/brush.test.ts
+++ b/products/engineering_analytics/frontend/lib/brush.test.ts
@@ -4,11 +4,9 @@ const HOUR = 3_600_000
const DAY = 24 * HOUR
describe('brush geometry', () => {
- it('defaultFocus picks the most recent lens-width, or the whole window when shorter', () => {
- // 7-day window, 24h lens → most recent day.
- expect(defaultFocus(0, 7 * DAY, DAY)).toEqual({ start: 6 * DAY, end: 7 * DAY })
- // Window already shorter than the lens → no sub-range to pan, focus the whole thing.
- expect(defaultFocus(0, 6 * HOUR, DAY)).toEqual({ start: 0, end: 6 * HOUR })
+ it('defaultFocus includes the full selected window', () => {
+ expect(defaultFocus(0, 7 * DAY)).toEqual({ start: 0, end: 7 * DAY })
+ expect(defaultFocus(0, 6 * HOUR)).toEqual({ start: 0, end: 6 * HOUR })
})
it('clampFocus slides a range back inside bounds while preserving its width', () => {
diff --git a/products/engineering_analytics/frontend/lib/brush.ts b/products/engineering_analytics/frontend/lib/brush.ts
index a7b1da4494a9..92312654b73a 100644
--- a/products/engineering_analytics/frontend/lib/brush.ts
+++ b/products/engineering_analytics/frontend/lib/brush.ts
@@ -1,6 +1,6 @@
// Pure geometry for the run-activity chart's focus lens — a context strip that shows the whole loaded
// window with a draggable lens selecting the sub-range the scatter and band zoom into. The default lens is
-// the most recent 24h (the live view), pannable back over older days and resizable up to the full window.
+// the full selected window and can be resized to zoom into a shorter period.
// Kept here, DOM-free, so the math (default placement, clamping, panning, resizing, px<->time) is unit-tested
// without rendering.
@@ -9,13 +9,9 @@ export interface TimeRange {
end: number
}
-/** The lens's initial position: the most recent `lensMs` of the window, or the whole window when it's
- * already shorter than the lens (nothing to pan over). */
-export function defaultFocus(tMin: number, tMax: number, lensMs: number): TimeRange {
- if (tMax - tMin <= lensMs) {
- return { start: tMin, end: tMax }
- }
- return { start: tMax - lensMs, end: tMax }
+/** The lens initially matches the selected date range so the chart and page filter stay aligned. */
+export function defaultFocus(tMin: number, tMax: number): TimeRange {
+ return { start: tMin, end: tMax }
}
/** Keep a range inside [tMin, tMax] and at least `minSpanMs` wide, preserving its width where possible so a