index.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.WordCloud = void 0;
  4. var tslib_1 = require("tslib");
  5. var plot_1 = require("../../core/plot");
  6. var adaptor_1 = require("./adaptor");
  7. var constant_1 = require("./constant");
  8. // 注册的shape
  9. require("./shapes/word-cloud");
  10. var utils_1 = require("./utils");
  11. var WordCloud = /** @class */ (function (_super) {
  12. tslib_1.__extends(WordCloud, _super);
  13. function WordCloud() {
  14. var _this = _super !== null && _super.apply(this, arguments) || this;
  15. /** 词云图 */
  16. _this.type = 'word-cloud';
  17. return _this;
  18. }
  19. /**
  20. * 获取 词云图 默认配置项
  21. * 供外部使用
  22. */
  23. WordCloud.getDefaultOptions = function () {
  24. return constant_1.DEFAULT_OPTIONS;
  25. };
  26. /**
  27. * @override
  28. * @param data
  29. */
  30. WordCloud.prototype.changeData = function (data) {
  31. this.updateOption({ data: data });
  32. if (this.options.imageMask) {
  33. this.render();
  34. }
  35. else {
  36. this.chart.changeData((0, utils_1.transform)({ chart: this.chart, options: this.options }));
  37. }
  38. };
  39. /**
  40. * 获取默认的 options 配置项
  41. */
  42. WordCloud.prototype.getDefaultOptions = function () {
  43. return WordCloud.getDefaultOptions();
  44. };
  45. /**
  46. * 覆写父类方法,词云图需要加载图片资源,所以需要异步渲染
  47. */
  48. WordCloud.prototype.render = function () {
  49. var _this = this;
  50. return new Promise(function (res) {
  51. var imageMask = _this.options.imageMask;
  52. if (!imageMask) {
  53. // 调用父类渲染函数
  54. _super.prototype.render.call(_this);
  55. res();
  56. return;
  57. }
  58. var handler = function (img) {
  59. _this.options = tslib_1.__assign(tslib_1.__assign({}, _this.options), { imageMask: img || null });
  60. // 调用父类渲染函数
  61. _super.prototype.render.call(_this);
  62. res();
  63. };
  64. (0, utils_1.processImageMask)(imageMask).then(handler).catch(handler);
  65. });
  66. };
  67. /**
  68. * 获取 词云图 的适配器
  69. */
  70. WordCloud.prototype.getSchemaAdaptor = function () {
  71. return adaptor_1.adaptor;
  72. };
  73. /**
  74. * 覆写父类的方法,因为词云图使用 单独的函数 进行布局,原理上有些不一样
  75. */
  76. WordCloud.prototype.triggerResize = function () {
  77. var _this = this;
  78. if (!this.chart.destroyed) {
  79. // 当整个词云图图表的宽高信息发生变化时,每个词语的坐标
  80. // 需要重新执行 adaptor,不然会出现布局错乱,
  81. // 如相邻词语重叠的情况。
  82. this.execAdaptor();
  83. // 延迟执行,有利于动画更流畅
  84. // TODO: 在多次更改画布尺寸时,动画会越来越卡顿,原因未知
  85. window.setTimeout(function () {
  86. // 执行父类的方法
  87. _super.prototype.triggerResize.call(_this);
  88. });
  89. }
  90. };
  91. return WordCloud;
  92. }(plot_1.Plot));
  93. exports.WordCloud = WordCloud;
  94. //# sourceMappingURL=index.js.map