UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

112 lines (105 loc) 7.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerComponentMark = exports.ComponentMark = void 0; const factory_1 = require("./../core/factory"), base_mark_1 = require("./base/base-mark"), vutils_1 = require("@visactor/vutils"), event_1 = require("../constant/event"), release_vrender_component_1 = require("../component/base/release-vrender-component"); class ComponentMark extends base_mark_1.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 = (0, release_vrender_component_1.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)) ? (0, release_vrender_component_1.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 && ((0, release_vrender_component_1.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 (0, vutils_1.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_1.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(event_1.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))); } } exports.ComponentMark = ComponentMark, ComponentMark.type = "component"; const registerComponentMark = () => { factory_1.Factory.registerMark(ComponentMark.type, ComponentMark); }; exports.registerComponentMark = registerComponentMark; //# sourceMappingURL=component.js.map