@mui/x-charts
Version:
The community edition of MUI X Charts components.
29 lines (27 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.niceDomain = niceDomain;
var _getScale = require("../internals/getScale");
/**
* Returns a nice domain for the given scale type and domain.
* Does not modify the original domain.
*
* Providing a count improves the nice domain calculation by trying to align tick values to round
* numbers or dates.
*
* For example, if you have a domain of [29, 72] and there are 5 ticks, the nice domain will be
* [20, 80] so that the ticks can be at [20, 35, 50, 65, 80].
* However, if there are 11 ticks, the nice domain will be [25, 75] so that the ticks can be at
* [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75].
*
* @param scaleType The type of the scale (e.g., 'linear', 'log', 'time', etc.).
* @param domain The domain to be made nicer.
* @param count An optional number of ticks to improve the nice domain calculation. Defaults to 5.
*/
function niceDomain(scaleType, domain, count = 5) {
const scale = (0, _getScale.getScale)(scaleType, domain, [0, 1]);
scale.nice(count);
return scale.domain();
}