preprocessSeries method

  1. @override
void preprocessSeries(
  1. List<MutableSeries<D>> seriesList
)
override

Pre-calculates some details for the series that will be needed later during the drawing phase.

Implementation

@override
void preprocessSeries(List<MutableSeries<D>> seriesList) {
  var localConfig = config as SymbolAnnotationRendererConfig;

  _seriesInfo.clear();

  var offset = 0.0;

  for (var series in seriesList) {
    final seriesKey = series.id;

    // Default to the configured radius if none was defined by the series.
    series.radiusPxFn ??= (_) => config.radiusPx;

    var maxRadius = 0.0;
    for (var index = 0; index < series.data.length; index++) {
      // Default to the configured radius if none was returned by the
      // accessor function.
      var radiusPx = series.radiusPxFn?.call(index)?.toDouble();
      radiusPx ??= config.radiusPx;

      maxRadius = max(maxRadius, radiusPx);
    }

    final rowInnerHeight = maxRadius * 2;

    final rowHeight = localConfig.verticalSymbolBottomPaddingPx +
        localConfig.verticalSymbolTopPaddingPx +
        rowInnerHeight;

    final symbolCenter = offset +
        localConfig.verticalSymbolTopPaddingPx +
        (rowInnerHeight / 2);

    series.measureFn = (index) => 0;
    series.measureOffsetFn = (index) => 0;

    // Override the key function to allow for range annotations that start at
    // the same point. This is a necessary hack because every annotation has a
    // measure value of 0, so the key generated in [PointRenderer] is not
    // unique enough.
    series.keyFn ??= (index) => '${series.id}__${series.domainFn(index)}__'
        '${series.domainLowerBoundFn!(index)}__'
        '${series.domainUpperBoundFn!(index)}';

    _seriesInfo[seriesKey] = _SeriesInfo<D>(
      rowHeight: rowHeight,
      rowStart: offset,
      symbolCenter: symbolCenter,
    );

    offset += rowHeight;
  }

  _currentHeight = offset.ceil();

  super.preprocessSeries(seriesList);
}