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) {
  _nodeToArcRenderElementMap.clear();
  seriesList.forEach((MutableSeries<D> series) {
    var elements = <SunburstArcRendererElement<D>>[];

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

    // The seriesMeasureTotal needs to be computed from currently displayed
    // top level.
    var seriesMeasureTotal = 0.0;
    for (var i = 0; i < series.data.length; i++) {
      final node = series.data[i] as TreeNode<Object>;
      final measure = measureFn(i);
      if (node.depth == 1 && measure != null) {
        seriesMeasureTotal += measure;
      }
    }

    // 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>[];

    // No data processing is same as the regular arc renderer.
    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 = SunburstArcRendererElement<D>(
          startAngle: startAngle,
          endAngle: endAngle,
          index: 0,
          key: 0,
          series: series);

      elements.add(details);
    } else {
      // Create SunburstArcRendererElement for each item in the tree,
      // excluding the root node.
      var root = series.data.first as TreeNode<D>;
      root.visit((node) {
        elements.addAll(_createArcRenderElementForNode(series, node));
      });
    }

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