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.

fix(trends): hide moving-average overlay when its series is toggled off (#63841)

Steven Shults01d31f2d2060
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts
index bc4bfaa82f6e..92bad10d51f6 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.test.ts
@@ -231,6 +231,15 @@ describe('trendsChartTransforms', () => {
expect(out.movingAverage).toEqual([{ seriesKey: 'a', window: 3 }])
})
+ it('skips hidden results so a toggled-off series has no MA overlay', () => {
+ const out = buildDerivedConfigs([makeResult({ id: 'a' }), makeResult({ id: 'b' })], {
+ showMovingAverage: true,
+ movingAverageIntervals: 3,
+ getHidden: (r) => r.id === 'b',
+ })
+ expect(out.movingAverage).toEqual([{ seriesKey: 'a', window: 3 }])
+ })
+
it('omits movingAverage when movingAverageIntervals is undefined', () => {
expect(buildDerivedConfigs([makeResult()], { showMovingAverage: true }).movingAverage).toBeUndefined()
})
@@ -328,6 +337,15 @@ describe('trendsChartTransforms', () => {
expect(out.comparisonOf).toEqual({ '1': '1', '1-ma': '1' })
})
+ it('omits the MA-of-previous key when the previous result is hidden', () => {
+ const out = buildDerivedConfigs([makeResult({ id: 1, compare: true, compare_label: 'previous' })], {
+ showMovingAverage: true,
+ movingAverageIntervals: 3,
+ getHidden: () => true,
+ })
+ expect(out.comparisonOf).toEqual({ '1': '1' })
+ })
+
it('omits the MA-of-previous key when the result is too short for an MA series', () => {
const out = buildDerivedConfigs(
[makeResult({ id: 1, compare: true, compare_label: 'previous', data: [1, 2] })],
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
index f7f6ba3dfca1..de746ba1ef11 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
@@ -124,6 +124,7 @@ export function buildDerivedConfigs<R extends TrendsResultLike>(
if (includeMa) {
const window = opts.movingAverageIntervals as number
out.movingAverage = results
+ .filter((r) => !opts.getHidden?.(r))
.filter((r) => r.data.length >= window)
.map((r) => ({ seriesKey: String(r.id), window }))
}
@@ -156,7 +157,7 @@ export function buildDerivedConfigs<R extends TrendsResultLike>(
// Self-map: applyComparisonDimming only checks key presence; the paired primary
// id isn't carried on TrendsResultLike.
comparisonOf[key] = key
- if (includeMa && r.data.length >= (opts.movingAverageIntervals as number)) {
+ if (includeMa && !opts.getHidden?.(r) && r.data.length >= (opts.movingAverageIntervals as number)) {
comparisonOf[movingAverageKey(key)] = key
}
}