UNPKG

@senx/discovery-widgets

Version:

Discovery Widgets Elements

319 lines (318 loc) 10.7 kB
/* * Copyright 2022-2025 SenX S.A.S. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { h, Host } from "@stencil/core"; import { DataModel } from "../../model/types"; import { Param } from "../../model/param"; import { Logger } from "../../utils/logger"; import { GTSLib } from "../../utils/gts.lib"; import { Utils } from "../../utils/utils"; export class DiscoveryImageComponent { constructor() { this.options = new Param(); this.debug = false; this.unit = ''; this.parsing = false; this.toDisplay = []; this.defOptions = new Param(); this.initial = false; } updateRes(newValue, oldValue) { if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) { this.result = GTSLib.getData(this.result); this.toDisplay = this.convert(this.result || new DataModel()); this.draw.emit(); } } componentWillLoad() { setTimeout(() => { var _a; this.parsing = true; this.initial = true; this.LOG = new Logger(DiscoveryImageComponent, this.debug); if (typeof this.options === 'string') { this.options = JSON.parse(this.options); } this.result = GTSLib.getData(this.result); this.toDisplay = this.convert(this.result || new DataModel()); (_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['componentWillLoad'], { type: this.type, options: this.options, toDisplay: this.toDisplay, result: this.result, }); this.parsing = false; if (this.initial) { this.draw.emit(); this.initial = false; } }); } convert(data) { const toDisplay = []; let options = Utils.mergeDeep(this.defOptions, this.options || {}); options = Utils.mergeDeep(options || {}, data.globalParams); this.options = Object.assign({}, options); if (GTSLib.isArray(data.data)) { (data.data || []).forEach(img => { if (GTSLib.isEmbeddedImage(img)) { toDisplay.push(img); } }); } else if (data.data && GTSLib.isEmbeddedImage(data.data)) { toDisplay.push(data.data); } return toDisplay; } // noinspection JSUnusedLocalSymbols async export(_type = 'png') { return Promise.resolve(this.toDisplay); } render() { return (h(Host, { key: 'a231a10c3985277591f817ac7542de558509a78d' }, h("div", { key: '18c22519a05791543b0853ef3983008d7d57deae', class: "images-wrapper", style: { width: '100%', height: '100%' } }, this.parsing ? h("discovery-spinner", null, "Parsing data...") : this.toDisplay.length > 0 ? this.toDisplay.map((img) => h("img", { src: img, class: "responsive", alt: "Result" })) : ''))); } static get is() { return "discovery-image"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["discovery-image.scss"] }; } static get styleUrls() { return { "$": ["discovery-image.css"] }; } static get properties() { return { "result": { "type": "string", "mutable": false, "complexType": { "original": "DataModel | string", "resolved": "DataModel | string", "references": { "DataModel": { "location": "import", "path": "../../model/types", "id": "src/model/types.ts::DataModel" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "result", "reflect": false }, "type": { "type": "string", "mutable": false, "complexType": { "original": "ChartType", "resolved": "string", "references": { "ChartType": { "location": "import", "path": "../../model/types", "id": "src/model/types.ts::ChartType" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "type", "reflect": false }, "options": { "type": "string", "mutable": false, "complexType": { "original": "Param | string", "resolved": "Param | string", "references": { "Param": { "location": "import", "path": "../../model/param", "id": "src/model/param.ts::Param" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "options", "reflect": false, "defaultValue": "new Param()" }, "width": { "type": "number", "mutable": false, "complexType": { "original": "number", "resolved": "number", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "width", "reflect": false }, "height": { "type": "number", "mutable": false, "complexType": { "original": "number", "resolved": "number", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "height", "reflect": false }, "debug": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "debug", "reflect": false, "defaultValue": "false" }, "unit": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "unit", "reflect": false, "defaultValue": "''" } }; } static get states() { return { "parsing": {}, "toDisplay": {} }; } static get events() { return [{ "method": "draw", "name": "draw", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "void", "resolved": "void", "references": {} } }]; } static get methods() { return { "export": { "complexType": { "signature": "(_type?: \"png\" | \"svg\") => Promise<string[]>", "parameters": [{ "name": "_type", "type": "\"svg\" | \"png\"", "docs": "" }], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<string[]>" }, "docs": { "text": "", "tags": [] } } }; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "result", "methodName": "updateRes" }]; } } //# sourceMappingURL=discovery-image.js.map