: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(quill-charts): canvas tick marks and axis-line coexistence (#67990)
Sam Pennington1af2858095bc
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.mdindex 6233bc117bfd..e5a5084845ae 100644--- a/packages/quill/packages/charts/AGENTS.md+++ b/packages/quill/packages/charts/AGENTS.md@@ -30,6 +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`). Config side: `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.- `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)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 1276fb297084..52fd6a3fb707 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@@ -11,6 +11,7 @@ import {drawBars,drawBarTracks,drawGrid,+ resolveAxisLineColor,type DrawContext,} from '../../../core/canvas-renderer'import { barColorAt } from '../../../core/color-utils'@@ -118,14 +119,17 @@ export function drawBarChartStatic(labels: drawLabels,}+ // 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.if (showGrid) {drawGrid(baseDrawCtx, {gridColor: theme.gridColor,+ frame: !showAxisLines,orientation: isHorizontal ? 'horizontal' : 'vertical',- categoryTicks: computeGridTicks(d3Scales, drawLabels, isHorizontal, xTickFormatter),+ // 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),})- } else if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: theme.gridColor })}const seriesBars = buildBarLayers({@@ -174,6 +178,10 @@ export function drawBarChartStatic(ctx.restore()}})++ if (showAxisLines) {+ drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ }}export interface DrawBarHoverArgs {diff --git a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsxindex 8eeaa04828d8..0373d169ebd3 100644--- a/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx+++ b/packages/quill/packages/charts/src/charts/ComboChart/ComboChart.tsx@@ -7,6 +7,7 @@ import {DEFAULT_BAR_CORNER_RADIUS,LINE_STROKE_WIDTH,drawAxes,+ resolveAxisLineColor,drawBarHighlight,drawBars,drawGrid,@@ -184,15 +185,17 @@ function ComboChartInner<Meta = unknown>({labels: drawLabels,}+ // 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.if (showGrid) {- const categoryTicks = computeVisibleXLabels(- drawLabels,- (label) => bandCenter(comboScales, label),- xTickFormatter- ).map((entry) => entry.x)- drawGrid(baseDrawCtx, { gridColor: theme.gridColor, categoryTicks })- } else if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: theme.gridColor })+ // 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+ ? []+ : computeVisibleXLabels(drawLabels, (label) => bandCenter(comboScales, label), xTickFormatter).map(+ (entry) => entry.x+ )+ drawGrid(baseDrawCtx, { gridColor: theme.gridColor, frame: !showAxisLines, categoryTicks })}// ── 1. Bars ──────────────────────────────────────────────────────────────────────@@ -232,6 +235,10 @@ function ComboChartInner<Meta = unknown>({: undefined,clipLeftEdge: showAxisLines,})++ if (showAxisLines) {+ drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ }},[seriesTypeOf,diff --git a/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx b/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsxindex 88b17ba7db1d..83b25611ad01 100644--- a/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx+++ b/packages/quill/packages/charts/src/charts/LineChart/LineChart.tsx@@ -8,6 +8,7 @@ import {drawGrid,drawLineHoverPoints,drawLineSeriesLayer,+ resolveAxisLineColor,} from '../../core/canvas-renderer'import type { DrawContext } from '../../core/canvas-renderer'import { Chart } from '../../core/Chart'@@ -185,10 +186,10 @@ function LineChartInner<Meta = unknown>({labels: drawLabels,}+ // 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.if (showGrid) {- drawGrid(baseDrawCtx, { gridColor: theme.gridColor })- } else if (showAxisLines) {- drawAxes(baseDrawCtx, { axisColor: theme.gridColor })+ drawGrid(baseDrawCtx, { gridColor: theme.gridColor, frame: !showAxisLines })}// Area then line+points per series, clipped vertically (shared with ComboChart). Areas use@@ -212,6 +213,10 @@ function LineChartInner<Meta = unknown>({: undefined,clipLeftEdge: showAxisLines,})++ if (showAxisLines) {+ drawAxes(baseDrawCtx, { axisColor: resolveAxisLineColor(theme) })+ }},[showGrid, showAxisLines, stackedData, smooth])diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsxindex cdc55c89c33e..d61d239c6ffc 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx@@ -37,6 +37,8 @@ export interface TimeSeriesBarChartConfig {showCrosshair?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */showAxisLines?: boolean+ /** 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. */tooltip?: TooltipConfig/** Stacked layout only — stack negatives below the zero baseline (d3.stackOffsetDiverging). */@@ -86,6 +88,7 @@ export function TimeSeriesBarChart<Meta = unknown>({barCornerRadius,showCrosshair,showAxisLines,+ showTickMarks,tooltip: tooltipConfig,divergingStack,fillStyle,@@ -121,6 +124,7 @@ export function TimeSeriesBarChart<Meta = unknown>({yAxisLabel: primaryYAxis?.label,showGrid: primaryYAxis?.showGrid,showAxisLines,+ showTickMarks,barLayout,axisOrientation,showCrosshair,diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsxindex e4df2160ed89..70df1327b971 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesComboChart/TimeSeriesComboChart.tsx@@ -38,6 +38,8 @@ export interface TimeSeriesComboChartConfig {showCrosshair?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */showAxisLines?: boolean+ /** 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). */curve?: 'linear' | 'monotone'/** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */@@ -86,6 +88,7 @@ export function TimeSeriesComboChart<Meta = unknown>({barCornerRadius,showCrosshair,showAxisLines,+ showTickMarks,curve,tooltip: tooltipConfig,legend,@@ -117,6 +120,7 @@ export function TimeSeriesComboChart<Meta = unknown>({yAxisLabel: primaryYAxis?.label,showGrid: primaryYAxis?.showGrid,showAxisLines,+ showTickMarks,curve,showCrosshair,defaultSeriesType,diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsxindex d5cc121f7d22..c8ef8d170fc0 100644--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx@@ -47,6 +47,8 @@ export interface TimeSeriesLineChartConfig {showCrosshair?: boolean/** Draw L-shaped axis baselines without grid lines (ignored when `yAxis.showGrid` is true). */showAxisLines?: boolean+ /** 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). */curve?: 'linear' | 'monotone'/** Tooltip behaviour (pinning, placement). Tooltip *content* is the `tooltip` render prop. */@@ -94,6 +96,7 @@ export function TimeSeriesLineChart<Meta = unknown>({percentStackView,showCrosshair,showAxisLines,+ showTickMarks,curve,tooltip: tooltipConfig,legend,@@ -133,6 +136,7 @@ export function TimeSeriesLineChart<Meta = unknown>({yAxisLabel: primaryYAxis?.label,showGrid: primaryYAxis?.showGrid,showAxisLines,+ showTickMarks,curve,percentStackView,showCrosshair,diff --git a/packages/quill/packages/charts/src/core/Chart.tsx b/packages/quill/packages/charts/src/core/Chart.tsxindex 87a24e41e385..a4d0656d8c22 100644--- a/packages/quill/packages/charts/src/core/Chart.tsx+++ b/packages/quill/packages/charts/src/core/Chart.tsx@@ -1,11 +1,22 @@import React, { useMemo } from 'react'-import { AxisLabels } from '../overlays/AxisLabels'+import {+ AxisLabels,+ computeVisibleValueTicks,+ computeVisibleXLabels,+ computeVisibleYTicks,+} from '../overlays/AxisLabels'import { AxisTitles } from '../overlays/AxisTitles'import { DefaultTooltip } from '../overlays/DefaultTooltip'import { Tooltip } from '../overlays/Tooltip'import { normalizeAxisLabel } from '../utils/axis-labels'-import { composeDrawHoverWithCrosshair, composeDrawHoverWithSelection } from './canvas-renderer'+import {+ composeDrawHoverWithCrosshair,+ composeDrawHoverWithSelection,+ drawTickMarks,+ resolveAxisLineColor,+ type TickMarkCoords,+} from './canvas-renderer'import { ChartHoverContext, ChartLayoutContext } from './chart-context'import type { ChartHoverContextValue, ChartLayoutContextValue } from './chart-context'import { ChartShell, countVisibleSeries, useCanvasBounds, useColoredSeries } from './chart-shell'@@ -124,6 +135,7 @@ export function Chart<Meta = unknown>({yAxisLabel,tooltip: tooltipConfig,showCrosshair = false,+ showTickMarks = false,axisOrientation = 'vertical',isPercent = false,animateHover,@@ -208,6 +220,79 @@ export function Chart<Meta = unknown>({const resolvedYFormatter = useResolvedYFormatter(scales, yTickFormatter)+ // Computed once and shared with AxisLabels and AxisTitles via context so they can't drift.+ const yGutters = useMemo<Gutter[]>(+ () =>+ !scales || hideYAxis || axisOrientation === 'horizontal'+ ? []+ : computeYAxisGutters(scales, {+ yTicks: scales.yTicks(),+ yTickFormatter: resolvedYFormatter,+ userYTickFormatter: yTickFormatter,+ yAxisFormatters,+ titles: yAxisTitles,+ }),+ [scales, hideYAxis, axisOrientation, resolvedYFormatter, yTickFormatter, yAxisFormatters, yAxisTitles]+ )++ // Mirrors AxisLabels' visible-label computation (same pure helpers, same inputs) so every tick+ // mark sits next to a rendered label. Drawn on canvas rather than as DOM overlays so ticks share+ // the axis/grid stroke snapping and can't drift a pixel against those lines.+ const tickMarkCoords = useMemo<TickMarkCoords | null>(() => {+ if (!showTickMarks || !scales || !dimensions) {+ return null+ }+ if (axisOrientation === 'horizontal') {+ const labelToY = labelToCoord ?? scales.x+ const ys = hideYAxis+ ? []+ : labels+ .filter((label, i) => !xTickFormatter || xTickFormatter(label, i) !== null)+ .map((label) => labelToY(label))+ .filter((y): y is number => y != null && isFinite(y))+ .map((y) => ({ y, side: 'left' as const, offset: 0 }))+ const xs = hideXAxis+ ? []+ : computeVisibleValueTicks(scales.yTicks(), scales.y, resolvedYFormatter).map((t) => t.x)+ return { xs, ys }+ }+ const xs = hideXAxis+ ? []+ : computeVisibleXLabels(labels, scales.x, xTickFormatter, maxCategoryLabelWidth).map((l) => l.x)+ const ys = yGutters.flatMap((gutter) =>+ computeVisibleYTicks(gutter.ticks, gutter.scale)+ .map((tick) => gutter.scale(tick))+ .filter((y) => isFinite(y))+ .map((y) => ({ y, side: gutter.side, offset: gutter.offset }))+ )+ return { xs, ys }+ }, [+ showTickMarks,+ scales,+ dimensions,+ axisOrientation,+ labels,+ xTickFormatter,+ maxCategoryLabelWidth,+ yGutters,+ hideXAxis,+ hideYAxis,+ resolvedYFormatter,+ labelToCoord,+ ])++ const drawStaticWithTicks = useMemo(() => {+ if (!tickMarkCoords) {+ return drawStatic+ }+ // Shared with the chart types' drawAxes calls, so ticks match their axis line.+ const tickColor = resolveAxisLineColor(theme)+ return (args: ChartDrawArgs): void => {+ drawStatic(args)+ drawTickMarks(args.ctx, args.dimensions, tickMarkCoords, tickColor)+ }+ }, [drawStatic, tickMarkCoords, theme])+const { hoverIndex, hoverPosition, tooltipCtx, dragRect, handlers } = useChartInteraction<Meta>({scales,dimensions,@@ -251,7 +336,7 @@ export function Chart<Meta = unknown>({hoverPosition,theme,dragRect,- drawStatic,+ drawStatic: drawStaticWithTicks,drawHover: composedDrawHover,hoverAnimationMs,})@@ -281,21 +366,6 @@ export function Chart<Meta = unknown>({)const axisColor = theme.axisColor ?? DEFAULT_AXIS_COLOR- // Computed once and shared with AxisLabels and AxisTitles via context so they can't drift.- const yGutters = useMemo<Gutter[]>(- () =>- !scales || hideYAxis || axisOrientation === 'horizontal'- ? []- : computeYAxisGutters(scales, {- yTicks: scales.yTicks(),- yTickFormatter: resolvedYFormatter,- userYTickFormatter: yTickFormatter,- yAxisFormatters,- titles: yAxisTitles,- }),- [scales, hideYAxis, axisOrientation, resolvedYFormatter, yTickFormatter, yAxisFormatters, yAxisTitles]- )-const layoutValue = useMemo<ChartLayoutContextValue | null>(() => {if (!scales || !dimensions) {return nulldiff --git a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts b/packages/quill/packages/charts/src/core/canvas-renderer.test.tsindex 5c65abf6ca9b..e219eb97948d 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.test.ts@@ -10,6 +10,8 @@ import {drawLine,drawLineSeriesLayer,drawSelectionRect,+ drawTickMarks,+ resolveAxisLineColor,} from './canvas-renderer'import type { ChartDrawArgs, ChartTheme } from './types'@@ -703,6 +705,94 @@ describe('hog-charts canvas-renderer', () => {})})+ describe('resolveAxisLineColor — precedence', () => {+ it.each([+ {+ name: 'returns axisLineColor when all three tiers are set',+ theme: { axisLineColor: '#111111', axisColor: '#222222', gridColor: '#333333' },+ expected: '#111111',+ },+ {+ name: 'falls back to axisColor when axisLineColor is absent',+ theme: { axisColor: '#222222', gridColor: '#333333' },+ expected: '#222222',+ },+ {+ name: 'falls back to gridColor when axisLineColor and axisColor are absent',+ theme: { gridColor: '#333333' },+ expected: '#333333',+ },+ {+ name: 'returns undefined when no tier is set',+ theme: {},+ expected: undefined,+ },+ ])('$name', ({ theme, expected }) => {+ expect(resolveAxisLineColor(theme as any)).toBe(expected)+ })+ })++ describe('drawTickMarks', () => {+ it('draws x ticks downward from the snapped baseline and y ticks outward from each side', () => {+ const ctx = mockCanvasContext()+ drawTickMarks(ctx, dimensions, {+ xs: [100.4],+ ys: [+ { y: 200.6, side: 'left', offset: 0 },+ { y: 120.2, side: 'right', offset: 10 },+ ],+ })+ const baselineY = Math.round(dimensions.plotTop + dimensions.plotHeight) + 0.5+ expect(ctx.moveTo).toHaveBeenCalledWith(100.5, baselineY)+ expect(ctx.lineTo).toHaveBeenCalledWith(100.5, baselineY + 4)+ const leftEdge = Math.round(dimensions.plotLeft) + 0.5+ expect(ctx.moveTo).toHaveBeenCalledWith(leftEdge - 4, 201.5)+ expect(ctx.lineTo).toHaveBeenCalledWith(leftEdge, 201.5)+ const rightEdge = Math.round(dimensions.plotLeft + dimensions.plotWidth + 10) + 0.5+ expect(ctx.moveTo).toHaveBeenCalledWith(rightEdge, 120.5)+ expect(ctx.lineTo).toHaveBeenCalledWith(rightEdge + 4, 120.5)+ })+ })++ describe('drawGrid — frame gating', () => {+ it('keeps the plot-edge frame strokes and the baseline gridline by default', () => {+ const ctx = mockCanvasContext()+ drawGrid(makeDrawContext(ctx, ['a', 'b']))+ const baselineY = Math.round(dimensions.plotTop + dimensions.plotHeight) + 0.5+ // The 0-value tick maps to the plot bottom; framed grids must keep drawing it.+ expect(ctx.moveTo.mock.calls.some(([, y]) => y === baselineY)).toBe(true)+ // Left frame stroke present.+ const leftX = Math.round(dimensions.plotLeft) + 0.5+ expect(ctx.moveTo.mock.calls.some(([x]) => x === leftX)).toBe(true)+ })++ 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()+ const drawCtx = makeDrawContext(ctx, ['a', 'b'])+ // Horizontal mode maps values to x; range starts at the plot's left edge, so the+ // 0 tick lands exactly on the value-axis baseline.+ 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)+ expect(drewBaselineTick).toBe(expectBaselineTick)+ }+ )++ it('skips the frame strokes and bottom-hugging gridline when frame is false', () => {+ const ctx = mockCanvasContext()+ drawGrid(makeDrawContext(ctx, ['a', 'b']), { frame: false })+ const baselineY = Math.round(dimensions.plotTop + dimensions.plotHeight) + 0.5+ // No stroke may run along the bottom edge — the chart's own axis line owns it.+ expect(ctx.moveTo.mock.calls.some(([, y]) => y === baselineY)).toBe(false)+ // And no right-edge closing stroke.+ const closingX = Math.round(dimensions.plotLeft + dimensions.plotWidth) + 0.5+ expect(ctx.moveTo.mock.calls.some(([x]) => x === closingX)).toBe(false)+ })+ })+describe('drawGrid', () => {it('draws a horizontal line at the first y-tick (vertical orientation)', () => {const ctx = mockCanvasContext()@@ -719,7 +809,7 @@ describe('hog-charts canvas-renderer', () => {const ctx = mockCanvasContext()drawGrid(makeDrawContext(ctx, ['a', 'b']))const leftX = dimensions.plotLeft + 0.5- const rightX = dimensions.plotLeft + dimensions.plotWidth - 0.5+ const rightX = dimensions.plotLeft + dimensions.plotWidth + 0.5expect(ctx.moveTo.mock.calls).toContainEqual([leftX, dimensions.plotTop])expect(ctx.lineTo.mock.calls).toContainEqual([leftX, dimensions.plotTop + dimensions.plotHeight])expect(ctx.moveTo.mock.calls).toContainEqual([rightX, dimensions.plotTop])@@ -746,7 +836,7 @@ describe('hog-charts canvas-renderer', () => {const ctx = mockCanvasContext()drawGrid(makeDrawContext(ctx, ['a', 'b']), { orientation: 'horizontal' })const topY = dimensions.plotTop + 0.5- const bottomY = dimensions.plotTop + dimensions.plotHeight - 0.5+ const bottomY = dimensions.plotTop + dimensions.plotHeight + 0.5expect(ctx.moveTo.mock.calls).toContainEqual([dimensions.plotLeft, topY])expect(ctx.lineTo.mock.calls).toContainEqual([dimensions.plotLeft + dimensions.plotWidth, topY])expect(ctx.moveTo.mock.calls).toContainEqual([dimensions.plotLeft, bottomY])diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.ts b/packages/quill/packages/charts/src/core/canvas-renderer.tsindex 5018ba785e03..39f682e140dc 100644--- a/packages/quill/packages/charts/src/core/canvas-renderer.ts+++ b/packages/quill/packages/charts/src/core/canvas-renderer.ts@@ -2,7 +2,7 @@ import { type ScaleLinear, type ScaleLogarithmic } from 'd3-scale'import { barColorAt, mixColors } from './color-utils'import { yTickCountForHeight } from './scales'-import type { BarFillStyle, BoxRect, ChartDimensions, ChartDrawArgs, DrawHoverResult, ResolvedSeries } from './types'+import type { BarFillStyle, BoxRect, ChartDimensions, ChartDrawArgs, ChartTheme, DrawHoverResult, ResolvedSeries } from './types'export interface DrawContext {ctx: CanvasRenderingContext2D@@ -583,6 +583,20 @@ export function drawPoints(drawCtx: DrawContext, series: ResolvedSeries, yValues}}+/** Snap a coordinate to the nearest half-pixel so a 1px stroke fills exactly one pixel row/column.+ * Every axis-adjacent stroke — grid lines, axis baselines, tick marks — must share this rule, or+ * they land one pixel apart and visibly misalign. */+function snapToPixel(coord: number): number {+ return Math.round(coord) + 0.5+}++/** The stroke color for axis lines and tick marks — separate from `axisColor` (tick-label text)+ * so hosts can mute the lines without muting the labels. One place, so the precedence can't+ * drift between call sites. */+export function resolveAxisLineColor(theme: ChartTheme): string | undefined {+ return theme.axisLineColor ?? theme.axisColor ?? theme.gridColor+}+export interface DrawAxesOptions {axisColor?: string}@@ -594,9 +608,10 @@ export function drawAxes(drawCtx: DrawContext, options: DrawAxesOptions = {}): vctx.strokeStyle = options.axisColor ?? 'rgba(0, 0, 0, 0.15)'ctx.lineWidth = 1ctx.setLineDash([])- // +0.5 / -0.5 pixel snapping keeps the 1px strokes crisp and inside the plot rect (see drawGrid).- const axisX = Math.round(dimensions.plotLeft) + 0.5- const axisY = Math.round(dimensions.plotTop + dimensions.plotHeight) - 0.5+ // snapToPixel matches drawGrid's tick snapping, so the bottom baseline coincides exactly with a+ // 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()@@ -609,8 +624,56 @@ export function drawAxes(drawCtx: DrawContext, options: DrawAxesOptions = {}): vctx.stroke()}+/** Length (px) of an axis tick mark, measured outward from the plot edge. */+export const TICK_MARK_LENGTH = 4++/** Pixel positions for canvas tick marks: `xs` tick below the plot's bottom edge, `ys` tick outside+ * the left or right plot edge (`offset` pushes stacked multi-axis gutters further outward). */+export interface TickMarkCoords {+ xs: number[]+ ys: { y: number; side: 'left' | 'right'; offset: number }[]+}++/** Draws short tick marks extending outward from the plot edges, one per visible axis label.+ * Canvas-drawn with the same snapping as `drawAxes`/`drawGrid` so each tick continues its+ * axis/grid line exactly — a DOM overlay can't guarantee that across subpixel rounding. */+export function drawTickMarks(+ ctx: CanvasRenderingContext2D,+ dimensions: ChartDimensions,+ coords: TickMarkCoords,+ color?: string+): void {+ ctx.strokeStyle = color ?? 'rgba(0, 0, 0, 0.15)'+ ctx.lineWidth = 1+ ctx.setLineDash([])+ const axisY = snapToPixel(dimensions.plotTop + dimensions.plotHeight)+ ctx.beginPath()+ for (const x of coords.xs) {+ const tickX = snapToPixel(x)+ ctx.moveTo(tickX, axisY)+ ctx.lineTo(tickX, axisY + TICK_MARK_LENGTH)+ }+ for (const { y, side, offset } of coords.ys) {+ const tickY = snapToPixel(y)+ if (side === 'left') {+ const edge = snapToPixel(dimensions.plotLeft - offset)+ ctx.moveTo(edge - TICK_MARK_LENGTH, tickY)+ ctx.lineTo(edge, tickY)+ } else {+ const edge = snapToPixel(dimensions.plotLeft + dimensions.plotWidth + offset)+ ctx.moveTo(edge, tickY)+ ctx.lineTo(edge + TICK_MARK_LENGTH, tickY)+ }+ }+ ctx.stroke()+}+export interface DrawGridOptions {gridColor?: string+ /** Draw the solid plot-edge baseline strokes framing the grid (both value-axis edges).+ * Defaults to true. Charts drawing their own axis lines pass false — the L-axis replaces the+ * near baseline, and the far one would read as a stray border. */+ frame?: booleanorientation?: 'vertical' | 'horizontal'/** Cross-axis grid line positions (x-pixels in vertical mode, y-pixels in horizontal). */categoryTicks?: number[]@@ -633,6 +696,7 @@ export function drawGrid(drawCtx: DrawContext, options: DrawGridOptions = {}): vconst categoryTicks = options.categoryTicks ?? []const valueTicks = (yScale as ScaleLinear<number, number>).ticks?.(yTickCountForHeight(tickAxisLength)) ?? []+ const frame = options.frame ?? truectx.strokeStyle = gridColorctx.lineWidth = 1@@ -645,7 +709,13 @@ export function drawGrid(drawCtx: DrawContext, options: DrawGridOptions = {}): vif (orientation === 'horizontal') {for (const tick of valueTicks) {- const x = Math.round(yScale(tick)) + 0.5+ const coord = yScale(tick)+ // In axis-line (frameless) mode, skip grid lines hugging the left edge — they'd double+ // up against the chart-drawn value-axis line. Framed grids keep their baseline gridline.+ if (!frame && coord - dimensions.plotLeft < AXIS_BASELINE_GAP) {+ continue+ }+ const x = snapToPixel(coord)ctx.beginPath()ctx.moveTo(x, dimensions.plotTop)ctx.lineTo(x, dimensions.plotTop + dimensions.plotHeight)@@ -655,29 +725,38 @@ export function drawGrid(drawCtx: DrawContext, options: DrawGridOptions = {}): vif (!isFinite(coord) || coord - dimensions.plotTop < AXIS_BASELINE_GAP) {continue}- const y = Math.round(coord) + 0.5+ const y = snapToPixel(coord)ctx.beginPath()ctx.moveTo(dimensions.plotLeft, y)ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, y)ctx.stroke()}- const axisY = Math.round(dimensions.plotTop) + 0.5- ctx.beginPath()- ctx.moveTo(dimensions.plotLeft, axisY)- ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, axisY)- ctx.stroke()- // Far-edge snap uses `- 0.5` (mirror of the `+ 0.5` near edge above) so the- // closing stroke lands just inside `plotTop + plotHeight` and stays within the plot rect.- const closingY = Math.round(dimensions.plotTop + dimensions.plotHeight) - 0.5- ctx.beginPath()- ctx.moveTo(dimensions.plotLeft, closingY)- ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, closingY)- ctx.stroke()+ if (frame) {+ const axisY = snapToPixel(dimensions.plotTop)+ ctx.beginPath()+ ctx.moveTo(dimensions.plotLeft, axisY)+ ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, axisY)+ ctx.stroke()+ // snapToPixel (Math.round + 0.5) matches the value-tick gridlines and drawAxes' baseline,+ // so a gridline or axis line at the plot bottom coincides exactly with this closing stroke+ // instead of landing 1px apart and doubling.+ const closingY = snapToPixel(dimensions.plotTop + dimensions.plotHeight)+ ctx.beginPath()+ ctx.moveTo(dimensions.plotLeft, closingY)+ ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, closingY)+ ctx.stroke()+ }return}for (const tick of valueTicks) {- const y = Math.round(yScale(tick)) + 0.5+ const coord = yScale(tick)+ // In axis-line (frameless) mode, skip grid lines hugging the bottom edge — they'd double+ // up against the chart-drawn x-axis line. Framed grids keep their baseline gridline.+ if (!frame && dimensions.plotTop + dimensions.plotHeight - coord < AXIS_BASELINE_GAP) {+ continue+ }+ const y = snapToPixel(coord)ctx.beginPath()ctx.moveTo(dimensions.plotLeft, y)ctx.lineTo(dimensions.plotLeft + dimensions.plotWidth, y)@@ -688,25 +767,28 @@ export function drawGrid(drawCtx: DrawContext, options: DrawGridOptions = {}): vif (!isFinite(coord) || coord - dimensions.plotLeft < AXIS_BASELINE_GAP) {continue}- const x = Math.round(coord) + 0.5+ const x = snapToPixel(coord)ctx.beginPath()ctx.moveTo(x, dimensions.plotTop)ctx.lineTo(x, dimensions.plotTop + dimensions.plotHeight)ctx.stroke()}- const axisX = Math.round(dimensions.plotLeft) + 0.5- ctx.beginPath()- ctx.moveTo(axisX, dimensions.plotTop)- ctx.lineTo(axisX, dimensions.plotTop + dimensions.plotHeight)- ctx.stroke()+ if (frame) {+ const axisX = snapToPixel(dimensions.plotLeft)+ ctx.beginPath()+ ctx.moveTo(axisX, dimensions.plotTop)+ ctx.lineTo(axisX, dimensions.plotTop + dimensions.plotHeight)+ ctx.stroke()- // See the horizontal-mode block for the `- 0.5` snap rationale (mirror of the near-edge `+ 0.5`).- const closingX = Math.round(dimensions.plotLeft + dimensions.plotWidth) - 0.5- ctx.beginPath()- ctx.moveTo(closingX, dimensions.plotTop)- ctx.lineTo(closingX, dimensions.plotTop + dimensions.plotHeight)- ctx.stroke()+ // snapToPixel keeps this closing stroke on the same half-pixel grid as the value/category+ // gridlines and drawAxes' baseline (see the horizontal-mode block), so coincident strokes align.+ const closingX = snapToPixel(dimensions.plotLeft + dimensions.plotWidth)+ ctx.beginPath()+ ctx.moveTo(closingX, dimensions.plotTop)+ ctx.lineTo(closingX, dimensions.plotTop + dimensions.plotHeight)+ ctx.stroke()+ }}export function drawCrosshair(diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.tsindex e3706a78a342..c7c808db6514 100644--- a/packages/quill/packages/charts/src/core/types.ts+++ b/packages/quill/packages/charts/src/core/types.ts@@ -7,6 +7,9 @@ export interface ChartTheme {colors: string[]backgroundColor?: stringaxisColor?: string+ /** Stroke color for the L-shaped axis baselines and tick marks. Falls back to `axisColor`,+ * then `gridColor` — set it to mute the lines without muting the tick label text. */+ axisLineColor?: stringgridColor?: stringcrosshairColor?: stringtooltipBackground?: string@@ -229,6 +232,9 @@ export interface ChartConfig {/** 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+ /** 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?: boolean/** Line/area interpolation. `linear` (default) draws straight segments; `monotone` smooths the* line with monotone-cubic curves that pass through every point without overshooting. */curve?: 'linear' | 'monotone'