@openremote/or-chart 1.4.0-snapshot.20250326163317 → 1.4.0-snapshot.20250331133457

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.
@@ -1038,4 +1038,4 @@
1038
1038
  <or-mwc-input ${pn(n)} type="${Ca.DATETIME}" required label="${We.t("start")}" .value="${t}"></or-mwc-input>
1039
1039
  <or-mwc-input ${pn(i)} type="${Ca.DATETIME}" required label="${We.t("ending")}" .value="${e}"></or-mwc-input>
1040
1040
  </div>
1041
- `)).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 Tp(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ue().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 Tp(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=Be.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ve.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=Be.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ve.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Em()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Em()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Em()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Em()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Em()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Em()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Em()(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 Tp(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=Em()().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)=>Tp(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=Be.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),s=Ve.Util.getAttributeLabel(e,o[0],r.type,!1),c=Ve.Util.resolveUnits(Ve.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+" "+We.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,Kh.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 Tp(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 Ue().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,s):yield Ue().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}))}};Ap.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",Lp([At({type:Object})],Ap.prototype,"assets",void 0),Lp([At({type:Object})],Ap.prototype,"activeAsset",void 0),Lp([At({type:Object})],Ap.prototype,"assetAttributes",void 0),Lp([At({type:Array})],Ap.prototype,"rightAxisAttributes",void 0),Lp([At()],Ap.prototype,"dataProvider",void 0),Lp([At({type:Array})],Ap.prototype,"colors",void 0),Lp([At({type:Object})],Ap.prototype,"datapointQuery",void 0),Lp([At({type:Object})],Ap.prototype,"config",void 0),Lp([At({type:Object})],Ap.prototype,"chartOptions",void 0),Lp([At({type:String})],Ap.prototype,"realm",void 0),Lp([At()],Ap.prototype,"panelName",void 0),Lp([At()],Ap.prototype,"attributeControls",void 0),Lp([At()],Ap.prototype,"timeframe",void 0),Lp([At()],Ap.prototype,"timestampControls",void 0),Lp([At()],Ap.prototype,"timePresetOptions",void 0),Lp([At()],Ap.prototype,"timePresetKey",void 0),Lp([At()],Ap.prototype,"showLegend",void 0),Lp([At()],Ap.prototype,"denseLegend",void 0),Lp([At()],Ap.prototype,"_loading",void 0),Lp([At()],Ap.prototype,"_data",void 0),Lp([At()],Ap.prototype,"_tableTemplate",void 0),Lp([Ot("#chart")],Ap.prototype,"_chartElem",void 0),Ap=Lp([St("or-chart")],Ap)})(),c})()));
1041
+ `)).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 Tp(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ue().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 Tp(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=Be.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ve.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=Be.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Ve.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Em()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Em()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Em()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Em()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Em()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Em()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Em()(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 Tp(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=Em()().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)=>Tp(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=Be.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),s=Ve.Util.getAttributeLabel(e,o[0],r.type,!1),c=Ve.Util.resolveUnits(Ve.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+" "+We.t("predicted"),m),h.unit=c,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,Kh.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 Tp(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 Ue().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,s):yield Ue().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}))}};Ap.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",Lp([At({type:Object})],Ap.prototype,"assets",void 0),Lp([At({type:Object})],Ap.prototype,"activeAsset",void 0),Lp([At({type:Object})],Ap.prototype,"assetAttributes",void 0),Lp([At({type:Array})],Ap.prototype,"rightAxisAttributes",void 0),Lp([At()],Ap.prototype,"dataProvider",void 0),Lp([At({type:Array})],Ap.prototype,"colors",void 0),Lp([At({type:Object})],Ap.prototype,"datapointQuery",void 0),Lp([At({type:Object})],Ap.prototype,"config",void 0),Lp([At({type:Object})],Ap.prototype,"chartOptions",void 0),Lp([At({type:String})],Ap.prototype,"realm",void 0),Lp([At()],Ap.prototype,"panelName",void 0),Lp([At()],Ap.prototype,"attributeControls",void 0),Lp([At()],Ap.prototype,"timeframe",void 0),Lp([At()],Ap.prototype,"timestampControls",void 0),Lp([At()],Ap.prototype,"timePresetOptions",void 0),Lp([At()],Ap.prototype,"timePresetKey",void 0),Lp([At()],Ap.prototype,"showLegend",void 0),Lp([At()],Ap.prototype,"denseLegend",void 0),Lp([At()],Ap.prototype,"_loading",void 0),Lp([At()],Ap.prototype,"_data",void 0),Lp([At()],Ap.prototype,"_tableTemplate",void 0),Lp([Ot("#chart")],Ap.prototype,"_chartElem",void 0),Ap=Lp([St("or-chart")],Ap)})(),c})()));
package/dist/umd/index.js CHANGED
@@ -1038,4 +1038,4 @@
1038
1038
  <or-mwc-input ${fn(n)} type="${No.DATETIME}" required label="${Be.t("start")}" .value="${t}"></or-mwc-input>
1039
1039
  <or-mwc-input ${fn(i)} type="${No.DATETIME}" required label="${Be.t("ending")}" .value="${e}"></or-mwc-input>
1040
1040
  </div>
1041
- `)).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 qc(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ye().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 qc(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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Xe.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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Xe.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Yo()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Yo()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Yo()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Yo()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Yo()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Yo()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Yo()(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 qc(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=Yo()().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)=>qc(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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),l=Xe.Util.getAttributeLabel(e,a[0],r.type,!1),d=Xe.Util.resolveUnits(Xe.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+" "+Be.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,vc.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 qc(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 Ye().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,l):yield Ye().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}))}};Qc.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",Wc([Rt({type:Object})],Qc.prototype,"assets",void 0),Wc([Rt({type:Object})],Qc.prototype,"activeAsset",void 0),Wc([Rt({type:Object})],Qc.prototype,"assetAttributes",void 0),Wc([Rt({type:Array})],Qc.prototype,"rightAxisAttributes",void 0),Wc([Rt()],Qc.prototype,"dataProvider",void 0),Wc([Rt({type:Array})],Qc.prototype,"colors",void 0),Wc([Rt({type:Object})],Qc.prototype,"datapointQuery",void 0),Wc([Rt({type:Object})],Qc.prototype,"config",void 0),Wc([Rt({type:Object})],Qc.prototype,"chartOptions",void 0),Wc([Rt({type:String})],Qc.prototype,"realm",void 0),Wc([Rt()],Qc.prototype,"panelName",void 0),Wc([Rt()],Qc.prototype,"attributeControls",void 0),Wc([Rt()],Qc.prototype,"timeframe",void 0),Wc([Rt()],Qc.prototype,"timestampControls",void 0),Wc([Rt()],Qc.prototype,"timePresetOptions",void 0),Wc([Rt()],Qc.prototype,"timePresetKey",void 0),Wc([Rt()],Qc.prototype,"showLegend",void 0),Wc([Rt()],Qc.prototype,"denseLegend",void 0),Wc([Rt()],Qc.prototype,"_loading",void 0),Wc([Rt()],Qc.prototype,"_data",void 0),Wc([Rt()],Qc.prototype,"_tableTemplate",void 0),Wc([Nt("#chart")],Qc.prototype,"_chartElem",void 0),Qc=Wc([It("or-chart")],Qc)})(),m})()));
1041
+ `)).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 qc(this,void 0,void 0,(function*(){if(t){this.assetAttributes=[];for(const e of t){const t=yield Ye().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 qc(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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Xe.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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset.type,t.name,t),n=Xe.Util.getAttributeLabel(t,e[0],this.activeAsset.type,!1);return[t.name,n]})):void 0}_getDefaultTimestampOptions(){return new Map([["lastHour",t=>[Yo()(t).subtract(1,"hour").toDate(),t]],["last24Hours",t=>[Yo()(t).subtract(24,"hours").toDate(),t]],["last7Days",t=>[Yo()(t).subtract(7,"days").toDate(),t]],["last30Days",t=>[Yo()(t).subtract(30,"days").toDate(),t]],["last90Days",t=>[Yo()(t).subtract(90,"days").toDate(),t]],["last6Months",t=>[Yo()(t).subtract(6,"months").toDate(),t]],["lastYear",t=>[Yo()(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 qc(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=Yo()().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)=>qc(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=Ve.AssetModelUtil.getAttributeAndValueDescriptors(r.type,e.name,e),l=Xe.Util.getAttributeLabel(e,a[0],r.type,!1),d=Xe.Util.resolveUnits(Xe.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+" "+Be.t("predicted"),m),u.unit=d,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,vc.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 qc(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 Ye().rest.api.AssetPredictedDatapointResource.getPredictedDatapoints(t.id,e.name,r,l):yield Ye().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}))}};Qc.DEFAULT_TIMESTAMP_FORMAT="L HH:mm:ss",Wc([Rt({type:Object})],Qc.prototype,"assets",void 0),Wc([Rt({type:Object})],Qc.prototype,"activeAsset",void 0),Wc([Rt({type:Object})],Qc.prototype,"assetAttributes",void 0),Wc([Rt({type:Array})],Qc.prototype,"rightAxisAttributes",void 0),Wc([Rt()],Qc.prototype,"dataProvider",void 0),Wc([Rt({type:Array})],Qc.prototype,"colors",void 0),Wc([Rt({type:Object})],Qc.prototype,"datapointQuery",void 0),Wc([Rt({type:Object})],Qc.prototype,"config",void 0),Wc([Rt({type:Object})],Qc.prototype,"chartOptions",void 0),Wc([Rt({type:String})],Qc.prototype,"realm",void 0),Wc([Rt()],Qc.prototype,"panelName",void 0),Wc([Rt()],Qc.prototype,"attributeControls",void 0),Wc([Rt()],Qc.prototype,"timeframe",void 0),Wc([Rt()],Qc.prototype,"timestampControls",void 0),Wc([Rt()],Qc.prototype,"timePresetOptions",void 0),Wc([Rt()],Qc.prototype,"timePresetKey",void 0),Wc([Rt()],Qc.prototype,"showLegend",void 0),Wc([Rt()],Qc.prototype,"denseLegend",void 0),Wc([Rt()],Qc.prototype,"_loading",void 0),Wc([Rt()],Qc.prototype,"_data",void 0),Wc([Rt()],Qc.prototype,"_tableTemplate",void 0),Wc([Nt("#chart")],Qc.prototype,"_chartElem",void 0),Qc=Wc([It("or-chart")],Qc)})(),m})()));