drawMajorTicksValue method

void drawMajorTicksValue({
  1. required Canvas canvas,
  2. required Size size,
})

Implementation

void drawMajorTicksValue({required Canvas canvas, required Size size}) {
  /// find the interval of max value
  final valueInterval = (maxValue - minValue) / divisions;

  final ticksInterval = getScaleInterval(size);

  // 8 Is the value required to adjust the tick position
  var majorTickMarkPosition = getScaleLowerLimit(size) - 8;

  for (var i = 0; i <= (divisions); i++) {
    // multiply the interval by the division to find the value at the division.
    var value = (i * valueInterval) + minValue;

    var stringValue = value.toStringAsFixed(decimalPlaces);

    // sets the paint properties of the tick value.
    final majorTickValuePainter = TextPainter(
      textAlign: TextAlign.center,
      text: TextSpan(
          style: majorTicksValueTextStyle.copyWith(), text: stringValue),
      textDirection: TextDirection.ltr,
    )..layout();

    switch (gaugeOrientation) {
      case GaugeOrientation.horizontal:

        /// Find the position of the ticks

        final Offset majorTickValuePosition = Offset(
            (size.width / 1.65) +
                gaugeStrokeWidth -
                (majorTickValuePainter.width / 2),
            majorTickMarkPosition);

        final pivot =
            majorTickValuePainter.size.center(majorTickValuePosition);

        canvas.save();
        canvas.translate(pivot.dx, pivot.dy);
        canvas.rotate(RadialHelper.degreesToRadians(-90));
        canvas.translate(-pivot.dx, -pivot.dy);

        majorTickValuePainter.paint(canvas, majorTickValuePosition);
        canvas.restore();
        break;
      case GaugeOrientation.vertical:

        /// Find the position of the ticks
        final Offset majorTickValuePosition = Offset(
            (size.width / 1.7) + gaugeStrokeWidth, majorTickMarkPosition);
        majorTickValuePainter.paint(canvas, majorTickValuePosition);
        break;
    }

    majorTickMarkPosition = majorTickMarkPosition + ticksInterval;
  }
}