generateOffSetsForLabel method

void generateOffSetsForLabel(
  1. Size startLabel,
  2. Size endLabel,
  3. Size size,
  4. double end,
  5. double primaryRulersHeight,
  6. double linearGaugeBoxContainerHeight,
  7. double labelTopMargin,
)

The formula is from the below source (!)https://stackoverflow.com/a/3542512/4565953

Implementation

void generateOffSetsForLabel(
    Size startLabel,
    Size endLabel,
    Size size,
    double end,
    double primaryRulersHeight,
    double linearGaugeBoxContainerHeight,
    double labelTopMargin) {
  primaryRulers.clear();

  Offset a = Offset(startLabel.width / 2, linearGaugeBoxContainerHeight);
  Offset b = Offset(
      size.width - (endLabel.width / 2), linearGaugeBoxContainerHeight);
  for (int i = 0; i < _linearGaugeLabel.length; i++) {
    double x = a.dx * (1 - ((i) / (_linearGaugeLabel.length - 1))) +
        b.dx * (i / (_linearGaugeLabel.length - 1));
    double y = a.dy * (1 - ((i) / (_linearGaugeLabel.length - 1))) +
        b.dy * (i / (_linearGaugeLabel.length - 1));
    primaryRulers[_linearGaugeLabel[i].text!] = [
      Offset(x, y),
      Offset(x, primaryRulersHeight)
    ];
  }
}