: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): let a query context hide the trends chart axes (#102752)
Sam Pennington90e95d09b5b6
diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex 6f6db031c712..b0b2512038ee 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -101,6 +101,8 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {* filter that returns nothing once the data moves. See `TaxonomicFilterProps.includeHiddenEvents`.*/includeHiddenEvents?: boolean+ /** Drop axis ticks and titles, for thumbnail-sized renders such as the chart type gallery. */+ hideAxes?: boolean}export type QueryContextColumnTitleComponent = ComponentType<{diff --git a/products/product_analytics/frontend/insights/trends/BoxPlot/BoxPlotChart.tsx b/products/product_analytics/frontend/insights/trends/BoxPlot/BoxPlotChart.tsxindex b28e544cde91..758296a425d2 100644--- a/products/product_analytics/frontend/insights/trends/BoxPlot/BoxPlotChart.tsx+++ b/products/product_analytics/frontend/insights/trends/BoxPlot/BoxPlotChart.tsx@@ -17,7 +17,7 @@ import { ChartParams } from '~/types'import { boxPlotChartLogic } from './boxPlotChartLogic'-export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Element {+export function BoxPlotChart({ showPersonsModal = true, context }: ChartParams): JSX.Element {const { insightProps } = useValues(insightLogic)const { boxplotData, seriesGroups, dateLabels, yAxisScaleType, querySource, interval, insightData, trendsFilter } =useValues(boxPlotChartLogic(insightProps))@@ -49,14 +49,17 @@ export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Elemconst formatValue = useCallback((value: number) => formatAggregationAxisValue(trendsFilter, value), [trendsFilter])+ const hideAxes = context?.hideAxesconst config = useChartConfig<BoxPlotConfig>(() => ({yScaleType: yAxisScaleType === 'log10' ? 'log' : 'linear',yTickFormatter: formatValue,+ hideXAxis: hideAxes,+ hideYAxis: hideAxes,showGrid: true,tooltip: { pinnable: true, placement: 'cursor' },}),- [yAxisScaleType, formatValue]+ [yAxisScaleType, formatValue, hideAxes])const handleBoxClick = useCallback(diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsxindex fc4d841940bd..44c4a10bea8e 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx@@ -211,6 +211,7 @@ export function TrendsBarChart({[trendsFilter, isPercentStackView, baseCurrency])+ const hideAxes = context?.hideAxesconst timeSeriesConfig: TimeSeriesBarChartConfig = useChartConfig(() => ({...buildTrendsBarTimeSeriesConfig({@@ -222,6 +223,7 @@ export function TrendsBarChart({interval,timezone,allDays: currentPeriodResult?.days ?? [],+ hideAxes,xAxisLabel: trendsFilter?.xAxisLabel,yAxisLabel: trendsFilter?.yAxisLabel,goalLines,@@ -241,6 +243,7 @@ export function TrendsBarChart({interval,timezone,currentPeriodResult?.days,+ hideAxes,trendsFilter?.xAxisLabel,trendsFilter?.yAxisLabel,goalLines,@@ -275,6 +278,8 @@ export function TrendsBarChart({yScaleType: yAxisScaleType === 'log10' ? 'log' : 'linear',axisOrientation: 'horizontal',barLayout: 'stacked',+ hideXAxis: hideAxes,+ hideYAxis: hideAxes,yTickFormatter: aggregatedYTickFormatter,xTickFormatter,xAxisLabel: trendsFilter?.xAxisLabel,@@ -290,6 +295,7 @@ export function TrendsBarChart({bars: { fitToHeight: embedded, divergingStack: true },}}, [+ hideAxes,yAxisScaleType,aggregatedYTickFormatter,trendsFilter?.xAxisLabel,diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.test.ts b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.test.tsindex 4bb6391a79ab..fdce5bcd2201 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.test.ts+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.test.ts@@ -331,6 +331,34 @@ describe('buildTrendsBarTimeSeriesConfig', () => {expect(cfg.xAxis).toEqual(expected)})+ it.each([+ { name: 'leaves axes visible by default', hideAxes: undefined, expectedHide: undefined },+ { name: 'hides axes while preserving their configuration', hideAxes: true, expectedHide: true },+ ])('$name', ({ hideAxes, expectedHide }) => {+ const tickFormatter = (value: string): string => `tick:${value}`+ const cfg = buildTrendsBarTimeSeriesConfig({+ isPercentStackView: false,+ isGrouped: false,+ hideAxes,+ interval: 'week',+ timezone: 'UTC',+ allDays: ['2024-01-01', '2024-01-08'],+ xAxisLabel: 'Signup date',+ yAxisLabel: 'Total events',+ xAxisTickFormatter: tickFormatter,+ })++ expect(cfg.xAxis).toMatchObject({+ label: 'Signup date',+ timezone: 'UTC',+ interval: 'week',+ allDays: ['2024-01-01', '2024-01-08'],+ tickFormatter,+ hide: expectedHide,+ })+ expect(cfg.yAxis).toMatchObject({ label: 'Total events', showGrid: true, hide: expectedHide })+ })+it('forwards the y-axis from buildTrendsYAxisConfig with showGrid: true', () => {const trendsFilter: TrendsFilter = { aggregationAxisFormat: 'duration', aggregationAxisPrefix: '~' }const cfg = buildTrendsBarTimeSeriesConfig({diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.tsindex 09610b113a70..3884c73c183b 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts@@ -96,6 +96,7 @@ export interface BuildTrendsBarTimeSeriesConfigOpts {allDays?: string[]xAxisLabel?: string | nullyAxisLabel?: string | null+ hideAxes?: boolean// Explicit x-axis tick formatter — used by hosts (e.g. MCP) that have label strings but no// interval/timezone for the auto date formatter. Mirrors the line config.xAxisTickFormatter?: (value: string, index: number) => string | null@@ -121,10 +122,12 @@ export function buildTrendsBarTimeSeriesConfig(interval: opts.interval ?? 'day',allDays: opts.allDays ?? [],tickFormatter: opts.xAxisTickFormatter,+ hide: opts.hideAxes,},yAxis: {...yAxis,label: normalizeAxisLabel(opts.yAxisLabel),+ hide: opts.hideAxes,},valueLabels: opts.valueLabels,goalLines: goalLineConfigs,diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsxindex e2e0c2273654..c709bc264190 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx@@ -294,6 +294,7 @@ export function TrendsLineChart({[series])+ const hideAxes = context?.hideAxesconst config = useChartConfig(() =>buildTrendsLineTimeSeriesConfig<IndexedTrendResult>({@@ -306,6 +307,7 @@ export function TrendsLineChart({interval,timezone,allDays,+ hideAxes,xAxisLabel: trendsFilter?.xAxisLabel,yAxisLabel: trendsFilter?.yAxisLabel,yAxisStartAtZero: trendsFilter?.yAxisStartAtZero,@@ -337,6 +339,7 @@ export function TrendsLineChart({interval,timezone,allDays,+ hideAxes,goalLines,incompletenessOffsetFromEnd,getTrendsHidden,diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.tsindex 7a2a0fc82ebe..bb72c89848a9 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts@@ -419,6 +419,33 @@ describe('trendsChartTransforms', () => {})+ it.each([+ { name: 'leaves axes visible by default', hideAxes: undefined, expectedHide: undefined },+ { name: 'hides axes while preserving their configuration', hideAxes: true, expectedHide: true },+ ])('$name', ({ hideAxes, expectedHide }) => {+ const tickFormatter = (value: string): string => `tick:${value}`+ const config = buildTrendsLineTimeSeriesConfig({+ ...baseOpts,+ hideAxes,+ interval: 'week',+ timezone: 'UTC',+ allDays: ['2024-01-01', '2024-01-08'],+ xAxisLabel: 'Signup date',+ yAxisLabel: 'Unique users',+ xAxisTickFormatter: tickFormatter,+ })++ expect(config.xAxis).toMatchObject({+ label: 'Signup date',+ timezone: 'UTC',+ interval: 'week',+ allDays: ['2024-01-01', '2024-01-08'],+ tickFormatter,+ hide: expectedHide,+ })+ expect(config.yAxis).toMatchObject({ label: 'Unique users', showGrid: true, hide: expectedHide })+ })+it('passes xAxisTickFormatter through to the x-axis', () => {const tickFormatter = (value: string): string => `tick:${value}`const config = buildTrendsLineTimeSeriesConfig({ ...baseOpts, xAxisTickFormatter: tickFormatter })diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.tsindex b486685e9aa9..435d805719c3 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts@@ -193,6 +193,7 @@ export interface BuildTrendsLineTimeSeriesConfigOpts<R extends TrendsResultLike>allDays?: string[]xAxisLabel?: string | nullyAxisLabel?: string | null+ hideAxes?: booleanxAxisTickFormatter?: (value: string, index: number) => string | nullgoalLines?: GoalLineLike[] | nullincompletenessOffsetFromEnd?: number@@ -246,10 +247,12 @@ export function buildTrendsLineTimeSeriesConfig<R extends TrendsResultLike>(interval: opts.interval ?? 'day',allDays: opts.allDays ?? [],tickFormatter: opts.xAxisTickFormatter,+ hide: opts.hideAxes,},yAxis: {...yAxis,label: normalizeAxisLabel(opts.yAxisLabel),+ hide: opts.hideAxes,},valueLabels: opts.valueLabels,goalLines: goalLineConfigs,diff --git a/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsxindex ceedb3bba5df..ef5f5914153f 100644--- a/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx@@ -60,13 +60,14 @@ export function TrendsSlopeChart({ context }: TrendsSlopeChartProps): JSX.Elemen// insight's "Show legend" toggle, so there's only ever one legend and no in-chart names.showSeriesLabels: false,legend: { show: !!showLegend },+ hideXAxis: context?.hideAxes,xTickFormatter: createXAxisTickCallback({interval: interval ?? 'day',allDays: currentPeriodResult?.days ?? [],timezone,}),}),- [trendsFilter, baseCurrency, showLegend, interval, currentPeriodResult, timezone]+ [trendsFilter, baseCurrency, showLegend, interval, currentPeriodResult, timezone, context?.hideAxes])if (series.length === 0) {