@openremote/or-attribute-barchart 1.12.1 → 1.12.3

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.js CHANGED
@@ -903,5 +903,5 @@
903
903
  <or-mwc-input ${bS(a)} type="${q.DATETIME}" required label="${eo.i18next.t("ending")}" .value="${e}"></or-mwc-input>
904
904
  </div>
905
905
  `).setActions([{actionName:"cancel",content:"cancel"},{actionName:"ok",content:"ok",action:()=>{var t,e,n,i;if((null==(t=r.value)?void 0:t.value)&&(null==(e=a.value)?void 0:e.value)&&r.value.value<a.value.value)this._isCustomWindow=!0,this.timeframe=[new Date(r.value.value),new Date(a.value.value)];else{let t;n=void 0,i=eo.i18next.t("errorOccurred"),n||(n=Mj.DialogHostElement||document.body),(t=new Mj).text=i,t.buttonText=void 0,t.buttonAction=void 0,t.isOpen=!0,t.addEventListener(MF.NAME,e=>{e.stopPropagation(),e.detail.opened||window.setTimeout(()=>{t.parentElement&&t.parentElement.removeChild(t)},0)}),n.append(t)}}}]),i||(i=M_.DialogHostElement||document.body),n.setOpen(!0),n.addEventListener(Mh.NAME,t=>{t.stopPropagation()}),n.addEventListener(Mp.NAME,t=>{t.stopPropagation(),window.setTimeout(()=>{n.parentElement&&n.parentElement.removeChild(n)},0)}),i.append(n)}_removeDatasetHighlights(t=this._chart){var e;if(t){let n=t.getOption();null==(e=n.series)||e.forEach(t=>{null!=t.itemStyle||(t.itemStyle={}),.2===t.itemStyle.opacity||.99===t.itemStyle.opacity?t.itemStyle.opacity=.31:t.itemStyle.opacity=1}),t.setOption(n)}}_addDatasetHighlight(t,e=this._chart){var n;if(e){let i=e.getOption();null==(n=i.series)||n.forEach(e=>{null!=e.itemStyle||(e.itemStyle={}),e.assetId!==t.id||e.attrName!==t.name?.31===e.itemStyle.opacity?e.itemStyle.opacity=.2:e.itemStyle.opacity=.3:.31===e.itemStyle.opacity&&(e.itemStyle.opacity=.99)}),e.setOption(i)}}_applyChartResponsiveness(){var t,e,n;if(this.shadowRoot){let e=this.shadowRoot.getElementById("container");if(e){let n=e.clientWidth<600;e.style.flexDirection=n?"column":"row";let i=this.shadowRoot.getElementById("controls");i&&(i.style.flexDirection=n?"row":"column");let r=this.shadowRoot.getElementById("period-controls");r&&(r.style.flexDirection=n?"row":"column");let a=this.shadowRoot.getElementById("attribute-list");a&&(a.style.gap=n?"4px 12px":"",a.style.maxHeight=n?"90px":"",a.style.flexFlow=n?"row wrap":"column nowrap",a.style.padding=n?"0":"5px 0"),this.shadowRoot.querySelectorAll(".attribute-list-item").forEach(t=>{t.style.minHeight=n?"0px":"44px",t.style.paddingLeft=n?"":"16px",t.children[1].style.flexDirection=n?"row":"column",t.children[1].style.gap=n?"4px":""}),null==(t=this._chart)||t.resize()}}let i=Math.max(1,(this._endOfPeriod-this._startOfPeriod)/this._intervalConfig.millis-1),r=(null==(e=this._chartElem)?void 0:e.clientWidth)?this._chartElem.clientWidth/50:Number.MAX_SAFE_INTEGER,a=Math.max(1,Math.min(i,Math.floor(1.5*r)));null==(n=this._chart)||n.setOption({xAxis:{show:a>1,splitNumber:a,minInterval:this._intervalConfig.millis,axisLabel:{rotate:45*(a>r)}}})}_cleanup(){this._chart&&(console.debug("Destroying bar chart..."),this._toggleChartEventListeners(!1),this._chart.dispose(),this._chart=void 0,this.requestUpdate())}_getTimeSelectionDates(t,e){var n;let i=Mt()(),r=Mt()(),a=null==(n=this.timeWindowOptions)?void 0:n.get(e);if(!a)throw Error(`Unsupported time window selected: ${e}`);let[o,s]=a;switch(t){case"this":1===s?(i=Mt()().startOf(o),r=Mt()().endOf(o)):(i=Mt()().subtract(.5*s,o),r=Mt()().add(.5*s,o));break;case"last":i=Mt()().subtract(s,o).startOf(o),r=1===s?Mt()().startOf(o):Mt()();break;default:console.error("Could not get time selection dates. The time prefix was not set correctly.")}return[i.toDate(),r.toDate()]}_shiftTimeframe(t,e,n,i){let r=this.timeWindowOptions.get(n);if(!r)throw Error(`Unsupported time window selected: ${n}`);let[a,o]=r,s=Mt()(t);"previous"===i?s.subtract(o,a):s.add(o,a);let l=Mt()(e);"previous"===i?l.subtract(o,a):l.add(o,a),this.timeframe=[s.toDate(),l.toDate()]}_getInterval(t,e,n,i=!1){let r=(e-t)/1e3/60/60,a=i?r:Math.round(r);if(n===Z.AUTO)if(a<=1)return{displayName:"5Minutes-auto",steps:5,orFormat:"MINUTE",momentFormat:"minutes",millis:3e5};else if(a<=6)return{displayName:"30Minutes-auto",steps:30,orFormat:"MINUTE",momentFormat:"minutes",millis:18e5};else if(a<=24)return{displayName:"hour-auto",steps:1,orFormat:"HOUR",momentFormat:"hours",millis:36e5};else if(a<=744)return{displayName:"day-auto",steps:1,orFormat:"DAY",momentFormat:"days",millis:864e5};else if(a<=8760)return{displayName:"week-auto",steps:1,orFormat:"WEEK",momentFormat:"weeks",millis:6048e5};else return{displayName:"month-auto",steps:1,orFormat:"MONTH",momentFormat:"months",millis:2592e6};if(n===Z.NONE){let t=this._endOfPeriod-this._startOfPeriod;return{displayName:"none",steps:Math.ceil(t/6e4),orFormat:"MINUTE",momentFormat:"minutes",millis:t}}let o=this.intervalOptions.get(n);if(Mt().duration(o.steps,o.momentFormat).asHours()<=a)return o;console.warn("Selected interval is larger than the timeframe! Changing to a valid timeframe...");let s=Array.from(this.intervalOptions.entries());for(let t=s.length-1;t>=0;t--){let[e,n]=s[t];if(Mt().duration(n.steps,n.momentFormat).asHours()<=a)return n}return s[0][1]}_loadData(){return M0(this,void 0,void 0,function*(){var t;let e;if(this._data||!this.assetAttributes||!this.assets||0===this.assets.length||0===this.assetAttributes.length||!this.datapointQuery)return;if(this._loading)if(!this._dataAbortController)return;else this._dataAbortController.abort("Data request overridden"),delete this._dataAbortController;this._loading=!0,this._latestError=void 0;let n=[];try{this._dataAbortController=new AbortController,(e=this.assetAttributes.map((t,e)=>M0(this,[t,e],void 0,function*([t,e],i){var r,a,o,s,l,d,c,u,m,h,p,f,_,g,y,v,b,x,w,M,k,T;let L=this.assets[t],S=!!(null==(a=null==(r=this.attributeConfig)?void 0:r.rightAxisAttributes)?void 0:a.find(t=>t.id===L.id&&t.name===e.name)),D=null==(o=this.attributeColors.find(t=>t[0].id===L.id&&t[0].name===e.name))?void 0:o[1],C=es.AssetModelUtil.getAttributeAndValueDescriptors(L.type,e.name,e),A=!!(null==(l=null==(s=this.attributeConfig)?void 0:s.faintAttributes)?void 0:l.find(t=>t.id===L.id&&t.name===e.name)),I=el.Util.getAttributeLabel(e,C[0],L.type,!1),E=el.Util.resolveUnits(el.Util.getAttributeUnits(e,C[0],L.type)),Y=i%this.colors.length,O={signal:null==(d=this._dataAbortController)?void 0:d.signal},P={AVG:{active:!!(null==(u=null==(c=this.attributeConfig)?void 0:c.methodAvgAttributes)?void 0:u.find(t=>t.id===L.id&&t.name===e.name)),formula:"AVG"},COUNT:{active:!!(null==(h=null==(m=this.attributeConfig)?void 0:m.methodCountAttributes)?void 0:h.find(t=>t.id===L.id&&t.name===e.name)),formula:"COUNT"},DIFFERENCE:{active:!!(null==(f=null==(p=this.attributeConfig)?void 0:p.methodDifferenceAttributes)?void 0:f.find(t=>t.id===L.id&&t.name===e.name)),formula:"DIFFERENCE"},MAX:{active:!!(null==(g=null==(_=this.attributeConfig)?void 0:_.methodMaxAttributes)?void 0:g.find(t=>t.id===L.id&&t.name===e.name)),formula:"MAX"},MEDIAN:{active:!!(null==(v=null==(y=this.attributeConfig)?void 0:y.methodMedianAttributes)?void 0:v.find(t=>t.id===L.id&&t.name===e.name)),formula:"MEDIAN"},MIN:{active:!!(null==(x=null==(b=this.attributeConfig)?void 0:b.methodMinAttributes)?void 0:x.find(t=>t.id===L.id&&t.name===e.name)),formula:"MIN"},MODE:{active:!!(null==(M=null==(w=this.attributeConfig)?void 0:w.methodModeAttributes)?void 0:M.find(t=>t.id===L.id&&t.name===e.name)),formula:"MODE"},SUM:{active:!!(null==(T=null==(k=this.attributeConfig)?void 0:k.methodSumAttributes)?void 0:T.find(t=>t.id===L.id&&t.name===e.name)),formula:"SUM"}};for(let[t,r]of Object.entries(P).sort(([t],[e])=>t.localeCompare(e)))if(r.active){let a=yield this._loadAttributeData(L,e,null!=D?D:this.colors[Y],this._startOfPeriod,this._endOfPeriod,r.formula,A,`${L.name} | ${I}
906
- ${eo.i18next.t(r.formula)}`,O,E);a.index=1e3*Object.keys(P).indexOf(t)+(i+1),a.assetId=L.id,a.attrName=e.name,a.unit=E,a.yAxisIndex=+!!S,a.color=null!=D?D:this.colors[Y],n.push(a)}})))&&(yield Promise.all(e));let t=n.sort((t,e)=>e.index-t.index).reverse();if(this.stacked){let e=new Set(t.map(t=>t.stack));e.size>1&&e.forEach(e=>{let n=[...t].reverse().find(t=>t.stack===e);n&&(n.label.show=!0)})}this._data=t,this._loading=!1}catch(e){if(console.error(e),(null==e?void 0:e.message)==="canceled")return;if(this._loading=!1,(0,Me.isAxiosError)(e)){if(e.message.includes("timeout")){this._latestError="noAttributeDataTimeout";return}else if((null==(t=e.response)?void 0:t.status)===413){this._latestError="datapointRequestTooLarge";return}}this._latestError="errorOccurred"}})}_loadAttributeData(t,e,n,i,r,a){return M0(this,arguments,void 0,function*(t,e,n,i,r,a,o=!1,s,l,d){var c,u,m,h;let p=this._getDefaultDatasetOptions(null!=s?s:"",a,n,o);if(t.id&&e.name&&this.datapointQuery){let n=structuredClone(this.datapointQuery);n.fromTimestamp=i,n.toTimestamp=r-1,n.formula=a,n.gapFill=!0,n.interval=`${null!=(u=null==(c=this._intervalConfig)?void 0:c.steps)?u:"???"} ${null!=(h=null==(m=this._intervalConfig)?void 0:m.orFormat)?h:"???"}`,console.debug(`Requesting datapoints for '${e.name}' of ${t.id}, between ${Mt()(i).format("lll")} and ${Mt()(r-1).format("lll")}...`);let o=yield ed().rest.api.AssetDatapointResource.getDatapoints(t.id,e.name,n,l);200===o.status&&(p.data=o.data.map(t=>({x:t.x,y:t.y})).map(t=>{var e,n;return[(null!=(e=t.x)?e:0)+.5*this._intervalConfig.millis,null==(n=t.y)?void 0:n.toFixed(this.decimals)]}))}return p})}_updateChartData(){var t,e,n,i,r,a,o;if(!this._chart)return void console.error("Could not update bar chart data; the bar chart is not initialized yet.");let s=null==(e=null==(t=this._data)?void 0:t[0])?void 0:e.data;if(s){let t=s[0][0];t!==this._startOfPeriod&&(this._startOfPeriod=t);let e=[...s].reverse()[0][0];e!==this._endOfPeriod&&(this._endOfPeriod=e)}let l=Math.max(1,(this._endOfPeriod-this._startOfPeriod)/this._intervalConfig.millis-1),d=(null==(n=this._chartElem)?void 0:n.clientWidth)?this._chartElem.clientWidth/50:Number.MAX_SAFE_INTEGER,c=Math.max(1,Math.min(l,Math.floor(1.5*d)));this._chart.setOption({xAxis:{show:c>1,splitNumber:c,minInterval:this._intervalConfig.millis,min:this._startOfPeriod,max:this._endOfPeriod,axisLabel:{interval:null==(i=this._intervalConfig)?void 0:i.millis,rotate:45*(c>d)}},dataZoom:{minValueSpan:(null!=(a=null==(r=this._intervalConfig)?void 0:r.millis)?a:0)*4},series:[...(null!=(o=this._data)?o:[]).map(t=>Object.assign({},t))]})}_toggleChartEventListeners(t){var e;t?(this._containerResizeObserver=new ResizeObserver(()=>this._applyChartResponsiveness()),this._containerResizeObserver.observe(this.shadowRoot.getElementById("container"))):(null==(e=this._containerResizeObserver)||e.disconnect(),this._containerResizeObserver=void 0)}_getDefaultChartOptions(){var t,e,n,i,r,a,o,s,l,d,c,u,m,h,p,f,_,g,y,v,b,x,w;let M=Math.max(1,(this._endOfPeriod-this._startOfPeriod)/this._intervalConfig.millis-1),k=(null==(t=this._chartElem)?void 0:t.clientWidth)?this._chartElem.clientWidth/50:Number.MAX_SAFE_INTEGER,T=Math.max(1,Math.min(M,Math.floor(1.5*k)));return{grid:{show:!0,backgroundColor:this._style.getPropertyValue("--internal-or-asset-tree-background-color"),borderColor:this._style.getPropertyValue("--internal-or-chart-text-color"),left:10,right:10,top:10,bottom:10,containLabel:!0},backgroundColor:this._style.getPropertyValue("--internal-or-asset-tree-background-color"),tooltip:{trigger:"axis",confine:!0,axisPointer:{type:"cross",label:{show:!0,formatter:t=>{var e,n,i,r,a;if("x"!==t.axisDimension)return Number(t.value).toFixed(this.decimals).toString();{let o=Mt()(t.value),s=o.clone().subtract((null!=(n=null==(e=this._intervalConfig)?void 0:e.millis)?n:0)/2,"milliseconds"),l=o.clone().add((null!=(r=null==(i=this._intervalConfig)?void 0:i.millis)?r:0)/2,"milliseconds");switch(null==(a=this._intervalConfig)?void 0:a.orFormat){case"MINUTE":case"HOUR":return`${s.format("lll")} - ${l.format("lll")}`;case"DAY":return`${o.format("dddd, LL")}`;case"WEEK":return`${eo.i18next.t("week")} ${s.format("w, LL")} - ${l.format("LL")}`;default:return`${s.format("LL")} - ${l.format("LL")}`}}}}}},xAxis:{type:"time",show:M>1,axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},splitNumber:T,minInterval:this._intervalConfig.millis,min:this._startOfPeriod,max:this._endOfPeriod,boundaryGap:!1,splitArea:{show:!0,areaStyle:{color:["transparent","rgba(0, 0, 0, 0.05)"]}},axisLabel:{rotate:45*(T>k),interval:null==(e=this._intervalConfig)?void 0:e.millis,fontSize:10,formatter:{year:"1-{MMM}-{yyyy}",month:"1-{MMM}-'{yy}",day:"{d}-{MMM}",hour:"{HH}:{mm}",minute:"{HH}:{mm}",second:"{HH}:{mm}:{ss}",millisecond:"{d}-{MMM} {HH}:{mm}",none:"{MMM}-{dd} {HH}:{mm}"}}},yAxis:[{type:"value",axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},boundaryGap:["10%","10%"],scale:!0,min:null==(a=null==(r=null==(i=null==(n=this.chartOptions)?void 0:n.options)?void 0:i.scales)?void 0:r.y)?void 0:a.min,max:null==(d=null==(l=null==(s=null==(o=this.chartOptions)?void 0:o.options)?void 0:s.scales)?void 0:l.y)?void 0:d.max},{type:"value",show:(null!=(m=null==(u=null==(c=this.attributeConfig)?void 0:c.rightAxisAttributes)?void 0:u.length)?m:0)>0,axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},boundaryGap:["10%","10%"],scale:!0,min:null==(_=null==(f=null==(p=null==(h=this.chartOptions)?void 0:h.options)?void 0:p.scales)?void 0:f.y1)?void 0:_.min,max:null==(b=null==(v=null==(y=null==(g=this.chartOptions)?void 0:g.options)?void 0:y.scales)?void 0:v.y1)?void 0:b.max}],dataZoom:[{type:"inside",minValueSpan:(null!=(w=null==(x=this._intervalConfig)?void 0:x.millis)?w:0)*4}],series:[]}}_getDefaultDatasetOptions(t,e,n,i=!1){let r=Object.entries(this.attributeConfig||{}).filter(([t,e])=>t.startsWith("method")&&(null==e?void 0:e.length)>0).length>1;return{name:t,type:"bar",data:[],stack:this.stacked?`${e}`:void 0,itemStyle:{color:n,opacity:i?.31:1},emphasis:{},label:{show:!this.stacked,align:"left",verticalAlign:"middle",position:"top",fontStyle:"italic",fontSize:10,rotate:90,distance:10,formatter:t=>{var n,i,a;if(r){let r=null==(a=null==(n=this._data)?void 0:n[null!=(i=t.seriesIndex)?i:0])?void 0:a.data;if((null==r?void 0:r.findIndex(t=>null!=t[1]))===t.dataIndex)return e}return""}}}}static getDefaultTimePrefixOptions(){return["this","last"]}static getDefaultTimeWindowOptions(){return new Map([["Hour",["hours",1]],["6Hours",["hours",6]],["24Hours",["hours",24]],["Day",["days",1]],["7Days",["days",7]],["Week",["weeks",1]],["30Days",["days",30]],["Month",["months",1]],["365Days",["days",365]],["Year",["years",1]]])}static getDefaultIntervalOptions(){return new Map([[Z.AUTO,{displayName:"auto",steps:1,orFormat:"MINUTE",momentFormat:"minutes",millis:6e4}],[Z.ONE_MINUTE,{displayName:"1Minute",steps:1,orFormat:"MINUTE",momentFormat:"minutes",millis:6e4}],[Z.FIVE_MINUTES,{displayName:"5Minutes",steps:5,orFormat:"MINUTE",momentFormat:"minutes",millis:3e5}],[Z.FIFTEEN_MINUTES,{displayName:"15Minutes",steps:15,orFormat:"MINUTE",momentFormat:"minutes",millis:9e5}],[Z.THIRTY_MINUTES,{displayName:"30Minutes",steps:30,orFormat:"MINUTE",momentFormat:"minutes",millis:18e5}],[Z.ONE_HOUR,{displayName:"hour",steps:1,orFormat:"HOUR",momentFormat:"hours",millis:36e5}],[Z.ONE_DAY,{displayName:"day",steps:1,orFormat:"DAY",momentFormat:"days",millis:864e5}],[Z.ONE_WEEK,{displayName:"week",steps:1,orFormat:"WEEK",momentFormat:"weeks",millis:6048e5}],[Z.ONE_MONTH,{displayName:"month",steps:1,orFormat:"MONTH",momentFormat:"months",millis:2592e6}],[Z.ONE_YEAR,{displayName:"year",steps:1,orFormat:"YEAR",momentFormat:"years",millis:31536e6}]])}};M2.DEFAULT_COLORS=["#3869B1","#DA7E30","#3F9852","#CC2428","#6B4C9A","#922427","#958C3D","#535055"],MQ([en({type:Object})],M2.prototype,"assets",void 0),MQ([en({type:Object})],M2.prototype,"assetAttributes",void 0),MQ([en({type:String})],M2.prototype,"realm",void 0),MQ([en({type:Array})],M2.prototype,"attributeColors",void 0),MQ([en({type:Object})],M2.prototype,"attributeConfig",void 0),MQ([en({type:Array})],M2.prototype,"colors",void 0),MQ([en({type:Object})],M2.prototype,"datapointQuery",void 0),MQ([en({type:Array})],M2.prototype,"timeframe",void 0),MQ([en({type:Object})],M2.prototype,"chartOptions",void 0),MQ([en({type:Boolean})],M2.prototype,"showLegend",void 0),MQ([en({type:Boolean})],M2.prototype,"denseLegend",void 0),MQ([en({type:Boolean})],M2.prototype,"stacked",void 0),MQ([en({type:Boolean})],M2.prototype,"timestampControls",void 0),MQ([en({type:Number})],M2.prototype,"decimals",void 0),MQ([en({type:Array})],M2.prototype,"timePrefixOptions",void 0),MQ([en({type:String})],M2.prototype,"timePrefixKey",void 0),MQ([en({type:Object})],M2.prototype,"timeWindowOptions",void 0),MQ([en({type:String})],M2.prototype,"timeWindowKey",void 0),MQ([en({type:Object})],M2.prototype,"intervalOptions",void 0),MQ([en({type:String})],M2.prototype,"interval",void 0),MQ([ei()],M2.prototype,"_isCustomWindow",void 0),MQ([ei()],M2.prototype,"_loading",void 0),MQ([ei()],M2.prototype,"_data",void 0),MQ([ea("#chart")],M2.prototype,"_chartElem",void 0),M2=J=MQ([et("or-attribute-barchart")],M2)})(),l})());
906
+ ${eo.i18next.t(r.formula)}`,O,E);a.index=1e3*Object.keys(P).indexOf(t)+(i+1),a.assetId=L.id,a.attrName=e.name,a.unit=E,a.yAxisIndex=+!!S,a.color=null!=D?D:this.colors[Y],n.push(a)}})))&&(yield Promise.all(e));let t=n.sort((t,e)=>e.index-t.index).reverse();if(this.stacked){let e=new Set(t.map(t=>t.stack));e.size>1&&e.forEach(e=>{let n=[...t].reverse().find(t=>t.stack===e);n&&(n.label.show=!0)})}this._data=t,this._loading=!1}catch(e){if(console.error(e),(null==e?void 0:e.message)==="canceled")return;if(this._loading=!1,(0,Me.isAxiosError)(e)){if(e.message.includes("timeout")){this._latestError="noAttributeDataTimeout";return}else if((null==(t=e.response)?void 0:t.status)===413){this._latestError="datapointRequestTooLarge";return}}this._latestError="errorOccurred"}})}_loadAttributeData(t,e,n,i,r,a){return M0(this,arguments,void 0,function*(t,e,n,i,r,a,o=!1,s,l,d){var c,u,m,h;let p=this._getDefaultDatasetOptions(null!=s?s:"",a,n,o);if(t.id&&e.name&&this.datapointQuery){let n=structuredClone(this.datapointQuery);n.fromTimestamp=i,n.toTimestamp=r-1,n.formula=a,n.gapFill=!0,n.interval=`${null!=(u=null==(c=this._intervalConfig)?void 0:c.steps)?u:"???"} ${null!=(h=null==(m=this._intervalConfig)?void 0:m.orFormat)?h:"???"}`,console.debug(`Requesting datapoints for '${e.name}' of ${t.id}, between ${Mt()(i).format("lll")} and ${Mt()(r-1).format("lll")}...`);let o=yield ed().rest.api.AssetDatapointResource.getDatapoints(t.id,e.name,n,l);200===o.status&&(p.data=o.data.map(t=>({x:t.x,y:t.y})).map(t=>{var e,n;return[(null!=(e=t.x)?e:0)+.5*this._intervalConfig.millis,null==(n=t.y)?void 0:n.toFixed(this.decimals)]}))}return p})}_updateChartData(){var t,e,n,i,r,a,o;if(!this._chart)return void console.error("Could not update bar chart data; the bar chart is not initialized yet.");let s=null==(e=null==(t=this._data)?void 0:t[0])?void 0:e.data;if(s){let t=s[0][0];t!==this._startOfPeriod&&(this._startOfPeriod=t);let e=[...s].reverse()[0][0];e!==this._endOfPeriod&&(this._endOfPeriod=e)}let l=Math.max(1,(this._endOfPeriod-this._startOfPeriod)/this._intervalConfig.millis-1),d=(null==(n=this._chartElem)?void 0:n.clientWidth)?this._chartElem.clientWidth/50:Number.MAX_SAFE_INTEGER,c=Math.max(1,Math.min(l,Math.floor(1.5*d)));this._chart.setOption({xAxis:{show:c>1,splitNumber:c,minInterval:this._intervalConfig.millis,min:this._startOfPeriod,max:this._endOfPeriod,axisLabel:{interval:null==(i=this._intervalConfig)?void 0:i.millis,rotate:45*(c>d)}},dataZoom:{minValueSpan:(null!=(a=null==(r=this._intervalConfig)?void 0:r.millis)?a:0)*4},series:[...(null!=(o=this._data)?o:[]).map(t=>Object.assign({},t))]})}_toggleChartEventListeners(t){var e;t?(this._containerResizeObserver=new ResizeObserver(()=>this._applyChartResponsiveness()),this._containerResizeObserver.observe(this.shadowRoot.getElementById("container"))):(null==(e=this._containerResizeObserver)||e.disconnect(),this._containerResizeObserver=void 0)}_getDefaultChartOptions(){var t,e,n,i,r,a,o,s,l,d,c,u,m,h,p,f,_,g,y,v,b,x,w;let M=Math.max(1,(this._endOfPeriod-this._startOfPeriod)/this._intervalConfig.millis-1),k=(null==(t=this._chartElem)?void 0:t.clientWidth)?this._chartElem.clientWidth/50:Number.MAX_SAFE_INTEGER,T=Math.max(1,Math.min(M,Math.floor(1.5*k)));return{grid:{show:!0,backgroundColor:this._style.getPropertyValue("--internal-or-asset-tree-background-color"),borderColor:this._style.getPropertyValue("--internal-or-chart-text-color"),left:10,right:10,top:10,bottom:10,containLabel:!0},backgroundColor:this._style.getPropertyValue("--internal-or-asset-tree-background-color"),tooltip:{trigger:"axis",confine:!0,axisPointer:{type:"cross",label:{show:!0,formatter:t=>{var e,n,i,r,a;if("x"!==t.axisDimension)return Number(t.value).toFixed(this.decimals).toString();{let o=Mt()(t.value),s=o.clone().subtract((null!=(n=null==(e=this._intervalConfig)?void 0:e.millis)?n:0)/2,"milliseconds"),l=o.clone().add((null!=(r=null==(i=this._intervalConfig)?void 0:i.millis)?r:0)/2,"milliseconds");switch(null==(a=this._intervalConfig)?void 0:a.orFormat){case"MINUTE":case"HOUR":return`${s.format("lll")} - ${l.format("lll")}`;case"DAY":return`${o.format("dddd, LL")}`;case"WEEK":return`${eo.i18next.t("week")} ${s.format("w, LL")} - ${l.format("LL")}`;default:return`${s.format("LL")} - ${l.format("LL")}`}}}}}},xAxis:{type:"time",show:M>1,axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},splitNumber:T,minInterval:this._intervalConfig.millis,min:this._startOfPeriod,max:this._endOfPeriod,boundaryGap:!1,splitArea:{show:!0,areaStyle:{color:["transparent","rgba(0, 0, 0, 0.05)"]}},axisLabel:{rotate:45*(T>k),interval:null==(e=this._intervalConfig)?void 0:e.millis,fontSize:10,formatter:{year:"1-{MMM}-{yyyy}",month:"1-{MMM}-'{yy}",day:"{d}-{MMM}",hour:"{HH}:{mm}",minute:"{HH}:{mm}",second:"{HH}:{mm}:{ss}",millisecond:"{d}-{MMM} {HH}:{mm}",none:"{MMM}-{dd} {HH}:{mm}"}}},yAxis:[{type:"value",axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},boundaryGap:["10%","10%"],scale:!0,min:null==(a=null==(r=null==(i=null==(n=this.chartOptions)?void 0:n.options)?void 0:i.scales)?void 0:r.y)?void 0:a.min,max:null==(d=null==(l=null==(s=null==(o=this.chartOptions)?void 0:o.options)?void 0:s.scales)?void 0:l.y)?void 0:d.max},{type:"value",show:(null!=(m=null==(u=null==(c=this.attributeConfig)?void 0:c.rightAxisAttributes)?void 0:u.length)?m:0)>0,axisLine:{lineStyle:{color:this._style.getPropertyValue("--internal-or-chart-text-color")}},boundaryGap:["10%","10%"],scale:!0,min:null==(_=null==(f=null==(p=null==(h=this.chartOptions)?void 0:h.options)?void 0:p.scales)?void 0:f.y1)?void 0:_.min,max:null==(b=null==(v=null==(y=null==(g=this.chartOptions)?void 0:g.options)?void 0:y.scales)?void 0:v.y1)?void 0:b.max}],dataZoom:[{type:"inside",minValueSpan:(null!=(w=null==(x=this._intervalConfig)?void 0:x.millis)?w:0)*4}],series:[]}}_getDefaultDatasetOptions(t,e,n,i=!1){let r=Object.entries(this.attributeConfig||{}).filter(([t,e])=>t.startsWith("method")&&(null==e?void 0:e.length)>0).length>1;return{name:t,type:"bar",data:[],stack:this.stacked?`${e}`:void 0,itemStyle:{color:n,opacity:i?.31:1},emphasis:{},label:{show:!this.stacked,align:"left",verticalAlign:"middle",position:"top",fontStyle:"italic",fontSize:10,rotate:90,distance:10,formatter:t=>{var n,i,a;if(r){let r=null==(a=null==(n=this._data)?void 0:n[null!=(i=t.seriesIndex)?i:0])?void 0:a.data;if((null==r?void 0:r.findIndex(t=>null!=t[1]))===t.dataIndex)return e}return""}}}}static getDefaultTimePrefixOptions(){return["this","last"]}static getDefaultTimeWindowOptions(){return new Map([["60Minutes",["minutes",60]],["Hour",["hours",1]],["6Hours",["hours",6]],["24Hours",["hours",24]],["Day",["days",1]],["7Days",["days",7]],["Week",["weeks",1]],["30Days",["days",30]],["Month",["months",1]],["90Days",["days",90]],["6Months",["months",6]],["365Days",["days",365]],["Year",["years",1]]])}static getDefaultIntervalOptions(){return new Map([[Z.AUTO,{displayName:"auto",steps:1,orFormat:"MINUTE",momentFormat:"minutes",millis:6e4}],[Z.ONE_MINUTE,{displayName:"1Minute",steps:1,orFormat:"MINUTE",momentFormat:"minutes",millis:6e4}],[Z.FIVE_MINUTES,{displayName:"5Minutes",steps:5,orFormat:"MINUTE",momentFormat:"minutes",millis:3e5}],[Z.FIFTEEN_MINUTES,{displayName:"15Minutes",steps:15,orFormat:"MINUTE",momentFormat:"minutes",millis:9e5}],[Z.THIRTY_MINUTES,{displayName:"30Minutes",steps:30,orFormat:"MINUTE",momentFormat:"minutes",millis:18e5}],[Z.ONE_HOUR,{displayName:"hour",steps:1,orFormat:"HOUR",momentFormat:"hours",millis:36e5}],[Z.ONE_DAY,{displayName:"day",steps:1,orFormat:"DAY",momentFormat:"days",millis:864e5}],[Z.ONE_WEEK,{displayName:"week",steps:1,orFormat:"WEEK",momentFormat:"weeks",millis:6048e5}],[Z.ONE_MONTH,{displayName:"month",steps:1,orFormat:"MONTH",momentFormat:"months",millis:2592e6}],[Z.ONE_YEAR,{displayName:"year",steps:1,orFormat:"YEAR",momentFormat:"years",millis:31536e6}]])}};M2.DEFAULT_COLORS=["#3869B1","#DA7E30","#3F9852","#CC2428","#6B4C9A","#922427","#958C3D","#535055"],MQ([en({type:Object})],M2.prototype,"assets",void 0),MQ([en({type:Object})],M2.prototype,"assetAttributes",void 0),MQ([en({type:String})],M2.prototype,"realm",void 0),MQ([en({type:Array})],M2.prototype,"attributeColors",void 0),MQ([en({type:Object})],M2.prototype,"attributeConfig",void 0),MQ([en({type:Array})],M2.prototype,"colors",void 0),MQ([en({type:Object})],M2.prototype,"datapointQuery",void 0),MQ([en({type:Array})],M2.prototype,"timeframe",void 0),MQ([en({type:Object})],M2.prototype,"chartOptions",void 0),MQ([en({type:Boolean})],M2.prototype,"showLegend",void 0),MQ([en({type:Boolean})],M2.prototype,"denseLegend",void 0),MQ([en({type:Boolean})],M2.prototype,"stacked",void 0),MQ([en({type:Boolean})],M2.prototype,"timestampControls",void 0),MQ([en({type:Number})],M2.prototype,"decimals",void 0),MQ([en({type:Array})],M2.prototype,"timePrefixOptions",void 0),MQ([en({type:String})],M2.prototype,"timePrefixKey",void 0),MQ([en({type:Object})],M2.prototype,"timeWindowOptions",void 0),MQ([en({type:String})],M2.prototype,"timeWindowKey",void 0),MQ([en({type:Object})],M2.prototype,"intervalOptions",void 0),MQ([en({type:String})],M2.prototype,"interval",void 0),MQ([ei()],M2.prototype,"_isCustomWindow",void 0),MQ([ei()],M2.prototype,"_loading",void 0),MQ([ei()],M2.prototype,"_data",void 0),MQ([ea("#chart")],M2.prototype,"_chartElem",void 0),M2=J=MQ([et("or-attribute-barchart")],M2)})(),l})());
907
907
  //# sourceMappingURL=index.js.map