paint method

  1. @override
void paint(
  1. Canvas canvas
)

Paints this XContainer on the passed canvas.

Delegates painting to all contained LabelContainers. Any contained LabelContainer must have been offset to the appropriate position.

A special situation is when the LabelContainers are tilted, say counterclockwise. Because labels are always painted horizontally in the screen coordinate system, we much tilt them by painting them on a rotated position. This is achieved as follows: At the moment of calling this paint, the top-left corner of the container (where the label will start painting), must be moved by rotation from the it's intended position clockwise. The canvas will be saved, then rotated, then labels painted horizontally into the offset, then the canvas rotated back for further painting. The canvas rotation back counterclockwise 'carries' with it the horizontally painted labels, which end up in the intended position but rotated counterclockwise.

Implementation

@override
void paint(ui.Canvas canvas) {
  if (!chartTopContainer.data.chartOptions.xContainerOptions.isXContainerShown) {
    return;
  }
  if (labelLayoutStrategy.isRotateLabelsReLayout) {
    // Tilted X labels. Must use canvas and offset coordinate rotation.
    canvas.save();
    canvas.rotate(labelLayoutStrategy.labelTiltRadians);

    _paintLabelContainers(canvas);

    canvas.restore();
  } else {
    // Horizontal X labels, potentially skipped or shrinked
    _paintLabelContainers(canvas);
  }
}