: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): dash incomplete metric data, default to short numbers (#65132)
Sam Pennington9afb17c8a869
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b62b126c134c..243623b6e6e9 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -669,9 +669,9 @@ snapshots:components-hogcharts-linechart--hovering-interior--light:hash: v1.k794b7964.9186ed84789ab03631d38096923a8632d535130057b6f92832decb65178be942.wGuboSulPIhdM2_GiDolvQD1kRpdyhlQuz9PFet_vSYcomponents-hogcharts-linechart--hovering-multi-series--dark:- hash: v1.k794b7964.da078843ba3e1569c6a36aa6f8ba3eb5f7dedc1852b4f256435711871b55a7ed.u12-UiyjvpbExGP33yhNmKIj7MefFMxWpXsGkf3VG74+ hash: v1.k794b7964.157939c1c62878808f9cfeffe7d10eb2b2dab6abdc98188102c23fce01e14fbd.FykAEyCz8bzzPkEoYgVpE-FBg4ncwlWAoKDgseFD-bAcomponents-hogcharts-linechart--hovering-multi-series--light:- hash: v1.k794b7964.2fa5cdb17438c5d62f6b5c075c8160df3cc4c197754fe78c0bf722cd575b0dca.92ma-HCbFCtCf_jrLu2ntgzLy0g843soMAf-qaCna-E+ hash: v1.k794b7964.2d2effaf2935816c82ddca8e6b46b1245a1c8bc7589c8d63cbae2398060e5001.UZwi1m_dJL4B6q1zWUpCUyEf2qnHxKAs83LEfm7a_Bwcomponents-hogcharts-linechart--hovering-over-aux-series--dark:hash: v1.k794b7964.1251a1dc7a11763c51054b76bcc092db995f51208e20e3ffe668690ae763c38b.L0wjl3-x2fOMd9HZpRiQP5GaQLJUBDzhFwkno_qgqdMcomponents-hogcharts-linechart--hovering-over-aux-series--light:@@ -728,6 +728,10 @@ snapshots:hash: v1.k794b7964.d6540f839923dacec7185415d7d8b5cb065e8d6514041fbfdd83b226dc993cf4.qXWVNsCEUsOo1vhn1YiXI9gQq0uKl9oUN5IJ5265d4gcomponents-hogcharts-metriccard--falling--light:hash: v1.k794b7964.258db964f84a31bfe604b19b1bfb9faa03bb98f41136c7188a2ea3db073a322b.GdxdeW4lJgAwqkeyyM94DlUkLOYIwP4OLkMN7qmqc6o+ components-hogcharts-metriccard--incomplete-trailing-period--dark:+ hash: v1.k794b7964.1ebc62758b2dbc68b96bca4f0cfbd02eec0982aeb3035907e84acbd629eb183a.eybJFxegiDZ2e7NLmI1p3spgKzS7qAAD-qRyV9SfS50+ components-hogcharts-metriccard--incomplete-trailing-period--light:+ hash: v1.k794b7964.e0ef3cced910b70e1612957a4dc88c55d53ded1de971fe63788efc2857f178fd.WE3IxSswycQjHLpNbwBSX6zPL8MFKAoRSrV0pZbBeXscomponents-hogcharts-metriccard--no-change--dark:hash: v1.k794b7964.cc7000b2031ab73a0922b493c62d140608f8f06ec054a5e6ecfa953967e4c0c9.Ee6vIwPcI14qimH2HuHvuUauqJlGIKsLv4tuIq_j-kgcomponents-hogcharts-metriccard--no-change--light:diff --git a/frontend/src/lib/components/UnitPicker/UnitPicker.tsx b/frontend/src/lib/components/UnitPicker/UnitPicker.tsxindex 0a54da7f73ed..46a86e4fc3e0 100644--- a/frontend/src/lib/components/UnitPicker/UnitPicker.tsx+++ b/frontend/src/lib/components/UnitPicker/UnitPicker.tsx@@ -7,6 +7,7 @@ import { LemonDivider } from 'lib/lemon-ui/LemonDivider'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import {AggregationAxisFormat,+ defaultAggregationAxisFormatForDisplay,INSIGHT_UNIT_OPTIONS,INSIGHT_UNIT_OPTIONS_SHORT,} from 'scenes/insights/aggregationAxisFormat'@@ -32,6 +33,8 @@ export function UnitPicker(): JSX.Element {const [isVisible, setIsVisible] = useState(false)const [localAxisFormat, setLocalAxisFormat] = useState(trendsFilter?.aggregationAxisFormat || undefined)+ // Some display types (e.g. Metric) render a default unit when none is explicitly set — reflect it here.+ const effectiveAxisFormat = localAxisFormat ?? defaultAggregationAxisFormatForDisplay(display)useKeyboardHotkeys({@@ -66,8 +69,8 @@ export function UnitPicker(): JSX.Element {const displayValue = useMemo(() => {let displayValue: React.ReactNode = 'None'- if (localAxisFormat) {- displayValue = INSIGHT_UNIT_OPTIONS_SHORT[localAxisFormat]+ if (effectiveAxisFormat) {+ displayValue = INSIGHT_UNIT_OPTIONS_SHORT[effectiveAxisFormat]}if (trendsFilter?.aggregationAxisPrefix?.length) {displayValue = `Prefix: ${trendsFilter?.aggregationAxisPrefix}`@@ -76,7 +79,7 @@ export function UnitPicker(): JSX.Element {displayValue = `Postfix: ${trendsFilter?.aggregationAxisPostfix}`}return displayValue- }, [localAxisFormat, trendsFilter])+ }, [effectiveAxisFormat, trendsFilter])const handleCustomPrefix = (): void => {showCustomUnitModal({@@ -112,7 +115,7 @@ export function UnitPicker(): JSX.Element {<LemonButtonkey={index}onClick={() => handleChange({ format: value })}- active={value === localAxisFormat}+ active={value === effectiveAxisFormat}fullWidth>{label}diff --git a/frontend/src/scenes/insights/aggregationAxisFormat.ts b/frontend/src/scenes/insights/aggregationAxisFormat.tsindex 4d47814a2783..1c1793905886 100644--- a/frontend/src/scenes/insights/aggregationAxisFormat.ts+++ b/frontend/src/scenes/insights/aggregationAxisFormat.ts@@ -21,6 +21,12 @@ export const INSIGHT_UNIT_OPTIONS: LemonSelectOptionLeaf<AggregationAxisFormat>[{ value: 'short', label: 'Short Number' },]+// The Metric display type reads as a single headline number, so it defaults to short numbers (e.g. "1.2k");+// other displays have no default unit. Returns the format to fall back to when none is explicitly set.+export const defaultAggregationAxisFormatForDisplay = (+ display: ChartDisplayType | null | undefined+): AggregationAxisFormat | undefined => (display === ChartDisplayType.Metric ? 'short' : undefined)+export const INSIGHT_UNIT_OPTIONS_SHORT: Record<AggregationAxisFormat, string> = {numeric: '',duration: 's',@@ -28,7 +34,7 @@ export const INSIGHT_UNIT_OPTIONS_SHORT: Record<AggregationAxisFormat, string> =percentage: '%',percentage_scaled: '%',currency: '$',- short: 'nr',+ short: 'Short',}// this function needs to support a trendsFilter as part of an insight query and// legacy trend filters, as we still return these as part of a data responsediff --git a/frontend/src/scenes/insights/aggregationAxisFormats.test.ts b/frontend/src/scenes/insights/aggregationAxisFormats.test.tsindex 1fb48dd20153..cf26ee535320 100644--- a/frontend/src/scenes/insights/aggregationAxisFormats.test.ts+++ b/frontend/src/scenes/insights/aggregationAxisFormats.test.ts@@ -1,10 +1,12 @@import {+ AggregationAxisFormat,+ defaultAggregationAxisFormatForDisplay,formatAggregationAxisValue,formatAggregationAxisValueWithShareOfTotal,} from 'scenes/insights/aggregationAxisFormat'import { CurrencyCode } from '~/queries/schema/schema-general'-import { FilterType } from '~/types'+import { ChartDisplayType, FilterType } from '~/types'describe('formatAggregationAxisValue', () => {const formatTestcases = [@@ -72,6 +74,26 @@ describe('formatAggregationAxisValue', () => {})})+describe('defaultAggregationAxisFormatForDisplay', () => {+ const cases: { display: ChartDisplayType; expected: AggregationAxisFormat | undefined }[] = [+ { display: ChartDisplayType.Metric, expected: 'short' },+ { display: ChartDisplayType.BoldNumber, expected: undefined },+ { display: ChartDisplayType.ActionsLineGraph, expected: undefined },+ { display: ChartDisplayType.ActionsPie, expected: undefined },+ ]++ cases.forEach(({ display, expected }) => {+ it(`returns ${String(expected)} for ${display}`, () => {+ expect(defaultAggregationAxisFormatForDisplay(display)).toEqual(expected)+ })+ })++ it('returns undefined when no display is set', () => {+ expect(defaultAggregationAxisFormatForDisplay(null)).toBeUndefined()+ expect(defaultAggregationAxisFormatForDisplay(undefined)).toBeUndefined()+ })+})+describe('formatAggregationAxisValueWithShareOfTotal', () => {const shareTestcases = [{ candidate: 250, total: 1000, filters: {}, expected: '250 (25%)' },diff --git a/frontend/src/scenes/insights/views/Metric/Metric.tsx b/frontend/src/scenes/insights/views/Metric/Metric.tsxindex d1da3f273599..c38cda76cc14 100644--- a/frontend/src/scenes/insights/views/Metric/Metric.tsx+++ b/frontend/src/scenes/insights/views/Metric/Metric.tsx@@ -6,12 +6,16 @@ import { MetricCard, useChartTheme } from '@posthog/quill-charts'import { dayjs } from 'lib/dayjs'import { hexToRGBA } from 'lib/utils/colors'import { DATE_FORMAT_WITHOUT_YEAR, formatDate } from 'lib/utils/datetime'-import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'+import {+ defaultAggregationAxisFormatForDisplay,+ formatAggregationAxisValue,+} from 'scenes/insights/aggregationAxisFormat'import { InsightEmptyState } from 'scenes/insights/EmptyStates'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'import { teamLogic } from 'scenes/teamLogic'+import { trendsDataLogic } from 'scenes/trends/trendsDataLogic'-import { ChartParams, TrendResult } from '~/types'+import { ChartDisplayType, ChartParams, TrendResult } from '~/types'import { insightLogic } from '../../insightLogic'import {@@ -36,6 +40,7 @@ const makeChangeColor = (hex: string): { background: string; foreground: stringexport function Metric({ inCardView }: ChartParams): JSX.Element {const { insightProps } = useValues(insightLogic)const { insightData, trendsFilter, interval } = useValues(insightVizDataLogic(insightProps))+ const { incompletenessOffsetFromEnd } = useValues(trendsDataLogic(insightProps))const { baseCurrency } = useValues(teamLogic)const theme = useChartTheme()@@ -75,6 +80,13 @@ export function Metric({ inCardView }: ChartParams): JSX.Element {const labels =resultSeries.days?.map((day) => formatDate(dayjs(day), DATE_FORMAT_WITHOUT_YEAR)) ?? resultSeries.labels+ // Dash the trailing in-progress period, matching the line chart. The offset is negative from the end.+ const dashedFromIndex =+ incompletenessOffsetFromEnd < 0 ? resultSeries.data.length + incompletenessOffsetFromEnd : undefined++ const aggregationAxisFormat =+ trendsFilter?.aggregationAxisFormat ?? defaultAggregationAxisFormatForDisplay(ChartDisplayType.Metric)+return (<div className={clsx('Metric ph-no-capture flex flex-col w-full p-2', inCardView && 'flex-1')}><MetricCard@@ -95,7 +107,10 @@ export function Metric({ inCardView }: ChartParams): JSX.Element {theme={theme}color={lineColor}showChange={showChange}- formatValue={(value) => formatAggregationAxisValue(trendsFilter, value, baseCurrency)}+ formatValue={(value) =>+ formatAggregationAxisValue({ ...trendsFilter, aggregationAxisFormat }, value, baseCurrency)+ }+ sparklineDashedFromIndex={dashedFromIndex}sparklineHeight={120}sparklineClassName="mt-4 -mx-2"dataAttr="metric-value"diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.mdindex 7ffb4ecc99d6..9518398c9f8b 100644--- a/packages/quill/packages/charts/AGENTS.md+++ b/packages/quill/packages/charts/AGENTS.md@@ -74,7 +74,7 @@ Charts fill their container and need a parent with real dimensions — a `0`-hei- Every multi-series chart (`LineChart`, `BarChart`, `TimeSeriesLineChart`, `TimeSeriesBarChart`, `SlopeChart`) takes a `config.legend: ChartLegendConfig` (`{ show, position, align, gap, interactive, hiddenKeys, onToggleSeries, renderItem }`). With `show: true` the chart renders a built-in legend that, by default (`interactive`), is click-to-toggle: clicking a row hides that series (no draw, no scale contribution, no tooltip — the axes rescale into the freed space) while the row stays listed but dimmed so it can be restored. The chart owns the toggled-off state (uncontrolled); set `interactive: false` for a static legend, or pass `hiddenKeys` + `onToggleSeries` to control it yourself. Hidden by default. `config.legend.renderItem(defaultNode, item)` wraps each rendered row, so consumers can augment it (e.g. attach a right-click context menu) while keeping the default swatch/label/toggle rendering — return `defaultNode` to leave a row untouched. Toggling on time-series charts lists the user's series only (not derived trend lines / CI bands) — and hiding a series also hides everything derived from it (its CI band, moving average, and trend line), so no orphaned overlay floats over the gap.- `Legend` (and `ChartLegend` for layout) is the lower-level presentational primitive: pass `items`, `onItemClick`, `hiddenKeys` — filtering series is the caller's state. Use it directly when the built-in `config.legend` can't express what you need (custom item order/labels). `useChartLegend(series, theme, config, items?)` is the shared hook the charts use — returns `visibleSeries` (hidden applied as `visibility.excluded`) plus `legendProps` to spread onto `<ChartLegend>`; `applyHiddenSeries` is the underlying helper. `LegendItem.secondaryLabel` shows muted trailing text (e.g. a slope chart's per-series change).- `SlopeChart` config: `showSeriesLabels` (name beside each point; steepest line wins label collisions), `showStartLabels`/`showEndLabels` (defaults overridable per series via `meta.showStartLabel`/`showEndLabel`), `legend` (`{ show, position }`, rows carry the formatted change, ordered biggest-to-smallest by end value to match the lines' right-edge order), `valueFormatter`/`deltaFormatter`. The value axis is hidden by default — the start/end labels are the readout. The default tooltip orders its rows biggest-to-smallest by the hovered point's value (so many-breakdown tooltips match the lines' vertical order) and formats values with `valueFormatter` so they match the on-chart labels' units; pass your own `tooltip` to override. (`DefaultTooltip` itself takes an optional `valueFormatter` for the same reason — without it values fall back to `toLocaleString`.) Per-series `meta.incompleteEnd` dashes only the second half of that connector (the last point is the current incomplete period); the renderer splits the final segment at its midpoint via `stroke.partial.fromFraction`, so a two-point line needs no phantom interior point.-- `MetricCard` is a left-aligned tile. Pass `title={null}` to drop the title row — the header band collapses when there is no title and no change pill, and the subtitle row is omitted when there is no subtitle (and no `labels`), so a value-only card renders just the number. `changeSize="md"` renders a larger change pill (default `sm`); `changeInline` puts the pill beside the headline instead of in the header; `sparklineFill` makes the sparkline fill the card's remaining height instead of a fixed `sparklineHeight`. `subtitle` always wins (shown at rest and on hover); `restingSubtitle` (e.g. `'Avg'`) shows only at rest and yields to the hovered point's label on hover — pair it with a `value` that summarizes the series (average/total) so the headline reads as a summary until hovered. `hoverChangeFromPreviousPoint` keeps the supplied resting `change` pill at rest but, while hovering, swaps it for the hovered point's change vs the previous point (hidden at the first point). `changeTooltip` shows a styled hover tooltip (floating-ui, using the host's tooltip surface tokens with chart-surface fallbacks) on the change pill (e.g. to spell out what the resting comparison is).+- `MetricCard` is a left-aligned tile. Pass `title={null}` to drop the title row — the header band collapses when there is no title and no change pill, and the subtitle row is omitted when there is no subtitle (and no `labels`), so a value-only card renders just the number. `changeSize="md"` renders a larger change pill (default `sm`); `changeInline` puts the pill beside the headline instead of in the header; `sparklineFill` makes the sparkline fill the card's remaining height instead of a fixed `sparklineHeight`; `sparklineDashedFromIndex` dashes the sparkline from that index onward (e.g. an in-progress trailing period). `subtitle` always wins (shown at rest and on hover); `restingSubtitle` (e.g. `'Avg'`) shows only at rest and yields to the hovered point's label on hover — pair it with a `value` that summarizes the series (average/total) so the headline reads as a summary until hovered. `hoverChangeFromPreviousPoint` keeps the supplied resting `change` pill at rest but, while hovering, swaps it for the hovered point's change vs the previous point (hidden at the first point). `changeTooltip` shows a styled hover tooltip (floating-ui, using the host's tooltip surface tokens with chart-surface fallbacks) on the change pill (e.g. to spell out what the resting comparison is).- `TimeSeriesComboChart` wraps `ComboChart` the way `TimeSeriesLineChart`/`TimeSeriesBarChart` wrap their base charts: `config.xAxis`/`config.yAxis` (date tick formatter, y-format, scale, grid), `config.goalLines` (off-scale targets stretch the value axis via `ComboChart`'s `valueDomain`), `config.legend` (click-to-toggle), and `config.valueLabels`. Per-series `type` (`'bar' | 'line' | 'area'`) drives rendering; `barLayout` (`'stacked' | 'grouped'`) and right-axis series (`yAxisId: 'right'`) carry over from `ComboChart`. `ComboChart` itself now also honors `valueDomain` (primary axis only) and `showAxisLines`.- y-axis `format`: `numeric | short | percentage | percentage_scaled | currency | duration | duration-ms`, plus `prefix`/`suffix`.- y-axis baseline: defaults to clamping a non-negative axis down to 0 (matching the classic insight axis). To float the axis to its data range instead — zooming in on the variation — set `yAxis.startAtZero: false` on `TimeSeriesLineChart`, or `config.floatBaseline: true` on the lower-level `LineChart`. Ignored on a log scale (no zero baseline) and applied to the primary axis only. Bar charts always draw from a zero baseline, so the flag is a no-op there.diff --git a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsxindex a39d42a76a33..851bab7fd5a5 100644--- a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx+++ b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx@@ -18,6 +18,8 @@ export interface SparklineProps {fill?: boolean/** Peak opacity of the gradient fill under the line. Range 0–1. */fillOpacity?: number+ /** Dash the line from this index onward (e.g. an in-progress trailing period). Omit for a fully solid line. */+ dashedFromIndex?: number/** Fires the hovered index, or -1 when not hovering. */onHoverIndexChange?: (index: number) => voidclassName?: string@@ -51,6 +53,7 @@ function SparklineInner({height = 120,fill = false,fillOpacity = 0.35,+ dashedFromIndex,onHoverIndexChange,className,dataAttr,@@ -68,9 +71,10 @@ function SparklineInner({data,color: resolvedColor,fill: { gradient: true, opacity: fillOpacity },+ stroke: dashedFromIndex != null ? { partial: { fromIndex: dashedFromIndex } } : undefined,},],- [data, resolvedColor, fillOpacity]+ [data, resolvedColor, fillOpacity, dashedFromIndex])const wrapperStyle = useMemo<React.CSSProperties | undefined>(() => (fill ? undefined : { height }), [fill, height])diff --git a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.stories.tsx b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.stories.tsxindex d666518f1fbf..9d01c91edbfc 100644--- a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.stories.tsx+++ b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.stories.tsx@@ -100,6 +100,29 @@ export const RestingSummary: Story = {},}+export const IncompleteTrailingPeriod: Story = {+ render: () => {+ const theme = useReactiveTheme()+ return (+ <Stage width={360} height={320}>+ <div className="rounded-xl border border-primary bg-surface-primary p-5 shadow-sm w-full h-full flex flex-col">+ <MetricCard+ title="Total Revenue"+ data={REVENUE}+ labels={MONTHS}+ theme={theme}+ color="#22d3ee"+ // Last two points are an in-progress period — dashed so it doesn't read as a real dip.+ sparklineDashedFromIndex={REVENUE.length - 2}+ sparklineClassName="mt-4 -mx-5 -mb-5"+ formatValue={(v) => `US$${Math.round(v).toLocaleString()}`}+ />+ </div>+ </Stage>+ )+ },+}+export const NumberOnly: Story = {render: () => (<Stage width={360} height={200}>diff --git a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsxindex 70ed67e8f3d6..6f1e2667f048 100644--- a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx+++ b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx@@ -48,6 +48,8 @@ export interface MetricCardProps {sparklineFill?: booleansparklineFillOpacity?: numbersparklineClassName?: string+ /** Dash the sparkline from this index onward (e.g. an in-progress trailing period). */+ sparklineDashedFromIndex?: numberformatValue?: (value: number) => stringformatChange?: (percent: number) => stringshowChange?: boolean@@ -110,6 +112,7 @@ function MetricCardInner({sparklineFill = false,sparklineFillOpacity = 0.35,sparklineClassName = 'mt-4',+ sparklineDashedFromIndex,formatValue = DEFAULT_FORMAT_VALUE,formatChange = DEFAULT_FORMAT_CHANGE,showChange = true,@@ -229,6 +232,7 @@ function MetricCardInner({height={sparklineHeight}fill={sparklineFill}fillOpacity={sparklineFillOpacity}+ dashedFromIndex={sparklineDashedFromIndex}onHoverIndexChange={setHoverIndex}className={sparklineClassName}dataAttr="metric-card-sparkline"diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts b/packages/quill/packages/charts/src/core/canvas-renderer.test.tsindex f493ba5ec194..5ca6c4ec7012 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.test.ts@@ -498,6 +498,62 @@ describe('hog-charts canvas-renderer', () => {drawArea(makeDrawContext(ctx, labels), series)expect(ctx.fill).toHaveBeenCalledTimes(expectedFills)})++ // The shaded (solid) area must end exactly where the trailing dashed/hatched area begins — same+ // boundary the stroke uses — so the fill doesn't bleed a segment past where the line turns dashed.+ it('solid fill meets the trailing hatch at one shared boundary, no overlap or gap', () => {+ const fillRanges: { min: number; max: number }[] = []+ let xs: number[] = []+ const ctx = Object.assign(mockCanvasContext(), {+ beginPath: jest.fn(() => {+ xs = []+ }),+ moveTo: jest.fn((x: number) => {+ xs.push(x)+ }),+ lineTo: jest.fn((x: number) => {+ xs.push(x)+ }),+ fill: jest.fn(() => {+ fillRanges.push({ min: Math.min(...xs), max: Math.max(...xs) })+ }),+ }) as unknown as jest.Mocked<CanvasRenderingContext2D>++ const labels = ['a', 'b', 'c', 'd', 'e']+ const series = makeSeries({ key: 's', data: [10, 20, 30, 40, 50], stroke: { partial: { fromIndex: 3 } } })+ drawArea(makeDrawContext(ctx, labels), series)++ // Call order is solid then trailing hatch.+ expect(fillRanges).toHaveLength(2)+ const [solid, hatch] = fillRanges+ expect(solid.max).toBe(hatch.min)+ })++ // A gradient fill must survive partial dashing — only the stroke dashes, so the fill stays a+ // single gradient area rather than flipping to the solid + hatch treatment.+ it('keeps a single gradient fill (no hatch) when the line is partially dashed', () => {+ const ctx = mockCanvasContext()+ const gradient = { addColorStop: jest.fn() } as unknown as CanvasGradient+ ;(ctx as unknown as { createLinearGradient: jest.Mock }).createLinearGradient = jest+ .fn()+ .mockReturnValue(gradient)+ const recordedFillStyles: unknown[] = []+ Object.defineProperty(ctx, 'fillStyle', {+ get: () => undefined,+ set: (v) => recordedFillStyles.push(v),+ })++ const series = makeSeries({+ key: 's',+ data: [10, 20, 30, 40, 50],+ fill: { gradient: true },+ stroke: { partial: { fromIndex: 3 } },+ })+ drawArea(makeDrawContext(ctx, ['a', 'b', 'c', 'd', 'e']), series)++ expect(ctx.fill).toHaveBeenCalledTimes(1)+ expect(recordedFillStyles).toEqual([gradient])+ })})describe('drawArea — fill.lowerData edge cases', () => {diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.ts b/packages/quill/packages/charts/src/core/canvas-renderer.tsindex ee4a4fd50a1e..6b28dfcc66bc 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.ts@@ -244,8 +244,9 @@ export function drawArea(ctx.globalAlpha = opacity- // Gradient applies only to the un-stacked baseline fill; dashed-partial segments- // stay on a solid fill via the branch below.+ // A gradient fill always paints the whole area; partial dashing then only affects the stroke+ // (drawLine), so the fade stays intact under an in-progress dashed tail instead of flipping to+ // the solid + hatch treatment below (which non-gradient area charts still use).const useGradient = series.fill?.gradient && !bottomValueslet gradient: CanvasGradient | null = nullif (useGradient) {@@ -259,7 +260,7 @@ export function drawArea(continue}- if (dashedFrom === null && dashedTo === null) {+ if (useGradient || (dashedFrom === null && dashedTo === null)) {ctx.fillStyle = gradient ?? series.colorfillAreaPath(ctx, top, bottom)continue@@ -288,11 +289,12 @@ export function drawArea(const solidStart = toSplit === -1 ? 0 : toSplitconst solidEnd = fromSplit === -1 ? top.length : fromSplit+ // Solid stops exactly where the trailing hatch begins (its `hatchStart = fromSplit - 1`), sharing+ // that one boundary point — no overlap. Otherwise the solid fill bleeds under the first dashed+ // segment and the shaded region stops a step past where the line turns dashed.if (solidEnd - solidStart >= 2) {- const trailingHatchPresent = dashedFrom !== null && fromSplit !== -1- const slicedEnd = trailingHatchPresent ? Math.min(top.length, solidEnd + 1) : solidEndctx.fillStyle = series.color- fillAreaPath(ctx, top.slice(solidStart, slicedEnd), bottom.slice(solidStart, slicedEnd))+ fillAreaPath(ctx, top.slice(solidStart, solidEnd), bottom.slice(solidStart, solidEnd))}if (dashedFrom !== null && fromSplit > 0) {diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.tsindex 92d51d3eee8c..da4936726f78 100644--- a/packages/quill/packages/charts/src/core/types.ts+++ b/packages/quill/packages/charts/src/core/types.ts@@ -90,8 +90,9 @@ export interface Series<Meta = unknown> {* filling down to the x-axis baseline. */lowerData?: number[]/** Fade the fill vertically from the series color at the top of the plot to transparent- * at the baseline. Ignored whenever the area has a bottom edge — stacking, `lowerData`,- * or dashed `stroke.partial` (those branches need a solid fill / hatch). */+ * at the baseline. Ignored when the area has a bottom edge — stacking or `lowerData`+ * (those need a solid fill). With a dashed `stroke.partial` the gradient is kept and only+ * the stroke dashes; non-gradient area fills instead hatch the dashed range. */gradient?: boolean}/** Auxiliary overlay derived from primary data — trend lines and moving averages.