@openremote/or-chart 1.2.0-snapshot.20241209103107 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/index.bundle.js +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.orbundle.js +2 -2
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +9 -9
package/dist/umd/index.bundle.js
CHANGED
|
@@ -1037,4 +1037,4 @@
|
|
|
1037
1037
|
<or-mwc-input ${Je(n)} type="${_a.DATETIME}" required label="${Te.t("start")}" .value="${t}"></or-mwc-input>
|
|
1038
1038
|
<or-mwc-input ${Je(i)} type="${_a.DATETIME}" required label="${Te.t("ending")}" .value="${e}"></or-mwc-input>
|
|
1039
1039
|
</div>
|
|
1040
|
-
`)).setActions([{actionName:"cancel",content:"cancel"},{actionName:"ok",content:"ok",action:()=>{var t,e;this.timePresetOptions&&(null===(t=n.value)||void 0===t?void 0:t.value)&&(null===(e=i.value)||void 0===e?void 0:e.value)&&(this.timeframe=[new Date(n.value.value),new Date(i.value.value)])}}]))}_addAttribute(t){return cp(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ee().rest.api.AssetResource.get(e.id);if(this.activeAsset=t.data,this.activeAsset){let t=this.assets.findIndex((t=>t.id===e.id));t<0&&(t=this.assets.length,this.assets=[...this.assets,this.activeAsset]),this.assetAttributes.push([t,e])}}this.assetAttributes=[...this.assetAttributes],this.saveSettings()}}))}_getSelectedAttributes(){return this.assetAttributes.map((([t,e])=>({id:this.assets[t].id,name:e.name})))}onCompleted(){return cp(this,void 0,void 0,(function*(){yield this.updateComplete}))}_cleanup(){this._chart&&(this._chart.destroy(),this._chart=void 0,this.requestUpdate())}_deleteAttribute(t){const e=this.assetAttributes.splice(t,1)[0][0];this.assetAttributes=[...this.assetAttributes],this.assetAttributes.some((([t,n])=>t===e))||(this.assets.splice(t,1),this.assetAttributes.forEach((t=>{t[0]>=e&&(t[0]-=1)}))),this.saveSettings()}_getAttributeOptionsOld(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Se.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ye.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getAttributeOptions(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Se.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ye.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[pm()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[pm()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[pm()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[pm()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[pm()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[pm()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[pm()(t).subtract(1,"year").toDate(),t]]])}_getInterval(t){return t<=1?[5,"MINUTE"]:t<=3?[10,"MINUTE"]:t<=6?[30,"MINUTE"]:t<=24?[1,"HOUR"]:t<=48?[3,"HOUR"]:t<=96?[12,"HOUR"]:t<=744?[1,"DAY"]:[1,"MONTH"]}_loadData(){return cp(this,void 0,void 0,(function*(){if(this._data||!this.assetAttributes||!this.assets||0===this.assets.length&&!this.dataProvider||0===this.assetAttributes.length&&!this.dataProvider||!this.datapointQuery)return;if(this._loading){if(!this._dataAbortController)return;this._dataAbortController.abort("Data request overridden"),delete this._dataAbortController}this._loading=!0;const
|
|
1040
|
+
`)).setActions([{actionName:"cancel",content:"cancel"},{actionName:"ok",content:"ok",action:()=>{var t,e;this.timePresetOptions&&(null===(t=n.value)||void 0===t?void 0:t.value)&&(null===(e=i.value)||void 0===e?void 0:e.value)&&(this.timeframe=[new Date(n.value.value),new Date(i.value.value)])}}]))}_addAttribute(t){return cp(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ee().rest.api.AssetResource.get(e.id);if(this.activeAsset=t.data,this.activeAsset){let t=this.assets.findIndex((t=>t.id===e.id));t<0&&(t=this.assets.length,this.assets=[...this.assets,this.activeAsset]),this.assetAttributes.push([t,e])}}this.assetAttributes=[...this.assetAttributes],this.saveSettings()}}))}_getSelectedAttributes(){return this.assetAttributes.map((([t,e])=>({id:this.assets[t].id,name:e.name})))}onCompleted(){return cp(this,void 0,void 0,(function*(){yield this.updateComplete}))}_cleanup(){this._chart&&(this._chart.destroy(),this._chart=void 0,this.requestUpdate())}_deleteAttribute(t){const e=this.assetAttributes.splice(t,1)[0][0];this.assetAttributes=[...this.assetAttributes],this.assetAttributes.some((([t,n])=>t===e))||(this.assets.splice(t,1),this.assetAttributes.forEach((t=>{t[0]>=e&&(t[0]-=1)}))),this.saveSettings()}_getAttributeOptionsOld(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Se.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ye.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getAttributeOptions(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Se.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ye.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[pm()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[pm()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[pm()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[pm()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[pm()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[pm()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[pm()(t).subtract(1,"year").toDate(),t]]])}_getInterval(t){return t<=1?[5,"MINUTE"]:t<=3?[10,"MINUTE"]:t<=6?[30,"MINUTE"]:t<=24?[1,"HOUR"]:t<=48?[3,"HOUR"]:t<=96?[12,"HOUR"]:t<=744?[1,"DAY"]:[1,"MONTH"]}_loadData(){var t;return cp(this,void 0,void 0,(function*(){if(this._data||!this.assetAttributes||!this.assets||0===this.assets.length&&!this.dataProvider||0===this.assetAttributes.length&&!this.dataProvider||!this.datapointQuery)return;if(this._loading){if(!this._dataAbortController)return;this._dataAbortController.abort("Data request overridden"),delete this._dataAbortController}this._loading=!0;const e=this.timePresetOptions.get(this.timePresetKey)(new Date);this._startOfPeriod=this.timeframe?this.timeframe[0].getTime():e[0].getTime(),this._endOfPeriod=this.timeframe?this.timeframe[1].getTime():e[1].getTime();const n=(this._endOfPeriod-this._startOfPeriod)/1e3/60/60,i=this._getInterval(n),r=i[0],a=i[1],o=a.toLowerCase();this._timeUnits=o,this._stepSize=r;const s=pm()().toDate().getTime();let l=s<this._startOfPeriod?this._startOfPeriod:s;const d=[];let c;try{this.dataProvider?yield this.dataProvider(this._startOfPeriod,this._endOfPeriod,a.toString(),r).then((t=>{t.forEach((t=>{d.push(t)}))})):(this._dataAbortController=new AbortController,c=this.assetAttributes.map((([t,e],n)=>cp(this,void 0,void 0,(function*(){var i;const r=this.assets[t],a=!!this.rightAxisAttributes.find((t=>t.id===r.id&&t.name===e.name)),o=Se.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),s=Ye.Util.getAttributeLabel(e,o[0],r.type,!1),c=Ye.Util.resolveUnits(Ye.Util.getAttributeUnits(e,o[0],r.type)),u=n%this.colors.length,m={signal:null===(i=this._dataAbortController)||void 0===i?void 0:i.signal};let h=yield this._loadAttributeData(r,e,this.colors[u],this._startOfPeriod,this._endOfPeriod,!1,r.name+" "+s,m);h.assetId=r.id,h.attrName=e.name,h.unit=c,h.yAxisID=a?"y1":"y",d.push(h),h=yield this._loadAttributeData(this.assets[t],e,this.colors[u],l,this._endOfPeriod,!0,r.name+" "+s+" "+Te.t("predicted"),m),d.push(h)}))))),c&&(yield Promise.all(c)),this._data=d,this._loading=!1}catch(e){if(console.error(e),"canceled"===(null==e?void 0:e.message))return;if(this._loading=!1,(0,Ih.isAxiosError)(e)){if(e.message.includes("timeout"))return void(this._latestError="noAttributeDataTimeout");if(413===(null===(t=e.response)||void 0===t?void 0:t.status))return void(this._latestError="datapointRequestTooLarge")}this._latestError="errorOccurred"}}))}_loadAttributeData(t,e,n,i,r,a,o,s){var l,d,c;return cp(this,void 0,void 0,(function*(){const i={borderColor:n,backgroundColor:n,label:o,pointRadius:2,fill:!1,data:[],borderDash:a?[2,4]:void 0};if(t.id&&e.name&&this.datapointQuery){let n;const r=JSON.parse(JSON.stringify(this.datapointQuery));if(r.fromTimestamp=this._startOfPeriod,r.toTimestamp=this._endOfPeriod,"lttb"==r.type)r.amountOfPoints?(null===(l=this._chartElem)||void 0===l?void 0:l.clientWidth)>0&&(r.amountOfPoints=Math.min(r.amountOfPoints,null===(d=this._chartElem)||void 0===d?void 0:d.clientWidth)):(null===(c=this._chartElem)||void 0===c?void 0:c.clientWidth)>0?r.amountOfPoints=Math.round(this._chartElem.clientWidth/5):(console.warn("Could not grab width of the Chart for estimating amount of data points. Using 100 points instead."),r.amountOfPoints=100);else if("interval"===r.type&&!r.interval){const t=(this.datapointQuery.toTimestamp-this.datapointQuery.fromTimestamp)/1e3/60/60,e=this._getInterval(t);r.interval=e[0].toString()+" "+e[1].toString()}n=a?yield Ee().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,s):yield Ee().rest.api.AssetDatapointResource.getDatapoints(t.id,e.name,r,s),200===n.status&&(i.data=n.data.filter((t=>null!==t.y&&void 0!==t.y)))}return i}))}};fp.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",dp([ft({type:Object})],fp.prototype,"assets",void 0),dp([ft({type:Object})],fp.prototype,"activeAsset",void 0),dp([ft({type:Object})],fp.prototype,"assetAttributes",void 0),dp([ft({type:Array})],fp.prototype,"rightAxisAttributes",void 0),dp([ft()],fp.prototype,"dataProvider",void 0),dp([ft({type:Array})],fp.prototype,"colors",void 0),dp([ft({type:Object})],fp.prototype,"datapointQuery",void 0),dp([ft({type:Object})],fp.prototype,"config",void 0),dp([ft({type:Object})],fp.prototype,"chartOptions",void 0),dp([ft({type:String})],fp.prototype,"realm",void 0),dp([ft()],fp.prototype,"panelName",void 0),dp([ft()],fp.prototype,"attributeControls",void 0),dp([ft()],fp.prototype,"timeframe",void 0),dp([ft()],fp.prototype,"timestampControls",void 0),dp([ft()],fp.prototype,"timePresetOptions",void 0),dp([ft()],fp.prototype,"timePresetKey",void 0),dp([ft()],fp.prototype,"showLegend",void 0),dp([ft()],fp.prototype,"denseLegend",void 0),dp([ft()],fp.prototype,"_loading",void 0),dp([ft()],fp.prototype,"_data",void 0),dp([ft()],fp.prototype,"_tableTemplate",void 0),dp([gt("#chart")],fp.prototype,"_chartElem",void 0),fp=dp([mt("or-chart")],fp)})(),c})()));
|
package/dist/umd/index.js
CHANGED
|
@@ -1037,4 +1037,4 @@
|
|
|
1037
1037
|
<or-mwc-input ${Je(n)} type="${bo.DATETIME}" required label="${Ce.t("start")}" .value="${t}"></or-mwc-input>
|
|
1038
1038
|
<or-mwc-input ${Je(i)} type="${bo.DATETIME}" required label="${Ce.t("ending")}" .value="${e}"></or-mwc-input>
|
|
1039
1039
|
</div>
|
|
1040
|
-
`)).setActions([{actionName:"cancel",content:"cancel"},{actionName:"ok",content:"ok",action:()=>{var t,e;this.timePresetOptions&&(null===(t=n.value)||void 0===t?void 0:t.value)&&(null===(e=i.value)||void 0===e?void 0:e.value)&&(this.timeframe=[new Date(n.value.value),new Date(i.value.value)])}}]))}_addAttribute(t){return Lc(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Oe().rest.api.AssetResource.get(e.id);if(this.activeAsset=t.data,this.activeAsset){let t=this.assets.findIndex((t=>t.id===e.id));t<0&&(t=this.assets.length,this.assets=[...this.assets,this.activeAsset]),this.assetAttributes.push([t,e])}}this.assetAttributes=[...this.assetAttributes],this.saveSettings()}}))}_getSelectedAttributes(){return this.assetAttributes.map((([t,e])=>({id:this.assets[t].id,name:e.name})))}onCompleted(){return Lc(this,void 0,void 0,(function*(){yield this.updateComplete}))}_cleanup(){this._chart&&(this._chart.destroy(),this._chart=void 0,this.requestUpdate())}_deleteAttribute(t){const e=this.assetAttributes.splice(t,1)[0][0];this.assetAttributes=[...this.assetAttributes],this.assetAttributes.some((([t,n])=>t===e))||(this.assets.splice(t,1),this.assetAttributes.forEach((t=>{t[0]>=e&&(t[0]-=1)}))),this.saveSettings()}_getAttributeOptionsOld(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Te.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Se.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getAttributeOptions(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Te.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Se.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Oo()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Oo()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Oo()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Oo()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Oo()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Oo()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Oo()(t).subtract(1,"year").toDate(),t]]])}_getInterval(t){return t<=1?[5,"MINUTE"]:t<=3?[10,"MINUTE"]:t<=6?[30,"MINUTE"]:t<=24?[1,"HOUR"]:t<=48?[3,"HOUR"]:t<=96?[12,"HOUR"]:t<=744?[1,"DAY"]:[1,"MONTH"]}_loadData(){return Lc(this,void 0,void 0,(function*(){if(this._data||!this.assetAttributes||!this.assets||0===this.assets.length&&!this.dataProvider||0===this.assetAttributes.length&&!this.dataProvider||!this.datapointQuery)return;if(this._loading){if(!this._dataAbortController)return;this._dataAbortController.abort("Data request overridden"),delete this._dataAbortController}this._loading=!0;const
|
|
1040
|
+
`)).setActions([{actionName:"cancel",content:"cancel"},{actionName:"ok",content:"ok",action:()=>{var t,e;this.timePresetOptions&&(null===(t=n.value)||void 0===t?void 0:t.value)&&(null===(e=i.value)||void 0===e?void 0:e.value)&&(this.timeframe=[new Date(n.value.value),new Date(i.value.value)])}}]))}_addAttribute(t){return Lc(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Oe().rest.api.AssetResource.get(e.id);if(this.activeAsset=t.data,this.activeAsset){let t=this.assets.findIndex((t=>t.id===e.id));t<0&&(t=this.assets.length,this.assets=[...this.assets,this.activeAsset]),this.assetAttributes.push([t,e])}}this.assetAttributes=[...this.assetAttributes],this.saveSettings()}}))}_getSelectedAttributes(){return this.assetAttributes.map((([t,e])=>({id:this.assets[t].id,name:e.name})))}onCompleted(){return Lc(this,void 0,void 0,(function*(){yield this.updateComplete}))}_cleanup(){this._chart&&(this._chart.destroy(),this._chart=void 0,this.requestUpdate())}_deleteAttribute(t){const e=this.assetAttributes.splice(t,1)[0][0];this.assetAttributes=[...this.assetAttributes],this.assetAttributes.some((([t,n])=>t===e))||(this.assets.splice(t,1),this.assetAttributes.forEach((t=>{t[0]>=e&&(t[0]-=1)}))),this.saveSettings()}_getAttributeOptionsOld(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Te.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Se.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getAttributeOptions(){if(!this.activeAsset||!this.activeAsset.attributes)return;this.shadowRoot&&this.shadowRoot.getElementById("chart-attribute-picker")&&(this.shadowRoot.getElementById("chart-attribute-picker").value="");const t=Object.values(this.activeAsset.attributes);return t&&t.length>0?t.filter((t=>t.meta&&(t.meta.hasOwnProperty("storeDataPoints")?t.meta.storeDataPoints:t.meta.hasOwnProperty("agentLink")))).filter((t=>this.assetAttributes&&!this.assetAttributes.some((([e,n])=>n.name===t.name&&this.assets[e].id===this.activeAsset.id)))).map((t=>{const e=Te.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Se.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Oo()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Oo()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Oo()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Oo()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Oo()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Oo()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Oo()(t).subtract(1,"year").toDate(),t]]])}_getInterval(t){return t<=1?[5,"MINUTE"]:t<=3?[10,"MINUTE"]:t<=6?[30,"MINUTE"]:t<=24?[1,"HOUR"]:t<=48?[3,"HOUR"]:t<=96?[12,"HOUR"]:t<=744?[1,"DAY"]:[1,"MONTH"]}_loadData(){var t;return Lc(this,void 0,void 0,(function*(){if(this._data||!this.assetAttributes||!this.assets||0===this.assets.length&&!this.dataProvider||0===this.assetAttributes.length&&!this.dataProvider||!this.datapointQuery)return;if(this._loading){if(!this._dataAbortController)return;this._dataAbortController.abort("Data request overridden"),delete this._dataAbortController}this._loading=!0;const e=this.timePresetOptions.get(this.timePresetKey)(new Date);this._startOfPeriod=this.timeframe?this.timeframe[0].getTime():e[0].getTime(),this._endOfPeriod=this.timeframe?this.timeframe[1].getTime():e[1].getTime();const n=(this._endOfPeriod-this._startOfPeriod)/1e3/60/60,i=this._getInterval(n),r=i[0],o=i[1],a=o.toLowerCase();this._timeUnits=a,this._stepSize=r;const l=Oo()().toDate().getTime();let c=l<this._startOfPeriod?this._startOfPeriod:l;const s=[];let d;try{this.dataProvider?yield this.dataProvider(this._startOfPeriod,this._endOfPeriod,o.toString(),r).then((t=>{t.forEach((t=>{s.push(t)}))})):(this._dataAbortController=new AbortController,d=this.assetAttributes.map((([t,e],n)=>Lc(this,void 0,void 0,(function*(){var i;const r=this.assets[t],o=!!this.rightAxisAttributes.find((t=>t.id===r.id&&t.name===e.name)),a=Te.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),l=Se.Util.getAttributeLabel(e,a[0],r.type,!1),d=Se.Util.resolveUnits(Se.Util.getAttributeUnits(e,a[0],r.type)),p=n%this.colors.length,m={signal:null===(i=this._dataAbortController)||void 0===i?void 0:i.signal};let u=yield this._loadAttributeData(r,e,this.colors[p],this._startOfPeriod,this._endOfPeriod,!1,r.name+" "+l,m);u.assetId=r.id,u.attrName=e.name,u.unit=d,u.yAxisID=o?"y1":"y",s.push(u),u=yield this._loadAttributeData(this.assets[t],e,this.colors[p],c,this._endOfPeriod,!0,r.name+" "+l+" "+Ce.t("predicted"),m),s.push(u)}))))),d&&(yield Promise.all(d)),this._data=s,this._loading=!1}catch(e){if(console.error(e),"canceled"===(null==e?void 0:e.message))return;if(this._loading=!1,(0,nc.isAxiosError)(e)){if(e.message.includes("timeout"))return void(this._latestError="noAttributeDataTimeout");if(413===(null===(t=e.response)||void 0===t?void 0:t.status))return void(this._latestError="datapointRequestTooLarge")}this._latestError="errorOccurred"}}))}_loadAttributeData(t,e,n,i,r,o,a,l){var c,s,d;return Lc(this,void 0,void 0,(function*(){const i={borderColor:n,backgroundColor:n,label:a,pointRadius:2,fill:!1,data:[],borderDash:o?[2,4]:void 0};if(t.id&&e.name&&this.datapointQuery){let n;const r=JSON.parse(JSON.stringify(this.datapointQuery));if(r.fromTimestamp=this._startOfPeriod,r.toTimestamp=this._endOfPeriod,"lttb"==r.type)r.amountOfPoints?(null===(c=this._chartElem)||void 0===c?void 0:c.clientWidth)>0&&(r.amountOfPoints=Math.min(r.amountOfPoints,null===(s=this._chartElem)||void 0===s?void 0:s.clientWidth)):(null===(d=this._chartElem)||void 0===d?void 0:d.clientWidth)>0?r.amountOfPoints=Math.round(this._chartElem.clientWidth/5):(console.warn("Could not grab width of the Chart for estimating amount of data points. Using 100 points instead."),r.amountOfPoints=100);else if("interval"===r.type&&!r.interval){const t=(this.datapointQuery.toTimestamp-this.datapointQuery.fromTimestamp)/1e3/60/60,e=this._getInterval(t);r.interval=e[0].toString()+" "+e[1].toString()}n=o?yield Oe().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,l):yield Oe().rest.api.AssetDatapointResource.getDatapoints(t.id,e.name,r,l),200===n.status&&(i.data=n.data.filter((t=>null!==t.y&&void 0!==t.y)))}return i}))}};Mc.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",Rc([ht({type:Object})],Mc.prototype,"assets",void 0),Rc([ht({type:Object})],Mc.prototype,"activeAsset",void 0),Rc([ht({type:Object})],Mc.prototype,"assetAttributes",void 0),Rc([ht({type:Array})],Mc.prototype,"rightAxisAttributes",void 0),Rc([ht()],Mc.prototype,"dataProvider",void 0),Rc([ht({type:Array})],Mc.prototype,"colors",void 0),Rc([ht({type:Object})],Mc.prototype,"datapointQuery",void 0),Rc([ht({type:Object})],Mc.prototype,"config",void 0),Rc([ht({type:Object})],Mc.prototype,"chartOptions",void 0),Rc([ht({type:String})],Mc.prototype,"realm",void 0),Rc([ht()],Mc.prototype,"panelName",void 0),Rc([ht()],Mc.prototype,"attributeControls",void 0),Rc([ht()],Mc.prototype,"timeframe",void 0),Rc([ht()],Mc.prototype,"timestampControls",void 0),Rc([ht()],Mc.prototype,"timePresetOptions",void 0),Rc([ht()],Mc.prototype,"timePresetKey",void 0),Rc([ht()],Mc.prototype,"showLegend",void 0),Rc([ht()],Mc.prototype,"denseLegend",void 0),Rc([ht()],Mc.prototype,"_loading",void 0),Rc([ht()],Mc.prototype,"_data",void 0),Rc([ht()],Mc.prototype,"_tableTemplate",void 0),Rc([bt("#chart")],Mc.prototype,"_chartElem",void 0),Mc=Rc([mt("or-chart")],Mc)})(),m})()));
|