@visactor/vtable
Version:
canvas table width high performance
45 lines (39 loc) • 3.69 kB
JavaScript
import { LinearScale, LogScale, SymlogScale } from "@visactor/vscale";
import { isFunction, isNil, isNumber, isValid } from "@visactor/vutils";
import { THEME_CONSTANTS } from "../../components/axis/get-axis-attributes";
const DEFAULT_CONTINUOUS_TICK_COUNT = 5;
export function getAxisDomainRangeAndLabels(min, max, axisOption, isZeroAlign, axisLength, target) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
if ((null == axisOption ? void 0 : axisOption.zero) && (min = Math.min(min, 0),
max = Math.max(max, 0)), null == axisOption ? void 0 : axisOption.expand) {
const domainMin = min, domainMax = max;
isValid(axisOption.expand.min) && (min = domainMin - (domainMax - domainMin) * axisOption.expand.min),
isValid(axisOption.expand.max) && (max = domainMax + (domainMax - domainMin) * axisOption.expand.max);
}
let scale, scaleTicks;
if (isNumber(null == axisOption ? void 0 : axisOption.min) && (min = axisOption.min),
isNumber(null == axisOption ? void 0 : axisOption.max) && (max = axisOption.max),
"log" === (null == axisOption ? void 0 : axisOption.type) ? (scale = new LogScale,
scale.base(null !== (_a = null == axisOption ? void 0 : axisOption.base) && void 0 !== _a ? _a : 10)) : "symlog" === (null == axisOption ? void 0 : axisOption.type) ? (scale = new SymlogScale,
scale.constant(null !== (_b = null == axisOption ? void 0 : axisOption.constant) && void 0 !== _b ? _b : 10)) : scale = new LinearScale,
scale.domain([ min, max ], !!(null == axisOption ? void 0 : axisOption.nice)), target) forceTickCountNice(scale, target); else if (null == axisOption ? void 0 : axisOption.nice) {
let tickCount = null !== (_f = null !== (_d = null === (_c = axisOption.tick) || void 0 === _c ? void 0 : _c.forceTickCount) && void 0 !== _d ? _d : null === (_e = axisOption.tick) || void 0 === _e ? void 0 : _e.tickCount) && void 0 !== _f ? _f : 10;
isFunction(tickCount) && (tickCount = tickCount({
axisLength: axisLength,
labelStyle: null !== (_h = null === (_g = null == axisOption ? void 0 : axisOption.label) || void 0 === _g ? void 0 : _g.style) && void 0 !== _h ? _h : {
fontSize: THEME_CONSTANTS.LABEL_FONT_SIZE
}
})), "accurateFirst" === axisOption.niceType && (tickCount = Math.max(10, tickCount)),
isNil(axisOption.min) && isNil(axisOption.max) ? scale.nice(tickCount) : isValid(axisOption.min) && isNil(axisOption.max) ? scale.niceMax(tickCount) : isNil(axisOption.min) && isValid(axisOption.max) && scale.niceMin(tickCount);
}
return delete scale._niceType, scaleTicks = (null !== (_k = null === (_j = null == target ? void 0 : target.targetTicks) || void 0 === _j ? void 0 : _j.length) && void 0 !== _k ? _k : null === (_l = null == axisOption ? void 0 : axisOption.tick) || void 0 === _l ? void 0 : _l.forceTickCount) ? scale.forceTicks(null !== (_o = null === (_m = null == target ? void 0 : target.targetTicks) || void 0 === _m ? void 0 : _m.length) && void 0 !== _o ? _o : null === (_p = null == axisOption ? void 0 : axisOption.tick) || void 0 === _p ? void 0 : _p.forceTickCount) : scale.ticks(isNumber(null === (_q = null == axisOption ? void 0 : axisOption.tick) || void 0 === _q ? void 0 : _q.tickCount) ? axisOption.tick.tickCount : 5, {
noDecimals: null === (_r = null == axisOption ? void 0 : axisOption.tick) || void 0 === _r ? void 0 : _r.noDecimals
}), {
range: scale.domain(),
ticks: scaleTicks
};
}
function forceTickCountNice(scale, target) {
scale.niceMax(target.targetTicks.length);
}
//# sourceMappingURL=get-axis-domain.js.map