preprocessSeries method
Pre-calculates some details for the series that will be needed later during the drawing phase.
Implementation
@override
void preprocessSeries(List<MutableSeries<D>> seriesList) {
for (final series in seriesList) {
final elements = <ArcRendererElement<D>>[];
final domainFn = series.domainFn;
final 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;
final arcLength = config.arcLength;
var totalAngle = 0.0;
final 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.
final angle = arcLength == 2 * pi ? arcLength * .999999 : arcLength;
final endAngle = startAngle + angle;
final 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++) {
final domain = domainFn(arcIndex);
final measure = measureFn(arcIndex);
measures.add(measure);
if (measure == null) {
continue;
}
final percentOfSeries = measure / seriesMeasureTotal;
final angle = arcLength * percentOfSeries;
final endAngle = startAngle + angle;
final 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);
}
}