: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(insights): extend drag-to-zoom to lifecycle and funnel-trends charts (#69907)
Sam Penningtonfbdf66dd428a
diff --git a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsxindex 06c6ad58910d..75a44156ba7c 100644--- a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx@@ -360,7 +360,14 @@ export function InsightVizDisplay({/>)case InsightType.FUNNELS:- return <Funnel inCardView={embedded} inSharedMode={inSharedMode} showPersonsModal={!inSharedMode} />+ return (+ <Funnel+ context={context}+ inCardView={embedded}+ inSharedMode={inSharedMode}+ showPersonsModal={!inSharedMode}+ />+ )case InsightType.RETENTION:return (<RetentionContainerdiff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsxindex 15041c019c45..999f31fbcd08 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx@@ -2,9 +2,18 @@ import '@testing-library/jest-dom'import { cleanup, configure, screen, waitFor } from '@testing-library/react'-import { ensureJsdom, waitForHogChartTooltip } from '@posthog/quill-charts/testing'--import { buildFunnelsQuery, chart, getHogChart, personsModal, renderInsight } from '~/test/insight-testing'+import { dragSelection, ensureJsdom, waitForHogChartTooltip } from '@posthog/quill-charts/testing'++import { FEATURE_FLAGS } from 'lib/constants'++import {+ buildFunnelsQuery,+ chart,+ getHogChart,+ getQuerySource,+ personsModal,+ renderInsight,+} from '~/test/insight-testing'import { buildAnnotation } from '~/test/insight-testing/test-data'import { AnnotationScope } from '~/types'@@ -247,4 +256,37 @@ describe('FunnelLineChart', () => {})})++ describe('drag-to-zoom', () => {+ const zoomFlag = { [FEATURE_FLAGS.INSIGHT_DRAG_TO_ZOOM]: true }+ const totalLabels = 5 // funnelTrendsSteps.default has 5 days/labels++ it('reports the dragged range as day strings to context.onDateRangeZoom', async () => {+ const onDateRangeZoom = jest.fn()+ renderInsight({ query: buildFunnelsQuery(), context: { onDateRangeZoom }, featureFlags: zoomFlag })++ const canvas = await screen.findByLabelText(/chart with/i)+ dragSelection(canvas.parentElement!, 1, 3, totalLabels)++ await waitFor(() => {+ expect(onDateRangeZoom).toHaveBeenCalledWith('2024-06-11', '2024-06-13')+ })+ })++ it('ignores drags when the drag-to-zoom flag is off', async () => {+ const onDateRangeZoom = jest.fn()+ renderInsight({+ query: buildFunnelsQuery(),+ context: { onDateRangeZoom },+ featureFlags: { [FEATURE_FLAGS.INSIGHT_DRAG_TO_ZOOM]: false },+ })++ const canvas = await screen.findByLabelText(/chart with/i)+ dragSelection(canvas.parentElement!, 1, 3, totalLabels)++ // A regression dropping the flag gate would ship zoom to everyone.+ expect(onDateRangeZoom).not.toHaveBeenCalled()+ expect(getQuerySource().dateRange).toBeUndefined()+ })+ })})diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsxindex 60b61a14b35b..caa3be3eabef 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx@@ -10,7 +10,7 @@ import type {TooltipContext,} from '@posthog/quill-charts'-import { useChartConfig, useChartTheme } from 'lib/charts/hooks'+import { useChartConfig, useChartTheme, useDateRangeZoom } from 'lib/charts/hooks'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'@@ -62,6 +62,7 @@ function resolveGroupTypeLabel(}export function FunnelLineChart({+ context,inSharedMode,showPersonsModal: showPersonsModalProp = true,}: Omit<ChartParams, 'filters'>): JSX.Element | null {@@ -211,6 +212,8 @@ export function FunnelLineChart({[clickDeps])+ const onDateRangeZoom = useDateRangeZoom(annotationDates, context?.onDateRangeZoom)+const renderTooltip = useCallback((ctx: TooltipContext<FunnelSeriesMeta>): JSX.Element => {if (quillTooltipEnabled) {@@ -282,6 +285,7 @@ export function FunnelLineChart({config={chartConfig}tooltip={renderTooltip}onPointClick={showPersonsModal ? onPointClick : undefined}+ onDateRangeZoom={onDateRangeZoom}className="LineGraph"dataAttr="trend-line-graph-funnel"onError={handleChartError}diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsxindex 9d2c3eeb88d4..d17d2877e388 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx@@ -2,10 +2,19 @@ import '@testing-library/jest-dom'import { cleanup, screen, waitFor } from '@testing-library/react'-import { setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'+import { dragSelection, setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'++import { FEATURE_FLAGS } from 'lib/constants'import { LifecycleQuery, LifecycleQueryResponse, NodeKind } from '~/queries/schema/schema-general'-import { chart, type InsightQuery, type MockResponse, personsModal, renderInsight } from '~/test/insight-testing'+import {+ chart,+ getQuerySource,+ type InsightQuery,+ type MockResponse,+ personsModal,+ renderInsight,+} from '~/test/insight-testing'let cleanupJsdom: () => voidlet cleanupRaf: () => void@@ -153,4 +162,42 @@ describe('TrendsLifecycleChart', () => {expect(screen.queryByTestId('hog-chart-timeseries-bar-legend')).not.toBeInTheDocument()}})++ describe('drag-to-zoom', () => {+ const zoomFlag = { [FEATURE_FLAGS.INSIGHT_DRAG_TO_ZOOM]: true }++ it('reports the dragged range as day strings to context.onDateRangeZoom', async () => {+ const onDateRangeZoom = jest.fn()+ renderInsight({+ query: buildLifecycleQuery() as unknown as InsightQuery,+ mocks: { additionalMockResponses: lifecycleMocks },+ context: { onDateRangeZoom },+ featureFlags: zoomFlag,+ })++ const canvas = await screen.findByLabelText(/chart with/i)+ dragSelection(canvas.parentElement!, 1, 3, LIFECYCLE_LABELS.length)++ await waitFor(() => {+ expect(onDateRangeZoom).toHaveBeenCalledWith('2024-06-11', '2024-06-13')+ })+ })++ it('ignores drags when the drag-to-zoom flag is off', async () => {+ const onDateRangeZoom = jest.fn()+ renderInsight({+ query: buildLifecycleQuery() as unknown as InsightQuery,+ mocks: { additionalMockResponses: lifecycleMocks },+ context: { onDateRangeZoom },+ featureFlags: { [FEATURE_FLAGS.INSIGHT_DRAG_TO_ZOOM]: false },+ })++ const canvas = await screen.findByLabelText(/chart with/i)+ dragSelection(canvas.parentElement!, 1, 3, LIFECYCLE_LABELS.length)++ // A regression dropping the flag gate would ship zoom to everyone.+ expect(onDateRangeZoom).not.toHaveBeenCalled()+ expect(getQuerySource().dateRange).toBeUndefined()+ })+ })})diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsxindex 0d9792cc981b..917eb8693986 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx@@ -4,7 +4,7 @@ import { useCallback, useMemo } from 'react'import { TimeSeriesBarChart } from '@posthog/quill-charts'import type { ChartLegendConfig, PointClickData, TooltipContext } from '@posthog/quill-charts'-import { useChartConfig, useChartTheme } from 'lib/charts/hooks'+import { useChartConfig, useChartTheme, useDateRangeZoom } from 'lib/charts/hooks'import { getBarColorFromStatus } from 'lib/colors'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'@@ -183,6 +183,8 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLi[clickDeps])+ const onDateRangeZoom = useDateRangeZoom(currentPeriodResult?.days, context?.onDateRangeZoom)+const renderTooltip = useCallback((ctx: TooltipContext<TrendsSeriesMeta>) => {const sharedProps = {@@ -244,6 +246,7 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLitheme={theme}tooltip={renderTooltip}onPointClick={canHandleClick ? onPointClick : undefined}+ onDateRangeZoom={onDateRangeZoom}className="BarGraph"dataAttr="trend-lifecycle-graph"onError={handleChartError}