UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

152 lines (146 loc) 7.62 kB
"use strict"; var __rest = this && this.__rest || function(s, e) { var t = {}; for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]); if (null != s && "function" == typeof Object.getOwnPropertySymbols) { var i = 0; for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]); } return t; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.BaseComponent = void 0; const constant_1 = require("@visactor/vrender-core/event/constant"), plugin_service_1 = require("../../plugin/components/plugin-service"), vutils_1 = require("@visactor/vutils"), event_1 = require("../../constant/event"), layout_model_1 = require("../../model/layout-model"), base_component_transformer_1 = require("./base-component-transformer"), release_vrender_component_1 = require("./release-vrender-component"); class BaseComponent extends layout_model_1.LayoutModel { constructor() { super(...arguments), this.name = "component", this.modelType = "component", this.transformerConstructor = base_component_transformer_1.BaseComponentSpecTransformer, this._forceReleaseVRenderComponents = !1, this._delegateEvent = (component, event, type, item = null, datum = null) => { var _a, _b; event instanceof constant_1.CustomEvent || this.event.emit(type, { model: this, node: component, event: event, item: item, datum: datum, source: event_1.Event_Source_Type.chart, chart: null === (_b = null === (_a = this._option) || void 0 === _a ? void 0 : _a.globalInstance) || void 0 === _b ? void 0 : _b.getChart() }, "model"); }; } static createComponent(specInfo, options) { const {spec: spec} = specInfo, others = __rest(specInfo, [ "spec" ]); return new this(spec, Object.assign(Object.assign({}, options), others)); } getRegions() { return this._regions; } created() { super.created(), this.initLayout(), this.pluginService = new plugin_service_1.ComponentPluginService(this); } initLayout() { var _a; super.initLayout(), this._regions = null !== (_a = this._regions) && void 0 !== _a ? _a : this._option.getRegionsInIndex(), this._layout && (this._layout.layoutBindRegionID = this._regions.map((x => null == x ? void 0 : x.id))); } _getNeedClearVRenderComponents() { return []; } getVRenderComponents() { return this._getNeedClearVRenderComponents(); } callPlugin(cb) { this.pluginService && this.pluginService.getAll().forEach((plugin => cb(plugin))); } getContainer() { var _a; return this._container || (this._container = null === (_a = this._option) || void 0 === _a ? void 0 : _a.globalInstance.getStage().find((node => "root" === node.name), !0)), this._container; } _compareSpec(spec, prevSpec) { const result = super._compareSpec(spec, prevSpec); return result.reMake || (result.reMake = [ "seriesId", "seriesIndex", "regionId", "regionIndex" ].some((k => !(0, vutils_1.isEqual)(null == prevSpec ? void 0 : prevSpec[k], spec[k])))), (null == prevSpec ? void 0 : prevSpec.visible) !== spec.visible && (result.reCompile = !0), result; } beforeRelease() { super.beforeRelease(), this._forceReleaseVRenderComponents = !0, this._forceReleaseExitingVRenderComponents(); } release() { var _a; this._shouldReleaseVRenderComponentsImmediately() && this._forceReleaseExitingVRenderComponents(), this.clear(), super.release(), null === (_a = this.pluginService) || void 0 === _a || _a.releaseAll(), this.pluginService = null; } _shouldReleaseVRenderComponentsImmediately() { return this._forceReleaseVRenderComponents; } _forceReleaseExitingVRenderComponents() { var _a; (null === (_a = this._exitingVRenderComponents) || void 0 === _a ? void 0 : _a.size) && (this._exitingVRenderComponents.forEach((component => { var _a, _b, _c; (0, release_vrender_component_1.releaseVRenderComponentSync)(component), null === (_c = null === (_b = null === (_a = this._option) || void 0 === _a ? void 0 : _a.globalInstance) || void 0 === _b ? void 0 : _b._unregisterExitingVRenderComponent) || void 0 === _c || _c.call(_b, component); })), this._exitingVRenderComponents.clear()); } _releaseVRenderComponent(component) { var _a; if (!this._shouldReleaseVRenderComponentsImmediately()) { const exitingComponents = (0, release_vrender_component_1.collectVRenderComponents)(component), releasedWithExit = (0, release_vrender_component_1.releaseVRenderComponent)(component, { enableExitAnimation: !0, removeFromParent: !0, onComplete: () => { exitingComponents.forEach((exitingComponent => { var _a, _b, _c, _d; null === (_a = this._exitingVRenderComponents) || void 0 === _a || _a.delete(exitingComponent), null === (_d = null === (_c = null === (_b = this._option) || void 0 === _b ? void 0 : _b.globalInstance) || void 0 === _c ? void 0 : _c._unregisterExitingVRenderComponent) || void 0 === _d || _d.call(_c, exitingComponent); })); } }); return releasedWithExit ? (this._exitingVRenderComponents = null !== (_a = this._exitingVRenderComponents) && void 0 !== _a ? _a : new Set, void exitingComponents.forEach((exitingComponent => { var _a, _b, _c; this._exitingVRenderComponents.add(exitingComponent), null === (_c = null === (_b = null === (_a = this._option) || void 0 === _a ? void 0 : _a.globalInstance) || void 0 === _b ? void 0 : _b._registerExitingVRenderComponent) || void 0 === _c || _c.call(_b, exitingComponent); }))) : void 0; } (0, release_vrender_component_1.releaseVRenderComponentSync)(component); } clear() { var _a; const components = this._getNeedClearVRenderComponents(); components && components.length && components.forEach((c => { c && this._releaseVRenderComponent(c); })), this._container = null, null === (_a = this.pluginService) || void 0 === _a || _a.clearAll(); } compile() { this.compileMarks(), this.reAppendComponents(); } compileMarks(group) { this.getMarks().forEach((m => { m.compile({ group: group, context: { model: this } }); })); } reAppendComponents() { const components = this._getNeedClearVRenderComponents(); components && components.length && components.forEach((c => { var _a; c && !c.stage && (null === (_a = this.getContainer()) || void 0 === _a || _a.appendChild(c)); })); } getBoundsInRect(rect, fullRect) { return { x1: 0, x2: 0, y1: 0, y2: 0 }; } getDatum(graphic) {} } exports.BaseComponent = BaseComponent, BaseComponent.transformerConstructor = base_component_transformer_1.BaseComponentSpecTransformer; //# sourceMappingURL=base-component.js.map