populateDataSource method

  1. @protected
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,
])

Implementation

@protected
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 pie series's pointRadiusMapper 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;

  final Function(int, D) preferredXValue = _valueToIndex;
  final Function(D? value, num x) 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(index);
      continue;
    }

    final num currentX = preferredXValue(i, rawX);
    addXValue(rawX, currentX);
    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);
      }
    }

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

  _dataCount = _chaoticXValues.length;
  _applyEmptyPointModeIfNeeded(chaoticYLists!);
  _doSortingIfNeeded(chaoticYLists, yLists, chaoticFLists, fLists);
}