index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { __extends } from "tslib";
  2. import { Event, VIEW_LIFE_CIRCLE } from '@antv/g2';
  3. import { Plot } from '../../core/plot';
  4. import { deepAssign, findViewById } from '../../utils';
  5. import { adaptor } from './adaptor';
  6. import { FIRST_AXES_VIEW, SECOND_AXES_VIEW, SERIES_FIELD_KEY } from './constant';
  7. import { isHorizontal, syncViewPadding, transformData } from './utils';
  8. var BidirectionalBar = /** @class */ (function (_super) {
  9. __extends(BidirectionalBar, _super);
  10. function BidirectionalBar() {
  11. var _this = _super !== null && _super.apply(this, arguments) || this;
  12. /** 图表类型 */
  13. _this.type = 'bidirectional-bar';
  14. return _this;
  15. }
  16. /**
  17. * 获取 默认配置项
  18. * 供外部使用
  19. */
  20. BidirectionalBar.getDefaultOptions = function () {
  21. return deepAssign({}, _super.getDefaultOptions.call(this), {
  22. syncViewPadding: syncViewPadding,
  23. });
  24. };
  25. /**
  26. * @override
  27. */
  28. BidirectionalBar.prototype.changeData = function (data) {
  29. if (data === void 0) { data = []; }
  30. this.chart.emit(VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, Event.fromData(this.chart, VIEW_LIFE_CIRCLE.BEFORE_CHANGE_DATA, null));
  31. // 更新options
  32. this.updateOption({ data: data });
  33. var _a = this.options, xField = _a.xField, yField = _a.yField, layout = _a.layout;
  34. // 处理数据
  35. var groupData = transformData(xField, yField, SERIES_FIELD_KEY, data, isHorizontal(layout));
  36. var firstViewData = groupData[0], secondViewData = groupData[1];
  37. var firstView = findViewById(this.chart, FIRST_AXES_VIEW);
  38. var secondView = findViewById(this.chart, SECOND_AXES_VIEW);
  39. // 更新对应view的data
  40. firstView.data(firstViewData);
  41. secondView.data(secondViewData);
  42. // 重新渲染
  43. this.chart.render(true);
  44. this.chart.emit(VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, Event.fromData(this.chart, VIEW_LIFE_CIRCLE.AFTER_CHANGE_DATA, null));
  45. };
  46. BidirectionalBar.prototype.getDefaultOptions = function () {
  47. return BidirectionalBar.getDefaultOptions();
  48. };
  49. /**
  50. * 获取对称条形图的适配器
  51. */
  52. BidirectionalBar.prototype.getSchemaAdaptor = function () {
  53. return adaptor;
  54. };
  55. /** 对称条形图分类字段 */
  56. BidirectionalBar.SERIES_FIELD_KEY = SERIES_FIELD_KEY;
  57. return BidirectionalBar;
  58. }(Plot));
  59. export { BidirectionalBar };
  60. //# sourceMappingURL=index.js.map