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(charts): draw a dot for line chart points with no line through them (#121351)

Sam Pennington9c35059cbabe
diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.test.ts b/packages/quill/packages/charts/src/core/canvas-renderer.test.ts
index e9a57f746fbf..f0fb831f59e7 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,7 @@ import {
drawGrid,
drawLine,
drawLineSeriesLayer,
+ drawPoints,
drawSelectionRect,
drawTickMarks,
resolveAxisLineColor,
@@ -141,6 +142,39 @@ describe('hog-charts canvas-renderer', () => {
})
})
+ describe('drawPoints — isolated points', () => {
+ it.each([
+ { name: 'draws a dot for a single-value series', labels: ['a'], data: [10], radius: undefined, arcs: [3] },
+ {
+ name: 'draws no dots for a connected line',
+ labels: ['a', 'b'],
+ data: [10, 90],
+ radius: undefined,
+ arcs: [],
+ },
+ {
+ name: 'draws a dot for a point between two gaps',
+ labels: ['a', 'b', 'c'],
+ data: [50, 10, 50],
+ radius: undefined,
+ arcs: [3],
+ },
+ {
+ name: 'keeps an explicit radius on every point',
+ labels: ['a', 'b'],
+ data: [10, 90],
+ radius: 5,
+ arcs: [5, 5],
+ },
+ { name: 'draws no dot when the radius is explicitly zero', labels: ['a'], data: [10], radius: 0, arcs: [] },
+ ])('$name', ({ labels, data, radius, arcs }) => {
+ const ctx = mockCanvasContext()
+ const series = makeSeries({ key: 's1', data, points: radius === undefined ? undefined : { radius } })
+ drawPoints(makeDrawContextWithGaps(ctx, labels, new Set([50])), series)
+ expect(ctx.arc.mock.calls.map((call) => call[2])).toEqual(arcs)
+ })
+ })
+
describe('drawLine — monotone smoothing and yFloor', () => {
it('emits one bezier segment per point pair and no interior lineTo when smooth', () => {
const ctx = mockCanvasContext()
diff --git a/packages/quill/packages/charts/src/core/canvas-renderer.ts b/packages/quill/packages/charts/src/core/canvas-renderer.ts
index 1144474298f5..8dacf84e7173 100644
--- a/packages/quill/packages/charts/src/core/canvas-renderer.ts
+++ b/packages/quill/packages/charts/src/core/canvas-renderer.ts
@@ -31,6 +31,9 @@ export interface DrawContext {
* `yFloor`/left-clip callers use to keep strokes flush against drawn axis lines. */
export const LINE_STROKE_WIDTH = 2
+/** Dot radius for a point with no line through it, e.g. a series with one value. */
+const ISOLATED_POINT_RADIUS = 3
+
export function drawLine(drawCtx: DrawContext, series: ResolvedSeries, yValues?: number[]): void {
const data = yValues ?? series.data
if (data.length === 0) {
@@ -584,11 +587,9 @@ function fillAreaPath(ctx: CanvasRenderingContext2D, top: Point[], bottom: Point
export function drawPoints(drawCtx: DrawContext, series: ResolvedSeries, yValues?: number[]): void {
const { ctx, xScale, yScale, labels } = drawCtx
const data = yValues ?? series.data
- const radius = series.points?.radius ?? 0
-
- if (radius <= 0) {
- return
- }
+ const radius = series.points?.radius
+ const isDrawable = (i: number): boolean =>
+ i >= 0 && i < data.length && xScale(labels[i]) != null && isFinite(yScale(data[i]))
ctx.fillStyle = series.color
@@ -598,8 +599,13 @@ export function drawPoints(drawCtx: DrawContext, series: ResolvedSeries, yValues
if (x == null || !isFinite(y)) {
continue
}
+ // No line passes through a point without drawable neighbors, so it needs a dot to be visible.
+ const r = radius ?? (!isDrawable(i - 1) && !isDrawable(i + 1) ? ISOLATED_POINT_RADIUS : 0)
+ if (r <= 0) {
+ continue
+ }
ctx.beginPath()
- ctx.arc(x, y, radius, 0, Math.PI * 2)
+ ctx.arc(x, y, r, 0, Math.PI * 2)
ctx.fill()
}
}
diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.ts
index 2789b9a38d11..0812d50f2c0c 100644
--- a/packages/quill/packages/charts/src/core/types.ts
+++ b/packages/quill/packages/charts/src/core/types.ts
@@ -79,7 +79,7 @@ export interface Series<Meta = unknown> {
* Defaults to `unknown` so the library is meta-agnostic internally; adapters narrow it
* via `Series<MyMeta>` to get typed reads in their tooltip/click handlers. */
meta?: Meta
- /** Point markers configuration. Omit for no dots. */
+ /** Point markers configuration. Omit to dot only the points with no line through them. A radius of 0 hides every dot. */
points?: {
/** Radius in CSS pixels. */
radius: number