updateSelection method

bool updateSelection(
  1. List<SeriesDatum<D>> datumSelection,
  2. List<ImmutableSeries<D>> seriesList, {
  3. bool notifyListeners = true,
})

Updates the selection state. If mouse driven, datumSelection should be ordered by distance from mouse, closest first.

Implementation

bool updateSelection(
    List<SeriesDatum<D>> datumSelection, List<ImmutableSeries<D>> seriesList,
    {bool notifyListeners = true}) {
  if (_locked) return false;

  final origSelectedDatum = _selectedDatum;
  final origSelectedSeries = _selectedSeries;

  _selectedDatum = datumSelection;
  _selectedSeries = seriesList;

  // Provide a copy, so listeners get an immutable model.
  final copyOfSelectionModel = SelectionModel.fromOther(this);
  _updatedListeners.forEach((listener) => listener(copyOfSelectionModel));

  final changed = !ListEquality<SeriesDatum<D>>()
          .equals(origSelectedDatum, _selectedDatum) ||
      !ListEquality<ImmutableSeries<D>>()
          .equals(origSelectedSeries, _selectedSeries);
  if (notifyListeners && changed) {
    _changedListeners.forEach((listener) => listener(copyOfSelectionModel));
  }
  return changed;
}