: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(flags): keep step and marker labels apart on the schedule timeline (#112987)
Phil Haack5020203a4881
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 3db293eeb757..4817711c44a5 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -10187,7 +10187,7 @@ snapshots:scenes-app-data-warehouse-settings-schemas--multi-schema--light:hash: v1.k794b7964.2f4bd6098d8c54c0b25ed9ee0ef7770a59c4d343191d065b0814299a27a42a22.6jWN3F1ozzMy7KZRTYHY1XPxasFL_u2H8Ybw9WcDjfkscenes-app-data-warehouse-sql-editor--bi-calculated-measure-editor--dark:- hash: v1.k794b7964.87b9871ba40527e15aff583d855822e3d4bd58d0dfbba0c5ebab4f6fc6f28d59.G36fGeQ5awgRh8N2pp3qgS7p3J5-56CokKJitervSQk+ hash: v1.k794b7964.12c7856456146005facc20476ace1bca873839da9b5071e68e56a4b3b9665886.yBDgd64GC9dNNDHAGXdBDO4vG2YcvhEMEBU5Z5TKS_Mscenes-app-data-warehouse-sql-editor--bi-calculated-measure-editor--light:hash: v1.k794b7964.69c71d482b1b19aa18a81b5ba0fc0bb038d8f3bdc9bdb0a7286c9addb4893dc2.LjgKhmcTELX-Cd50ZnnKmKLTGxv3AH0cD5BfLrBKfQ8scenes-app-data-warehouse-sql-editor--bi-catalog-snapshot--dark:@@ -10978,6 +10978,10 @@ snapshots:hash: v1.k794b7964.80b91247f288e836b99853ff3a1921184cc36621729d964870047e1b356cd2fe.vji9HS2Hp2Kdn6IsqOBZsMM2B9hpQ7-2yH4EEat4Jh4scenes-app-feature-flags-schedule-timeline--edge-step-labels--light:hash: v1.k794b7964.b977adbbcb59635a3b478ffd4ed41f7bc5803bb159f90a675668e2571f6c70e5.c_WEpoX7fZ1siRkx54hn1JgrT4MYzcJujYqQOXpyFKw+ scenes-app-feature-flags-schedule-timeline--marker-beside-full-rollout-step--dark:+ hash: v1.k794b7964.d07aa33fc1e263650225f4b44f79baf1937689c11ba42c6ac996506a632aa57d.DXBIHP7jpUf27ifHqIHRdtFAqfpowKjb4f-TmB36uK8+ scenes-app-feature-flags-schedule-timeline--marker-beside-full-rollout-step--light:+ hash: v1.k794b7964.421de448b718e2d93b10cac538f4da409455e467af5dce52a66dbf27ad97f0e2.sPHbTyKL9VeL-hOLt3nN5KX5mM68pz-I3nggmhfexHcscenes-app-feature-flags-schedule-timeline--rollout-ramp--dark:hash: v1.k794b7964.a25d523cfa2098bcd1505f27e1152a712086ba2f5b4c2733ed02abf76e3e2990.wBGaE6uS0YbRr65WjgHcOLfToFjg9_YeU_jy6znKqaEscenes-app-feature-flags-schedule-timeline--rollout-ramp--light:diff --git a/frontend/src/scenes/feature-flags/ScheduleTimeline.stories.tsx b/frontend/src/scenes/feature-flags/ScheduleTimeline.stories.tsxindex 27b8b24b843f..ddf563a6f874 100644--- a/frontend/src/scenes/feature-flags/ScheduleTimeline.stories.tsx+++ b/frontend/src/scenes/feature-flags/ScheduleTimeline.stories.tsx@@ -118,6 +118,30 @@ export function SingleOccurrence(): JSX.Element {)}+export function MarkerBesideFullRolloutStep(): JSX.Element {+ return (+ <div className="max-w-3xl">+ <ScheduleTimeline+ occurrences={[+ coveredRolloutStep(1, 25),+ occurrence(+ 2,+ { operation: ScheduledChangeOperationType.UpdateStatus, value: false },+ { active: false, rolloutPercentage: 100, variantCount: null }+ ),+ occurrence(+ 30,+ { operation: ScheduledChangeOperationType.UpdateStatus, value: true },+ { active: true, rolloutPercentage: 100, variantCount: null }+ ),+ ]}+ currentRolloutPercentage={100}+ timezone="UTC"+ />+ </div>+ )+}+export function CoveredRolloutRamp(): JSX.Element {return (<div className="max-w-3xl">diff --git a/frontend/src/scenes/feature-flags/ScheduleTimeline.test.tsx b/frontend/src/scenes/feature-flags/ScheduleTimeline.test.tsxindex f4a1045815e3..73388670d164 100644--- a/frontend/src/scenes/feature-flags/ScheduleTimeline.test.tsx+++ b/frontend/src/scenes/feature-flags/ScheduleTimeline.test.tsx@@ -190,6 +190,60 @@ describe('ScheduleTimeline', () => {])})+ it.each([+ {+ name: 'a full-rollout step label',+ earlier: coveredStep(true, 25),+ earlierText: 'still 100%',+ offAt: '2099-08-27T10:22:00Z',+ },+ {+ // The two estimated label boxes sit about two units apart. Only the minimum space that the+ // layout keeps between labels sends "Off" up a lane.+ name: 'a marker label just before it',+ earlier: occurrence({+ timestamp: '2099-09-04T10:22:00Z',+ projected: { active: true, rolloutPercentage: 100, variantCount: null },+ }),+ earlierText: 'On',+ offAt: '2099-09-05T03:22:00Z',+ },+ {+ // Digits and "%" draw wider than the average character. At the average width the two boxes+ // clear the minimum space, but the app font draws the labels as "99.99%Off".+ name: 'a bare percentage step label',+ earlier: occurrence({+ operation: ScheduledChangeOperationType.AddReleaseCondition,+ addedRolloutPercentage: 99.99,+ projected: { active: true, rolloutPercentage: 99.99, variantCount: null },+ }),+ earlierText: '99.99%',+ offAt: '2099-08-28T05:22:00Z',+ },+ ])('lifts a marker label clear of $name in the same row', ({ earlier, earlierText, offAt }) => {+ render(+ <ScheduleTimeline+ occurrences={[+ earlier,+ occurrence({+ timestamp: offAt,+ projected: { active: false, rolloutPercentage: 100, variantCount: null },+ }),+ occurrence({+ timestamp: '2099-09-24T10:22:00Z',+ operation: ScheduledChangeOperationType.UpdateVariants,+ projected: { active: false, rolloutPercentage: 100, variantCount: 3 },+ }),+ ]}+ currentRolloutPercentage={100}+ timezone="UTC"+ />+ )++ const baseline = (text: string): number => Number(screen.getByText(text).getAttribute('y'))+ expect(baseline(earlierText) - baseline('Off')).toBeGreaterThanOrEqual(9)+ })+it('anchors a step label at its mark near either edge, so the text stays in the plot', () => {const step = (timestamp: string, rollout: number): ScheduleOccurrence =>occurrence({diff --git a/frontend/src/scenes/feature-flags/ScheduleTimeline.tsx b/frontend/src/scenes/feature-flags/ScheduleTimeline.tsxindex fced2ff71a17..18f314d87b48 100644--- a/frontend/src/scenes/feature-flags/ScheduleTimeline.tsx+++ b/frontend/src/scenes/feature-flags/ScheduleTimeline.tsx@@ -13,10 +13,6 @@ const PLOT_HEIGHT = HEIGHT - MARGIN.top - MARGIN.bottomconst BASELINE_Y = MARGIN.top + PLOT_HEIGHT/** Minimum viewBox-unit gap between time-axis labels before the later one is dropped. */const TIME_LABEL_MIN_GAP = 40-/** Minimum viewBox-unit gap between top labels before the later one moves to the second lane. */-const TOP_LABEL_MIN_GAP = 40-/** How far the second lane sits above the first. Tuned against the 9px label size. */-const TOP_LABEL_LANE_OFFSET = 10const LABEL_FONT_SIZE = 9/** Average width of one label character at the 9px size, measured in a browser. */const LABEL_CHAR_WIDTH = 4.5@@ -31,6 +27,15 @@ const WIDEST_LABEL = 'still 100% (needs approval)'* builder's longest string carries through here on its own.*/const LABEL_EDGE_PAD = (WIDEST_LABEL.length * LABEL_CHAR_WIDTH) / 2 + 5+/**+ * Digits and "%" draw wider than the average character. In RoundHog at the 9px size, "99.99%" measures+ * about 33 units against 27 from the average, a shortfall that the label gap does not cover.+ */+const LABEL_DIGIT_WIDTH = 5.5+const LABEL_PERCENT_WIDTH = 8.7+/** The width estimate runs short on labels such as "On". Two labels with no space between them read as one word. */+const LABEL_GAP = LABEL_CHAR_WIDTH+const TOP_LABEL_LANE_OFFSET = LABEL_FONT_SIZE + 1type LabelAnchor = 'start' | 'middle' | 'end'@@ -111,9 +116,19 @@ function markTitle(occurrence: ScheduleOccurrence, unlabelledRollout: number | n.join('. ')}+function withApprovalNote(occurrence: ScheduleOccurrence, label: string): string {+ return occurrence.needsApproval ? `${label} (needs approval)` : label+}++function describeScheduledOccurrence(occurrence: ScheduleOccurrence, timezone: string): string {+ return withApprovalNote(+ occurrence,+ `${describeOccurrence(occurrence)} on ${formatOccurrenceTime(occurrence.timestamp, timezone)}`+ )+}+function stepLabel(occurrence: ScheduleOccurrence, rollout: number): string {- const level = occurrence.rolloutUnchanged ? `still ${rollout}%` : `${rollout}%`- return occurrence.needsApproval ? `${level} (needs approval)` : level+ return withApprovalNote(occurrence, occurrence.rolloutUnchanged ? `still ${rollout}%` : `${rollout}%`)}/**@@ -130,12 +145,6 @@ function labelAnchor(x: number): LabelAnchor {return 'middle'}-function labelExtent(x: number, anchor: LabelAnchor, text: string): { left: number; right: number } {- const width = text.length * LABEL_CHAR_WIDTH- const left = anchor === 'start' ? x : anchor === 'end' ? x - width : x - width / 2- return { left, right: left + width }-}-interface PlacedLabel {text: stringy: number@@ -144,21 +153,43 @@ interface PlacedLabel {right: number}+function estimateLabelWidth(text: string): number {+ let width = 0+ for (const char of text) {+ width += char === '%' ? LABEL_PERCENT_WIDTH : /\d/.test(char) ? LABEL_DIGIT_WIDTH : LABEL_CHAR_WIDTH+ }+ return width+}++function placeLabel(x: number, y: number, text: string): PlacedLabel {+ const anchor = labelAnchor(x)+ const width = estimateLabelWidth(text)+ const left = anchor === 'start' ? x : anchor === 'end' ? x - width : x - width / 2+ return { text, y, anchor, left, right: left + width }+}++function overlapsAny(label: PlacedLabel, placed: PlacedLabel[]): boolean {+ return placed.some(+ (shown) =>+ Math.abs(shown.y - label.y) < LABEL_FONT_SIZE &&+ label.left < shown.right + LABEL_GAP &&+ label.right + LABEL_GAP > shown.left+ )+}+/** Where each occurrence's marks and labels land, resolved before render so the JSX map stays pure. */interface OccurrenceLayout {x: number/** Null when the previous time label is too close. */timeLabel: string | null- /** Alternates between two heights when top-lane markers land near the same x. */- topLabelY: number/** The step mark's y. Null for a marker. */stepY: number | null/**- * Null for a marker, and for a step label that would overlap an earlier step label whose baseline- * sits within one font size of its own. One font size is 9 units and the plot spends 0.9 units per- * rollout point, so two steps less than about 10 points apart on nearby dates stack their text.+ * Null for a step label that would overlap an earlier label whose baseline sits within one font+ * size of its own. One font size is 9 units and the plot spends 0.9 units per rollout point, so two+ * steps less than about 10 points apart on nearby dates would otherwise stack their text.*/- placedStepLabel: PlacedLabel | null+ label: PlacedLabel | null}/**@@ -186,8 +217,7 @@ export function ScheduleTimeline({const occurrence = occurrences[0]return (<div className="text-sm text-muted" data-attr="feature-flag-schedule-timeline">- Next: {describeOccurrence(occurrence)} on {formatOccurrenceTime(occurrence.timestamp, timezone)}- {occurrence.needsApproval ? ' (needs approval)' : ''}+ {`Next: ${describeScheduledOccurrence(occurrence, timezone)}`}</div>)}@@ -202,43 +232,31 @@ export function ScheduleTimeline({const layouts: OccurrenceLayout[] = []let lastTimeLabelX = -Infinity- let lastTopLabelX = -Infinity- let topLabelLane = 0- const shownStepLabels: PlacedLabel[] = []+ const placedLabels: PlacedLabel[] = []occurrences.forEach((occurrence, index) => {const x = xFor(times[index])const timeLabel = x - lastTimeLabelX >= TIME_LABEL_MIN_GAP ? relativeLabel(times[index], now) : nullif (timeLabel) {lastTimeLabelX = x}- let topLabelY = MARGIN.top - 8let stepY: number | null = null- let placedStepLabel: PlacedLabel | null = null+ let label: PlacedLabel | nullconst rollout = occurrence.projected.rolloutPercentageif (occurrence.operation === ScheduledChangeOperationType.AddReleaseCondition && rollout !== null) {stepY = yForRollout(rollout)- const text = stepLabel(occurrence, rollout)- const anchor = labelAnchor(x)- const label = { text, y: stepY - 7, anchor, ...labelExtent(x, anchor, text) }- const collides = shownStepLabels.some(- (shown) =>- Math.abs(shown.y - label.y) < LABEL_FONT_SIZE &&- label.left < shown.right &&- label.right > shown.left- )- if (!collides) {- shownStepLabels.push(label)- placedStepLabel = label- }+ const candidate = placeLabel(x, stepY - 7, stepLabel(occurrence, rollout))+ label = overlapsAny(candidate, placedLabels) ? null : candidate} else {- // Two lanes clear the common case of a pair landing together. Three or more markers- // inside one gap still overlap, because the lane alternates rather than tracks every- // occupied slot. The occurrence cap keeps that rare.- topLabelLane = x - lastTopLabelX < TOP_LABEL_MIN_GAP ? 1 - topLabelLane : 0- lastTopLabelX = x- topLabelY -= topLabelLane * TOP_LABEL_LANE_OFFSET+ const text = withApprovalNote(occurrence, markerLabel(occurrence))+ const lanes = [0, 1].map((lane) => placeLabel(x, MARGIN.top - 8 - lane * TOP_LABEL_LANE_OFFSET, text))+ // A marker label is the only visible text that names its change. The layout therefore+ // never drops it.+ label = lanes.find((lane) => !overlapsAny(lane, placedLabels)) ?? lanes[0]+ }+ if (label) {+ placedLabels.push(label)}- layouts.push({ x, timeLabel, topLabelY, stepY, placedStepLabel })+ layouts.push({ x, timeLabel, stepY, label })})// Step-line segments, split so an approval-blocked step dashes its jump and not its run.@@ -283,12 +301,7 @@ export function ScheduleTimeline({// role="img" makes the chart a single leaf node, so a screen reader never descends into the// marks and hears no date, level, or approval state. The label has to carry the plan itself.const chartLabel = `Timeline of ${occurrences.length} upcoming scheduled changes: ${occurrences- .map(- (occurrence) =>- `${describeOccurrence(occurrence)} on ${formatOccurrenceTime(occurrence.timestamp, timezone)}${- occurrence.needsApproval ? ' (needs approval)' : ''- }`- )+ .map((occurrence) => describeScheduledOccurrence(occurrence, timezone)).join(', then ')}`return (@@ -347,12 +360,12 @@ export function ScheduleTimeline({))}{occurrences.map((occurrence, index) => {- const { x, timeLabel, topLabelY, stepY, placedStepLabel } = layouts[index]+ const { x, timeLabel, stepY, label } = layouts[index]const blocked = occurrence.needsApproval// A browser shows only the first <title> child as the hover tooltip.const title = markTitle(occurrence,- stepY !== null && !placedStepLabel ? occurrence.projected.rolloutPercentage : null+ stepY !== null && !label ? occurrence.projected.rolloutPercentage : null)return (<g key={`${occurrence.schedule.id}-${occurrence.timestamp}`} opacity={blocked ? 0.5 : 1}>@@ -365,49 +378,35 @@ export function ScheduleTimeline({stroke="var(--color-border-primary)"/>{stepY !== null ? (- <>- <circle- cx={x}- cy={stepY}- r={3.5}- fill="var(--data-color-1)"- stroke="var(--color-bg-surface-primary)"- strokeWidth={1.5}- strokeDasharray={blocked ? '2 2' : undefined}- />- {placedStepLabel && (- <text- x={x}- y={placedStepLabel.y}- textAnchor={placedStepLabel.anchor}- fontSize={LABEL_FONT_SIZE}- fill="var(--color-text-secondary)"- >- {placedStepLabel.text}- </text>- )}- </>+ <circle+ cx={x}+ cy={stepY}+ r={3.5}+ fill="var(--data-color-1)"+ stroke="var(--color-bg-surface-primary)"+ strokeWidth={1.5}+ strokeDasharray={blocked ? '2 2' : undefined}+ />) : (- <>- <line- x1={x}- x2={x}- y1={MARGIN.top - 4}- y2={BASELINE_Y}- stroke="var(--color-border-primary)"- strokeDasharray="2 3"- />- <text- x={x}- y={topLabelY}- textAnchor={labelAnchor(x)}- fontSize={LABEL_FONT_SIZE}- fill="var(--color-text-secondary)"- >- {markerLabel(occurrence)}- {blocked ? ' (needs approval)' : ''}- </text>- </>+ <line+ x1={x}+ x2={x}+ y1={MARGIN.top - 4}+ y2={BASELINE_Y}+ stroke="var(--color-border-primary)"+ strokeDasharray="2 3"+ />+ )}+ {label && (+ <text+ x={x}+ y={label.y}+ textAnchor={label.anchor}+ fontSize={LABEL_FONT_SIZE}+ fill="var(--color-text-secondary)"+ >+ {label.text}+ </text>)}{timeLabel && (<text