function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } var Util = require('../util'); var Guide = require('./base'); var Text = /*#__PURE__*/function (_Guide) { _inheritsLoose(Text, _Guide); var _super = _createSuper(Text); function Text() { return _Guide.apply(this, arguments) || this; } var _proto = Text.prototype; _proto.getDefaultCfg = function getDefaultCfg() { var cfg = _Guide.prototype.getDefaultCfg.call(this); return Util.mix({}, cfg, { /** * 辅助元素类型 * @type {String} */ name: 'text', /** * 辅助文本的位置 * @type {Object | Function | Array} */ position: null, /** * 辅助文本的显示文字 * @type {String} */ content: null, /** * 辅助文本的样式配置 * @type {Object} */ style: { fill: '#999', fontSize: 12, fontWeight: 500, textAlign: 'center' }, /** * x 方向的偏移量 * @type {Number} */ offsetX: null, /** * y 方向的偏移量 * @type {Number} */ offsetY: null, top: true }); }; _proto.render = function render(coord, group) { var self = this; var point = self.parsePoint(coord, self.get('position')); if (!point) { return; } var textStyle = Util.mix({}, self.get('style')); var offsetX = self.get('offsetX'); var offsetY = self.get('offsetY'); if (offsetX) { point.x += offsetX; } if (offsetY) { point.y += offsetY; } if (textStyle.rotate) { textStyle.rotate = textStyle.rotate * Math.PI / 180; // 将角度转换为弧度 } var guideText = group.addShape('Text', { zIndex: self.get('zIndex'), attrs: Util.mix({ text: self.get('content') }, textStyle, point) }); guideText.name = 'guide-text'; self.get('appendInfo') && guideText.setSilent('appendInfo', self.get('appendInfo')); self.set('el', guideText); }; return Text; }(Guide); module.exports = Text;