index.js 2.1 KB

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