time.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var util_1 = require("@antv/util");
  5. var time_1 = require("../util/time");
  6. var base_1 = require("./base");
  7. /**
  8. * 时间分类度量
  9. * @class
  10. */
  11. var TimeCat = /** @class */ (function (_super) {
  12. tslib_1.__extends(TimeCat, _super);
  13. function TimeCat() {
  14. var _this = _super !== null && _super.apply(this, arguments) || this;
  15. _this.type = 'timeCat';
  16. return _this;
  17. }
  18. /**
  19. * @override
  20. */
  21. TimeCat.prototype.translate = function (value) {
  22. value = time_1.toTimeStamp(value);
  23. var index = this.values.indexOf(value);
  24. if (index === -1) {
  25. if (util_1.isNumber(value) && value < this.values.length) {
  26. index = value;
  27. }
  28. else {
  29. index = NaN;
  30. }
  31. }
  32. return index;
  33. };
  34. /**
  35. * 由于时间类型数据需要转换一下,所以复写 getText
  36. * @override
  37. */
  38. TimeCat.prototype.getText = function (value, tickIndex) {
  39. var index = this.translate(value);
  40. if (index > -1) {
  41. var result = this.values[index];
  42. var formatter = this.formatter;
  43. result = formatter ? formatter(result, tickIndex) : time_1.timeFormat(result, this.mask);
  44. return result;
  45. }
  46. return value;
  47. };
  48. TimeCat.prototype.initCfg = function () {
  49. this.tickMethod = 'time-cat';
  50. this.mask = 'YYYY-MM-DD';
  51. this.tickCount = 7; // 一般时间数据会显示 7, 14, 30 天的数字
  52. };
  53. TimeCat.prototype.setDomain = function () {
  54. var values = this.values;
  55. // 针对时间分类类型,会将时间统一转换为时间戳
  56. util_1.each(values, function (v, i) {
  57. values[i] = time_1.toTimeStamp(v);
  58. });
  59. values.sort(function (v1, v2) {
  60. return v1 - v2;
  61. });
  62. _super.prototype.setDomain.call(this);
  63. };
  64. return TimeCat;
  65. }(base_1.default));
  66. exports.default = TimeCat;
  67. //# sourceMappingURL=time.js.map