drawGroupPrimitives method

  1. @override
List<MarkElement<ElementStyle>> drawGroupPrimitives(
  1. List<Attributes> group,
  2. CoordConv coord,
  3. Offset origin
)
override

Renders primitive elements of all tuples of a group.

The tuples are rendered in groups. the Attributes.shape of the first tuple of a group will be taken as a represent, and it's drawGroupPrimitives method decides the basic way to render the whole group. If different tuples have different shapes, define and call special element rendering methods for each item.

Implementation

@override
List<MarkElement> drawGroupPrimitives(
  List<Attributes> group,
  CoordConv coord,
  Offset origin,
) {
  assert(!(coord is PolarCoordConv && coord.transposed));

  final contours = <List<Offset>>[];

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

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

  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.
    contours.last.add(contours.first.first);
  }

  final primitives = <MarkElement>[];

  final represent = group.first;
  final style = getPaintStyle(
      represent, true, represent.size ?? defaultSize, coord.region, dash);

  for (var contour in contours) {
    if (smooth) {
      primitives.add(SplineElement(
          start: contour.first,
          cubics: getCubicControls(contour, false, true),
          style: style));
    } else {
      primitives.add(PolylineElement(points: contour, style: style));
    }
  }

  return primitives;
}