text.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../../util/common");
  5. var _base = _interopRequireDefault(require("./base"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  8. var Text = /*#__PURE__*/function (_GuideBase) {
  9. _inheritsLoose(Text, _GuideBase);
  10. function Text() {
  11. return _GuideBase.apply(this, arguments) || this;
  12. }
  13. var _proto = Text.prototype;
  14. _proto._initDefaultCfg = function _initDefaultCfg() {
  15. this.type = 'text';
  16. /**
  17. * the position of text
  18. * @type {Function | Array}
  19. */
  20. this.position = null;
  21. /**
  22. * the display content
  23. * @type {String}
  24. */
  25. this.content = null;
  26. /**
  27. * style configuration for text
  28. * @type {Object}
  29. */
  30. this.style = {
  31. fill: '#000'
  32. };
  33. /**
  34. * offset of horizontal direction
  35. * @type {Number}
  36. */
  37. this.offsetX = 0;
  38. /**
  39. * offset of vertical direction
  40. * @type {Number}
  41. */
  42. this.offsetY = 0;
  43. };
  44. _proto.render = function render(coord, container) {
  45. var position = this.position;
  46. var point = this.parsePoint(coord, position);
  47. if (!point) {
  48. return;
  49. }
  50. var content = this.content,
  51. style = this.style,
  52. offsetX = this.offsetX,
  53. offsetY = this.offsetY;
  54. if (offsetX) {
  55. point.x += offsetX;
  56. }
  57. if (offsetY) {
  58. point.y += offsetY;
  59. }
  60. var shape = container.addShape('text', {
  61. className: 'guide-text',
  62. attrs: (0, _common.mix)({
  63. x: point.x,
  64. y: point.y,
  65. text: content
  66. }, style)
  67. });
  68. this.element = shape;
  69. return shape;
  70. };
  71. return Text;
  72. }(_base["default"]);
  73. _base["default"].Text = Text;
  74. var _default = Text;
  75. exports["default"] = _default;