index.js 67 KB

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