legendKeys property
List<GraphLegendKey>
get
legendKeys
What a legend would list: each slice of a polar pane (its color, its label and its share), else each named mark (an area and the line along its top once).
Implementation
List<GraphLegendKey> get legendKeys {
final out = <GraphLegendKey>[];
for (final p in spec.panes) {
if (!p.polar) continue;
final m = p.marks.where((m) => m.type == 'arc').firstOrNull;
if (m == null) return out;
final rows = _tweenTo ?? _target ?? this.rows;
var total = 0.0;
for (final r in rows) {
if (r[m.y] case final num v when v.isFinite && v > 0) total += v;
}
for (var i = 0; i < rows.length; i++) {
final label = rows[i][spec.x.label]?.toString() ?? '';
if (label.isEmpty) continue;
final v = rows[i][m.y];
final share = v is num && v.isFinite && v > 0 && total > 0 ? '${(v / total * 100).round()}%' : '';
out.add(GraphLegendKey(markColor(m, i), label, spec.legend.values ? share : ''));
}
return out;
}
final seen = <String>{};
for (final p in spec.panes) {
for (final m in p.marks) {
if (m.name.isEmpty || m.overlay != null || m.type == 'candle' || m.byDirection) continue;
if (seen.add(m.valueField)) out.add(GraphLegendKey(m.color, m.name, ''));
}
}
return out;
}