clipToViewport method

void clipToViewport(
  1. Canvas canvas,
  2. ChartViewport viewport,
  3. void body()
)

Clip canvas to the viewport plot area for the duration of body.

Prevents drawing outside the chart bounds (e.g., on axis labels).

Implementation

void clipToViewport(
  Canvas canvas,
  ChartViewport viewport,
  void Function() body,
) {
  canvas.save();
  canvas.clipRect(viewport.rect);
  body();
  canvas.restore();
}