transformValues method

  1. @override
void transformValues()
override

Transforms the x and y values to screen coordinates.

Implementation

@override
void transformValues() {
  if (x.isNaN ||
      lowerQuartile.isNaN ||
      upperQuartile.isNaN ||
      minimum.isNaN ||
      maximum.isNaN ||
      median.isNaN ||
      mean.isNaN) {
    segmentRect = null;
    _oldSegmentRect = null;
    _oldPoints.clear();
    points.clear();
    return;
  }

  points.clear();
  _medianLinePoints.clear();
  _meanLinePoints.clear();
  _outlierPoints.clear();

  final PointToPixelCallback transformX = series.pointToPixelX;
  final PointToPixelCallback transformY = series.pointToPixelY;
  final num left = x + series.sbsInfo.minimum;
  final num right = x + series.sbsInfo.maximum;

  final double centerY = lowerQuartile + (upperQuartile - lowerQuartile) / 2;
  if (!lowerQuartile.isNaN && !upperQuartile.isNaN) {
    double x1 = transformX(left, upperQuartile);
    double y1 = transformY(left, upperQuartile);
    double x2 = transformX(right, lowerQuartile);
    double y2 = transformY(right, lowerQuartile);

    if (y1 > y2) {
      final double temp = y1;
      y1 = y2;
      y2 = temp;
    }

    if (x1 > x2) {
      final double temp = x1;
      x1 = x2;
      x2 = temp;
    }

    segmentRect = Rect.fromLTRB(x1, y1, x2, y2);
    _oldSegmentRect ??= Rect.fromLTRB(
      transformX(left, centerY),
      transformY(left, centerY),
      transformX(right, centerY),
      transformY(right, centerY),
    );
  }

  if (segmentRect == null) {
    return;
  }

  final double centerX = (right + left) / 2;
  _addMinMaxPoints(transformX, transformY, centerX, centerY, left, right);

  if (!median.isNaN) {
    _medianLinePoints
        .add(Offset(transformX(left, median), transformY(left, median)));
    _medianLinePoints
        .add(Offset(transformX(right, median), transformY(right, median)));
  }

  if (series.showMean && !mean.isNaN) {
    final double meanX = transformX(centerX, mean);
    final double meanY = transformY(centerX, mean);

    final double markerHeight = series.markerSettings.height;
    final double markerWidth = series.markerSettings.width;
    _meanLinePoints
        .add(Offset(meanX + markerWidth / 2, meanY - markerHeight / 2));
    _meanLinePoints
        .add(Offset(meanX - markerWidth / 2, meanY + markerHeight / 2));

    _meanLinePoints
        .add(Offset(meanX + markerWidth / 2, meanY + markerHeight / 2));
    _meanLinePoints
        .add(Offset(meanX - markerWidth / 2, meanY - markerHeight / 2));
  }

  if (outliers != null && outliers!.isNotEmpty) {
    final int length = outliers!.length;
    for (int i = 0; i < length; i++) {
      final num outlier = outliers![i];
      final double outlierX = transformX(centerX, outlier);
      final double outlierY = transformY(centerX, outlier);
      _outlierPoints.add(Offset(outlierX, outlierY));
    }
  }
}