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.

feat(mcp): let the trends chart hide its header and controls (#119216)

Sam Penningtonce56288e5fbe
diff --git a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
index 0dc8ed918db9..bd6faba2a8d0 100644
--- a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
+++ b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
@@ -77,7 +77,15 @@ function calculateTotal(results: TrendsResultItem[]): number {
}, 0)
}
-export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): ReactElement {
+export function TrendsVisualizer({
+ query,
+ results,
+ title = TITLE,
+ overlay,
+ showControls = true,
+ chartClassName = 'h-[400px]',
+ showTitle = true,
+}: TrendsVisualizerProps): ReactElement {
const displayType = getDisplayType(query)
const [chartType, setChartType] = useState<ChartType>(defaultChartType(displayType))
const [chartConfig, setChartConfig] = useState(() => chartConfigFromTrendsFilter(query?.trendsFilter))
@@ -86,7 +94,7 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
if (!results || results.length === 0) {
return (
<div>
- <ChartHeader title={TITLE} />
+ {showTitle && <ChartHeader title={title} />}
<Empty>
<EmptyHeader>
<EmptyMedia>{emptyStateIllustration('chart')}</EmptyMedia>
@@ -102,7 +110,7 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
const label = results[0] ? getSeriesLabel(results[0], 0) : 'Total'
return (
<div>
- <ChartHeader title={TITLE} />
+ {showTitle && <ChartHeader title={title} />}
<BigNumber value={total} label={label} />
</div>
)
@@ -111,7 +119,7 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
if (displayType === 'ActionsProportionBar') {
return (
<div>
- <ChartHeader title={TITLE} />
+ {showTitle && <ChartHeader title={title} />}
<div className="flex flex-col w-full justify-center p-4">
<ProportionBar
series={buildProportionBarSeries(results, colorAt)}
@@ -133,8 +141,8 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
const barConfig = buildTrendsBarValueConfig()
return (
<div>
- <ChartHeader title={TITLE} />
- <div className="flex flex-col w-full h-[400px]">
+ {showTitle && <ChartHeader title={title} />}
+ <div className={`flex flex-col w-full ${chartClassName}`}>
<BarValueChart
series={barSeries}
labels={items.map((item) => item.label)}
@@ -156,8 +164,8 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
const pieView = pieViewFromTrendsFilter(query?.trendsFilter, displayType === 'ActionsDonut')
return (
<div>
- <ChartHeader title={TITLE} />
- <div className="flex flex-col w-full h-[400px]">
+ {showTitle && <ChartHeader title={title} />}
+ <div className={`flex flex-col w-full ${chartClassName}`}>
<PieChart
series={slices}
theme={theme}
@@ -230,7 +238,9 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
theme={theme}
config={config}
tooltip={renderDateTooltip}
- />
+ >
+ {overlay}
+ </TimeSeriesBarChart>
)
}
const series = buildTrendsSeries(trendResults, {
@@ -257,26 +267,34 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
theme={theme}
config={config}
tooltip={renderDateTooltip}
- />
+ >
+ {overlay}
+ </TimeSeriesLineChart>
)
}
return (
<div>
- <ChartHeader title={TITLE}>
- {/* eslint-disable-next-line react/forbid-elements */}
- <Select value={effectiveType} onChange={handleChartTypeChange} options={chartTypeOptions} />
- {effectiveType !== 'slope' && (
- <ChartSettings
- family={isBarFamily(effectiveType) ? 'bar' : 'line'}
- config={chartConfig}
- onChange={setChartConfig}
- derivedSeriesDisabled={derivedSeriesDisabled}
- percentStackDisabled={!supportsPercentStack(effectiveType)}
- />
- )}
- </ChartHeader>
- <div className="flex flex-col w-full h-[400px]">{renderChart()}</div>
+ {(showTitle || showControls) && (
+ <ChartHeader title={showTitle ? title : ''}>
+ {showControls && (
+ <>
+ {/* eslint-disable-next-line react/forbid-elements */}
+ <Select value={effectiveType} onChange={handleChartTypeChange} options={chartTypeOptions} />
+ {effectiveType !== 'slope' && (
+ <ChartSettings
+ family={isBarFamily(effectiveType) ? 'bar' : 'line'}
+ config={chartConfig}
+ onChange={setChartConfig}
+ derivedSeriesDisabled={derivedSeriesDisabled}
+ percentStackDisabled={!supportsPercentStack(effectiveType)}
+ />
+ )}
+ </>
+ )}
+ </ChartHeader>
+ )}
+ <div className={`flex flex-col w-full ${chartClassName}`}>{renderChart()}</div>
</div>
)
}
diff --git a/services/mcp/src/ui-apps/components/types.ts b/services/mcp/src/ui-apps/components/types.ts
index c6bd68f0731c..e7b2f5d1e334 100644
--- a/services/mcp/src/ui-apps/components/types.ts
+++ b/services/mcp/src/ui-apps/components/types.ts
@@ -1,3 +1,5 @@
+import type { ReactNode } from 'react'
+
import type { YAxisFormat } from '@posthog/quill-charts'
// ============================================================================
@@ -220,6 +222,12 @@ export type PathsResult = PathsResultItem[]
export interface TrendsVisualizerProps {
query: TrendsQuery | undefined
results: TrendsResult
+ title?: string
+ /** Drawn as a child of a line or bar chart, so it can read the chart's scales. */
+ overlay?: ReactNode
+ showControls?: boolean
+ chartClassName?: string
+ showTitle?: boolean | 'axis'
}
export interface FunnelVisualizerProps {