UNPKG

@visactor/vscale

Version:

Scales for visual encoding, used in VGrammar, VTable

46 lines (42 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.LogNiceMixin = void 0; const tick_sample_1 = require("./utils/tick-sample"), utils_1 = require("./utils/utils"); class LogNiceMixin { nice(count = 10, option) { var _b, _c, _d, _e; const originalDomain = this._domain; let niceMinMax = [], niceType = null; if (option) { const res = (0, tick_sample_1.parseNiceOptions)(originalDomain, option); if (niceMinMax = res.niceMinMax, this._domainValidator = res.domainValidator, niceType = res.niceType, res.niceDomain) return this._niceDomain = res.niceDomain, this.rescale(), this; } else niceType = "all"; if (niceType) { const niceDomain = (0, utils_1.nice)(originalDomain.slice(), null !== (_c = null === (_b = this.getNiceConfig) || void 0 === _b ? void 0 : _b.call(this)) && void 0 !== _c ? _c : { floor: x => Math.floor(x), ceil: x => Math.ceil(x) }); return "min" === niceType ? niceDomain[niceDomain.length - 1] = null !== (_d = niceMinMax[1]) && void 0 !== _d ? _d : niceDomain[niceDomain.length - 1] : "max" === niceType && (niceDomain[0] = null !== (_e = niceMinMax[0]) && void 0 !== _e ? _e : niceDomain[0]), this._niceDomain = niceDomain, this.rescale(), this; } return this; } niceMin() { const maxD = this._domain[this._domain.length - 1]; this.nice(); const niceDomain = this._domain.slice(); return this._domain && (niceDomain[niceDomain.length - 1] = maxD, this._niceDomain = niceDomain, this.rescale()), this; } niceMax() { const minD = this._domain[0]; this.nice(); const niceDomain = this._domain.slice(); return this._domain && (niceDomain[0] = minD, this._niceDomain = niceDomain, this.rescale()), this; } } exports.LogNiceMixin = LogNiceMixin; //# sourceMappingURL=log-nice-mixin.js.map