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(quill-charts): forward more static tooltip options from config.tooltip (#125452)

Sam Penningtonb43c89f42b80
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
index 49f2ec71f6b0..0686cf330ea9 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
@@ -52,7 +52,7 @@ export interface TimeSeriesBarChartConfig {
showAxisLines?: AxisLinesConfig
/** Draw short tick marks next to each visible axis label. Pairs with `showAxisLines`. */
showTickMarks?: boolean
- /** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */
+ /** Tooltip behaviour and built-in content options. A `tooltip` render prop replaces the content. */
tooltip?: TooltipConfig
/** Stacked layout only — stack negatives below the zero baseline (d3.stackOffsetDiverging). */
divergingStack?: boolean
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.test.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.test.tsx
index 1500d79572fc..66feeb66acba 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.test.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.test.tsx
@@ -1,7 +1,7 @@
import { fireEvent } from '@testing-library/react'
import { useChartLayout } from '../../core/chart-context'
-import type { ChartTheme, Series } from '../../core/types'
+import type { ChartTheme, Series, TooltipConfig } from '../../core/types'
import { getChart, renderChart, waitForChartTooltip } from '../../testing'
import { TimeSeriesComboChart } from './TimeSeriesComboChart'
@@ -290,32 +290,43 @@ describe('TimeSeriesComboChart', () => {
expect(tooltip.seriesData.map((s) => s.series.key).sort()).toEqual(['bar', 'line'])
})
- it('formats the built-in tooltip rows with config.tooltip.valueFormatter', async () => {
+ it.each<{ name: string; tooltip: TooltipConfig; series: Series[]; contains: string[]; omits: string[] }>([
+ {
+ name: 'valueFormatter',
+ tooltip: { valueFormatter: (v) => `$${v}` },
+ series: BAR_AND_LINE,
+ contains: ['$60'],
+ omits: [],
+ },
+ {
+ name: 'showTotal',
+ tooltip: { showTotal: true, totalLabel: 'Sum' },
+ series: BAR_AND_LINE,
+ contains: ['Sum'],
+ omits: [],
+ },
+ {
+ name: 'hideZeroRows',
+ tooltip: { hideZeroRows: true },
+ series: [BAR_AND_LINE[0], { key: 'empty', label: 'Empty', data: [1, 0, 1], type: 'line' }],
+ contains: ['Bar'],
+ omits: ['Empty'],
+ },
+ {
+ name: 'showHeader',
+ tooltip: { showHeader: false },
+ series: BAR_AND_LINE,
+ contains: ['Bar'],
+ omits: ['Tue'],
+ },
+ ])('applies config.tooltip.$name to the built-in tooltip', async ({ tooltip, series, contains, omits }) => {
const { chart } = renderChart(
- <TimeSeriesComboChart
- series={BAR_AND_LINE}
- labels={LABELS}
- theme={THEME}
- config={{ tooltip: { valueFormatter: (v) => `$${v}` } }}
- />
- )
- chart.hoverAtIndex(1)
- const tooltip = await waitForChartTooltip()
- expect(tooltip.textContent).toContain('$60')
- })
-
- it('appends a total row when config.tooltip.showTotal is set', async () => {
- const { chart } = renderChart(
- <TimeSeriesComboChart
- series={BAR_AND_LINE}
- labels={LABELS}
- theme={THEME}
- config={{ tooltip: { showTotal: true, totalLabel: 'Sum' } }}
- />
+ <TimeSeriesComboChart series={series} labels={LABELS} theme={THEME} config={{ tooltip }} />
)
chart.hoverAtIndex(1)
- const tooltip = await waitForChartTooltip()
- expect(tooltip.textContent).toContain('Sum')
+ const { textContent } = await waitForChartTooltip()
+ contains.forEach((text) => expect(textContent).toContain(text))
+ omits.forEach((text) => expect(textContent).not.toContain(text))
})
})
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
index 074ae761a525..1d4458608c67 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
@@ -56,7 +56,7 @@ export interface TimeSeriesComboChartConfig {
showTickMarks?: boolean
/** Line interpolation for line/area series: `linear` (default) or `monotone` (smooth curve). */
curve?: 'linear' | 'monotone'
- /** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */
+ /** Tooltip behaviour and built-in content options. A `tooltip` render prop replaces the content. */
tooltip?: TooltipConfig
/** Built-in legend with click-to-toggle series visibility. Hidden by default. */
legend?: ChartLegendConfig
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
index 7abdc61002a0..eca0e2401bb1 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
@@ -59,7 +59,7 @@ export interface TimeSeriesLineChartConfig {
showTickMarks?: boolean
/** Line interpolation: `linear` (default) or `monotone` (smooth curve through every point). */
curve?: 'linear' | 'monotone'
- /** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */
+ /** Tooltip behaviour and built-in content options. A `tooltip` render prop replaces the content. */
tooltip?: TooltipConfig
/** Built-in legend with click-to-toggle series visibility. Hidden by default. */
legend?: ChartLegendConfig
diff --git a/packages/quill/packages/charts/src/core/Chart.tsx b/packages/quill/packages/charts/src/core/Chart.tsx
index 4d7c2ba4e910..d7a2f324b7ee 100644
--- a/packages/quill/packages/charts/src/core/Chart.tsx
+++ b/packages/quill/packages/charts/src/core/Chart.tsx
@@ -191,39 +191,12 @@ export function Chart<Meta = unknown>({
pinnable: pinnableTooltip = false,
resolveClickToNearestSeries = false,
placement: tooltipPlacement = 'follow-data',
- valueFormatter: tooltipValueFormatter,
- labelFormatter: tooltipLabelFormatter,
- showTotal: tooltipShowTotal,
- totalLabel: tooltipTotalLabel,
- totalFormatter: tooltipTotalFormatter,
- sortedByValue: tooltipSortedByValue,
+ ...defaultTooltipOptions
} = tooltipConfig ?? {}
- // No render prop: render DefaultTooltip with config.tooltip's formatters (all undefined → bare default).
- const renderTooltip = useMemo<(ctx: TooltipContext<Meta>) => React.ReactNode>(
- () =>
- renderTooltipProp ??
- ((ctx: TooltipContext<Meta>) => (
- <DefaultTooltip
- {...ctx}
- valueFormatter={tooltipValueFormatter}
- labelFormatter={tooltipLabelFormatter}
- showTotal={tooltipShowTotal}
- totalLabel={tooltipTotalLabel}
- totalFormatter={tooltipTotalFormatter}
- sortedByValue={tooltipSortedByValue}
- />
- )),
- [
- renderTooltipProp,
- tooltipValueFormatter,
- tooltipLabelFormatter,
- tooltipShowTotal,
- tooltipTotalLabel,
- tooltipTotalFormatter,
- tooltipSortedByValue,
- ]
- )
+ // No render prop: render DefaultTooltip with config.tooltip's content options.
+ const renderTooltip =
+ renderTooltipProp ?? ((ctx: TooltipContext<Meta>) => <DefaultTooltip {...ctx} {...defaultTooltipOptions} />)
const margins = useChartMargins({
series,
diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.ts
index 9f470bb7e05e..d86aa6facb11 100644
--- a/packages/quill/packages/charts/src/core/types.ts
+++ b/packages/quill/packages/charts/src/core/types.ts
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react'
import type { LegendItem } from '../components/Legend/Legend'
import type { LegendItemControls } from '../components/Legend/useChartLegend'
+import type { DefaultTooltipProps } from '../overlays/DefaultTooltip'
/** Visual theme colours consumed by chart rendering. */
export interface ChartTheme {
@@ -377,7 +378,7 @@ export interface ChartLegendConfig {
renderItem?: (defaultNode: ReactNode, item: LegendItem, controls: LegendItemControls) => ReactNode
}
-export interface TooltipConfig {
+export interface TooltipConfig extends Pick<DefaultTooltipProps, 'labelRenderer' | 'showHeader' | 'hideZeroRows'> {
/** Show a tooltip on hover. Defaults to true. */
enabled?: boolean
/** When true, clicking a data point with multiple series pins the tooltip in place. */
diff --git a/packages/quill/packages/charts/src/docs/tooltips.md b/packages/quill/packages/charts/src/docs/tooltips.md
index 7922c9f7cbae..112809fab791 100644
--- a/packages/quill/packages/charts/src/docs/tooltips.md
+++ b/packages/quill/packages/charts/src/docs/tooltips.md
@@ -15,8 +15,8 @@ Other charts, such as scatter and pie, provide specialized tooltips; check their
## Formatting without a render prop
-`config.tooltip` also forwards `valueFormatter`, `labelFormatter`, `showTotal`, `totalLabel`, `totalFormatter`, and `sortedByValue` into `DefaultTooltip`.
-Prefer this for "format each row" and "add a total" cases (SQL insights pass per-column formatters this way).
+`config.tooltip` also forwards `valueFormatter`, `labelFormatter`, `labelRenderer`, `showHeader`, `showTotal`, `totalLabel`, `totalFormatter`, `sortedByValue`, and `hideZeroRows` into `DefaultTooltip`.
+Prefer this for "format each row", "hide empty rows" and "add a total" cases (SQL insights pass per-column formatters this way).
A render prop, if given, owns the content and these fields are ignored.
## `DefaultTooltip` props