UNPKG

@senx/discovery-plugin-marauder

Version:

Discovery plugin - Marauder's map

831 lines (827 loc) 44.8 kB
import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client'; import { a as DataModel } from './types.js'; import { P as Param, G as GTSLib, U as Utils, L as Logger, _, v as v4 } from './utils.js'; import { i as init } from './index3.js'; import { C as ColorLib } from './color-lib.js'; import { d as defineCustomElement$1 } from './discovery-spinner2.js'; const discoveryBarCss = "/*!\n * Copyright 2022 SenX S.A.S.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */:host>div{width:100%;height:100%}:host>div>div{width:100%;height:100%}:host .wv-tooltip{max-width:300px}:host .wv-tooltip div{word-wrap:anywhere}"; const DiscoveryBarStyle0 = discoveryBarCss; const DiscoveryBarComponent = /*@__PURE__*/ proxyCustomElement(class DiscoveryBarComponent extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.draw = createEvent(this, "draw", 7); this.dataZoom = createEvent(this, "dataZoom", 7); this.leftMarginComputed = createEvent(this, "leftMarginComputed", 7); this.dataPointOver = createEvent(this, "dataPointOver", 7); this.dataPointSelected = createEvent(this, "dataPointSelected", 7); this.timeBounds = createEvent(this, "timeBounds", 7); this.poi = createEvent(this, "poi", 7); this.options = Object.assign(Object.assign({}, new Param()), { timeMode: 'date' }); this.debug = false; this.parsing = false; this.rendering = false; this.defOptions = Object.assign(Object.assign({}, new Param()), { timeMode: 'date' }); this.divider = 1000; this.hasFocus = false; this.isGTS = false; this.pois = []; this.innerWidth = 0; this.innerHeight = 0; this.zoomXInfo = {}; } updateRes() { this.chartOpts = this.convert(GTSLib.getData(this.result)); this.setOpts(true); } optionsUpdate(newValue, oldValue) { var _a, _b, _c; (_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['optionsUpdate'], newValue, oldValue); let opts = newValue; if (!!newValue && typeof newValue === 'string') { opts = JSON.parse(newValue); } if (!Utils.deepEqual(opts, this.innerOptions)) { this.innerOptions = Utils.clone(opts); if (!!this.myChart) { this.chartOpts = this.convert((_b = this.result) !== null && _b !== void 0 ? _b : new DataModel()); this.setOpts(true); } (_c = this.LOG) === null || _c === void 0 ? void 0 : _c.debug(['optionsUpdate 2'], { options: this.innerOptions, newValue, oldValue }, this.chartOpts); } } async resize() { const dims = Utils.getContentBounds(this.el.parentElement); const width = dims.w - 4; const height = dims.h; if (this.myChart && (this.innerWidth !== width || this.innerHeight !== dims.h)) { this.innerWidth = width; this.innerHeight = this.innerHeight !== dims.h ? height - this.el.parentElement.offsetTop : this.innerHeight; this.myChart.resize({ width: this.innerWidth, height: this.innerHeight, silent: true }); } return Promise.resolve(); } async setZoom(dataZoom) { var _a, _b, _c; if (!!this.myChart) { dataZoom.start = (_a = dataZoom.start) !== null && _a !== void 0 ? _a : 0; if (((_b = this.zoom) === null || _b === void 0 ? void 0 : _b.start) !== dataZoom.start || ((_c = this.zoom) === null || _c === void 0 ? void 0 : _c.end) !== dataZoom.end) { this.zoom = dataZoom; this.myChart.dispatchAction(Object.assign(Object.assign({ type: 'dataZoom' }, dataZoom), { dataZoomIndex: 0 })); } } return Promise.resolve(); } // noinspection JSUnusedGlobalSymbols componentWillLoad() { var _a, _b; this.parsing = true; this.LOG = new Logger(DiscoveryBarComponent, this.debug); if (typeof this.options === 'string') { this.innerOptions = JSON.parse(this.options); } else { this.innerOptions = this.options; } this.result = GTSLib.getData(this.result); this.divider = GTSLib.getDivider(this.options.timeUnit || 'us'); this.chartOpts = this.convert(this.result || new DataModel()); (_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['componentWillLoad'], { type: this.type, options: this.innerOptions, chartOpts: this.chartOpts, }); (_b = this.LOG) === null || _b === void 0 ? void 0 : _b.debug(['componentWillLoad'], this.el.parentElement.parentElement); this.setOpts(); } setOpts(notMerge = false) { var _a, _b; if ((((_a = this.chartOpts) === null || _a === void 0 ? void 0 : _a.series) || []).length === 0) { this.chartOpts.title = { show: true, textStyle: { color: Utils.getLabelColor(this.el), fontSize: 20 }, text: this.innerOptions.noDataLabel || '', left: 'center', top: 'center', }; this.chartOpts.xAxis = { show: false }; this.chartOpts.yAxis = { show: false }; this.chartOpts.tooltip = { show: false }; } else { this.chartOpts.title = Object.assign(Object.assign({}, (_b = this.chartOpts.title) !== null && _b !== void 0 ? _b : {}), { show: false }); } setTimeout(() => { var _a; if (this.myChart) { this.myChart.setOption((_a = this.chartOpts) !== null && _a !== void 0 ? _a : {}, notMerge, true); if (this.zoomXInfo.start !== undefined) { this.myChart.dispatchAction({ type: 'dataZoom', start: this.zoomXInfo.start, end: this.zoomXInfo.end, dataZoomIndex: 0, }); } } }); } getCommonSeriesParam(color, params) { var _a, _b, _c, _d, _e, _f; const isHorizontal = !!this.innerOptions.bar && !!this.innerOptions.bar.horizontal; const isStacked = (params === null || params === void 0 ? void 0 : params.stacked) !== undefined ? params === null || params === void 0 ? void 0 : params.stacked : (_c = (_b = (_a = this.innerOptions) === null || _a === void 0 ? void 0 : _a.bar) === null || _b === void 0 ? void 0 : _b.stacked) !== null && _c !== void 0 ? _c : (_d = this.innerOptions) === null || _d === void 0 ? void 0 : _d.stacked; const datasetNoAlpha = this.innerOptions.datasetNoAlpha; return { stack: isStacked ? 'total' : undefined, stackStrategy: isStacked ? 'all' : undefined, animation: !!((_f = (_e = this.innerOptions) === null || _e === void 0 ? void 0 : _e.bar) === null || _f === void 0 ? void 0 : _f.animate), large: true, clip: false, emphasis: { focus: 'series', itemStyle: { opacity: 1, borderColor: color, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.8), }, }, blur: { lineStyle: { color }, itemStyle: { opacity: 0.8, borderColor: color, color: { type: 'linear', x: isHorizontal ? 1 : 0, y: 0, x2: 0, y2: isHorizontal ? 0 : 1, colorStops: [ { offset: 0, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.7) }, { offset: 1, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.3) }, ], }, }, }, label: { show: !!this.innerOptions.showValues, position: 'top', textStyle: { color: Utils.getLabelColor(this.el), fontSize: 14 }, }, lineStyle: { color }, itemStyle: { opacity: 0.8, borderColor: color, color: { type: 'linear', x: isHorizontal ? 1 : 0, y: 0, x2: 0, y2: isHorizontal ? 0 : 1, colorStops: [ { offset: 0, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.7) }, { offset: 1, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.3) }, ], }, }, }; } convert(data) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23; let options = Utils.mergeDeep(this.defOptions, this.innerOptions || {}); options = Utils.mergeDeep(options || {}, data.globalParams); this.innerOptions = Utils.clone(options); const series = []; let gtsList; if (GTSLib.isArray(data.data)) { data.data = GTSLib.flatDeep(data.data); (_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['convert', 'isArray']); if (data.data.length > 0 && GTSLib.isGts(data.data[0])) { (_b = this.LOG) === null || _b === void 0 ? void 0 : _b.debug(['convert', 'isArray 2']); gtsList = GTSLib.flattenGtsIdArray(data.data, 0).res; } else { (_c = this.LOG) === null || _c === void 0 ? void 0 : _c.debug(['convert', 'isArray 3']); gtsList = data.data; } } else { (_d = this.LOG) === null || _d === void 0 ? void 0 : _d.debug(['convert', 'not array']); gtsList = [data.data]; } (_e = this.LOG) === null || _e === void 0 ? void 0 : _e.debug(['convert'], { options: this.innerOptions, gtsList }); const gtsCount = gtsList.length; let min = Number.MAX_SAFE_INTEGER; let max = Number.MIN_SAFE_INTEGER; let hasTimeBounds = false; const opts = Object.assign({ animation: !!((_g = (_f = this.innerOptions) === null || _f === void 0 ? void 0 : _f.bar) === null || _g === void 0 ? void 0 : _g.animate), grid: { left: (!!this.innerOptions.leftMargin && this.innerOptions.leftMargin > this.leftMargin) ? this.innerOptions.leftMargin - this.leftMargin + 10 : 10, top: !((_j = (_h = this.innerOptions) === null || _h === void 0 ? void 0 : _h.bar) === null || _j === void 0 ? void 0 : _j.horizontal) && !!(this.unit || this.innerOptions.unit) ? 30 : 10, bottom: !!this.innerOptions.showLegend ? ((_l = (_k = this.innerOptions) === null || _k === void 0 ? void 0 : _k.bar) === null || _l === void 0 ? void 0 : _l.horizontal) && !!(this.unit || this.innerOptions.unit) ? 50 : 30 : ((_o = (_m = this.innerOptions) === null || _m === void 0 ? void 0 : _m.bar) === null || _o === void 0 ? void 0 : _o.horizontal) && !!(this.unit || this.innerOptions.unit) ? 20 : 10 + (!!this.innerOptions.showRangeSelector ? 40 : 0), right: 10, containLabel: true, }, visualMap: new Array(gtsCount), tooltip: { trigger: 'axis', transitionDuration: 0, axisPointer: { type: 'shadow' }, backgroundColor: Utils.getCSSColor(this.el, '--warp-view-tooltip-bg-color', 'white'), hideDelay: this.innerOptions.tooltipDelay || 100, formatter: (params) => { return `<div style="font-size:14px;color:#666;font-weight:400;line-height:1;">${this.innerOptions.timeMode !== 'date' ? params[0].value[0] : (GTSLib.toISOString(GTSLib.zonedTimeToUtc(params[0].value[0], 1, this.innerOptions.timeZone), 1, this.innerOptions.timeZone, this.innerOptions.fullDateDisplay ? this.innerOptions.timeFormat : undefined) || '') .replace('T', ' ').replace(/\+[0-9]{2}:[0-9]{2}$/gi, '')}</div> ${params.map(s => `${s.marker} <span style="font-size:14px;color:#666;font-weight:400;margin-left:2px">${GTSLib.getName(s.seriesName)}</span> <span style="float:right;margin-left:20px;font-size:14px;color:#666;font-weight:900">${s.value[1]}</span>`).join('<br>')}`; }, }, toolbox: { show: this.innerOptions.showControls, feature: { saveAsImage: { type: 'png', excludeComponents: ['toolbox'] }, restore: { show: true }, }, }, legend: { bottom: 0, left: 'center', show: !!this.innerOptions.showLegend, height: 30, type: 'scroll', textStyle: { color: Utils.getLabelColor(this.el) }, formatter: n => GTSLib.getName(n), }, dataZoom: [ { type: 'slider', height: '20px', show: !!this.innerOptions.showRangeSelector, bottom: !!this.innerOptions.showLegend ? 30 : 20, }, { type: 'inside', orient: 'vertical', zoomOnMouseWheel: 'ctrl', }, { type: 'inside', orient: 'horizontal', zoomOnMouseWheel: true, }, ], series: [] }, ((_q = (_p = this.innerOptions) === null || _p === void 0 ? void 0 : _p.extra) === null || _q === void 0 ? void 0 : _q.chartOpts) || {}); for (let i = 0; i < gtsCount; i++) { const gts = gtsList[i]; const c = ColorLib.getColor(gts.id || i, this.innerOptions.scheme); let color = ((data.params || [])[i] || { datasetColor: c }).datasetColor || c; if (!!data.params && !!data.params[i] && (data.params[i].pieces || []).length > 0) { opts.visualMap[i] = { show: false, seriesIndex: i, borderColor: color, dimension: !!data.params[i].xpieces ? !(this.innerOptions.bar || { horizontal: false }).horizontal ? 0 : 1 : !(this.innerOptions.bar || { horizontal: false }).horizontal ? 1 : 0, pieces: data.params[gts.id].pieces.map(p => ({ color: p.color || '#D81B60', lte: p.lte, gte: p.gte })), outOfRange: { color }, }; } if (GTSLib.isGtsToPlot(gts) && !!gts.v) { this.isGTS = true; min = Math.min(min, ...gts.v.map(v => v[0])); max = Math.max(max, ...gts.v.map(v => v[0])); hasTimeBounds = true; let type = ((data.params || [])[i] || { type: 'bar' }).type || 'bar'; const datasetNoAlpha = (_t = (_s = ((_r = data.params) !== null && _r !== void 0 ? _r : [])[i]) === null || _s === void 0 ? void 0 : _s.datasetNoAlpha) !== null && _t !== void 0 ? _t : this.innerOptions.datasetNoAlpha; let areaStyle; if (type === 'area') { type = 'line'; areaStyle = { opacity: 0.8, color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.7) }, { offset: 1, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.1) }, ], global: false, // false by default }, }; } opts.series.push(Object.assign(Object.assign({}, this.getCommonSeriesParam(color, ((_u = data.params) !== null && _u !== void 0 ? _u : [])[i])), { id: gts.id, type, areaStyle, name: GTSLib.setName(gts.id, ((_w = (((_v = data.params) !== null && _v !== void 0 ? _v : [])[i] || { key: undefined }).key) !== null && _w !== void 0 ? _w : GTSLib.serializeGtsMetadata(gts))), data: gts.v .sort((a, b) => a[0] < b[0] ? -1 : 1) .map((d) => { const ts = this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(d[0], this.divider, this.innerOptions.timeZone) : d[0]; if (!!(this.innerOptions.bar || { horizontal: false }).horizontal) { return [d[d.length - 1], ts]; } else { return [ts, d[d.length - 1]]; } }) })); } else if (!gts.v) { this.innerOptions.timeMode = 'custom'; (_x = this.LOG) === null || _x === void 0 ? void 0 : _x.debug(['convert', 'gts'], gts); ((_y = gts.columns) !== null && _y !== void 0 ? _y : []).forEach((label, index) => { var _a, _b, _c, _d, _e, _f; const datasetNoAlpha = (_c = (_b = ((_a = data.params) !== null && _a !== void 0 ? _a : [])[index]) === null || _b === void 0 ? void 0 : _b.datasetNoAlpha) !== null && _c !== void 0 ? _c : this.innerOptions.datasetNoAlpha; color = (_f = (_e = ((_d = data.params) !== null && _d !== void 0 ? _d : [])[index]) === null || _e === void 0 ? void 0 : _e.datasetColor) !== null && _f !== void 0 ? _f : ColorLib.getColor(index, this.innerOptions.scheme); let type = ((data.params || [])[index] || { type: 'bar' }).type || 'bar'; let areaStyle; if (type === 'area') { type = 'line'; areaStyle = { opacity: 0.8, color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.7) }, { offset: 1, color: ColorLib.transparentize(color, datasetNoAlpha ? 1 : 0.1) }, ], global: false, // false by default }, }; } opts.series.push(Object.assign(Object.assign({}, this.getCommonSeriesParam(color, (data.params || [])[index])), { name: label, type, areaStyle, data: gts.rows.map((r) => { return !!(this.innerOptions.bar || { horizontal: false }).horizontal ? [r[index + 1], r[0]] : [r[0], r[index + 1]]; }) })); }); } } opts.yAxis = { name: !((_0 = (_z = this.innerOptions) === null || _z === void 0 ? void 0 : _z.bar) === null || _0 === void 0 ? void 0 : _0.horizontal) ? this.unit || this.innerOptions.unit : undefined, show: !this.innerOptions.hideYAxis, emphasis: { focus: 'series' }, nameTextStyle: { color: Utils.getLabelColor(this.el) }, type: ((_2 = (_1 = this.innerOptions) === null || _1 === void 0 ? void 0 : _1.bar) === null || _2 === void 0 ? void 0 : _2.horizontal) ? this.isGTS ? this.innerOptions.timeMode === 'date' ? 'time' : 'category' : 'category' : 'value', splitLine: { lineStyle: { color: Utils.getGridColor(this.el) } }, axisLine: { lineStyle: { color: Utils.getGridColor(this.el) } }, axisLabel: { hideOverlap: true, color: Utils.getLabelColor(this.el), show: !this.innerOptions.hideYAxis, formatter: ((_4 = (_3 = this.innerOptions) === null || _3 === void 0 ? void 0 : _3.bar) === null || _4 === void 0 ? void 0 : _4.horizontal) ? this.innerOptions.timeMode === 'date' ? this.innerOptions.fullDateDisplay ? (value) => GTSLib.toISOString(GTSLib.zonedTimeToUtc(value, 1, this.innerOptions.timeZone), 1, this.innerOptions.timeZone, this.innerOptions.timeFormat) .replace('T', '\n').replace(/\+[0-9]{2}:[0-9]{2}$/gi, '') : undefined : undefined : undefined, }, axisTick: { lineStyle: { color: Utils.getGridColor(this.el) }, }, min: ((_6 = (_5 = this.innerOptions) === null || _5 === void 0 ? void 0 : _5.bar) === null || _6 === void 0 ? void 0 : _6.horizontal) ? ((_7 = this.innerOptions.bounds) === null || _7 === void 0 ? void 0 : _7.minDate) !== undefined ? this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(this.innerOptions.bounds.minDate, this.divider, this.innerOptions.timeZone) : this.innerOptions.bounds.minDate : undefined : this.innerOptions.bounds && this.innerOptions.bounds.yRanges && this.innerOptions.bounds.yRanges.length > 0 ? this.innerOptions.bounds.yRanges[0] : undefined, max: ((_9 = (_8 = this.innerOptions) === null || _8 === void 0 ? void 0 : _8.bar) === null || _9 === void 0 ? void 0 : _9.horizontal) ? ((_10 = this.innerOptions.bounds) === null || _10 === void 0 ? void 0 : _10.maxDate) !== undefined ? this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(this.innerOptions.bounds.maxDate, this.divider, this.innerOptions.timeZone) : this.innerOptions.bounds.maxDate : undefined : this.innerOptions.bounds && this.innerOptions.bounds.yRanges && this.innerOptions.bounds.yRanges.length > 0 ? this.innerOptions.bounds.yRanges[1] : undefined, }; opts.xAxis = { name: ((_12 = (_11 = this.innerOptions) === null || _11 === void 0 ? void 0 : _11.bar) === null || _12 === void 0 ? void 0 : _12.horizontal) ? this.unit || this.innerOptions.unit : undefined, nameTextStyle: { padding: [0, 10, -35, 0], align: 'right', verticalAlign: 'bottom', }, show: !this.innerOptions.hideXAxis, emphasis: { focus: 'series' }, type: ((_14 = (_13 = this.innerOptions) === null || _13 === void 0 ? void 0 : _13.bar) === null || _14 === void 0 ? void 0 : _14.horizontal) ? 'value' : this.isGTS ? this.innerOptions.timeMode === 'date' ? 'time' : 'category' : 'category', axisLine: { lineStyle: { color: Utils.getGridColor(this.el) } }, axisLabel: { hideOverlap: true, show: !this.innerOptions.hideXAxis, color: Utils.getLabelColor(this.el), formatter: !((_16 = (_15 = this.innerOptions) === null || _15 === void 0 ? void 0 : _15.bar) === null || _16 === void 0 ? void 0 : _16.horizontal) ? this.innerOptions.timeMode === 'date' ? this.innerOptions.fullDateDisplay ? (value) => GTSLib.toISOString(GTSLib.zonedTimeToUtc(value, 1, this.innerOptions.timeZone), 1, this.innerOptions.timeZone, this.innerOptions.timeFormat) .replace('T', '\n').replace(/\+[0-9]{2}:[0-9]{2}$/gi, '') : undefined : undefined : undefined, }, axisTick: { lineStyle: { color: Utils.getGridColor(this.el) } }, min: ((_18 = (_17 = this.innerOptions) === null || _17 === void 0 ? void 0 : _17.bar) === null || _18 === void 0 ? void 0 : _18.horizontal) ? this.innerOptions.bounds && this.innerOptions.bounds.yRanges && this.innerOptions.bounds.yRanges.length > 0 ? this.innerOptions.bounds.yRanges[0] : undefined : ((_19 = this.innerOptions.bounds) === null || _19 === void 0 ? void 0 : _19.minDate) !== undefined ? this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(this.innerOptions.bounds.minDate, this.divider, this.innerOptions.timeZone) : this.innerOptions.bounds.minDate : undefined, max: ((_21 = (_20 = this.innerOptions) === null || _20 === void 0 ? void 0 : _20.bar) === null || _21 === void 0 ? void 0 : _21.horizontal) ? this.innerOptions.bounds && this.innerOptions.bounds.yRanges && this.innerOptions.bounds.yRanges.length > 0 ? this.innerOptions.bounds.yRanges[1] : undefined : ((_22 = this.innerOptions.bounds) === null || _22 === void 0 ? void 0 : _22.maxDate) !== undefined ? this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(this.innerOptions.bounds.maxDate, this.divider, this.innerOptions.timeZone) : this.innerOptions.bounds.maxDate : undefined, }; if (hasTimeBounds) { this.timeBounds.emit({ min, max }); this.bounds = { min, max }; } (_23 = this.LOG) === null || _23 === void 0 ? void 0 : _23.debug(['convert', 'series'], series); const markArea = [...(this.innerOptions.thresholds || []) .map(t => { const m = [{ itemStyle: { color: ColorLib.transparentize(t.color || '#f44336', !!t.fill ? 0.3 : 0) } }, {}]; if (!!(this.innerOptions.bar || { horizontal: false }).horizontal) { m[0].xAxis = t.value || 0; m[1] = { itemStyle: t.from ? { color: ColorLib.transparentize(t.color || '#f44336', !!t.fill ? 0.3 : 0) } : undefined, xAxis: t.from || 0, }; m[0].name = `${t.value || 0}`; m[0].label = { color: t.color || '#f44336', position: 'insideTopRight' }; } else { m[0].yAxis = t.value || 0; m[1] = { itemStyle: t.from ? { color: ColorLib.transparentize(t.color || '#f44336', !!t.fill ? 0.3 : 0) } : undefined, yAxis: t.from || 0, }; } return m; }), ...(this.innerOptions.markers || []) .filter(t => !!t.fill) .map(t => { return [{ itemStyle: { color: ColorLib.transparentize(t.color || '#D81B60', !!t.fill ? t.alpha || 0.5 : 0), borderType: t.type || 'dashed', }, label: { color: t.color || '#D81B60', position: 'insideTopRight', distance: 5, show: !!t.name }, name: t.name || t.value || 0, yAxis: (!!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.value / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, xAxis: (!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.value / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, }, { itemStyle: { color: ColorLib.transparentize(t.color || '#D81B60', !!t.fill ? t.alpha || 0.5 : 0), borderType: t.type || 'dashed', }, yAxis: (!!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.start / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, xAxis: (!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.start / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, }]; })]; const markLine = [...(this.innerOptions.thresholds || []) .map(t => { const m = { name: t.value || 0, label: { color: t.color || '#f44336', position: 'insideEndTop' }, lineStyle: { color: t.color || '#f44336', type: 'dashed' }, }; if (!!(this.innerOptions.bar || { horizontal: false }).horizontal) { m.xAxis = t.value || 0; m.label.show = false; } else { m.yAxis = t.value || 0; } return m; }), ...(this.innerOptions.markers || []) .filter(t => !t.fill) .map(t => { return { name: t.name || t.value || 0, label: { color: t.color || '#D81B60', position: 'insideEndTop', formatter: '{b}', show: !!t.name }, lineStyle: { color: t.color || '#D81B60', type: t.type || 'dashed' }, yAxis: (!!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.value / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, xAxis: (!(this.innerOptions.bar || { horizontal: false }).horizontal) ? ((t.value / (this.innerOptions.timeMode === 'date' ? this.divider : 1)) || 0) : undefined, }; })]; if (markLine.length > 0) { opts.series.push({ name: '', type: 'line', symbolSize: 0, data: [], markArea: { data: markArea, }, markLine: { emphasis: { lineStyle: { width: 1 } }, symbol: ['none', 'none'], data: markLine, }, }); } this.parsing = false; return opts; } zoomHandler(start, end) { var _a, _b, _c, _d, _e, _f; this.zoomXInfo = { start, end, min: (_b = (_a = this.innerOptions.bounds) === null || _a === void 0 ? void 0 : _a.minDate) !== null && _b !== void 0 ? _b : (_c = this.bounds) === null || _c === void 0 ? void 0 : _c.min, max: (_e = (_d = this.innerOptions.bounds) === null || _d === void 0 ? void 0 : _d.maxDate) !== null && _e !== void 0 ? _e : (_f = this.bounds) === null || _f === void 0 ? void 0 : _f.max, orientation: 'x', }; this.dataZoom.emit(this.zoomXInfo); } // noinspection JSUnusedGlobalSymbols componentDidLoad() { const zoomHandler = _.throttle((start, end) => this.zoomHandler(start, end), 16, { leading: true, trailing: true }); const focusHandler = _.throttle((type, event) => { if (this.hasFocus) { switch (type) { case 'mouseover': const c = event.data.coord || event.data; this.dataPointOver.emit({ date: c[0], name: GTSLib.getName(event.seriesName), value: c[1], meta: {} }); break; case 'highlight': let ts; (event.batch || []).forEach(b => { const s = this.myChart.getOption().series[b.seriesIndex]; ts = s.data[b.dataIndex][0]; ts = this.innerOptions.timeMode === 'date' ? GTSLib.zonedTimeToUtc(ts * this.divider, this.divider, this.innerOptions.timeZone || 'UTC') * this.divider : ts; }); if (ts !== undefined) { this.dataPointSelected.emit({ date: ts, name: '.*', meta: {} }); } break; } } }, 100, { leading: true, trailing: true }); setTimeout(() => { this.height = Utils.getContentBounds(this.el.parentElement).h; this.parsing = false; this.rendering = true; let initial = false; this.myChart = init(this.graph); this.myChart.on('rendered', () => { this.rendering = false; let found = false; let x = 0; setTimeout(() => { while (!found && x < 1024) { found = this.myChart.containPixel({ gridIndex: 0 }, [x, this.myChart.getHeight() / 2]); x++; } if (this.leftMargin !== x && x < 1024) { setTimeout(() => { this.leftMarginComputed.emit(x); this.leftMargin = x; }); } if (initial) setTimeout(() => this.draw.emit()); initial = false; }); }); this.myChart.on('dataZoom', (event) => { let start; let end; if (!!event.batch) { const batch = (event.batch || [])[0] || {}; start = batch.start || batch.startValue; end = batch.end || batch.endValue; this.zoomHandler(start, end); } else if (event.start !== undefined && event.end !== undefined) { start = event.start; end = event.end; zoomHandler(start, end); } }); this.myChart.on('restore', () => { this.dataZoom.emit({ type: 'restore', start: 0, end: 100 }); }); this.el.addEventListener('dblclick', () => this.myChart.dispatchAction({ type: 'dataZoom', start: 0, end: 100, })); this.el.addEventListener('mouseover', () => this.hasFocus = true); this.el.addEventListener('mouseout', () => { this.hasFocus = false; this.dataPointOver.emit({}); }); this.myChart.on('mouseout', () => { this.dataPointOver.emit({}); }); this.myChart.on('mouseover', (event) => focusHandler('mouseover', event)); this.myChart.on('highlight', (event) => focusHandler('highlight', event)); this.myChart.on('click', (event) => { const date = this.innerOptions.timeMode === 'date' ? GTSLib.zonedTimeToUtc(event.value[0], 1, this.innerOptions.timeZone) * this.divider : event.value[0]; if (event.componentType !== 'markLine') { this.dataPointSelected.emit({ date, name: GTSLib.getName(event.seriesName), value: event.value[1], meta: {}, }); } if (this.innerOptions.poi) { if (this.pois.find(p => p.date === event.value[0])) { this.pois = this.pois.filter(p => p.date !== event.value[0]); } else if (event.componentType !== 'markLine') { this.pois.push({ date, name: GTSLib.getName(event.seriesName), value: event.value[1], meta: {}, uid: v4(), }); } this.chartOpts.series = this.chartOpts.series.filter(s => 'poi' !== s.id); this.poi.emit(this.pois); this.chartOpts.series.push({ id: 'poi', name: '', type: 'line', data: [], markLine: { emphasis: { lineStyle: { width: 1 } }, symbol: ['none', 'pin'], symbolSize: 20, symbolKeepAspect: true, data: this.pois.map(p => ({ name: 'poi-' + p.uid, label: { show: false }, lineStyle: { color: this.innerOptions.poiColor, type: this.innerOptions.poiLine }, xAxis: this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(p.date / this.divider, 1, this.innerOptions.timeZone) : p.date, })), }, }); setTimeout(() => { var _a; return this.myChart.setOption((_a = this.chartOpts) !== null && _a !== void 0 ? _a : {}, true, false); }); } }); this.setOpts(); initial = true; }); } async export(type = 'png') { return Promise.resolve(this.myChart ? this.myChart.getDataURL({ type, excludeComponents: ['toolbox'], }) : undefined); } async show(regexp) { this.myChart.dispatchAction({ type: 'legendSelect', batch: this.myChart.getOption().series .filter(s => new RegExp(regexp).test(GTSLib.getName(s.name))), }); return Promise.resolve(); } async hide(regexp) { this.myChart.dispatchAction({ type: 'legendUnSelect', batch: this.myChart.getOption().series .filter(s => new RegExp(regexp).test(GTSLib.getName(s.name))), }); return Promise.resolve(); } async hideById(id) { if (this.myChart) { this.myChart.dispatchAction({ type: 'legendUnSelect', batch: this.myChart.getOption().series .filter((s, i) => new RegExp(id.toString()).test((s.id || i).toString())), }); } return Promise.resolve(); } async showById(id) { if (this.myChart) { this.myChart.dispatchAction({ type: 'legendSelect', batch: this.myChart.getOption().series .filter((s, i) => new RegExp(id.toString()).test((s.id || i).toString())), }); } return Promise.resolve(); } async setFocus(regexp, ts, value) { var _a; if (!this.myChart || this.hasFocus) return; const date = this.innerOptions.timeMode === 'date' ? GTSLib.utcToZonedTime(ts !== null && ts !== void 0 ? ts : 0, this.divider, this.innerOptions.timeZone) : ts !== null && ts !== void 0 ? ts : 0; let seriesIndex = 0; let dataIndex = 0; if (!!regexp) { this.chartOpts.series .filter(s => new RegExp(regexp).test(GTSLib.getName(s.name))) .forEach(s => { const data = s.data.filter(d => d[0] === date); if (data && data.length > 0 && data[0]) { seriesIndex = this.chartOpts.series.indexOf(s); dataIndex = s.data.indexOf(data[0]); } }); } if (GTSLib.isArray(this.chartOpts.xAxis)) { this.chartOpts.xAxis .forEach(a => { var _a; return a.axisPointer = Object.assign(Object.assign({}, (_a = a.axisPointer) !== null && _a !== void 0 ? _a : {}), { value: date, status: 'show' }); }); } else { this.chartOpts.xAxis.axisPointer = Object.assign(Object.assign({}, this.chartOpts.xAxis.axisPointer || {}), { value: date, status: 'show' }); } if (GTSLib.isArray(this.chartOpts.yAxis)) { this.chartOpts.yAxis .forEach(a => { var _a; return a.axisPointer = Object.assign(Object.assign({}, (_a = a.axisPointer) !== null && _a !== void 0 ? _a : {}), { value: value !== null && value !== void 0 ? value : 0, status: 'show' }); }); } else { this.chartOpts.yAxis.axisPointer = Object.assign(Object.assign({}, (_a = this.chartOpts.yAxis.axisPointer) !== null && _a !== void 0 ? _a : {}), { value: value !== null && value !== void 0 ? value : 0, status: 'show' }); } this.chartOpts.tooltip.show = true; this.myChart.dispatchAction({ type: 'showTip', seriesIndex, dataIndex }); this.setOpts(); return Promise.resolve(); } async unFocus() { if (!this.myChart || this.hasFocus) return; this.chartOpts.series.forEach(s => s.markPoint = undefined); this.chartOpts.xAxis.axisPointer = Object.assign(Object.assign({}, this.chartOpts.xAxis.axisPointer || {}), { status: 'hide' }); this.chartOpts.yAxis.axisPointer = Object.assign(Object.assign({}, this.chartOpts.yAxis.axisPointer || {}), { status: 'hide' }); this.myChart.dispatchAction({ type: 'hideTip' }); this.setOpts(); return Promise.resolve(); } render() { return h("div", { key: 'd86a8ac94609b0d7a6d8659bcdad1e98e00aaf98', style: { width: '100%', height: '100%' } }, this.parsing ? h("discovery-spinner", null, "Parsing data...") : '', this.rendering ? h("discovery-spinner", null, "Rendering data...") : '', h("div", { key: '2b24f737e57b6395dbd980bc4ce66e4ce9334368', ref: (el) => this.graph = el })); } get el() { return this; } static get watchers() { return { "result": ["updateRes"], "options": ["optionsUpdate"] }; } static get style() { return DiscoveryBarStyle0; } }, [1, "discovery-bar", { "result": [1025], "type": [1], "options": [1], "width": [2], "height": [1026], "debug": [4], "unit": [1], "parsing": [32], "rendering": [32], "innerOptions": [32], "resize": [64], "setZoom": [64], "export": [64], "show": [64], "hide": [64], "hideById": [64], "showById": [64], "setFocus": [64], "unFocus": [64] }, undefined, { "result": ["updateRes"], "options": ["optionsUpdate"] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["discovery-bar", "discovery-spinner"]; components.forEach(tagName => { switch (tagName) { case "discovery-bar": if (!customElements.get(tagName)) { customElements.define(tagName, DiscoveryBarComponent); } break; case "discovery-spinner": if (!customElements.get(tagName)) { defineCustomElement$1(); } break; } }); } export { DiscoveryBarComponent as D, defineCustomElement as d }; //# sourceMappingURL=discovery-bar2.js.map