layout method

  1. @override
void layout(
  1. Context context,
  2. BoxConstraints constraints, {
  3. bool parentUsesSize = false,
})
override

First widget pass to calculate the children layout and bounding box

Implementation

@override
void layout(Context context, BoxConstraints constraints,
    {bool parentUsesSize = false}) {
  super.layout(context, constraints, parentUsesSize: parentUsesSize);

  final datasets = Chart.of(context).datasets;
  final size = constraints.biggest;

  // In simple conditions, this loop will run only 2 times.
  var count = 5;
  while (count-- > 0) {
    _xAxis.crossAxisPosition = _yAxis.axisPosition;
    _xAxis.axisPosition =
        math.max(_xAxis.axisPosition, _yAxis.crossAxisPosition);
    _xAxis.layout(context, constraints);
    assert(_xAxis.box != null);
    _yAxis.crossAxisPosition = _xAxis.axisPosition;
    _yAxis.axisPosition =
        math.max(_yAxis.axisPosition, _xAxis.crossAxisPosition);
    _yAxis.layout(context, constraints);
    assert(_yAxis.box != null);
    if (_yAxis.crossAxisPosition == _xAxis.axisPosition &&
        _xAxis.crossAxisPosition == _yAxis.axisPosition) {
      break;
    }
  }

  final width = _yAxis.axisPosition;
  final height = _xAxis.axisPosition;
  gridBox = PdfRect(width, height, size.x - width, size.y - height);

  for (final dataset in datasets) {
    dataset.layout(context, BoxConstraints.tight(gridBox.size));
    dataset.box =
        PdfRect.fromPoints(PdfPoint(width, height), dataset.box!.size);
  }
}