paint method

  1. @override
void paint(
  1. Canvas canvas,
  2. Size size
)
inherited

Paints the chart on the passed canvas, limited to the size area.

This paint method is the core method call of painting the chart, in the sense it is guaranteed to be called by the Flutter framework (see class comment), hence it provides a "hook" into the chart being able to paint and draw itself.

The substantial role is to pass the size provided by the framework layout to chartTopContainer's ChartTopContainer.chartArea. The container needs this information for layout, see chartTopContainer's ChartTopContainer.layout.

Once the above role is done, it delegates all painting to canvas to the chartTopContainer.

Implementation

@override
void paint(ui.Canvas canvas, ui.Size size) {
  // Applications should handle size=(0,0) which may happen
  //   - just return and wait for re-call with size > (0,0).
  if (size == ui.Size.zero) {
    print(' ### Size: paint(): passed size 0!');
    return;
  }

  // set background: canvas.drawPaint(ui.Paint()..color = material.Colors.green);

  // Once we know the size, let the container manage it's size.
  // This is the layout size. Once done, we can delegate painting
  // to canvas to the [ChartContainer].
  chartTopContainer.chartArea = size;

  // Layout the whole chart container - provides all positions to paint and draw
  // all chart elements.
  chartTopContainer.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(ui.Offset.zero & size); // Offset & Size => Rect
}