index.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1679043784182, function(require, module, exports) {
  8. Object.defineProperty(exports, "__esModule", { value: true });
  9. exports.registerTickMethod = exports.getTickMethod = exports.registerScale = exports.getScale = exports.Scale = exports.Quantize = exports.Quantile = exports.TimeCat = exports.Time = exports.Pow = exports.Log = exports.Linear = exports.Identity = exports.Category = void 0;
  10. var base_1 = require("./base");
  11. exports.Scale = base_1.default;
  12. var base_2 = require("./category/base");
  13. exports.Category = base_2.default;
  14. var time_1 = require("./category/time");
  15. exports.TimeCat = time_1.default;
  16. var linear_1 = require("./continuous/linear");
  17. exports.Linear = linear_1.default;
  18. var log_1 = require("./continuous/log");
  19. exports.Log = log_1.default;
  20. var pow_1 = require("./continuous/pow");
  21. exports.Pow = pow_1.default;
  22. var time_2 = require("./continuous/time");
  23. exports.Time = time_2.default;
  24. var quantize_1 = require("./continuous/quantize");
  25. exports.Quantize = quantize_1.default;
  26. var quantile_1 = require("./continuous/quantile");
  27. exports.Quantile = quantile_1.default;
  28. var factory_1 = require("./factory");
  29. Object.defineProperty(exports, "getScale", { enumerable: true, get: function () { return factory_1.getScale; } });
  30. Object.defineProperty(exports, "registerScale", { enumerable: true, get: function () { return factory_1.registerScale; } });
  31. var index_1 = require("./identity/index");
  32. exports.Identity = index_1.default;
  33. var index_2 = require("./tick-method/index");
  34. Object.defineProperty(exports, "getTickMethod", { enumerable: true, get: function () { return index_2.getTickMethod; } });
  35. Object.defineProperty(exports, "registerTickMethod", { enumerable: true, get: function () { return index_2.registerTickMethod; } });
  36. factory_1.registerScale('cat', base_2.default);
  37. factory_1.registerScale('category', base_2.default);
  38. factory_1.registerScale('identity', index_1.default);
  39. factory_1.registerScale('linear', linear_1.default);
  40. factory_1.registerScale('log', log_1.default);
  41. factory_1.registerScale('pow', pow_1.default);
  42. factory_1.registerScale('time', time_2.default);
  43. factory_1.registerScale('timeCat', time_1.default);
  44. factory_1.registerScale('quantize', quantize_1.default);
  45. factory_1.registerScale('quantile', quantile_1.default);
  46. //# sourceMappingURL=index.js.map
  47. }, function(modId) {var map = {"./base":1679043784183,"./category/base":1679043784185,"./category/time":1679043784186,"./continuous/linear":1679043784189,"./continuous/log":1679043784191,"./continuous/pow":1679043784193,"./continuous/time":1679043784194,"./continuous/quantize":1679043784195,"./continuous/quantile":1679043784196,"./factory":1679043784197,"./identity/index":1679043784198,"./tick-method/index":1679043784199}; return __REQUIRE__(map[modId], modId); })
  48. __DEFINE__(1679043784183, function(require, module, exports) {
  49. Object.defineProperty(exports, "__esModule", { value: true });
  50. var util_1 = require("@antv/util");
  51. var register_1 = require("./tick-method/register");
  52. var Scale = /** @class */ (function () {
  53. function Scale(cfg) {
  54. /**
  55. * 度量的类型
  56. */
  57. this.type = 'base';
  58. /**
  59. * 是否分类类型的度量
  60. */
  61. this.isCategory = false;
  62. /**
  63. * 是否线性度量,有linear, time 度量
  64. */
  65. this.isLinear = false;
  66. /**
  67. * 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持
  68. */
  69. this.isContinuous = false;
  70. /**
  71. * 是否是常量的度量,传入和传出一致
  72. */
  73. this.isIdentity = false;
  74. this.values = [];
  75. this.range = [0, 1];
  76. this.ticks = [];
  77. this.__cfg__ = cfg;
  78. this.initCfg();
  79. this.init();
  80. }
  81. // 对于原始值的必要转换,如分类、时间字段需转换成数值,用transform/map命名可能更好
  82. Scale.prototype.translate = function (v) {
  83. return v;
  84. };
  85. /** 重新初始化 */
  86. Scale.prototype.change = function (cfg) {
  87. // 覆盖配置项,而不替代
  88. util_1.assign(this.__cfg__, cfg);
  89. this.init();
  90. };
  91. Scale.prototype.clone = function () {
  92. return this.constructor(this.__cfg__);
  93. };
  94. /** 获取坐标轴需要的ticks */
  95. Scale.prototype.getTicks = function () {
  96. var _this = this;
  97. return util_1.map(this.ticks, function (tick, idx) {
  98. if (util_1.isObject(tick)) {
  99. // 仅当符合Tick类型时才有意义
  100. return tick;
  101. }
  102. return {
  103. text: _this.getText(tick, idx),
  104. tickValue: tick,
  105. value: _this.scale(tick),
  106. };
  107. });
  108. };
  109. /** 获取Tick的格式化结果 */
  110. Scale.prototype.getText = function (value, key) {
  111. var formatter = this.formatter;
  112. var res = formatter ? formatter(value, key) : value;
  113. if (util_1.isNil(res) || !util_1.isFunction(res.toString)) {
  114. return '';
  115. }
  116. return res.toString();
  117. };
  118. // 获取配置项中的值,当前 scale 上的值可能会被修改
  119. Scale.prototype.getConfig = function (key) {
  120. return this.__cfg__[key];
  121. };
  122. // scale初始化
  123. Scale.prototype.init = function () {
  124. util_1.assign(this, this.__cfg__);
  125. this.setDomain();
  126. if (util_1.isEmpty(this.getConfig('ticks'))) {
  127. this.ticks = this.calculateTicks();
  128. }
  129. };
  130. // 子类上覆盖某些属性,不能直接在类上声明,否则会被覆盖
  131. Scale.prototype.initCfg = function () { };
  132. Scale.prototype.setDomain = function () { };
  133. Scale.prototype.calculateTicks = function () {
  134. var tickMethod = this.tickMethod;
  135. var ticks = [];
  136. if (util_1.isString(tickMethod)) {
  137. var method = register_1.getTickMethod(tickMethod);
  138. if (!method) {
  139. throw new Error('There is no method to to calculate ticks!');
  140. }
  141. ticks = method(this);
  142. }
  143. else if (util_1.isFunction(tickMethod)) {
  144. ticks = tickMethod(this);
  145. }
  146. return ticks;
  147. };
  148. // range 的最小值
  149. Scale.prototype.rangeMin = function () {
  150. return this.range[0];
  151. };
  152. // range 的最大值
  153. Scale.prototype.rangeMax = function () {
  154. return this.range[1];
  155. };
  156. /** 定义域转 0~1 */
  157. Scale.prototype.calcPercent = function (value, min, max) {
  158. if (util_1.isNumber(value)) {
  159. return (value - min) / (max - min);
  160. }
  161. return NaN;
  162. };
  163. /** 0~1转定义域 */
  164. Scale.prototype.calcValue = function (percent, min, max) {
  165. return min + percent * (max - min);
  166. };
  167. return Scale;
  168. }());
  169. exports.default = Scale;
  170. //# sourceMappingURL=base.js.map
  171. }, function(modId) { var map = {"./tick-method/register":1679043784184}; return __REQUIRE__(map[modId], modId); })
  172. __DEFINE__(1679043784184, function(require, module, exports) {
  173. Object.defineProperty(exports, "__esModule", { value: true });
  174. exports.registerTickMethod = exports.getTickMethod = void 0;
  175. var methodCache = {};
  176. /**
  177. * 获取计算 ticks 的方法
  178. * @param key 键值
  179. * @returns 计算 ticks 的方法
  180. */
  181. function getTickMethod(key) {
  182. return methodCache[key];
  183. }
  184. exports.getTickMethod = getTickMethod;
  185. /**
  186. * 注册计算 ticks 的方法
  187. * @param key 键值
  188. * @param method 方法
  189. */
  190. function registerTickMethod(key, method) {
  191. methodCache[key] = method;
  192. }
  193. exports.registerTickMethod = registerTickMethod;
  194. //# sourceMappingURL=register.js.map
  195. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  196. __DEFINE__(1679043784185, function(require, module, exports) {
  197. Object.defineProperty(exports, "__esModule", { value: true });
  198. var tslib_1 = require("tslib");
  199. var util_1 = require("@antv/util");
  200. var base_1 = require("../base");
  201. /**
  202. * 分类度量
  203. * @class
  204. */
  205. var Category = /** @class */ (function (_super) {
  206. tslib_1.__extends(Category, _super);
  207. function Category() {
  208. var _this = _super !== null && _super.apply(this, arguments) || this;
  209. _this.type = 'cat';
  210. _this.isCategory = true;
  211. return _this;
  212. }
  213. Category.prototype.buildIndexMap = function () {
  214. if (!this.translateIndexMap) {
  215. this.translateIndexMap = new Map();
  216. // 重新构建缓存
  217. for (var i = 0; i < this.values.length; i++) {
  218. this.translateIndexMap.set(this.values[i], i);
  219. }
  220. }
  221. };
  222. Category.prototype.translate = function (value) {
  223. // 按需构建 map
  224. this.buildIndexMap();
  225. // 找得到
  226. var idx = this.translateIndexMap.get(value);
  227. if (idx === undefined) {
  228. idx = util_1.isNumber(value) ? value : NaN;
  229. }
  230. return idx;
  231. };
  232. Category.prototype.scale = function (value) {
  233. var order = this.translate(value);
  234. // 分类数据允许 0.5 范围内调整
  235. // if (order < this.min - 0.5 || order > this.max + 0.5) {
  236. // return NaN;
  237. // }
  238. var percent = this.calcPercent(order, this.min, this.max);
  239. return this.calcValue(percent, this.rangeMin(), this.rangeMax());
  240. };
  241. Category.prototype.invert = function (scaledValue) {
  242. var domainRange = this.max - this.min;
  243. var percent = this.calcPercent(scaledValue, this.rangeMin(), this.rangeMax());
  244. var idx = Math.round(domainRange * percent) + this.min;
  245. if (idx < this.min || idx > this.max) {
  246. return NaN;
  247. }
  248. return this.values[idx];
  249. };
  250. Category.prototype.getText = function (value) {
  251. var args = [];
  252. for (var _i = 1; _i < arguments.length; _i++) {
  253. args[_i - 1] = arguments[_i];
  254. }
  255. var v = value;
  256. // value为index
  257. if (util_1.isNumber(value) && !this.values.includes(value)) {
  258. v = this.values[v];
  259. }
  260. return _super.prototype.getText.apply(this, tslib_1.__spreadArrays([v], args));
  261. };
  262. // 复写属性
  263. Category.prototype.initCfg = function () {
  264. this.tickMethod = 'cat';
  265. };
  266. // 设置 min, max
  267. Category.prototype.setDomain = function () {
  268. // 用户有可能设置 min
  269. if (util_1.isNil(this.getConfig('min'))) {
  270. this.min = 0;
  271. }
  272. if (util_1.isNil(this.getConfig('max'))) {
  273. var size = this.values.length;
  274. this.max = size > 1 ? size - 1 : size;
  275. }
  276. // scale.init 的时候清除缓存
  277. if (this.translateIndexMap) {
  278. this.translateIndexMap = undefined;
  279. }
  280. };
  281. return Category;
  282. }(base_1.default));
  283. exports.default = Category;
  284. //# sourceMappingURL=base.js.map
  285. }, function(modId) { var map = {"../base":1679043784183}; return __REQUIRE__(map[modId], modId); })
  286. __DEFINE__(1679043784186, function(require, module, exports) {
  287. Object.defineProperty(exports, "__esModule", { value: true });
  288. var tslib_1 = require("tslib");
  289. var util_1 = require("@antv/util");
  290. var time_1 = require("../util/time");
  291. var base_1 = require("./base");
  292. /**
  293. * 时间分类度量
  294. * @class
  295. */
  296. var TimeCat = /** @class */ (function (_super) {
  297. tslib_1.__extends(TimeCat, _super);
  298. function TimeCat() {
  299. var _this = _super !== null && _super.apply(this, arguments) || this;
  300. _this.type = 'timeCat';
  301. return _this;
  302. }
  303. /**
  304. * @override
  305. */
  306. TimeCat.prototype.translate = function (value) {
  307. value = time_1.toTimeStamp(value);
  308. var index = this.values.indexOf(value);
  309. if (index === -1) {
  310. if (util_1.isNumber(value) && value < this.values.length) {
  311. index = value;
  312. }
  313. else {
  314. index = NaN;
  315. }
  316. }
  317. return index;
  318. };
  319. /**
  320. * 由于时间类型数据需要转换一下,所以复写 getText
  321. * @override
  322. */
  323. TimeCat.prototype.getText = function (value, tickIndex) {
  324. var index = this.translate(value);
  325. if (index > -1) {
  326. var result = this.values[index];
  327. var formatter = this.formatter;
  328. result = formatter ? formatter(result, tickIndex) : time_1.timeFormat(result, this.mask);
  329. return result;
  330. }
  331. return value;
  332. };
  333. TimeCat.prototype.initCfg = function () {
  334. this.tickMethod = 'time-cat';
  335. this.mask = 'YYYY-MM-DD';
  336. this.tickCount = 7; // 一般时间数据会显示 7, 14, 30 天的数字
  337. };
  338. TimeCat.prototype.setDomain = function () {
  339. var values = this.values;
  340. // 针对时间分类类型,会将时间统一转换为时间戳
  341. util_1.each(values, function (v, i) {
  342. values[i] = time_1.toTimeStamp(v);
  343. });
  344. values.sort(function (v1, v2) {
  345. return v1 - v2;
  346. });
  347. _super.prototype.setDomain.call(this);
  348. };
  349. return TimeCat;
  350. }(base_1.default));
  351. exports.default = TimeCat;
  352. //# sourceMappingURL=time.js.map
  353. }, function(modId) { var map = {"../util/time":1679043784187,"./base":1679043784185}; return __REQUIRE__(map[modId], modId); })
  354. __DEFINE__(1679043784187, function(require, module, exports) {
  355. Object.defineProperty(exports, "__esModule", { value: true });
  356. exports.getTickInterval = exports.YEAR = exports.MONTH = exports.DAY = exports.HOUR = exports.MINUTE = exports.SECOND = exports.toTimeStamp = exports.timeFormat = void 0;
  357. var util_1 = require("@antv/util");
  358. var fecha_1 = require("fecha");
  359. var fecha1 = require("fecha");
  360. var bisector_1 = require("./bisector");
  361. var FORMAT_METHOD = 'format';
  362. function timeFormat(time, mask) {
  363. var method = fecha1[FORMAT_METHOD] || fecha_1.default[FORMAT_METHOD];
  364. return method(time, mask);
  365. }
  366. exports.timeFormat = timeFormat;
  367. /**
  368. * 转换成时间戳
  369. * @param value 时间值
  370. */
  371. function toTimeStamp(value) {
  372. if (util_1.isString(value)) {
  373. if (value.indexOf('T') > 0) {
  374. value = new Date(value).getTime();
  375. }
  376. else {
  377. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  378. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  379. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  380. value = new Date(value.replace(/-/gi, '/')).getTime();
  381. }
  382. }
  383. if (util_1.isDate(value)) {
  384. value = value.getTime();
  385. }
  386. return value;
  387. }
  388. exports.toTimeStamp = toTimeStamp;
  389. var SECOND = 1000;
  390. exports.SECOND = SECOND;
  391. var MINUTE = 60 * SECOND;
  392. exports.MINUTE = MINUTE;
  393. var HOUR = 60 * MINUTE;
  394. exports.HOUR = HOUR;
  395. var DAY = 24 * HOUR;
  396. exports.DAY = DAY;
  397. var MONTH = DAY * 31;
  398. exports.MONTH = MONTH;
  399. var YEAR = DAY * 365;
  400. exports.YEAR = YEAR;
  401. var intervals = [
  402. ['HH:mm:ss', SECOND],
  403. ['HH:mm:ss', SECOND * 10],
  404. ['HH:mm:ss', SECOND * 30],
  405. ['HH:mm', MINUTE],
  406. ['HH:mm', MINUTE * 10],
  407. ['HH:mm', MINUTE * 30],
  408. ['HH', HOUR],
  409. ['HH', HOUR * 6],
  410. ['HH', HOUR * 12],
  411. ['YYYY-MM-DD', DAY],
  412. ['YYYY-MM-DD', DAY * 4],
  413. ['YYYY-WW', DAY * 7],
  414. ['YYYY-MM', MONTH],
  415. ['YYYY-MM', MONTH * 4],
  416. ['YYYY-MM', MONTH * 6],
  417. ['YYYY', DAY * 380],
  418. ];
  419. function getTickInterval(min, max, tickCount) {
  420. var target = (max - min) / tickCount;
  421. var idx = bisector_1.default(function (o) { return o[1]; })(intervals, target) - 1;
  422. var interval = intervals[idx];
  423. if (idx < 0) {
  424. interval = intervals[0];
  425. }
  426. else if (idx >= intervals.length) {
  427. interval = util_1.last(intervals);
  428. }
  429. return interval;
  430. }
  431. exports.getTickInterval = getTickInterval;
  432. //# sourceMappingURL=time.js.map
  433. }, function(modId) { var map = {"./bisector":1679043784188}; return __REQUIRE__(map[modId], modId); })
  434. __DEFINE__(1679043784188, function(require, module, exports) {
  435. Object.defineProperty(exports, "__esModule", { value: true });
  436. var util_1 = require("@antv/util");
  437. /**
  438. * 二分右侧查找
  439. * https://github.com/d3/d3-array/blob/master/src/bisector.js
  440. */
  441. function default_1(getter) {
  442. /**
  443. * x: 目标值
  444. * lo: 起始位置
  445. * hi: 结束位置
  446. */
  447. return function (a, x, _lo, _hi) {
  448. var lo = util_1.isNil(_lo) ? 0 : _lo;
  449. var hi = util_1.isNil(_hi) ? a.length : _hi;
  450. while (lo < hi) {
  451. var mid = (lo + hi) >>> 1;
  452. if (getter(a[mid]) > x) {
  453. hi = mid;
  454. }
  455. else {
  456. lo = mid + 1;
  457. }
  458. }
  459. return lo;
  460. };
  461. }
  462. exports.default = default_1;
  463. //# sourceMappingURL=bisector.js.map
  464. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  465. __DEFINE__(1679043784189, function(require, module, exports) {
  466. Object.defineProperty(exports, "__esModule", { value: true });
  467. var tslib_1 = require("tslib");
  468. var base_1 = require("./base");
  469. /**
  470. * 线性度量
  471. * @class
  472. */
  473. var Linear = /** @class */ (function (_super) {
  474. tslib_1.__extends(Linear, _super);
  475. function Linear() {
  476. var _this = _super !== null && _super.apply(this, arguments) || this;
  477. _this.type = 'linear';
  478. _this.isLinear = true;
  479. return _this;
  480. }
  481. Linear.prototype.invert = function (value) {
  482. var percent = this.getInvertPercent(value);
  483. return this.min + percent * (this.max - this.min);
  484. };
  485. Linear.prototype.initCfg = function () {
  486. this.tickMethod = 'wilkinson-extended';
  487. this.nice = false;
  488. };
  489. return Linear;
  490. }(base_1.default));
  491. exports.default = Linear;
  492. //# sourceMappingURL=linear.js.map
  493. }, function(modId) { var map = {"./base":1679043784190}; return __REQUIRE__(map[modId], modId); })
  494. __DEFINE__(1679043784190, function(require, module, exports) {
  495. Object.defineProperty(exports, "__esModule", { value: true });
  496. var tslib_1 = require("tslib");
  497. var util_1 = require("@antv/util");
  498. var base_1 = require("../base");
  499. /**
  500. * 连续度量的基类
  501. * @class
  502. */
  503. var Continuous = /** @class */ (function (_super) {
  504. tslib_1.__extends(Continuous, _super);
  505. function Continuous() {
  506. var _this = _super !== null && _super.apply(this, arguments) || this;
  507. _this.isContinuous = true;
  508. return _this;
  509. }
  510. Continuous.prototype.scale = function (value) {
  511. if (util_1.isNil(value)) {
  512. return NaN;
  513. }
  514. var rangeMin = this.rangeMin();
  515. var rangeMax = this.rangeMax();
  516. var max = this.max;
  517. var min = this.min;
  518. if (max === min) {
  519. return rangeMin;
  520. }
  521. var percent = this.getScalePercent(value);
  522. return rangeMin + percent * (rangeMax - rangeMin);
  523. };
  524. Continuous.prototype.init = function () {
  525. _super.prototype.init.call(this);
  526. // init 完成后保证 min, max 包含 ticks 的范围
  527. var ticks = this.ticks;
  528. var firstTick = util_1.head(ticks);
  529. var lastTick = util_1.last(ticks);
  530. if (firstTick < this.min) {
  531. this.min = firstTick;
  532. }
  533. if (lastTick > this.max) {
  534. this.max = lastTick;
  535. }
  536. // strict-limit 方式
  537. if (!util_1.isNil(this.minLimit)) {
  538. this.min = firstTick;
  539. }
  540. if (!util_1.isNil(this.maxLimit)) {
  541. this.max = lastTick;
  542. }
  543. };
  544. Continuous.prototype.setDomain = function () {
  545. var _a = util_1.getRange(this.values), min = _a.min, max = _a.max;
  546. if (util_1.isNil(this.min)) {
  547. this.min = min;
  548. }
  549. if (util_1.isNil(this.max)) {
  550. this.max = max;
  551. }
  552. if (this.min > this.max) {
  553. this.min = min;
  554. this.max = max;
  555. }
  556. };
  557. Continuous.prototype.calculateTicks = function () {
  558. var _this = this;
  559. var ticks = _super.prototype.calculateTicks.call(this);
  560. if (!this.nice) {
  561. ticks = util_1.filter(ticks, function (tick) {
  562. return tick >= _this.min && tick <= _this.max;
  563. });
  564. }
  565. return ticks;
  566. };
  567. // 计算原始值值占的百分比
  568. Continuous.prototype.getScalePercent = function (value) {
  569. var max = this.max;
  570. var min = this.min;
  571. return (value - min) / (max - min);
  572. };
  573. Continuous.prototype.getInvertPercent = function (value) {
  574. return (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  575. };
  576. return Continuous;
  577. }(base_1.default));
  578. exports.default = Continuous;
  579. //# sourceMappingURL=base.js.map
  580. }, function(modId) { var map = {"../base":1679043784183}; return __REQUIRE__(map[modId], modId); })
  581. __DEFINE__(1679043784191, function(require, module, exports) {
  582. Object.defineProperty(exports, "__esModule", { value: true });
  583. var tslib_1 = require("tslib");
  584. var math_1 = require("../util/math");
  585. var base_1 = require("./base");
  586. /**
  587. * Log 度量,处理非均匀分布
  588. */
  589. var Log = /** @class */ (function (_super) {
  590. tslib_1.__extends(Log, _super);
  591. function Log() {
  592. var _this = _super !== null && _super.apply(this, arguments) || this;
  593. _this.type = 'log';
  594. return _this;
  595. }
  596. /**
  597. * @override
  598. */
  599. Log.prototype.invert = function (value) {
  600. var base = this.base;
  601. var max = math_1.log(base, this.max);
  602. var rangeMin = this.rangeMin();
  603. var range = this.rangeMax() - rangeMin;
  604. var min;
  605. var positiveMin = this.positiveMin;
  606. if (positiveMin) {
  607. if (value === 0) {
  608. return 0;
  609. }
  610. min = math_1.log(base, positiveMin / base);
  611. var appendPercent = (1 / (max - min)) * range; // 0 到 positiveMin的占比
  612. if (value < appendPercent) {
  613. // 落到 0 - positiveMin 之间
  614. return (value / appendPercent) * positiveMin;
  615. }
  616. }
  617. else {
  618. min = math_1.log(base, this.min);
  619. }
  620. var percent = (value - rangeMin) / range;
  621. var tmp = percent * (max - min) + min;
  622. return Math.pow(base, tmp);
  623. };
  624. Log.prototype.initCfg = function () {
  625. this.tickMethod = 'log';
  626. this.base = 10;
  627. this.tickCount = 6;
  628. this.nice = true;
  629. };
  630. // 设置
  631. Log.prototype.setDomain = function () {
  632. _super.prototype.setDomain.call(this);
  633. var min = this.min;
  634. if (min < 0) {
  635. throw new Error('When you use log scale, the minimum value must be greater than zero!');
  636. }
  637. if (min === 0) {
  638. this.positiveMin = math_1.getLogPositiveMin(this.values, this.base, this.max);
  639. }
  640. };
  641. // 根据当前值获取占比
  642. Log.prototype.getScalePercent = function (value) {
  643. var max = this.max;
  644. var min = this.min;
  645. if (max === min) {
  646. return 0;
  647. }
  648. // 如果值小于等于0,则按照0处理
  649. if (value <= 0) {
  650. return 0;
  651. }
  652. var base = this.base;
  653. var positiveMin = this.positiveMin;
  654. // 如果min == 0, 则根据比0大的最小值,计算比例关系。这个最小值作为坐标轴上的第二个tick,第一个是0但是不显示
  655. if (positiveMin) {
  656. min = (positiveMin * 1) / base;
  657. }
  658. var percent;
  659. // 如果数值小于次小值,那么就计算 value / 次小值 占整体的比例
  660. if (value < positiveMin) {
  661. percent = value / positiveMin / (math_1.log(base, max) - math_1.log(base, min));
  662. }
  663. else {
  664. percent = (math_1.log(base, value) - math_1.log(base, min)) / (math_1.log(base, max) - math_1.log(base, min));
  665. }
  666. return percent;
  667. };
  668. return Log;
  669. }(base_1.default));
  670. exports.default = Log;
  671. //# sourceMappingURL=log.js.map
  672. }, function(modId) { var map = {"../util/math":1679043784192,"./base":1679043784190}; return __REQUIRE__(map[modId], modId); })
  673. __DEFINE__(1679043784192, function(require, module, exports) {
  674. Object.defineProperty(exports, "__esModule", { value: true });
  675. exports.precisionAdd = exports.getLogPositiveMin = exports.log = exports.calBase = void 0;
  676. var util_1 = require("@antv/util");
  677. // 求以a为次幂,结果为b的基数,如 x^^a = b;求x
  678. // 虽然数学上 b 不支持负数,但是这里需要支持 负数
  679. function calBase(a, b) {
  680. var e = Math.E;
  681. var value;
  682. if (b >= 0) {
  683. value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  684. }
  685. else {
  686. value = Math.pow(e, Math.log(-b) / a) * -1; // 使用换底公式求底
  687. }
  688. return value;
  689. }
  690. exports.calBase = calBase;
  691. function log(a, b) {
  692. if (a === 1) {
  693. return 1;
  694. }
  695. return Math.log(b) / Math.log(a);
  696. }
  697. exports.log = log;
  698. function getLogPositiveMin(values, base, max) {
  699. if (util_1.isNil(max)) {
  700. max = Math.max.apply(null, values);
  701. }
  702. var positiveMin = max;
  703. util_1.each(values, function (value) {
  704. if (value > 0 && value < positiveMin) {
  705. positiveMin = value;
  706. }
  707. });
  708. if (positiveMin === max) {
  709. positiveMin = max / base;
  710. }
  711. if (positiveMin > 1) {
  712. positiveMin = 1;
  713. }
  714. return positiveMin;
  715. }
  716. exports.getLogPositiveMin = getLogPositiveMin;
  717. function digitLength(num) {
  718. // Get digit length of e
  719. var eSplit = num.toString().split(/[eE]/);
  720. var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
  721. return len > 0 ? len : 0;
  722. }
  723. /**
  724. * 高精度加法,解决 0.1 + 0.2 !== 0.3 的经典问题
  725. *
  726. * @param num1 加数
  727. * @param num2 被加数
  728. * @return {number} 返回值
  729. */
  730. function precisionAdd(num1, num2) {
  731. var num1Digits = digitLength(num1);
  732. var num2Digits = digitLength(num2);
  733. var baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
  734. return (num1 * baseNum + num2 * baseNum) / baseNum;
  735. }
  736. exports.precisionAdd = precisionAdd;
  737. //# sourceMappingURL=math.js.map
  738. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  739. __DEFINE__(1679043784193, function(require, module, exports) {
  740. Object.defineProperty(exports, "__esModule", { value: true });
  741. var tslib_1 = require("tslib");
  742. var math_1 = require("../util/math");
  743. var base_1 = require("./base");
  744. /**
  745. * Pow 度量,处理非均匀分布
  746. */
  747. var Pow = /** @class */ (function (_super) {
  748. tslib_1.__extends(Pow, _super);
  749. function Pow() {
  750. var _this = _super !== null && _super.apply(this, arguments) || this;
  751. _this.type = 'pow';
  752. return _this;
  753. }
  754. /**
  755. * @override
  756. */
  757. Pow.prototype.invert = function (value) {
  758. var percent = this.getInvertPercent(value);
  759. var exponent = this.exponent;
  760. var max = math_1.calBase(exponent, this.max);
  761. var min = math_1.calBase(exponent, this.min);
  762. var tmp = percent * (max - min) + min;
  763. var factor = tmp >= 0 ? 1 : -1;
  764. return Math.pow(tmp, exponent) * factor;
  765. };
  766. Pow.prototype.initCfg = function () {
  767. this.tickMethod = 'pow';
  768. this.exponent = 2;
  769. this.tickCount = 5;
  770. this.nice = true;
  771. };
  772. // 获取度量计算时,value占的定义域百分比
  773. Pow.prototype.getScalePercent = function (value) {
  774. var max = this.max;
  775. var min = this.min;
  776. if (max === min) {
  777. return 0;
  778. }
  779. var exponent = this.exponent;
  780. var percent = (math_1.calBase(exponent, value) - math_1.calBase(exponent, min)) / (math_1.calBase(exponent, max) - math_1.calBase(exponent, min));
  781. return percent;
  782. };
  783. return Pow;
  784. }(base_1.default));
  785. exports.default = Pow;
  786. //# sourceMappingURL=pow.js.map
  787. }, function(modId) { var map = {"../util/math":1679043784192,"./base":1679043784190}; return __REQUIRE__(map[modId], modId); })
  788. __DEFINE__(1679043784194, function(require, module, exports) {
  789. Object.defineProperty(exports, "__esModule", { value: true });
  790. var tslib_1 = require("tslib");
  791. var util_1 = require("@antv/util");
  792. var time_1 = require("../util/time");
  793. var linear_1 = require("./linear");
  794. /**
  795. * 时间度量
  796. * @class
  797. */
  798. var Time = /** @class */ (function (_super) {
  799. tslib_1.__extends(Time, _super);
  800. function Time() {
  801. var _this = _super !== null && _super.apply(this, arguments) || this;
  802. _this.type = 'time';
  803. return _this;
  804. }
  805. /**
  806. * @override
  807. */
  808. Time.prototype.getText = function (value, index) {
  809. var numberValue = this.translate(value);
  810. var formatter = this.formatter;
  811. return formatter ? formatter(numberValue, index) : time_1.timeFormat(numberValue, this.mask);
  812. };
  813. /**
  814. * @override
  815. */
  816. Time.prototype.scale = function (value) {
  817. var v = value;
  818. if (util_1.isString(v) || util_1.isDate(v)) {
  819. v = this.translate(v);
  820. }
  821. return _super.prototype.scale.call(this, v);
  822. };
  823. /**
  824. * 将时间转换成数字
  825. * @override
  826. */
  827. Time.prototype.translate = function (v) {
  828. return time_1.toTimeStamp(v);
  829. };
  830. Time.prototype.initCfg = function () {
  831. this.tickMethod = 'time-pretty';
  832. this.mask = 'YYYY-MM-DD';
  833. this.tickCount = 7;
  834. this.nice = false;
  835. };
  836. Time.prototype.setDomain = function () {
  837. var values = this.values;
  838. // 是否设置了 min, max,而不是直接取 this.min, this.max
  839. var minConfig = this.getConfig('min');
  840. var maxConfig = this.getConfig('max');
  841. // 如果设置了 min,max 则转换成时间戳
  842. if (!util_1.isNil(minConfig) || !util_1.isNumber(minConfig)) {
  843. this.min = this.translate(this.min);
  844. }
  845. if (!util_1.isNil(maxConfig) || !util_1.isNumber(maxConfig)) {
  846. this.max = this.translate(this.max);
  847. }
  848. // 没有设置 min, max 时
  849. if (values && values.length) {
  850. // 重新计算最大最小值
  851. var timeStamps_1 = [];
  852. var min_1 = Infinity; // 最小值
  853. var secondMin_1 = min_1; // 次小值
  854. var max_1 = 0;
  855. // 使用一个循环,计算min,max,secondMin
  856. util_1.each(values, function (v) {
  857. var timeStamp = time_1.toTimeStamp(v);
  858. if (isNaN(timeStamp)) {
  859. throw new TypeError("Invalid Time: " + v + " in time scale!");
  860. }
  861. if (min_1 > timeStamp) {
  862. secondMin_1 = min_1;
  863. min_1 = timeStamp;
  864. }
  865. else if (secondMin_1 > timeStamp) {
  866. secondMin_1 = timeStamp;
  867. }
  868. if (max_1 < timeStamp) {
  869. max_1 = timeStamp;
  870. }
  871. timeStamps_1.push(timeStamp);
  872. });
  873. // 存在多个值时,设置最小间距
  874. if (values.length > 1) {
  875. this.minTickInterval = secondMin_1 - min_1;
  876. }
  877. if (util_1.isNil(minConfig)) {
  878. this.min = min_1;
  879. }
  880. if (util_1.isNil(maxConfig)) {
  881. this.max = max_1;
  882. }
  883. }
  884. };
  885. return Time;
  886. }(linear_1.default));
  887. exports.default = Time;
  888. //# sourceMappingURL=time.js.map
  889. }, function(modId) { var map = {"../util/time":1679043784187,"./linear":1679043784189}; return __REQUIRE__(map[modId], modId); })
  890. __DEFINE__(1679043784195, function(require, module, exports) {
  891. Object.defineProperty(exports, "__esModule", { value: true });
  892. var tslib_1 = require("tslib");
  893. var util_1 = require("@antv/util");
  894. var base_1 = require("./base");
  895. /**
  896. * 分段度量
  897. */
  898. var Quantize = /** @class */ (function (_super) {
  899. tslib_1.__extends(Quantize, _super);
  900. function Quantize() {
  901. var _this = _super !== null && _super.apply(this, arguments) || this;
  902. _this.type = 'quantize';
  903. return _this;
  904. }
  905. Quantize.prototype.invert = function (value) {
  906. var ticks = this.ticks;
  907. var length = ticks.length;
  908. var percent = this.getInvertPercent(value);
  909. var minIndex = Math.floor(percent * (length - 1));
  910. // 最后一个
  911. if (minIndex >= length - 1) {
  912. return util_1.last(ticks);
  913. }
  914. // 超出左边界, 则取第一个
  915. if (minIndex < 0) {
  916. return util_1.head(ticks);
  917. }
  918. var minTick = ticks[minIndex];
  919. var nextTick = ticks[minIndex + 1];
  920. // 比当前值小的 tick 在度量上的占比
  921. var minIndexPercent = minIndex / (length - 1);
  922. var maxIndexPercent = (minIndex + 1) / (length - 1);
  923. return minTick + (percent - minIndexPercent) / (maxIndexPercent - minIndexPercent) * (nextTick - minTick);
  924. };
  925. Quantize.prototype.initCfg = function () {
  926. this.tickMethod = 'r-pretty';
  927. this.tickCount = 5;
  928. this.nice = true;
  929. };
  930. Quantize.prototype.calculateTicks = function () {
  931. var ticks = _super.prototype.calculateTicks.call(this);
  932. if (!this.nice) { // 如果 nice = false ,补充 min, max
  933. if (util_1.last(ticks) !== this.max) {
  934. ticks.push(this.max);
  935. }
  936. if (util_1.head(ticks) !== this.min) {
  937. ticks.unshift(this.min);
  938. }
  939. }
  940. return ticks;
  941. };
  942. // 计算当前值在刻度中的占比
  943. Quantize.prototype.getScalePercent = function (value) {
  944. var ticks = this.ticks;
  945. // 超出左边界
  946. if (value < util_1.head(ticks)) {
  947. return 0;
  948. }
  949. // 超出右边界
  950. if (value > util_1.last(ticks)) {
  951. return 1;
  952. }
  953. var minIndex = 0;
  954. util_1.each(ticks, function (tick, index) {
  955. if (value >= tick) {
  956. minIndex = index;
  957. }
  958. else {
  959. return false;
  960. }
  961. });
  962. return minIndex / (ticks.length - 1);
  963. };
  964. return Quantize;
  965. }(base_1.default));
  966. exports.default = Quantize;
  967. //# sourceMappingURL=quantize.js.map
  968. }, function(modId) { var map = {"./base":1679043784190}; return __REQUIRE__(map[modId], modId); })
  969. __DEFINE__(1679043784196, function(require, module, exports) {
  970. Object.defineProperty(exports, "__esModule", { value: true });
  971. var tslib_1 = require("tslib");
  972. var quantize_1 = require("./quantize");
  973. var Quantile = /** @class */ (function (_super) {
  974. tslib_1.__extends(Quantile, _super);
  975. function Quantile() {
  976. var _this = _super !== null && _super.apply(this, arguments) || this;
  977. _this.type = 'quantile';
  978. return _this;
  979. }
  980. Quantile.prototype.initCfg = function () {
  981. this.tickMethod = 'quantile';
  982. this.tickCount = 5;
  983. this.nice = true;
  984. };
  985. return Quantile;
  986. }(quantize_1.default));
  987. exports.default = Quantile;
  988. //# sourceMappingURL=quantile.js.map
  989. }, function(modId) { var map = {"./quantize":1679043784195}; return __REQUIRE__(map[modId], modId); })
  990. __DEFINE__(1679043784197, function(require, module, exports) {
  991. Object.defineProperty(exports, "__esModule", { value: true });
  992. exports.registerScale = exports.getScale = exports.Scale = void 0;
  993. var base_1 = require("./base");
  994. exports.Scale = base_1.default;
  995. var map = {};
  996. function getClass(key) {
  997. return map[key];
  998. }
  999. exports.getScale = getClass;
  1000. function registerClass(key, cls) {
  1001. if (getClass(key)) {
  1002. throw new Error("type '" + key + "' existed.");
  1003. }
  1004. map[key] = cls;
  1005. }
  1006. exports.registerScale = registerClass;
  1007. //# sourceMappingURL=factory.js.map
  1008. }, function(modId) { var map = {"./base":1679043784183}; return __REQUIRE__(map[modId], modId); })
  1009. __DEFINE__(1679043784198, function(require, module, exports) {
  1010. Object.defineProperty(exports, "__esModule", { value: true });
  1011. var tslib_1 = require("tslib");
  1012. var util_1 = require("@antv/util");
  1013. var base_1 = require("../base");
  1014. /**
  1015. * identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
  1016. * 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
  1017. * 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
  1018. */
  1019. var Identity = /** @class */ (function (_super) {
  1020. tslib_1.__extends(Identity, _super);
  1021. function Identity() {
  1022. var _this = _super !== null && _super.apply(this, arguments) || this;
  1023. _this.type = 'identity';
  1024. _this.isIdentity = true;
  1025. return _this;
  1026. }
  1027. Identity.prototype.calculateTicks = function () {
  1028. return this.values;
  1029. };
  1030. Identity.prototype.scale = function (value) {
  1031. // 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
  1032. if (this.values[0] !== value && util_1.isNumber(value)) {
  1033. return value;
  1034. }
  1035. return this.range[0];
  1036. };
  1037. Identity.prototype.invert = function (value) {
  1038. var range = this.range;
  1039. if (value < range[0] || value > range[1]) {
  1040. return NaN;
  1041. }
  1042. return this.values[0];
  1043. };
  1044. return Identity;
  1045. }(base_1.default));
  1046. exports.default = Identity;
  1047. //# sourceMappingURL=index.js.map
  1048. }, function(modId) { var map = {"../base":1679043784183}; return __REQUIRE__(map[modId], modId); })
  1049. __DEFINE__(1679043784199, function(require, module, exports) {
  1050. Object.defineProperty(exports, "__esModule", { value: true });
  1051. exports.registerTickMethod = exports.getTickMethod = void 0;
  1052. var cat_1 = require("./cat");
  1053. var d3_linear_1 = require("./d3-linear");
  1054. var linear_1 = require("./linear");
  1055. var log_1 = require("./log");
  1056. var pow_1 = require("./pow");
  1057. var quantile_1 = require("./quantile");
  1058. var r_prettry_1 = require("./r-prettry");
  1059. var register_1 = require("./register");
  1060. Object.defineProperty(exports, "getTickMethod", { enumerable: true, get: function () { return register_1.getTickMethod; } });
  1061. Object.defineProperty(exports, "registerTickMethod", { enumerable: true, get: function () { return register_1.registerTickMethod; } });
  1062. var time_1 = require("./time");
  1063. var time_cat_1 = require("./time-cat");
  1064. var time_pretty_1 = require("./time-pretty");
  1065. register_1.registerTickMethod('cat', cat_1.default);
  1066. register_1.registerTickMethod('time-cat', time_cat_1.default);
  1067. register_1.registerTickMethod('wilkinson-extended', linear_1.default);
  1068. register_1.registerTickMethod('r-pretty', r_prettry_1.default);
  1069. register_1.registerTickMethod('time', time_1.default);
  1070. register_1.registerTickMethod('time-pretty', time_pretty_1.default);
  1071. register_1.registerTickMethod('log', log_1.default);
  1072. register_1.registerTickMethod('pow', pow_1.default);
  1073. register_1.registerTickMethod('quantile', quantile_1.default);
  1074. register_1.registerTickMethod('d3-linear', d3_linear_1.default);
  1075. //# sourceMappingURL=index.js.map
  1076. }, function(modId) { var map = {"./cat":1679043784200,"./d3-linear":1679043784201,"./linear":1679043784205,"./log":1679043784208,"./pow":1679043784209,"./quantile":1679043784211,"./r-prettry":1679043784212,"./register":1679043784184,"./time":1679043784213,"./time-cat":1679043784214,"./time-pretty":1679043784215}; return __REQUIRE__(map[modId], modId); })
  1077. __DEFINE__(1679043784200, function(require, module, exports) {
  1078. Object.defineProperty(exports, "__esModule", { value: true });
  1079. var util_1 = require("@antv/util");
  1080. /**
  1081. * 计算分类 ticks
  1082. * @param cfg 度量的配置项
  1083. * @returns 计算后的 ticks
  1084. */
  1085. function calculateCatTicks(cfg) {
  1086. var values = cfg.values, tickInterval = cfg.tickInterval, tickCount = cfg.tickCount, showLast = cfg.showLast;
  1087. if (util_1.isNumber(tickInterval)) {
  1088. var ticks_1 = util_1.filter(values, function (__, i) { return i % tickInterval === 0; });
  1089. var lastValue = util_1.last(values);
  1090. if (showLast && util_1.last(ticks_1) !== lastValue) {
  1091. ticks_1.push(lastValue);
  1092. }
  1093. return ticks_1;
  1094. }
  1095. var len = values.length;
  1096. var min = cfg.min, max = cfg.max;
  1097. if (util_1.isNil(min)) {
  1098. min = 0;
  1099. }
  1100. if (util_1.isNil(max)) {
  1101. max = values.length - 1;
  1102. }
  1103. if (!util_1.isNumber(tickCount) || tickCount >= len)
  1104. return values.slice(min, max + 1);
  1105. if (tickCount <= 0 || max <= 0)
  1106. return [];
  1107. var interval = tickCount === 1 ? len : Math.floor(len / (tickCount - 1));
  1108. var ticks = [];
  1109. var idx = min;
  1110. for (var i = 0; i < tickCount; i++) {
  1111. if (idx >= max)
  1112. break;
  1113. idx = Math.min(min + i * interval, max);
  1114. if (i === tickCount - 1 && showLast)
  1115. ticks.push(values[max]);
  1116. else
  1117. ticks.push(values[idx]);
  1118. }
  1119. return ticks;
  1120. }
  1121. exports.default = calculateCatTicks;
  1122. //# sourceMappingURL=cat.js.map
  1123. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1124. __DEFINE__(1679043784201, function(require, module, exports) {
  1125. Object.defineProperty(exports, "__esModule", { value: true });
  1126. var util_1 = require("@antv/util");
  1127. var d3_linear_1 = require("../util/d3-linear");
  1128. var interval_1 = require("../util/interval");
  1129. var strict_limit_1 = require("../util/strict-limit");
  1130. function d3LinearTickMethod(cfg) {
  1131. var min = cfg.min, max = cfg.max, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  1132. var ticks = d3_linear_1.default(cfg);
  1133. if (!util_1.isNil(minLimit) || !util_1.isNil(maxLimit)) {
  1134. return strict_limit_1.default(cfg, util_1.head(ticks), util_1.last(ticks));
  1135. }
  1136. if (tickInterval) {
  1137. return interval_1.default(min, max, tickInterval).ticks;
  1138. }
  1139. return ticks;
  1140. }
  1141. exports.default = d3LinearTickMethod;
  1142. //# sourceMappingURL=d3-linear.js.map
  1143. }, function(modId) { var map = {"../util/d3-linear":1679043784202,"../util/interval":1679043784203,"../util/strict-limit":1679043784204}; return __REQUIRE__(map[modId], modId); })
  1144. __DEFINE__(1679043784202, function(require, module, exports) {
  1145. Object.defineProperty(exports, "__esModule", { value: true });
  1146. exports.D3Linear = void 0;
  1147. function d3Linear(cfg) {
  1148. var min = cfg.min, max = cfg.max, nice = cfg.nice, tickCount = cfg.tickCount;
  1149. var linear = new D3Linear();
  1150. linear.domain([min, max]);
  1151. if (nice) {
  1152. linear.nice(tickCount);
  1153. }
  1154. return linear.ticks(tickCount);
  1155. }
  1156. exports.default = d3Linear;
  1157. var DEFAULT_COUNT = 5;
  1158. var e10 = Math.sqrt(50);
  1159. var e5 = Math.sqrt(10);
  1160. var e2 = Math.sqrt(2);
  1161. // https://github.com/d3/d3-scale
  1162. var D3Linear = /** @class */ (function () {
  1163. function D3Linear() {
  1164. this._domain = [0, 1];
  1165. }
  1166. D3Linear.prototype.domain = function (domain) {
  1167. if (domain) {
  1168. this._domain = Array.from(domain, Number);
  1169. return this;
  1170. }
  1171. return this._domain.slice();
  1172. };
  1173. D3Linear.prototype.nice = function (count) {
  1174. var _a, _b;
  1175. if (count === void 0) { count = DEFAULT_COUNT; }
  1176. var d = this._domain.slice();
  1177. var i0 = 0;
  1178. var i1 = this._domain.length - 1;
  1179. var start = this._domain[i0];
  1180. var stop = this._domain[i1];
  1181. var step;
  1182. if (stop < start) {
  1183. _a = [stop, start], start = _a[0], stop = _a[1];
  1184. _b = [i1, i0], i0 = _b[0], i1 = _b[1];
  1185. }
  1186. step = tickIncrement(start, stop, count);
  1187. if (step > 0) {
  1188. start = Math.floor(start / step) * step;
  1189. stop = Math.ceil(stop / step) * step;
  1190. step = tickIncrement(start, stop, count);
  1191. }
  1192. else if (step < 0) {
  1193. start = Math.ceil(start * step) / step;
  1194. stop = Math.floor(stop * step) / step;
  1195. step = tickIncrement(start, stop, count);
  1196. }
  1197. if (step > 0) {
  1198. d[i0] = Math.floor(start / step) * step;
  1199. d[i1] = Math.ceil(stop / step) * step;
  1200. this.domain(d);
  1201. }
  1202. else if (step < 0) {
  1203. d[i0] = Math.ceil(start * step) / step;
  1204. d[i1] = Math.floor(stop * step) / step;
  1205. this.domain(d);
  1206. }
  1207. return this;
  1208. };
  1209. D3Linear.prototype.ticks = function (count) {
  1210. if (count === void 0) { count = DEFAULT_COUNT; }
  1211. return d3ArrayTicks(this._domain[0], this._domain[this._domain.length - 1], count || DEFAULT_COUNT);
  1212. };
  1213. return D3Linear;
  1214. }());
  1215. exports.D3Linear = D3Linear;
  1216. function d3ArrayTicks(start, stop, count) {
  1217. var reverse;
  1218. var i = -1;
  1219. var n;
  1220. var ticks;
  1221. var step;
  1222. (stop = +stop), (start = +start), (count = +count);
  1223. if (start === stop && count > 0) {
  1224. return [start];
  1225. }
  1226. // tslint:disable-next-line
  1227. if ((reverse = stop < start)) {
  1228. (n = start), (start = stop), (stop = n);
  1229. }
  1230. // tslint:disable-next-line
  1231. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) {
  1232. return [];
  1233. }
  1234. if (step > 0) {
  1235. start = Math.ceil(start / step);
  1236. stop = Math.floor(stop / step);
  1237. ticks = new Array((n = Math.ceil(stop - start + 1)));
  1238. while (++i < n) {
  1239. ticks[i] = (start + i) * step;
  1240. }
  1241. }
  1242. else {
  1243. start = Math.floor(start * step);
  1244. stop = Math.ceil(stop * step);
  1245. ticks = new Array((n = Math.ceil(start - stop + 1)));
  1246. while (++i < n) {
  1247. ticks[i] = (start - i) / step;
  1248. }
  1249. }
  1250. if (reverse) {
  1251. ticks.reverse();
  1252. }
  1253. return ticks;
  1254. }
  1255. function tickIncrement(start, stop, count) {
  1256. var step = (stop - start) / Math.max(0, count);
  1257. var power = Math.floor(Math.log(step) / Math.LN10);
  1258. var error = step / Math.pow(10, power);
  1259. return power >= 0
  1260. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  1261. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  1262. }
  1263. //# sourceMappingURL=d3-linear.js.map
  1264. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1265. __DEFINE__(1679043784203, function(require, module, exports) {
  1266. Object.defineProperty(exports, "__esModule", { value: true });
  1267. var util_1 = require("@antv/util");
  1268. function snapMultiple(v, base, snapType) {
  1269. var div;
  1270. if (snapType === 'ceil') {
  1271. div = Math.ceil(v / base);
  1272. }
  1273. else if (snapType === 'floor') {
  1274. div = Math.floor(v / base);
  1275. }
  1276. else {
  1277. div = Math.round(v / base);
  1278. }
  1279. return div * base;
  1280. }
  1281. function intervalTicks(min, max, interval) {
  1282. // 变成 interval 的倍数
  1283. var minTick = snapMultiple(min, interval, 'floor');
  1284. var maxTick = snapMultiple(max, interval, 'ceil');
  1285. // 统一小数位数
  1286. minTick = util_1.fixedBase(minTick, interval);
  1287. maxTick = util_1.fixedBase(maxTick, interval);
  1288. var ticks = [];
  1289. // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
  1290. var availableInterval = Math.max((maxTick - minTick) / (Math.pow(2, 12) - 1), interval);
  1291. for (var i = minTick; i <= maxTick; i = i + availableInterval) {
  1292. var tickValue = util_1.fixedBase(i, availableInterval); // 防止浮点数加法出现问题
  1293. ticks.push(tickValue);
  1294. }
  1295. return {
  1296. min: minTick,
  1297. max: maxTick,
  1298. ticks: ticks
  1299. };
  1300. }
  1301. exports.default = intervalTicks;
  1302. //# sourceMappingURL=interval.js.map
  1303. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1304. __DEFINE__(1679043784204, function(require, module, exports) {
  1305. Object.defineProperty(exports, "__esModule", { value: true });
  1306. var util_1 = require("@antv/util");
  1307. /**
  1308. * 按照给定的 minLimit/maxLimit/tickCount 均匀计算出刻度 ticks
  1309. *
  1310. * @param cfg Scale 配置项
  1311. * @return ticks
  1312. */
  1313. function strictLimit(cfg, defaultMin, defaultMax) {
  1314. var _a;
  1315. var minLimit = cfg.minLimit, maxLimit = cfg.maxLimit, min = cfg.min, max = cfg.max, _b = cfg.tickCount, tickCount = _b === void 0 ? 5 : _b;
  1316. var tickMin = util_1.isNil(minLimit) ? (util_1.isNil(defaultMin) ? min : defaultMin) : minLimit;
  1317. var tickMax = util_1.isNil(maxLimit) ? (util_1.isNil(defaultMax) ? max : defaultMax) : maxLimit;
  1318. if (tickMin > tickMax) {
  1319. _a = [tickMin, tickMax], tickMax = _a[0], tickMin = _a[1];
  1320. }
  1321. if (tickCount <= 2) {
  1322. return [tickMin, tickMax];
  1323. }
  1324. var step = (tickMax - tickMin) / (tickCount - 1);
  1325. var ticks = [];
  1326. for (var i = 0; i < tickCount; i++) {
  1327. ticks.push(tickMin + step * i);
  1328. }
  1329. return ticks;
  1330. }
  1331. exports.default = strictLimit;
  1332. //# sourceMappingURL=strict-limit.js.map
  1333. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1334. __DEFINE__(1679043784205, function(require, module, exports) {
  1335. Object.defineProperty(exports, "__esModule", { value: true });
  1336. var util_1 = require("@antv/util");
  1337. var extended_1 = require("../util/extended");
  1338. var interval_1 = require("../util/interval");
  1339. var strict_limit_1 = require("../util/strict-limit");
  1340. /**
  1341. * 计算线性的 ticks,使用 wilkinson extended 方法
  1342. * @param cfg 度量的配置项
  1343. * @returns 计算后的 ticks
  1344. */
  1345. function linear(cfg) {
  1346. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, nice = cfg.nice, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  1347. var ticks = extended_1.default(min, max, tickCount, nice).ticks;
  1348. if (!util_1.isNil(minLimit) || !util_1.isNil(maxLimit)) {
  1349. return strict_limit_1.default(cfg, util_1.head(ticks), util_1.last(ticks));
  1350. }
  1351. if (tickInterval) {
  1352. return interval_1.default(min, max, tickInterval).ticks;
  1353. }
  1354. return ticks;
  1355. }
  1356. exports.default = linear;
  1357. //# sourceMappingURL=linear.js.map
  1358. }, function(modId) { var map = {"../util/extended":1679043784206,"../util/interval":1679043784203,"../util/strict-limit":1679043784204}; return __REQUIRE__(map[modId], modId); })
  1359. __DEFINE__(1679043784206, function(require, module, exports) {
  1360. Object.defineProperty(exports, "__esModule", { value: true });
  1361. exports.ALL_Q = exports.DEFAULT_Q = void 0;
  1362. var util_1 = require("@antv/util");
  1363. var pretty_number_1 = require("./pretty-number");
  1364. exports.DEFAULT_Q = [1, 5, 2, 2.5, 4, 3];
  1365. exports.ALL_Q = [1, 5, 2, 2.5, 4, 3, 1.5, 7, 6, 8, 9];
  1366. var eps = Number.EPSILON * 100;
  1367. function mod(n, m) {
  1368. return ((n % m) + m) % m;
  1369. }
  1370. function round(n) {
  1371. return Math.round(n * 1e12) / 1e12;
  1372. }
  1373. function simplicity(q, Q, j, lmin, lmax, lstep) {
  1374. var n = util_1.size(Q);
  1375. var i = util_1.indexOf(Q, q);
  1376. var v = 0;
  1377. var m = mod(lmin, lstep);
  1378. if ((m < eps || lstep - m < eps) && lmin <= 0 && lmax >= 0) {
  1379. v = 1;
  1380. }
  1381. return 1 - i / (n - 1) - j + v;
  1382. }
  1383. function simplicityMax(q, Q, j) {
  1384. var n = util_1.size(Q);
  1385. var i = util_1.indexOf(Q, q);
  1386. var v = 1;
  1387. return 1 - i / (n - 1) - j + v;
  1388. }
  1389. function density(k, m, dMin, dMax, lMin, lMax) {
  1390. var r = (k - 1) / (lMax - lMin);
  1391. var rt = (m - 1) / (Math.max(lMax, dMax) - Math.min(dMin, lMin));
  1392. return 2 - Math.max(r / rt, rt / r);
  1393. }
  1394. function densityMax(k, m) {
  1395. if (k >= m) {
  1396. return 2 - (k - 1) / (m - 1);
  1397. }
  1398. return 1;
  1399. }
  1400. function coverage(dMin, dMax, lMin, lMax) {
  1401. var range = dMax - dMin;
  1402. return 1 - (0.5 * (Math.pow((dMax - lMax), 2) + Math.pow((dMin - lMin), 2))) / Math.pow((0.1 * range), 2);
  1403. }
  1404. function coverageMax(dMin, dMax, span) {
  1405. var range = dMax - dMin;
  1406. if (span > range) {
  1407. var half = (span - range) / 2;
  1408. return 1 - Math.pow(half, 2) / Math.pow((0.1 * range), 2);
  1409. }
  1410. return 1;
  1411. }
  1412. function legibility() {
  1413. return 1;
  1414. }
  1415. /**
  1416. * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes
  1417. * https://www.yuque.com/preview/yuque/0/2019/pdf/185317/1546999150858-45c3b9c2-4e86-4223-bf1a-8a732e8195ed.pdf
  1418. * @param dMin 最小值
  1419. * @param dMax 最大值
  1420. * @param m tick个数
  1421. * @param onlyLoose 是否允许扩展min、max,不绝对强制,例如[3, 97]
  1422. * @param Q nice numbers集合
  1423. * @param w 四个优化组件的权重
  1424. */
  1425. function extended(dMin, dMax, n, onlyLoose, Q, w) {
  1426. if (n === void 0) { n = 5; }
  1427. if (onlyLoose === void 0) { onlyLoose = true; }
  1428. if (Q === void 0) { Q = exports.DEFAULT_Q; }
  1429. if (w === void 0) { w = [0.25, 0.2, 0.5, 0.05]; }
  1430. // 处理小于 0 和小数的 tickCount
  1431. var m = n < 0 ? 0 : Math.round(n);
  1432. // nan 也会导致异常
  1433. if (Number.isNaN(dMin) || Number.isNaN(dMax) || typeof dMin !== 'number' || typeof dMax !== 'number' || !m) {
  1434. return {
  1435. min: 0,
  1436. max: 0,
  1437. ticks: [],
  1438. };
  1439. }
  1440. // js 极大值极小值问题,差值小于 1e-15 会导致计算出错
  1441. if (dMax - dMin < 1e-15 || m === 1) {
  1442. return {
  1443. min: dMin,
  1444. max: dMax,
  1445. ticks: [dMin],
  1446. };
  1447. }
  1448. // js 超大值问题
  1449. if (dMax - dMin > 1e148) {
  1450. var count = n || 5;
  1451. var step_1 = (dMax - dMin) / count;
  1452. return {
  1453. min: dMin,
  1454. max: dMax,
  1455. ticks: Array(count).fill(null).map(function (_, idx) {
  1456. return pretty_number_1.prettyNumber(dMin + step_1 * idx);
  1457. }),
  1458. };
  1459. }
  1460. var best = {
  1461. score: -2,
  1462. lmin: 0,
  1463. lmax: 0,
  1464. lstep: 0,
  1465. };
  1466. var j = 1;
  1467. while (j < Infinity) {
  1468. for (var i = 0; i < Q.length; i += 1) {
  1469. var q = Q[i];
  1470. var sm = simplicityMax(q, Q, j);
  1471. if (w[0] * sm + w[1] + w[2] + w[3] < best.score) {
  1472. j = Infinity;
  1473. break;
  1474. }
  1475. var k = 2;
  1476. while (k < Infinity) {
  1477. var dm = densityMax(k, m);
  1478. if (w[0] * sm + w[1] + w[2] * dm + w[3] < best.score) {
  1479. break;
  1480. }
  1481. var delta = (dMax - dMin) / (k + 1) / j / q;
  1482. var z = Math.ceil(Math.log10(delta));
  1483. while (z < Infinity) {
  1484. var step = j * q * Math.pow(10, z);
  1485. var cm = coverageMax(dMin, dMax, step * (k - 1));
  1486. if (w[0] * sm + w[1] * cm + w[2] * dm + w[3] < best.score) {
  1487. break;
  1488. }
  1489. var minStart = Math.floor(dMax / step) * j - (k - 1) * j;
  1490. var maxStart = Math.ceil(dMin / step) * j;
  1491. if (minStart <= maxStart) {
  1492. var count = maxStart - minStart;
  1493. for (var i_1 = 0; i_1 <= count; i_1 += 1) {
  1494. var start = minStart + i_1;
  1495. var lMin = start * (step / j);
  1496. var lMax = lMin + step * (k - 1);
  1497. var lStep = step;
  1498. var s = simplicity(q, Q, j, lMin, lMax, lStep);
  1499. var c = coverage(dMin, dMax, lMin, lMax);
  1500. var g = density(k, m, dMin, dMax, lMin, lMax);
  1501. var l = legibility();
  1502. var score = w[0] * s + w[1] * c + w[2] * g + w[3] * l;
  1503. if (score > best.score && (!onlyLoose || (lMin <= dMin && lMax >= dMax))) {
  1504. best.lmin = lMin;
  1505. best.lmax = lMax;
  1506. best.lstep = lStep;
  1507. best.score = score;
  1508. }
  1509. }
  1510. }
  1511. z += 1;
  1512. }
  1513. k += 1;
  1514. }
  1515. }
  1516. j += 1;
  1517. }
  1518. // 处理精度问题,保证这三个数没有精度问题
  1519. var lmax = pretty_number_1.prettyNumber(best.lmax);
  1520. var lmin = pretty_number_1.prettyNumber(best.lmin);
  1521. var lstep = pretty_number_1.prettyNumber(best.lstep);
  1522. // 加 round 是为处理 extended(0.94, 1, 5)
  1523. // 保证生成的 tickCount 没有精度问题
  1524. var tickCount = Math.floor(round((lmax - lmin) / lstep)) + 1;
  1525. var ticks = new Array(tickCount);
  1526. // 少用乘法:防止出现 -1.2 + 1.2 * 3 = 2.3999999999999995 的情况
  1527. ticks[0] = pretty_number_1.prettyNumber(lmin);
  1528. for (var i = 1; i < tickCount; i++) {
  1529. ticks[i] = pretty_number_1.prettyNumber(ticks[i - 1] + lstep);
  1530. }
  1531. return {
  1532. min: Math.min(dMin, util_1.head(ticks)),
  1533. max: Math.max(dMax, util_1.last(ticks)),
  1534. ticks: ticks,
  1535. };
  1536. }
  1537. exports.default = extended;
  1538. //# sourceMappingURL=extended.js.map
  1539. }, function(modId) { var map = {"./pretty-number":1679043784207}; return __REQUIRE__(map[modId], modId); })
  1540. __DEFINE__(1679043784207, function(require, module, exports) {
  1541. Object.defineProperty(exports, "__esModule", { value: true });
  1542. exports.prettyNumber = void 0;
  1543. // 为了解决 js 运算的精度问题
  1544. function prettyNumber(n) {
  1545. return Math.abs(n) < 1e-15 ? n : parseFloat(n.toFixed(15));
  1546. }
  1547. exports.prettyNumber = prettyNumber;
  1548. //# sourceMappingURL=pretty-number.js.map
  1549. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1550. __DEFINE__(1679043784208, function(require, module, exports) {
  1551. Object.defineProperty(exports, "__esModule", { value: true });
  1552. var math_1 = require("../util/math");
  1553. /**
  1554. * 计算 log 的 ticks,考虑 min = 0 的场景
  1555. * @param cfg 度量的配置项
  1556. * @returns 计算后的 ticks
  1557. */
  1558. function calculateLogTicks(cfg) {
  1559. var base = cfg.base, tickCount = cfg.tickCount, min = cfg.min, max = cfg.max, values = cfg.values;
  1560. var minTick;
  1561. var maxTick = math_1.log(base, max);
  1562. if (min > 0) {
  1563. minTick = Math.floor(math_1.log(base, min));
  1564. }
  1565. else {
  1566. var positiveMin = math_1.getLogPositiveMin(values, base, max);
  1567. minTick = Math.floor(math_1.log(base, positiveMin));
  1568. }
  1569. var count = maxTick - minTick;
  1570. var avg = Math.ceil(count / tickCount);
  1571. var ticks = [];
  1572. for (var i = minTick; i < maxTick + avg; i = i + avg) {
  1573. ticks.push(Math.pow(base, i));
  1574. }
  1575. if (min <= 0) {
  1576. // 最小值 <= 0 时显示 0
  1577. ticks.unshift(0);
  1578. }
  1579. return ticks;
  1580. }
  1581. exports.default = calculateLogTicks;
  1582. //# sourceMappingURL=log.js.map
  1583. }, function(modId) { var map = {"../util/math":1679043784192}; return __REQUIRE__(map[modId], modId); })
  1584. __DEFINE__(1679043784209, function(require, module, exports) {
  1585. Object.defineProperty(exports, "__esModule", { value: true });
  1586. var math_1 = require("../util/math");
  1587. var pretty_1 = require("../util/pretty");
  1588. /**
  1589. * 计算 Pow 的 ticks
  1590. * @param cfg 度量的配置项
  1591. * @returns 计算后的 ticks
  1592. */
  1593. function calculatePowTicks(cfg) {
  1594. var exponent = cfg.exponent, tickCount = cfg.tickCount;
  1595. var max = Math.ceil(math_1.calBase(exponent, cfg.max));
  1596. var min = Math.floor(math_1.calBase(exponent, cfg.min));
  1597. var ticks = pretty_1.default(min, max, tickCount).ticks;
  1598. return ticks.map(function (tick) {
  1599. var factor = tick >= 0 ? 1 : -1;
  1600. return Math.pow(tick, exponent) * factor;
  1601. });
  1602. }
  1603. exports.default = calculatePowTicks;
  1604. //# sourceMappingURL=pow.js.map
  1605. }, function(modId) { var map = {"../util/math":1679043784192,"../util/pretty":1679043784210}; return __REQUIRE__(map[modId], modId); })
  1606. __DEFINE__(1679043784210, function(require, module, exports) {
  1607. Object.defineProperty(exports, "__esModule", { value: true });
  1608. var pretty_number_1 = require("./pretty-number");
  1609. function pretty(min, max, m) {
  1610. if (m === void 0) { m = 5; }
  1611. if (min === max) {
  1612. return {
  1613. max: max,
  1614. min: min,
  1615. ticks: [min],
  1616. };
  1617. }
  1618. var n = m < 0 ? 0 : Math.round(m);
  1619. if (n === 0)
  1620. return { max: max, min: min, ticks: [] };
  1621. /*
  1622. R pretty:
  1623. https://svn.r-project.org/R/trunk/src/appl/pretty.c
  1624. https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/pretty
  1625. */
  1626. var h = 1.5; // high.u.bias
  1627. var h5 = 0.5 + 1.5 * h; // u5.bias
  1628. // 反正我也不会调参,跳过所有判断步骤
  1629. var d = max - min;
  1630. var c = d / n;
  1631. // 当d非常小的时候触发,但似乎没什么用
  1632. // const min_n = Math.floor(n / 3);
  1633. // const shrink_sml = Math.pow(2, 5);
  1634. // if (Math.log10(d) < -2) {
  1635. // c = (_.max([ Math.abs(max), Math.abs(min) ]) * shrink_sml) / min_n;
  1636. // }
  1637. var base = Math.pow(10, Math.floor(Math.log10(c)));
  1638. var unit = base;
  1639. if (2 * base - c < h * (c - unit)) {
  1640. unit = 2 * base;
  1641. if (5 * base - c < h5 * (c - unit)) {
  1642. unit = 5 * base;
  1643. if (10 * base - c < h * (c - unit)) {
  1644. unit = 10 * base;
  1645. }
  1646. }
  1647. }
  1648. var nu = Math.ceil(max / unit);
  1649. var ns = Math.floor(min / unit);
  1650. var hi = Math.max(nu * unit, max);
  1651. var lo = Math.min(ns * unit, min);
  1652. var size = Math.floor((hi - lo) / unit) + 1;
  1653. var ticks = new Array(size);
  1654. for (var i = 0; i < size; i++) {
  1655. ticks[i] = pretty_number_1.prettyNumber(lo + i * unit);
  1656. }
  1657. return {
  1658. min: lo,
  1659. max: hi,
  1660. ticks: ticks,
  1661. };
  1662. }
  1663. exports.default = pretty;
  1664. //# sourceMappingURL=pretty.js.map
  1665. }, function(modId) { var map = {"./pretty-number":1679043784207}; return __REQUIRE__(map[modId], modId); })
  1666. __DEFINE__(1679043784211, function(require, module, exports) {
  1667. Object.defineProperty(exports, "__esModule", { value: true });
  1668. /**
  1669. * 计算几分位 https://github.com/simple-statistics/simple-statistics/blob/master/src/quantile_sorted.js
  1670. * @param x 数组
  1671. * @param p 百分比
  1672. */
  1673. function quantileSorted(x, p) {
  1674. var idx = x.length * p;
  1675. /*if (x.length === 0) { // 当前场景这些条件不可能命中
  1676. throw new Error('quantile requires at least one value.');
  1677. } else if (p < 0 || p > 1) {
  1678. throw new Error('quantiles must be between 0 and 1');
  1679. } else */
  1680. if (p === 1) {
  1681. // If p is 1, directly return the last element
  1682. return x[x.length - 1];
  1683. }
  1684. else if (p === 0) {
  1685. // If p is 0, directly return the first element
  1686. return x[0];
  1687. }
  1688. else if (idx % 1 !== 0) {
  1689. // If p is not integer, return the next element in array
  1690. return x[Math.ceil(idx) - 1];
  1691. }
  1692. else if (x.length % 2 === 0) {
  1693. // If the list has even-length, we'll take the average of this number
  1694. // and the next value, if there is one
  1695. return (x[idx - 1] + x[idx]) / 2;
  1696. }
  1697. else {
  1698. // Finally, in the simple case of an integer value
  1699. // with an odd-length list, return the x value at the index.
  1700. return x[idx];
  1701. }
  1702. }
  1703. function calculateTicks(cfg) {
  1704. var tickCount = cfg.tickCount, values = cfg.values;
  1705. if (!values || !values.length) {
  1706. return [];
  1707. }
  1708. var sorted = values.slice().sort(function (a, b) {
  1709. return a - b;
  1710. });
  1711. var ticks = [];
  1712. for (var i = 0; i < tickCount; i++) {
  1713. var p = i / (tickCount - 1);
  1714. ticks.push(quantileSorted(sorted, p));
  1715. }
  1716. return ticks;
  1717. }
  1718. exports.default = calculateTicks;
  1719. //# sourceMappingURL=quantile.js.map
  1720. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1721. __DEFINE__(1679043784212, function(require, module, exports) {
  1722. Object.defineProperty(exports, "__esModule", { value: true });
  1723. var util_1 = require("@antv/util");
  1724. var interval_1 = require("../util/interval");
  1725. var pretty_1 = require("../util/pretty");
  1726. var strict_limit_1 = require("../util/strict-limit");
  1727. /**
  1728. * 计算线性的 ticks,使用 R's pretty 方法
  1729. * @param cfg 度量的配置项
  1730. * @returns 计算后的 ticks
  1731. */
  1732. function linearPretty(cfg) {
  1733. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  1734. var ticks = pretty_1.default(min, max, tickCount).ticks;
  1735. if (!util_1.isNil(minLimit) || !util_1.isNil(maxLimit)) {
  1736. return strict_limit_1.default(cfg, util_1.head(ticks), util_1.last(ticks));
  1737. }
  1738. if (tickInterval) {
  1739. return interval_1.default(min, max, tickInterval).ticks;
  1740. }
  1741. return ticks;
  1742. }
  1743. exports.default = linearPretty;
  1744. //# sourceMappingURL=r-prettry.js.map
  1745. }, function(modId) { var map = {"../util/interval":1679043784203,"../util/pretty":1679043784210,"../util/strict-limit":1679043784204}; return __REQUIRE__(map[modId], modId); })
  1746. __DEFINE__(1679043784213, function(require, module, exports) {
  1747. Object.defineProperty(exports, "__esModule", { value: true });
  1748. var time_1 = require("../util/time");
  1749. function calculateTimeTicks(cfg) {
  1750. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval;
  1751. var tickInterval = cfg.tickInterval;
  1752. var tickCount = cfg.tickCount;
  1753. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  1754. if (tickInterval) {
  1755. tickCount = Math.ceil((max - min) / tickInterval);
  1756. }
  1757. else {
  1758. tickInterval = time_1.getTickInterval(min, max, tickCount)[1];
  1759. var count = (max - min) / tickInterval;
  1760. var ratio = count / tickCount;
  1761. if (ratio > 1) {
  1762. tickInterval = tickInterval * Math.ceil(ratio);
  1763. }
  1764. // 如果设置了最小间距,则使用最小间距
  1765. if (minTickInterval && tickInterval < minTickInterval) {
  1766. tickInterval = minTickInterval;
  1767. }
  1768. }
  1769. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  1770. var ticks = [];
  1771. for (var i = min; i < max + tickInterval; i += tickInterval) {
  1772. ticks.push(i);
  1773. }
  1774. return ticks;
  1775. }
  1776. exports.default = calculateTimeTicks;
  1777. //# sourceMappingURL=time.js.map
  1778. }, function(modId) { var map = {"../util/time":1679043784187}; return __REQUIRE__(map[modId], modId); })
  1779. __DEFINE__(1679043784214, function(require, module, exports) {
  1780. Object.defineProperty(exports, "__esModule", { value: true });
  1781. var tslib_1 = require("tslib");
  1782. var cat_1 = require("./cat");
  1783. /**
  1784. * 计算时间分类的 ticks, 保头,保尾
  1785. * @param cfg 度量的配置项
  1786. * @returns 计算后的 ticks
  1787. */
  1788. function timeCat(cfg) {
  1789. // 默认保留最后一条
  1790. var ticks = cat_1.default(tslib_1.__assign({ showLast: true }, cfg));
  1791. return ticks;
  1792. }
  1793. exports.default = timeCat;
  1794. //# sourceMappingURL=time-cat.js.map
  1795. }, function(modId) { var map = {"./cat":1679043784200}; return __REQUIRE__(map[modId], modId); })
  1796. __DEFINE__(1679043784215, function(require, module, exports) {
  1797. Object.defineProperty(exports, "__esModule", { value: true });
  1798. var time_1 = require("../util/time");
  1799. function getYear(date) {
  1800. return new Date(date).getFullYear();
  1801. }
  1802. function createYear(year) {
  1803. return new Date(year, 0, 1).getTime();
  1804. }
  1805. function getMonth(date) {
  1806. return new Date(date).getMonth();
  1807. }
  1808. function diffMonth(min, max) {
  1809. var minYear = getYear(min);
  1810. var maxYear = getYear(max);
  1811. var minMonth = getMonth(min);
  1812. var maxMonth = getMonth(max);
  1813. return (maxYear - minYear) * 12 + ((maxMonth - minMonth) % 12);
  1814. }
  1815. function creatMonth(year, month) {
  1816. return new Date(year, month, 1).getTime();
  1817. }
  1818. function diffDay(min, max) {
  1819. return Math.ceil((max - min) / time_1.DAY);
  1820. }
  1821. function diffHour(min, max) {
  1822. return Math.ceil((max - min) / time_1.HOUR);
  1823. }
  1824. function diffMinus(min, max) {
  1825. return Math.ceil((max - min) / (60 * 1000));
  1826. }
  1827. /**
  1828. * 计算 time 的 ticks,对 month, year 进行 pretty 处理
  1829. * @param cfg 度量的配置项
  1830. * @returns 计算后的 ticks
  1831. */
  1832. function timePretty(cfg) {
  1833. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval, tickCount = cfg.tickCount;
  1834. var tickInterval = cfg.tickInterval;
  1835. var ticks = [];
  1836. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  1837. if (!tickInterval) {
  1838. tickInterval = (max - min) / tickCount;
  1839. // 如果设置了最小间距,则使用最小间距
  1840. if (minTickInterval && tickInterval < minTickInterval) {
  1841. tickInterval = minTickInterval;
  1842. }
  1843. }
  1844. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  1845. var minYear = getYear(min);
  1846. // 如果间距大于 1 年,则将开始日期从整年开始
  1847. if (tickInterval > time_1.YEAR) {
  1848. var maxYear = getYear(max);
  1849. var yearInterval = Math.ceil(tickInterval / time_1.YEAR);
  1850. for (var i = minYear; i <= maxYear + yearInterval; i = i + yearInterval) {
  1851. ticks.push(createYear(i));
  1852. }
  1853. }
  1854. else if (tickInterval > time_1.MONTH) {
  1855. // 大于月时
  1856. var monthInterval = Math.ceil(tickInterval / time_1.MONTH);
  1857. var mmMoth = getMonth(min);
  1858. var dMonths = diffMonth(min, max);
  1859. for (var i = 0; i <= dMonths + monthInterval; i = i + monthInterval) {
  1860. ticks.push(creatMonth(minYear, i + mmMoth));
  1861. }
  1862. }
  1863. else if (tickInterval > time_1.DAY) {
  1864. // 大于天
  1865. var date = new Date(min);
  1866. var year = date.getFullYear();
  1867. var month = date.getMonth();
  1868. var mday = date.getDate();
  1869. var day = Math.ceil(tickInterval / time_1.DAY);
  1870. var ddays = diffDay(min, max);
  1871. for (var i = 0; i < ddays + day; i = i + day) {
  1872. ticks.push(new Date(year, month, mday + i).getTime());
  1873. }
  1874. }
  1875. else if (tickInterval > time_1.HOUR) {
  1876. // 大于小时
  1877. var date = new Date(min);
  1878. var year = date.getFullYear();
  1879. var month = date.getMonth();
  1880. var day = date.getDate();
  1881. var hour = date.getHours();
  1882. var hours = Math.ceil(tickInterval / time_1.HOUR);
  1883. var dHours = diffHour(min, max);
  1884. for (var i = 0; i <= dHours + hours; i = i + hours) {
  1885. ticks.push(new Date(year, month, day, hour + i).getTime());
  1886. }
  1887. }
  1888. else if (tickInterval > time_1.MINUTE) {
  1889. // 大于分钟
  1890. var dMinus = diffMinus(min, max);
  1891. var minutes = Math.ceil(tickInterval / time_1.MINUTE);
  1892. for (var i = 0; i <= dMinus + minutes; i = i + minutes) {
  1893. ticks.push(min + i * time_1.MINUTE);
  1894. }
  1895. }
  1896. else {
  1897. // 小于分钟
  1898. var interval = tickInterval;
  1899. if (interval < time_1.SECOND) {
  1900. interval = time_1.SECOND;
  1901. }
  1902. var minSecond = Math.floor(min / time_1.SECOND) * time_1.SECOND;
  1903. var dSeconds = Math.ceil((max - min) / time_1.SECOND);
  1904. var seconds = Math.ceil(interval / time_1.SECOND);
  1905. for (var i = 0; i < dSeconds + seconds; i = i + seconds) {
  1906. ticks.push(minSecond + i * time_1.SECOND);
  1907. }
  1908. }
  1909. // 最好是能从算法能解决这个问题,但是如果指定了 tickInterval,计算 ticks,也只能这么算,所以
  1910. // 打印警告提示
  1911. if (ticks.length >= 512) {
  1912. console.warn("Notice: current ticks length(" + ticks.length + ") >= 512, may cause performance issues, even out of memory. Because of the configure \"tickInterval\"(in milliseconds, current is " + tickInterval + ") is too small, increase the value to solve the problem!");
  1913. }
  1914. return ticks;
  1915. }
  1916. exports.default = timePretty;
  1917. //# sourceMappingURL=time-pretty.js.map
  1918. }, function(modId) { var map = {"../util/time":1679043784187}; return __REQUIRE__(map[modId], modId); })
  1919. return __REQUIRE__(1679043784182);
  1920. })()
  1921. //miniprogram-npm-outsideDeps=["@antv/util","tslib","fecha"]
  1922. //# sourceMappingURL=index.js.map