UNPKG

@antv/g2

Version:

the Grammar of Graphics in Javascript

25 lines 844 B
import { get, set } from '@antv/util'; /** * Convert a percentage string to a ratio. */ export const percentToRatio = (gap) => { if (!gap || typeof gap !== 'string') { return gap; } const value = gap.endsWith('%') ? parseFloat(gap.slice(0, -1)) / 100 : parseFloat(gap); if (isNaN(value) || value < 0 || value > 1) { throw new Error(`Invalid gap value: ${gap}. It should be between 0 and 1.`); } return value; }; export function axisBreaks(options) { const { axis } = options; const breaks = get(axis, 'y.breaks'); if (breaks) { set(options, 'scale.y.breaks', breaks.map((item) => (Object.assign(Object.assign({ key: `break-${item.start}-${item.end}` }, item), { gap: percentToRatio(item.gap) })))); } return options; } //# sourceMappingURL=axis-breaks.js.map