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,
  List<ChartValueMapper<T, Object>>? fPaths,
  List<List<Object?>>? chaoticFLists,
  List<List<Object?>>? fLists,
]) {
  _populateDataSource();

  if (yPaths == null) {
    yPaths = <ChartValueMapper<T, num>>[];
    chaoticYLists = <List<num>>[];
    yLists = <List<num>>[];
  }

  if (yValueMapper != null) {
    yPaths.add(yValueMapper!);
    if (sortingOrder == SortingOrder.none) {
      chaoticYLists?.add(yValues);
    } else {
      chaoticYLists?.add(_chaoticYValues);
      yLists?.add(yValues);
    }
  }

  _resetDataSourceHolders();
  if (!_canPopulateDataPoints(yPaths, chaoticYLists)) {
    _dataCount = _chaoticXValues.length;
    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 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 < _histoXLength; i++) {
    final D rawX = _histogramXValues[i] as D;
    final num currentX = preferredXValue(i, rawX);
    addXValue(rawX, currentX);
    xMinimum = min(xMinimum, currentX);
    xMaximum = max(xMaximum, currentX);

    for (int j = 0; j < yPathLength; j++) {
      final num yValue = _histogramYValues[i];
      chaoticYLists![j].add(yValue);
      yMinimum = min(yMinimum, yValue);
      yMaximum = max(yMaximum, yValue);
    }

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

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

  _copyXAndRawXValues();
  computeNonEmptyYValues();
  _populateTrendlineDataSource();
  if (dataCount < 1) {
    return;
  }

  super._calculateSbsInfo();
}