CartesianScale class

The reversible data↔pixel mapping for an index-based cartesian chart (line/area/bar/candlestick). Renderers compute this once and use it for both painting (xForIndex/yForValue) and hit-testing (valueForY/nearestIndex), so paint geometry and interaction geometry can never drift apart.

X is mapped by index: count evenly spaced columns across bounds. Y is a linear value axis from minValue (at the bottom) to maxValue (at the top).

Constructors

CartesianScale({required ChartBounds bounds, required int count, required double minValue, required double maxValue})
Creates a scale over bounds with count columns spanning minValue to maxValue on the value axis.
const

Properties

bounds → ChartBounds
The plot rectangle the scale maps into.
final
count → int
The number of evenly spaced columns along the x-axis.
final
hashCode → int
The hash code for this object.
no setterinherited
maxValue → double
The value at the top of the y-axis.
final
minValue → double
The value at the bottom of the y-axis.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

nearestIndex(double px) → int
The column index nearest pixel px, clamped to 0..count-1. A non-finite px (which would make round() throw) resolves to the first column.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
valueForY(double y) → double
The data value at pixel y — the inverse of yForValue.
xForIndex(int index) → double
The pixel x of column index. A single column is centered; otherwise columns span the full plot width with count - 1 equal gaps.
yForValue(double value) → double
The pixel y of data value (y grows downward, so larger values sit higher).

Operators

operator ==(Object other) → bool
The equality operator.
inherited