UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

157 lines (147 loc) 7.3 kB
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; }; import { CustomEvent } from "@visactor/vrender-core/event/constant"; import { ComponentPluginService } from "../../plugin/components/plugin-service"; import { isEqual } from "@visactor/vutils"; import { Event_Source_Type } from "../../constant/event"; import { LayoutModel } from "../../model/layout-model"; import { BaseComponentSpecTransformer } from "./base-component-transformer"; import { collectVRenderComponents, releaseVRenderComponent, releaseVRenderComponentSync } from "./release-vrender-component"; export class BaseComponent extends LayoutModel { constructor() { super(...arguments), this.name = "component", this.modelType = "component", this.transformerConstructor = BaseComponentSpecTransformer, this._forceReleaseVRenderComponents = !1, this._delegateEvent = (component, event, type, item = null, datum = null) => { var _a, _b; event instanceof CustomEvent || this.event.emit(type, { model: this, node: component, event: event, item: item, datum: datum, source: 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 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 => !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; 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 = collectVRenderComponents(component), releasedWithExit = 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; } 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) {} } BaseComponent.transformerConstructor = BaseComponentSpecTransformer; //# sourceMappingURL=base-component.js.map