scale.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["scale"] = factory();
  8. else
  9. root["scale"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 13);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports, __webpack_require__) {
  79. var mix = __webpack_require__(16);
  80. var each = __webpack_require__(1);
  81. var isObject = __webpack_require__(7);
  82. var isNil = __webpack_require__(2);
  83. var Scale =
  84. /*#__PURE__*/
  85. function () {
  86. var _proto = Scale.prototype;
  87. _proto._initDefaultCfg = function _initDefaultCfg() {
  88. this.type = 'base';
  89. /**
  90. * 格式化函数,输出文本或者tick时的格式化函数
  91. * @type {Function}
  92. */
  93. this.formatter = null;
  94. /**
  95. * 输出的值域
  96. * @type {Array}
  97. */
  98. this.range = [0, 1];
  99. /**
  100. * 度量的标记
  101. * @type {Array}
  102. */
  103. this.ticks = null;
  104. /**
  105. * 参与度量计算的值,可选项
  106. * @type {Array}
  107. */
  108. this.values = [];
  109. };
  110. function Scale(cfg) {
  111. this._initDefaultCfg();
  112. mix(this, cfg);
  113. this.init();
  114. }
  115. /**
  116. * 度量初始化
  117. * @protected
  118. */
  119. _proto.init = function init() {};
  120. /**
  121. * 获取该度量的ticks,返回的是多个对象,
  122. * - text: tick 的文本
  123. * - value: 对应的度量转换后的值
  124. * <code>
  125. * [
  126. * {text: 0,value:0}
  127. * {text: 1,value:0.2}
  128. * {text: 2,value:0.4}
  129. * {text: 3,value:0.6}
  130. * {text: 4,value:0.8}
  131. * {text: 5,value:1}
  132. * ]
  133. * </code>
  134. * @param {Number} count 输出tick的个数的近似值,默认是 10
  135. * @return {Array} 返回 ticks 数组
  136. */
  137. _proto.getTicks = function getTicks() {
  138. var self = this;
  139. var ticks = self.ticks;
  140. var rst = [];
  141. each(ticks, function (tick) {
  142. var obj;
  143. if (isObject(tick)) {
  144. obj = tick;
  145. } else {
  146. obj = {
  147. text: self.getText(tick),
  148. tickValue: tick,
  149. value: self.scale(tick)
  150. };
  151. }
  152. rst.push(obj);
  153. });
  154. return rst;
  155. };
  156. /**
  157. * 获取格式化后的文本
  158. * @param {*} value 输入的数据
  159. * @param {*} key 字段的 key
  160. * @return {String} 格式化的文本
  161. */
  162. _proto.getText = function getText(value, key) {
  163. var formatter = this.formatter;
  164. value = formatter ? formatter(value, key) : value;
  165. if (isNil(value) || !value.toString) {
  166. value = '';
  167. }
  168. return value.toString();
  169. };
  170. /**
  171. * 输出的值域最小值
  172. * @protected
  173. * @return {Number} 返回最小的值
  174. */
  175. _proto.rangeMin = function rangeMin() {
  176. return this.range[0];
  177. };
  178. /**
  179. * 输出的值域最大值
  180. * @protected
  181. * @return {Number} 返回最大的值
  182. */
  183. _proto.rangeMax = function rangeMax() {
  184. var range = this.range;
  185. return range[range.length - 1];
  186. };
  187. /**
  188. * 度量转换后的结果,翻转回输入域
  189. * @param {Number} value 需要翻转的数值
  190. * @return {*} 度量的输入值
  191. */
  192. _proto.invert = function invert(value) {
  193. return value;
  194. };
  195. /**
  196. * 将传入的值从非数值转换成数值格式,如分类字符串、时间字符串等
  197. * @param {*} value 传入的值
  198. * @return {Number} 转换的值
  199. */
  200. _proto.translate = function translate(value) {
  201. return value;
  202. };
  203. /**
  204. * 进行度量转换
  205. * @param {*} value 输入值
  206. * @return {Number} 输出值,在设定的输出值域之间,默认[0,1]
  207. */
  208. _proto.scale = function scale(value) {
  209. return value;
  210. };
  211. /**
  212. * 克隆一个新的scale,拥有跟当前scale相同的输入域、输出域等
  213. * @return {Scale} 克隆的度量
  214. */
  215. _proto.clone = function clone() {
  216. var self = this;
  217. var constr = self.constructor;
  218. var cfg = {};
  219. each(self, function (v, k) {
  220. cfg[k] = self[k];
  221. });
  222. return new constr(cfg);
  223. };
  224. /**
  225. * 更改度量的属性信息
  226. * @param {Object} info 属性信息
  227. * @chainable
  228. * @return {Scale} 返回自身的引用
  229. */
  230. _proto.change = function change(info) {
  231. this.ticks = null;
  232. mix(this, info);
  233. this.init();
  234. return this;
  235. };
  236. return Scale;
  237. }();
  238. module.exports = Scale;
  239. /***/ }),
  240. /* 1 */
  241. /***/ (function(module, exports, __webpack_require__) {
  242. var isObject = __webpack_require__(7);
  243. var isArray = __webpack_require__(17);
  244. var each = function each(elements, func) {
  245. if (!elements) {
  246. return;
  247. }
  248. var rst = void 0;
  249. if (isArray(elements)) {
  250. for (var i = 0, len = elements.length; i < len; i++) {
  251. rst = func(elements[i], i);
  252. if (rst === false) {
  253. break;
  254. }
  255. }
  256. } else if (isObject(elements)) {
  257. for (var k in elements) {
  258. if (elements.hasOwnProperty(k)) {
  259. rst = func(elements[k], k);
  260. if (rst === false) {
  261. break;
  262. }
  263. }
  264. }
  265. }
  266. };
  267. module.exports = each;
  268. /***/ }),
  269. /* 2 */
  270. /***/ (function(module, exports) {
  271. // isFinite,
  272. var isNil = function isNil(value) {
  273. /**
  274. * isNil(null) => true
  275. * isNil() => true
  276. */
  277. return value === null || value === undefined;
  278. };
  279. module.exports = isNil;
  280. /***/ }),
  281. /* 3 */
  282. /***/ (function(module, exports) {
  283. var toString = {}.toString;
  284. var isType = function isType(value, type) {
  285. return toString.call(value) === '[object ' + type + ']';
  286. };
  287. module.exports = isType;
  288. /***/ }),
  289. /* 4 */
  290. /***/ (function(module, exports, __webpack_require__) {
  291. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  292. /**
  293. * @fileOverview The measurement of linear data scale function
  294. * @author dxq613@gmail.com
  295. */
  296. var isNil = __webpack_require__(2);
  297. var each = __webpack_require__(1);
  298. var Base = __webpack_require__(0);
  299. var numberAuto = __webpack_require__(18);
  300. /**
  301. * 线性度量
  302. * @class Scale.Linear
  303. */
  304. var Linear =
  305. /*#__PURE__*/
  306. function (_Base) {
  307. _inheritsLoose(Linear, _Base);
  308. function Linear() {
  309. return _Base.apply(this, arguments) || this;
  310. }
  311. var _proto = Linear.prototype;
  312. _proto._initDefaultCfg = function _initDefaultCfg() {
  313. _Base.prototype._initDefaultCfg.call(this);
  314. var self = this;
  315. self.type = 'linear';
  316. self.isLinear = true;
  317. /**
  318. * 是否为了用户习惯,优化min,max和ticks,如果进行优化,则会根据生成的ticks调整min,max,否则舍弃(min,max)范围之外的ticks
  319. * @type {Boolean}
  320. * @default false
  321. */
  322. self.nice = false;
  323. /**
  324. * min value of the scale
  325. * @type {Number}
  326. * @default null
  327. */
  328. self.min = null;
  329. /**
  330. * min value limitted of the scale
  331. * @type {Number}
  332. * @default null
  333. */
  334. self.minLimit = null;
  335. /**
  336. * max value of the scale
  337. * @type {Number}
  338. * @default null
  339. */
  340. self.max = null;
  341. /**
  342. * max value limitted of the scale
  343. * @type {Number}
  344. * @default null
  345. */
  346. self.maxLimit = null;
  347. /**
  348. * 自动生成标记时的个数
  349. * @type {Number}
  350. * @default null
  351. */
  352. self.tickCount = null;
  353. /**
  354. * 坐标轴点之间的间距,指的是真实数据的差值
  355. * @type {Number}
  356. * @default null
  357. */
  358. self.tickInterval = null;
  359. /**
  360. * 坐标轴点之间的最小间距,指的是真实数据的差值
  361. * @type {Number}
  362. * @default null
  363. */
  364. self.minTickInterval = null;
  365. /**
  366. * 用于计算坐标点时逼近的数组
  367. * @type {Array}
  368. */
  369. self.snapArray = null;
  370. };
  371. /**
  372. * @protected
  373. * @override
  374. */
  375. _proto.init = function init() {
  376. var self = this;
  377. if (!self.ticks) {
  378. self.min = self.translate(self.min);
  379. self.max = self.translate(self.max);
  380. self.initTicks();
  381. } else {
  382. var ticks = self.ticks;
  383. var firstValue = self.translate(ticks[0]);
  384. var lastValue = self.translate(ticks[ticks.length - 1]);
  385. if (isNil(self.min) || self.min > firstValue) {
  386. self.min = firstValue;
  387. }
  388. if (isNil(self.max) || self.max < lastValue) {
  389. self.max = lastValue;
  390. }
  391. }
  392. };
  393. /**
  394. * 计算坐标点
  395. * @protected
  396. * @return {Array} 计算完成的坐标点
  397. */
  398. _proto.calculateTicks = function calculateTicks() {
  399. var min = this.min,
  400. max = this.max,
  401. minLimit = this.minLimit,
  402. maxLimit = this.maxLimit,
  403. tickCount = this.tickCount,
  404. tickInterval = this.tickInterval,
  405. minTickInterval = this.minTickInterval,
  406. snapArray = this.snapArray;
  407. if (tickCount === 1) {
  408. throw new Error('linear scale\'tickCount should not be 1');
  409. }
  410. if (max < min) {
  411. throw new Error("max: " + max + " should not be less than min: " + min);
  412. }
  413. var tmp = numberAuto({
  414. min: min,
  415. max: max,
  416. minLimit: minLimit,
  417. maxLimit: maxLimit,
  418. minCount: tickCount,
  419. maxCount: tickCount,
  420. interval: tickInterval,
  421. minTickInterval: minTickInterval,
  422. snapArray: snapArray
  423. });
  424. return tmp.ticks;
  425. }; // 初始化ticks
  426. _proto.initTicks = function initTicks() {
  427. var self = this;
  428. var calTicks = self.calculateTicks();
  429. if (self.nice) {
  430. // 如果需要优化显示的tick
  431. self.ticks = calTicks;
  432. self.min = calTicks[0];
  433. self.max = calTicks[calTicks.length - 1];
  434. } else {
  435. var ticks = [];
  436. each(calTicks, function (tick) {
  437. if (tick >= self.min && tick <= self.max) {
  438. ticks.push(tick);
  439. }
  440. }); // 如果 ticks 为空,直接输入最小值、最大值
  441. if (!ticks.length) {
  442. ticks.push(self.min);
  443. ticks.push(self.max);
  444. }
  445. self.ticks = ticks;
  446. }
  447. };
  448. /**
  449. * @override
  450. */
  451. _proto.scale = function scale(value) {
  452. if (isNil(value)) {
  453. return NaN;
  454. }
  455. var max = this.max;
  456. var min = this.min;
  457. if (max === min) {
  458. return 0;
  459. }
  460. var percent = (value - min) / (max - min);
  461. var rangeMin = this.rangeMin();
  462. var rangeMax = this.rangeMax();
  463. return rangeMin + percent * (rangeMax - rangeMin);
  464. };
  465. /**
  466. * @override
  467. */
  468. _proto.invert = function invert(value) {
  469. var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  470. return this.min + percent * (this.max - this.min);
  471. };
  472. return Linear;
  473. }(Base);
  474. Base.Linear = Linear;
  475. module.exports = Linear;
  476. /***/ }),
  477. /* 5 */
  478. /***/ (function(module, exports, __webpack_require__) {
  479. /**
  480. * 判断是否数字
  481. * @return {Boolean} 是否数字
  482. */
  483. var isType = __webpack_require__(3);
  484. var isNumber = function isNumber(value) {
  485. return isType(value, 'Number');
  486. };
  487. module.exports = isNumber;
  488. /***/ }),
  489. /* 6 */
  490. /***/ (function(module, exports, __webpack_require__) {
  491. var isType = __webpack_require__(3);
  492. var isString = function isString(str) {
  493. return isType(str, 'String');
  494. };
  495. module.exports = isString;
  496. /***/ }),
  497. /* 7 */
  498. /***/ (function(module, exports) {
  499. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  500. return typeof obj;
  501. } : function (obj) {
  502. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  503. };
  504. var isObject = function isObject(value) {
  505. /**
  506. * isObject({}) => true
  507. * isObject([1, 2, 3]) => true
  508. * isObject(Function) => true
  509. * isObject(null) => false
  510. */
  511. var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
  512. return value !== null && type === 'object' || type === 'function';
  513. };
  514. module.exports = isObject;
  515. /***/ }),
  516. /* 8 */
  517. /***/ (function(module, exports) {
  518. /**
  519. * @fileOverview 计算方法
  520. * @author dxq613@gmail.com
  521. */
  522. // 如果小数点后面超过 10 位浮点数时进行一下处理
  523. var DECIMAL_LENGTH = 12; // 获取系数
  524. function getFactor(v) {
  525. var factor = 1;
  526. if (v === Infinity || v === -Infinity) {
  527. throw new Error('Not support Infinity!');
  528. }
  529. if (v < 1) {
  530. var count = 0;
  531. while (v < 1) {
  532. factor = factor / 10;
  533. v = v * 10;
  534. count++;
  535. } // 浮点数计算出现问题
  536. if (factor.toString().length > DECIMAL_LENGTH) {
  537. factor = parseFloat(factor.toFixed(count));
  538. }
  539. } else {
  540. while (v > 10) {
  541. factor = factor * 10;
  542. v = v / 10;
  543. }
  544. }
  545. return factor;
  546. } // 取小于当前值的
  547. function arrayFloor(values, value) {
  548. var length = values.length;
  549. if (length === 0) {
  550. return NaN;
  551. }
  552. var pre = values[0];
  553. if (value < values[0]) {
  554. return NaN;
  555. }
  556. if (value >= values[length - 1]) {
  557. return values[length - 1];
  558. }
  559. for (var i = 1; i < values.length; i++) {
  560. if (value < values[i]) {
  561. break;
  562. }
  563. pre = values[i];
  564. }
  565. return pre;
  566. } // 大于当前值的第一个
  567. function arrayCeiling(values, value) {
  568. var length = values.length;
  569. if (length === 0) {
  570. return NaN;
  571. } // var pre = values[0];
  572. var rst;
  573. if (value > values[length - 1]) {
  574. return NaN;
  575. }
  576. if (value < values[0]) {
  577. return values[0];
  578. }
  579. for (var i = 1; i < values.length; i++) {
  580. if (value <= values[i]) {
  581. rst = values[i];
  582. break;
  583. }
  584. }
  585. return rst;
  586. }
  587. var Util = {
  588. // 获取逼近的数值
  589. snapFactorTo: function snapFactorTo(v, arr, snapType) {
  590. // 假设 v = -512,isFloor = true
  591. if (isNaN(v)) {
  592. return NaN;
  593. }
  594. var factor = 1; // 计算系数
  595. if (v !== 0) {
  596. if (v < 0) {
  597. factor = -1;
  598. }
  599. v = v * factor; // v = 512
  600. var tmpFactor = getFactor(v);
  601. factor = factor * tmpFactor; // factor = -100
  602. v = v / tmpFactor; // v = 5.12
  603. }
  604. if (snapType === 'floor') {
  605. v = Util.snapFloor(arr, v); // v = 5
  606. } else if (snapType === 'ceil') {
  607. v = Util.snapCeiling(arr, v); // v = 6
  608. } else {
  609. v = Util.snapTo(arr, v); // 四舍五入 5
  610. }
  611. var rst = v * factor; // 如果出现浮点数计算问题,需要处理一下
  612. if (Math.abs(factor) < 1 && rst.toString().length > DECIMAL_LENGTH) {
  613. var decimalVal = parseInt(1 / factor);
  614. var symbol = factor > 0 ? 1 : -1;
  615. rst = v / decimalVal * symbol;
  616. }
  617. return rst;
  618. },
  619. // 获取逼近的倍数
  620. snapMultiple: function snapMultiple(v, base, snapType) {
  621. var div;
  622. if (snapType === 'ceil') {
  623. div = Math.ceil(v / base);
  624. } else if (snapType === 'floor') {
  625. div = Math.floor(v / base);
  626. } else {
  627. div = Math.round(v / base);
  628. }
  629. return div * base;
  630. },
  631. /**
  632. * 获取逼近的值,用于对齐数据
  633. * @param {Array} values 数据集合
  634. * @param {Number} value 数值
  635. * @return {Number} 逼近的值
  636. */
  637. snapTo: function snapTo(values, value) {
  638. // 这里假定values是升序排列
  639. var floorVal = arrayFloor(values, value);
  640. var ceilingVal = arrayCeiling(values, value);
  641. if (isNaN(floorVal) || isNaN(ceilingVal)) {
  642. if (values[0] >= value) {
  643. return values[0];
  644. }
  645. var last = values[values.length - 1];
  646. if (last <= value) {
  647. return last;
  648. }
  649. }
  650. if (Math.abs(value - floorVal) < Math.abs(ceilingVal - value)) {
  651. return floorVal;
  652. }
  653. return ceilingVal;
  654. },
  655. /**
  656. * 获取逼近的最小值,用于对齐数据
  657. * @param {Array} values 数据集合
  658. * @param {Number} value 数值
  659. * @return {Number} 逼近的最小值
  660. */
  661. snapFloor: function snapFloor(values, value) {
  662. // 这里假定values是升序排列
  663. return arrayFloor(values, value);
  664. },
  665. /**
  666. * 获取逼近的最大值,用于对齐数据
  667. * @param {Array} values 数据集合
  668. * @param {Number} value 数值
  669. * @return {Number} 逼近的最大值
  670. */
  671. snapCeiling: function snapCeiling(values, value) {
  672. // 这里假定values是升序排列
  673. return arrayCeiling(values, value);
  674. },
  675. fixedBase: function fixedBase(v, base) {
  676. var str = base.toString();
  677. var index = str.indexOf('.');
  678. if (index === -1) {
  679. return Math.round(v);
  680. }
  681. var length = str.substr(index + 1).length;
  682. if (length > 20) {
  683. length = 20;
  684. }
  685. return parseFloat(v.toFixed(length));
  686. }
  687. };
  688. module.exports = Util;
  689. /***/ }),
  690. /* 9 */
  691. /***/ (function(module, exports, __webpack_require__) {
  692. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  693. var Base = __webpack_require__(0);
  694. var catAuto = __webpack_require__(10);
  695. var each = __webpack_require__(1);
  696. var isNumber = __webpack_require__(5);
  697. var isString = __webpack_require__(6);
  698. var Category =
  699. /*#__PURE__*/
  700. function (_Base) {
  701. _inheritsLoose(Category, _Base);
  702. function Category() {
  703. return _Base.apply(this, arguments) || this;
  704. }
  705. var _proto = Category.prototype;
  706. _proto._initDefaultCfg = function _initDefaultCfg() {
  707. _Base.prototype._initDefaultCfg.call(this);
  708. this.type = 'cat';
  709. /**
  710. * 是否分类度量
  711. * @type {Boolean}
  712. */
  713. this.isCategory = true;
  714. this.isRounding = true; // 是否进行取整操作
  715. };
  716. /**
  717. * @override
  718. */
  719. _proto.init = function init() {
  720. var self = this;
  721. var values = self.values;
  722. var tickCount = self.tickCount;
  723. each(values, function (v, i) {
  724. values[i] = v.toString();
  725. });
  726. if (!self.ticks) {
  727. var ticks = values;
  728. if (tickCount) {
  729. var temp = catAuto({
  730. maxCount: tickCount,
  731. data: values,
  732. isRounding: self.isRounding
  733. });
  734. ticks = temp.ticks;
  735. }
  736. this.ticks = ticks;
  737. }
  738. };
  739. /**
  740. * @override
  741. */
  742. _proto.getText = function getText(value) {
  743. if (this.values.indexOf(value) === -1 && isNumber(value)) {
  744. value = this.values[Math.round(value)];
  745. }
  746. return _Base.prototype.getText.call(this, value);
  747. };
  748. /**
  749. * @override
  750. */
  751. _proto.translate = function translate(value) {
  752. var index = this.values.indexOf(value);
  753. if (index === -1 && isNumber(value)) {
  754. index = value;
  755. } else if (index === -1) {
  756. index = NaN;
  757. }
  758. return index;
  759. };
  760. /**
  761. * @override
  762. */
  763. _proto.scale = function scale(value) {
  764. var rangeMin = this.rangeMin();
  765. var rangeMax = this.rangeMax();
  766. var percent;
  767. if (isString(value) || this.values.indexOf(value) !== -1) {
  768. value = this.translate(value);
  769. }
  770. if (this.values.length > 1) {
  771. percent = value / (this.values.length - 1);
  772. } else {
  773. percent = value;
  774. }
  775. return rangeMin + percent * (rangeMax - rangeMin);
  776. };
  777. /**
  778. * @override
  779. */
  780. _proto.invert = function invert(value) {
  781. if (isString(value)) {
  782. // 如果已经是字符串
  783. return value;
  784. }
  785. var min = this.rangeMin();
  786. var max = this.rangeMax(); // 归一到 范围内
  787. if (value < min) {
  788. value = min;
  789. }
  790. if (value > max) {
  791. value = max;
  792. }
  793. var percent = (value - min) / (max - min);
  794. var index = Math.round(percent * (this.values.length - 1)) % this.values.length;
  795. index = index || 0;
  796. return this.values[index];
  797. };
  798. return Category;
  799. }(Base);
  800. Base.Cat = Category;
  801. module.exports = Category;
  802. /***/ }),
  803. /* 10 */
  804. /***/ (function(module, exports, __webpack_require__) {
  805. /**
  806. * @fileOverview 计算分类的的坐标点
  807. * @author dxq613@gmail.com
  808. */
  809. var each = __webpack_require__(1);
  810. var MAX_COUNT = 8;
  811. var SUB_COUNT = 4; // 控制个数不能过小
  812. function getSimpleArray(data) {
  813. var arr = [];
  814. each(data, function (sub) {
  815. arr = arr.concat(sub);
  816. });
  817. return arr;
  818. }
  819. function getGreatestFactor(count, number) {
  820. var i;
  821. for (i = number; i > 0; i--) {
  822. if (count % i === 0) {
  823. break;
  824. }
  825. } // 如果是素数,没有可以整除的数字
  826. if (i === 1) {
  827. for (i = number; i > 0; i--) {
  828. if ((count - 1) % i === 0) {
  829. break;
  830. }
  831. }
  832. }
  833. return i;
  834. }
  835. module.exports = function (info) {
  836. var rst = {};
  837. var ticks = [];
  838. var isRounding = info.isRounding;
  839. var categories = getSimpleArray(info.data);
  840. var length = categories.length;
  841. var maxCount = info.maxCount || MAX_COUNT;
  842. var tickCount;
  843. if (isRounding) {
  844. // 取整操作
  845. tickCount = getGreatestFactor(length - 1, maxCount - 1) + 1; // 如果计算出来只有两个坐标点,则直接使用传入的 maxCount
  846. if (tickCount === 2) {
  847. tickCount = maxCount;
  848. } else if (tickCount < maxCount - SUB_COUNT) {
  849. tickCount = maxCount - SUB_COUNT;
  850. }
  851. } else {
  852. tickCount = maxCount;
  853. }
  854. if (!isRounding && length <= tickCount + tickCount / 2) {
  855. ticks = [].concat(categories);
  856. } else {
  857. var step = parseInt(length / (tickCount - 1), 10);
  858. var groups = categories.map(function (e, i) {
  859. return i % step === 0 ? categories.slice(i, i + step) : null;
  860. }).filter(function (e) {
  861. return e;
  862. });
  863. for (var i = 1, groupLen = groups.length; i < groupLen && (isRounding ? i * step < length - step : i < tickCount - 1); i++) {
  864. ticks.push(groups[i][0]);
  865. }
  866. if (categories.length) {
  867. ticks.unshift(categories[0]);
  868. var last = categories[length - 1];
  869. if (ticks.indexOf(last) === -1) {
  870. ticks.push(last);
  871. }
  872. }
  873. }
  874. rst.categories = categories;
  875. rst.ticks = ticks;
  876. return rst;
  877. };
  878. /***/ }),
  879. /* 11 */
  880. /***/ (function(module, exports, __webpack_require__) {
  881. var __WEBPACK_AMD_DEFINE_RESULT__;(function (main) {
  882. 'use strict';
  883. /**
  884. * Parse or format dates
  885. * @class fecha
  886. */
  887. var fecha = {};
  888. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  889. var twoDigits = /\d\d?/;
  890. var threeDigits = /\d{3}/;
  891. var fourDigits = /\d{4}/;
  892. var word = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  893. var literal = /\[([^]*?)\]/gm;
  894. var noop = function () {};
  895. function shorten(arr, sLen) {
  896. var newArr = [];
  897. for (var i = 0, len = arr.length; i < len; i++) {
  898. newArr.push(arr[i].substr(0, sLen));
  899. }
  900. return newArr;
  901. }
  902. function monthUpdate(arrName) {
  903. return function (d, v, i18n) {
  904. var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
  905. if (~index) {
  906. d.month = index;
  907. }
  908. };
  909. }
  910. function pad(val, len) {
  911. val = String(val);
  912. len = len || 2;
  913. while (val.length < len) {
  914. val = '0' + val;
  915. }
  916. return val;
  917. }
  918. var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  919. var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  920. var monthNamesShort = shorten(monthNames, 3);
  921. var dayNamesShort = shorten(dayNames, 3);
  922. fecha.i18n = {
  923. dayNamesShort: dayNamesShort,
  924. dayNames: dayNames,
  925. monthNamesShort: monthNamesShort,
  926. monthNames: monthNames,
  927. amPm: ['am', 'pm'],
  928. DoFn: function DoFn(D) {
  929. return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
  930. }
  931. };
  932. var formatFlags = {
  933. D: function (dateObj) {
  934. return dateObj.getDate();
  935. },
  936. DD: function (dateObj) {
  937. return pad(dateObj.getDate());
  938. },
  939. Do: function (dateObj, i18n) {
  940. return i18n.DoFn(dateObj.getDate());
  941. },
  942. d: function (dateObj) {
  943. return dateObj.getDay();
  944. },
  945. dd: function (dateObj) {
  946. return pad(dateObj.getDay());
  947. },
  948. ddd: function (dateObj, i18n) {
  949. return i18n.dayNamesShort[dateObj.getDay()];
  950. },
  951. dddd: function (dateObj, i18n) {
  952. return i18n.dayNames[dateObj.getDay()];
  953. },
  954. M: function (dateObj) {
  955. return dateObj.getMonth() + 1;
  956. },
  957. MM: function (dateObj) {
  958. return pad(dateObj.getMonth() + 1);
  959. },
  960. MMM: function (dateObj, i18n) {
  961. return i18n.monthNamesShort[dateObj.getMonth()];
  962. },
  963. MMMM: function (dateObj, i18n) {
  964. return i18n.monthNames[dateObj.getMonth()];
  965. },
  966. YY: function (dateObj) {
  967. return String(dateObj.getFullYear()).substr(2);
  968. },
  969. YYYY: function (dateObj) {
  970. return pad(dateObj.getFullYear(), 4);
  971. },
  972. h: function (dateObj) {
  973. return dateObj.getHours() % 12 || 12;
  974. },
  975. hh: function (dateObj) {
  976. return pad(dateObj.getHours() % 12 || 12);
  977. },
  978. H: function (dateObj) {
  979. return dateObj.getHours();
  980. },
  981. HH: function (dateObj) {
  982. return pad(dateObj.getHours());
  983. },
  984. m: function (dateObj) {
  985. return dateObj.getMinutes();
  986. },
  987. mm: function (dateObj) {
  988. return pad(dateObj.getMinutes());
  989. },
  990. s: function (dateObj) {
  991. return dateObj.getSeconds();
  992. },
  993. ss: function (dateObj) {
  994. return pad(dateObj.getSeconds());
  995. },
  996. S: function (dateObj) {
  997. return Math.round(dateObj.getMilliseconds() / 100);
  998. },
  999. SS: function (dateObj) {
  1000. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  1001. },
  1002. SSS: function (dateObj) {
  1003. return pad(dateObj.getMilliseconds(), 3);
  1004. },
  1005. a: function (dateObj, i18n) {
  1006. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  1007. },
  1008. A: function (dateObj, i18n) {
  1009. return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
  1010. },
  1011. ZZ: function (dateObj) {
  1012. var o = dateObj.getTimezoneOffset();
  1013. return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
  1014. }
  1015. };
  1016. var parseFlags = {
  1017. D: [twoDigits, function (d, v) {
  1018. d.day = v;
  1019. }],
  1020. Do: [new RegExp(twoDigits.source + word.source), function (d, v) {
  1021. d.day = parseInt(v, 10);
  1022. }],
  1023. M: [twoDigits, function (d, v) {
  1024. d.month = v - 1;
  1025. }],
  1026. YY: [twoDigits, function (d, v) {
  1027. var da = new Date(),
  1028. cent = +('' + da.getFullYear()).substr(0, 2);
  1029. d.year = '' + (v > 68 ? cent - 1 : cent) + v;
  1030. }],
  1031. h: [twoDigits, function (d, v) {
  1032. d.hour = v;
  1033. }],
  1034. m: [twoDigits, function (d, v) {
  1035. d.minute = v;
  1036. }],
  1037. s: [twoDigits, function (d, v) {
  1038. d.second = v;
  1039. }],
  1040. YYYY: [fourDigits, function (d, v) {
  1041. d.year = v;
  1042. }],
  1043. S: [/\d/, function (d, v) {
  1044. d.millisecond = v * 100;
  1045. }],
  1046. SS: [/\d{2}/, function (d, v) {
  1047. d.millisecond = v * 10;
  1048. }],
  1049. SSS: [threeDigits, function (d, v) {
  1050. d.millisecond = v;
  1051. }],
  1052. d: [twoDigits, noop],
  1053. ddd: [word, noop],
  1054. MMM: [word, monthUpdate('monthNamesShort')],
  1055. MMMM: [word, monthUpdate('monthNames')],
  1056. a: [word, function (d, v, i18n) {
  1057. var val = v.toLowerCase();
  1058. if (val === i18n.amPm[0]) {
  1059. d.isPm = false;
  1060. } else if (val === i18n.amPm[1]) {
  1061. d.isPm = true;
  1062. }
  1063. }],
  1064. ZZ: [/([\+\-]\d\d:?\d\d|Z)/, function (d, v) {
  1065. if (v === 'Z') v = '+00:00';
  1066. var parts = (v + '').match(/([\+\-]|\d\d)/gi),
  1067. minutes;
  1068. if (parts) {
  1069. minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
  1070. d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
  1071. }
  1072. }]
  1073. };
  1074. parseFlags.dd = parseFlags.d;
  1075. parseFlags.dddd = parseFlags.ddd;
  1076. parseFlags.DD = parseFlags.D;
  1077. parseFlags.mm = parseFlags.m;
  1078. parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
  1079. parseFlags.MM = parseFlags.M;
  1080. parseFlags.ss = parseFlags.s;
  1081. parseFlags.A = parseFlags.a; // Some common format strings
  1082. fecha.masks = {
  1083. default: 'ddd MMM DD YYYY HH:mm:ss',
  1084. shortDate: 'M/D/YY',
  1085. mediumDate: 'MMM D, YYYY',
  1086. longDate: 'MMMM D, YYYY',
  1087. fullDate: 'dddd, MMMM D, YYYY',
  1088. shortTime: 'HH:mm',
  1089. mediumTime: 'HH:mm:ss',
  1090. longTime: 'HH:mm:ss.SSS'
  1091. };
  1092. /***
  1093. * Format a date
  1094. * @method format
  1095. * @param {Date|number} dateObj
  1096. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  1097. */
  1098. fecha.format = function (dateObj, mask, i18nSettings) {
  1099. var i18n = i18nSettings || fecha.i18n;
  1100. if (typeof dateObj === 'number') {
  1101. dateObj = new Date(dateObj);
  1102. }
  1103. if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
  1104. throw new Error('Invalid Date in fecha.format');
  1105. }
  1106. mask = fecha.masks[mask] || mask || fecha.masks['default'];
  1107. var literals = []; // Make literals inactive by replacing them with ??
  1108. mask = mask.replace(literal, function ($0, $1) {
  1109. literals.push($1);
  1110. return '??';
  1111. }); // Apply formatting rules
  1112. mask = mask.replace(token, function ($0) {
  1113. return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
  1114. }); // Inline literal values back into the formatted value
  1115. return mask.replace(/\?\?/g, function () {
  1116. return literals.shift();
  1117. });
  1118. };
  1119. /**
  1120. * Parse a date string into an object, changes - into /
  1121. * @method parse
  1122. * @param {string} dateStr Date string
  1123. * @param {string} format Date parse format
  1124. * @returns {Date|boolean}
  1125. */
  1126. fecha.parse = function (dateStr, format, i18nSettings) {
  1127. var i18n = i18nSettings || fecha.i18n;
  1128. if (typeof format !== 'string') {
  1129. throw new Error('Invalid format in fecha.parse');
  1130. }
  1131. format = fecha.masks[format] || format; // Avoid regular expression denial of service, fail early for really long strings
  1132. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  1133. if (dateStr.length > 1000) {
  1134. return false;
  1135. }
  1136. var isValid = true;
  1137. var dateInfo = {};
  1138. format.replace(token, function ($0) {
  1139. if (parseFlags[$0]) {
  1140. var info = parseFlags[$0];
  1141. var index = dateStr.search(info[0]);
  1142. if (!~index) {
  1143. isValid = false;
  1144. } else {
  1145. dateStr.replace(info[0], function (result) {
  1146. info[1](dateInfo, result, i18n);
  1147. dateStr = dateStr.substr(index + result.length);
  1148. return result;
  1149. });
  1150. }
  1151. }
  1152. return parseFlags[$0] ? '' : $0.slice(1, $0.length - 1);
  1153. });
  1154. if (!isValid) {
  1155. return false;
  1156. }
  1157. var today = new Date();
  1158. if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
  1159. dateInfo.hour = +dateInfo.hour + 12;
  1160. } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
  1161. dateInfo.hour = 0;
  1162. }
  1163. var date;
  1164. if (dateInfo.timezoneOffset != null) {
  1165. dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
  1166. date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
  1167. } else {
  1168. date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
  1169. }
  1170. return date;
  1171. };
  1172. /* istanbul ignore next */
  1173. if (typeof module !== 'undefined' && module.exports) {
  1174. module.exports = fecha;
  1175. } else if (true) {
  1176. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  1177. return fecha;
  1178. }).call(exports, __webpack_require__, exports, module),
  1179. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  1180. } else {
  1181. main.fecha = fecha;
  1182. }
  1183. })(this);
  1184. /***/ }),
  1185. /* 12 */
  1186. /***/ (function(module, exports, __webpack_require__) {
  1187. /**
  1188. * @fileOverview 提取公共代码到util方法
  1189. * @author dxq613@gmail.com
  1190. */
  1191. var isString = __webpack_require__(6);
  1192. var isDate = __webpack_require__(22);
  1193. module.exports = {
  1194. toTimeStamp: function toTimeStamp(value) {
  1195. if (isString(value)) {
  1196. if (value.indexOf('T') > 0) {
  1197. value = new Date(value).getTime();
  1198. } else {
  1199. value = new Date(value.replace(/-/ig, '/')).getTime();
  1200. }
  1201. }
  1202. if (isDate(value)) {
  1203. value = value.getTime();
  1204. }
  1205. return value;
  1206. }
  1207. };
  1208. /***/ }),
  1209. /* 13 */
  1210. /***/ (function(module, exports, __webpack_require__) {
  1211. /**
  1212. * @fileOverview Scale entry, used to reference all the scales
  1213. * @author dxq613@gmail.com
  1214. */
  1215. var lowerFirst = __webpack_require__(14);
  1216. var Base = __webpack_require__(0);
  1217. Base.Linear = __webpack_require__(4);
  1218. Base.Identity = __webpack_require__(19);
  1219. Base.Cat = __webpack_require__(9);
  1220. Base.Time = __webpack_require__(20);
  1221. Base.TimeCat = __webpack_require__(23);
  1222. Base.Log = __webpack_require__(24);
  1223. Base.Pow = __webpack_require__(25);
  1224. var _loop = function _loop(k) {
  1225. if (Base.hasOwnProperty(k)) {
  1226. var methodName = lowerFirst(k);
  1227. Base[methodName] = function (cfg) {
  1228. return new Base[k](cfg);
  1229. };
  1230. }
  1231. };
  1232. for (var k in Base) {
  1233. _loop(k);
  1234. }
  1235. var CAT_ARR = ['cat', 'timeCat'];
  1236. Base.isCategory = function (type) {
  1237. return CAT_ARR.indexOf(type) >= 0;
  1238. };
  1239. module.exports = Base;
  1240. /***/ }),
  1241. /* 14 */
  1242. /***/ (function(module, exports, __webpack_require__) {
  1243. var toString = __webpack_require__(15);
  1244. var lowerFirst = function lowerFirst(value) {
  1245. var str = toString(value);
  1246. return str.charAt(0).toLowerCase() + str.substring(1);
  1247. };
  1248. module.exports = lowerFirst;
  1249. /***/ }),
  1250. /* 15 */
  1251. /***/ (function(module, exports, __webpack_require__) {
  1252. var isNil = __webpack_require__(2);
  1253. function toString(value) {
  1254. if (isNil(value)) return '';
  1255. return value.toString();
  1256. }
  1257. module.exports = toString;
  1258. /***/ }),
  1259. /* 16 */
  1260. /***/ (function(module, exports) {
  1261. function _mix(dist, obj) {
  1262. for (var key in obj) {
  1263. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  1264. dist[key] = obj[key];
  1265. }
  1266. }
  1267. }
  1268. var mix = function mix(dist, src1, src2, src3) {
  1269. if (src1) _mix(dist, src1);
  1270. if (src2) _mix(dist, src2);
  1271. if (src3) _mix(dist, src3);
  1272. return dist;
  1273. };
  1274. module.exports = mix;
  1275. /***/ }),
  1276. /* 17 */
  1277. /***/ (function(module, exports, __webpack_require__) {
  1278. var isType = __webpack_require__(3);
  1279. var isArray = Array.isArray ? Array.isArray : function (value) {
  1280. return isType(value, 'Array');
  1281. };
  1282. module.exports = isArray;
  1283. /***/ }),
  1284. /* 18 */
  1285. /***/ (function(module, exports, __webpack_require__) {
  1286. /**
  1287. * @fileOverview 自动计算数字坐标轴
  1288. * @author dxq613@gmail.com
  1289. */
  1290. var isNil = __webpack_require__(2);
  1291. var isNumber = __webpack_require__(5);
  1292. var AutoUtil = __webpack_require__(8);
  1293. var MIN_COUNT = 5;
  1294. var MAX_COUNT = 7;
  1295. var SNAP_COUNT_ARRAY = [0, 1, 1.2, 1.5, 1.6, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10];
  1296. var SNAP_ARRAY = [0, 1, 2, 4, 5, 10];
  1297. module.exports = function (info) {
  1298. var min = info.min;
  1299. var max = info.max;
  1300. var interval = info.interval;
  1301. var minTickInterval = info.minTickInterval;
  1302. var ticks = [];
  1303. var minCount = info.minCount || MIN_COUNT;
  1304. var maxCount = info.maxCount || MAX_COUNT;
  1305. var isFixedCount = minCount === maxCount; // 是否限定死了个数
  1306. var minLimit = isNil(info.minLimit) ? -Infinity : info.minLimit; // 限定的最小值
  1307. var maxLimit = isNil(info.maxLimit) ? Infinity : info.maxLimit; // 限定最大值
  1308. var avgCount = (minCount + maxCount) / 2;
  1309. var count = avgCount; // 用户传入的逼近数组
  1310. var snapArray = info.snapArray ? info.snapArray : isFixedCount ? SNAP_COUNT_ARRAY : SNAP_ARRAY; // 如果限定大小范围,同时大小范围等于用户传入的范围,同时限定了个数,interval 按照个数均分
  1311. if (min === minLimit && max === maxLimit && isFixedCount) {
  1312. interval = (max - min) / (count - 1);
  1313. }
  1314. if (isNil(min)) {
  1315. min = 0;
  1316. }
  1317. if (isNil(max)) {
  1318. max = 0;
  1319. }
  1320. if (max === min) {
  1321. if (min === 0) {
  1322. max = 1;
  1323. } else {
  1324. if (min > 0) {
  1325. min = 0;
  1326. } else {
  1327. max = 0;
  1328. }
  1329. }
  1330. if (max - min < 5 && !interval && max - min >= 1) {
  1331. interval = 1;
  1332. }
  1333. }
  1334. if (isNil(interval)) {
  1335. // 计算间距
  1336. var temp = (max - min) / (avgCount - 1);
  1337. interval = AutoUtil.snapFactorTo(temp, snapArray, 'ceil');
  1338. if (maxCount !== minCount) {
  1339. count = parseInt((max - min) / interval, 10);
  1340. if (count > maxCount) {
  1341. count = maxCount;
  1342. }
  1343. if (count < minCount) {
  1344. count = minCount;
  1345. } // 不确定tick的个数时,使得tick偏小
  1346. interval = AutoUtil.snapFactorTo((max - min) / (count - 1), snapArray, 'floor');
  1347. }
  1348. } // interval should not be less than minTickInterval
  1349. if (isNumber(minTickInterval) && interval < minTickInterval) {
  1350. interval = minTickInterval;
  1351. }
  1352. if (info.interval || maxCount !== minCount) {
  1353. // 校正 max 和 min
  1354. max = Math.min(AutoUtil.snapMultiple(max, interval, 'ceil'), maxLimit); // 向上逼近
  1355. min = Math.max(AutoUtil.snapMultiple(min, interval, 'floor'), minLimit); // 向下逼近
  1356. count = Math.round((max - min) / interval);
  1357. min = AutoUtil.fixedBase(min, interval);
  1358. max = AutoUtil.fixedBase(max, interval);
  1359. } else {
  1360. avgCount = parseInt(avgCount, 10); // 取整
  1361. var avg = (max + min) / 2;
  1362. var avgTick = AutoUtil.snapMultiple(avg, interval, 'ceil');
  1363. var sideCount = Math.floor((avgCount - 2) / 2);
  1364. var maxTick = avgTick + sideCount * interval;
  1365. var minTick;
  1366. if (avgCount % 2 === 0) {
  1367. minTick = avgTick - sideCount * interval;
  1368. } else {
  1369. minTick = avgTick - (sideCount + 1) * interval;
  1370. }
  1371. if (maxTick < max) {
  1372. maxTick = maxTick + interval;
  1373. }
  1374. if (minTick > min) {
  1375. minTick = minTick - interval;
  1376. }
  1377. max = AutoUtil.fixedBase(maxTick, interval);
  1378. min = AutoUtil.fixedBase(minTick, interval);
  1379. }
  1380. max = Math.min(max, maxLimit);
  1381. min = Math.max(min, minLimit);
  1382. ticks.push(min);
  1383. for (var i = 1; i < count; i++) {
  1384. var tickValue = AutoUtil.fixedBase(interval * i + min, interval);
  1385. if (tickValue < max) {
  1386. ticks.push(tickValue);
  1387. }
  1388. }
  1389. if (ticks[ticks.length - 1] < max) {
  1390. ticks.push(max);
  1391. }
  1392. return {
  1393. min: min,
  1394. max: max,
  1395. interval: interval,
  1396. count: count,
  1397. ticks: ticks
  1398. };
  1399. };
  1400. /***/ }),
  1401. /* 19 */
  1402. /***/ (function(module, exports, __webpack_require__) {
  1403. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1404. var Base = __webpack_require__(0);
  1405. var isNumber = __webpack_require__(5);
  1406. var Identity =
  1407. /*#__PURE__*/
  1408. function (_Base) {
  1409. _inheritsLoose(Identity, _Base);
  1410. function Identity() {
  1411. return _Base.apply(this, arguments) || this;
  1412. }
  1413. var _proto = Identity.prototype;
  1414. _proto._initDefaultCfg = function _initDefaultCfg() {
  1415. _Base.prototype._initDefaultCfg.call(this);
  1416. this.isIdentity = true;
  1417. this.type = 'identity';
  1418. /**
  1419. * 常量值
  1420. * @type {*}
  1421. */
  1422. this.value = null;
  1423. };
  1424. /**
  1425. * @override
  1426. */
  1427. _proto.getText = function getText() {
  1428. return this.value.toString();
  1429. };
  1430. /**
  1431. * @override
  1432. */
  1433. _proto.scale = function scale(value) {
  1434. if (this.value !== value && isNumber(value)) {
  1435. return value;
  1436. }
  1437. return this.range[0];
  1438. };
  1439. /**
  1440. * @override
  1441. */
  1442. _proto.invert = function invert() {
  1443. return this.value;
  1444. };
  1445. return Identity;
  1446. }(Base);
  1447. Base.Identity = Identity;
  1448. module.exports = Identity;
  1449. /***/ }),
  1450. /* 20 */
  1451. /***/ (function(module, exports, __webpack_require__) {
  1452. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1453. /**
  1454. * @fileOverview The measurement of linear data scale function
  1455. * @author dxq613@gmail.com
  1456. */
  1457. var fecha = __webpack_require__(11);
  1458. var each = __webpack_require__(1);
  1459. var isNil = __webpack_require__(2);
  1460. var isString = __webpack_require__(6);
  1461. var Base = __webpack_require__(0);
  1462. var Linear = __webpack_require__(4);
  1463. var timeAuto = __webpack_require__(21);
  1464. var TimeUtil = __webpack_require__(12);
  1465. /**
  1466. * 时间度量的构造函数
  1467. * @class Scale.Time
  1468. */
  1469. var Time =
  1470. /*#__PURE__*/
  1471. function (_Linear) {
  1472. _inheritsLoose(Time, _Linear);
  1473. function Time() {
  1474. return _Linear.apply(this, arguments) || this;
  1475. }
  1476. var _proto = Time.prototype;
  1477. _proto._initDefaultCfg = function _initDefaultCfg() {
  1478. _Linear.prototype._initDefaultCfg.call(this);
  1479. this.type = 'time';
  1480. this.mask = 'YYYY-MM-DD';
  1481. };
  1482. /**
  1483. * @override
  1484. */
  1485. _proto.init = function init() {
  1486. var self = this;
  1487. var values = self.values;
  1488. if (values && values.length) {
  1489. // 重新计算最大最小值
  1490. var timeStamps = [];
  1491. var min = Infinity; // 最小值
  1492. var secondMin = min; // 次小值
  1493. var max = 0; // 使用一个循环,计算min,max,secondMin
  1494. each(values, function (v) {
  1495. var timeStamp = self._toTimeStamp(v);
  1496. if (isNaN(timeStamp)) {
  1497. throw new TypeError("Invalid Time: " + v);
  1498. }
  1499. if (min > timeStamp) {
  1500. secondMin = min;
  1501. min = timeStamp;
  1502. } else if (secondMin > timeStamp) {
  1503. secondMin = timeStamp;
  1504. }
  1505. if (max < timeStamp) {
  1506. max = timeStamp;
  1507. }
  1508. timeStamps.push(timeStamp);
  1509. }); // 存在多个值时,设置最小间距
  1510. if (values.length > 1) {
  1511. self.minTickInterval = secondMin - min;
  1512. }
  1513. if (isNil(self.min) || self._toTimeStamp(self.min) > min) {
  1514. self.min = min;
  1515. }
  1516. if (isNil(self.max) || self._toTimeStamp(self.max) < max) {
  1517. self.max = max;
  1518. }
  1519. }
  1520. _Linear.prototype.init.call(this);
  1521. };
  1522. _proto.calculateTicks = function calculateTicks() {
  1523. var self = this;
  1524. var min = self.min;
  1525. var max = self.max;
  1526. var count = self.tickCount;
  1527. var interval = self.tickInterval;
  1528. var tmp = timeAuto({
  1529. min: min,
  1530. max: max,
  1531. minCount: count,
  1532. maxCount: count,
  1533. interval: interval,
  1534. minInterval: self.minTickInterval
  1535. });
  1536. return tmp.ticks;
  1537. };
  1538. /**
  1539. * @override
  1540. */
  1541. _proto.getText = function getText(value) {
  1542. var formatter = this.formatter;
  1543. value = this.translate(value);
  1544. value = formatter ? formatter(value) : fecha.format(value, this.mask);
  1545. return value;
  1546. };
  1547. /**
  1548. * @override
  1549. */
  1550. _proto.scale = function scale(value) {
  1551. if (isString(value)) {
  1552. value = this.translate(value);
  1553. }
  1554. return _Linear.prototype.scale.call(this, value);
  1555. };
  1556. /**
  1557. * @override
  1558. */
  1559. _proto.translate = function translate(value) {
  1560. return this._toTimeStamp(value);
  1561. }; // 将时间转换为时间戳
  1562. _proto._toTimeStamp = function _toTimeStamp(value) {
  1563. return TimeUtil.toTimeStamp(value);
  1564. };
  1565. return Time;
  1566. }(Linear);
  1567. Base.Time = Time;
  1568. module.exports = Time;
  1569. /***/ }),
  1570. /* 21 */
  1571. /***/ (function(module, exports, __webpack_require__) {
  1572. /**
  1573. * @fileOverview 计算时间坐标轴
  1574. * @author dxq613@gmail.com
  1575. */
  1576. var AutoUtil = __webpack_require__(8);
  1577. var isNil = __webpack_require__(2);
  1578. var MAX_COUNT = 6;
  1579. var SNAP_ARRAY = [1, 2, 4, 6, 8, 12];
  1580. var MINUTE_MS = 60 * 1000;
  1581. var HOUR_MS = 3600 * 1000;
  1582. var DAY_MS = 24 * 3600 * 1000;
  1583. function getYear(date) {
  1584. return new Date(date).getFullYear();
  1585. }
  1586. function createYear(year) {
  1587. return new Date(year, 0, 1).getTime();
  1588. }
  1589. function getMonth(date) {
  1590. return new Date(date).getMonth();
  1591. }
  1592. function diffMonth(min, max) {
  1593. var minYear = getYear(min);
  1594. var maxYear = getYear(max);
  1595. var minMonth = getMonth(min);
  1596. var maxMonth = getMonth(max);
  1597. return (maxYear - minYear) * 12 + (maxMonth - minMonth) % 12;
  1598. }
  1599. function creatMonth(year, month) {
  1600. return new Date(year, month, 1).getTime();
  1601. }
  1602. function diffDay(min, max) {
  1603. return Math.ceil((max - min) / DAY_MS);
  1604. }
  1605. function diffHour(min, max) {
  1606. return Math.ceil((max - min) / HOUR_MS);
  1607. }
  1608. function diffMinus(min, max) {
  1609. return Math.ceil((max - min) / (60 * 1000));
  1610. }
  1611. module.exports = function (info) {
  1612. var minInterval = info.minInterval;
  1613. var ticks = [];
  1614. var min = info.min;
  1615. var max = info.max;
  1616. var interval = info.interval;
  1617. var count; // 如果最大值和最小值相等,则设置最大值大于最小值一天
  1618. if (max === min) {
  1619. max = min + DAY_MS;
  1620. } // 计算间距
  1621. if (isNil(interval)) {
  1622. var innerTime = max - min;
  1623. var dms = DAY_MS; // 天代表的秒
  1624. var yms = 365 * dms; // 年代表的秒
  1625. interval = parseInt(innerTime / (info.maxCount || MAX_COUNT), 10);
  1626. if (minInterval && minInterval > interval) {
  1627. interval = minInterval;
  1628. }
  1629. var yfactor = interval / yms;
  1630. var minYear = getYear(min); // 大于半年
  1631. if (yfactor > 0.51) {
  1632. var year = Math.ceil(yfactor); // interval = year * yms;
  1633. var maxYear = getYear(max);
  1634. for (var i = minYear; i <= maxYear + year; i = i + year) {
  1635. ticks.push(createYear(i));
  1636. }
  1637. interval = null;
  1638. } else if (yfactor > 0.0834) {
  1639. // 大于一个月
  1640. var month = Math.ceil(yfactor / 0.0834);
  1641. var mmMoth = getMonth(min);
  1642. var dMonths = diffMonth(min, max);
  1643. for (var _i = 0; _i <= dMonths + month; _i = _i + month) {
  1644. ticks.push(creatMonth(minYear, _i + mmMoth));
  1645. }
  1646. interval = null;
  1647. } else if (interval > dms * 0.5) {
  1648. // 大于一天
  1649. var date = new Date(min);
  1650. var _year = date.getFullYear();
  1651. var _month = date.getMonth(min);
  1652. var mday = date.getDate();
  1653. var day = Math.ceil(interval / dms);
  1654. var ddays = diffDay(min, max);
  1655. interval = day * dms;
  1656. for (var _i2 = 0; _i2 < ddays + day; _i2 = _i2 + day) {
  1657. ticks.push(new Date(_year, _month, mday + _i2).getTime());
  1658. }
  1659. } else if (interval > HOUR_MS) {
  1660. // 大于一个小时
  1661. var _date = new Date(min);
  1662. var _year2 = _date.getFullYear();
  1663. var _month2 = _date.getMonth(min);
  1664. var _day = _date.getDate();
  1665. var hour = _date.getHours();
  1666. var hours = AutoUtil.snapTo(SNAP_ARRAY, Math.ceil(interval / HOUR_MS));
  1667. var dHours = diffHour(min, max);
  1668. interval = hours * HOUR_MS;
  1669. for (var _i3 = 0; _i3 <= dHours + hours; _i3 = _i3 + hours) {
  1670. ticks.push(new Date(_year2, _month2, _day, hour + _i3).getTime());
  1671. }
  1672. } else if (interval > MINUTE_MS) {
  1673. // 最小单位是分钟
  1674. var dMinus = diffMinus(min, max);
  1675. var minutes = Math.ceil(interval / MINUTE_MS);
  1676. interval = minutes * MINUTE_MS;
  1677. for (var _i4 = 0; _i4 <= dMinus + minutes; _i4 = _i4 + minutes) {
  1678. ticks.push(min + _i4 * MINUTE_MS);
  1679. }
  1680. } else {
  1681. if (interval < 1000) {
  1682. interval = 1000;
  1683. }
  1684. min = Math.floor(min / 1000) * 1000;
  1685. var dSeconds = Math.ceil((max - min) / 1000);
  1686. var seconds = Math.ceil(interval / 1000);
  1687. interval = seconds * 1000;
  1688. for (var _i5 = 0; _i5 < dSeconds + seconds; _i5 = _i5 + seconds) {
  1689. ticks.push(min + _i5 * 1000);
  1690. }
  1691. }
  1692. }
  1693. if (!ticks.length) {
  1694. min = Math.floor(min / 1000) * 1000;
  1695. max = Math.ceil(max / 1000) * 1000;
  1696. count = (max - min) / interval;
  1697. for (var _i6 = 0; _i6 <= count; _i6++) {
  1698. ticks.push(AutoUtil.fixedBase(interval * _i6 + min, interval));
  1699. }
  1700. }
  1701. return {
  1702. max: max,
  1703. min: min,
  1704. interval: interval,
  1705. ticks: ticks,
  1706. count: ticks.length
  1707. };
  1708. };
  1709. /***/ }),
  1710. /* 22 */
  1711. /***/ (function(module, exports, __webpack_require__) {
  1712. var isType = __webpack_require__(3);
  1713. var isDate = function isDate(value) {
  1714. return isType(value, 'Date');
  1715. };
  1716. module.exports = isDate;
  1717. /***/ }),
  1718. /* 23 */
  1719. /***/ (function(module, exports, __webpack_require__) {
  1720. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1721. /**
  1722. * @fileOverview 时间数据作为分类类型
  1723. * @author dxq613@gmail.com
  1724. */
  1725. var Base = __webpack_require__(0);
  1726. var Category = __webpack_require__(9);
  1727. var fecha = __webpack_require__(11);
  1728. var catAuto = __webpack_require__(10);
  1729. var TimeUtil = __webpack_require__(12);
  1730. var each = __webpack_require__(1);
  1731. var isNumber = __webpack_require__(5);
  1732. var isObject = __webpack_require__(7);
  1733. var isString = __webpack_require__(6);
  1734. /**
  1735. * 度量的构造函数
  1736. * @class Scale.TimeCategory
  1737. */
  1738. var TimeCategory =
  1739. /*#__PURE__*/
  1740. function (_Category) {
  1741. _inheritsLoose(TimeCategory, _Category);
  1742. function TimeCategory() {
  1743. return _Category.apply(this, arguments) || this;
  1744. }
  1745. var _proto = TimeCategory.prototype;
  1746. _proto._initDefaultCfg = function _initDefaultCfg() {
  1747. _Category.prototype._initDefaultCfg.call(this);
  1748. this.type = 'timeCat';
  1749. /**
  1750. * 是否需要排序,默认进行排序
  1751. * @type {Boolean}
  1752. */
  1753. this.sortable = true;
  1754. this.tickCount = 5;
  1755. /**
  1756. * 时间格式化
  1757. * @type {String}
  1758. */
  1759. this.mask = 'YYYY-MM-DD';
  1760. };
  1761. _proto.init = function init() {
  1762. var self = this;
  1763. var values = this.values; // 针对时间分类类型,会将时间统一转换为时间戳
  1764. each(values, function (v, i) {
  1765. values[i] = self._toTimeStamp(v);
  1766. });
  1767. if (this.sortable) {
  1768. // 允许排序
  1769. values.sort(function (v1, v2) {
  1770. return v1 - v2;
  1771. });
  1772. }
  1773. if (!self.ticks) {
  1774. self.ticks = this.calculateTicks();
  1775. }
  1776. };
  1777. /**
  1778. * 计算 ticks
  1779. * @return {array} 返回 ticks 数组
  1780. */
  1781. _proto.calculateTicks = function calculateTicks() {
  1782. var self = this;
  1783. var count = self.tickCount;
  1784. var ticks;
  1785. if (count) {
  1786. var temp = catAuto({
  1787. maxCount: count,
  1788. data: self.values,
  1789. isRounding: self.isRounding
  1790. });
  1791. ticks = temp.ticks;
  1792. } else {
  1793. ticks = self.values;
  1794. }
  1795. return ticks;
  1796. };
  1797. /**
  1798. * @override
  1799. */
  1800. _proto.translate = function translate(value) {
  1801. value = this._toTimeStamp(value);
  1802. var index = this.values.indexOf(value);
  1803. if (index === -1) {
  1804. if (isNumber(value) && value < this.values.length) {
  1805. index = value;
  1806. } else {
  1807. index = NaN;
  1808. }
  1809. }
  1810. return index;
  1811. };
  1812. /**
  1813. * @override
  1814. */
  1815. _proto.scale = function scale(value) {
  1816. var rangeMin = this.rangeMin();
  1817. var rangeMax = this.rangeMax();
  1818. var index = this.translate(value);
  1819. var percent;
  1820. if (this.values.length === 1 || isNaN(index)) {
  1821. // is index is NAN should not be set as 0
  1822. percent = index;
  1823. } else if (index > -1) {
  1824. percent = index / (this.values.length - 1);
  1825. } else {
  1826. percent = 0;
  1827. }
  1828. return rangeMin + percent * (rangeMax - rangeMin);
  1829. };
  1830. /**
  1831. * @override
  1832. */
  1833. _proto.getText = function getText(value) {
  1834. var result = '';
  1835. var index = this.translate(value);
  1836. if (index > -1) {
  1837. result = this.values[index];
  1838. } else {
  1839. result = value;
  1840. }
  1841. var formatter = this.formatter;
  1842. result = parseInt(result, 10);
  1843. result = formatter ? formatter(result) : fecha.format(result, this.mask);
  1844. return result;
  1845. };
  1846. /**
  1847. * @override
  1848. */
  1849. _proto.getTicks = function getTicks() {
  1850. var self = this;
  1851. var ticks = this.ticks;
  1852. var rst = [];
  1853. each(ticks, function (tick) {
  1854. var obj;
  1855. if (isObject(tick)) {
  1856. obj = tick;
  1857. } else {
  1858. obj = {
  1859. text: isString(tick) ? tick : self.getText(tick),
  1860. value: self.scale(tick),
  1861. tickValue: tick // 用于坐标轴上文本动画时确定前后帧的对应关系
  1862. };
  1863. }
  1864. rst.push(obj);
  1865. });
  1866. return rst;
  1867. }; // 将时间转换为时间戳
  1868. _proto._toTimeStamp = function _toTimeStamp(value) {
  1869. return TimeUtil.toTimeStamp(value);
  1870. };
  1871. return TimeCategory;
  1872. }(Category);
  1873. Base.TimeCat = TimeCategory;
  1874. module.exports = TimeCategory;
  1875. /***/ }),
  1876. /* 24 */
  1877. /***/ (function(module, exports, __webpack_require__) {
  1878. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1879. /**
  1880. * @fileOverview 使用度量,进行log转换
  1881. * @author dxq613@gmail.com
  1882. */
  1883. var each = __webpack_require__(1);
  1884. var Base = __webpack_require__(0);
  1885. var Linear = __webpack_require__(4); // 计算log
  1886. function log(a, b) {
  1887. if (a === 1) {
  1888. return 1;
  1889. }
  1890. return Math.log(b) / Math.log(a);
  1891. }
  1892. /**
  1893. * 度量的log计算
  1894. * @class Scale.Log
  1895. */
  1896. var Log =
  1897. /*#__PURE__*/
  1898. function (_Linear) {
  1899. _inheritsLoose(Log, _Linear);
  1900. function Log() {
  1901. return _Linear.apply(this, arguments) || this;
  1902. }
  1903. var _proto = Log.prototype;
  1904. _proto._initDefaultCfg = function _initDefaultCfg() {
  1905. _Linear.prototype._initDefaultCfg.call(this);
  1906. this.type = 'log';
  1907. /**
  1908. * @override
  1909. * log 的坐标点的个数控制在10个以下
  1910. * @type {Number}
  1911. */
  1912. this.tickCount = 10;
  1913. /**
  1914. * 进行log计算的基数
  1915. * @type {Number}
  1916. */
  1917. this.base = 2; // 最小的tick,仅内部使用
  1918. this._minTick = null;
  1919. };
  1920. /**
  1921. * @override
  1922. */
  1923. _proto.calculateTicks = function calculateTicks() {
  1924. var self = this;
  1925. var base = self.base;
  1926. var minTick;
  1927. if (self.min < 0) {
  1928. throw new Error('The minimum value must be greater than zero!');
  1929. }
  1930. var maxTick = log(base, self.max);
  1931. if (self.min > 0) {
  1932. minTick = Math.floor(log(base, self.min));
  1933. } else {
  1934. var values = self.values;
  1935. var positiveMin = self.max; // 查找大于0的第一个值, 如果都小于0,默认为1
  1936. each(values, function (value) {
  1937. if (value > 0 && value < positiveMin) {
  1938. positiveMin = value;
  1939. }
  1940. });
  1941. if (positiveMin === self.max) {
  1942. positiveMin = self.max / base;
  1943. }
  1944. if (positiveMin > 1) {
  1945. positiveMin = 1;
  1946. }
  1947. minTick = Math.floor(log(base, positiveMin));
  1948. self._minTick = minTick;
  1949. self.positiveMin = positiveMin;
  1950. }
  1951. var count = maxTick - minTick;
  1952. var tickCount = self.tickCount;
  1953. var avg = Math.ceil(count / tickCount);
  1954. var ticks = [];
  1955. for (var i = minTick; i < maxTick + avg; i = i + avg) {
  1956. ticks.push(Math.pow(base, i));
  1957. }
  1958. if (self.min === 0) {
  1959. ticks.unshift(0);
  1960. }
  1961. return ticks;
  1962. }; // 获取度量计算时,value占的定义域百分比
  1963. _proto._getScalePercent = function _getScalePercent(value) {
  1964. var max = this.max;
  1965. var min = this.min;
  1966. if (max === min) {
  1967. return 0;
  1968. } // 如果值小于等于0,则按照0处理
  1969. if (value <= 0) {
  1970. return 0;
  1971. }
  1972. var base = this.base;
  1973. var positiveMin = this.positiveMin; // 如果min == 0, 则根据比0大的最小值,计算比例关系。这个最小值作为坐标轴上的第二个tick,第一个是0但是不显示
  1974. if (positiveMin) {
  1975. min = positiveMin * 1 / base;
  1976. }
  1977. var percent; // 如果数值小于次小值,那么就计算 value / 次小值 占整体的比例
  1978. if (value < positiveMin) {
  1979. percent = value / positiveMin / (log(base, max) - log(base, min));
  1980. } else {
  1981. percent = (log(base, value) - log(base, min)) / (log(base, max) - log(base, min));
  1982. }
  1983. return percent;
  1984. };
  1985. /**
  1986. * @override
  1987. */
  1988. _proto.scale = function scale(value) {
  1989. var percent = this._getScalePercent(value);
  1990. var rangeMin = this.rangeMin();
  1991. var rangeMax = this.rangeMax();
  1992. return rangeMin + percent * (rangeMax - rangeMin);
  1993. };
  1994. /**
  1995. * @override
  1996. */
  1997. _proto.invert = function invert(value) {
  1998. var base = this.base;
  1999. var max = log(base, this.max);
  2000. var rangeMin = this.rangeMin();
  2001. var range = this.rangeMax() - rangeMin;
  2002. var min;
  2003. var positiveMin = this.positiveMin;
  2004. if (positiveMin) {
  2005. if (value === 0) {
  2006. return 0;
  2007. }
  2008. min = log(base, positiveMin / base);
  2009. var appendPercent = 1 / (max - min) * range; // 0 到 positiveMin的占比
  2010. if (value < appendPercent) {
  2011. // 落到 0 - positiveMin 之间
  2012. return value / appendPercent * positiveMin;
  2013. }
  2014. } else {
  2015. min = log(base, this.min);
  2016. }
  2017. var percent = (value - rangeMin) / range;
  2018. var tmp = percent * (max - min) + min;
  2019. return Math.pow(base, tmp);
  2020. };
  2021. return Log;
  2022. }(Linear);
  2023. Base.Log = Log;
  2024. module.exports = Log;
  2025. /***/ }),
  2026. /* 25 */
  2027. /***/ (function(module, exports, __webpack_require__) {
  2028. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2029. /**
  2030. * @fileOverview 使用pow进行度量计算
  2031. * @author dxq613@gmail.com
  2032. */
  2033. var Base = __webpack_require__(0);
  2034. var Linear = __webpack_require__(4); // 求以a为次幂,结果为b的基数,如 x^^a = b;求x
  2035. function calBase(a, b) {
  2036. var e = Math.E;
  2037. var value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  2038. return value;
  2039. }
  2040. /**
  2041. * 度量的Pow计算
  2042. * @class Scale.Log
  2043. */
  2044. var Pow =
  2045. /*#__PURE__*/
  2046. function (_Linear) {
  2047. _inheritsLoose(Pow, _Linear);
  2048. function Pow() {
  2049. return _Linear.apply(this, arguments) || this;
  2050. }
  2051. var _proto = Pow.prototype;
  2052. _proto._initDefaultCfg = function _initDefaultCfg() {
  2053. _Linear.prototype._initDefaultCfg.call(this);
  2054. this.type = 'pow';
  2055. /**
  2056. * @override
  2057. * pow 的坐标点的个数控制在10个以下
  2058. * @type {Number}
  2059. */
  2060. this.tickCount = 10;
  2061. /**
  2062. * 进行pow计算的基数
  2063. * @type {Number}
  2064. */
  2065. this.exponent = 2;
  2066. };
  2067. /**
  2068. * @override
  2069. */
  2070. _proto.calculateTicks = function calculateTicks() {
  2071. var self = this;
  2072. var exponent = self.exponent;
  2073. var min;
  2074. var max = Math.ceil(calBase(exponent, self.max));
  2075. if (self.min >= 0) {
  2076. min = Math.floor(calBase(exponent, self.min));
  2077. } else {
  2078. min = 0;
  2079. }
  2080. if (min > max) {
  2081. var tmp = max;
  2082. max = min;
  2083. min = tmp;
  2084. }
  2085. var count = max - min;
  2086. var tickCount = self.tickCount;
  2087. var avg = Math.ceil(count / tickCount);
  2088. var ticks = [];
  2089. for (var i = min; i < max + avg; i = i + avg) {
  2090. ticks.push(Math.pow(i, exponent));
  2091. }
  2092. return ticks;
  2093. }; // 获取度量计算时,value占的定义域百分比
  2094. _proto._getScalePercent = function _getScalePercent(value) {
  2095. var max = this.max;
  2096. var min = this.min;
  2097. if (max === min) {
  2098. return 0;
  2099. }
  2100. var exponent = this.exponent;
  2101. var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
  2102. return percent;
  2103. };
  2104. /**
  2105. * @override
  2106. */
  2107. _proto.scale = function scale(value) {
  2108. var percent = this._getScalePercent(value);
  2109. var rangeMin = this.rangeMin();
  2110. var rangeMax = this.rangeMax();
  2111. return rangeMin + percent * (rangeMax - rangeMin);
  2112. };
  2113. /**
  2114. * @override
  2115. */
  2116. _proto.invert = function invert(value) {
  2117. var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  2118. var exponent = this.exponent;
  2119. var max = calBase(exponent, this.max);
  2120. var min = calBase(exponent, this.min);
  2121. var tmp = percent * (max - min) + min;
  2122. return Math.pow(tmp, exponent);
  2123. };
  2124. return Pow;
  2125. }(Linear);
  2126. Base.Pow = Pow;
  2127. module.exports = Pow;
  2128. /***/ })
  2129. /******/ ]);
  2130. });
  2131. //# sourceMappingURL=scale.js.map