preprocessSeries method

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

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

Implementation

@override
void preprocessSeries(List<MutableSeries<D>> seriesList) {
  seriesList.forEach((MutableSeries<D> series) {
    var elements = <ArcRendererElement<D>>[];

    var domainFn = series.domainFn;
    var measureFn = series.measureFn;

    final seriesMeasureTotal = series.seriesMeasureTotal;

    // On the canvas, arc measurements are defined as angles from the positive
    // x axis. Start our first slice at the positive y axis instead.
    var startAngle = config.startAngle;
    var arcLength = config.arcLength;

    var totalAngle = 0.0;

    var measures = <num?>[];

    if (series.data.isEmpty) {
      // If the series has no data, generate an empty arc element that
      // occupies the entire chart.
      //
      // Use a tiny epsilon difference to ensure that the canvas renders a
      // "full" circle, in the correct direction.
      var angle = arcLength == 2 * pi ? arcLength * .999999 : arcLength;
      var endAngle = startAngle + angle;

      var details = ArcRendererElement<D>(
        startAngle: startAngle,
        endAngle: endAngle,
        index: 0,
        key: 0,
        series: series,
      );

      elements.add(details);
    } else {
      // Otherwise, generate an arc element per datum.
      for (var arcIndex = 0; arcIndex < series.data.length; arcIndex++) {
        var domain = domainFn(arcIndex);
        var measure = measureFn(arcIndex);
        measures.add(measure);
        if (measure == null) {
          continue;
        }

        final percentOfSeries = measure / seriesMeasureTotal;
        var angle = arcLength * percentOfSeries;
        var endAngle = startAngle + angle;

        var details = ArcRendererElement<D>(
          startAngle: startAngle,
          endAngle: endAngle,
          index: arcIndex,
          key: arcIndex,
          domain: domain,
          series: series,
        );

        elements.add(details);

        // Update the starting angle for the next datum in the series.
        startAngle = endAngle;

        totalAngle = totalAngle + angle;
      }
    }

    series.setAttr(arcElementsKey, elements);
  });
}