@mui/x-charts
Version:
The community edition of MUI X Charts components.
41 lines (37 loc) • 1.32 kB
JavaScript
import { scaleBand } from "./scaleBand.mjs";
/**
* Constructs a new point scale with the specified range, no padding, no rounding and center alignment.
* The domain defaults to the empty domain.
* If range is not specified, it defaults to the unit range [0, 1].
*
* The generic corresponds to the data type of domain elements.
*
* @param range A two-element array of numeric values.
*/
/**
* Constructs a new point scale with the specified domain and range, no padding, no rounding and center alignment.
* The domain defaults to the empty domain.
*
* The generic corresponds to the data type of domain elements.
*
* @param domain Array of domain values.
* @param range A two-element array of numeric values.
*/
export function scalePoint(...args) {
// ScalePoint is essentially ScaleBand with paddingInner(1)
const scale = scaleBand(...args).paddingInner(1);
// Remove paddingInner method and make padding alias to paddingOuter
const originalCopy = scale.copy;
scale.padding = scale.paddingOuter;
delete scale.paddingInner;
delete scale.paddingOuter;
scale.copy = () => {
const copied = originalCopy();
copied.padding = copied.paddingOuter;
delete copied.paddingInner;
delete copied.paddingOuter;
copied.copy = scale.copy;
return copied;
};
return scale;
}