getPositionByValue method

double getPositionByValue(
  1. num value
)

Returns the position on the ruler corresponding to a specific value.

This method calculates the position (e.g., the offset or pixel position) on the ruler that corresponds to a given value (e.g., "kg", "cm", etc.). It is used to visually align the ruler based on a specific measurement value.

Implementation

double getPositionByValue(num value) {
  double offsetValue = 0;
  for (ScaleIntervals config in widget.scaleUnit.scaleIntervals) {
    if (config.begin <= value && config.end >= value) {
      offsetValue +=
          ((value - config.begin) / config.scale) * _ruleScaleInterval;
      break;
    } else if (value >= config.begin) {
      var totalCount =
      ((config.end - config.begin) / config.scale).truncate();
      offsetValue += totalCount * _ruleScaleInterval;
    }
  }
  return offsetValue;
}