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(insights): wire SQL insight display options to quill charts (#68737)

Sam Pennington010ef7b0756e
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
index 8b9cf6df6cba..69fb40edaca9 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
@@ -95,6 +95,48 @@ describe('SqlBarGraph', () => {
})
})
+ describe('dual y-axis', () => {
+ it.each([
+ { name: 'grouped', display: ChartDisplayType.ActionsBar },
+ { name: 'stacked', display: ChartDisplayType.ActionsStackedBar },
+ ])('renders a right gutter formatted from its own column in the $name layout', async ({ display }) => {
+ renderBar(
+ display,
+ {
+ yAxis: [
+ { column: 'a', settings: { formatting: { prefix: '$' } } },
+ {
+ column: 'b',
+ settings: { formatting: { suffix: '%' }, display: { yAxisPosition: 'right' } },
+ },
+ ],
+ },
+ twoSeries()
+ )
+
+ await screen.findByLabelText(/chart with 2 data series/i)
+ await waitFor(() => expect(getHogChart().hasRightAxis).toBe(true))
+ const chart = getHogChart()
+ expect(chart.yTicks().length).toBeGreaterThan(0)
+ expect(chart.yTicks().every((tick) => tick.startsWith('$'))).toBe(true)
+ const rightTicks = chart.yRightTicks()
+ expect(rightTicks.length).toBeGreaterThan(0)
+ expect(rightTicks.every((tick) => tick.endsWith('%'))).toBe(true)
+ })
+
+ it('renders the axis on the right when the only series targets the right axis', async () => {
+ renderBar(
+ ChartDisplayType.ActionsBar,
+ { yAxis: [{ column: 'a', settings: { display: { yAxisPosition: 'right' } } }] },
+ barFixture([{ name: 'a', valueAt: (i) => (i + 1) * 100 }])
+ )
+
+ await screen.findByLabelText(/chart with/i)
+ await waitFor(() => expect(getHogChart().yRightTicks().length).toBeGreaterThan(0))
+ expect(getHogChart().yTicks()).toHaveLength(0)
+ })
+ })
+
describe('tooltip', () => {
// Grouped/stacked bars split the band, so a band-center hover only deterministically lands on
// a single bar — assert tooltip content with one series, layout/legend with two.
@@ -108,7 +150,8 @@ describe('SqlBarGraph', () => {
await screen.findByLabelText(/chart with/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
- expect(tooltip.value('a')).toBe('3,000')
+ // formatSqlSeriesValue output — matches the line/combo tooltips, not toLocaleString.
+ expect(tooltip.value('a')).toBe('3000')
expect(tooltip.label()).toBe('Dec 1, 2025')
expect(tooltip.swatchColors()).toHaveLength(1)
})
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
index 518e14ce4cb3..87a69f9b6bca 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
@@ -155,6 +155,33 @@ describe('SqlLineGraph', () => {
expect(rightTicks.length).toBeGreaterThan(0)
expect(rightTicks.every((tick) => tick.endsWith('%'))).toBe(true)
})
+
+ it('hides only the right gutter when the right axis turns tick labels off', async () => {
+ await renderChart({
+ chartSettings: { rightYAxisSettings: { showTicks: false } },
+ yData: [
+ ySeries('revenue', [1200, 1400, 1300]),
+ ySeries('conversion', [12, 18, 15], { display: { yAxisPosition: 'right' } }),
+ ],
+ })
+
+ await waitFor(() => expect(getHogChart().yTicks().length).toBeGreaterThan(0))
+ expect(getHogChart().yRightTicks()).toHaveLength(0)
+ })
+
+ it('floats only the right axis when its begin-at-zero is off', async () => {
+ await renderChart({
+ chartSettings: { rightYAxisSettings: { startAtZero: false } },
+ yData: [
+ ySeries('revenue', [1200, 1400, 1300]),
+ ySeries('conversion', [800, 900, 850], { display: { yAxisPosition: 'right' } }),
+ ],
+ })
+
+ await waitFor(() => expect(getHogChart().hasRightAxis).toBe(true))
+ expect(lowestTick(getHogChart().yRightTicks())).toBeGreaterThan(0)
+ expect(lowestTick(getHogChart().yTicks())).toBe(0)
+ })
})
describe('start at zero', () => {
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.test.ts b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.test.ts
index 192ba8c8c03d..dce593fec868 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.test.ts
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.test.ts
@@ -575,6 +575,27 @@ describe('sqlLineGraphAdapter', () => {
expect(Array.isArray(config.yAxis)).toBe(false)
})
+ it.each([
+ ['leaves showAxisLines unset when both borders are on (app style default applies)', {}, undefined],
+ [
+ 'turns off the x axis line when showXAxisBorder is off',
+ { showXAxisBorder: false },
+ { x: false, y: true },
+ ],
+ [
+ 'turns off the y axis line when showYAxisBorder is off',
+ { showYAxisBorder: false },
+ { x: true, y: false },
+ ],
+ ])('%s', (_name, chartSettings, expected) => {
+ const config = buildLineChartConfig({
+ xData: dateXData,
+ chartSettings: chartSettings as ChartSettings,
+ timezone: 'UTC',
+ })
+ expect(config.showAxisLines).toEqual(expected)
+ })
+
it('emits a per-axis array honoring each column settings when a series targets the right axis', () => {
const ySeriesData = [ySeries('a', [1, 2]), ySeries('b', [3, 4], { display: { yAxisPosition: 'right' } })]
const chartSettings: ChartSettings = {
@@ -770,6 +791,28 @@ describe('sqlLineGraphAdapter', () => {
expect(config.trendLines).toEqual([])
})
+ it('maps the axis-border toggles to per-edge showAxisLines for bars', () => {
+ const config = buildBarChartConfig({
+ xData: dateXData,
+ chartSettings: { showXAxisBorder: false },
+ timezone: 'UTC',
+ visualizationType: ChartDisplayType.ActionsBar,
+ })
+ expect(config.showAxisLines).toEqual({ x: false, y: true })
+ })
+
+ it('builds the shared SQL tooltip so bars honor showTotalRow and per-column formatting', () => {
+ const config = buildBarChartConfig({
+ xData: dateXData,
+ chartSettings: { showTotalRow: false },
+ timezone: 'UTC',
+ visualizationType: ChartDisplayType.ActionsBar,
+ ySeriesData: [ySeries('a', [1]), ySeries('b', [2])],
+ })
+ expect(config.tooltip).toMatchObject({ showTotal: false })
+ expect(config.tooltip!.valueFormatter).toBeInstanceOf(Function)
+ })
+
it('emits a per-axis array with forceLinear threaded through both gutters when a series targets the right axis', () => {
const ySeriesData = [ySeries('a', [1, 2]), ySeries('b', [3, 4], { display: { yAxisPosition: 'right' } })]
const config = buildBarChartConfig({
@@ -807,6 +850,16 @@ describe('sqlLineGraphAdapter', () => {
expect(config.barLayout).toBe(expected)
})
+ it('maps the axis-border toggles to per-edge showAxisLines for combo', () => {
+ const config = buildComboChartConfig({
+ xData: dateXData,
+ chartSettings: { showYAxisBorder: false },
+ timezone: 'UTC',
+ visualizationType: ChartDisplayType.ActionsBar,
+ })
+ expect(config.showAxisLines).toEqual({ x: true, y: false })
+ })
+
it('wires goal lines, legend, and a date x-axis formatter', () => {
const config = buildComboChartConfig({
xData: dateXData,
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.ts b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.ts
index 8bb8e4663c53..5cf96e5e66b5 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.ts
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlLineGraphAdapter.ts
@@ -1,5 +1,6 @@
import { lemonToast } from '@posthog/lemon-ui'
import {
+ type AxisLinesConfig,
type ChartLegendConfig,
type Series,
type SeriesType,
@@ -366,6 +367,14 @@ function buildLegendConfig(chartSettings: ChartSettings): ChartLegendConfig {
return { show: chartSettings.showLegend ?? false, position: 'top', interactive: true }
}
+/** The X/Y axis-border toggles map onto quill's per-edge axis lines — undefined when both are on
+ * (the default), so the app-level style default still applies. */
+function buildAxisLinesConfig(chartSettings: ChartSettings): AxisLinesConfig | undefined {
+ const x = chartSettings.showXAxisBorder ?? true
+ const y = chartSettings.showYAxisBorder ?? true
+ return x && y ? undefined : { x, y }
+}
+
/**
* "Show values on series" — each on-series label formats with its own column's settings, reusing the
* tooltip's {@link formatSqlSeriesValue} path so labels read identically to the tooltip. `seriesIndex`
@@ -416,6 +425,7 @@ export function buildLineChartConfig({
]
: buildYAxisConfig(chartSettings.leftYAxisSettings, leftSeries, chartSettings.yAxisAtZero),
goalLines: schemaGoalLinesToConfigs(goalLines),
+ showAxisLines: buildAxisLinesConfig(chartSettings),
trendLines: buildTrendLineConfigs(ySeriesData),
legend: buildLegendConfig(chartSettings),
valueLabels: buildValueLabelsConfig(chartSettings, ySeriesData),
@@ -459,13 +469,17 @@ export function buildBarChartConfig({
forceLinear: barLayout === 'percent',
}),
goalLines: schemaGoalLinesToConfigs(goalLines),
+ showAxisLines: buildAxisLinesConfig(chartSettings),
barLayout,
// Percent bars scale against a [0, 1] domain; trend lines plot raw series values, so they'd
// render off-scale and invisible.
trendLines: barLayout === 'percent' ? [] : buildTrendLineConfigs(ySeriesData),
legend: buildLegendConfig(chartSettings),
valueLabels: buildValueLabelsConfig(chartSettings, ySeriesData),
- tooltip: { enabled: true, pinnable: true, placement: 'cursor', ...(labelFormatter ? { labelFormatter } : {}) },
+ tooltip: {
+ ...buildSqlTooltipConfig(chartSettings, ySeriesData),
+ ...(labelFormatter ? { labelFormatter } : {}),
+ },
}
}
@@ -504,6 +518,7 @@ export function buildComboChartConfig({
forceLinear: isPercent,
}),
goalLines: schemaGoalLinesToConfigs(goalLines),
+ showAxisLines: buildAxisLinesConfig(chartSettings),
barLayout,
// Percent bars scale against a [0, 1] domain; trend lines plot raw series values, so they'd
// render off-scale and invisible.
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index 66f8726768eb..d9fbba9e6e50 100644
--- a/packages/quill/packages/charts/AGENTS.md
+++ b/packages/quill/packages/charts/AGENTS.md
@@ -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`/`TimeSeriesComboChart` take the same `yAxis` array; a sole axis pinned `right` renders on the right on every chart type.
+- 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. `hide` and `startAtZero` are honored per entry (bar-series axes keep their zero baseline). 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.
## Testing
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
index 6c0628e12ccb..faf66633f345 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx
@@ -125,7 +125,7 @@ export function TimeSeriesBarChart<Meta = unknown>({
xTickFormatter,
yTickFormatter,
hideXAxis: xAxis?.hide,
- hideYAxis: primaryYAxis?.hide,
+ hideYAxis: yAxes ? yAxes.length > 0 && yAxes.every((a) => a.hide) : primaryYAxis?.hide,
xAxisLabel: xAxis?.label,
yAxisLabel: primaryYAxis?.label,
showGrid: primaryYAxis?.showGrid ?? showGrid,
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
index 55b4168ed12f..c47d2fd2c285 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx
@@ -121,7 +121,7 @@ export function TimeSeriesComboChart<Meta = unknown>({
xTickFormatter,
yTickFormatter,
hideXAxis: xAxis?.hide,
- hideYAxis: primaryYAxis?.hide,
+ hideYAxis: yAxes ? yAxes.length > 0 && yAxes.every((a) => a.hide) : primaryYAxis?.hide,
xAxisLabel: xAxis?.label,
yAxisLabel: primaryYAxis?.label,
showGrid: primaryYAxis?.showGrid ?? showGrid,
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
index 8daa8c4cb7db..232936af4902 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
@@ -205,6 +205,26 @@ describe('TimeSeriesLineChart', () => {
expect(chart.yRightTicks().length).toBeGreaterThan(0)
})
+ it('hides only the right axis when its entry sets hide, keeping the left axis', () => {
+ const yAxis = [{ id: 'left' }, { id: 'right', position: 'right' as const, hide: true }]
+ const { chart } = renderHogChart(
+ <TimeSeriesLineChart series={LEFT_RIGHT_SERIES} labels={LABELS} theme={THEME} config={{ yAxis }} />
+ )
+ expect(chart.yTicks().length).toBeGreaterThan(0)
+ expect(chart.yRightTicks()).toHaveLength(0)
+ })
+
+ it('collapses the y-axis gutter only when every entry sets hide', () => {
+ const yAxis = [
+ { id: 'left', hide: true },
+ { id: 'right', position: 'right' as const, hide: true },
+ ]
+ const { chart } = renderHogChart(
+ <TimeSeriesLineChart series={LEFT_RIGHT_SERIES} labels={LABELS} theme={THEME} config={{ yAxis }} />
+ )
+ expect(chart.yTicks()).toHaveLength(0)
+ })
+
it('formats each axis with its own tick formatter', () => {
const { chart } = renderHogChart(
<TimeSeriesLineChart
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
index 79cf1db98099..a081bc596636 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
@@ -137,7 +137,8 @@ export function TimeSeriesLineChart<Meta = unknown>({
xTickFormatter,
yTickFormatter,
hideXAxis: xAxis?.hide,
- hideYAxis: primaryYAxis?.hide,
+ // Multi-axis: each axis hides its own gutter; collapse globally only when all are hidden.
+ hideYAxis: yAxes ? yAxes.length > 0 && yAxes.every((a) => a.hide) : primaryYAxis?.hide,
xAxisLabel: xAxis?.label,
yAxisLabel: primaryYAxis?.label,
showGrid: primaryYAxis?.showGrid ?? showGrid,
diff --git a/packages/quill/packages/charts/src/core/Chart.tsx b/packages/quill/packages/charts/src/core/Chart.tsx
index fcbae8d5e072..e1bc012be282 100644
--- a/packages/quill/packages/charts/src/core/Chart.tsx
+++ b/packages/quill/packages/charts/src/core/Chart.tsx
@@ -153,6 +153,7 @@ export function Chart<Meta = unknown>({
formatters: yAxisFormatters,
positions: yAxisPositions,
titles: yAxisTitles,
+ hidden: yAxisHidden,
} = useYAxisMaps(yAxes, yAxisLabel)
const hoverAnimationMs = resolveHoverAnimationMs(animateHover)
const interactionAxis: 'x' | 'y' = axisOrientation === 'horizontal' ? 'y' : 'x'
@@ -210,6 +211,7 @@ export function Chart<Meta = unknown>({
yAxisFormatters,
yAxisPositions,
yAxisTitles,
+ yAxisHidden,
})
const { canvasRef, overlayCanvasRef, wrapperRef, dimensions, ctx, overlayCtx } = useChartCanvas({ margins })
@@ -236,8 +238,18 @@ export function Chart<Meta = unknown>({
userYTickFormatter: yTickFormatter,
yAxisFormatters,
titles: yAxisTitles,
+ hiddenAxes: yAxisHidden,
}),
- [scales, hideYAxis, axisOrientation, resolvedYFormatter, yTickFormatter, yAxisFormatters, yAxisTitles]
+ [
+ scales,
+ hideYAxis,
+ axisOrientation,
+ resolvedYFormatter,
+ yTickFormatter,
+ yAxisFormatters,
+ yAxisTitles,
+ yAxisHidden,
+ ]
)
// Mirrors AxisLabels' visible-label computation (same pure helpers, same inputs) so every tick
@@ -330,7 +342,14 @@ export function Chart<Meta = unknown>({
labelToCoord,
})
return composeDrawHoverWithSelection(withCrosshair)
- }, [showCrosshair, theme.crosshairColor, theme.crosshairDashPattern, axisOrientation, labelToCoord, drawHoverRef.current])
+ }, [
+ showCrosshair,
+ theme.crosshairColor,
+ theme.crosshairDashPattern,
+ axisOrientation,
+ labelToCoord,
+ drawHoverRef.current,
+ ])
useChartDraw({
ctx,
diff --git a/packages/quill/packages/charts/src/core/combo-scales.test.ts b/packages/quill/packages/charts/src/core/combo-scales.test.ts
index 6ad9e1d3d1ec..f2c65230ca98 100644
--- a/packages/quill/packages/charts/src/core/combo-scales.test.ts
+++ b/packages/quill/packages/charts/src/core/combo-scales.test.ts
@@ -162,6 +162,20 @@ describe('combo-scales', () => {
expect(scales.yAxes.right.position).toBe('right')
})
+ it('floats a line-only axis with startAtZero false but keeps bar axes on a zero baseline', () => {
+ const bar = makeSeries({ key: 'bar', data: [800, 1000], type: 'bar' })
+ const line = makeSeries({ key: 'line', data: [800, 1000], type: 'line', yAxisId: 'right' })
+ const scales = createComboScales([bar, line], ['a', 'b'], dimensions, {
+ seriesTypeOf: typeOfWithDefault('line'),
+ axes: [
+ { id: DEFAULT_Y_AXIS_ID, position: 'left', startAtZero: false },
+ { id: 'right', position: 'right', startAtZero: false },
+ ],
+ })
+ expect(scales.yAxes[DEFAULT_Y_AXIS_ID].scale.domain()[0]).toBe(0)
+ expect(scales.yAxes.right.scale.domain()[0]).toBeGreaterThan(0)
+ })
+
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.ts
index 10c156538482..295c99b97f29 100644
--- a/packages/quill/packages/charts/src/core/combo-scales.ts
+++ b/packages/quill/packages/charts/src/core/combo-scales.ts
@@ -39,8 +39,9 @@ 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' }[]
+ /** Per-axis overrides — explicit values win over the alternating-side default and
+ * `options.scaleType`. `startAtZero: false` is ignored for axes carrying bar series. */
+ axes?: { id: string; position?: 'left' | 'right'; scaleType?: 'linear' | 'log'; startAtZero?: boolean }[]
}
export function resolveSeriesType(series: Pick<Series, 'type'>, defaultType: SeriesType): SeriesType {
@@ -113,10 +114,12 @@ export function createComboScales(
// Percent-clamp only axes that actually carry bar series — a line/area-only axis (e.g. a
// series explicitly routed to the right axis) keeps its own data-derived scale instead of
// being forced onto [0, 1].
+ const hasBarSeries = axisSeries.some((s) => seriesTypeOf(s) === 'bar')
const scale = createYScale(axisValueSeries, dimensions, {
scaleType: axisOverrides.get(axisId)?.scaleType ?? scaleType,
- percentStack: barLayout === 'percent' && axisSeries.some((s) => seriesTypeOf(s) === 'bar'),
+ percentStack: barLayout === 'percent' && hasBarSeries,
valueDomain: axisId === primaryAxisId ? valueDomain : undefined,
+ floatBaseline: !hasBarSeries && axisOverrides.get(axisId)?.startAtZero === false,
})
yAxes[axisId] = { scale, position }
}
diff --git a/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts b/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts
index 37cd0ba3c7d0..fdfc24fa6ab9 100644
--- a/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts
+++ b/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts
@@ -49,6 +49,8 @@ interface UseChartMarginsOptions {
* reservation in step with the scales' config-driven positions. Multi-axis charts only. */
yAxisPositions?: Record<string, 'left' | 'right'>
yAxisTitles?: Record<string, string>
+ /** Axis ids whose gutters are hidden — no margin reserved. Mirrors `computeYAxisGutters`. */
+ yAxisHidden?: Record<string, boolean>
}
function widestCategoryLabelWidth(
@@ -100,6 +102,7 @@ export function useChartMargins({
yAxisFormatters,
yAxisPositions,
yAxisTitles,
+ yAxisHidden,
}: UseChartMarginsOptions): ChartMargins {
const isHorizontal = axisOrientation === 'horizontal'
const valueSeries = valueRangeSeries ?? series
@@ -131,7 +134,7 @@ export function useChartMargins({
let left = 0
let right = 0
for (const { axisId, position } of orderedAxisPositions(valueSeries)) {
- if (!yAxisTitles[axisId]) {
+ if (!yAxisTitles[axisId] || yAxisHidden?.[axisId]) {
continue
}
if ((yAxisPositions?.[axisId] ?? position) === 'left') {
@@ -141,7 +144,7 @@ export function useChartMargins({
}
}
return { left, right }
- }, [hideYAxis, isHorizontal, usesPerSideGutters, valueSeries, yAxisPositions, yAxisTitles])
+ }, [hideYAxis, isHorizontal, usesPerSideGutters, valueSeries, yAxisPositions, yAxisTitles, yAxisHidden])
const yLabelWidth = useMemo<number>(() => {
if (hideYAxis) {
@@ -189,6 +192,9 @@ export function useChartMargins({
let left = 0
let right = 0
for (const { axisId, position } of orderedAxisPositions(valueSeries)) {
+ if (yAxisHidden?.[axisId]) {
+ continue
+ }
const formatter = yAxisFormatters?.[axisId] ?? yTickFormatter
const side = yAxisPositions?.[axisId] ?? position
const width = Math.ceil(widestValueLabelWidth(byAxis.get(axisId) ?? [], formatter)) + Y_LABEL_RIGHT_PADDING
@@ -199,7 +205,16 @@ export function useChartMargins({
}
}
return { left, right }
- }, [hideYAxis, isHorizontal, usesPerSideGutters, valueSeries, yTickFormatter, yAxisFormatters, yAxisPositions])
+ }, [
+ hideYAxis,
+ isHorizontal,
+ usesPerSideGutters,
+ valueSeries,
+ yTickFormatter,
+ yAxisFormatters,
+ yAxisPositions,
+ yAxisHidden,
+ ])
return useMemo<ChartMargins>(() => {
const bottom = hideXAxis
diff --git a/packages/quill/packages/charts/src/core/hooks/useYAxisMaps.ts b/packages/quill/packages/charts/src/core/hooks/useYAxisMaps.ts
index d1714da261a7..8ba14b9a08d4 100644
--- a/packages/quill/packages/charts/src/core/hooks/useYAxisMaps.ts
+++ b/packages/quill/packages/charts/src/core/hooks/useYAxisMaps.ts
@@ -11,6 +11,8 @@ export interface YAxisMaps {
positions?: Record<string, 'left' | 'right'>
/** Per-axis titles keyed by axis id; single-axis charts fall back to the scalar `yAxisLabel`. */
titles: Record<string, string>
+ /** Axis ids whose tick labels (and margin gutters) are hidden. Absent when no axis hides. */
+ hidden?: Record<string, boolean>
}
/** Per-axis tick formatters, sides, and titles keyed by axis id (formatters/sides are absent for
@@ -28,6 +30,7 @@ export function useYAxisMaps(yAxes: YAxis[] | undefined, yAxisLabel?: string): Y
const formatters: Record<string, (value: number) => string> = {}
const positions: Record<string, 'left' | 'right'> = {}
const titles: Record<string, string> = {}
+ const hidden: Record<string, boolean> = {}
for (const axis of yAxes) {
if (axis.tickFormatter) {
formatters[axis.id] = axis.tickFormatter
@@ -37,11 +40,15 @@ export function useYAxisMaps(yAxes: YAxis[] | undefined, yAxisLabel?: string): Y
if (label) {
titles[axis.id] = label
}
+ if (axis.hide) {
+ hidden[axis.id] = true
+ }
}
return {
formatters: Object.keys(formatters).length > 0 ? formatters : undefined,
positions,
titles,
+ hidden: Object.keys(hidden).length > 0 ? hidden : undefined,
}
}, [yAxes, yAxisLabel])
}
diff --git a/packages/quill/packages/charts/src/core/scales.test.ts b/packages/quill/packages/charts/src/core/scales.test.ts
index 613356963f05..d7718434668f 100644
--- a/packages/quill/packages/charts/src/core/scales.test.ts
+++ b/packages/quill/packages/charts/src/core/scales.test.ts
@@ -408,6 +408,19 @@ describe('hog-charts scales', () => {
expect(result.yAxes!.y1.scale.domain()[1]).toBeLessThan(1000)
})
+ it('floats an axis to its data range when its axes entry sets startAtZero false', () => {
+ const left = makeSeries({ key: 'left', data: [800, 1000], yAxisId: DEFAULT_Y_AXIS_ID })
+ const right = makeSeries({ key: 'right', data: [800, 1000], yAxisId: 'y1' })
+ const result = createScales([left, right], ['a', 'b'], dimensions, {
+ axes: [
+ { id: DEFAULT_Y_AXIS_ID, position: 'left' },
+ { id: 'y1', position: 'right', startAtZero: false },
+ ],
+ })
+ expect(result.yAxes![DEFAULT_Y_AXIS_ID].scale.domain()[0]).toBe(0)
+ expect(result.yAxes!.y1.scale.domain()[0]).toBeGreaterThan(0)
+ })
+
it('applies a per-axis scaleType from options.axes to that axis only', () => {
const left = makeSeries({ key: 'left', data: [1, 1000], yAxisId: DEFAULT_Y_AXIS_ID })
const right = makeSeries({ key: 'right', data: [1, 1000], yAxisId: 'y1' })
diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.ts
index 60746115c3d2..50791c2da4ab 100644
--- a/packages/quill/packages/charts/src/core/scales.ts
+++ b/packages/quill/packages/charts/src/core/scales.ts
@@ -325,10 +325,9 @@ export function createScales(
/** Applied to the primary y-axis only — goal lines (`{ include }`) render against the
* primary axis, so secondary axes keep their own data-derived scale. */
valueDomain?: ValueDomain
- /** Per-axis overrides keyed by axis id. When an axis is listed its `scaleType` and
- * `position` win; otherwise it falls back to `options.scaleType` and the alternating-side
- * default from {@link orderedAxisPositions}. */
- axes?: { id: string; position?: 'left' | 'right'; scaleType?: 'linear' | 'log' }[]
+ /** Per-axis overrides — explicit values win over the alternating-side default and the
+ * scalar `scaleType`/`floatBaseline` options (which only reach the primary axis). */
+ axes?: { id: string; position?: 'left' | 'right'; scaleType?: 'linear' | 'log'; startAtZero?: boolean }[]
/** Float the primary axis to its data range instead of clamping the baseline to 0. Applied to
* the primary axis only, like `valueDomain`. See {@link buildValueScale}. */
floatBaseline?: boolean
@@ -363,7 +362,12 @@ export function createScales(
scaleType: override?.scaleType ?? options.scaleType,
percentStack: options.percentStack,
valueDomain: axisIndex === 0 ? options.valueDomain : undefined,
- floatBaseline: axisIndex === 0 ? options.floatBaseline : undefined,
+ floatBaseline:
+ override?.startAtZero != null
+ ? override.startAtZero === false
+ : axisIndex === 0
+ ? options.floatBaseline
+ : undefined,
})
yAxes[axisId] = { scale, position: override?.position ?? position }
})
diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.ts
index 822d54ac23dc..ea48e5e001ce 100644
--- a/packages/quill/packages/charts/src/core/types.ts
+++ b/packages/quill/packages/charts/src/core/types.ts
@@ -301,6 +301,10 @@ export interface YAxis {
tickFormatter?: (value: number) => string
/** Axis title. */
label?: string
+ /** Hide this axis's tick labels and margin gutter. The scale still applies to its series. */
+ hide?: boolean
+ /** `false` floats this axis to its data range instead of clamping a non-negative domain to 0. */
+ startAtZero?: boolean
}
/** Built-in legend config for the multi-series charts. The chart renders a {@link Legend} and,
diff --git a/packages/quill/packages/charts/src/core/y-axis-gutters.test.ts b/packages/quill/packages/charts/src/core/y-axis-gutters.test.ts
index 74cebd539260..e4ad24381352 100644
--- a/packages/quill/packages/charts/src/core/y-axis-gutters.test.ts
+++ b/packages/quill/packages/charts/src/core/y-axis-gutters.test.ts
@@ -22,10 +22,13 @@ describe('computeYAxisGutters', () => {
})
it('stacks same-side gutters outward, each offset by the inner gutters width plus the gap', () => {
- const gutters = computeYAxisGutters(scales({ left: axis('left'), right: axis('right'), right2: axis('right') }), {
- yTicks: [],
- yAxisFormatters: formatters,
- })
+ const gutters = computeYAxisGutters(
+ scales({ left: axis('left'), right: axis('right'), right2: axis('right') }),
+ {
+ yTicks: [],
+ yAxisFormatters: formatters,
+ }
+ )
const right = gutters.find((g) => g.axisId === 'right')
const right2 = gutters.find((g) => g.axisId === 'right2')
expect(right).toMatchObject({ offset: 0, width: 20 })
@@ -33,13 +36,30 @@ describe('computeYAxisGutters', () => {
})
it('reserves a title band that pushes the next same-side gutter out', () => {
- const gutters = computeYAxisGutters(scales({ left: axis('left'), right: axis('right'), right2: axis('right') }), {
- yTicks: [],
- yAxisFormatters: formatters,
- titles: { right: 'Inner title' },
- })
+ const gutters = computeYAxisGutters(
+ scales({ left: axis('left'), right: axis('right'), right2: axis('right') }),
+ {
+ yTicks: [],
+ yAxisFormatters: formatters,
+ titles: { right: 'Inner title' },
+ }
+ )
const right2 = gutters.find((g) => g.axisId === 'right2')
expect(right2?.offset).toBe(20 + GUTTER_GAP + Y_AXIS_TITLE_MARGIN)
expect(gutters.find((g) => g.axisId === 'right')?.title).toBe('Inner title')
})
+
+ it('skips hidden axes entirely, so the next same-side gutter takes their slot', () => {
+ const gutters = computeYAxisGutters(
+ scales({ left: axis('left'), right: axis('right'), right2: axis('right') }),
+ {
+ yTicks: [],
+ yAxisFormatters: formatters,
+ hiddenAxes: { right: true },
+ }
+ )
+ expect(gutters.map((g) => g.axisId)).toEqual(['left', 'right2'])
+ const right2 = gutters.find((g) => g.axisId === 'right2')
+ expect(right2).toMatchObject({ offset: 0 })
+ })
})
diff --git a/packages/quill/packages/charts/src/core/y-axis-gutters.ts b/packages/quill/packages/charts/src/core/y-axis-gutters.ts
index f6977ba50510..13e6c10c99fc 100644
--- a/packages/quill/packages/charts/src/core/y-axis-gutters.ts
+++ b/packages/quill/packages/charts/src/core/y-axis-gutters.ts
@@ -27,6 +27,8 @@ export interface YAxisGutterOptions {
userYTickFormatter?: (value: number) => string
yAxisFormatters?: Record<string, (value: number) => string>
titles?: Record<string, string>
+ /** Axis ids to skip entirely — no ticks, no title, no gutter step. Multi-axis path only. */
+ hiddenAxes?: Record<string, boolean>
}
/** Gap from the plot edge to a gutter's tick labels — shared by AxisLabels and AxisTitles. */
@@ -41,7 +43,7 @@ function widestTickWidth(ticks: number[], formatter: (value: number) => string):
* `AxisTitles` (titles) so the two can't drift. */
export function computeYAxisGutters(
scales: ChartScales,
- { yTicks, yTickFormatter, userYTickFormatter, yAxisFormatters, titles }: YAxisGutterOptions
+ { yTicks, yTickFormatter, userYTickFormatter, yAxisFormatters, titles, hiddenAxes }: YAxisGutterOptions
): Gutter[] {
if (!scales.yAxes) {
const formatter = yTickFormatter ?? autoFormatterFor(yTicks)
@@ -63,6 +65,9 @@ export function computeYAxisGutters(
let rightCum = 0
const gutters: Gutter[] = []
for (const [axisId, axis] of Object.entries(scales.yAxes)) {
+ if (hiddenAxes?.[axisId]) {
+ continue
+ }
const ticks = axis.ticks()
const formatter = yAxisFormatters?.[axisId] ?? userYTickFormatter ?? autoFormatterFor(ticks)
const offset = axis.position === 'left' ? leftCum : rightCum
diff --git a/packages/quill/packages/charts/src/utils/use-axis-formatters.ts b/packages/quill/packages/charts/src/utils/use-axis-formatters.ts
index 8cf116ffb72b..a24c61742b56 100644
--- a/packages/quill/packages/charts/src/utils/use-axis-formatters.ts
+++ b/packages/quill/packages/charts/src/utils/use-axis-formatters.ts
@@ -32,7 +32,8 @@ export interface YAxisConfig extends YFormatterConfig {
showGrid?: boolean
/** Y-axis baseline behavior. The default (`undefined`/`true`) clamps a non-negative axis down to
* 0. Set `false` to float the axis to its data range instead (zoom in on the variation). Ignored
- * on a log scale, and only honored for the primary axis in the array (multi-axis) form. */
+ * on a log scale; honored per axis in the array (multi-axis) form, except axes carrying bar
+ * series, which always draw from 0. */
startAtZero?: boolean
}
@@ -132,6 +133,8 @@ export function buildYAxes(axisList: NormalizedYAxis[]): YAxis[] {
scaleType: config.scale,
tickFormatter: resolveYTickFormatter(config),
label: config.label,
+ hide: config.hide,
+ startAtZero: config.startAtZero,
}))
}