UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

50 lines (43 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerTextMark = exports.TextMark = void 0; const factory_1 = require("./../core/factory"), base_mark_1 = require("./base/base-mark"), vrender_bridge_1 = require("../vrender-bridge"), vutils_1 = require("@visactor/vutils"); class TextMark extends base_mark_1.BaseMark { getTextType() { return this._textType; } constructor(name, option) { super(name, option), this.type = TextMark.type, this._textType = "text"; } _getDefaultStyle() { return Object.assign(Object.assign({}, super._getDefaultStyle()), { angle: 0, textAlign: "center", lineWidth: 0, textConfig: [] }); } initStyleWithSpec(spec) { super.initStyleWithSpec(spec), spec.textType && (this._textType = spec.textType); } _transformGraphicAttributes(g, attrs, groupAttrs) { const textAttrs = super._transformGraphicAttributes(g, attrs, groupAttrs), {text: text} = textAttrs; return (0, vutils_1.isObject)(text) && (0, vutils_1.isValid)(text.text) && ("rich" === this._textType || "rich" === text.type) && (textAttrs.textConfig = text.text), textAttrs; } _createGraphic(attrs = {}) { const {text: text} = attrs; return "rich" === this._textType || "rich" === (null == text ? void 0 : text.type) ? (0, vrender_bridge_1.createRichText)(attrs) : (0, vrender_bridge_1.createText)(attrs); } } exports.TextMark = TextMark, TextMark.type = "text"; const registerTextMark = () => { factory_1.Factory.registerMark(TextMark.type, TextMark), (0, vrender_bridge_1.registerShadowRoot)(), (0, vrender_bridge_1.registerText)(), (0, vrender_bridge_1.registerRichtext)(), factory_1.Factory.registerGraphicComponent("text", vrender_bridge_1.createText), factory_1.Factory.registerGraphicComponent("richtext", vrender_bridge_1.createRichText); }; exports.registerTextMark = registerTextMark; //# sourceMappingURL=text.js.map