(self.webpackChunkibis_vega_transform=self.webpackChunkibis_vega_transform||[]).push([[707],{2707:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>x});var i=n(8751),a=n(6510),s=n(3398),r=n.n(s),o=n(1797),c=n(1614),l=n(4515),d=n(6658),p=n(9340),u=n(640),h=n(9672);class f extends h.c{mapUnit(e,{config:t}){if(e.encoding){const{encoding:n,transform:i}=e,{bins:a,timeUnits:s,aggregate:r,groupby:o,encoding:c}=(0,u.Hn)(n,t),l=[...i||[],...a,...s,...0===r.length?[]:[{aggregate:r,groupby:o}]];return Object.assign(Object.assign(Object.assign({},e),l.length>0?{transform:l}:{}),{encoding:c})}return e}}const g=new f;var m=n(5114),w=n(4036),_=n(9246);function v(e){const t={};for(const n in e){const i=e[n];let a;"string"==typeof i?(a=Date.parse(e[n]),isNaN(a)&&(a=i)):a=i,t[n]=a}return t}class b extends w.wx{constructor(e){super([],e),this._state={state:"initial"}}transform(e,t){return"fetched"===this._state.state?this.output(t,this._state.data):("fetching"===this._state.state&&(this._state.aborted=!0),this._state={state:"fetching",aborted:!1},{async:async function(e,t){const{tracing:n,kernel:i}=b;if(!i)throw new Error("Not connected to any kernel");const a=n?await _.client.startSpanExtract({name:"transform",relationship:"follows_from",reference:e.span}):null,s=async()=>{n&&await _.client.finishSpan(a)};if(t.aborted)return await s(),null;const r=i.createComm("queryibis"),c=new o.PromiseDelegate;if(r.onMsg=e=>c.resolve(e.content.data),n&&(e=Object.assign(Object.assign({},e),{span:await _.client.injectSpan(a)})),t.aborted)return await s(),null;if(await r.open(e).done,t.aborted)return await s(),null;const l=await c.promise;if(t.aborted)return await s(),null;const d=l.map(v);return await s(),t.aborted?null:d}(e,this._state).then((e=>e?(this._state={state:"fetched",data:e},e=>e.touch(this)):()=>{}))})}output(e,t){t.forEach(w.ax);const n=e.fork(e.NO_FIELDS&e.NO_SOURCE);return n.rem=this.value,this.value=n.source=n.add=t,this._state={state:"initial"},n}}b.Definition={type:"QueryIbis",metadata:{changes:!0,source:!0},params:[{name:"name",type:"string",required:!0},{name:"data",type:"expr",required:!1},{name:"transform",type:"transform",array:!0,required:!1},{name:"span",type:"object",required:!1}]};const S=b;m.transforms.queryibis=b;const y="application/vnd.vega.ibis.v5+json";class k extends a.Widget{constructor(e,t){super(),this.getKernel=e,this.tracing=t,this._isDisposed=!1,this._view=null,this._renderingSpec=!1,this._renderedSpec=null}async renderModel(e){const{spec:t,span:n}=e.data[y],{tracing:i}=this;let a=i?await _.client.startSpanExtract({name:"renderModel",reference:n,relationship:"follows_from"}):null;const s=await this.getKernel();if(!s)return;if(this._renderingSpec||this._renderedSpec&&JSON.stringify(this._renderedSpec)===JSON.stringify(t))return;this._renderingSpec=!0,this._view&&(this._view.finalize(),this._view=null);const u=i?await _.client.startSpan({name:"compileSpec",reference:a,relationship:"child_of"}):null,h=await async function(e,t,n,i){var a,s;const r=null===(s=null===(a=t.usermeta)||void 0===a?void 0:a.embedOptions)||void 0===s?void 0:s.theme;r&&(0,d.Ee)(t,p[r]);const u=(0,l.py)(t.config||{}),h=function(e,t){return g.map(e,{config:t})}((0,c.normalize)(t,u),u);console.log("Extracted Vega-Lite Spec",t);const f=(0,c.compile)(h,{config:u}).spec,m=new o.PromiseDelegate,w=e.createComm("ibis_vega_transform:compiler");return w.onMsg=e=>m.resolve(e.content.data),await w.open({spec:f,span:n,rootSpan:i}).done,await m.promise}(s,t,i?await _.client.injectSpan(u):n,n);i&&await _.client.finishSpan(u);const f=i?await _.client.startSpan({name:"vegaEmbed",reference:a,relationship:"child_of"}):null;S.kernel=s,S.tracing=i;const m=await r()(this.node,h,{actions:!0,defaultStyle:!0,mode:"vega"});this._view=m.view,i&&await _.client.finishSpan(f),this._renderingSpec=!1,this._renderedSpec=t,i&&await _.client.finishSpan(a)}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed=!0,this._view&&(this._view.finalize(),this._view=null)}}const x={activate:function(e,t){t.widgetAdded.connect(((e,t)=>{t.content.rendermime.addFactory({safe:!0,defaultRank:50,mimeTypes:[y],createRenderer:()=>new k((async()=>{var e;return null===(e=t.context.sessionContext.session)||void 0===e?void 0:e.kernel}),!0)},0)}))},id:"ibis_vega_transform:plugin",requires:[i.INotebookTracker],autoStart:!0}}}]);