import{textMetrics as N,Marks as oe}from"/-/vega-scenegraph@v4.13.0-kC2RziuM0eIjiq6SsQ1g/dist=es2020,mode=imports,min/optimized/vega-scenegraph.js";import{canvas as K}from"/-/vega-canvas@v1.2.7-hCEcvULuKIOqBVGX1Tn8/dist=es2020,mode=imports,min/optimized/vega-canvas.js";import{Transform as ne,rederive as fe}from"/-/vega-dataflow@v5.7.6-WDoszrJUyhTwz7sPwzda/dist=es2020,mode=imports,min/optimized/vega-dataflow.js";import{inherits as le,isFunction as ue,error as se,array as re}from"/-/vega-util@v1.17.2-LUfkDhormMyfWqy3Ts6U/dist=es2020,mode=imports,min/optimized/vega-util.js";const Q=4278190080;function me(e,i){const f=e.bitmap();return(i||[]).forEach(l=>f.set(e(l.boundary[0]),e(l.boundary[3]))),[f,void 0]}function ce(e,i,f,l,a){const n=e.width,t=e.height,m=l||a,M=K(n,t).getContext("2d"),r=K(n,t).getContext("2d"),s=m&&K(n,t).getContext("2d");f.forEach(y=>G(M,y,!1)),G(r,i,!1),m&&G(s,i,!0);const d=V(M,n,t),o=V(r,n,t),u=m&&V(s,n,t),c=e.bitmap(),b=m&&e.bitmap();let g,v,x,p,w,k,z,h;for(v=0;v{a.items.forEach(n=>G(e,n.items,f))}):oe[l].draw(e,{items:f?i.map(de):i})}function de(e){const i=fe(e,{});return i.stroke&&i.strokeOpacity!==0||i.fill&&i.fillOpacity!==0?{...i,strokeOpacity:1,stroke:"#000",fillOpacity:0}:i}const L=5,T=31,j=32,C=new Uint32Array(j+1),S=new Uint32Array(j+1);S[0]=0,C[0]=~S[0];for(let e=1;e<=j;++e)S[e]=S[e-1]<<1|1,C[e]=~S[e];function he(e,i){const f=new Uint32Array(~~((e*i+j)/j));function l(n,t){f[n]|=t}function a(n,t){f[n]&=t}return{array:f,get:(n,t)=>{const m=t*e+n;return f[m>>>L]&1<<(m&T)},set:(n,t)=>{const m=t*e+n;l(m>>>L,1<<(m&T))},clear:(n,t)=>{const m=t*e+n;a(m>>>L,~(1<<(m&T)))},getRange:(n,t,m,M)=>{let r=M,s,d,o,u;for(;r>=t;--r)if(s=r*e+n,d=r*e+m,o=s>>>L,u=d>>>L,o===u){if(f[o]&C[s&T]&S[(d&T)+1])return!0}else{if(f[o]&C[s&T])return!0;if(f[u]&S[(d&T)+1])return!0;for(let c=o+1;c{let r,s,d,o,u;for(;t<=M;++t)if(r=t*e+n,s=t*e+m,d=r>>>L,o=s>>>L,d===o)l(d,C[r&T]&S[(s&T)+1]);else for(l(d,C[r&T]),l(o,S[(s&T)+1]),u=d+1;u{let r,s,d,o,u;for(;t<=M;++t)if(r=t*e+n,s=t*e+m,d=r>>>L,o=s>>>L,d===o)a(d,S[r&T]|C[(s&T)+1]);else for(a(d,S[r&T]),a(o,C[(s&T)+1]),u=d+1;un<0||t<0||M>=i||m>=e}}function ye(e,i,f){const l=Math.max(1,Math.sqrt(e*i/1e6)),a=~~((e+2*f+l)/l),n=~~((i+2*f+l)/l),t=m=>~~((m+f)/l);return t.invert=m=>m*l-f,t.bitmap=()=>he(a,n),t.ratio=l,t.padding=f,t.width=e,t.height=i,t}function xe(e,i,f,l){const a=e.width,n=e.height;return function(t){const m=t.datum.datum.items[l].items,M=m.length,r=t.datum.fontSize,s=N.width(t.datum,t.datum.text);let d=0,o,u,c,b,g,v,x;for(let p=0;p=d&&(d=x,t.x=g,t.y=v);return g=s/2,v=r/2,o=t.x-g,u=t.x+g,c=t.y-v,b=t.y+v,t.align="center",o<0&&u<=a?t.align="left":0<=o&&aa||i-(t=l/2)<0||i+t>n}function U(e,i,f,l,a,n,t,m){const M=a*n/(l*2),r=e(i-M),s=e(i+M),d=e(f-(n=n/2)),o=e(f+n);return t.outOfBounds(r,d,s,o)||t.getRange(r,d,s,o)||m&&m.getRange(r,d,s,o)}function ge(e,i,f,l){const a=e.width,n=e.height,t=i[0],m=i[1];function M(r,s,d,o,u){const c=e.invert(r),b=e.invert(s);let g=d,v=n,x;if(!H(c,b,o,u,a,n)&&!U(e,c,b,u,o,g,t,m)&&!U(e,c,b,u,o,u,t,null)){for(;v-g>=1;)x=(g+v)/2,U(e,c,b,u,o,x,t,m)?v=x:g=x;if(g>d)return[c,b,g,!0]}}return function(r){const s=r.datum.datum.items[l].items,d=s.length,o=r.datum.fontSize,u=N.width(r.datum,r.datum.text);let c=f?o:0,b=!1,g=!1,v=0,x,p,w,k,z,h,y,E,A,O,R,B,P,I,D,F,q;for(let W=0;Wp&&(q=x,x=p,p=q),w>k&&(q=w,w=k,k=q),A=e(x),R=e(p),O=~~((A+R)/2),B=e(w),I=e(k),P=~~((B+I)/2),y=O;y>=A;--y)for(E=P;E>=B;--E)F=M(y,E,c,u,o),F&&([r.x,r.y,c,b]=F);for(y=O;y<=R;++y)for(E=P;E<=I;++E)F=M(y,E,c,u,o),F&&([r.x,r.y,c,b]=F);!b&&!f&&(D=Math.abs(p-x+k-w),z=(x+p)/2,h=(w+k)/2,D>=v&&!H(z,h,u,o,a,n)&&!U(e,z,h,o,u,o,t,null)&&(v=D,r.x=z,r.y=h,g=!0))}return b||g?(z=u/2,h=o/2,t.setRange(e(r.x-z),e(r.y-h),e(r.x+z),e(r.y+h)),r.align="center",r.baseline="middle",!0):!1}}const pe=[-1,-1,1,1],be=[-1,1,-1,1];function ve(e,i,f,l){const a=e.width,n=e.height,t=i[0],m=i[1],M=e.bitmap();return function(r){const s=r.datum.datum.items[l].items,d=s.length,o=r.datum.fontSize,u=N.width(r.datum,r.datum.text),c=[];let b=f?o:0,g=!1,v=!1,x=0,p,w,k,z,h,y,E,A,O,R,B,P;for(let I=0;I=1;)B=(O+R)/2,U(e,h,y,o,u,B,t,m)?R=B:O=B;O>b&&(r.x=h,r.y=y,b=O,g=!0)}}!g&&!f&&(P=Math.abs(w-p+z-k),h=(p+w)/2,y=(k+z)/2,P>=x&&!H(h,y,u,o,a,n)&&!U(e,h,y,o,u,o,t,null)&&(x=P,r.x=h,r.y=y,v=!0))}return g||v?(h=u/2,y=o/2,t.setRange(e(r.x-h),e(r.y-y),e(r.x+h),e(r.y+y)),r.align="center",r.baseline="middle",!0):!1}}const Me=["right","center","left"],Ae=["bottom","middle","top"];function we(e,i,f,l){const a=e.width,n=e.height,t=i[0],m=i[1],M=l.length;return function(r){const s=r.boundary,d=r.datum.fontSize;if(s[2]<0||s[5]<0||s[0]>a||s[3]>n)return!1;let o=r.textWidth??0,u,c,b,g,v,x,p,w,k,z,h,y,E,A,O;for(let R=0;R>>2&3)-1,b=u===0&&c===0||l[R]<0,g=u&&c?Math.SQRT1_2:1,v=l[R]<0?-1:1,x=s[1+u]+l[R]*u*g,h=s[4+c]+v*d*c/2+l[R]*c*g,w=h-d/2,k=h+d/2,y=e(x),A=e(w),O=e(k),!o)if(ie(y,y,A,O,t,m,x,x,w,k,s,b))o=N.width(r.datum,r.datum.text);else continue;if(z=x+v*o*u/2,x=z-o/2,p=z+o/2,y=e(x),E=e(p),ie(y,E,A,O,t,m,x,p,w,k,s,b))return r.x=u?u*v<0?p:x:z,r.y=c?c*v<0?k:w:h,r.align=Me[u*v+1],r.baseline=Ae[c*v+1],t.setRange(y,A,E,O),!0}return!1}}function ie(e,i,f,l,a,n,t,m,M,r,s,d){return!(a.outOfBounds(e,f,i,l)||(d&&n||a).getRange(e,f,i,l))}const X=0,J=4,Y=8,Z=0,_=1,$=2,ke={"top-left":X+Z,top:X+_,"top-right":X+$,left:J+Z,middle:J+_,right:J+$,"bottom-left":Y+Z,bottom:Y+_,"bottom-right":Y+$},ze={naive:xe,"reduced-search":ge,floodfill:ve};function Re(e,i,f,l,a,n,t,m,M,r,s){if(!e.length)return e;const d=Math.max(l.length,a.length),o=Ee(l,d),u=Oe(a,d),c=Te(e[0].datum),b=c==="group"&&e[0].datum.items[M].marktype,g=b==="area",v=Ie(c,b,m,M),x=r===null||r===Infinity,p=g&&s==="naive";let w=-1,k=-1;const z=e.map(A=>{const O=x?N.width(A,A.text):void 0;return w=Math.max(w,O),k=Math.max(k,A.fontSize),{datum:A,opacity:0,x:void 0,y:void 0,align:void 0,baseline:void 0,boundary:v(A),textWidth:O}});r=r===null||r===Infinity?Math.max(w,k)+Math.max(...l):r;const h=ye(i[0],i[1],r);let y;if(!p){f&&z.sort((R,B)=>f(R.datum,B.datum));let A=!1;for(let R=0;RR.datum);y=n.length||O?ce(h,O||[],n,A,g):me(h,t&&z)}const E=g?ze[s](h,y,t,M):we(h,y,u,o);return z.forEach(A=>A.opacity=+E(A)),z}function Ee(e,i){const f=new Float64Array(i),l=e.length;for(let a=0;a[n.x,n.x,n.x,n.y,n.y,n.y];return e?e==="line"||e==="area"?n=>a(n.datum):i==="line"?n=>{const t=n.datum.items[l].items;return a(t.length?t[f==="start"?0:t.length-1]:{x:NaN,y:NaN})}:n=>{const t=n.datum.bounds;return[t.x1,(t.x1+t.x2)/2,t.x2,t.y1,(t.y1+t.y2)/2,t.y2]}:a}const ee=["x","y","opacity","align","baseline"],ae=["top-left","left","bottom-left","top","bottom","top-right","right","bottom-right"];function te(e){ne.call(this,null,e)}te.Definition={type:"Label",metadata:{modifies:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"sort",type:"compare"},{name:"anchor",type:"string",array:!0,default:ae},{name:"offset",type:"number",array:!0,default:[1]},{name:"padding",type:"number",default:0,null:!0},{name:"lineAnchor",type:"string",values:["start","end"],default:"end"},{name:"markIndex",type:"number",default:0},{name:"avoidBaseMark",type:"boolean",default:!0},{name:"avoidMarks",type:"data",array:!0},{name:"method",type:"string",default:"naive"},{name:"as",type:"string",array:!0,length:ee.length,default:ee}]},le(te,ne,{transform(e,i){function f(n){const t=e[n];return ue(t)&&i.modified(t.fields)}const l=e.modified();if(!(l||i.changed(i.ADD_REM)||f("sort")))return;(!e.size||e.size.length!==2)&&se("Size parameter should be specified as a [width, height] array.");const a=e.as||ee;return Re(i.materialize(i.SOURCE).source||[],e.size,e.sort,re(e.offset==null?1:e.offset),re(e.anchor||ae),e.avoidMarks||[],e.avoidBaseMark!==!1,e.lineAnchor||"end",e.markIndex||0,e.padding===void 0?0:e.padding,e.method||"naive").forEach(n=>{const t=n.datum;t[a[0]]=n.x,t[a[1]]=n.y,t[a[2]]=n.opacity,t[a[3]]=n.align,t[a[4]]=n.baseline}),i.reflow(l).modifies(a)}});export{te as label};export default null;