preprocessSeries method

Map<String, List<MutableSeries<D>>> preprocessSeries(
  1. List<MutableSeries<D>> seriesList
)

Preprocess series to allow stacking and other mutations.

Build a map of rendererId to series.

Implementation

Map<String, List<MutableSeries<D>>> preprocessSeries(
  List<MutableSeries<D>> seriesList,
) {
  final rendererToSeriesList = <String, List<MutableSeries<D>>>{};

  final unusedRenderers = _usingRenderers;
  _usingRenderers = <String>{};

  // Build map of rendererIds to SeriesLists.
  for (final series in seriesList) {
    final rendererId = series.getAttr(rendererIdKey)!;
    rendererToSeriesList.putIfAbsent(rendererId, () => []).add(series);

    _usingRenderers.add(rendererId);
    unusedRenderers.remove(rendererId);
  }

  // Allow unused renderers to render out content.
  for (final rendererId in unusedRenderers) {
    rendererToSeriesList[rendererId] = [];
  }

  // Have each renderer preprocess their seriesLists.
  rendererToSeriesList.forEach((rendererId, seriesList) {
    getSeriesRenderer(rendererId).preprocessSeries(seriesList);
  });

  return rendererToSeriesList;
}