UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

111 lines (103 loc) 6.74 kB
import { Factory } from "./../core/factory"; import { BaseMark } from "./base/base-mark"; import { isNil } from "@visactor/vutils"; import { HOOK_EVENT } from "../constant/event"; import { releaseVRenderComponent, releaseVRenderComponentSync } from "../component/base/release-vrender-component"; 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; } _clearExitingComponent(component) { this._exitingComponent === component && (this._unregisterExitingComponent(component), this._exitingComponent = void 0, this._exitingProduct = void 0); } _removeProductAfterExit(component, product) { product.parent && product.parent.removeChild(product, !0), this._product === product && (this._product = null, this._compiledProductId = null), this._clearExitingComponent(component); } _registerExitingComponent(component) { var _a, _b, _c, _d, _e; null === (_e = null === (_d = null === (_c = null === (_b = null === (_a = this.model) || void 0 === _a ? void 0 : _a.getOption) || void 0 === _b ? void 0 : _b.call(_a)) || void 0 === _c ? void 0 : _c.globalInstance) || void 0 === _d ? void 0 : _d._registerExitingVRenderComponent) || void 0 === _e || _e.call(_d, component); } _unregisterExitingComponent(component) { var _a, _b, _c, _d, _e; null === (_e = null === (_d = null === (_c = null === (_b = null === (_a = this.model) || void 0 === _a ? void 0 : _a.getOption) || void 0 === _b ? void 0 : _b.call(_a)) || void 0 === _c ? void 0 : _c.globalInstance) || void 0 === _d ? void 0 : _d._unregisterExitingVRenderComponent) || void 0 === _e || _e.call(_d, component); } _releaseComponentWithExitAnimation(component, releaseProduct) { var _a, _b; const product = this._product; if (!component || (null === (_b = null === (_a = this.model) || void 0 === _a ? void 0 : _a._shouldReleaseVRenderComponentsImmediately) || void 0 === _b ? void 0 : _b.call(_a))) return !1; const releasedWithExit = releaseVRenderComponent(component, { enableExitAnimation: !0, removeFromParent: !0, onComplete: () => { releaseProduct && product ? this._removeProductAfterExit(component, product) : this._clearExitingComponent(component); } }); return releasedWithExit && (this._exitingComponent = component, this._exitingProduct = releaseProduct ? product : void 0, this._registerExitingComponent(component)), releasedWithExit; } clearComponent() { var _a, _b; const component = this._component; component && ((null === (_b = null === (_a = this.model) || void 0 === _a ? void 0 : _a._shouldReleaseVRenderComponentsImmediately) || void 0 === _b ? void 0 : _b.call(_a)) ? releaseVRenderComponentSync(component) : this._releaseComponentWithExitAnimation(component, !1), this._component = null); } releaseWithExitAnimation() { const component = this._component; return !!this._releaseComponentWithExitAnimation(component, !0) && (this._component = null, this._exitingComponent = component, !0); } forceReleaseExitAnimation() { var _a; this._exitingComponent && (releaseVRenderComponentSync(this._exitingComponent), this._unregisterExitingComponent(this._exitingComponent), (null === (_a = this._exitingProduct) || void 0 === _a ? void 0 : _a.parent) && this._exitingProduct.parent.removeChild(this._exitingProduct, !0), this._exitingComponent = void 0, this._exitingProduct = void 0); } _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._product && this._component.parent !== this._product && this._product.appendChild(this._component)) : (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() { var _a, _b; return (null === (_b = null === (_a = this.model) || void 0 === _a ? void 0 : _a._shouldReleaseVRenderComponentsImmediately) || void 0 === _b ? void 0 : _b.call(_a)) ? (this.forceReleaseExitAnimation(), super.release(), void this.removeProduct(!0)) : this._exitingComponent ? (this._releaseComponentWithExitAnimation(this._exitingComponent, !0) || this.removeProduct(!0), void super.release()) : void (this.releaseWithExitAnimation() ? super.release() : (super.release(), this.removeProduct(!0))); } } ComponentMark.type = "component"; export const registerComponentMark = () => { Factory.registerMark(ComponentMark.type, ComponentMark); }; //# sourceMappingURL=component.js.map