UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

47 lines (39 loc) 1.76 kB
import { Factory } from "./../core/factory"; import { BaseMark } from "./base/base-mark"; import { registerRichtext, registerShadowRoot, registerText } from "@visactor/vrender-kits"; import { createRichText, createText } from "@visactor/vrender-core"; import { isObject, isValid } from "@visactor/vutils"; export class TextMark extends 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 isObject(text) && 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) ? createRichText(attrs) : createText(attrs); } } TextMark.type = "text"; export const registerTextMark = () => { Factory.registerMark(TextMark.type, TextMark), registerShadowRoot(), registerText(), registerRichtext(), Factory.registerGraphicComponent("text", createText), Factory.registerGraphicComponent("richtext", createRichText); }; //# sourceMappingURL=text.js.map