text.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var group_component_1 = require("../abstract/group-component");
  5. var graphic_1 = require("../util/graphic");
  6. var matrix_1 = require("../util/matrix");
  7. var theme_1 = require("../util/theme");
  8. var TextAnnotation = /** @class */ (function (_super) {
  9. tslib_1.__extends(TextAnnotation, _super);
  10. function TextAnnotation() {
  11. return _super !== null && _super.apply(this, arguments) || this;
  12. }
  13. /**
  14. * @protected
  15. * 默认的配置项
  16. * @returns {object} 默认的配置项
  17. */
  18. TextAnnotation.prototype.getDefaultCfg = function () {
  19. var cfg = _super.prototype.getDefaultCfg.call(this);
  20. return tslib_1.__assign(tslib_1.__assign({}, cfg), { name: 'annotation', type: 'text', locationType: 'point', x: 0, y: 0, content: '', rotate: null, style: {}, background: null, maxLength: null, autoEllipsis: true, isVertical: false, ellipsisPosition: 'tail', defaultCfg: {
  21. style: {
  22. fill: theme_1.default.textColor,
  23. fontSize: 12,
  24. textAlign: 'center',
  25. textBaseline: 'middle',
  26. fontFamily: theme_1.default.fontFamily,
  27. },
  28. } });
  29. };
  30. // 复写 setLocation 方法,不需要重新创建 text
  31. TextAnnotation.prototype.setLocation = function (location) {
  32. this.set('x', location.x);
  33. this.set('y', location.y);
  34. this.resetLocation();
  35. };
  36. TextAnnotation.prototype.renderInner = function (group) {
  37. var _a = this.getLocation(), x = _a.x, y = _a.y;
  38. var content = this.get('content');
  39. var style = this.get('style');
  40. var id = this.getElementId('text');
  41. var name = this.get('name') + "-text";
  42. var maxLength = this.get('maxLength');
  43. var autoEllipsis = this.get('autoEllipsis');
  44. var isVertical = this.get('isVertical');
  45. var ellipsisPosition = this.get('ellipsisPosition');
  46. var background = this.get('background');
  47. var rotate = this.get('rotate');
  48. var cfg = {
  49. id: id,
  50. name: name,
  51. x: x,
  52. y: y,
  53. content: content,
  54. style: style,
  55. maxLength: maxLength,
  56. autoEllipsis: autoEllipsis,
  57. isVertical: isVertical,
  58. ellipsisPosition: ellipsisPosition,
  59. background: background,
  60. rotate: rotate,
  61. };
  62. graphic_1.renderTag(group, cfg);
  63. };
  64. TextAnnotation.prototype.resetLocation = function () {
  65. var textGroup = this.getElementByLocalId('text-group');
  66. if (textGroup) {
  67. var _a = this.getLocation(), x = _a.x, y = _a.y;
  68. var rotate = this.get('rotate');
  69. matrix_1.applyTranslate(textGroup, x, y);
  70. matrix_1.applyRotate(textGroup, rotate, x, y);
  71. }
  72. };
  73. return TextAnnotation;
  74. }(group_component_1.default));
  75. exports.default = TextAnnotation;
  76. //# sourceMappingURL=text.js.map