slices method

An arc mark's slices: each row's share of the turn (a negative or missing value has none).

Implementation

List<GraphSlice> slices(GraphMarkSpec m) {
  final values = [
    for (final r in rows)
      if (r[m.y] case final num v when v.isFinite && v > 0) v.toDouble() else 0.0,
  ];
  final total = values.fold(0.0, (a, b) => a + b);
  if (total <= 0) return const [];
  final gap = values.where((v) => v > 0).length > 1 ? m.gap * math.pi / 180 : 0.0;
  var at = m.startAngle * math.pi / 180;
  final out = <GraphSlice>[];
  for (var i = 0; i < values.length; i++) {
    final sweep = values[i] / total * 2 * math.pi;
    if (sweep > gap) out.add(GraphSlice(i, at + gap / 2, sweep - gap, markColor(m, i)));
    at += sweep;
  }
  return out;
}