calculateOffsets method

  1. @override
void calculateOffsets()
override

Calculates the offsets of the chart to the border depending on the position of an eventual legend or depending on the length of the y-axis and x-axis labels and their position

Implementation

@override
void calculateOffsets() {
  if (legend != null) legendRenderer!.computeLegend(getData());
  renderer?.initBuffers();
  calcMinMax();

  if (!_customViewPortEnabled) {
    double offsetLeft = 0, offsetRight = 0, offsetTop = 0, offsetBottom = 0;

    _offsetsBuffer = calculateLegendOffsets(_offsetsBuffer);

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

    // offsets for y-labels
    if (_axisLeft!.needsOffset()) {
      offsetLeft +=
          _axisLeft!.getRequiredWidthSpace(_axisRendererLeft!.axisLabelPaint);
    }

    if (_axisRight!.needsOffset()) {
      offsetRight += _axisRight!
          .getRequiredWidthSpace(_axisRendererRight!.axisLabelPaint);
    }

    if (xAxis!.enabled && xAxis!.drawLabels) {
      double xLabelHeight = xAxis!.labelRotatedHeight +
          xAxis!.yOffset +
          xAxis!.getRequiredHeightSpace(_xAxisRenderer!.axisLabelPaint);

      // offsets for x-labels
      if (xAxis!.position == XAxisPosition.bottom) {
        offsetBottom += xLabelHeight;
      } else if (xAxis!.position == XAxisPosition.top) {
        offsetTop += xLabelHeight;
      } else if (xAxis!.position == XAxisPosition.bothSided) {
        offsetBottom += xLabelHeight;
        offsetTop += xLabelHeight;
      }
    }

    offsetTop += extraTopOffset;
    offsetRight += extraRightOffset;
    offsetBottom += extraBottomOffset;
    offsetLeft += extraLeftOffset;

    double minOffset = Utils.convertDpToPixel(_minOffset);

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

  prepareOffsetMatrix();
  prepareValuePxMatrix();
}