drawVerticalLines method

void drawVerticalLines(
  1. BuildContext context,
  2. CanvasWrapper canvasWrapper,
  3. PaintHolder<D> holder,
  4. Size viewSize,
)

Implementation

void drawVerticalLines(
  BuildContext context,
  CanvasWrapper canvasWrapper,
  PaintHolder<D> holder,
  Size viewSize,
) {
  for (final line in holder.data.extraLinesData.verticalLines) {
    final from = Offset(getPixelX(line.x, viewSize, holder), 0);
    final to = Offset(getPixelX(line.x, viewSize, holder), viewSize.height);

    _extraLinesPaint
      ..color = line.color
      ..strokeWidth = line.strokeWidth
      ..transparentIfWidthIsZero();

    canvasWrapper.drawDashedLine(
      from,
      to,
      _extraLinesPaint,
      line.dashArray,
    );

    if (line.sizedPicture != null) {
      final centerX = line.sizedPicture!.width / 2;
      final centerY = line.sizedPicture!.height / 2;
      final xPosition = to.dx - centerX;
      final yPosition = viewSize.height - centerY;

      canvasWrapper
        ..save()
        ..translate(xPosition, yPosition)
        ..drawPicture(line.sizedPicture!.picture)
        ..restore();
    }

    if (line.image != null) {
      final centerX = line.image!.width / 2;
      final centerY = line.image!.height + 2;
      final centeredImageOffset =
          Offset(to.dx - centerX, viewSize.height - centerY);
      canvasWrapper.drawImage(
        line.image!,
        centeredImageOffset,
        _imagePaint,
      );
    }

    if (line.label.show) {
      final label = line.label;
      final style =
          TextStyle(fontSize: 11, color: line.color).merge(label.style);
      final padding = label.padding as EdgeInsets;

      final span = TextSpan(
        text: label.labelResolver(line),
        style: Utils().getThemeAwareTextStyle(context, style),
      );

      final tp = TextPainter(
        text: span,
        textDirection: TextDirection.ltr,
      );
      // ignore: cascade_invocations
      tp.layout();

      canvasWrapper.drawText(
        tp,
        label.alignment.withinRect(
          Rect.fromLTRB(
            to.dx - padding.right - tp.width,
            from.dy + padding.top,
            from.dx + padding.left,
            to.dy - padding.bottom,
          ),
        ),
      );
    }
  }
}