drawGroupPrimitives method
List<MarkElement<ElementStyle> >
drawGroupPrimitives(
- List<
Attributes> group, - CoordConv coord,
- 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 RectCoordConv);
assert(!coord.transposed);
final primitives = <MarkElement>[];
for (var item in group) {
assert(item.shape is CandlestickShape);
final style = getPaintStyle(item, (item.shape as CandlestickShape).hollow,
(item.shape as CandlestickShape).strokeWidth, null, null);
// Candle stick shape dosen't allow NaN value.
final points = item.position.map((p) => coord.convert(p)).toList();
final x = points.first.dx;
final ys = points.map((p) => p.dy).toList()..sort();
final bias = (item.size ?? defaultSize) / 2;
final top = ys[0];
final topEdge = ys[1];
final bottomEdge = ys[2];
final bottom = ys[3];
if ((item.shape as CandlestickShape).hollow) {
primitives.add(PathElement(segments: [
MoveSegment(end: Offset(x, top)),
LineSegment(end: Offset(x, topEdge)),
MoveSegment(end: Offset(x - bias, topEdge)),
LineSegment(end: Offset(x + bias, topEdge)),
LineSegment(end: Offset(x + bias, bottomEdge)),
LineSegment(end: Offset(x - bias, bottomEdge)),
CloseSegment(),
MoveSegment(end: Offset(x, bottomEdge)),
LineSegment(end: Offset(x, bottom)),
], style: style, tag: item.tag));
} else {
// If the stoke style is fill, the lines created by Path.lineTo will not
// be rendered.
final strokeBias = (item.shape as CandlestickShape).strokeWidth / 2;
primitives.add(PathElement(segments: [
MoveSegment(end: Offset(x + strokeBias, top)),
LineSegment(end: Offset(x + strokeBias, topEdge)),
LineSegment(end: Offset(x + bias, topEdge)),
LineSegment(end: Offset(x + bias, bottomEdge)),
LineSegment(end: Offset(x + strokeBias, bottomEdge)),
LineSegment(end: Offset(x + strokeBias, bottom)),
LineSegment(end: Offset(x - strokeBias, bottom)),
LineSegment(end: Offset(x - strokeBias, bottomEdge)),
LineSegment(end: Offset(x - bias, bottomEdge)),
LineSegment(end: Offset(x - bias, topEdge)),
LineSegment(end: Offset(x - strokeBias, topEdge)),
LineSegment(end: Offset(x - strokeBias, top)),
CloseSegment(),
], style: style, tag: item.tag));
}
// No labels.
}
return primitives;
}