UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

117 lines (111 loc) 4.96 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 vrender_core_1 = require("@visactor/vrender-core"), 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"); class BaseComponent extends layout_model_1.LayoutModel { constructor() { super(...arguments), this.name = "component", this.modelType = "component", this.transformerConstructor = base_component_transformer_1.BaseComponentSpecTransformer, this._delegateEvent = (component, event, type, item = null, datum = null) => { var _a, _b; event instanceof vrender_core_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; } release() { var _a; super.release(), this.clear(), null === (_a = this.pluginService) || void 0 === _a || _a.releaseAll(), this.pluginService = null; } clear() { var _a; const components = this._getNeedClearVRenderComponents(); components && components.length && components.forEach((c => { var _a; c && (null === (_a = this.getContainer()) || void 0 === _a || _a.removeChild(c), c = null); })), 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