textSpanLogic method

dynamic textSpanLogic(
  1. Canvas canvas,
  2. bool flg,
  3. int i,
  4. int graphCount,
)

Implementation

textSpanLogic(Canvas canvas, bool flg, int i, int graphCount) {
  String textValue = "";
  switch (flg) {
    case true:

      /// Even value if it overlaps with the graph.
      if (radData == RadData.horizontal) {
        if ((valueListY?.length ?? 0) > i) {
          textValue = (valueListY?[i] ?? "");
        }
      } else {
        if ((valueListX?.length ?? 0) > i) {
          textValue = (valueListX?[i] ?? "");
        }
      }
      break;
    case false:

      /// Even value if it overlaps with the graph.
      if (radData == RadData.horizontal) {
        if ((valueListX?.length ?? 0) > i) {
          textValue = (valueListX?[i] ?? "");
        }
      } else {
        if ((valueListY?.length ?? 0) > i) {
          textValue = (valueListY?[i] ?? "");
        }
      }
      break;
  }

  if (i <= wLines) {
    double s = boxSize;
    double s2 = sizeSet.width / wLines * i;
    final textSpan = TextSpan(
      style: textStyle,
      children: <TextSpan>[TextSpan(text: textValue)],
    );

    final textPainter = TextPainter(
      text: textSpan,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(
      minWidth: 0,
      maxWidth: s,
    );
    double h = (textPainter.height);
    double w = (textPainter.width);
    double v = -(s * i) + s + graphValue;
    double v2 = -(s * graphCount) + graphValue;
    if (radData == RadData.horizontal) {
      /// If true, horizonal line.
      if (flg) {
        /// Vertical graph text
        offset = Offset(-s / 2, (v - h / 2));
      } else {
        /// Horizonal graph text
        offset = Offset(s2 - w / 2, s + h / 2);
      }
    } else {
      /// If true, vertical line.
      if (flg) {
        /// Vertical graph text
        offset = Offset(v2 - s / 2, -s2 - h / 2);
      } else {
        /// Horizonal graph text
        offset = Offset(v - w / 2, h / 2);
      }
    }

    textPainter.paint(canvas, offset);
  }
}