text.js 2.9 KB

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