: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(quill-charts): right y-axis rendering and per-axis, per-edge axis config (#68736)
Sam Pennington92db62cc7aec
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.mdindex 360d97519a7f..66f8726768eb 100644--- a/packages/quill/packages/charts/AGENTS.md+++ b/packages/quill/packages/charts/AGENTS.md@@ -30,7 +30,7 @@ const theme = useChartTheme() // reads CSS vars, tracks light/dark switches- Series colors come from `--data-color-1..15` (ordered categorical palette from `@posthog/quill-tokens`); chrome from `--color-graph-axis-label` / `--color-graph-axis-line` / `--color-graph-crosshair`.- `themeFromCssVars()` is the one-shot non-hook version; `DEFAULT_CHART_COLORS` is the no-DOM fallback (kept in sync with tokens by a CI-enforced test).- Omit `color` on a series to get palette assignment by index — preferred. Explicit `color` accepts hex or `var(--...)`.-- Restyle knobs, all optional and off by default so themes/hosts opt in: `theme.axisLineColor` strokes the L-axis baselines and tick marks without changing tick-label text color (falls back `axisColor` → `gridColor`); `theme.gridDashPattern` / `theme.crosshairDashPattern` (e.g. `[3, 3]`) dash the interior grid lines / hover crosshair (plot-edge frame strokes stay solid). Config side: `showGrid` draws the grid lines — a top-level key on every chart, including the time-series wrappers; grid lines are always aligned to the primary (left) y-axis ticks, and a `showGrid` set on the primary `yAxis` config wins (on secondary axes it is ignored — two grids with unaligned ticks would just be noise); `showAxisLines` draws the L-axis (alongside the grid; the grid then skips its own frame and category lines), `showTickMarks` draws short canvas tick marks snapped to the same pixel grid as the axis, and `curve: 'monotone'` smooths line/area series through every point without overshoot. With axis lines on, line strokes are trimmed at the y-axis and floored onto the x-axis so they rest against the axis instead of straddling it.+- Restyle knobs, all optional and off by default so themes/hosts opt in: `theme.axisLineColor` strokes the L-axis baselines and tick marks without changing tick-label text color (falls back `axisColor` → `gridColor`); `theme.gridDashPattern` / `theme.crosshairDashPattern` (e.g. `[3, 3]`) dash the interior grid lines / hover crosshair (plot-edge frame strokes stay solid). Config side: `showGrid` draws the grid lines — a top-level key on every chart, including the time-series wrappers; grid lines are always aligned to the primary (left) y-axis ticks, and a `showGrid` set on the primary `yAxis` config wins (on secondary axes it is ignored — two grids with unaligned ticks would just be noise); `showAxisLines` draws the L-axis (alongside the grid; the grid then skips its own frame and category lines; a right-positioned y-axis gets its own right axis line; `{ x, y }` toggles each edge independently), `showTickMarks` draws short canvas tick marks snapped to the same pixel grid as the axis, and `curve: 'monotone'` smooths line/area series through every point without overshoot. With axis lines on, line strokes are trimmed at the y-axis and floored onto the x-axis so they rest against the axis instead of straddling it.- `theme.skipDraw` suppresses all canvas painting (static layer + hover overlay) while still mounting the `<canvas>` element. Use it for deterministic visual-snapshot tests where the async paint pipeline (ResizeObserver → requestAnimationFrame) races the screenshot — the chart renders blank but layout and DOM selectors are unaffected.## Series shape (all multi-series charts)@@ -83,7 +83,7 @@ Charts fill their container and need a parent with real dimensions — a `0`-hei- `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' | 'percent'`) 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.-- Dual / multi y-axis: give a series a `yAxisId` to scale it against a second axis. On `TimeSeriesLineChart`, pass `config.yAxis` as an **array** — one `YAxisConfig` per axis — to format/scale each axis independently: set `id` (matches `Series.yAxisId`; first entry defaults to `'left'`), `position` (`'left'`/`'right'`; first entry defaults to `'left'`, the rest to `'right'`), and the usual `scale`/`format`/`tickFormatter`/`label`/`showGrid` per entry. A single object stays single-axis (unchanged). The second axis only renders when a series actually targets it; the primary (left) axis owns the gridlines. More than two axes work too (trends `showMultipleYAxes`): they stack outward per side and alternate sides. Each entry's `label` renders that axis's title at its own gutter — every axis is titled the same way (a single-object `yAxis`/scalar `yAxisLabel` is just the one left axis), driven by the shared `computeYAxisGutters` layout that `AxisLabels` (ticks) and `AxisTitles` (titles) both read so the two can't drift. `TimeSeriesBarChart`/`ComboChart` already render per-`yAxisId` axes but share one tick formatter across gutters.+- Dual / multi y-axis: give a series a `yAxisId` to scale it against a second axis. On `TimeSeriesLineChart`, pass `config.yAxis` as an **array** — one `YAxisConfig` per axis — to format/scale each axis independently: set `id` (matches `Series.yAxisId`; first entry defaults to `'left'`), `position` (`'left'`/`'right'`; first entry defaults to `'left'`, the rest to `'right'`), and the usual `scale`/`format`/`tickFormatter`/`label`/`showGrid` per entry. A single object stays single-axis (unchanged). The second axis only renders when a series actually targets it; the primary (left) axis owns the gridlines. More than two axes work too (trends `showMultipleYAxes`): they stack outward per side and alternate sides. Each entry's `label` renders that axis's title at its own gutter — every axis is titled the same way (a single-object `yAxis`/scalar `yAxisLabel` is just the one left axis), driven by the shared `computeYAxisGutters` layout that `AxisLabels` (ticks) and `AxisTitles` (titles) both read so the two can't drift. `TimeSeriesBarChart`/`TimeSeriesComboChart` take the same `yAxis` array; a sole axis pinned `right` renders on the right on every chart type.- `onDateRangeZoom` (on `LineChart`/`TimeSeriesLineChart`/base `Chart`) enables x-axis drag-to-zoom: the user drags horizontally and the callback fires once with `{ startLabel, endLabel, startIndex, endIndex }` for the spanned range. The cursor switches to a crosshair when set. x-axis only — no effect on charts with a vertical interaction axis.## Testingdiff --git a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsxindex ba1b98a804e6..bd46f9f20ae7 100644--- a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx+++ b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx@@ -32,6 +32,7 @@ import type {Series,TooltipContext,} from '../../core/types'+import { resolveAxisLines } from '../../core/types'import { BarTooltip } from './BarTooltip'import { computeWrapperMinHeight, HORIZONTAL_MIN_BAND_SIZE_DEFAULT } from './utils/bar-config'import { cursorInInertTrackGap, groupedBandSlotAtCursor } from './utils/bars-under-cursor'@@ -79,7 +80,10 @@ function BarChartInner<Meta = unknown>({barLayout = 'stacked',axisOrientation = 'vertical',xTickFormatter,+ yAxes: configYAxes,} = config ?? {}+ const { x: xAxisLine, y: yAxisLine } = resolveAxisLines(showAxisLines)+ const axisLines = useMemo(() => ({ x: xAxisLine, y: yAxisLine }), [xAxisLine, yAxisLine])const {cornerRadius: barCornerRadius = 0,track: trackConfig = false,@@ -182,6 +186,7 @@ function BarChartInner<Meta = unknown>({minBandSize: resolvedMinBandSize,valueDomain,valuePadding,+ axes: configYAxes,})const tickAxisLength = isHorizontal ? dimensions.plotWidth : dimensions.plotHeight@@ -255,6 +260,7 @@ function BarChartInner<Meta = unknown>({resolvedMinBandSize,valueDomain,valuePadding,+ configYAxes,])@@ -264,7 +270,7 @@ function BarChartInner<Meta = unknown>({barLayout,isHorizontal,showGrid,- showAxisLines,+ axisLines,xTickFormatter,stackedData,topStackedKeyByAxis,@@ -276,7 +282,7 @@ function BarChartInner<Meta = unknown>({}),[showGrid,- showAxisLines,+ axisLines,stackedData,barLayout,isHorizontal,diff --git a/packages/quill/packages/charts/src/charts/BarChart/utils/draw-bar-chart.ts b/packages/quill/packages/charts/src/charts/BarChart/utils/draw-bar-chart.tsindex 3bf7b39bea75..d26c836ec5e9 100644--- a/packages/quill/packages/charts/src/charts/BarChart/utils/draw-bar-chart.ts+++ b/packages/quill/packages/charts/src/charts/BarChart/utils/draw-bar-chart.ts@@ -81,7 +81,7 @@ export interface DrawBarChartStaticArgs {barLayout: BarLayoutisHorizontal: booleanshowGrid: boolean- showAxisLines: boolean+ axisLines: { x: boolean; y: boolean }xTickFormatter: BarChartConfig['xTickFormatter']stackedData: Map<string, StackedBand> | undefinedtopStackedKeyByAxis: Map<string, string>@@ -101,7 +101,7 @@ export function drawBarChartStatic(barLayout,isHorizontal,showGrid,- showAxisLines,+ axisLines,xTickFormatter,stackedData,topStackedKeyByAxis,@@ -127,15 +127,16 @@ export function drawBarChartStatic(// Grid sits behind the bars; the L-axis is drawn after them (below) so a bar doesn't paint over// the baseline where it meets the axis.+ const axisLineStyle = axisLines.x || axisLines.yif (showGrid) {drawGrid(baseDrawCtx, {gridColor: theme.gridColor,gridDash: theme.gridDashPattern,- frame: !showAxisLines,+ frame: !axisLineStyle,orientation: isHorizontal ? 'horizontal' : 'vertical',// In the axis-line style only the value-axis grid guides reading; category lines// through the band gaps are noise (line charts never draw them either).- categoryTicks: showAxisLines ? [] : computeGridTicks(d3Scales, drawLabels, isHorizontal, xTickFormatter),+ categoryTicks: axisLineStyle ? [] : computeGridTicks(d3Scales, drawLabels, isHorizontal, xTickFormatter),})}@@ -202,8 +203,15 @@ export function drawBarChartStatic(}})- if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ if (axisLineStyle) {+ const hasRightAxis =+ !isHorizontal && Object.values(d3Scales.yAxes ?? {}).some((axis) => axis.position === 'right')+ drawAxes(baseDrawCtx, {+ axisColor: resolveAxisLineColor(theme),+ xLine: axisLines.x,+ yLine: axisLines.y,+ rightAxis: hasRightAxis,+ })}}diff --git a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsxindex c79cbf029c33..552031283d14 100644--- a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx+++ b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx@@ -1,7 +1,13 @@import { color as d3Color } from 'd3-color'import React, { useCallback, useMemo } from 'react'-import { applyOuterStackCaps, bandCenter, buildBarLayers, computeBarAtIndex, groupedBarCenter } from '../../core/bar-layout'+import {+ applyOuterStackCaps,+ bandCenter,+ buildBarLayers,+ computeBarAtIndex,+ groupedBarCenter,+} from '../../core/bar-layout'import {BAR_HIGHLIGHT_DARKEN,DEFAULT_BAR_CORNER_RADIUS,@@ -46,7 +52,7 @@ import type {SeriesType,TooltipContext,} from '../../core/types'-import { DEFAULT_SERIES_TYPE, DEFAULT_Y_AXIS_ID } from '../../core/types'+import { DEFAULT_SERIES_TYPE, DEFAULT_Y_AXIS_ID, resolveAxisLines } from '../../core/types'import { computeVisibleXLabels } from '../../overlays/AxisLabels'import { resolveBarsAtCursor } from '../BarChart/utils/bars-under-cursor'@@ -93,8 +99,11 @@ function ComboChartInner<Meta = unknown>({xTickFormatter,valueDomain,curve,+ yAxes: configYAxes,} = config ?? {}const smooth = curve === 'monotone'+ const { x: xAxisLine, y: yAxisLine } = resolveAxisLines(showAxisLines)+ const axisLines = useMemo(() => ({ x: xAxisLine, y: yAxisLine }), [xAxisLine, yAxisLine])const seriesTypeOf = useCallback((s: Pick<Series, 'type'>): SeriesType => resolveSeriesType(s, defaultSeriesType),@@ -134,6 +143,7 @@ function ComboChartInner<Meta = unknown>({seriesTypeOf,barStackedData,valueDomain,+ axes: configYAxes,})const yTickCount = yTickCountForHeight(dimensions.plotHeight)@@ -166,7 +176,7 @@ function ComboChartInner<Meta = unknown>({_private: comboPrivate,}},- [yScaleType, barLayout, seriesTypeOf, barStackedData, valueDomain]+ [yScaleType, barLayout, seriesTypeOf, barStackedData, valueDomain, configYAxes])const drawStatic = useCallback(@@ -188,10 +198,11 @@ function ComboChartInner<Meta = unknown>({// Grid sits behind the data; the L-axis is drawn after the series (below) so neither bars// nor lines paint over the baseline where they meet the axis.+ const axisLineStyle = axisLines.x || axisLines.yif (showGrid) {// In the axis-line style only the value-axis grid guides reading; category lines// through the band gaps are noise (line charts never draw them either).- const categoryTicks = showAxisLines+ const categoryTicks = axisLineStyle? []: computeVisibleXLabels(drawLabels, (label) => bandCenter(comboScales, label), xTickFormatter).map((entry) => entry.x@@ -199,7 +210,7 @@ function ComboChartInner<Meta = unknown>({drawGrid(baseDrawCtx, {gridColor: theme.gridColor,gridDash: theme.gridDashPattern,- frame: !showAxisLines,+ frame: !axisLineStyle,categoryTicks,})}@@ -244,20 +255,24 @@ function ComboChartInner<Meta = unknown>({smooth,// Rest baseline-hugging strokes on the axis line, and trim the first point's// stroke at the y-axis, instead of straddling either axis line.- yFloor: showAxisLines- ? dimensions.plotTop + dimensions.plotHeight - LINE_STROKE_WIDTH / 2- : undefined,- clipLeftEdge: showAxisLines,+ yFloor: axisLines.x ? dimensions.plotTop + dimensions.plotHeight - LINE_STROKE_WIDTH / 2 : undefined,+ clipLeftEdge: axisLines.y,})- if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ if (axisLineStyle) {+ const hasRightAxis = Object.values(comboScales.yAxes).some((axis) => axis.position === 'right')+ drawAxes(baseDrawCtx, {+ axisColor: resolveAxisLineColor(theme),+ xLine: axisLines.x,+ yLine: axisLines.y,+ rightAxis: hasRightAxis,+ })}},[seriesTypeOf,showGrid,- showAxisLines,+ axisLines,xTickFormatter,barLayout,barStackedData,diff --git a/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx b/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsxindex 3d01219b1bfd..f5276450ff69 100644--- a/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx+++ b/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx@@ -24,7 +24,7 @@ import {yTickCountForHeight,} from '../../core/scales'import type { ScaleSet, StackedBand } from '../../core/scales'-import { DEFAULT_Y_AXIS_ID } from '../../core/types'+import { DEFAULT_Y_AXIS_ID, resolveAxisLines } from '../../core/types'import type {ChartDimensions,ChartDrawArgs,@@ -92,6 +92,9 @@ function LineChartInner<Meta = unknown>({curve,} = config ?? {}const smooth = curve === 'monotone'+ // Resolve to primitives so an inline `{ x, y }` config object can't churn the draw callbacks.+ const { x: xAxisLine, y: yAxisLine } = resolveAxisLines(showAxisLines)+ const axisLines = useMemo(() => ({ x: xAxisLine, y: yAxisLine }), [xAxisLine, yAxisLine])const { visibleSeries, legendProps } = useChartLegend(series, theme, config?.legend)@@ -188,8 +191,13 @@ function LineChartInner<Meta = unknown>({// Grid sits behind the data; the L-axis is drawn after the series (below) so the line// doesn't paint over the baseline where it meets the axis.+ const axisLineStyle = axisLines.x || axisLines.yif (showGrid) {- drawGrid(baseDrawCtx, { gridColor: theme.gridColor, gridDash: theme.gridDashPattern, frame: !showAxisLines })+ drawGrid(baseDrawCtx, {+ gridColor: theme.gridColor,+ gridDash: theme.gridDashPattern,+ frame: !axisLineStyle,+ })}// Area then line+points per series, clipped vertically (shared with ComboChart). Areas use@@ -208,21 +216,33 @@ function LineChartInner<Meta = unknown>({smooth,// Rest baseline-hugging strokes on the axis line, and trim the first point's// stroke at the y-axis, instead of straddling either axis line.- yFloor: showAxisLines- ? dimensions.plotTop + dimensions.plotHeight - LINE_STROKE_WIDTH / 2- : undefined,- clipLeftEdge: showAxisLines,+ yFloor: axisLines.x ? dimensions.plotTop + dimensions.plotHeight - LINE_STROKE_WIDTH / 2 : undefined,+ clipLeftEdge: axisLines.y,})- if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ if (axisLineStyle) {+ const hasRightAxis = Object.values(d3Scales.yAxes ?? {}).some((axis) => axis.position === 'right')+ drawAxes(baseDrawCtx, {+ axisColor: resolveAxisLineColor(theme),+ xLine: axisLines.x,+ yLine: axisLines.y,+ rightAxis: hasRightAxis,+ })}},- [showGrid, showAxisLines, stackedData, smooth]+ [showGrid, axisLines, stackedData, smooth])const drawHover = useCallback(- ({ ctx, scales, series: coloredSeries, labels: drawLabels, hoverIndex, hoverPosition, theme }: ChartDrawArgs): boolean => {+ ({+ ctx,+ scales,+ series: coloredSeries,+ labels: drawLabels,+ hoverIndex,+ hoverPosition,+ theme,+ }: ChartDrawArgs): boolean => {if (hoverIndex < 0) {return false}diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsxindex 3e10e295b645..6c0628e12ccb 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx@@ -2,6 +2,7 @@ import React from 'react'import { ChartLegend } from '../../components/Legend/ChartLegend'import type {+ AxisLinesConfig,BarChartConfig,BarFillStyle,ChartLegendConfig,@@ -39,7 +40,7 @@ export interface TimeSeriesBarChartConfig {* `yAxis` config, when set, wins. */showGrid?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */- showAxisLines?: boolean+ showAxisLines?: AxisLinesConfig/** Draw short tick marks next to each visible axis label. Pairs with `showAxisLines`. */showTickMarks?: boolean/** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsxindex ba567ad59333..55b4168ed12f 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx@@ -2,6 +2,7 @@ import React from 'react'import { ChartLegend } from '../../components/Legend/ChartLegend'import type {+ AxisLinesConfig,ChartLegendConfig,ChartTheme,ComboChartConfig,@@ -40,7 +41,7 @@ export interface TimeSeriesComboChartConfig {* `yAxis` config, when set, wins. */showGrid?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */- showAxisLines?: boolean+ showAxisLines?: AxisLinesConfig/** Draw short tick marks next to each visible axis label. Pairs with `showAxisLines`. */showTickMarks?: boolean/** Line interpolation for line/area series: `linear` (default) or `monotone` (smooth curve). */diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsxindex bea901d413cd..79cf1db98099 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx@@ -2,6 +2,7 @@ import React from 'react'import { ChartLegend } from '../../components/Legend/ChartLegend'import type {+ AxisLinesConfig,ChartLegendConfig,ChartTheme,DateRangeZoomData,@@ -49,7 +50,7 @@ export interface TimeSeriesLineChartConfig {* `yAxis` config, when set, wins. */showGrid?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */- showAxisLines?: boolean+ showAxisLines?: AxisLinesConfig/** Draw short tick marks next to each visible axis label. Pairs with `showAxisLines`. */showTickMarks?: boolean/** Line interpolation: `linear` (default) or `monotone` (smooth curve through every point). */diff --git a/packages/quill/packages/charts/src/core/bar-scales.test.ts b/packages/quill/packages/charts/src/core/bar-scales.test.tsindex 86dab69bf126..9341fea5f4f6 100644--- a/packages/quill/packages/charts/src/core/bar-scales.test.ts+++ b/packages/quill/packages/charts/src/core/bar-scales.test.ts@@ -350,11 +350,37 @@ describe('hog-charts bar scales', () => {expect(yAxes).toBeUndefined()})- it('ignores per-series axes for stacked layouts (shared axis only)', () => {+ it('builds per-axis scales for stacked layouts (stacks are per-axis)', () => {const { yAxes } = createBarScales([smallSeries, largeSeries], ['a', 'b', 'c'], dimensions, {barLayout: 'stacked',})- expect(yAxes).toBeUndefined()+ expect(yAxes!.left.position).toBe('left')+ expect(yAxes!.y1.position).toBe('right')+ expect(yAxes!.left.scale(30)).toBeCloseTo(yAxes!.y1.scale(3000), 0)+ })++ it('honors explicit position and scaleType overrides from `axes`', () => {+ const { yAxes } = createBarScales([smallSeries, largeSeries], ['a', 'b', 'c'], dimensions, {+ barLayout: 'grouped',+ axes: [+ { id: 'left', position: 'right' },+ { id: 'y1', position: 'left', scaleType: 'log' },+ ],+ })+ expect(yAxes!.left.position).toBe('right')+ expect(yAxes!.y1.position).toBe('left')+ expect(yAxes!.left.scale.domain()[0]).toBe(0)+ expect(yAxes!.y1.scale.domain()[0]).toBeGreaterThan(0)+ })++ it('produces a yAxes record for a sole axis explicitly positioned right', () => {+ const series = [makeSeries({ key: 's1', data: [10, 20, 30], yAxisId: 'right' })]+ const { yAxes, value } = createBarScales(series, ['a', 'b', 'c'], dimensions, {+ barLayout: 'stacked',+ axes: [{ id: 'right', position: 'right' }],+ })+ expect(yAxes!.right.position).toBe('right')+ expect(value(30)).toBeCloseTo(yAxes!.right.scale(30), 5)})})})diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts b/packages/quill/packages/charts/src/core/canvas-renderer.test.tsindex 29a71e9750ec..76a7da0a1e80 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.test.ts@@ -6,6 +6,7 @@ import {composeDrawHoverWithSelection,type DrawContext,drawArea,+ drawAxes,drawGrid,drawLine,drawLineSeriesLayer,@@ -754,6 +755,32 @@ describe('hog-charts canvas-renderer', () => {})})+ describe('drawAxes — edge gating', () => {+ it.each([+ { name: 'default draws the left + bottom L only', opts: {}, x: true, y: true, right: false },+ { name: 'rightAxis strokes the right edge', opts: { rightAxis: true }, x: true, y: true, right: true },+ { name: 'x line off', opts: { xLine: false }, x: false, y: true, right: false },+ { name: 'y line off', opts: { yLine: false }, x: true, y: false, right: false },+ {+ name: 'right axis follows the y line',+ opts: { yLine: false, rightAxis: true },+ x: true,+ y: false,+ right: false,+ },+ ])('$name', ({ opts, x, y, right }) => {+ const ctx = mockCanvasContext()+ drawAxes(makeDrawContext(ctx, ['a']), opts)+ const leftX = Math.round(dimensions.plotLeft) + 0.5+ const rightX = Math.round(dimensions.plotLeft + dimensions.plotWidth) + 0.5+ const baselineY = Math.round(dimensions.plotTop + dimensions.plotHeight) + 0.5+ expect(ctx.moveTo.mock.calls.some(([mx, my]) => mx === leftX && my === dimensions.plotTop)).toBe(y)+ // The x line ends at the snapped right edge so it meets a right axis line exactly.+ expect(ctx.lineTo.mock.calls.some(([lx, ly]) => lx === rightX && ly === baselineY)).toBe(x)+ expect(ctx.moveTo.mock.calls.some(([mx, my]) => mx === rightX && my === dimensions.plotTop)).toBe(right)+ })+ })+describe('drawGrid — frame gating', () => {it('keeps the plot-edge frame strokes and the baseline gridline by default', () => {const ctx = mockCanvasContext()@@ -766,7 +793,10 @@ describe('hog-charts canvas-renderer', () => {expect(ctx.moveTo.mock.calls.some(([x]) => x === leftX)).toBe(true)})- it.each([{ frame: true, expectBaselineTick: true }, { frame: false, expectBaselineTick: false }])(+ it.each([+ { frame: true, expectBaselineTick: true },+ { frame: false, expectBaselineTick: false },+ ])('horizontal orientation: baseline-hugging value gridline drawn only when framed (frame: $frame)',({ frame, expectBaselineTick }) => {const ctx = mockCanvasContext()@@ -776,7 +806,9 @@ describe('hog-charts canvas-renderer', () => {drawCtx.yScale = scaleLinear().domain([0, 100]).range([48, 784])drawGrid(drawCtx, { orientation: 'horizontal', frame })const baselineX = Math.round(48) + 0.5- const drewBaselineTick = ctx.moveTo.mock.calls.some(([x, y]) => x === baselineX && y === dimensions.plotTop)+ const drewBaselineTick = ctx.moveTo.mock.calls.some(+ ([x, y]) => x === baselineX && y === dimensions.plotTop+ )expect(drewBaselineTick).toBe(expectBaselineTick)})@@ -1072,17 +1104,13 @@ describe('hog-charts canvas-renderer', () => {it('draws a full-plot-height band spanning the dragged range', () => {const ctx = mockCanvasContext()- composeDrawHoverWithSelection(jest.fn())(- makeSelectionArgs(ctx, { x0: plotLeft + 100, x1: plotLeft + 250 })- )+ composeDrawHoverWithSelection(jest.fn())(makeSelectionArgs(ctx, { x0: plotLeft + 100, x1: plotLeft + 250 }))expect(ctx.fillRect).toHaveBeenCalledWith(plotLeft + 100, plotTop, 150, plotHeight)})it('normalizes a right-to-left drag before drawing', () => {const ctx = mockCanvasContext()- composeDrawHoverWithSelection(jest.fn())(- makeSelectionArgs(ctx, { x0: plotLeft + 250, x1: plotLeft + 100 })- )+ composeDrawHoverWithSelection(jest.fn())(makeSelectionArgs(ctx, { x0: plotLeft + 250, x1: plotLeft + 100 }))expect(ctx.fillRect).toHaveBeenCalledWith(plotLeft + 100, plotTop, 150, plotHeight)})@@ -1096,9 +1124,7 @@ describe('hog-charts canvas-renderer', () => {it('draws nothing when the selection collapses to zero width', () => {const ctx = mockCanvasContext()- composeDrawHoverWithSelection(jest.fn())(- makeSelectionArgs(ctx, { x0: plotLeft + 10, x1: plotLeft + 10 })- )+ composeDrawHoverWithSelection(jest.fn())(makeSelectionArgs(ctx, { x0: plotLeft + 10, x1: plotLeft + 10 }))expect(ctx.fillRect).not.toHaveBeenCalled()})})@@ -1111,7 +1137,11 @@ describe('hog-charts canvas-renderer', () => {const resolveYScale = (): ScaleLinear<number, number> => yScaleit.each([- { clipLeftEdge: true, expectedLeft: Math.round(dimensions.plotLeft), expectedWidth: dimensions.width - Math.round(dimensions.plotLeft) },+ {+ clipLeftEdge: true,+ expectedLeft: Math.round(dimensions.plotLeft),+ expectedWidth: dimensions.width - Math.round(dimensions.plotLeft),+ },{ clipLeftEdge: false, expectedLeft: 0, expectedWidth: dimensions.width },])('passes left=$expectedLeft width=$expectedWidth to ctx.rect when clipLeftEdge=$clipLeftEdge',diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.ts b/packages/quill/packages/charts/src/core/canvas-renderer.tsindex bd7da8b91078..3f98fa0ab1b2 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.ts@@ -2,7 +2,15 @@ import { type ScaleLinear, type ScaleLogarithmic } from 'd3-scale'import { barColorAt, mixColors } from './color-utils'import { yTickCountForHeight } from './scales'-import type { BarFillStyle, BoxRect, ChartDimensions, ChartDrawArgs, ChartTheme, DrawHoverResult, ResolvedSeries } from './types'+import type {+ BarFillStyle,+ BoxRect,+ ChartDimensions,+ ChartDrawArgs,+ ChartTheme,+ DrawHoverResult,+ ResolvedSeries,+} from './types'export interface DrawContext {ctx: CanvasRenderingContext2D@@ -599,12 +607,19 @@ export function resolveAxisLineColor(theme: ChartTheme): string | undefined {export interface DrawAxesOptions {axisColor?: string+ /** Stroke the bottom (x) baseline. Default true. */+ xLine?: boolean+ /** Stroke the left (y) baseline. Default true. */+ yLine?: boolean+ /** Also stroke the right plot edge — for charts with a right-positioned y-axis. Gated on `yLine`. */+ rightAxis?: boolean}/** Draws just the L-shaped axis baselines — the left value axis and the bottom category axis —* without any interior grid lines. For charts that want axis framing but a clean, grid-free plot. */export function drawAxes(drawCtx: DrawContext, options: DrawAxesOptions = {}): void {const { ctx, dimensions } = drawCtx+ const { xLine = true, yLine = true } = optionsctx.strokeStyle = options.axisColor ?? 'rgba(0, 0, 0, 0.15)'ctx.lineWidth = 1ctx.setLineDash([])@@ -612,16 +627,27 @@ export function drawAxes(drawCtx: DrawContext, options: DrawAxesOptions = {}): v// zero-value grid line and with drawTickMarks' ticks.const axisX = snapToPixel(dimensions.plotLeft)const axisY = snapToPixel(dimensions.plotTop + dimensions.plotHeight)- // Route both strokes through the shared, snapped corner (axisX, axisY) so the L meets cleanly- // even when plotLeft/plotHeight are fractional.- ctx.beginPath()- ctx.moveTo(axisX, dimensions.plotTop)- ctx.lineTo(axisX, axisY)- ctx.stroke()- ctx.beginPath()- ctx.moveTo(axisX, axisY)- ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, axisY)- ctx.stroke()+ const rightX = snapToPixel(dimensions.plotLeft + dimensions.plotWidth)+ // Route the strokes through shared, snapped corners so the lines meet cleanly even when the+ // plot edges are fractional.+ if (yLine) {+ ctx.beginPath()+ ctx.moveTo(axisX, dimensions.plotTop)+ ctx.lineTo(axisX, axisY)+ ctx.stroke()+ }+ if (xLine) {+ ctx.beginPath()+ ctx.moveTo(axisX, axisY)+ ctx.lineTo(rightX, axisY)+ ctx.stroke()+ }+ if (yLine && options.rightAxis) {+ ctx.beginPath()+ ctx.moveTo(rightX, dimensions.plotTop)+ ctx.lineTo(rightX, axisY)+ ctx.stroke()+ }}/** Length (px) of an axis tick mark, measured outward from the plot edge. */diff --git a/packages/quill/packages/charts/src/core/combo-scales.test.ts b/packages/quill/packages/charts/src/core/combo-scales.test.tsindex 3031cd36c9b1..6ad9e1d3d1ec 100644--- a/packages/quill/packages/charts/src/core/combo-scales.test.ts+++ b/packages/quill/packages/charts/src/core/combo-scales.test.ts@@ -153,6 +153,15 @@ describe('combo-scales', () => {expect(leftMax).toBeLessThan(500)})+ it('pins a sole axis right when the axes override says so', () => {+ const bar = makeSeries({ key: 'b', data: [1, 2], type: 'bar', yAxisId: 'right' })+ const scales = createComboScales([bar], ['a', 'b'], dimensions, {+ seriesTypeOf: typeOfWithDefault('bar'),+ axes: [{ id: 'right', position: 'right' }],+ })+ expect(scales.yAxes.right.position).toBe('right')+ })+it('points combo.y at the default axis when present', () => {const leftLine = makeSeries({ key: 'l', data: [10] })const rightBar = makeSeries({ key: 'r', data: [1000], type: 'bar', yAxisId: 'y1' })diff --git a/packages/quill/packages/charts/src/core/combo-scales.ts b/packages/quill/packages/charts/src/core/combo-scales.tsindex aa359da226ba..10c156538482 100644--- a/packages/quill/packages/charts/src/core/combo-scales.ts+++ b/packages/quill/packages/charts/src/core/combo-scales.ts@@ -39,6 +39,8 @@ export interface CreateComboScalesOptions {/** Applied to the primary (default/left) axis only — goal lines (`{ include }`) render against* the primary axis, so secondary axes keep their own data-derived scale. See {@link ValueDomain}. */valueDomain?: ValueDomain+ /** Per-axis overrides — explicit values win over the alternating-side default and `options.scaleType`. */+ axes?: { id: string; position?: 'left' | 'right'; scaleType?: 'linear' | 'log' }[]}export function resolveSeriesType(series: Pick<Series, 'type'>, defaultType: SeriesType): SeriesType {@@ -63,6 +65,7 @@ export function createComboScales(seriesTypeOf,barStackedData,valueDomain,+ axes,} = optionsconst band = scaleBand<string>()@@ -80,7 +83,11 @@ export function createComboScales(}// Empty chart still needs an axis to draw against.- const axisPositions = orderedAxisPositions(series)+ const axisOverrides = new Map((axes ?? []).map((a) => [a.id, a]))+ const axisPositions = orderedAxisPositions(series).map(({ axisId, position }) => ({+ axisId,+ position: axisOverrides.get(axisId)?.position ?? position,+ }))if (axisPositions.length === 0) {axisPositions.push({ axisId: DEFAULT_Y_AXIS_ID, position: 'left' })}@@ -107,7 +114,7 @@ export function createComboScales(// series explicitly routed to the right axis) keeps its own data-derived scale instead of// being forced onto [0, 1].const scale = createYScale(axisValueSeries, dimensions, {- scaleType,+ scaleType: axisOverrides.get(axisId)?.scaleType ?? scaleType,percentStack: barLayout === 'percent' && axisSeries.some((s) => seriesTypeOf(s) === 'bar'),valueDomain: axisId === primaryAxisId ? valueDomain : undefined,})diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.tsindex ebb9a5af47d2..60746115c3d2 100644--- a/packages/quill/packages/charts/src/core/scales.ts+++ b/packages/quill/packages/charts/src/core/scales.ts@@ -491,9 +491,7 @@ export function buildSegmentResolveValue(/** Returns the stacked bottom value for each series — use with {@link buildStackedPositionValue}* to compute per-segment midpoints for tooltip hover detection. */-export function buildStackedBottomValue(- stackedData: Map<string, StackedBand> | undefined-): ResolveValueFn | undefined {+export function buildStackedBottomValue(stackedData: Map<string, StackedBand> | undefined): ResolveValueFn | undefined {if (!stackedData) {return undefined}@@ -556,6 +554,8 @@ export function createBarScales(valueDomain?: ValueDomain/** Px reserved past the bars at the value-axis data end(s) — see {@link BarsConfig.valuePadding}. */valuePadding?: number+ /** Per-axis overrides — explicit values win over the alternating-side default and `options.scaleType`. */+ axes?: { id: string; position?: 'left' | 'right'; scaleType?: 'linear' | 'log' }[]} = {}): BarScaleSet {const {@@ -570,6 +570,7 @@ export function createBarScales(minBandSize,valueDomain,valuePadding = 0,+ axes,} = optionsconst isHorizontal = axisOrientation === 'horizontal'@@ -614,25 +615,29 @@ export function createBarScales(const valueSeries = series.map(restrictToKept)const valueStackedSeries = stackedSeries?.map(restrictToKept)- // Build per-axis scales for grouped layouts with multiple axes. Stacked/percent layouts- // share a single value axis — per-series yAxisId is ignored so the stack is consistent.+ // Per-axis scales for multi-axis charts (stacking is already per-axis). A sole axis pinned+ // right also needs a `yAxes` record — the fast path below always renders its gutter left.const visibleSeries = valueSeries.filter((s) => !s.visibility?.excluded)- const positions = orderedAxisPositions(visibleSeries)- if (positions.length > 1 && barLayout === 'grouped') {+ const axisOverrides = new Map((axes ?? []).map((a) => [a.id, a]))+ const positions = orderedAxisPositions(visibleSeries).map(({ axisId, position }) => ({+ axisId,+ position: axisOverrides.get(axisId)?.position ?? position,+ }))+ const soleAxisOnRight = positions.length === 1 && positions[0].position === 'right'+ if (positions.length > 1 || soleAxisOnRight) {const byAxis = groupVisibleSeriesByAxis(visibleSeries)const yAxes: Record<string, { scale: D3YScale; position: 'left' | 'right' }> = {}positions.forEach(({ axisId, position }, axisIndex) => {const axisSeries = byAxis.get(axisId) ?? []- const axisKeys = new Set(axisSeries.map((s) => s.key))- // Filter the pre-computed stacked tops to this axis so the domain reflects- // the cumulative stack for this axis's series, not raw individual values.- const axisStackedSeries = stackedSeries?.filter((s) => axisKeys.has(s.key))+ // Filter the pre-computed stacked tops to this axis, matching on yAxisId (not key) —+ // diverging stacks add synthetic `__bottom` entries whose yAxisId carries over.+ const axisStackedSeries = valueStackedSeries?.filter((s) => (s.yAxisId ?? DEFAULT_Y_AXIS_ID) === axisId)const scale = buildBarValueScale(axisSeries,valueRange,tickCount,barLayout,- scaleType,+ axisOverrides.get(axisId)?.scaleType ?? scaleType,axisStackedSeries?.length ? axisStackedSeries : undefined,axisIndex === 0 ? valueDomain : undefined,valuePaddingdiff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.tsindex 28838620ee61..822d54ac23dc 100644--- a/packages/quill/packages/charts/src/core/types.ts+++ b/packages/quill/packages/charts/src/core/types.ts@@ -218,6 +218,17 @@ export interface ChartMargins {left: number}+/** `showAxisLines` value — a boolean toggles both edges; `{ x, y }` toggles each independently+ * (an omitted edge defaults to shown). */+export type AxisLinesConfig = boolean | { x?: boolean; y?: boolean }++export function resolveAxisLines(value: AxisLinesConfig | undefined): { x: boolean; y: boolean } {+ if (value == null || typeof value === 'boolean') {+ return { x: !!value, y: !!value }+ }+ return { x: value.x ?? true, y: value.y ?? true }+}+/** Base configuration shared by all chart types. */export interface ChartConfig {// — Scale —@@ -243,7 +254,7 @@ export interface ChartConfig {showGrid?: boolean/** Draw only the L-shaped axis baselines (left + bottom) without interior grid lines. Ignored* when `showGrid` is true, since the grid already frames the plot. */- showAxisLines?: boolean+ showAxisLines?: AxisLinesConfig/** Draw short tick marks on the axes next to each visible tick label. Pairs with* `showAxisLines` for a clean, grid-free axis that still reads precisely. */showTickMarks?: booleandiff --git a/packages/quill/packages/charts/src/index.ts b/packages/quill/packages/charts/src/index.tsindex d2946a35f269..fa87502a2a42 100644--- a/packages/quill/packages/charts/src/index.ts+++ b/packages/quill/packages/charts/src/index.ts@@ -89,6 +89,7 @@ export type { Gutter } from './core/y-axis-gutters'// Core typesexport type {+ AxisLinesConfig,BarChartConfig,BarsConfig,ChartConfig,@@ -114,7 +115,7 @@ export type {YAxis,YAxisScale,} from './core/types'-export { DEFAULT_Y_AXIS_ID } from './core/types'+export { DEFAULT_Y_AXIS_ID, resolveAxisLines } from './core/types'// Theme: read a ChartTheme from quill data-viz CSS vars (with a built-in fallback palette)export { themeFromCssVars, useChartTheme, DEFAULT_CHART_COLORS } from './core/theme'