: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(experiments): respect metric goal in timeseries chart colors (#58769)
Anders5bb19aa182de
diff --git a/frontend/src/scenes/experiments/experimentTimeseriesLogic.ts b/frontend/src/scenes/experiments/experimentTimeseriesLogic.tsindex ea014fb2e788..e85ed556b582 100644--- a/frontend/src/scenes/experiments/experimentTimeseriesLogic.ts+++ b/frontend/src/scenes/experiments/experimentTimeseriesLogic.ts@@ -20,7 +20,7 @@ import { Experiment, ExperimentIdType } from '~/types'import type { experimentTimeseriesLogicType } from './experimentTimeseriesLogicType'import { COLORS } from './MetricsView/shared/colors'-import { getVariantInterval } from './MetricsView/shared/utils'+import { getMetricColors, getVariantInterval } from './MetricsView/shared/utils'export interface ProcessedTimeseriesDataPoint {date: string@@ -52,7 +52,7 @@ export interface ProcessedChartData {export interface ExperimentTimeseriesLogicProps {experiment: Experiment- metric?: ExperimentMetric+ metric: ExperimentMetric | undefined}export const experimentTimeseriesLogic = kea<experimentTimeseriesLogicType>([@@ -249,11 +249,14 @@ export const experimentTimeseriesLogic = kea<experimentTimeseriesLogicType>([// Generate Chart.js-ready datasetschartData: [- (s, props) => [s.processedVariantData, props.experiment],+ (s, props) => [s.processedVariantData, props.experiment, props.metric],(processedVariantData: (variantKey: string) => ProcessedTimeseriesDataPoint[],- experiment: Experiment+ experiment: Experiment,+ metric: ExperimentMetric | undefined): ((variantKey: string) => ProcessedChartData | null) => {+ // Swap positive/negative colors when the metric goal is "decrease"+ const goalColors = getMetricColors(COLORS, metric?.goal)return (variantKey: string) => {const processedData = processedVariantData(variantKey)if (processedData.length === 0) {@@ -323,11 +326,10 @@ export const experimentTimeseriesLogic = kea<experimentTimeseriesLogicType>([const index = context.dataIndexconst dataPoint = trimmedData[index]if (dataPoint?.significant) {- // Check if delta is positive or negativeconst isPositive = dataPoint.value !== null && dataPoint.value > 0return isPositive- ? hexToRGBA(COLORS.BAR_POSITIVE, 0.15)- : hexToRGBA(COLORS.BAR_NEGATIVE, 0.15)+ ? hexToRGBA(goalColors.positive, 0.15)+ : hexToRGBA(goalColors.negative, 0.15)}return hexToRGBA(COLORS.BAR_DEFAULT, 0.1)}@@ -338,11 +340,10 @@ export const experimentTimeseriesLogic = kea<experimentTimeseriesLogicType>([const index = ctx.p0DataIndexconst dataPoint = trimmedData[index]if (dataPoint?.significant) {- // Check if delta is positive or negativeconst isPositive = dataPoint.value !== null && dataPoint.value > 0return isPositive- ? hexToRGBA(COLORS.BAR_POSITIVE, 0.15)- : hexToRGBA(COLORS.BAR_NEGATIVE, 0.15)+ ? hexToRGBA(goalColors.positive, 0.15)+ : hexToRGBA(goalColors.negative, 0.15)}return hexToRGBA(COLORS.BAR_DEFAULT, 0.1)},