paint method
Implements abstract paint for the whole chart.
Paints the chart on the passed canvas
, limited to the size
area.
This paint method is the core method call of painting the chart.
Called from the chart's painter baseclass, the ChartPainter
, which
paint(Canvas, Size) is guaranteed to be called by the Flutter framework
(see class comment), hence ChartPainter.paint
starts the chart painting.
In detail, this method paints all elements of the chart - the legend in _paintLegend
,
the grid in drawGrid
, the x/y labels in _paintXLabels
and _paintYLabels
,
and the data values, column by column, in drawDataPresentersColumns
.
Before the actual canvas painting, at the beginning of this method,
this class's layout is performed, which recursively lays out all member Container
s.
Once this top container is layed out, the paint is called on all
member Container
s (YContainer,XContainer etc),
which recursively paints the leaf Container
s lines, rectangles and circles
in their calculated layout positions.
Implementation
@override
void paint(ui.Canvas canvas) {
// Layout the whole chart container - provides all positions to paint and draw
// all chart elements.
layout(LayoutExpansion(width: chartArea.width, height: chartArea.height));
// Draws the Y labels area of the chart.
yContainer.paint(canvas);
// Draws the X labels area of the chart.
xContainer.paint(canvas);
// Draws the legend area of the chart.
legendContainer.paint(canvas);
// Draws the grid, then data area - bars (bar chart), lines and points (line chart).
dataContainer.paint(canvas);
// clip canvas to size - this does nothing
// todo-1: THIS canvas.clipRect VVVV CAUSES THE PAINT() TO BE CALLED AGAIN. WHY??
// canvas.clipRect(const ui.Offset.zero & size); // Offset & Size => Rect
}