getLocation method

  1. @override
double? getLocation(
  1. D? domain
)

Get location for the domain.

Implementation

@override
double? getLocation(D? domain) {
  const epsilon = 2e-10;
  if (domain != null) {
    final scale = this.scale!;
    final range = scale.range!;

    var domainLocation = scale[domain]!.toDouble();

    // If domain location is outside of scale range but only outside by less
    // than epsilon, correct the potential mislocation caused by floating
    // point computation by moving it inside of scale range.
    if (domainLocation > range.max && domainLocation - epsilon < range.max) {
      return domainLocation - epsilon;
    } else if (domainLocation < range.min &&
        domainLocation + epsilon > range.min) {
      return domainLocation + epsilon;
    }
    return domainLocation;
  }
  return null;
}