: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(mcp): let people resize the chart explanation panel (#125433)
Sam Penningtonc0fae73ca7bb
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex dadc047dff1e..63c7188a813c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6239,9 +6239,9 @@ snapshots:mcp-apps-experiments--running--light:hash: v1.k794b7964.f7ae67feb87956b98204afeb00f52012a62fc090b18d186d0575110924e5cb69.lWvegECniqeejO8WWNUVam5X0NQTkwxq2iifV-mN5JImcp-apps-explain-chart--chapter-beside-the-chart--light:- hash: v1.k794b7964.59974ba8a33be7e981f575614bb77b3fe73dc905c9f6cb5db54e61591c7484ae.Qzl-nCRtGQHeYMHKmGsneXCagaDtWsjsyZlavdRVmmU+ hash: v1.k794b7964.1b3a4ae5d4f98f938dda78e7339e93624825472835fce63a58f960d535986fe6.fM-kwGLy2mjTyMtlHv_or2Sxi83wlTcjjs4xOPz_Ldomcp-apps-explain-chart--evidence-chart--light:- hash: v1.k794b7964.c25bffca27dae4d96ed3a8a534297c79fc55e9f5a332472bedfeb46f4cb79bd8.DQxHAg-l47utDGyaTLdaaAMkkaLBaeHnxF-YTKFnmh0+ hash: v1.k794b7964.850e4f7171b0ba2dc7a44928d12787534ec33bff3f8d7108a8022690a166150c.Q0BhB8TGCyT0vAZK4wlYvG7qORDvCZaMQWMoHGZsmSwmcp-apps-explain-chart--single-chapter--light:hash: v1.k794b7964.8d0d4e81255c25acbe114b45d698a66d4b3ff5be122c97eea1f5cc2066711a72.jx6b5OO_YEIBQZHEUccM0lJ6vaRZBUUWxs3dJgxxwKwmcp-apps-explain-chart--summary--light:diff --git a/products/product_analytics/mcp/apps/explainChart/ExplainChartView.tsx b/products/product_analytics/mcp/apps/explainChart/ExplainChartView.tsxindex 466ff3055a08..235a1048a7f7 100644--- a/products/product_analytics/mcp/apps/explainChart/ExplainChartView.tsx+++ b/products/product_analytics/mcp/apps/explainChart/ExplainChartView.tsx@@ -1,5 +1,5 @@import { ArrowLeft } from 'lucide-react'-import { type ReactElement, type ReactNode, useEffect, useMemo, useState } from 'react'+import { type CSSProperties, type ReactElement, type ReactNode, useEffect, useMemo, useRef, useState } from 'react'import { Button, Text } from '@posthog/quill'@@ -7,10 +7,16 @@ import type { ExplainChartData, StoryChapter, StoryEvidence } from './explainChaimport { StoryChapterView } from './StoryChapterView'import { StoryChartOverlay } from './StoryChartOverlay'import { buildStoryPages, type StoryPage } from './storyPages'+import { StoryPanelResizeGrip } from './StoryPanelResizeGrip'import { StorySingleChapterView } from './StorySingleChapterView'import { StorySteps } from './StorySteps'import { StorySummaryView } from './StorySummaryView'+// The panel takes a share of the space, so a small screen keeps more of it for the chart.+const DEFAULT_PANEL_WIDTH = 'clamp(280px, 35%, 420px)'+const MIN_PANEL_WIDTH = 240+const MIN_CHART_WIDTH = 320+const wholeFormat = new Intl.NumberFormat('en-US', { maximumFractionDigits: 1 })const smallFormat = new Intl.NumberFormat('en-US', { maximumSignificantDigits: 2 })const defaultFormat = (value: number): string =>@@ -77,6 +83,12 @@ export function ExplainChartView({const [activeIndex, setActiveIndex] = useState(singleChapter ? 1 : 0)const [previewIndex, setPreviewIndex] = useState<number | null>(null)const [shownEvidenceIndex, setShownEvidenceIndex] = useState<number | null>(null)+ // Null keeps the default width until the panel is dragged.+ const [panelWidth, setPanelWidth] = useState<number | null>(null)+ const rowRef = useRef<HTMLDivElement>(null)+ const asideRef = useRef<HTMLElement>(null)+ const maxPanelWidth = (): number =>+ Math.max(MIN_PANEL_WIDTH, (rowRef.current?.clientWidth ?? Infinity) - MIN_CHART_WIDTH)const active = pages[activeIndex] ?? pages[0]!const hasNext = activeIndex + 1 < pages.lengthconst shownEvidence: StoryEvidence | null =@@ -125,7 +137,7 @@ export function ExplainChartView({return (<div className="@container/story" data-attr="explain-chart">- <div className="flex flex-col @3xl/story:flex-row">+ <div ref={rowRef} className="flex flex-col @3xl/story:flex-row"><div className="min-w-0 flex-1">{/* The header is one line in both views, so showing an evidence chart moves nothing. The evidence's text stays highlighted in the panel. */}{evidenceCharts && evidenceView ? (@@ -155,9 +167,26 @@ export function ExplainChartView({)}</div><aside- className="relative shrink-0 border-t border-border @3xl/story:w-80 @3xl/story:border-t-0 @3xl/story:border-l"+ ref={asideRef}+ className="relative shrink-0 border-t border-border @3xl/story:w-(--story-panel-width) @3xl/story:border-t-0 @3xl/story:border-l"+ style={+ {+ // The browser keeps room for the chart when the space shrinks after a drag.+ '--story-panel-width':+ panelWidth === null+ ? DEFAULT_PANEL_WIDTH+ : `clamp(${MIN_PANEL_WIDTH}px, ${panelWidth}px, calc(100% - ${MIN_CHART_WIDTH}px))`,+ } as CSSProperties+ }aria-label="Explanation of this chart">+ <StoryPanelResizeGrip+ getWidth={() => asideRef.current?.offsetWidth ?? panelWidth ?? MIN_PANEL_WIDTH}+ minWidth={MIN_PANEL_WIDTH}+ maxWidth={maxPanelWidth()}+ onResize={(width) => setPanelWidth(Math.min(Math.max(width, MIN_PANEL_WIDTH), maxPanelWidth()))}+ onReset={() => setPanelWidth(null)}+ />{/* Beside the chart, the panel takes the chart's height and the page scrolls inside it. */}<div className="flex flex-col @3xl/story:absolute @3xl/story:inset-0">{/* Keyed on the page, so each chapter opens at its top and an evidence chart keeps the scroll. */}@@ -192,7 +221,8 @@ export function ExplainChartView({/>)}</div>- {!singleChapter && (+ {/* One chapter shows on its own and a chart with none shows its summary alone, so steps add nothing. */}+ {pages.length > 2 && (<div className="flex items-center justify-between gap-3 border-t border-border py-2 ps-4 pe-3"><StoryStepspages={pages}diff --git a/products/product_analytics/mcp/apps/explainChart/StoryPanelResizeGrip.tsx b/products/product_analytics/mcp/apps/explainChart/StoryPanelResizeGrip.tsxnew file mode 100644index 000000000000..1fac1f2e2c33--- /dev/null+++ b/products/product_analytics/mcp/apps/explainChart/StoryPanelResizeGrip.tsx@@ -0,0 +1,65 @@+import { type KeyboardEvent, type PointerEvent, type ReactElement, useRef } from 'react'++import { ResizeGrip } from '@posthog/quill'++const KEYBOARD_STEP = 16++export interface StoryPanelResizeGripProps {+ getWidth: () => number+ minWidth: number+ maxWidth: number+ onResize: (width: number) => void+ onReset: () => void+}++/** The drag handle on the panel's start edge. Dragging toward the chart widens the panel. */+export function StoryPanelResizeGrip({+ getWidth,+ minWidth,+ maxWidth,+ onResize,+ onReset,+}: StoryPanelResizeGripProps): ReactElement {+ const drag = useRef<{ x: number; width: number } | null>(null)++ const onPointerDown = (event: PointerEvent<HTMLDivElement>): void => {+ if (event.button !== 0) {+ return+ }+ event.preventDefault()+ event.currentTarget.setPointerCapture(event.pointerId)+ drag.current = { x: event.clientX, width: getWidth() }+ }++ const onPointerMove = (event: PointerEvent<HTMLDivElement>): void => {+ if (drag.current) {+ onResize(drag.current.width + drag.current.x - event.clientX)+ }+ }++ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {+ if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {+ event.preventDefault()+ onResize(getWidth() + (event.key === 'ArrowLeft' ? KEYBOARD_STEP : -KEYBOARD_STEP))+ }+ }++ return (+ <ResizeGrip+ aria-label="Resize the explanation"+ aria-valuenow={Math.round(getWidth())}+ aria-valuemin={minWidth}+ aria-valuemax={Number.isFinite(maxWidth) ? Math.round(maxWidth) : undefined}+ tabIndex={0}+ // The panel's border is the line, so only the pill shows, centered on that border.+ className="absolute inset-y-0 start-0 z-10 hidden -translate-x-1/2 bg-transparent [--quill-resizable-hit-size:0.5rem] @3xl/story:flex rtl:translate-x-1/2"+ onPointerDown={onPointerDown}+ onPointerMove={onPointerMove}+ onPointerUp={() => (drag.current = null)}+ onPointerCancel={() => (drag.current = null)}+ onKeyDown={onKeyDown}+ onDoubleClick={onReset}+ data-attr="explain-chart-panel-resize"+ />+ )+}diff --git a/products/product_analytics/mcp/apps/explainChart/StorySummaryView.tsx b/products/product_analytics/mcp/apps/explainChart/StorySummaryView.tsxindex 47a91b521315..1e2988bd429a 100644--- a/products/product_analytics/mcp/apps/explainChart/StorySummaryView.tsx+++ b/products/product_analytics/mcp/apps/explainChart/StorySummaryView.tsx@@ -64,7 +64,7 @@ export function StorySummaryView({<li key={index}><buttontype="button"- className="flex w-full cursor-pointer items-center gap-2.5 rounded-md border-0 bg-transparent px-2 py-1.5 text-start hover:bg-muted focus-visible:outline-2 focus-visible:outline-ring"+ className="flex w-full cursor-pointer items-center gap-2.5 rounded-md border-0 bg-transparent px-2 py-1.5 text-start hover:bg-fill-hover focus-visible:outline-2 focus-visible:outline-ring"onClick={() => onSelect(index)}onMouseEnter={() => onPreview(index)}onMouseLeave={() => onPreview(null)}