isDomainSpecifiedByUser.js 1.1 KB

1234567891011121314151617181920212223
  1. import { isNumber } from './DataUtils';
  2. /**
  3. * Takes a domain and user props to determine whether he provided the domain via props or if we need to calculate it.
  4. * @param {AxisDomain} domain The potential domain from props
  5. * @param {Boolean} allowDataOverflow from props
  6. * @param {String} axisType from props
  7. * @returns {Boolean} `true` if domain is specified by user
  8. */
  9. export function isDomainSpecifiedByUser(domain, allowDataOverflow, axisType) {
  10. if (axisType === 'number' && allowDataOverflow === true && Array.isArray(domain)) {
  11. var domainStart = domain === null || domain === void 0 ? void 0 : domain[0];
  12. var domainEnd = domain === null || domain === void 0 ? void 0 : domain[1];
  13. /*
  14. * The `isNumber` check is needed because the user could also provide strings like "dataMin" via the domain props.
  15. * In such case, we have to compute the domain from the data.
  16. */
  17. if (!!domainStart && !!domainEnd && isNumber(domainStart) && isNumber(domainEnd)) {
  18. return true;
  19. }
  20. }
  21. return false;
  22. }