modify method

  1. @override
AttributesGroups modify(
  1. AttributesGroups groups,
  2. Map<String, ScaleConv<dynamic, num>> scales,
  3. AlgForm form,
  4. CoordConv coord,
  5. Offset origin,
)
override

Modifies the position of mark items.

The aesthetic encodes are in the groups.

Note that the modifier should be functional, which means to return a new groups list as result, not to change the input groups.

Implementation

@override
AttributesGroups modify(
    AttributesGroups groups,
    Map<String, ScaleConv<dynamic, num>> scales,
    AlgForm form,
    CoordConv coord,
    Offset origin) {
  final normalZero = origin.dy;

  // The first group need no change.
  final AttributesGroups rst = [groups.first];
  for (var i = 1; i < groups.length; i++) {
    final group = groups[i];
    // The stacking is accumulative, so refers to the pre one from rst.
    final preGroup = rst[i - 1];
    final groupRst = <Attributes>[];
    for (var j = 0; j < group.length; j++) {
      final position = group[j].position;
      final prePosition = preGroup[j].position;

      var preTop = normalZero;
      for (var point in prePosition) {
        final y = point.dy;
        if (y.isFinite) {
          preTop = (preTop - normalZero).abs() >= (y - normalZero).abs()
              ? preTop
              : y;
        }
      }

      groupRst.add(group[j].withPosition(position
          .map((point) => Offset(
                point.dx,
                point.dy + (preTop - normalZero),
              ))
          .toList()));
    }
    rst.add(groupRst);
  }

  return rst;
}