Sitelet https://github.com/chartjs/Chart.js/pull/12327
Skip to content

Declare and document all five Scale draw stages - #12327

Open
aron-intframe wants to merge 1 commit into
chartjs:masterfrom
aron-intframe:scale-draw-stages
Open

aron-intframe wants to merge 1 commit into
chartjs:masterfrom
aron-intframe:scale-draw-stages

Conversation

@aron-intframe

Copy link
Copy Markdown

Description

Scale#draw dispatches to five methods, one per part of the axis (drawBackground, drawGrid, drawBorder, drawTitle, drawLabels), and RadialLinearScale overrides all five. The Scale type declares only three, and gives drawTitle a chartArea parameter neither call site passes, so a TypeScript scale cannot reach the other two through super and super.drawTitle() does not compile:

error TS2339: Property 'drawBackground' does not exist on type 'Scale<O>'.
error TS2554: Expected 1 arguments, but got 0.

This declares all five and documents them in docs/developers/axes.md. That is the part of #3214 still open: #8598 split the drawing into these methods, but they were never written down as the supported way to customize one part of an axis.

Narrowing drawTitle(chartArea: ChartArea) to drawTitle() is a types-only break for anyone who declared that parameter, though it has always been undefined at runtime. Happy to use chartArea?: ChartArea instead.

User-Facing Changes

None at runtime. TypeScript scales can now override all five draw stages, and the docs list them.

Tests

test/types/extensions/scale.ts overrides the five stages through super: the errors above before, tsc -p test/types clean after. A new Core.scale draw spec asserts the dispatch order and that drawTitle gets no arguments; making draw pass chartArea to it turns that spec red. Full suite 1704/1704, Chrome headless 148 on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant