preprocessSeries method

  1. @override
Map<String, List<MutableSeries<D>>> preprocessSeries(
  1. List<MutableSeries<D>> seriesList
)
override

Preprocess series to allow stacking and other mutations.

Build a map of rendererId to series.

Implementation

@override
Map<String, List<MutableSeries<D>>> preprocessSeries(
    List<MutableSeries<D>> seriesList) {
  var rendererToSeriesList = super.preprocessSeries(seriesList);
  _useSecondaryMeasureAxis = false;
  // Check if primary or secondary measure axis is being used.
  for (final series in seriesList) {
    final measureAxisId = series.getAttr(measureAxisIdKey);
    _usePrimaryMeasureAxis = _usePrimaryMeasureAxis ||
        (measureAxisId == null || measureAxisId == Axis.primaryMeasureAxisId);
    _useSecondaryMeasureAxis = _useSecondaryMeasureAxis ||
        (measureAxisId == Axis.secondaryMeasureAxisId);
  }

  // Add or remove the primary axis view.
  if (_usePrimaryMeasureAxis) {
    addView(_primaryMeasureAxis);
  } else {
    removeView(_primaryMeasureAxis);
  }

  // Add or remove the secondary axis view.
  if (_useSecondaryMeasureAxis) {
    addView(_secondaryMeasureAxis);
  } else {
    removeView(_secondaryMeasureAxis);
  }

  // Add all disjoint axis views so that their range will be configured.
  _disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
    addView(axis);
  });

  final domainAxis = this.domainAxis!;

  // Reset stale values from previous draw cycles.
  domainAxis.resetDomains();
  _primaryMeasureAxis.resetDomains();
  _secondaryMeasureAxis.resetDomains();

  _disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
    axis.resetDomains();
  });

  final reverseAxisDirection = context.isRtl;

  if (vertical) {
    domainAxis
      ..axisOrientation = AxisOrientation.bottom
      ..reverseOutputRange = reverseAxisDirection;

    _primaryMeasureAxis
      ..axisOrientation = (reverseAxisDirection
          ? AxisOrientation.right
          : AxisOrientation.left)
      ..reverseOutputRange = flipVerticalAxisOutput;

    _secondaryMeasureAxis
      ..axisOrientation = (reverseAxisDirection
          ? AxisOrientation.left
          : AxisOrientation.right)
      ..reverseOutputRange = flipVerticalAxisOutput;

    _disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
      axis
        ..axisOrientation = (reverseAxisDirection
            ? AxisOrientation.left
            : AxisOrientation.right)
        ..reverseOutputRange = flipVerticalAxisOutput;
    });
  } else {
    domainAxis
      ..axisOrientation = (reverseAxisDirection
          ? AxisOrientation.right
          : AxisOrientation.left)
      ..reverseOutputRange = flipVerticalAxisOutput;

    _primaryMeasureAxis
      ..axisOrientation = AxisOrientation.bottom
      ..reverseOutputRange = reverseAxisDirection;

    _secondaryMeasureAxis
      ..axisOrientation = AxisOrientation.top
      ..reverseOutputRange = reverseAxisDirection;

    _disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
      axis
        ..axisOrientation = AxisOrientation.top
        ..reverseOutputRange = reverseAxisDirection;
    });
  }

  // Have each renderer configure the axes with their domain and measure
  // values.
  rendererToSeriesList
      .forEach((String rendererId, List<MutableSeries<D>> seriesList) {
    getSeriesRenderer(rendererId).configureDomainAxes(seriesList);
    getSeriesRenderer(rendererId).configureMeasureAxes(seriesList);
  });

  return rendererToSeriesList;
}