SelectionModel<D>.fromConfig constructor
SelectionModel<D>.fromConfig (
- List<
SeriesDatumConfig< ? selectedDataConfig,D> > - List<
String> ? selectedSeriesConfig, - List<
ImmutableSeries< seriesListD> >
Create selection model from configuration.
Implementation
SelectionModel.fromConfig(List<SeriesDatumConfig<D>>? selectedDataConfig,
List<String>? selectedSeriesConfig, List<ImmutableSeries<D>> seriesList) {
final selectedDataMap = <String, List<D>>{};
if (selectedDataConfig != null) {
for (final config in selectedDataConfig) {
selectedDataMap[config.seriesId] ??= <D>[];
selectedDataMap[config.seriesId]!.add(config.domainValue);
}
// Add to list of selected series.
_selectedSeries.addAll(seriesList.where((ImmutableSeries<D> series) =>
selectedDataMap.keys.contains(series.id)));
// Add to list of selected data.
for (final series in seriesList) {
if (selectedDataMap.containsKey(series.id)) {
final domainFn = series.domainFn;
for (var i = 0; i < series.data.length; i++) {
final Object? datum = series.data[i];
if (selectedDataMap[series.id]!.contains(domainFn(i))) {
_selectedDatum.add(SeriesDatum(series, datum));
}
}
}
}
}
// Add to list of selected series, if it does not already exist.
if (selectedSeriesConfig != null) {
final existingSeriesIds = {
for (final series in _selectedSeries) series.id,
};
final remainingSeriesToAdd = selectedSeriesConfig
.where((String seriesId) => !existingSeriesIds.contains(seriesId))
.toSet();
_selectedSeries.addAll(seriesList.where((ImmutableSeries<D> series) =>
remainingSeriesToAdd.contains(series.id)));
}
}