barGroups method

List<List<int>> barGroups(
  1. int pane
)

A pane's bars by their place in the row: marks with the same stack are one group (one on another), every other bar a group of its own. The numbers are the marks' places in the pane. Overlay bars (volume under a price) are not grouped: each is drawn across the row.

Implementation

List<List<int>> barGroups(int pane) {
  final marks = spec.panes[pane].marks;
  final groups = <List<int>>[];
  final byStack = <String, List<int>>{};
  for (var i = 0; i < marks.length; i++) {
    final m = marks[i];
    if (m.type != 'bar' || m.overlay != null) continue;
    final stack = m.stack;
    if (stack == null) {
      groups.add([i]);
    } else if (byStack[stack] case final list?) {
      list.add(i);
    } else {
      groups.add(byStack[stack] = [i]);
    }
  }
  return groups;
}