"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[6987],{74156:(_e,Ce,p)=>{p.d(Ce,{q:()=>Fe});var f=p(41407),X=p(39953),Le=p(82803);const me=10,Fe=({colorPalette:q,min:ae,max:he,display:I,hoverValue:se,useStopsPercentage:ye})=>{const[ne,ce]=(0,X.useState)([]),[oe,ue]=(0,X.useState)({isShown:!1,value:0}),[re,be]=(0,X.useState)(null),ze=(0,Le.l4)(),de=Ee(ze,ne);(0,X.useEffect)(()=>{ce(fe({colorArray:q,stops:me,useStopsPercentage:ye}))},[q,ye]);const Te=we=>{const Ge=we.nativeEvent.offsetX,$e=we.currentTarget.offsetWidth,Pe=Math.floor(Ge*100/$e+1),Ne=Math.floor((he-ae)*Pe/100+ae);ue({isShown:!0,value:Ne}),be(Pe)},pe=()=>{ue({isShown:!1,value:0})};return(0,X.useEffect)(()=>{be(se==null?null:i((se-ae)/(he-ae)))},[se,ae,he]),X.createElement("div",{className:de.scaleWrapper,onMouseMove:Te,onMouseLeave:pe},X.createElement("div",{className:de.scaleGradient},I&&(oe.isShown||se!==void 0)&&X.createElement("div",{className:de.followerContainer},X.createElement("div",{className:de.follower,style:{left:`${re}%`}}))),I&&X.createElement("div",{className:de.followerContainer},X.createElement("div",{className:de.legendValues},X.createElement("span",null,I(ae)),X.createElement("span",null,I(he))),re!=null&&(oe.isShown||se!==void 0)&&X.createElement("span",{className:de.hoverValue,style:{left:`${re}%`}},I(se??oe.value))))},fe=({colorArray:q,stops:ae,useStopsPercentage:he=!0})=>{const I=q.length;if(he&&I<=20){const ce=1/I*100;let oe=0;const ue=[];for(const re of q)oe>0?ue.push(`${re} ${oe}%`):ue.push(re),oe+=ce,ue.push(`${re} ${oe}%`);return ue}const se=q[I-1],ye=Math.ceil(I/ae),ne=new Set;for(let ce=0;ce<I;ce+=ye)ne.add(q[ce]);return ne.add(se),[...ne]};function i(q){return q>1?100:q<0?0:q*100}const Ee=(q,ae)=>({scaleWrapper:(0,f.css)`
    width: 100%;
    font-size: 11px;
    opacity: 1;
  `,scaleGradient:(0,f.css)`
    background: linear-gradient(90deg, ${ae.join()});
    height: 10px;
    pointer-events: none;
  `,legendValues:(0,f.css)`
    display: flex;
    justify-content: space-between;
    pointer-events: none;
  `,hoverValue:(0,f.css)`
    position: absolute;
    margin-top: -14px;
    padding: 3px 15px;
    background: ${q.colors.background.primary};
    transform: translateX(-50%);
  `,followerContainer:(0,f.css)`
    position: relative;
    pointer-events: none;
    white-space: nowrap;
  `,follower:(0,f.css)`
    position: absolute;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    transform: translateX(-50%) translateY(-50%);
    border: 2px solid ${q.colors.text.primary};
    margin-top: 5px;
  `})},14121:(_e,Ce,p)=>{p.r(Ce),p.d(Ce,{plugin:()=>vt});var f=p(39953),X=p(40530),Le=p(82909),me=p(89591),Fe=p(63671),fe=p(32688),i=p(34547),Ee=p(41456),q=p(86246),ae=p(74156),he=p(78181),I=p(70394),se=p(41407),ye=p(52716),ne=p(51226),ce=p(30639),oe=p(82803),ue=p(31276),re=p(96248),be=p(79469),ze=p(70393),de=p(41013),Te=p(61068),pe=p(83502),we=p(69330),Ge=p(12223),$e=p(4919),Pe=p(97433),Ne=p(80854);const et=e=>e.hover.seriesIdx===2?f.createElement(Ne.H,{data:e.data.exemplars,rowIndex:e.hover.dataIdx,header:"Exemplar"}):f.createElement(tt,{...e}),tt=({data:e,hover:a,showHistogram:t,scopedVars:d,replaceVars:l})=>{const n=a.dataIdx,c=e.heatmap?.fields[0],u=e.heatmap?.fields[1],S=e.heatmap?.fields[2],o=s=>{if(c?.display)return(0,pe.zc)(c.display(s));if(c?.type===me.fS.time){const M="YYYY-MM-DD HH:mm:ss";return(0,Pe.h4)().getCurrent()?.formatDate(s,M)}return`${s}`},y=c?.values,$=u?.values,k=S?.values,H=(0,I.d8)(e.heatmap),_=u?.display?s=>(0,pe.zc)(u.display(s)):s=>`${s}`,j=n%e.yBucketCount;let Z,w,x;if(H.yOrdinalDisplay){const s=e.yLayout===i.kv.le?j-1:j,M=e.yLayout===i.kv.le?j:j+1;Z=s<0?H.yMinDisplay:`${H.yOrdinalDisplay[s]}`,w=`${H.yOrdinalDisplay[M]}`,(!H.yOrdinalLabel||Number.isNaN(+H.yOrdinalLabel[0]))&&(x=e.yLayout===i.kv.le?w:Z)}else{const s=$?.[j];if(e.yLayout===i.kv.le)if(w=`${s}`,e.yLog){let D=(e.yLog===2?Math.log2:Math.log10)(s)-1/e.yLogSplit;Z=`${e.yLog**D}`}else Z=`${s-e.yBucketSize}`;else if(Z=`${s}`,e.yLog){let D=(e.yLog===2?Math.log2:Math.log10)(s)+1/e.yLogSplit;w=`${e.yLog**D}`}else w=`${s+e.yBucketSize}`}let O,B;e.xLayout===i.kv.le?(B=y?.[n],O=B-e.xBucketSize):(O=y?.[n],B=O+e.xBucketSize);const J=k?.[n],V=e.heatmap?.fields.filter(s=>!s.config.custom?.hideFrom?.tooltip),F=[],E=new Set;for(const s of V??[]){if(s.config.links&&s.config.links.length>0&&e.heatmap){const D=d.find(T=>T&&T.__dataContext&&T.__dataContext.value.field.name===x);s.getLinks=(0,ye.oB)(e.heatmap,s,D||{},l)}if(s.getLinks){const D=s.values[n],T=s.display?s.display(D):{text:`${D}`,numeric:+D};s.getLinks({calculatedValue:T,valueRowIndex:n}).forEach(P=>{const U=`${P.title}/${P.href}`;E.has(U)||(F.push(P),E.add(U))})}}let R=(0,f.useRef)(null),ee=150,A=50,z=Math.round(ee*devicePixelRatio),Y=Math.round(A*devicePixelRatio);(0,f.useEffect)(()=>{if(t){let s=R.current?.getContext("2d");if(s&&y&&$&&k){let M=n;for(;y[M--]===y[n];);M++;let D=M+e.yBucketCount,T=0,P=M;for(;P<D;){let le=k[P];T=Math.max(T,le),P++}let U=new Path2D,C=new Path2D;P=M;let te=0;for(;P<D;){let le=k[P];if(le>0){let K=le/T,r=te/(e.yBucketCount+1);(P===n?U:C).rect(Math.round(z*r),Math.round(Y*(1-K)),Math.round(z/e.yBucketCount),Math.round(Y*K))}P++,te++}s.clearRect(0,0,z,Y),s.fillStyle="#ffffff80",s.fill(C),s.fillStyle="#ff000080",s.fill(U)}}},[n]);const[Q]=(0,f.useState)(()=>e.heatmap?.meta?.type===ne.P.HeatmapCells&&!(0,I.qJ)(e.heatmap));if(Q)return f.createElement("div",null,f.createElement(Ne.H,{data:e.heatmap,rowIndex:n}));const b=()=>{if(x)return f.createElement("div",null,"Name: ",x);switch(e.yLayout){case i.kv.unknown:return f.createElement("div",null,_(Z))}return f.createElement("div",null,"Bucket: ",_(Z)," - ",_(w))};return f.createElement(f.Fragment,null,f.createElement("div",null,f.createElement("div",null,o(O)),e.xLayout!==i.kv.unknown&&f.createElement("div",null,o(B))),t&&f.createElement("canvas",{width:z,height:Y,ref:R,style:{width:z+"px",height:Y+"px"}}),f.createElement("div",null,b(),f.createElement("div",null,(0,we.CZ)(S,e.heatmap),": ",e.display(J))),F.length>0&&f.createElement(Ge.wc,null,F.map((s,M)=>f.createElement($e.Qj,{key:M,icon:"external-link-alt",target:s.target,href:s.href,onClick:s.onClick,fill:"text",style:{width:"100%"}},s.title))))};var lt=p(82837),at=p(94123),Be=p(52226),Ve=p(92697),Ye=p(36316),ge=p(80742),nt=p(40793),ot=p(80115),Ue=p(14197);function it(e){const{dataRef:a,theme:t,eventBus:d,onhover:l,onclick:n,onzoom:c,isToolTipOpen:u,timeZone:S,getTimeRange:o,cellGap:y,hideLE:$,hideGE:k,yAxisConfig:H,ySizeDivisor:_,sync:j,eventsScope:Z="__global_"}=e,w="x";let x="time",O=!0;a.current?.heatmap?.fields[0].type!==me.fS.time&&(x=a.current?.heatmap?.fields[0].config?.unit??"x",O=!1);const B=devicePixelRatio;let J=a.current?.heatmap?.meta?.type;const V=t.visualization.getColorByName(e.exemplarColor);let F,E,R=new ot.U(S),ee;R.addHook("init",r=>{r.root.querySelectorAll(".u-cursor-pt").forEach(h=>{Object.assign(h.style,{borderRadius:"0",border:"1px solid white",background:"transparent"})}),n&&r.over.addEventListener("mouseup",h=>{r.cursor.drag._x||r.cursor.drag._y||n(h)},!0)}),c&&R.addHook("setSelect",r=>{c({xMin:r.posToVal(r.select.left,w),xMax:r.posToVal(r.select.left+r.select.width,w)}),r.setSelect({left:0,top:0,width:0,height:0},!1)}),O&&R.addHook("setData",r=>{let{min:h,max:m}=r.scales.x,g=o().from.valueOf(),v=o().to.valueOf();(h!==g||m!==v)&&queueMicrotask(()=>{r.setScale(w,{min:g,max:v})})}),R.addHook("syncRect",(r,h)=>{ee=h});const A={point:{[x]:null},data:a.current?.heatmap},z=new Ye.es(A);let Y;l&&R.addHook("setLegend",r=>{if(r.cursor.idxs!=null)for(let h=0;h<r.cursor.idxs.length;h++){const m=r.cursor.idxs[h];if(m!=null){const{left:g,top:v}=r.cursor;A.rowIndex=m,A.point[x]=r.posToVal(g,w),d.publish(z),u.current||(Y&&(clearTimeout(Y),Y=0),l({seriesIdx:h,dataIdx:m,pageX:ee.left+g,pageY:ee.top+v}));return}}u.current||Y||(Y=setTimeout(()=>{l(null),A.rowIndex=void 0,A.point[x]=null,d.publish(z)},100))}),R.addHook("drawClear",r=>{F=F||new Ue.lW(0,0,r.bbox.width,r.bbox.height),F.clear(),r.series.forEach((h,m)=>{m>0&&(h._paths=null)})}),R.setMode(2),R.addScale({scaleKey:w,isTime:O,orientation:i.wN.Horizontal,direction:i.bQ.Right,range:(r,h,m)=>{if(O)return[o().from.valueOf(),o().to.valueOf()];if(a.current?.xLayout===i.kv.le)return[h-a.current?.xBucketSize,m];if(a.current?.xLayout===i.kv.ge)return[h,m+a.current?.xBucketSize];{let g=a.current?.xBucketSize/2;return[h-g,m+g]}}});let Q;if(!O){Q=[];for(let r=0;r<10;r++)Q.push(r*a.current?.xBucketSize)}R.addAxis({scaleKey:w,placement:i.LB.Bottom,incrs:Q,isTime:O,theme:t,timeZone:S});const b=a.current?.heatmap?.fields[1];if(!b)return R;const M=b.config?.custom?.scaleDistribution??{type:i.wf.Linear},D=!!H.reverse,T=J===ne.P.HeatmapCells&&!(0,I.qJ)(a.current?.heatmap),P=M.type!==i.wf.Linear||T,U=(0,I.d8)(a.current?.heatmap).yOrdinalDisplay!=null,C="y_"+(Math.random()+1).toString(36).substring(7);R.addScale({scaleKey:C,isTime:!1,orientation:i.wN.Vertical,direction:D?i.bQ.Down:i.bQ.Up,distribution:P?i.wf.Log:i.wf.Linear,log:M.log??2,range:T?(r,h,m)=>{let g,v;if([g,v]=P?Ve.Z.rangeLog(h,m,M.log??2,!0):[h,m],P&&!U){let N=r.scales[C].log,W=N===2?Math.log2:Math.log10,{min:G,max:xe}=H;if(G!=null&&G>0){let Se=W(G);g=N**(0,ge.mB)(Se,1)}if(xe!=null&&xe>0){let Se=W(xe);v=N**(0,ge.UO)(Se,1)}}return[g,v]}:(r,h,m)=>{let g=h,v=m,{min:N,max:W}=H;if(P){let G=r.scales[C].log,xe=!1,Se=!1,De=G===2?Math.log2:Math.log10;if(_!==1){let ke=De(h),qe=De(m);Number.isInteger(ke)||(g=G**(0,ge.mB)(ke,1),xe=!0),Number.isInteger(qe)||(v=G**(0,ge.UO)(qe,1),Se=!0)}if(a.current?.yLayout===i.kv.le?xe||(g/=G):a.current?.yLayout===i.kv.ge?Se||(v*=G):(g/=G/2,v*=G/2),!U){if(N!=null&&N>0){let ke=De(N);g=G**(0,ge.mB)(ke,1)}if(W!=null&&W>0){let ke=De(W);v=G**(0,ge.UO)(ke,1)}}}else{let G=a.current?.yBucketSize;G===0&&(G=1),G&&(a.current?.yLayout===i.kv.le?g-=G:a.current?.yLayout===i.kv.ge?v+=G:(g-=G/2,v+=G/2)),U||(g=N??g,v=W??v)}return[g,v]}});const te=b.display??(0,pe.Cf)("short");R.addAxis({scaleKey:C,show:H.axisPlacement!==i.LB.Hidden,placement:H.axisPlacement||i.LB.Left,size:H.axisWidth||null,label:H.axisLabel,theme:t,formatValue:(r,h)=>(0,pe.zc)(te(r,h)),splits:U?r=>{const h=(0,I.d8)(a.current?.heatmap);if(!h.yOrdinalDisplay)return[0,1];let m=h.yOrdinalDisplay.map((g,v)=>v);switch(a.current?.yLayout){case i.kv.le:m.unshift(-1);break;case i.kv.ge:m.push(m.length);break}if(r.height<60)m=[m[0],m[m.length-1]];else for(;m.length>3&&(r.height-15)/m.length<10;)m=m.filter((g,v)=>v%2===0);return m}:void 0,values:U?(r,h)=>{const m=(0,I.d8)(a.current?.heatmap);return m.yOrdinalDisplay?h.map(g=>g<0?m.yMinDisplay??"":m.yOrdinalDisplay[g]??""):h}:void 0});const le=T?ct:st;R.addSeries({facets:[{scale:w,auto:!0,sorted:1},{scale:C,auto:!0}],pathBuilder:le({each:(r,h,m,g,v,N,W)=>{F.add({x:g-r.bbox.left,y:v-r.bbox.top,w:N,h:W,sidx:h,didx:m})},gap:y,hideLE:$,hideGE:k,xAlign:a.current?.xLayout===i.kv.le?-1:a.current?.xLayout===i.kv.ge?1:0,yAlign:(a.current?.yLayout===i.kv.le?-1:a.current?.yLayout===i.kv.ge?1:0)*(D?-1:1),ySizeDivisor:_,disp:{fill:{values:(r,h)=>a.current?.heatmapColors?.values,index:a.current?.heatmapColors?.palette}}}),theme:t,scaleKey:""}),R.addSeries({facets:[{scale:w,auto:!0,sorted:1},{scale:C,auto:!0}],pathBuilder:rt({each:(r,h,m,g,v,N,W)=>{F.add({x:g-r.bbox.left,y:v-r.bbox.top,w:N,h:W,sidx:h,didx:m})}},V),theme:t,scaleKey:""});const K={drag:{x:!0,y:!1,setScale:!1},dataIdx:(r,h)=>{if(h===1){E=null;let m=r.cursor.left*B,g=r.cursor.top*B;F.get(m,g,1,1,v=>{(0,Ue.Pn)(m,g,v.x,v.y,v.x+v.w,v.y+v.h)&&(E=v)})}return E&&h===E.sidx?E.didx:null},points:{fill:"rgba(255,255,255, 0.3)",bbox:(r,h)=>{let m=E&&h===E.sidx;return{left:m?E.x/B:-10,top:m?E.y/B:-10,width:m?E.w/B:0,height:m?E.h/B:0}}}};return j&&j()!==nt.m.Off&&(K.sync={key:Z,scales:[w,C],filters:{pub:(r,h,m,g,v,N,W)=>(m<0?(A.point[x]=null,d.publish(new Ye.xH)):(A.point[x]=h.posToVal(m,w),d.publish(z)),!0)}},R.setSync()),R.setCursor(K),R}const Ke=4;function st(e){const{disp:a,each:t,gap:d=1,hideLE:l=-1/0,hideGE:n=1/0,xAlign:c=1,yAlign:u=1,ySizeDivisor:S=1}=e,o=devicePixelRatio,y=d>=Ke?Math.round:k=>k,$=Math.round(d*o);return(k,H)=>(Ve.Z.orient(k,H,(_,j,Z,w,x,O,B,J,V,F,E,R,ee,A,z)=>{let Y=k.data[H];const Q=Y[0],b=Y[1],s=Y[2],M=Q.length;let D=a.fill.values(k,H),T=a.fill.index??[...new Set(D)],P=T.map(N=>new Path2D),U=M-b.lastIndexOf(b[0]),C=M/U,te=b[1]-b[0]||x.max-x.min,le=Q[U]-Q[0],K,r;w.distr===3?K=Math.abs(O(Q[0]*w.log,w,F,J)-O(Q[0],w,F,J)):K=Math.abs(O(le,w,F,J)-O(0,w,F,J)),x.distr===3?r=Math.abs(B(b[0]*x.log,x,E,V)-B(b[0],x,E,V))/S:r=Math.abs(B(te,x,E,V)-B(0,x,E,V))/S,K=Math.max(1,y(K-$)),r=Math.max(1,y(r-$));let h=c===-1?-K:c===0?-K/2:0,m=u===1?-r:u===0?-r/2:0,g=b.slice(0,U).map(N=>y(B(N,x,E,V)+m)),v=Array.from({length:C},(N,W)=>y(O(Q[W*U],w,F,J)+h));for(let N=0;N<M;N++)if(s[N]>l&&s[N]<n){let W=v[~~(N/U)],G=g[N%U],xe=P[D[N]];A(xe,W,G,K,r),t(k,1,N,W,G,K,r)}return k.ctx.save(),k.ctx.rect(k.bbox.left,k.bbox.top,k.bbox.width,k.bbox.height),k.ctx.clip(),P.forEach((N,W)=>{k.ctx.fillStyle=T[W],k.ctx.fill(N)}),k.ctx.restore(),null}),null)}function rt(e,a){return(t,d)=>(Ve.Z.orient(t,d,(l,n,c,u,S,o,y,$,k,H,_,j,Z,w,x)=>{let O=new Path2D,B=[O],J=[a??"rgba(255,0,255,0.7)"];for(let V=0;V<n.length;V++){let F=c[V];F-=.5;let E=Math.round(Math.random())*2-1;F+=E*.5*Math.random();let R=o(n[V],u,H,$),ee=y(F,S,_,k),A=8,z=8;w(O,R-A/2,ee-z/2,A,z),e.each(t,d,V,R-A/2,ee-z/2,A,z)}t.ctx.save(),t.ctx.rect(t.bbox.left,t.bbox.top,t.bbox.width,t.bbox.height),t.ctx.clip(),B.forEach((V,F)=>{t.ctx.fillStyle=J[F],t.ctx.fill(V)}),t.ctx.restore()}),null)}function ct(e){const{disp:a,each:t,gap:d=1,hideLE:l=-1/0,hideGE:n=1/0}=e,c=devicePixelRatio,u=d>=Ke?Math.round:o=>o,S=Math.round(d*c);return(o,y)=>(Ve.Z.orient(o,y,($,k,H,_,j,Z,w,x,O,B,J,V,F,E,R)=>{let ee=o.data[y];const A=ee[0],z=ee[1],Y=ee[2],Q=ee[3],b=A.length;let s=a.fill.values(o,y),M=a.fill.index??[...new Set(s)],D=M.map(C=>new Path2D),T=new Map,P=new Map;for(let C=0;C<A.length;C++){let te=A[C],le=z[C],K=Y[C];T.has(te)||T.set(te,u(Z(te,_,B,x))),P.has(le)||P.set(le,u(w(le,j,J,O))),P.has(K)||P.set(K,u(w(K,j,J,O)))}let U=T.get(A.find(C=>C!==A[0]))-T.get(A[0]);for(let C=0;C<b;C++){if(Q[C]<=l||Q[C]>=n)continue;let te=A[C],le=z[C],K=Y[C],r=T.get(te),h=P.get(le),m=P.get(K),g=U,v=h-m;g=Math.max(1,g-S),v=Math.max(1,v-S);let N=r,W=h,G=D[s[C]];E(G,N,W,g,v),t(o,1,C,N,W,g,v)}o.ctx.save(),o.ctx.rect(o.bbox.left,o.bbox.top,o.bbox.width,o.bbox.height),o.ctx.clip(),D.forEach((C,te)=>{o.ctx.fillStyle=M[te],o.ctx.fill(C)}),o.ctx.restore()}),null)}const je=(e,a,t,d=-1/0,l=1/0)=>{if(a==null){a=1/0;for(let n=0;n<e.length;n++)e[n]>d&&e[n]<l&&(a=Math.min(a,e[n]))}if(t==null){t=-1/0;for(let n=0;n<e.length;n++)e[n]>d&&e[n]<l&&(t=Math.max(t,e[n]))}return[a,t]},Ze=(e,a,t,d)=>{let l=d-t||1,n=a.length,c=Array(e.length);for(let u=0;u<e.length;u++)c[u]=e[u]<t?0:e[u]>d?n-1:Math.min(n-1,Math.floor(n*(e[u]-t)/l));return c};function We(e,a,t,d,l,n,c){if(!e?.length)return{};(0,we.UY)(e);const u=a?.find(o=>o.name==="exemplar");if(n&&u?.fields.forEach((o,y)=>{u.fields[y].getLinks=n(u,o)}),t.calculate){if(fe.config.featureToggles.transformationsVariableSupport){const o={...t,calculation:{xBuckets:{...t.calculation?.xBuckets},yBuckets:{...t.calculation?.yBuckets}}};return o.calculation?.xBuckets?.value&&c!==void 0&&(o.calculation.xBuckets.value=c(o.calculation.xBuckets.value)),o.calculation?.yBuckets?.value&&c!==void 0&&(o.calculation.yBuckets.value=c(o.calculation.yBuckets.value)),He((0,I.xf)(e,o.calculation??{}),u,o,d,l)}return He((0,I.xf)(e,t.calculation??{}),u,t,d,l)}let S;for(const o of e)switch(o.meta?.type){case ne.P.HeatmapCells:return(0,I.qJ)(o)?He(o,u,t,d,l):ut(o,u,t,d,l);case ne.P.HeatmapRows:S=o}if(!S)if(e.length>1)e.every(y=>!Number.isNaN((0,Be.Ky)(y.fields[1].state?.displayName)))&&e.sort(Be.nf),S=[(0,lt._9)({frames:e})][0];else{let o=e[0],y=o.fields.filter(k=>k.type===me.fS.number);y.every(k=>!Number.isNaN((0,Be.Ky)(k.state?.displayName)))?(y.sort((k,H)=>(0,Be.Ky)(k.state?.displayName)-(0,Be.Ky)(H.state?.displayName)),S={...o,fields:[o.fields.find(k=>k.type===me.fS.time),...y]}):S=o}return He((0,I.Cj)({unit:t.yAxis?.unit,decimals:t.yAxis?.decimals,...t.rowsFrame,frame:S}),u,t,d,l)}const ut=(e,a,t,d,l)=>{if(e.meta?.type!==ne.P.HeatmapCells||(0,I.qJ)(e))return{warning:"Expected sparse heatmap format",heatmap:e};Oe(e.fields[1],t.yAxis,l);const n=e.fields[3],c=Oe(n,t.cellValues,l);let[u,S]=je(n.values,t.color.min,t.color.max,t.filterValues?.le,t.filterValues?.ge);return{heatmap:e,heatmapColors:{palette:d,values:Ze(n.values,d,u,S),minValue:u,maxValue:S},exemplars:a,display:o=>(0,pe.zc)(c(o))}},He=(e,a,t,d,l)=>{if(e.meta?.type!==ne.P.HeatmapCells)return{warning:"Expected heatmap scanlines format",heatmap:e};if(e.fields.length<2||e.length<2)return{heatmap:e};const n=(0,I.d8)(e);let c,u,S;for(const V of e.fields)switch(V.name){case"y":u=V.name;case"yMin":case"yMax":{u||(u=V.name),n.yOrdinalDisplay==null&&Oe(V,t.yAxis,l);break}case"x":case"xMin":case"xMax":c=V.name;break;default:V.type===me.fS.number&&!S&&(S=V)}if(!u)return{warning:"Missing Y field",heatmap:e};if(!u)return{warning:"Missing X field",heatmap:e};if(!S)return{warning:"Missing value field",heatmap:e};const o=Oe(S,t.cellValues,l),y=e.fields[0].values,$=e.fields[1].values,k=y.length;let H=k-$.lastIndexOf($[0]),_=k/H,j=$[1]-$[0],Z=y[H]-y[0],[w,x]=je(S.values,t.color.min,t.color.max,t.filterValues?.le,t.filterValues?.ge),O=t.calculation?.xBuckets,B=t.calculation?.yBuckets;return{heatmap:e,heatmapColors:{palette:d,values:Ze(S.values,d,w,x),minValue:w,maxValue:x},exemplars:a?.length?a:void 0,xBucketSize:Z,yBucketSize:j,xBucketCount:_,yBucketCount:H,yLog:B?.scale?.log??0,xLog:O?.scale?.log??0,xLogSplit:O?.scale?.log?+(O?.value??"1"):1,yLogSplit:B?.scale?.log?+(B?.value??"1"):1,xLayout:c==="xMax"?i.kv.le:c==="xMin"?i.kv.ge:i.kv.unknown,yLayout:u==="yMax"?i.kv.le:u==="yMin"?i.kv.ge:i.kv.unknown,display:V=>(0,pe.zc)(o(V))}};function Oe(e,a,t){if(a?.unit?.length||a?.decimals!=null){const{unit:d,decimals:l}=a;e.display=void 0,e.config={...e.config},d?.length&&(e.config.unit=d),l!=null&&(e.config.decimals=l)}return e.display||(e.display=(0,at.U)({field:e,theme:t})),e.display}var Je=p(39228),dt=p(40041),Qe=p(63374),ie=(e=>(e.Opacity="opacity",e.Scheme="scheme",e))(ie||{}),ve=(e=>(e.Exponential="exponential",e.Linear="linear",e))(ve||{});const Ie={calculate:!1,cellGap:1,cellValues:{},color:{scheme:"Oranges",fill:"dark-orange",reverse:!1,exponent:.5,steps:64},exemplars:{color:"rgba(255,0,255,0.7)"},filterValues:{le:1e-9},legend:{show:!0},showValue:i.Jp.Auto,tooltip:{show:!0,yHistogram:!1}},L={...Ie,color:{...Ie.color,mode:ie.Scheme,scale:ve.Exponential},yAxis:{...Ie.yAxis,axisPlacement:i.LB.Left},rowsFrame:{...Ie.rowsFrame,layout:i.kv.auto}},Me=[{name:"BrBG",invert:"always"},{name:"PiYG",invert:"always"},{name:"PRGn",invert:"always"},{name:"PuOr",invert:"always"},{name:"RdBu",invert:"always"},{name:"RdGy",invert:"always"},{name:"RdYlBu",invert:"always"},{name:"RdYlGn",invert:"always"},{name:"Spectral",invert:"always"},{name:"Blues",invert:"dark"},{name:"Greens",invert:"dark"},{name:"Greys",invert:"dark"},{name:"Oranges",invert:"dark"},{name:"Purples",invert:"dark"},{name:"Reds",invert:"dark"},{name:"Turbo",invert:"light"},{name:"Cividis",invert:"light"},{name:"Viridis",invert:"light"},{name:"Magma",invert:"light"},{name:"Inferno",invert:"light"},{name:"Plasma",invert:"light"},{name:"Warm",invert:"light"},{name:"Cool",invert:"light"},{name:"Cubehelix",invert:"light",name2:"CubehelixDefault"},{name:"BuGn",invert:"dark"},{name:"BuPu",invert:"dark"},{name:"GnBu",invert:"dark"},{name:"OrRd",invert:"dark"},{name:"PuBuGn",invert:"dark"},{name:"PuBu",invert:"dark"},{name:"PuRd",invert:"dark"},{name:"RdPu",invert:"dark"},{name:"YlGnBu",invert:"dark"},{name:"YlGn",invert:"dark"},{name:"YlOrBr",invert:"dark"},{name:"YlOrRd",invert:"dark"},{name:"Rainbow",invert:"always"},{name:"Sinebow",invert:"always"}],mt=Me.find(e=>e.name==="Spectral");function Re(e,a){const t={...L.color,...e},d=[],l=(t.steps??128)-1;if(e.mode===ie.Opacity){const n=(0,Qe.Z)(a.visualization.getColorByName(e.fill)).toPercentageRgb(),c=t.scale===ve.Exponential?Je.scalePow().exponent(t.exponent).domain([0,1]).range([0,1]):Je.scaleLinear().domain([0,1]).range([0,1]);for(let u=0;u<=l;u++)n.a=c(u/l),d.push((0,Qe.Z)(n).toString("hex8"))}else{const n=Me.find(S=>S.name===t.scheme)??mt;let c="interpolate"+(n.name2??n.name);const u=dt[c];for(let S=0;S<=l;S++){let o=u(S/l),y=o.indexOf("rgb")===0?"#"+[...o.matchAll(/\d+/g)].map($=>(+$[0]).toString(16).padStart(2,"0")).join(""):o;d.push(y)}(n.invert==="always"||n.invert==="dark"&&a.isDark||n.invert==="light"&&a.isLight)&&d.reverse(),e.reverse&&d.reverse()}return d}const ft=({data:e,id:a,timeRange:t,timeZone:d,width:l,height:n,options:c,fieldConfig:u,eventBus:S,onChangeTimeRange:o,replaceVariables:y})=>{const $=(0,oe.l4)(),k=(0,oe.wW)(ht),{sync:H}=(0,ue.R9)();let _=[];for(const b of e.series)for(const s of b.fields)s.state?.scopedVars&&_.push(s.state.scopedVars);let j=(0,f.useRef)(t);j.current=t;const Z=(0,f.useCallback)((b,s)=>(0,ye.oB)(b,s,s.state?.scopedVars??{},y),[y]),w=(0,f.useMemo)(()=>Re(c.color,$),[c.color,$]),x=(0,f.useMemo)(()=>{try{return We(e.series,e.annotations,c,w,$,Z,y)}catch(b){return{warning:`${b}`}}},[e.series,e.annotations,c,w,$,Z,y]),O=(0,f.useMemo)(()=>{let b=[],s=[];const M=(0,I.d8)(x.heatmap);return x.exemplars?.length&&M.yMatchWithLabel&&(b=x.exemplars?.fields[0].values,M.yOrdinalDisplay!=null?s=(x.exemplars?.fields.find(P=>P.name===M.yMatchWithLabel).values).map(P=>M.yOrdinalLabel?.indexOf(P)):s=x.exemplars?.fields[1].values),[null,x.heatmap?.fields.map(D=>D.values),[b,s]]},[x.heatmap,x.exemplars]),[B,J]=(0,f.useState)(void 0),[V,F]=(0,f.useState)(!1),E=(0,f.useRef)(!1),R=()=>{E.current=!1,F(!1),A(null)},ee=()=>{E.current=!E.current,F(E.current)},A=(0,f.useCallback)(b=>{J(b??void 0)},[c,e.structureRev]),z=(0,f.useRef)(x);z.current=x;const Y=(0,f.useMemo)(()=>{const b=z.current?.heatmap?.fields[1].config?.custom?.scaleDistribution;return it({dataRef:z,theme:$,eventBus:S,onhover:A,onclick:c.tooltip.show?ee:null,onzoom:s=>{s.xMax-s.xMin>1&&o({from:s.xMin,to:s.xMax})},isToolTipOpen:E,timeZone:d,getTimeRange:()=>j.current,sync:H,cellGap:c.cellGap,hideLE:c.filterValues?.le,hideGE:c.filterValues?.ge,exemplarColor:c.exemplars?.color??"rgba(255,0,255,0.7)",yAxisConfig:c.yAxis,ySizeDivisor:b?.type===i.wf.Log?+(c.calculation?.yBuckets?.value||1):1})},[c,d,e.structureRev]),Q=()=>{if(!x.heatmap||!c.legend.show)return null;let M=z.current?.heatmap?.meta?.type===ne.P.HeatmapCells&&!(0,I.qJ)(z.current?.heatmap)?3:2;const D=x.heatmap.fields[M];let T;return B&&x.heatmap.fields&&B.seriesIdx===1&&(T=D.values[B.dataIdx]),f.createElement(re.AY.Legend,{placement:"bottom",maxHeight:"20%"},f.createElement("div",{className:k.colorScaleWrapper},f.createElement(ae.q,{hoverValue:T,colorPalette:w,min:z.current.heatmapColors?.minValue,max:z.current.heatmapColors?.maxValue,display:x.display})))};return x.warning||!x.heatmap?f.createElement(ce.Z,{panelId:a,fieldConfig:u,data:e,needsNumberField:!0,message:x.warning}):f.createElement(f.Fragment,null,f.createElement(re.AY,{width:l,height:n,legend:Q()},(b,s)=>f.createElement(be.N,{config:Y,data:O,width:b,height:s})),f.createElement(ze.h_,null,B&&c.tooltip.show&&f.createElement(de.S,{position:{x:B.pageX,y:B.pageY},offset:{x:10,y:10},allowPointerEvents:E.current},V&&f.createElement(Te.o,{onClick:R}),f.createElement(et,{timeRange:t,data:x,hover:B,showHistogram:c.tooltip.yHistogram,replaceVars:y,scopedVars:_}))))},ht=e=>({colorScaleWrapper:(0,se.css)`
    margin-left: 25px;
    padding: 10px 0;
    max-width: 300px;
  `}),pt=e=>Object.keys(e.options).length===0?Xe(e,"heatmap",{angular:e},e.fieldConfig):e.options,Xe=(e,a,t,d)=>{if(a==="heatmap"&&t.angular){const{fieldConfig:l,options:n}=xt({...t.angular,fieldConfig:d});return e.fieldConfig=l,n}if(a==="heatmap-new"){const{bucketFrame:l,...n}=e.options;return l?{...n,rowsFrame:l}:e.options}return{}};function xt(e){const a={defaults:{},overrides:[]},t=e.dataFormat!=="tsbuckets",d={...L.calculation},l={logBase:1,...e.yAxis};t&&(e.xBucketSize?d.xBuckets={mode:i.kW.Size,value:`${e.xBucketSize}`}:e.xBucketNumber&&(d.xBuckets={mode:i.kW.Count,value:`${e.xBucketNumber}`}),e.yBucketSize?d.yBuckets={mode:i.kW.Size,value:`${e.yBucketSize}`}:e.xBucketNumber&&(d.yBuckets={mode:i.kW.Count,value:`${e.yBucketNumber}`}),l.logBase>1&&(d.yBuckets={mode:i.kW.Count,value:+l.splitFactor>0?`${l.splitFactor}`:void 0,scale:{type:i.wf.Log,log:l.logBase}}));const n=Ae(e.cards?.cardPadding,2),c={calculate:t,calculation:d,color:{...L.color,steps:128},cellGap:n||1,cellRadius:Ae(e.cards?.cardRound),yAxis:{axisPlacement:l.show===!1?i.LB.Hidden:i.LB.Left,reverse:!!e.reverseYBuckets,axisWidth:Ae(l.width),min:l.min,max:l.max,unit:l.format,decimals:l.decimals},cellValues:{decimals:Ae(e.tooltipDecimals)},rowsFrame:{layout:yt(e.yBucketBound)},legend:{show:!!e.legend?.show},showValue:i.Jp.Never,tooltip:{show:!!e.tooltip?.show,yHistogram:!!e.tooltip?.showHistogram},exemplars:{...L.exemplars}};e.hideZeroBuckets&&(c.filterValues={...L.filterValues});const u=e.color??{};switch(u?.mode){case"spectrum":{c.color.mode=ie.Scheme;const S=u.colorScheme;let o=Me.find(y=>y.name===S);o||(o=Me.find(y=>S.indexOf(y.name)>=0)),c.color.scheme=o?o.name:L.color.scheme;break}case"opacity":{c.color.mode=ie.Opacity,c.color.scale=u.scale;break}}return c.color.fill=u.cardColor,c.color.min=u.min,c.color.max=u.max,typeof u.min=="number"&&typeof u.max=="number"&&u.min>u.max&&(c.color.min=u.max,c.color.max=u.min,c.color.reverse=!0),{fieldConfig:a,options:c}}function yt(e){switch(e){case"upper":return i.kv.ge;case"lower":return i.kv.le;case"middle":return i.kv.unknown}return i.kv.auto}function Ae(e,a){if(e==null||e==="")return a;const t=+e;return isNaN(t)?a:t}class gt{getSuggestionsForData(a){const{dataSummary:t}=a;if(!a.data?.series||!t.hasData||t.timeFieldCount<1||t.numberFieldCount<2||t.numberFieldCount>10)return;const d=Re(L.color,fe.config.theme2),l=We(a.data.series,void 0,L,d,fe.config.theme2);!l||l.warning||a.getListAppender({name:"",pluginId:"heatmap",options:{},fieldConfig:{defaults:{custom:{}},overrides:[]}})}}const vt=new X.c(ft).useFieldConfig({disableStandardOptions:Object.values(Le.qb).filter(e=>e!==Le.qb.Links),useCustomConfig:e=>{e.addCustomEditor({id:"scaleDistribution",path:"scaleDistribution",name:"Y axis scale",category:["Heatmap"],editor:Ee.Y,override:Ee.Y,defaultValue:{type:i.wf.Linear},shouldApply:a=>a.type===me.fS.number,process:Fe.kG,hideFromDefaults:!0}),(0,q.B)(e)}}).setPanelChangeHandler(Xe).setMigrationHandler(pt).setPanelOptions((e,a)=>{const t=a.options??L;let d=!1;if(a.data.length>0)try{const n=Re(t.color,fe.config.theme2),c=We(a.data,void 0,t,n,fe.config.theme2,void 0,a.replaceVariables);d=(0,I.d8)(c.heatmap).yOrdinalDisplay!=null}catch{}let l=["Heatmap"];e.addRadio({path:"calculate",name:"Calculate from data",defaultValue:L.calculate,category:l,settings:{options:[{label:"Yes",value:!0},{label:"No",value:!1}]}}),t.calculate&&(0,he.J)("calculation.",e,t.calculation,l),l=["Y Axis"],e.addRadio({path:"yAxis.axisPlacement",name:"Placement",defaultValue:L.yAxis.axisPlacement??i.LB.Left,category:l,settings:{options:[{label:"Left",value:i.LB.Left},{label:"Right",value:i.LB.Right},{label:"Hidden",value:i.LB.Hidden}]}}).addUnitPicker({category:l,path:"yAxis.unit",name:"Unit",defaultValue:void 0,settings:{isClearable:!0}}).addNumberInput({category:l,path:"yAxis.decimals",name:"Decimals",settings:{placeholder:"Auto"}}),d||e.addNumberInput({path:"yAxis.min",name:"Min value",settings:{placeholder:"Auto"},category:l}).addTextInput({path:"yAxis.max",name:"Max value",settings:{placeholder:"Auto"},category:l}),e.addNumberInput({path:"yAxis.axisWidth",name:"Axis width",defaultValue:L.yAxis.axisWidth,settings:{placeholder:"Auto",min:5},category:l}).addTextInput({path:"yAxis.axisLabel",name:"Axis label",defaultValue:L.yAxis.axisLabel,settings:{placeholder:"Auto"},category:l}),t.calculate||e.addRadio({path:"rowsFrame.layout",name:"Tick alignment",defaultValue:L.rowsFrame?.layout??i.kv.auto,category:l,settings:{options:[{label:"Auto",value:i.kv.auto},{label:"Top (LE)",value:i.kv.le},{label:"Middle",value:i.kv.unknown},{label:"Bottom (GE)",value:i.kv.ge}]}}),e.addBooleanSwitch({path:"yAxis.reverse",name:"Reverse",defaultValue:L.yAxis.reverse===!0,category:l}),l=["Colors"],e.addRadio({path:"color.mode",name:"Mode",defaultValue:L.color.mode,category:l,settings:{options:[{label:"Scheme",value:ie.Scheme},{label:"Opacity",value:ie.Opacity}]}}),e.addColorPicker({path:"color.fill",name:"Color",defaultValue:L.color.fill,category:l,showIf:n=>n.color.mode===ie.Opacity}),e.addRadio({path:"color.scale",name:"Scale",defaultValue:L.color.scale,category:l,settings:{options:[{label:"Exponential",value:ve.Exponential},{label:"Linear",value:ve.Linear}]},showIf:n=>n.color.mode===ie.Opacity}),e.addSliderInput({path:"color.exponent",name:"Exponent",defaultValue:L.color.exponent,category:l,settings:{min:.1,max:2,step:.1},showIf:n=>n.color.mode===ie.Opacity&&n.color.scale===ve.Exponential}),e.addSelect({path:"color.scheme",name:"Scheme",description:"",defaultValue:L.color.scheme,category:l,settings:{options:Me.map(n=>({value:n.name,label:n.name}))},showIf:n=>n.color.mode!==ie.Opacity}),e.addSliderInput({path:"color.steps",name:"Steps",defaultValue:L.color.steps,category:l,settings:{min:2,max:128,step:1}}).addBooleanSwitch({path:"color.reverse",name:"Reverse",defaultValue:L.color.reverse,category:l}).addCustomEditor({id:"__scale__",path:"__scale__",name:"",category:l,editor:()=>{const n=Re(t.color,fe.config.theme2);return f.createElement("div",null,f.createElement(ae.q,{colorPalette:n,min:1,max:100}))}}),e.addNumberInput({path:"color.min",name:"Start color scale from value",defaultValue:L.color.min,settings:{placeholder:"Auto (min)"},category:l}).addNumberInput({path:"color.max",name:"End color scale at value",defaultValue:L.color.max,settings:{placeholder:"Auto (max)"},category:l}),l=["Cell display"],t.calculate||e.addTextInput({path:"rowsFrame.value",name:"Value name",defaultValue:L.rowsFrame?.value,settings:{placeholder:"Value"},category:l}),e.addUnitPicker({category:l,path:"cellValues.unit",name:"Unit",defaultValue:void 0,settings:{isClearable:!0}}).addNumberInput({category:l,path:"cellValues.decimals",name:"Decimals",settings:{placeholder:"Auto"}}),e.addSliderInput({name:"Cell gap",path:"cellGap",defaultValue:L.cellGap,category:l,settings:{min:0,max:25}}).addNumberInput({path:"filterValues.le",name:"Hide cells with values <=",defaultValue:L.filterValues?.le,settings:{placeholder:"None"},category:l}).addNumberInput({path:"filterValues.ge",name:"Hide cells with values >=",defaultValue:L.filterValues?.ge,settings:{placeholder:"None"},category:l}),l=["Tooltip"],e.addBooleanSwitch({path:"tooltip.show",name:"Show tooltip",defaultValue:L.tooltip.show,category:l}),e.addBooleanSwitch({path:"tooltip.yHistogram",name:"Show histogram (Y axis)",defaultValue:L.tooltip.yHistogram,category:l,showIf:n=>n.tooltip.show}),l=["Legend"],e.addBooleanSwitch({path:"legend.show",name:"Show legend",defaultValue:L.legend.show,category:l}),l=["Exemplars"],e.addColorPicker({path:"exemplars.color",name:"Color",defaultValue:L.exemplars.color,category:l})}).setSuggestionsSupplier(new gt)}}]);

//# sourceMappingURL=heatmapPanel.e4138b2560d01e083c21.js.map