: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
fix(insights): sort hog-charts trends tooltip rows by value (#60003)
Sam Penningtond9c3a98037a4
diff --git a/frontend/src/scenes/insights/InsightTooltip/InsightTooltip.tsx b/frontend/src/scenes/insights/InsightTooltip/InsightTooltip.tsxindex e08e343d81f2..f3225c34417e 100644--- a/frontend/src/scenes/insights/InsightTooltip/InsightTooltip.tsx+++ b/frontend/src/scenes/insights/InsightTooltip/InsightTooltip.tsx@@ -270,6 +270,7 @@ export function InsightTooltip({columns.push({key: 'datum',+ className: 'datum-column',width: 200,title: <span className="whitespace-nowrap">{title}</span>,sticky: true,diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsxindex 04a6178cd325..6378c28c0063 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx@@ -66,6 +66,34 @@ describe('TrendsLineChart', () => {expect(glyphs.length).toBe(2)})+ it('sorts tooltip rows by descending value regardless of series order', async () => {+ // At index 2: Pageview=134, Napped=5, Minimal=1, NoActivity=0.+ // Input order, alphabetic, and value order all differ.+ renderInsight({+ query: buildTrendsQuery({+ series: [+ { kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' },+ { kind: NodeKind.EventsNode, event: 'Minimal', name: 'Minimal' },+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },+ { kind: NodeKind.EventsNode, event: 'NoActivity', name: 'NoActivity' },+ ],+ }),+ featureFlags: HOG_CHARTS_FLAG,+ })++ const tooltip = await chart.hoverTooltip(2)++ const rows = tooltip.rows()+ expect(rows[0]).toContain('Pageview')+ expect(rows[1]).toContain('Napped')+ expect(rows[2]).toContain('Minimal')+ expect(rows[3]).toContain('NoActivity')+ expect(tooltip.row('Pageview')).toContain('134')+ expect(tooltip.row('Napped')).toContain('5')+ expect(tooltip.row('Minimal')).toContain('1')+ expect(tooltip.row('NoActivity')).toContain('0')+ })+it('shows breakdown values in the tooltip', async () => {renderInsight({query: buildTrendsQuery({diff --git a/products/product_analytics/frontend/insights/trends/shared/TrendsTooltip.tsx b/products/product_analytics/frontend/insights/trends/shared/TrendsTooltip.tsxindex f9ed170a983b..81019d11c8ab 100644--- a/products/product_analytics/frontend/insights/trends/shared/TrendsTooltip.tsx+++ b/products/product_analytics/frontend/insights/trends/shared/TrendsTooltip.tsx@@ -65,27 +65,31 @@ export function TrendsTooltip({renderCount: renderCountOverride,renderSeriesOverride,}: TrendsTooltipProps): React.ReactElement {- const seriesData = useMemo<SeriesDatum[]>(- () =>- context.seriesData.map((entry, idx) => {- const meta = entry.series.meta ?? {}- return {- id: idx,- dataIndex: context.dataIndex,- datasetIndex: idx,- order: meta.order ?? idx,- label: entry.series.label,- color: entry.color,- count: entry.value,- action: meta.action,- breakdown_value: meta.breakdown_value,- compare_label: meta.compare_label,- date_label: meta.days?.[context.dataIndex],- filter: meta.filter,- }- }),- [context.seriesData, context.dataIndex]- )+ const seriesData = useMemo<SeriesDatum[]>(() => {+ const data = context.seriesData.map((entry, idx) => {+ const meta = entry.series.meta ?? {}+ return {+ id: idx,+ dataIndex: context.dataIndex,+ datasetIndex: idx,+ order: meta.order ?? idx,+ label: entry.series.label,+ color: entry.color,+ count: entry.value,+ action: meta.action,+ breakdown_value: meta.breakdown_value,+ compare_label: meta.compare_label,+ date_label: meta.days?.[context.dataIndex],+ filter: meta.filter,+ }+ })+ data.sort(+ (a, b) =>+ b.count - a.count ||+ (a.label === undefined || b.label === undefined ? 0 : a.label.localeCompare(b.label))+ )+ return data.map((s, id) => ({ ...s, id }))+ }, [context.seriesData, context.dataIndex])const date = context.seriesData[0]?.series.meta?.days?.[context.dataIndex]