index.js 3.0 KB

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