text.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. var Util = require('../../util/common');
  9. var GuideBase = require('./base');
  10. var Text = /*#__PURE__*/function (_GuideBase) {
  11. (0, _inheritsLoose2["default"])(Text, _GuideBase);
  12. var _super = _createSuper(Text);
  13. function Text() {
  14. return _GuideBase.apply(this, arguments) || this;
  15. }
  16. var _proto = Text.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. this.type = 'text';
  19. /**
  20. * the position of text
  21. * @type {Function | Array}
  22. */
  23. this.position = null;
  24. /**
  25. * the display content
  26. * @type {String}
  27. */
  28. this.content = null;
  29. /**
  30. * style configuration for text
  31. * @type {Object}
  32. */
  33. this.style = {
  34. fill: '#000'
  35. };
  36. /**
  37. * offset of horizontal direction
  38. * @type {Number}
  39. */
  40. this.offsetX = 0;
  41. /**
  42. * offset of vertical direction
  43. * @type {Number}
  44. */
  45. this.offsetY = 0;
  46. };
  47. _proto.render = function render(coord, container) {
  48. var position = this.position;
  49. var point = this.parsePoint(coord, position);
  50. if (!point) {
  51. return;
  52. }
  53. var content = this.content,
  54. style = this.style,
  55. offsetX = this.offsetX,
  56. offsetY = this.offsetY;
  57. if (offsetX) {
  58. point.x += offsetX;
  59. }
  60. if (offsetY) {
  61. point.y += offsetY;
  62. }
  63. var shape = container.addShape('text', {
  64. className: 'guide-text',
  65. attrs: Util.mix({
  66. x: point.x,
  67. y: point.y,
  68. text: content
  69. }, style)
  70. });
  71. this.element = shape;
  72. return shape;
  73. };
  74. return Text;
  75. }(GuideBase);
  76. GuideBase.Text = Text;
  77. module.exports = Text;