calculateOffsets method

  1. @override
void calculateOffsets()
override

Computes the content rectangle with the axes swapped: the y axis labels take space at the top (left axis) and bottom (right axis), the x axis labels at the left (XAxisPosition.BOTTOM) or right (XAxisPosition.TOP). Unlike BarChart.calculateOffsets, this always recalculates, also while setViewPortOffsets is active, as in Kotlin.

Implementation

@override
void calculateOffsets() {
  var offsetLeft = 0.0;
  var offsetRight = 0.0;
  var offsetTop = 0.0;
  var offsetBottom = 0.0;

  calculateLegendOffsets(_offsetsBuffer);

  offsetLeft += _offsetsBuffer.left;
  offsetTop += _offsetsBuffer.top;
  offsetRight += _offsetsBuffer.right;
  offsetBottom += _offsetsBuffer.bottom;

  if (axisLeft.needsOffset) {
    offsetTop += axisLeft.getRequiredHeightSpace(
      rendererLeftYAxis.paintAxisLabels,
    );
  }

  if (axisRight.needsOffset) {
    offsetBottom += axisRight.getRequiredHeightSpace(
      rendererRightYAxis.paintAxisLabels,
    );
  }

  final xlabelwidth = xAxis.labelRotatedWidth;

  if (xAxis.isEnabled) {
    switch (xAxis.position) {
      case XAxisPosition.BOTTOM:
        offsetLeft += xlabelwidth;
      case XAxisPosition.TOP:
        offsetRight += xlabelwidth;
      case XAxisPosition.BOTH_SIDED:
        offsetLeft += xlabelwidth;
        offsetRight += xlabelwidth;
      default:
        break;
    }
  }

  offsetTop += Utils.convertDpToPixel(extraTopOffset);
  offsetRight += Utils.convertDpToPixel(extraRightOffset);
  offsetBottom += Utils.convertDpToPixel(extraBottomOffset);
  offsetLeft += Utils.convertDpToPixel(extraLeftOffset);

  final minOffset = Utils.convertDpToPixel(this.minOffset);

  viewPortHandler.restrainViewPort(
    math.max(minOffset, offsetLeft),
    math.max(minOffset, offsetTop),
    math.max(minOffset, offsetRight),
    math.max(minOffset, offsetBottom),
  );

  if (isLogEnabled) {
    debugPrint(
      '${Chart.LOG_TAG}: offsetLeft: $offsetLeft, offsetTop: $offsetTop, offsetRight: $offsetRight, '
      'offsetBottom: $offsetBottom',
    );
    debugPrint('${Chart.LOG_TAG}: Content: ${viewPortHandler.contentRect}');
  }

  prepareOffsetMatrix();
  prepareValuePxMatrix();
}