: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): add trends chart overlay, series fading, quill classes (#125432)
Sam Penningtonbc523932a7cc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e0517a43b640..1ffd9b1a55d1 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6207,17 +6207,17 @@ snapshots:mcp-apps-error-tracking--active--light:hash: v1.k794b7964.3c4efa7c47d8f2863f3cec2c180dbf617b7a9b4253892f83900241929ab831b4.PQds2YnDLqkVbifI_HkTi1Uh7fkqL_P_ptcsfpXAwdAmcp-apps-error-tracking--chained-exceptions--light:- hash: v1.k794b7964.096d69f4fde77a9ac89511ae7ba93221e85536b87841b7e7159697b9f4395bb7.TVR1hiWBaf1fPox0u2aUFciJi7w44OhC0-_WEFjGVS0+ hash: v1.k794b7964.0a93d5af685fdf77c1ed0baec222a80990482e69717d6e9e15e234c44013cca3.CwqM851HR-Wtj1C3qOgYPlgAHQBcNJ8hbwxR3tTzPYImcp-apps-error-tracking--error-details--light:- hash: v1.k794b7964.115fc29fefb183de94ac95a3e950aeb03077f023b1784847ab65685fda533d35.Qr-CBJXrSn2ime3BNJ-Xk0rvryl7mDgRARc-nOdzusM+ hash: v1.k794b7964.5f963c5c2d51cc3472a82305ad69cfeb55c5afa31808b570322a7beea9291fc1.fXaVdJlPcGcFgzcrpBoqg4oNw6bgj5EOdRlIyzrdMDomcp-apps-error-tracking--list--light:hash: v1.k794b7964.5d0f644498e4d7f6b6ae68e20bbdc3b6558328fed023324847e3f1c16a170a04.2PkrcHUH-sxszQi7U9Ae3VmIHrschF7tCsDN4SwdI3omcp-apps-error-tracking--python-stack-trace--light:- hash: v1.k794b7964.d80733b9a543cc59a61a99b8515eaf35fa17b95a4d7d282c469c5ddf49be5cb5.2hXi52twI4RVs4FegK34kQf5bGN26uKyur7GeBeXuRE+ hash: v1.k794b7964.635dac25c78113a56fb07f1ce7dd4d7f836f0653043bafe5e4cd3fbd9ffca8e5.Ezf9xqpg_Q332zQn8jNrqhq4n0jdWOE6T2Gg0TC-skomcp-apps-error-tracking--resolved--light:hash: v1.k794b7964.fde427a04a5be7d7bd22031125188c719c92e3cec3040de64e833259496836a4.tr8wf9B0D2VjRFAGVH8LpfHNiLuXIUBQkPcsRigf1MQmcp-apps-error-tracking--stack-trace--light:- hash: v1.k794b7964.ad8da946c8891849416cc66d17c77e44dc83e62d5b71cb2eb433779d1ddc0cb3.s-3zNqXOIZXWGTq1Ts0ETT809GtSjhzHcG4PbGrfgDo+ hash: v1.k794b7964.2627aef797c4b97e7dbe53d02b2eca403405a5b56bf4914fcebc20ed1768422d.yjrCveWD68MhxkwAtcP_FEiA90SkfM_wDCQ5J6cRhbsmcp-apps-error-tracking--with-breakdown--light:hash: v1.k794b7964.1dd412a9421bb62e86ff964b3a0449375c9429b972a66fe3074db04bc7d7dd97.qWnA19cd9of2KGwgsVLoFh0yzOSwj8lWaSr2cDaW4_0mcp-apps-error-tracking--with-external-links--light:diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex 70673bd043e3..cbc612d66dc6 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -1,4 +1,4 @@-import { CSSProperties, ComponentType, HTMLProps } from 'react'+import { CSSProperties, ComponentType, HTMLProps, ReactNode } from 'react'import { ExpandableConfig } from 'lib/lemon-ui/LemonTable'import type { TaskQueue } from 'scenes/dashboard/dashboardUtils'@@ -103,6 +103,10 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {customActions?: JSX.Element | JSX.Element[]/** Callback for drag-to-zoom on time series charts. Enables x-axis drag selection when set. */onDateRangeZoom?: (dateFrom: string, dateTo: string) => void+ /** Drawn on top of a trends line or bar chart, as a child of the chart, so it can read the chart's scales. */+ chartOverlay?: ReactNode+ /** When a series matches, a trends line or bar chart fades every series that does not. */+ isSeriesHighlighted?: (result: TrendResult) => boolean/** Wired by the web analytics scene so a pre-computed tile's badge can offer "always query live data". */onDisableWebAnalyticsPrecompute?: () => void/**diff --git a/frontend/src/styles/quill-bridge.scss b/frontend/src/styles/quill-bridge.scssindex 7d2e36714108..bbf66fcadce1 100644--- a/frontend/src/styles/quill-bridge.scss+++ b/frontend/src/styles/quill-bridge.scss@@ -122,9 +122,12 @@* `bg-muted` collides: PostHog's compiled rule reads `--muted-3000`, quill's* reads `--muted`. Pin the class to quill's muted surface inside the subtree* without hijacking `--muted-3000` (which `text-muted` also depends on).+ * PostHog's utilities are `!important` in a layer, so this rule must be too, in the same layer.*/-[data-quill] .bg-muted {- background-color: var(--muted);+@layer utilities {+ [data-quill] .bg-muted {+ background-color: var(--muted) !important;+ }}[data-quill] .bg-popover {@@ -165,6 +168,14 @@background-color: var(--destructive-foreground);}+[data-quill] .bg-foreground {+ background-color: var(--foreground);+}++[data-quill] .bg-muted-foreground {+ background-color: var(--muted-foreground);+}+[data-quill] .text-foreground {color: var(--foreground);}@@ -182,6 +193,10 @@color: var(--muted-foreground);}+[data-quill] .text-background {+ color: var(--background);+}+[data-quill] .text-subtle-foreground {color: var(--subtle-foreground);}@@ -234,6 +249,15 @@border-color: var(--muted-foreground);}+[data-quill] .border-foreground {+ border-color: var(--foreground);+}++/* stylelint-disable-next-line selector-class-pattern -- the name of Tailwind's hover variant class */+[data-quill] .hover\:border-foreground:hover {+ border-color: var(--foreground);+}+[data-quill] .border-input {border-color: var(--input);}@@ -242,6 +266,11 @@border-color: var(--ring);}+/* stylelint-disable-next-line selector-class-pattern -- the name of Tailwind's focus-visible variant class */+[data-quill] .focus-visible\:outline-ring:focus-visible {+ outline-color: var(--ring);+}+/** Tailwind ring utilities with quill colour names. `ring-1`, `ring-2`, etc.* are structural (PostHog's compiled bundle has them) and readdiff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsxindex bfbbf01a396b..488503d4993f 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx@@ -45,6 +45,7 @@ import {handleTrendsChartClick,type TrendsChartClickDeps,} from '../shared/handleTrendsChartClick'+import { withHighlightedSeries } from '../shared/highlightedSeries'import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'import { trendsFilterToYFormatterConfig } from '../shared/trendsAxisFormat'import { buildTrendsSeriesMeta, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'@@ -192,10 +193,16 @@ export function TrendsBarChart({])+ const isSeriesHighlighted = context?.isSeriesHighlighted+ const getColor = useMemo(+ () => withHighlightedSeries(getTrendsColor, indexedResults ?? [], isSeriesHighlighted),+ [getTrendsColor, indexedResults, isSeriesHighlighted]+ )+const { series, labels, displayLabels } = useMemo(() => {if (isAggregated) {return buildTrendsBarAggregatedSeries<IndexedTrendResult, TrendsSeriesMeta>(indexedResults ?? [], {- getColor: getTrendsColor,+ getColor,getHidden: getTrendsHidden,buildMeta,stackBreakdowns,@@ -203,7 +210,7 @@ export function TrendsBarChart({})}const timeSeries = buildTrendsBarTimeSeries<IndexedTrendResult, TrendsSeriesMeta>(indexedResults ?? [], {- getColor: getTrendsColor,+ getColor,// Hidden series stay listed (dimmed) and are excluded via config.legend.hiddenKeys// instead of being dropped here, so the legend can restore them.getHidden: undefined,@@ -224,7 +231,7 @@ export function TrendsBarChart({}, [isAggregated,indexedResults,- getTrendsColor,+ getColor,getTrendsHidden,isStickiness,currentPeriodResult?.days,@@ -485,6 +492,7 @@ export function TrendsBarChart({/>)}{showValuesOnSeries && <ValueLabels valueFormatter={valueLabelFormatter} />}+ {context?.chartOverlay}</BarChart>)}@@ -535,6 +543,7 @@ export function TrendsBarChart({previousSeriesKey={previousSeriesKey}/>)}+ {context?.chartOverlay}</TimeSeriesBarChart>)}diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsxindex db0d7f57308e..0ecebb45c334 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx@@ -37,6 +37,7 @@ import { INSIGHT_TOOLTIP_CONFIG } from '../../shared/tooltipConfig'import { makeChartErrorHandler } from '../shared/chartErrorHandler'import { getTrendsSeriesDisplayLabel } from '../shared/getTrendsSeriesDisplayLabel'import { canHandleTrendsChartClick, handleTrendsChartClick } from '../shared/handleTrendsChartClick'+import { withHighlightedSeries } from '../shared/highlightedSeries'import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'import { buildTrendsSeriesMeta, resolveGroupTypeLabel, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'import { useInsightsLegendConfig } from '../shared/useInsightsLegendConfig'@@ -296,6 +297,12 @@ export function TrendsLineChart({])+ const isSeriesHighlighted = context?.isSeriesHighlighted+ const getColor = useMemo(+ () => withHighlightedSeries(getTrendsColor, indexedResults ?? [], isSeriesHighlighted),+ [getTrendsColor, indexedResults, isSeriesHighlighted]+ )+const series = useMemo(() =>buildTrendsSeries<IndexedTrendResult, TrendsSeriesMeta>(indexedResults ?? [], {@@ -303,7 +310,7 @@ export function TrendsLineChart({showMultipleYAxes: showMultipleYAxes ?? undefined,incompletenessOffsetFromEnd,isStickiness,- getColor: getTrendsColor,+ getColor,// Hidden series are listed (dimmed) and excluded via config.legend.hiddenKeys instead// of being dropped here, so the legend can restore them.getHidden: undefined,@@ -316,7 +323,7 @@ export function TrendsLineChart({showMultipleYAxes,incompletenessOffsetFromEnd,isStickiness,- getTrendsColor,+ getColor,getLabel,buildMeta,]@@ -429,6 +436,7 @@ export function TrendsLineChart({/>) : null}{showAnnotations && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationsDates} />}+ {context?.chartOverlay}</TimeSeriesLineChart>)}diff --git a/products/product_analytics/frontend/insights/trends/shared/highlightedSeries.ts b/products/product_analytics/frontend/insights/trends/shared/highlightedSeries.tsnew file mode 100644index 000000000000..4cbd24f4fb74--- /dev/null+++ b/products/product_analytics/frontend/insights/trends/shared/highlightedSeries.ts@@ -0,0 +1,14 @@+import { dimHexColor } from './compareDimming'++const FADED_SERIES_OPACITY = 0.25++export function withHighlightedSeries<T>(+ getColor: (result: T) => string,+ results: T[],+ isHighlighted: ((result: T) => boolean) | undefined+): (result: T) => string {+ if (!isHighlighted || !results.some(isHighlighted)) {+ return getColor+ }+ return (result) => (isHighlighted(result) ? getColor(result) : dimHexColor(getColor(result), FADED_SERIES_OPACITY))+}