renderGroup method

  1. @override
List<Figure> renderGroup(
  1. List<Aes> group,
  2. CoordConv coord,
  3. Offset origin
)
override

Renders the whole group of tuples.

The tuples are rendered in groups. the Aes.shape of the first tuple of a group will be taken as a represent, and it's renderGroup method decides the basic way to render the whole group. The renderGroup method then may call renderItems of each tuple of the group respectively or render in it's own way accrording to the implementation.

Implementation

@override
List<Figure> renderGroup(
  List<Aes> group,
  CoordConv coord,
  Offset origin,
) {
  final segments = <List<Offset>>[];
  final labels = <Aes, Offset>{};

  var currentSegment = <Offset>[];
  for (var item in group) {
    assert(item.shape is BasicLineShape);

    if (item.position.last.dy.isFinite) {
      final point = coord.convert(item.position.last);
      currentSegment.add(point);
      labels[item] = point;
    } else if (currentSegment.isNotEmpty) {
      segments.add(currentSegment);
      currentSegment = [];
    }
  }
  if (currentSegment.isNotEmpty) {
    segments.add(currentSegment);
  }

  if (loop &&
      group.first.position.last.dy.isFinite &&
      group.last.position.last.dy.isFinite) {
    // Because lines may be broken by NaN, don't loop by Path.close.
    segments.last.add(segments.first.first);
  }

  final path = Path();
  for (var segment in segments) {
    Paths.polyline(
      points: segment,
      smooth: smooth,
      path: path,
    );
  }

  final rst = <Figure>[];

  final represent = group.first;
  rst.addAll(renderBasicItem(
    dash == null ? path : Paths.dashLine(source: path, dashArray: dash!),
    represent,
    true,
    represent.size ?? defaultSize,
    coord.region,
  ));

  for (var item in labels.keys) {
    if (item.label != null && item.label!.haveText) {
      rst.add(renderLabel(
        item.label!,
        labels[item]!,
        coord.transposed ? Alignment.centerRight : Alignment.topCenter,
      ));
    }
  }

  return rst;
}