painting library

Drafter's extension API — import this alongside package:drafter/drafter.dart when you write a custom ChartRenderer or draw directly into a chart Canvas.

The everyday chart widgets, data models and theming live in the main package:drafter/drafter.dart entrypoint. This secondary entrypoint exposes the lower-level building blocks so they don't clutter the primary namespace:

Classes

AccessibilityFormat
Shared formatting so every renderer's ChartRenderer.accessibilityValue reads consistently. Trims trailing zeros so 40.0 announces as "40".
ChartAxis
Cross-chart math & layout helpers so no chart re-implements them: axis tick steps, cartesian/radial bounds, and text-alignment offsets. Pure value math.
ChartBounds
The inset plotting rectangle for a cartesian chart (line/bar/scatter).
ChartCanvas
A thin, reusable widget that hosts any ChartRenderer in a CustomPaint, reads the theme from the environment, and traces the chart in with the shared reveal animation. Every concrete chart widget wraps this — so the animation/theming plumbing lives in exactly one place.
ChartFormatting
Deterministic, platform-independent number formatting for axis labels and value read-outs. Integer arithmetic avoids float-precision drift and drops trailing zeros (3.0 -> "3", 3.10 -> "3.1").
ChartRenderer
Draws one chart into a Canvas. Implementations hold immutable data + style, mirroring the Compose/SwiftUI renderer pattern: a renderer is a pure value that, given a canvas, size, theme, and reveal progress, draws itself.
ChartText
RadialLayout
Center + radius for a radial chart (pie/gauge/radar/polar/sunburst).

Enums

HAlign
Horizontal anchor for a label drawn at an origin x.
VAlign
Vertical anchor for a label drawn at an origin y.

Functions

areaGradientShader(Color color, {required double top, required double bottom, double topAlpha = 0.32}) Gradient
A soft vertical gradient shader fading from color near top to transparent at bottom. Mirrors areaGradient in the Compose library.
drawChartText(Canvas canvas, String text, Offset at, {required Color color, double fontSize = 9, FontWeight weight = FontWeight.normal, HAlign h = HAlign.start, VAlign v = VAlign.top}) → void
Draws text anchored at at by h/v. The shared label helper every chart uses (the equivalent of SwiftUI's context.draw(Text…, at:, anchor:)).
drawSmoothLine(Canvas canvas, {required List<Offset> points, required Color color, required double baseline, required double progress, double strokeWidth = 6, bool fill = true, bool endDot = true, bool smooth = true}) → void
Draws a single smooth line series with an optional gradient area fill, a tracing left-to-right reveal animation, and an optional highlighted end dot. The Flutter equivalent of DrawScope.drawSmoothLine.
drawVertexDot(Canvas canvas, Offset center, Color color, double radius) → void
Draws a small filled dot with a white halo — used to mark line vertices.
normalizedLabels(List<String> labels, int count) List<String>
Pads or truncates labels to exactly count entries, so a mismatched label array can never drive a different number of columns than the data. Missing labels become empty strings; extra labels are dropped.
polylinePath(List<Offset> points) Path
A straight-segment polyline path, used when a series opts out of smoothing.
smoothPath(List<Offset> points) Path
Builds a smooth cubic-bezier Path that passes through every vertex in points using a Catmull-Rom spline (tension 0.5). Falls back to straight segments below three points, where a curve is undefined.
trimPath(Path path, double t) Path
Returns the sub-path of path from its start up to fraction t in 0..1, the Flutter equivalent of SwiftUI's Path.trimmedPath(from:to:).