populateDataSource method

  1. @override
void populateDataSource([
  1. List<ChartValueMapper<T, num>>? yPaths,
  2. List<List<num>>? chaoticYLists,
  3. List<List<num>>? yLists,
  4. List<ChartValueMapper<T, Object>>? fPaths,
  5. List<List<Object?>>? chaoticFLists,
  6. List<List<Object?>>? fLists,
])
override

Implementation

@override
void populateDataSource([
  List<ChartValueMapper<T, num>>? yPaths,
  List<List<num>>? chaoticYLists,
  List<List<num>>? yLists,
  // Here fPath is widget specific feature path.
  // For example, in bubble series's bubbleSizeMapper is a feature path.
  List<ChartValueMapper<T, Object>>? fPaths,
  List<List<Object?>>? chaoticFLists,
  List<List<Object?>>? fLists,
]) {
  _resetDataSourceHolders();
  if (!_canPopulateDataPoints(yPaths, chaoticYLists)) {
    return;
  }

  if (fPaths == null) {
    fPaths = <ChartValueMapper<T, Object>>[];
    chaoticFLists = <List<Object?>>[];
    fLists = <List<Object?>>[];
  }
  _addPointColorMapper(fPaths, chaoticFLists, fLists);
  _addSortValueMapper(fPaths, chaoticFLists, fLists);

  final int length = dataSource!.length;
  final int yPathLength = yPaths!.length;
  final int fPathLength = fPaths.length;

  num previousX = double.negativeInfinity;
  num xMinimum = double.infinity;
  num xMaximum = double.negativeInfinity;
  num yMinimum = double.infinity;
  num yMaximum = double.negativeInfinity;
  final Function(int, D) preferredXValue = _preferredXValue();
  final Function(D?, num) addXValue = _addXValueIntoRawAndChaoticXLists;

  for (int i = 0; i < length; i++) {
    final T current = dataSource![i];
    final D? rawX = xValueMapper!(current, i);
    if (rawX == null) {
      _xNullPointIndexes.add(i);
      continue;
    }

    final num currentX = preferredXValue(i, rawX);
    addXValue(rawX, currentX);
    xMinimum = min(xMinimum, currentX);
    xMaximum = max(xMaximum, currentX);
    if (_hasLinearDataSource) {
      _hasLinearDataSource = currentX >= previousX;
    }

    for (int j = 0; j < yPathLength; j++) {
      final ChartValueMapper<T, num> yPath = yPaths[j];
      final num? yValue = yPath(current, i);
      if (yValue == null || yValue.isNaN) {
        chaoticYLists![j].add(double.nan);
        if (!emptyPointIndexes.contains(i)) {
          emptyPointIndexes.add(i);
        }
      } else {
        chaoticYLists![j].add(yValue);
        yMinimum = min(yMinimum, yValue);
        yMaximum = max(yMaximum, yValue);
      }
    }

    for (int j = 0; j < fPathLength; j++) {
      final ChartValueMapper<T, Object> fPath = fPaths[j];
      final Object? fValue = fPath(current, i);
      chaoticFLists![j].add(fValue);
    }

    previousX = currentX;
  }

  xMin = xMinimum;
  xMax = xMaximum;
  yMin = yMinimum;
  yMax = yMaximum;
  _dataCount = _chaoticXValues.length;
  _canFindLinearVisibleIndexes = _hasLinearDataSource;

  _applyEmptyPointModeIfNeeded(chaoticYLists!);
  _doSortingIfNeeded(chaoticYLists, yLists, chaoticFLists, fLists);
  computeNonEmptyYValues();
  _populateTrendlineDataSource();
  _updateXValuesForCategoryTypeAxes();
}