index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Gauge = void 0;
  4. var tslib_1 = require("tslib");
  5. var g2_1 = require("@antv/g2");
  6. var plot_1 = require("../../core/plot");
  7. var adaptor_1 = require("./adaptor");
  8. var constants_1 = require("./constants");
  9. // 注册 shape
  10. require("./shapes/indicator");
  11. require("./shapes/meter-gauge");
  12. var utils_1 = require("./utils");
  13. /**
  14. * 仪表盘
  15. */
  16. var Gauge = /** @class */ (function (_super) {
  17. tslib_1.__extends(Gauge, _super);
  18. function Gauge() {
  19. var _this = _super !== null && _super.apply(this, arguments) || this;
  20. /** 图表类型 */
  21. _this.type = 'gauge';
  22. return _this;
  23. }
  24. /**
  25. * 获取 仪表盘 默认配置项
  26. * 供外部使用
  27. */
  28. Gauge.getDefaultOptions = function () {
  29. return constants_1.DEFAULT_OPTIONS;
  30. };
  31. /**
  32. * 更新数据
  33. * @param percent
  34. */
  35. Gauge.prototype.changeData = function (percent) {
  36. this.chart.emit(g2_1.VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, g2_1.Event.fromData(this.chart, g2_1.VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, null));
  37. this.updateOption({ percent: percent });
  38. var indicatorView = this.chart.views.find(function (v) { return v.id === constants_1.INDICATEOR_VIEW_ID; });
  39. if (indicatorView) {
  40. indicatorView.data((0, utils_1.getIndicatorData)(percent));
  41. }
  42. var rangeView = this.chart.views.find(function (v) { return v.id === constants_1.RANGE_VIEW_ID; });
  43. if (rangeView) {
  44. rangeView.data((0, utils_1.getRangeData)(percent, this.options.range));
  45. }
  46. // todo 后续让 G2 层在 afterrender 之后,来重绘 annotations
  47. (0, adaptor_1.statistic)({ chart: this.chart, options: this.options }, true);
  48. this.chart.emit(g2_1.VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, g2_1.Event.fromData(this.chart, g2_1.VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, null));
  49. };
  50. /**
  51. * 获取默认配置
  52. * 供 base 使用
  53. */
  54. Gauge.prototype.getDefaultOptions = function () {
  55. return Gauge.getDefaultOptions();
  56. };
  57. /**
  58. * 获取适配器
  59. */
  60. Gauge.prototype.getSchemaAdaptor = function () {
  61. return adaptor_1.adaptor;
  62. };
  63. return Gauge;
  64. }(plot_1.Plot));
  65. exports.Gauge = Gauge;
  66. //# sourceMappingURL=index.js.map