UNPKG

@visactor/vtable

Version:

canvas table width high performance

50 lines (44 loc) 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.getAxisDomainRangeAndLabels = void 0; const vscale_1 = require("@visactor/vscale"), vutils_1 = require("@visactor/vutils"), get_axis_attributes_1 = require("../../components/axis/get-axis-attributes"), DEFAULT_CONTINUOUS_TICK_COUNT = 5; 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; (0, vutils_1.isValid)(axisOption.expand.min) && (min = domainMin - (domainMax - domainMin) * axisOption.expand.min), (0, vutils_1.isValid)(axisOption.expand.max) && (max = domainMax + (domainMax - domainMin) * axisOption.expand.max); } let scale, scaleTicks; if ((0, vutils_1.isNumber)(null == axisOption ? void 0 : axisOption.min) && (min = axisOption.min), (0, vutils_1.isNumber)(null == axisOption ? void 0 : axisOption.max) && (max = axisOption.max), "log" === (null == axisOption ? void 0 : axisOption.type) ? (scale = new vscale_1.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 vscale_1.SymlogScale, scale.constant(null !== (_b = null == axisOption ? void 0 : axisOption.constant) && void 0 !== _b ? _b : 10)) : scale = new vscale_1.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; (0, vutils_1.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: get_axis_attributes_1.THEME_CONSTANTS.LABEL_FONT_SIZE } })), "accurateFirst" === axisOption.niceType && (tickCount = Math.max(10, tickCount)), (0, vutils_1.isNil)(axisOption.min) && (0, vutils_1.isNil)(axisOption.max) ? scale.nice(tickCount) : (0, vutils_1.isValid)(axisOption.min) && (0, vutils_1.isNil)(axisOption.max) ? scale.niceMax(tickCount) : (0, vutils_1.isNil)(axisOption.min) && (0, vutils_1.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((0, vutils_1.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); } exports.getAxisDomainRangeAndLabels = getAxisDomainRangeAndLabels; //# sourceMappingURL=get-axis-domain.js.map