@visactor/vchart
Version:
charts lib based @visactor/VGrammar
62 lines (55 loc) • 2.94 kB
JavaScript
import { Factory } from "./../core/factory";
import { BaseMark } from "./base/base-mark";
import { isNil } from "@visactor/vutils";
import { HOOK_EVENT } from "../constant/event";
export class ComponentMark extends BaseMark {
constructor(name, option) {
super(name, option), this.type = "component", this._componentType = option.componentType,
this._mode = option.mode;
}
_getDefaultStyle() {
return {};
}
getComponent() {
return this._component;
}
clearComponent() {
this._component && (this._component.parent && this._component.parent.removeChild(this._component),
this._component = null);
}
_getAttrsFromConfig(attrs = {}) {
const configAttrs = super._getAttrsFromConfig(attrs);
return isNil(this._markConfig.interactive) || (configAttrs.pickable = this._markConfig.interactive),
attrs;
}
setAttributeTransform(t) {
this._attributesTransform = t;
}
renderInner() {
var _a;
const style = null !== (_a = this._simpleStyle) && void 0 !== _a ? _a : this.getAttributesOfState({});
let attrs = this._getAttrsFromConfig(style);
this._attributesTransform && (attrs = this._attributesTransform(attrs)), this._animationConfig && (attrs = Object.assign(Object.assign({}, attrs), {
animation: !0,
animationAppear: this._animationConfig.appear ? Array.isArray(this._animationConfig.appear) ? this._animationConfig.appear[0] : this._animationConfig.appear : void 0,
animationEnter: this._animationConfig.enter ? Array.isArray(this._animationConfig.enter) ? this._animationConfig.enter[0] : this._animationConfig.enter : void 0,
animationUpdate: this._animationConfig.update ? Array.isArray(this._animationConfig.update) ? this._animationConfig.update[0] : this._animationConfig.update : void 0,
animationExit: this._animationConfig.exit ? Array.isArray(this._animationConfig.exit) ? this._animationConfig.exit[0] : this._animationConfig.exit : void 0
})), this._component ? this._component.setAttributes(attrs) : (this._component = Factory.createGraphicComponent(this._componentType, attrs, {
mode: this._mode,
skipDefault: this._markConfig.skipTheme
}), this._component && this._product.appendChild(this._component)), this._component && (this._component.context = this._getCommonContext()),
this._markConfig.support3d && this._product && this._product.setMode("3d"), this.model.event.emit(HOOK_EVENT.AFTER_ELEMENT_ENCODE, {
mark: this,
model: this.model
}), this.needClear = !0;
}
release() {
super.release(), this.removeProduct();
}
}
ComponentMark.type = "component";
export const registerComponentMark = () => {
Factory.registerMark(ComponentMark.type, ComponentMark);
};
//# sourceMappingURL=component.js.map