text.js 1.7 KB

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