"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5882],{95882(P,F,f){f.d(F,{getPartitionByValuesTransformer:()=>h,o:()=>y});var b=f(2543),S=f(81160),$=f(19560),B=f(69192),V=f(72830),E=f(25496),L=f(97836),c=f(52358);const g=(e,r,a=[])=>(r===0?a.push(e):e.forEach(n=>{g(n,r-1,a)}),a);function T(e){const r=e[0].length,a=e.length,n=new Map;for(let s=0;s<r;s++){let i=n;for(let l=0;l<a;l++){let t=e[l][s],o=i.get(t);o==null&&(o=l===a-1?[]:new Map,i.set(t,o)),i=o}i.push(s)}return g(n,a)}const C={asLabels:!0,append:!1,withNames:!1,separator1:"=",separator2:" "};function D(e,r,a){return r.map((n,s)=>e.withNames?`${n}${e.separator1}${a[s]}`:a[s]).join(e.separator2)}function M(e,r){const a={};return e.forEach((n,s)=>{a[n]=String(r[s])}),a}const h=()=>({id:$.F.partitionByValues,name:(0,c.t)("transformers.get-partition-by-values-transformer.name.partition-by-values","Partition by values"),description:(0,c.t)("transformers.get-partition-by-values-transformer.description.split-oneframe-dataset-multiple-series","Split a one-frame dataset into multiple series."),defaultOptions:{keepFields:!1},operator:(e,r)=>a=>a.pipe((0,S.T)(n=>h().transformer(e,r)(n))),transformer:(e,r)=>{const a=(0,E.R)({names:e.fields});if(!a)return L.W.transformer({},r);const n=(0,B.NS)(a);return s=>s.length?y(s[0],n,e):s}});function O(e,r,a){const n=e.fields.filter(t=>r(t,e,[e]));if(!n.length)return[e];const s=n.map(t=>t.values),i=n.map(t=>t.name),l={...C,...a?.naming};return T(s).map(t=>{let o=e.name,N={};if(l.asLabels)N=M(i,n.map((m,p)=>s[p][t[0]]));else{let m=D(l,i,n.map((p,u)=>s[u][t[0]]));l?.append&&e.name&&(m=`${e.name} ${m}`),o=m}let v=e.fields;if(!a?.keepFields){const m=new Set(i);v=e.fields.filter(p=>!m.has(p.name))}return{name:o,refId:`${e.refId}-${o}`,meta:e.meta,length:t.length,fields:v.map(m=>{const p=m.values,u=Array(t.length);for(let d=0;d<t.length;d++)u[d]=p[t[d]];return{name:m.name,type:m.type,config:(0,b.cloneDeep)(m.config),labels:{...m.labels,...N},values:u}})}})}function y(e,r,a){let n={},s={...e,fields:e.fields.map(l=>{let t=l,o=l.config.displayNameFromDS??l.config.displayName;return o&&(t={...l,config:{...l.config},state:{...l.state}},n[o]=l.name,t.name=o,delete t.config.displayName,delete t.config.displayNameFromDS,delete t.state?.displayName),t})},i=O(s,r,a);return(0,V.Fm)(i),i.forEach(l=>{l.fields.forEach(t=>{t.name in n&&(t.name=n[t.name]??t.name,t.config.displayName=t.state.displayName),delete t.state?.displayName,delete t.state?.multipleFrames})}),i}}}]);

//# sourceMappingURL=5882.57262d03cd88c3cfc3f0.js.map