iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 15.6 kB
JavaScript
export const __rspack_esm_id=48347;export const __rspack_esm_ids=[48347];export const __webpack_modules__={90433(t,e,o){o.d(e,{Vy:()=>a,fI:()=>i,ux:()=>s});var n=o(22786),r=o(79468);function a(t,e){const o=t%54+1;return e.getPropertyValue(`--color-${o}`)}function i(t,e){const o=e.getPropertyValue(`--graph-color-${t+1}`)||a(t,e);return(0,r.RQ)(o)}const s=(0,n.A)(t=>Array.from({length:54},(e,o)=>i(o,t)),(t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===e[0].getPropertyValue("--color-1"))},29961(t,e,o){o.a(t,async function(t,n){try{o.d(e,{d:()=>s,n:()=>d});var r=o(72487),a=o(30162),i=t([r,a]);function s(t,e,o){return"month"===t?{formatter:t=>{const n=new Date(t);return 0===n.getMonth()?`{bold|${(0,r.fr)(n,e,o)}}`:(0,r.Wq)(n,e,o)}}:"year"===t?{formatter:t=>(0,r.Pm)(new Date(t),e,o)}:void 0}function d(t,e,o,n){const i=n/60/24,s=new Date(t);if(i>88)return 0===s.getMonth()?`{bold|${(0,r.fr)(s,e,o)}}`:(0,r.Wq)(s,e,o);if(i>35)return 1===s.getDate()?`{bold|${(0,r.sl)(s,e,o)}}`:(0,r.sl)(s,e,o);if(i>7){const t=(0,r.sl)(s,e,o);return 1===s.getDate()?`{bold|${t}}`:t}return i>2?(0,r.gu)(s,e,o):n&&n<5?(0,a.ie)(s,e,o):0===s.getHours()&&0===s.getMinutes()&&0===s.getSeconds()?`{bold|${(0,r.sl)(s,e,o)}}`:(0,a.fU)(s,e,o)}[r,a]=i.then?(await i)():i,n()}catch(c){n(c)}})},33062(t,e,o){var n=o(62826),r=o(5124),a=o(22441);class i extends r.WF{willUpdate(t){t.has("color")&&(this.style.backgroundColor=this.color)}render(){return r.s6}constructor(...t){super(...t),this.color="",this.rtl=!1}}i.styles=r.AH`:host{display:inline-block;margin-inline-end:4px;margin-inline-start:initial;border-radius:10px;width:10px;height:10px;vertical-align:middle}:host([rtl]){direction:rtl}`,(0,n.Cg)([(0,a.MZ)()],i.prototype,"color",void 0),(0,n.Cg)([(0,a.MZ)({type:Boolean,reflect:!0})],i.prototype,"rtl",void 0),i=(0,n.Cg)([(0,a.EM)("ha-chart-tooltip-marker")],i)},3609(t,e,o){o.a(t,async function(t,e){try{o(44114),o(18111),o(22489),o(20116),o(7588),o(61701),o(18237),o(45367),o(92731),o(17642),o(58004),o(33853),o(45876),o(32475),o(15024),o(31698);var n=o(62826),r=o(22441),a=o(5124),i=o(22786),s=o(88696),d=o(1087),c=o(13234),h=o(3461),u=o(44439),l=(o(33062),o(38962)),p=t([u,l]);[u,l]=p.then?(await p)():p;const g=5,y=12,f=6,x=5;class v extends a.WF{render(){const t={grid:{top:0,bottom:0,left:0,right:0},tooltip:{trigger:"item",formatter:this._renderTooltip,appendTo:document.body}};return a.qy`<ha-chart-base .hass="${this.hass}" .data="${this._createData(this.data,this._sizeController.value?.width)}" .options="${t}" height="100%" .extraComponents="${[c.A]}" @chart-click="${this._handleChartClick}" @chart-sankeyroam="${this._handleChartSankeyRoam}"></ha-chart-base>`}_processLinks(t,e){const o=new Map,n=new Map,r=[];return e.forEach(e=>{const a=t.find(t=>t.id===e.source),i=t.find(t=>t.id===e.target);if(!a||!i)return;const s=n.get(a.id)||0,d=o.get(i.id)||0,c=a.value-s,h=i.value-d,u=Math.min(e.value??c,c,h);o.set(i.id,d+u),n.set(a.id,s+u),u>0&&r.push({...e,value:u})}),r}_findParentIndex(t,e,o){const n=e.filter(e=>e.target===t).map(t=>t.source);if(0===n.length)return-1;let r=0,a=0;for(const t of n){let e=0;for(let n=o.length-1;n>=0;n--){const i=o[n],s=i.findIndex(e=>e.id===t);if(-1!==s){r+=e+s,a++;break}e+=i.length}}return a>0?r/a:-1}constructor(...t){super(...t),this.data={nodes:[],links:[]},this.vertical=!1,this._currentZoom=1,this._sizeController=new s.P(this,{callback:t=>t[0]?.contentRect}),this._renderTooltip=t=>{const e=t.data,o=this.valueFormatter?this.valueFormatter(e.value):e.value,n=a.qy`<div style="direction:ltr;display:inline"> ${o} </div>`;if(e.id){const o=this.data.nodes.find(t=>t.id===e.id);return a.qy`<ha-chart-tooltip-marker .color="${String(t.color??"")}"></ha-chart-tooltip-marker> ${o?.label??e.id}<br>${n}`}if(e.source&&e.target){const t=this.data.nodes.find(t=>t.id===e.source),o=this.data.nodes.find(t=>t.id===e.target);return a.qy`${t?.label??e.source} → ${o?.label??e.target}<br>${n}`}return null},this._handleChartSankeyRoam=t=>{this._currentZoom=t.detail.zoom},this._handleChartClick=t=>{const e=t.detail;if("node"!==e.dataType)return;const o=e.data?.id;if(!o)return;const n=this.data.nodes.find(t=>t.id===o);n?.entityId&&(0,d.r)(this,"node-click",{node:n})},this._createData=(0,i.A)((t,e=0)=>{const o=t.nodes.filter(t=>t.value>0),n=[...new Set(o.map(t=>t.index))].sort(),r=new Map,a=[];n.forEach((e,n)=>{r.set(e,n);const i=o.filter(t=>t.index===e);i.length>0&&a.push(a.length>0?i.sort((e,o)=>{const n=this._findParentIndex(e.id,t.links,a),r=this._findParentIndex(o.id,t.links,a);return n===r?0:-1===n?1:-1===r?-1:n-r}):i)});const i=this._processLinks(o,t.links),s=e/n.length-30-x;return{id:"sankey",type:"sankey",nodes:a.flat().map(t=>({id:t.id,value:t.value,itemStyle:{color:t.color},depth:r.get(t.index)})),links:i,draggable:!1,scaleLimit:{min:1,max:4},orient:this.vertical?"vertical":"horizontal",nodeWidth:15,nodeGap:f,lineStyle:{color:"gradient",opacity:.4,curveness:.5},layoutIterations:0,animationDuration:500,label:{formatter:e=>t.nodes.find(t=>t.id===e.data.id)?.label??e.data.id,position:this.vertical?"bottom":"right",distance:x,minMargin:5,overflow:"break"},labelLayout:t=>{if(this.vertical){const e=t.text.split(" ").reduce((t,e)=>t.length>e.length?t:e,""),o=(0,h.W)(e,y),n=(t.rect.width+6)*this._currentZoom,r=Math.min(y,n/o*y);return{fontSize:r>1?r:0,width:n,align:"center",dy:-2}}const e=(t.rect.height+8)*this._currentZoom,o=Math.min(e/t.labelRect.height*y,y);return{fontSize:o,lineHeight:o,width:s,height:t.rect.height}},top:this.vertical?0:g,bottom:this.vertical?25:g,left:this.vertical?g:0,right:this.vertical?g:s+x,emphasis:{focus:"adjacency"}}})}}v.styles=a.AH`:host{display:block;flex:1;max-width:100%;background:var(--ha-card-background,var(--card-background-color))}ha-chart-base{width:100%;height:100%}`,(0,n.Cg)([(0,r.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,n.Cg)([(0,r.MZ)({attribute:!1})],v.prototype,"data",void 0),(0,n.Cg)([(0,r.MZ)({type:Boolean})],v.prototype,"vertical",void 0),(0,n.Cg)([(0,r.MZ)({attribute:!1})],v.prototype,"valueFormatter",void 0),(0,n.Cg)([(0,r.wk)()],v.prototype,"_sizeController",void 0),v=(0,n.Cg)([(0,r.EM)("ha-sankey-chart")],v),e()}catch(t){e(t)}})},48949(t,e,o){o.d(e,{Q:()=>s});var n=o(62826),r=o(22441),a=o(71769),i=o(84187);const s=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._unsubMql=(0,a.m)(this.mobileSizeQuery,t=>{this._isMobileSize=t})}disconnectedCallback(){super.disconnectedCallback(),this._unsubMql?.(),this._unsubMql=void 0}constructor(...t){super(...t),this._isMobileSize=!1,this._isMobileClient=i.M,this.mobileSizeQuery="all and (max-width: 450px), all and (max-height: 500px)"}}return(0,n.Cg)([(0,r.wk)()],e.prototype,"_isMobileSize",void 0),e}},54706(t,e,o){o.d(e,{E:()=>a});o(74423),o(18111),o(13579);var n=o(62826),r=o(22441);const a=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then(t=>t()):t()}this.__unsubs=void 0}}updated(t){if(super.updated(t),t.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const e of t.keys())if(this.hassSubscribeRequiredHostProps.includes(e))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some(t=>void 0===this[t])&&(this.__unsubs=this.hassSubscribe())}}return(0,n.Cg)([(0,r.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},13234(t,e,o){o.d(e,{A:()=>_});var n=o(47685),r=(o(44114),o(18111),o(22489),o(20116),o(30531),o(7588),o(61701),o(18237),o(13579),o(45367),o(92731),o(17642),o(58004),o(33853),o(45876),o(32475),o(15024),o(31698),o(83354));function a(t){return"passThrough"in t}function i(t,e){t.eachSeriesByType("sankey",t=>{if("justify"!==t.get("nodeAlign"))return;const o=t.get("nodeWidth"),n=t.get("nodeGap"),i=(0,r.Lj)(t,e).refContainer,{width:u,height:g}=i,y=t.getGraph();!function(t,e,o,n,r,i,u){const g=t.filter(t=>t.getLayout().value>0),y=[...new Set(g.map(t=>t.hostGraph.data.getRawDataItem(t.dataIndex).depth||0))].sort(),v=function(t,e){const o=[];return e.forEach(e=>{const n=function(t,e,o){if(0===t.getLayout().value)return[];const n=s(t.node1,e),r=s(t.node2,e),a=d(t),i=function(t,e,o){return o.slice(t+1,e)}(n.depthIndex,r.depthIndex,e),h=t.node1.hostGraph.data.getRawDataItem(t.node1.dataIndex),u=t.node2.hostGraph.data.getRawDataItem(t.node2.dataIndex),l=i.map(t=>{const e=function(t,e,o,n){return{passThrough:!0,id:c(t,e,o),value:n,depth:o,sourceId:t,targetId:e}}(h.id,u.id,t,a);return o.push(e),e.id});return l}(e,t,o);e.passThroughNodeIds=n}),o}(y,e),b=function(t,e,o,n,r,i,s,d){const{sectionSize:c,sectionDepthSize:u}=function(t,e,o,n,r){const a=("vertical"===t?e:o)-2*r,i="vertical"===t?o/n.length:e/n.length;return{sectionSize:a,sectionDepthSize:i}}(s,r,i,n,d),g=function(t,e){const o={};return t.forEach(t=>{const e=t.getLayout().depth;o[e]?o[e].push(t):o[e]=[t]}),e.forEach(t=>{o[t.depth]?o[t.depth].push(t):o[t.depth]=[t]}),o}(t,e),y=function(t,e,o){const n=e.map(e=>[...t[e]||[]]),r=n.map(l),a=(t,a)=>{const i=f(t,n,r,e,o),s=n[t],d=r[t];n[t]=a,r[t]=l(a);return f(t,n,r,e,o)<i||(n[t]=s,r[t]=d,!1)};for(let t=0;t<4;t++){let t=!1;for(let o=1;o<n.length;o++){const i=e[o-1],s=p(n[o],r[o-1],t=>h(t,"source",i,e));s.changed&&a(o,s.sorted)&&(t=!0)}for(let o=n.length-2;o>=0;o--){const i=e[o+1],s=p(n[o],r[o+1],t=>h(t,"target",i,e));s.changed&&a(o,s.sorted)&&(t=!0)}if(!t)break}const i={};return e.forEach((t,e)=>{i[t]=n[e]}),i}(g,n,o);let v=0;const b=n.map(t=>{const e=function(t){return t.map(t=>({node:t,id:t.id,value:a(t)?t.value:t.getLayout().value,x:0,y:0,dx:0,dy:0,size:0}))}(y[t]||[]),o=c-(e.length+1)*d,n=e.reduce((t,e)=>t+e.value,0),{nodes:r,valueToSizeRatio:i}=x(e,o,n,v);return i>v&&(v=i),{nodes:r,depth:t,totalValue:n,valueToSizeRatio:i}});return b.forEach((t,e)=>{!function(t,e,o,n,r,a){let i=0;t.valueToSizeRatio!==r?t.nodes.forEach(t=>{const e=Math.max(1,Math.floor(t.value/r));i+=e,t.size=e}):i=t.nodes.reduce((t,e)=>t+e.size,0);const s=o-i;let d=s/(t.nodes.length+1);t.nodes.forEach(o=>{"vertical"===a?(o.x=d,o.y=e*n):(o.x=e*n,o.y=d),d+=o.size+s/(t.nodes.length+1)})}(t,e,c,u,v,s)}),b.flatMap(t=>t.nodes)}(g,v,e,y,r,i,u,n);!function(t,e,o){const n=function(t){return"vertical"===t?{breadth:"x",depth:"y",breadthSize:"dx",depthSize:"dy"}:{breadth:"y",depth:"x",breadthSize:"dy",depthSize:"dx"}}(o),r="vertical"===o?"curveVertical":"curveHorizontal";(function(t,e,o){t.forEach(t=>{t[o.breadthSize]=t.size,t[o.depthSize]=e,a(t.node)||t.node.setLayout({x:t.x,y:t.y,dx:t.dx,dy:t.dy},!0)})})(t,e,n),function(t,e){t.forEach(t=>{a(t.node)||t.node.outEdges.forEach(o=>{const n=o.hostGraph.edgeData.getRawDataItem(o.dataIndex).value/t.value*t.size;o.setLayout({[e.breadthSize]:n,[e.depthSize]:0},!0)})})}(t,n),function(t,e){t.forEach(t=>{a(t.node)||(t.node.outEdges.sort((t,o)=>t.node2.getLayout()[e.breadth]-o.node2.getLayout()[e.breadth]),t.node.inEdges.sort((t,o)=>t.node1.getLayout()[e.breadth]-o.node1.getLayout()[e.breadth]))})}(t,n),t.forEach(e=>{a(e.node)||(function(t,e,o){if(a(t.node))return;let n=0;t.node.outEdges.forEach(r=>{r.setLayout({x:"vertical"===e?t.x+n:t.x+t.dx,y:"vertical"===e?t.y+t.dy:t.y+n},!0),n+=r.getLayout()[o.breadthSize]})}(e,o,n),function(t,e,o,n,r){if(a(t.node))return;let i=0;t.node.inEdges.forEach(a=>{const s=function(t,e,o,n){const r=[];return t.passThroughNodeIds.forEach(t=>{const a=e.find(e=>e.id===t);r.push({x:a.x,y:a.y,type:n}),"vertical"===o?r.push({x:a.x,y:a.y+a.dy,type:"line"}):r.push({x:a.x+a.dx,y:a.y,type:"line"})}),r}(a,e,o,r);a.setLayout({targets:[...s,{x:"vertical"===o?t.x+i:t.x,y:"vertical"===o?t.y:t.y+i,type:r}]},!0),i+=a.getLayout()[n.breadthSize]})}(e,t,o,n,r))})}(b,o,u)}(y.nodes,y.edges,o,n,u,g,t.get("orient"))})}function s(t,e){const o=t.hostGraph.data.getRawDataItem(t.dataIndex).depth||0,n=e.findIndex(t=>t===o);return{depth:o,depthIndex:n}}function d(t){return t.hostGraph.edgeData.getRawDataItem(t.dataIndex).value}function c(t,e,o){return`${t}-${e}-${o}`}function h(t,e,o,n){if(a(t)){return[{id:"source"===e?t.sourceId:t.targetId,weight:t.value},{id:c(t.sourceId,t.targetId,o),weight:t.value}]}const r="source"===e?t.inEdges:t.outEdges,i=[];return r.forEach(t=>{const r=t.node1.hostGraph.data.getRawDataItem(t.node1.dataIndex),a=t.node2.hostGraph.data.getRawDataItem(t.node2.dataIndex),h=s("source"===e?t.node1:t.node2,n).depth,u=d(t);if(h===o){const t="source"===e?r:a;return void i.push({id:t.id,weight:u})}("source"===e?h<o:h>o)&&i.push({id:c(r.id,a.id,o),weight:u})}),i}function u(t,e,o){let n=0,r=0;return t.forEach(({id:t,weight:o})=>{const a=e.get(t);void 0!==a&&(n+=a*o,r+=o)}),r>0?n/r:o}function l(t){const e=new Map;return t.forEach((t,o)=>e.set(t.id,o)),e}function p(t,e,o){const n=t.map((t,n)=>({node:t,index:n,barycenter:u(o(t),e,n)}));n.sort((t,e)=>t.barycenter-e.barycenter||t.index-e.index);const r=n.map(t=>t.node),a=r.some((e,o)=>e!==t[o]);return{sorted:r,changed:a}}function g(t,e,o,n,r,a){const i=[];return n.forEach(n=>{if(0===n.getLayout().value)return;const d=n.node1.hostGraph.data.getRawDataItem(n.node1.dataIndex),h=n.node2.hostGraph.data.getRawDataItem(n.node2.dataIndex),u=s(n.node1,o).depth,l=s(n.node2,o).depth;if(u>t||l<e)return;const p=u===t?d.id:c(d.id,h.id,t),g=l===e?h.id:c(d.id,h.id,e),y=r.get(p),f=a.get(g);void 0!==y&&void 0!==f&&i.push({sourceIdx:y,targetIdx:f})}),i}function y(t){let e=0;for(let o=0;o<t.length;o++)for(let n=o+1;n<t.length;n++){const r=t[o],a=t[n];(r.sourceIdx-a.sourceIdx)*(r.targetIdx-a.targetIdx)<0&&e++}return e}function f(t,e,o,n,r){let a=0;return t>0&&(a+=y(g(n[t-1],n[t],n,r,o[t-1],o[t]))),t<e.length-1&&(a+=y(g(n[t],n[t+1],n,r,o[t],o[t+1]))),a}function x(t,e,o,n=0){let r=o/e;r<n&&(r=n);let a=0;const i=t.map(t=>{if(1===t.size)return t;let e=Math.floor(t.value/r);return e<1&&(a+=1-e,e=1),{...t,size:e}});return a>0?x(i,e-a,o,r):{nodes:i,valueToSizeRatio:r}}var v=o(30052);class b extends v.A{render(t,e,o){super.render(t,e,o);const n=t.getData("edge");t.getGraph().eachEdge(t=>{const e=t.getLayout(),o=t.getModel().getModel("lineStyle").get("curveness"),r=n.getItemGraphicEl(t.dataIndex);r.buildPath=t=>function(t,e,o){if(!e.targets?.length)return;t.moveTo(e.x,e.y);const n=e.targets[e.targets.length-1],r=[{x:e.x,y:e.y,type:n.type},...e.targets];for(let e=1;e<r.length;e++){const n=r[e],a=r[e-1];"curveHorizontal"===n.type?t.bezierCurveTo(a.x*(1-o)+n.x*o,a.y,n.x*(1-o)+a.x*o,n.y,n.x,n.y):"curveVertical"===n.type?t.bezierCurveTo(a.x,a.y*(1-o)+n.y*o,n.x,n.y*(1-o)+a.y*o,n.x,n.y):t.lineTo(n.x,n.y)}t.lineTo(n.x+e.dx,n.y+e.dy);for(let n=r.length-2;n>=0;n--){const a={x:r[n+1].x+e.dx,y:r[n+1].y+e.dy,type:r[n+1].type},i={x:r[n].x+e.dx,y:r[n].y+e.dy,type:a.type};"curveHorizontal"===i.type?t.bezierCurveTo(a.x*(1-o)+i.x*o,a.y,i.x*(1-o)+a.x*o,i.y,i.x,i.y):"curveVertical"===i.type?t.bezierCurveTo(a.x,a.y*(1-o)+i.y*o,i.x,i.y*(1-o)+a.y*o,i.x,i.y):t.lineTo(i.x,i.y)}t.closePath()}(t,e,o),r.dirtyShape()})}}const m=b;function _(t){(0,n.a)(t),t.registerLayout(i),t.registerChartView(m)}},84187(t,e,o){o.d(e,{M:()=>n});const n=/(?:iphone|android|ipad)/i.test(navigator.userAgent)},3461(t,e,o){let n;function r(t,e,o="Roboto, Noto, sans-serif"){n||(n=document.createElement("canvas"));const r=n.getContext("2d");if(!r)return 0;r.font=`${e}px ${o}`;const a=r.measureText(t);return Math.ceil(Math.max(a.actualBoundingBoxRight+a.actualBoundingBoxLeft,a.width))}o.d(e,{W:()=>r})}};