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(insights): tooltip polish — compare label, bar ordering, box plot, stacked segment fix (#67210)

Sam Pennington1114e2c6c1bf
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e908c545c1e8..338a1bafe24b 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1101,9 +1101,9 @@ snapshots:
components-integrations-slack--slack-integration--light:
hash: v1.k794b7964.5e31191fe884081eaecccc0ca410571bfea114969731061b25274559c377e9c2.48o8xuoIkdsSSYnrrvbAKMwn9XvAGobjR0zC3-wD7bc
components-integrations-slack--slack-integration-added--dark:
- hash: v1.k794b7964.a1ad42b0f0f975569b93110a669febd3e486f6b90ee785b80979ae83dcbff1db.hV7aqt2bShW5KttL4NDjY3p-mcL2bXJKtEJJvQhn8ao
+ hash: v1.k794b7964.8f7edaa75ee5a78345d8b9bf243a225dd4ce33c0d49736ba1c639058735917b3.2y8Hrz8TZeJMytRC68aWpdlYlrM_DOAXfHFgBlBAUFQ
components-integrations-slack--slack-integration-added--light:
- hash: v1.k794b7964.ed6cb6ffb8918525982aca7a4eed6c21a239d5cacfe49c0c81898e842fd012ac.c_YqaIbzzzNXueagP2l8S4VMtTe870p7kVDnC6P-27A
+ hash: v1.k794b7964.a2894354ba60c0274e03cec4401c2eaf175acb8920494244ed0fd9a834d8b06a.Nrd5QEZeXhY_62Re5ZJG0DaebRGgXlX5V0cdF5-vXq4
components-integrations-slack--slack-integration-instance-not-configured--dark:
hash: v1.k794b7964.b9ee8adc2251177b325e3775fe7fd391540c3dba77c06d9da9db33ec80eddf81.VkdQOtlSqpDDliAWoEWxISdK8UUYqJyt7gFvAGeB7HE
components-integrations-slack--slack-integration-instance-not-configured--light:
diff --git a/frontend/src/scenes/insights/views/BoxPlot/BoxPlotChart.tsx b/frontend/src/scenes/insights/views/BoxPlot/BoxPlotChart.tsx
index b2841e067b36..3bf0b86b0d9b 100644
--- a/frontend/src/scenes/insights/views/BoxPlot/BoxPlotChart.tsx
+++ b/frontend/src/scenes/insights/views/BoxPlot/BoxPlotChart.tsx
@@ -9,6 +9,8 @@ import { buildTheme } from 'lib/charts/utils/theme'
import { getSeriesColor } from 'lib/colors'
import { DateDisplay } from 'lib/components/DateDisplay'
import { SeriesLetter } from 'lib/components/SeriesGlyph'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'
import { insightLogic } from 'scenes/insights/insightLogic'
import { InsightTooltip } from 'scenes/insights/InsightTooltip/InsightTooltip'
@@ -63,6 +65,8 @@ export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Elem
useValues(boxPlotChartLogic(insightProps))
const { timezone, weekStartDay } = useValues(teamLogic)
const { isDarkModeOn } = useValues(themeLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
+ const quillTooltipEnabled = !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_INSIGHTS_TOOLTIPS]
// isDarkModeOn invalidates the memo so buildTheme() re-reads CSS vars on dark-mode toggle.
const theme = useMemo(() => buildTheme(), [isDarkModeOn])
@@ -89,13 +93,16 @@ export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Elem
[seriesGroups]
)
+ const formatValue = useCallback((value: number) => formatAggregationAxisValue(trendsFilter, value), [trendsFilter])
+
const config = useMemo<BoxPlotConfig>(
() => ({
yScaleType: yAxisScaleType === 'log10' ? 'log' : 'linear',
- yTickFormatter: (value: number) => formatAggregationAxisValue(trendsFilter, value),
+ yTickFormatter: formatValue,
showGrid: true,
+ tooltip: quillTooltipEnabled ? { pinnable: true, placement: 'cursor' } : undefined,
}),
- [yAxisScaleType, trendsFilter]
+ [yAxisScaleType, formatValue, quillTooltipEnabled]
)
const renderTooltip = useCallback(
@@ -126,13 +133,13 @@ export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Elem
{value}
</div>
)}
- renderCount={(value: number) => formatAggregationAxisValue(trendsFilter, value)}
+ renderCount={(value: number) => formatValue(value)}
hideInspectActorsSection={!showPersonsModal}
groupTypeLabel="people"
/>
)
},
- [seriesGroups, timezone, interval, insightData, showPersonsModal, trendsFilter]
+ [seriesGroups, timezone, interval, insightData, showPersonsModal, formatValue]
)
const handleBoxClick = useCallback(
@@ -188,7 +195,7 @@ export function BoxPlotChart({ showPersonsModal = true }: ChartParams): JSX.Elem
labels={dateLabels}
theme={theme}
config={config}
- tooltip={renderTooltip}
+ tooltip={quillTooltipEnabled ? undefined : renderTooltip}
onBoxClick={handleBoxClick}
dataAttr="box-plot-graph"
/>
diff --git a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx
index fbadf348c8f2..471007d030bb 100644
--- a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx
+++ b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx
@@ -8,6 +8,7 @@ import { ChartErrorBoundary } from '../../core/ChartErrorBoundary'
import { useLatest } from '../../core/hooks/useLatest'
import {
buildSegmentResolveValue,
+ buildStackedBottomValue,
buildStackedPositionValue,
computeDivergingStackData,
computePercentStackData,
@@ -344,6 +345,7 @@ function BarChartInner<Meta = unknown>({
// at the stacked top (resolvePositionValue) so a stacked bar doesn't read as a running total.
const resolveValue = useMemo(() => buildSegmentResolveValue(stackedData), [stackedData])
const resolvePositionValue = useMemo(() => buildStackedPositionValue(stackedData), [stackedData])
+ const resolveBottomValue = useMemo(() => buildStackedBottomValue(stackedData), [stackedData])
const seriesRef = useLatest(visibleSeries)
const labelsRef = useLatest(labels)
@@ -399,6 +401,7 @@ function BarChartInner<Meta = unknown>({
dataAttr={dataAttr}
resolveValue={resolveValue}
resolvePositionValue={resolvePositionValue}
+ resolveBottomValue={resolveBottomValue}
>
{children}
</Chart>
diff --git a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx
index 5b84b3f2756f..511ae001aa90 100644
--- a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx
+++ b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx
@@ -19,6 +19,7 @@ import { barColorAt } from '../../core/color-utils'
import { type ComboChartPrivate, createComboScales, partitionByType, resolveSeriesType } from '../../core/combo-scales'
import {
buildSegmentResolveValue,
+ buildStackedBottomValue,
buildStackedPositionValue,
computeStackData,
computeTopStackedKeyByAxis,
@@ -315,6 +316,7 @@ function ComboChartInner<Meta = unknown>({
// still yields correct line values.
const resolveValue = useMemo(() => buildSegmentResolveValue(barStackedData), [barStackedData])
const resolvePositionValue = useMemo(() => buildStackedPositionValue(barStackedData), [barStackedData])
+ const resolveBottomValue = useMemo(() => buildStackedBottomValue(barStackedData), [barStackedData])
return (
<Chart
@@ -331,6 +333,7 @@ function ComboChartInner<Meta = unknown>({
dataAttr={dataAttr}
resolveValue={resolveValue}
resolvePositionValue={resolvePositionValue}
+ resolveBottomValue={resolveBottomValue}
>
{children}
</Chart>
diff --git a/packages/quill/packages/charts/src/core/Chart.tsx b/packages/quill/packages/charts/src/core/Chart.tsx
index 88aabbe7b35f..a076c9ffe424 100644
--- a/packages/quill/packages/charts/src/core/Chart.tsx
+++ b/packages/quill/packages/charts/src/core/Chart.tsx
@@ -76,6 +76,9 @@ export interface ChartProps<Meta = unknown> {
* visual top of each segment, while each tooltip row still shows that series's own value
* via `resolveValue`. */
resolvePositionValue?: ResolveValueFn
+ /** Resolves the stacked bottom value per series — used to compute segment midpoints for
+ * tooltip closest-series detection. Only bar charts provide this. */
+ resolveBottomValue?: ResolveValueFn
/** Required for horizontal orientation — maps labels to the coordinate on the categorical
* axis (y in horizontal mode). Should be referentially stable; non-stable identities
* invalidate the interaction memo on every render. */
@@ -107,6 +110,7 @@ export function Chart<Meta = unknown>({
children,
resolveValue,
resolvePositionValue,
+ resolveBottomValue,
labelToCoord,
valueRangeSeries,
wrapClickData,
@@ -216,6 +220,7 @@ export function Chart<Meta = unknown>({
onDateRangeZoom,
resolveValue,
resolvePositionValue,
+ resolveBottomValue,
interactionAxis,
labelToCoord,
wrapClickData,
diff --git a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
index 16b2cd7cd335..b0b7def8d576 100644
--- a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
+++ b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
@@ -38,6 +38,9 @@ interface UseChartInteractionOptions<Meta> {
* charts pass the stacked-top resolver so the anchor lands at the visual top of each
* segment while each tooltip row still shows its own value via `resolveValue`. */
resolvePositionValue?: ResolveValueFn
+ /** Resolves the stacked bottom value per series — passed to buildTooltipContext so yPixel
+ * is set to the segment midpoint, making closest-series detection match the visual boundary. */
+ resolveBottomValue?: ResolveValueFn
interactionAxis?: 'x' | 'y'
labelToCoord?: (label: string) => number | undefined
/** Chart-type seam: rewrite the click payload (e.g. resolve the stacked segment under the
@@ -72,6 +75,7 @@ export function useChartInteraction<Meta = unknown>({
onDateRangeZoom,
resolveValue = defaultResolveValue,
resolvePositionValue,
+ resolveBottomValue,
interactionAxis = 'x',
labelToCoord,
wrapClickData,
@@ -80,11 +84,12 @@ export function useChartInteraction<Meta = unknown>({
// value (i.e. non-stacked charts, where the two are identical).
const effectivePositionResolve = resolvePositionValue ?? resolveValue
- // resolveValue / effectivePositionResolve are read live in the pinned-rebuild path so an
- // unmemoized closure on either doesn't trigger a rebuild every render — see the contract
- // on `ChartProps.resolveValue`.
+ // resolveValue / effectivePositionResolve / resolveBottomValue are read live in the
+ // pinned-rebuild path so an unmemoized closure on any of them doesn't trigger a rebuild
+ // every render — see the contract on `ChartProps.resolveValue`.
const resolveValueRef = useLatest(resolveValue)
const effectivePositionResolveRef = useLatest(effectivePositionResolve)
+ const resolveBottomValueRef = useLatest(resolveBottomValue)
const rebuildPinnedCtx = useCallback(
(prev: TooltipContext<Meta>): TooltipContext<Meta> | null => {
@@ -107,11 +112,12 @@ export function useChartInteraction<Meta = unknown>({
interactionAxis,
prev.hoverPosition,
effectivePositionResolveRef.current,
+ resolveBottomValueRef.current,
scales.extent?.(labels[prev.dataIndex]),
prev.hoverPosition ? scales.bandSlotAtCursor?.(labels[prev.dataIndex], prev.hoverPosition) : undefined
)
},
- // resolveValueRef / effectivePositionResolveRef are stable
+ // resolveValueRef / effectivePositionResolveRef / resolveBottomValueRef are stable refs
[
scales,
dimensions,
@@ -122,6 +128,7 @@ export function useChartInteraction<Meta = unknown>({
interactionAxis,
resolveValueRef,
effectivePositionResolveRef,
+ resolveBottomValueRef,
]
)
@@ -203,6 +210,7 @@ export function useChartInteraction<Meta = unknown>({
interactionAxis,
{ x: mouseX, y: mouseY },
effectivePositionResolve,
+ resolveBottomValue,
scales.extent?.(labels[index]),
scales.bandSlotAtCursor?.(labels[index], { x: mouseX, y: mouseY })
)
diff --git a/packages/quill/packages/charts/src/core/interaction.ts b/packages/quill/packages/charts/src/core/interaction.ts
index 471c2613a546..13e1e62e206c 100644
--- a/packages/quill/packages/charts/src/core/interaction.ts
+++ b/packages/quill/packages/charts/src/core/interaction.ts
@@ -99,6 +99,10 @@ export function buildTooltipContext<Meta = unknown>(
* Stacked charts pass the stacked-top resolver here so the anchor lands at the visual top
* of each segment while each tooltip row still shows its own value via `resolveValue`. */
resolvePositionValue: ResolveValueFn = resolveValue,
+ /** Resolves the stacked *bottom* value for each series — used to compute the segment midpoint
+ * for tooltip row highlighting. When provided, yPixel is set to the segment midpoint so
+ * findClosestSeriesKey transitions at the visual boundary between segments. */
+ resolveBottomValue?: ResolveValueFn,
/** Optional horizontal data-extent centered on the categorical axis position — bar charts
* pass band width so the tooltip can anchor at the band edge instead of its center. */
positionExtent?: number,
@@ -137,11 +141,21 @@ export function buildTooltipContext<Meta = unknown>(
// reads the right color/meta/label rather than the shared series-level ones.
const bar = s.bars?.[dataIndex]
const entrySeries = bar ? { ...s, meta: bar.meta ?? s.meta, label: bar.label ?? s.label } : s
+ const segmentValue = resolveValue(s, dataIndex)
+ // When resolveBottomValue is provided (stacked bar charts), use the segment midpoint
+ // so findClosestSeriesKey transitions exactly at the visual boundary between segments.
+ let yPx = px
+ if (isFinite(px) && resolveBottomValue) {
+ const bottomPx = seriesValueScale(resolveBottomValue(s, dataIndex))
+ if (isFinite(bottomPx)) {
+ yPx = (px + bottomPx) / 2
+ }
+ }
seriesData.push({
series: entrySeries,
- value: resolveValue(s, dataIndex),
+ value: segmentValue,
color: barColorAt(s, dataIndex),
- yPixel: isFinite(px) ? px : undefined,
+ yPixel: isFinite(yPx) ? yPx : undefined,
})
}
}
diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.ts
index 7f9d07602d42..07551035864b 100644
--- a/packages/quill/packages/charts/src/core/scales.ts
+++ b/packages/quill/packages/charts/src/core/scales.ts
@@ -489,6 +489,27 @@ export function buildSegmentResolveValue(
}
}
+/** Returns the stacked bottom value for each series — use with {@link buildStackedPositionValue}
+ * to compute per-segment midpoints for tooltip hover detection. */
+export function buildStackedBottomValue(
+ stackedData: Map<string, StackedBand> | undefined
+): ResolveValueFn | undefined {
+ if (!stackedData) {
+ return undefined
+ }
+ return (s, dataIndex) => {
+ const bottom = stackedData.get(s.key)?.bottom[dataIndex]
+ if (Number.isFinite(bottom)) {
+ return bottom as number
+ }
+ // Non-stacked series (e.g. overlay trend lines) aren't in the stack map.
+ // Fall back to the series value so the midpoint collapses to the series's
+ // own pixel position — matching buildStackedPositionValue's fallback.
+ const raw = s.data[dataIndex]
+ return typeof raw === 'number' && Number.isFinite(raw) ? raw : 0
+ }
+}
+
export interface BarScaleSet {
band: ScaleBand<string>
value: D3YScale
diff --git a/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx b/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx
index c8e7589cb017..408a30ffafa9 100644
--- a/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx
+++ b/packages/quill/packages/charts/src/overlays/DefaultTooltip.tsx
@@ -172,7 +172,9 @@ export function DefaultTooltip<Meta = unknown>({
{labelContent}
</span>
</span>
- <strong data-attr="hog-chart-tooltip-value">{format(s.value, s)}</strong>
+ <strong data-attr="hog-chart-tooltip-value" className="tabular-nums">
+ {format(s.value, s)}
+ </strong>
</div>
)
})}
diff --git a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
index 83b8222abb22..1c673d217c3d 100644
--- a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
+++ b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx
@@ -18,6 +18,8 @@ import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
import { BreakdownFilter, CurrencyCode, DateRange, TrendsFilter } from '~/queries/schema/schema-general'
import { ActionFilter, IntervalType } from '~/types'
+// ── Types ──────────────────────────────────────────────────────────────────
+
type InsightSeriesMetaBase = {
action?: ActionFilter
breakdown_value?: string | number | string[] | null
@@ -43,25 +45,113 @@ export interface InsightSeriesTooltipProps<Meta extends InsightSeriesMetaBase> {
formatCompareLabel?: (label: string, dateLabel?: string) => string
onRowClick?: (datum: SeriesDatum) => void
showHeader?: boolean
- /** Override the auto-derived date header. Stickiness needs this since its `date`
- * is an interval-count integer, not a date — letting it format as a calendar date
- * produces a wrong "Thursday, 1 Jan 1970" header. */
+ /** Override the auto-derived date header — stickiness passes an interval-count integer
+ * rather than a date, so the default calendar formatter would produce the wrong label. */
altTitle?: string | ((tooltipData: SeriesDatum[], formattedDate: string) => React.ReactNode)
- /** Overrides the default value formatter — needed for the pie chart, which renders the
- * raw aggregation plus the slice's share of the total. */
+ /** Override the value formatter — pie chart passes slice share alongside the raw count. */
renderCount?: (value: number) => string
- /** Overrides the default row label — used by lifecycle, where the label is the lifecycle
- * status (e.g. "New") rather than the entity name. */
+ /** Override the row label — lifecycle uses the status name rather than the event name. */
renderSeriesOverride?: (datum: SeriesDatum) => React.ReactNode
- /** Sort rows by value descending. Defaults true; pass false to use visual top-to-bottom order (e.g. lifecycle). */
+ /** Sort rows by value descending. Pass false to preserve visual top-to-bottom order. */
sortedByValue?: boolean
- /** Hide rows with value 0 — useful when zero means the series is absent (e.g. lifecycle statuses). */
+ /** Hide rows whose value is exactly 0 (e.g. absent lifecycle statuses). */
hideZeroRows?: boolean
}
-/** Renders hog-charts' DefaultTooltip for insight series charts so they share the same tooltip
- * surface as SQL insights. Maps the quill TooltipContext to the insight-flavored value/label/date
- * formatting and wires the per-series persons-modal drill-down. */
+// ── Pure helpers ───────────────────────────────────────────────────────────
+
+/** Format a single row's value given the chart's display mode. */
+function formatRowValue(
+ value: number,
+ opts: {
+ override?: (value: number) => string
+ showPercentView?: boolean
+ isPercentStackView?: boolean
+ trendsFilter?: TrendsFilter | null
+ baseCurrency?: CurrencyCode
+ }
+): string {
+ if (opts.override) {
+ return opts.override(value)
+ }
+ if (opts.showPercentView) {
+ return `${value.toFixed(1)}%`
+ }
+ if (opts.isPercentStackView) {
+ // quill-charts delivers percent-stack segments as 0..1 fractions.
+ return percentage(value)
+ }
+ return formatAggregationAxisValue(opts.trendsFilter, value, opts.baseCurrency)
+}
+
+// ── SeriesLabel ────────────────────────────────────────────────────────────
+
+interface SeriesLabelProps {
+ datum: SeriesDatum
+ breakdownFilter?: BreakdownFilter
+ formatCompareLabel?: (label: string, dateLabel?: string) => string
+ hasMultipleEvents: boolean
+ renderSeriesOverride?: (datum: SeriesDatum) => React.ReactNode
+}
+
+/**
+ * Label for a single tooltip row. Handles four cases:
+ * 1. Custom override (lifecycle status, etc.)
+ * 2. Breakdown + compare — breakdown truncates; period label is always fully visible
+ * 3. Breakdown or compare alone — same split layout
+ * 4. Plain series label
+ */
+export function SeriesLabel({
+ datum,
+ breakdownFilter,
+ formatCompareLabel,
+ hasMultipleEvents,
+ renderSeriesOverride,
+}: SeriesLabelProps): React.ReactNode {
+ if (renderSeriesOverride) {
+ return renderSeriesOverride(datum)
+ }
+
+ const hasBreakdown =
+ datum.breakdown_value !== undefined && datum.breakdown_value !== null && datum.breakdown_value !== ''
+
+ if (!hasBreakdown && !datum.compare_label) {
+ return datum.label
+ }
+
+ const comparePeriod = datum.compare_label
+ ? formatCompareLabel
+ ? formatCompareLabel(String(datum.compare_label), datum.date_label)
+ : datum.compare_label === 'current'
+ ? 'Current'
+ : 'Previous'
+ : null
+
+ const breakdownTitle = hasBreakdown
+ ? getDatumTitle({ ...datum, compare_label: undefined }, breakdownFilter, formatCompareLabel)
+ : null
+
+ const eventPrefix = hasMultipleEvents ? (
+ <span className="opacity-50 mr-1 shrink-0">
+ {(datum.action ? getDisplayNameFromEntityFilter(datum.action) : null) ?? datum.label} ·
+ </span>
+ ) : null
+
+ // inline-flex: breakdown span truncates (flex-1), period label stays visible (shrink-0).
+ return (
+ <span className="inline-flex items-center w-full overflow-hidden">
+ {eventPrefix}
+ <span className="truncate min-w-0 flex-1">{breakdownTitle ?? datum.label}</span>
+ {comparePeriod && <span className="shrink-0 opacity-60">&nbsp;·&nbsp;{comparePeriod}</span>}
+ </span>
+ )
+}
+
+// ── InsightSeriesTooltip ───────────────────────────────────────────────────
+
+/** DefaultTooltip adapter for insight series charts (trends, retention, stickiness).
+ * Maps the quill TooltipContext to insight-flavored value/label/date formatting and
+ * wires persons-modal drill-down via onRowClick. */
export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
context,
timezone = 'UTC',
@@ -77,7 +167,7 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
onRowClick,
showHeader,
altTitle,
- renderCount: renderCountOverride,
+ renderCount,
renderSeriesOverride,
sortedByValue = true,
hideZeroRows,
@@ -85,48 +175,34 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)
const { weekStartDay } = useValues(teamLogic)
- // Map each quill series entry (keyed by series.key) to the InsightTooltip SeriesDatum shape so the
- // existing breakdown/compare/value formatting helpers stay reusable. `datasetIndex` mirrors the
- // entry's position in context.seriesData, which the chart's onRowClick maps back to a series key.
+ // Quill delivers one entry per series key; map to SeriesDatum so existing
+ // formatting helpers (getDatumTitle, formatAggregationValue, etc.) stay reusable.
const datumByKey = useMemo(() => {
const m = new Map<string, SeriesDatum>()
context.seriesData.forEach((entry, idx) => {
- const meta = entry.series.meta ?? {}
+ const meta = (entry.series.meta ?? {}) as InsightSeriesMetaBase
m.set(entry.series.key, {
id: idx,
dataIndex: context.dataIndex,
datasetIndex: idx,
- order: (meta as InsightSeriesMetaBase).order ?? idx,
+ order: meta.order ?? idx,
label: entry.series.label,
color: entry.color,
count: entry.value,
- action: (meta as InsightSeriesMetaBase).action,
- breakdown_value: (meta as InsightSeriesMetaBase).breakdown_value ?? undefined,
- compare_label: (meta as InsightSeriesMetaBase).compare_label,
- date_label: (meta as InsightSeriesMetaBase).days?.[context.dataIndex],
- filter: (meta as InsightSeriesMetaBase).filter,
+ action: meta.action,
+ breakdown_value: meta.breakdown_value ?? undefined,
+ compare_label: meta.compare_label,
+ date_label: meta.days?.[context.dataIndex],
+ filter: meta.filter,
})
})
return m
}, [context.seriesData, context.dataIndex])
- const renderCount = useCallback(
- (value: number): string => {
- if (renderCountOverride) {
- return renderCountOverride(value)
- }
- if (showPercentView) {
- // Stickiness percent view: value is already a percentage.
- return `${value.toFixed(1)}%`
- }
- if (!isPercentStackView) {
- return formatAggregationAxisValue(trendsFilter, value, baseCurrency)
- }
- // hog-charts passes each segment as a 0..1 fraction, so format it directly as a percentage.
- return percentage(value)
- },
- [renderCountOverride, showPercentView, isPercentStackView, trendsFilter, baseCurrency]
- )
+ const hasMultipleEvents = useMemo(() => {
+ const events = new Set([...datumByKey.values()].map((d) => d.action?.id ?? d.action?.name))
+ return events.size > 1
+ }, [datumByKey])
const valueFormatter = useCallback(
(value: number, entry: InsightSeriesTooltipEntry<Meta>): React.ReactNode => {
@@ -134,48 +210,45 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({
return formatAggregationValue(
datum?.action?.math_property,
value,
- renderCount,
+ (v) =>
+ formatRowValue(v, {
+ override: renderCount,
+ showPercentView,
+ isPercentStackView,
+ trendsFilter,
+ baseCurrency,
+ }),
formatPropertyValueForDisplay
)
},
- [datumByKey, renderCount, formatPropertyValueForDisplay]
+ [
+ datumByKey,
+ renderCount,
+ showPercentView,
+ isPercentStackView,
+ trendsFilter,
+ baseCurrency,
+ formatPropertyValueForDisplay,
+ ]
)
- // Multiple distinct events in the tooltip — prefix breakdown rows with the event name
- // so the user knows which series each breakdown value belongs to.
- const hasMultipleEvents = useMemo(() => {
- const events = new Set([...datumByKey.values()].map((d) => d.action?.id ?? d.action?.name))
- return events.size > 1
- }, [datumByKey])
-
const labelRenderer = useCallback(
(entry: InsightSeriesTooltipEntry<Meta>): React.ReactNode => {
const datum = datumByKey.get(entry.series.key)
if (!datum) {
return entry.series.label
}
- if (renderSeriesOverride) {
- return renderSeriesOverride(datum)
- }
- const hasBreakdown =
- datum.breakdown_value !== undefined && datum.breakdown_value !== null && datum.breakdown_value !== ''
- if (hasBreakdown || datum.compare_label) {
- const title = getDatumTitle(datum, breakdownFilter, formatCompareLabel)
- if (hasMultipleEvents && (hasBreakdown || datum.compare_label)) {
- const seriesName =
- (datum.action ? getDisplayNameFromEntityFilter(datum.action) : null) ?? datum.label
- return (
- <>
- <span className="opacity-50 mr-1 shrink-0">{seriesName} ·</span>
- {title}
- </>
- )
- }
- return title
- }
- return datum.label
+ return (
+ <SeriesLabel
+ datum={datum}
+ breakdownFilter={breakdownFilter}
+ formatCompareLabel={formatCompareLabel}
+ hasMultipleEvents={hasMultipleEvents}
+ renderSeriesOverride={renderSeriesOverride}
+ />
+ )
},
- [datumByKey, renderSeriesOverride, breakdownFilter, formatCompareLabel, hasMultipleEvents]
+ [datumByKey, breakdownFilter, formatCompareLabel, hasMultipleEvents, renderSeriesOverride]
)
const labelFormatter = useCallback((): React.ReactNode => {
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
index 0ebe881eca18..2cda002b633e 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
@@ -61,7 +61,7 @@ interface TrendsBarChartProps {
}
const EMPTY_LABELS: string[] = []
-const AGGREGATED_TOOLTIP_CONFIG = { pinnable: false }
+const AGGREGATED_TOOLTIP_CONFIG = { pinnable: false, placement: 'cursor' as const }
type AggregationLabelFn = (groupTypeIndex: number | null | undefined) => { plural: string }
@@ -395,6 +395,7 @@ export function TrendsBarChart({
formatCompareLabel: context?.formatCompareLabel,
onRowClick,
showHeader: isAggregated ? (false as const) : undefined,
+ sortedByValue: false,
}
return quillTooltipEnabled ? (
<InsightSeriesTooltip {...sharedProps} />