getLocation method

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

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!;

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

    // If domain location is outside of scale range but only outside by less
    // than epsilon, correct the potential mis-location 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;
}