draw method

  1. @override
void draw(
  1. Canvas canvas,
  2. double posX,
  3. double posY
)
override

Draws the drawable at size, translated by getOffsetForDrawingAtPoint.

Kotlin sets the drawable bounds to the size (keeping their origin) and restores them afterwards; a ChartDrawable keeps no bounds, so it is drawn into (0, 0, width, height) after the translation.

Implementation

@override
void draw(ui.Canvas canvas, double posX, double posY) {
  final offset = getOffsetForDrawingAtPoint(posX, posY);

  var width = size.width;
  var height = size.height;

  if (width == 0) width = _drawable.intrinsicWidth.toDouble();
  if (height == 0) height = _drawable.intrinsicHeight.toDouble();

  final saveId = canvas.getSaveCount();
  canvas.save();
  canvas.translate(posX + offset.x, posY + offset.y);
  _drawable.draw(
    canvas,
    MutableRect(0, 0, truncateToDevicePx(width), truncateToDevicePx(height)),
  );
  canvas.restoreToCount(saveId);
}