drawText method

  1. @override
void drawText(
  1. Canvas canvas,
  2. CandleEntity data,
  3. double x
)
override

Implementation

@override
void drawText(Canvas canvas, CandleEntity data, double x) {
  if (isLine == true) return;
  for (int i = 0; i < stateLi.length; ++i) {
    TextSpan? span;
    if (stateLi[i] == MainState.MA) {
      span = TextSpan(
        children: _createMATextSpan(data),
      );
    } else if (stateLi[i] == MainState.BOLL) {
      span = TextSpan(
        children: [
          if (data.up != 0)
            TextSpan(
                text: "BOLL:${format(data.mb)}    ",
                style: getTextStyle(this.chartColors.ma5Color)),
          if (data.mb != 0)
            TextSpan(
                text: "UB:${format(data.up)}    ",
                style: getTextStyle(this.chartColors.ma10Color)),
          if (data.dn != 0)
            TextSpan(
                text: "LB:${format(data.dn)}    ",
                style: getTextStyle(this.chartColors.ma30Color)),
        ],
      );
    } else if (stateLi[i] == MainState.SAR) {
      span = TextSpan(
        text: "SAR:${format(data.sar)}",
        style: getTextStyle(this.chartColors.sarColor),
      );
    }
    if (span == null) return;
    TextPainter tp =
        TextPainter(text: span, textDirection: TextDirection.ltr);
    tp.layout();

    Offset offset = Offset(x, chartRect.top - topPadding + i * 12);

    canvas.drawRect(
        Rect.fromLTRB(
          offset.dx - 2,
          offset.dy - 2,
          tp.width + offset.dx + 2,
          tp.height + offset.dy + 2,
        ),
        Paint()..color = this.chartColors.bgColor);

    tp.paint(canvas, offset);
  }
}