@milaboratories/graph-maker 1.1.117 → 1.1.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91565,7 +91565,7 @@ var ZW = class GH {
91565
91565
  }
91566
91566
  getColumnCategories(t) {
91567
91567
  if (!this.columnNames.includes(t)) throw new Error(`Column ${t} does not exist`);
91568
- return dr.uniq(this.getColumn(t)).map(String);
91568
+ return dr.uniq(this.getColumn(t)).filter((n) => n !== null).map(String);
91569
91569
  }
91570
91570
  setGrouping(t) {
91571
91571
  let n = { grouped: {}, rows: this.rows }, r = [n];
@@ -15127,7 +15127,7 @@ void main() {
15127
15127
  ${k.x+k.width/2},
15128
15128
  ${k.y+k.height/2})`,children:ie.jsx("text",{transform:`rotate(${o.position==="left"?-90:90})`,dominantBaseline:"central",textAnchor:"middle",children:o.title})}),t&&ie.jsx("rect",{x:k.x,y:k.y,width:k.width,height:k.height,stroke:Vt,fill:"none"}),B&&ie.jsx("g",{fontSize:"14px",transform:`translate(${P.x},${P.y})`,children:r.map(I=>{let $=f.yAxisLabels!==0,N=o.position==="left",F=-(90-f.yAxisLabels),Z=f.yAxisLabels===0?"middle":N?"end":"start",ee=$?"central":N?"auto":"hanging",le=N?P.width:0,Q=N?le-g:le+g,j=N?Q-T3:Q+T3,U=a.y(I)+c/2;return ie.jsxs("g",{children:[ie.jsx("line",{x1:le,x2:Q,y1:U,y2:U,stroke:Vt}),ie.jsx("text",{x:j,y:U,textAnchor:Z,transform:`rotate(${F},${j},${U})`,dominantBaseline:ee,children:h[I]})]},I)})}),t&&ie.jsx("rect",{x:P.x,y:P.y,height:P.height,width:P.width,stroke:Vt,fill:"none"})]})]})}function l9t({sideElementBBoxes:e,debug:t,xKeys:n,yKeys:r,scales:a,xAxis:i,yAxis:o,stepX:s,stepY:c,xGroupKeys:f,yGroupKeys:A,xKeysByGroups:h,yKeysByGroups:v,labelAngles:g,xLabels:C,yLabels:b,xGroupLabels:x,yGroupLabels:B}){return ie.jsxs("g",{fontWeight:"500",children:[ie.jsx(o9t,{sideElementBBoxes:e,xKeys:n,yKeys:r,scales:a,xAxis:i,yAxis:o,stepX:s,stepY:c,labelAngles:g,xLabels:C,yLabels:b,debug:t}),ie.jsx(i9t,{sideElementBBoxes:e,xGroupKeys:f,yGroupKeys:A,xKeysByGroups:h,yKeysByGroups:v,xGroupLabels:x,yGroupLabels:B,scales:a,stepX:s,stepY:c,xAxis:i,yAxis:o,labelAngles:g,debug:t})]})}function oZ(e,t="top"){let{source:n,target:r}=e;return t==="top"||t==="bottom"?`M ${n.x},${n.y} L ${r.x},${n.y} L${r.x},${r.y}`:`M ${n.x},${n.y} L ${n.x},${r.y} L${r.x},${r.y}`}function lZ(e,t,n,r,a){if(!n)return"";let i=n.aes[e];if(!y9(i))return i;let o=i.value,s=a[o],c=r[o][t.data.keys[0]];return t.data.keys.every(f=>c===r[o][f])?s(String(c))[e]:s.unknown()[e]}var sZ={x:0,y:0,width:0,height:0};function s9t({dendrograms:e,sideElementBBoxes:t,xDataByKeys:n,yDataByKeys:r,aesScales:a}){let i=e.x.data,o=e.y.data,s=i?t[i.position].dendro:sZ,c=o?t[o.position].dendro:sZ;function f(h,v){return lZ(h,v,i,n,a)}function A(h,v){return lZ(h,v,o,r,a)}return ie.jsxs("g",{children:[ie.jsx("g",{transform:`translate(${s.x},${s.y})`,children:i&&!i.hidden&&e.x.trees.map((h,v)=>{let g=h.links(),C=h.descendants();return ie.jsxs("g",{children:[g.map(b=>{let x=i.edgeInheritance==="up"?b.source:b.target;return ie.jsx("path",{d:oZ(b,i.position),stroke:f("lineColor",x),strokeWidth:f("lineWidth",x),strokeDasharray:Of(f("lineShape",x)),fill:"none"},`${b.source.x},${b.source.y},${b.target.x},${b.target.y}`)}),i.showNodes&&C.map(b=>ie.jsx("g",{transform:`translate(${b.x},${b.y})`,children:Yc(f("dotShape",b),f("dotSize",b),f("dotFill",b))},`${b.x},${b.y}`))]},v)})}),ie.jsx("g",{transform:`translate(${c.x},${c.y})`,children:o&&!o.hidden&&e.y.trees.map((h,v)=>{let g=h.links(),C=h.descendants();return ie.jsxs("g",{children:[g.map(b=>{let x=o.edgeInheritance==="up"?b.source:b.target;return ie.jsx("path",{d:oZ(b,o.position),stroke:A("lineColor",x),strokeWidth:A("lineWidth",x),strokeDasharray:Of(A("lineShape",x)),fill:"none"},`${b.source.x},${b.source.y},${b.target.x},${b.target.y}`)}),o.showNodes&&C.map(b=>ie.jsx("g",{transform:`translate(${b.x},${b.y})`,children:Yc(A("dotShape",b),A("dotSize",b),A("dotFill",b))},`${b.x},${b.y}`))]},v)})})]})}function u9t({frame:e,width:t,height:n,xGroupKeys:r,yGroupKeys:a,xKeysByGroups:i,yKeysByGroups:o,scales:s,stepX:c,stepY:f}){return ie.jsxs("g",{children:[e.type==="full"&&ie.jsx("rect",{fill:"none",stroke:Vt,x:"0",y:"0",width:t,height:n}),e.type==="groups"&&r.map(A=>{let h=i[A].length;if(h===0)return null;let v=h*c,g=s.x(i[A][0]);return a.map(C=>{let b=o[C].length;if(b===0)return null;let x=b*f,B=s.y(o[C][0]);return ie.jsx("rect",{x:g,y:B,width:v,height:x,stroke:Vt,fill:"none"},`${g}_${B}`)})})]})}function jM(e){if(e===null)return"null";if(typeof e=="number"){let t=e>0?Math.floor(e):Math.ceil(e),n=e-t;return t+Number(n.toPrecision(2))}return e}function c9t(e,t,n=[]){let r=e.data,a=[`X: ${t.xLabels[e.x]}`,`Y: ${t.yLabels[e.y]}`,`Value: ${jM(e.value)}${e.value!==e.normalizedValue?` (${jM(e.normalizedValue)})`:""}`];for(let i of n)a.push(`${i.label}: ${r[i.valueLabels??i.value]}`);return a}function f9t(e,t){let n=[];return e.xKey&&n.push(`X: ${t.xLabels[e.xKey]}`),e.yKey&&n.push(`Y: ${t.yLabels[e.yKey]}`),n.push(`${e.title}: ${jM(e.value)}`),n}function d9t(e){return e!==null&&!("data"in e)}function uZ(e){return e!==null&&"data"in e}function A9t({dendrograms:e,facetKey:t,dimensions:n,scales:r,cells:a,xGroupKeys:i,yGroupKeys:o,xKeysByGroups:s,yKeysByGroups:c,colorScale:f,chartSettings:A,cellsMeta:h,stepX:v,stepY:g,sharedX:C,sharedY:b,annotations:x,annotationColorScales:B,dendrogramAesScales:k,aes:P,labelAngles:I,chartSizes:$,margins:N,tooltipsContainer:F,tooltipsData:Z}){let[ee,le]=tn.useState(),{xAxis:Q,yAxis:j,tooltips:U}=A,{width:Y,height:X}=n.inner,{padding:te,chartEdgeSides:pe,sideElementBBoxes:ae}=n,{xGroupLabels:ge,yGroupLabels:me,xLabels:fe,yLabels:Ce}=h,De=r.x.domain(),ke=r.y.domain(),$e={left:N.left+n.left+te.left,right:$.totalWidth-(N.left+n.left+te.left),top:N.top+n.top+te.top,bottom:$.totalHeight-(N.top+n.top+te.top)},je=!1,Oe=ee&&Z.fixed;return ie.jsxs("g",{transform:`translate(${n.left},${n.top})`,fontSize:X7t,children:[ie.jsxs("g",{transform:`translate(${te.left},${te.top})`,children:[ie.jsx(a9t,{facetKey:t,sideElementBBoxes:ae,annotations:x,cellsMeta:h,annotationColorScales:B,sharedX:C,sharedY:b,chartEdgeSides:pe,width:Y,height:X,scales:r,stepX:v,stepY:g,aes:P,frame:A.frame,xGroupKeys:i,yGroupKeys:o,xKeysByGroups:s,yKeysByGroups:c,tooltipsData:Z,activeElementContainer:ee}),ie.jsx(s9t,{dendrograms:e,sideElementBBoxes:ae,xDataByKeys:h.xDataByKeys,yDataByKeys:h.yDataByKeys,aesScales:k}),ae.top.facetTitle.isVisible&&ie.jsx("text",{x:ae.top.facetTitle.x,y:ae.top.facetTitle.y+ae.top.facetTitle.height-W7t,fontWeight:"500",fontSize:"20px",children:h.facetKeyValues[t].join(", ")}),je,De.map(ft=>ke.map(ze=>{var gt;let Xe=(gt=a==null?void 0:a[ft])==null?void 0:gt[ze],tt=Oe&&uZ(Z.selectedData)&&(Xe==null?void 0:Xe.id)===Z.selectedData.id,qe=Xe?ie.jsx("rect",{x:r.x(ft),y:r.y(ze),width:v,height:g,stroke:P.cellStrokeColor,fill:Xe.value===null?P.emptyCellColor:f(Xe.normalizedValue),onMouseOver:()=>Z.onMouseOver(Xe,t),onMouseLeave:()=>Z.onMouseLeave()},Xe?Xe.id:`${ft}_${ze}`):null;return tt?cu.createPortal(qe,ee):qe})),ie.jsx(u9t,{frame:A.frame,xGroupKeys:i,yGroupKeys:o,xKeysByGroups:s,yKeysByGroups:c,scales:r,stepX:v,stepY:g,width:Y,height:X}),ie.jsx(l9t,{xAxis:Q,yAxis:j,scales:r,stepX:v,stepY:g,debug:je,sideElementBBoxes:ae,xKeys:De,yKeys:ke,xGroupKeys:i,yGroupKeys:o,xKeysByGroups:s,yKeysByGroups:c,xGroupLabels:ge,yGroupLabels:me,labelAngles:I,xLabels:fe,yLabels:Ce})]}),A.tooltips.show&&uZ(Z.selectedData)&&Z.currentFacet===t&&ie.jsx(fu,{content:c9t(Z.selectedData,h,U==null?void 0:U.content),x:r.x(String(Z.selectedData.x))+v/2,y:r.y(String(Z.selectedData.y))+g/2,offset:De.length>1?v/2:0,active:!0,sideDistances:$e,fixed:Z.fixed,onClose:Z.onClose,container:F}),A.tooltips.show&&d9t(Z.selectedData)&&Z.currentFacet===t&&ie.jsx(fu,{content:f9t(Z.selectedData,h),x:Z.selectedData.x,y:Z.selectedData.y,offset:0,active:!0,sideDistances:$e,fixed:Z.fixed,onClose:Z.onClose,container:F}),ie.jsxs("g",{transform:`translate(${te.left},${te.top})`,children:[Z.fixed&&ie.jsx("rect",{width:$.chartWidth,height:$.chartHeight,fill:"rgba(255, 255, 255, 0.8)"}),ie.jsx("g",{ref:ft=>{ft&&!ee&&le(ft)}})]})]})}function h9t({margins:e,captionsSizes:t,settingsId:n,chartSettings:r,chartSizes:a,chartsDimensions:i,facetKeys:o,facetSettings:s,xGroupKeys:c,yGroupKeys:f,scales:A,colorScale:h,groupedCells:v,cellsMeta:g,step:C,annotations:b,annotationColorScales:x,legend:B,aes:k,dendrograms:P,dendrogramAesScales:I,columnsCount:$,labelAngles:N,onTooltipHintSwitch:F}){let[Z,ee]=tn.useState(),le=p3(F),Q=tn.useRef(null);tn.useEffect(()=>{Q.current&&ee(Q.current)},[]);let j=i[o[0]].padding,U=i[o[$-1]].padding,Y=e.left+a.chartsWidth+FM,X=e.top+j.top;return ie.jsx(y3,{dataId:n,children:ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${a.totalWidth} ${a.totalHeight}`,width:a.totalWidth,height:a.totalHeight,fontFamily:"Manrope",children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${e.left},${e.top})`,children:[ie.jsx(w3,{title:[r.title.name],show:r.title.show,position:r.title.position,leftPadding:j.left,rightPadding:U.right,chartsWidth:a.chartsWidth}),o.map(te=>{let{cells:pe,xKeysByGroups:ae,yKeysByGroups:ge}=v[te];return ie.jsx(A9t,{dendrograms:P[te],captionsSizes:t,facetKey:te,dimensions:i[te],xGroupKeys:c,yGroupKeys:f,xKeysByGroups:s.sharedX?g.xKeysByGroups:ae,yKeysByGroups:s.sharedY?g.yKeysByGroups:ge,sharedX:s.sharedX,sharedY:s.sharedY,scales:{x:A.x[te],y:A.y[te]},cells:pe,cellsMeta:g,stepX:C.x[te],stepY:C.y[te],colorScale:h,chartSettings:r,aes:k,annotations:b,annotationColorScales:x,dendrogramAesScales:I,labelAngles:N,margins:e,chartSizes:a,tooltipsContainer:Z,tooltipsData:le},te)})]}),ie.jsx("g",{transform:`translate(${Y},${X})`,children:ie.jsx(b3,{legendData:B})}),ie.jsx("g",{ref:Q,style:{outline:"none"}})]})})}function cZ(e,t,n){function r(a){a[n]=t(a.data.height),a.children&&a.children.forEach(r)}r(e)}function fZ(e,t,n,r=n){function a(i){i[r]=i[n]+t,i.children&&i.children.forEach(a)}a(e)}var p9t=(e,t)=>{let n=Math.min(...t),r=Math.max(...t);if(n===r){let o=e%2===0?[]:[n];for(let s=1;s<e/2+1;s++)o.push(n+s),o.unshift(n-s);return o}if(e<2)return[n,r];let a=(r-n)/(e-1),i=[];for(let o=0;o<e-1;o++)i.push(n+a*o);return i.push(r),i};function dZ(e,t,n){let r=n;return e&&(e.colorRange&&(r=e.colorRange),e.method==="standardScaling"&&(r=[-2,2]),e.method==="meanNormalization"&&(r=[-.75,.75])),p9t(t,r)}var v9t=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"component",ie.jsx(ie.Fragment,{}));Be(this,"chartsDimensions",{});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,chartsWidth:600,chartsHeight:350,totalWidth:600,totalHeight:350});Be(this,"margins",{top:Uv,bottom:Uv,left:Uv,right:Uv});Be(this,"captionsSizes",{xAxisCaptions:100,yAxisCaptions:100,xGroupCaptions:Gv,yGroupCaptions:Gv,xCaptionTail:0,yCaptionTail:0});Be(this,"labelAngles",{xAxisLabels:0,yAxisLabels:0,xGroupLabels:0,yGroupLabels:0});Be(this,"columnsCount",1);Be(this,"rowsCount",1);Be(this,"scales",{x:{null:Qo().domain(["null"]).range([1])},y:{null:Qo().domain(["null"]).range([1])}});Be(this,"step",{x:{},y:{}});Be(this,"colorScale",Zr().domain([0,1]).range(["white","black"]));Be(this,"annotationColorScales",{});Be(this,"dendrogramAesScales",{});Be(this,"legend",{width:0,height:0,items:[]});Be(this,"dendrograms",{})}clear(){var e;this.parentNode&&this.rootNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),this.parentNode=null,this.rootNode=null),setTimeout(()=>{var t;(t=this.reactRoot)==null||t.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.reactRoot=Qh(this.rootNode))}updateMargins(e){this.margins={top:e.show?24+24*2:Uv,bottom:Uv,left:Uv,right:this.legend.width+Uv},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartsWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+Math.max(this.chartSizes.chartsHeight+this.margins.bottom,this.legend.height)}updateLegendSize(e,t,n,r,a){if(!t.show){this.legend={width:0,height:0,items:[]};return}let i=this.chartSizes.chartHeight,o=[],s={width:0,height:0,left:0,top:0},c=v=>v.reduce((g,C)=>(g[C]=String(C),g),{});if(e==="continuous"){let v=this.colorScale,g=h3(v,a),C=Zr([g[0],g[g.length-1]],[i,0]),b=r.label??r.value;o.push({...s,type:"continuous",id:"heatmapValue",scale:v,values:g,title:b,tickPositionScale:C})}else if(e==="discrete"){let v=this.colorScale,g=r.label??r.value,C=v.domain(),b=c(C);o.push({...s,type:"discreteColor",id:"heatmapValue",title:g,scale:v,values:C,labels:b})}if(n.forEach(v=>{let g=v.valueColumn.label??v.valueColumn.value;if(v.type==="continuous"){let C=this.annotationColorScales[v.id].scale,b=h3(C,a),x=Zr([b[0],b[b.length-1]],[i,0]);o.push({...s,type:"continuous",id:v.id,tickPositionScale:x,title:g,scale:C,values:b})}if(v.type==="discrete"){let C=this.annotationColorScales[v.id].scale,b=C.domain(),x=c(b);o.push({...s,type:"discreteColor",id:v.id,title:g,scale:C,values:b,labels:x})}}),!o.length){this.legend={width:0,height:0,items:[]};return}let f=S3(o,this.chartSizes.chartHeight),A=f[f.length-1],h=A.left+A.width+FM;this.legend={width:h,height:i,items:f}}updateCaptionsSize(e,t,n,r){let a=new hc("bold 14px Arial"),{xGroupKeys:i,yGroupKeys:o,xGroupLabels:s,yGroupLabels:c,xKeysByGroups:f,yKeysByGroups:A,xLabels:h,yLabels:v}=e.meta;this.labelAngles={xAxisLabels:t.axisLabelsAngle,yAxisLabels:n.axisLabelsAngle,xGroupLabels:t.groupLabelsAngle,yGroupLabels:n.groupLabelsAngle};function g(le,Q){let j=0;for(let U of le){let Y=a.getTextWidth(Q[U]);Y>j&&(j=Y)}return j}let C=Zn.flatten(Object.values(f)),b=Zn.flatten(Object.values(A)),x=g(C,h),B=g(b,v),k=g(i,s),P=g(o,c),{xCaptionTail:I,yCaptionTail:$}=t9t(this.labelAngles,r,this.step,e,a),N=this.labelAngles.xGroupLabels/180*Math.PI,F=this.labelAngles.yGroupLabels/180*Math.PI,Z=this.labelAngles.xAxisLabels/180*Math.PI,ee=this.labelAngles.yAxisLabels/180*Math.PI;this.captionsSizes={xCaptionTail:I,yCaptionTail:$,xGroupCaptions:k*Math.sin(N)||Gv,yGroupCaptions:P*Math.sin(F)||Gv,xAxisCaptions:x*Math.sin(Z)||Gv,yAxisCaptions:B*Math.sin(ee)||Gv}}updateChartDimensions(e,t,n,r,a,i,o,s,c,f){let A=t.length,h=Math.min(a.nRows??A,A),v=Math.min(a.nCols??A,A);this.columnsCount=a.nRows?Math.ceil(A/h):v,this.rowsCount=Math.ceil(A/this.columnsCount);let{width:g,height:C}=e,{sharedX:b,sharedY:x}=a;this.chartsDimensions={};let B=0,k=0;t.forEach(($,N)=>{let F=N%this.columnsCount+1,Z=iZ(N,t.length,this.columnsCount,this.rowsCount),ee=this.step.x[$],le=this.step.y[$],Q=K7t(i,o,this.captionsSizes,s,c,f,Z,b,x,t,n,r,ee,le),j=e9t(s,Z,b,x);function U(ae){return Math.max(sp[ae].reduce((ge,me)=>ge+Q[ae][me],0),j[ae],G7t)}let Y={left:U("left"),right:U("right"),top:U("top"),bottom:U("bottom")};Y.left<this.captionsSizes.xCaptionTail&&(Y.left=this.captionsSizes.xCaptionTail),Y.bottom<this.captionsSizes.yCaptionTail&&(Y.bottom=this.captionsSizes.yCaptionTail);let X=Z7t(Q,g,C),te=g+Y.left+Y.right,pe=C+Y.top+Y.bottom;this.chartsDimensions[$]={left:B,top:k,inner:{width:g,height:C},outer:{width:te,height:pe},padding:Y,sideElementBBoxes:X,chartEdgeSides:Z},B+=te,F===this.columnsCount&&(B=0,k+=pe)});let P=t.slice(0,this.columnsCount).reduce(($,N)=>$+this.chartsDimensions[N].outer.width,0),I=t.filter(($,N)=>N%this.columnsCount===0).reduce(($,N)=>$+this.chartsDimensions[N].outer.height,0);this.chartSizes.chartsWidth=P,this.chartSizes.chartsHeight=I}updateChartsSizes(e){let{width:t,height:n}=e;this.chartSizes.chartWidth=t,this.chartSizes.chartHeight=n}updateScales(e,t,n,r,a,i,o,s,c){let{width:f,height:A}=a,{meta:h,facets:v}=t,{sharedX:g,sharedY:C}=r,b=(B,k={})=>B.sort((P,I)=>i.sorting==="asc"?(k[P]??P).localeCompare(k[I]??I,"en",{numeric:!0}):(k[I]??I).localeCompare(k[P]??P,"en",{numeric:!0})),x=(B,k={})=>B.sort((P,I)=>o.sorting==="asc"?(k[P]??P).localeCompare(k[I]??I,"en",{numeric:!0}):(k[I]??I).localeCompare(k[P]??P,"en",{numeric:!0}));e.forEach(B=>{let k=v[B],P=b(h.xGroupKeys),I=x(h.yGroupKeys),{xKeysByGroups:$}=g?h:k,{yKeysByGroups:N}=C?h:k,F=P.map(ge=>$[ge].length),Z=I.map(ge=>N[ge].length),ee=F.reduce((ge,me)=>ge+me,0),le=Z.reduce((ge,me)=>ge+me,0),Q=(f-(F.filter(ge=>ge>0).length-1)*n)/ee,j=(A-(Z.filter(ge=>ge>0).length-1)*n)/le,U=[],Y=[],X=0;P.forEach(ge=>{let me=s?$[ge]:b($[ge],h.xLabels);Y.push(...me),me.forEach(()=>{U.push(X),X+=Q}),me.length>0&&(X+=n)});let te=[],pe=[],ae=0;I.forEach(ge=>{let me=c?N[ge]:x(N[ge],h.yLabels);pe.push(...me),me.forEach(()=>{te.push(ae),ae+=j}),me.length>0&&(ae+=n)}),this.scales.x[B]=Qo().domain(Y).range(U),this.scales.y[B]=Qo().domain(pe).range(te),this.step.x[B]=Q,this.step.y[B]=j})}updateAesScale(e,t,n,r,a,i,o){if(e==="continuous")n.valueColors?this.colorScale=Zr().domain(n.valuesByColors??dZ(o,n.valueColors.length,t)).range(n.valueColors):n.colorsList&&(this.colorScale=Zr().domain(dZ(o,n.colorsList.length,t)).range(n.colorsList));else if(n.colorsMap){let f=Object.entries(n.colorsMap);this.colorScale=Qo().domain(f.map(A=>A[0])).range(f.map(A=>A[1])).unknown("#ccc")}else n.colorsList&&(this.colorScale=aZ(n.colorsList,i.map(String)));let{xDataByKeys:s,yDataByKeys:c}=a.meta;r.forEach(f=>{let{colors:A,type:h,axis:v,valueColumn:g}=f,C=(v==="x"?s:c)[g.value];if(h==="discrete"){let b=Zn.uniq(Object.values(C).map(String)).sort();this.annotationColorScales[f.id]={type:"discrete",scale:aZ(A,b)}}else{let b=Object.values(C).map(Number);if(!b.length)return;let[x=b[0],B=b[0]]=M0(b);this.annotationColorScales[f.id]={type:"continuous",scale:J7t(A,x,B,0,.5,1)}}})}updateDendrogram(e,t,n,r,a,i,o){e.forEach(s=>{this.dendrograms[s]={x:{trees:[],data:i},y:{trees:[],data:o}};let{xKeysByGroups:c,yKeysByGroups:f}=r[s],{hierarchyX:A,hierarchyY:h}=a[s],v=Math.max(...A.map(C=>C.data.height)),g=Math.max(...h.map(C=>C.data.height));i&&(this.dendrograms[s].x.trees=A.map((C,b)=>{let x=t[b],B=c[x];IB().separation(()=>1).size([B.length*this.step.x[s],i.size])(C);let k=C,P=Zr().domain(i.position==="top"?[0,v]:[v,0]).range([i.size,0]);return cZ(k,P,"y"),fZ(k,this.scales.x[s](B[0]),"x"),k}),this.dendrograms[s].x.data=i),o&&(this.dendrograms[s].y.trees=h.map((C,b)=>{let x=n[b],B=f[x];IB().separation(()=>1).size([B.length*this.step.y[s],o.size])(C);let k=C,P=Zr().domain(o.position==="left"?[0,g]:[g,0]).range([o.size,0]);return fZ(k,this.scales.y[s](B[0]),"x","y"),cZ(k,P,"x"),k}),this.dendrograms[s].y.data=o)})}updateDendrogramAesScales(e){if(!e)return;let t=Object.keys(e);this.dendrogramAesScales=t.reduce((n,r)=>{let a=e[r],i=Object.keys(a);return n[r]=Qo().domain(i).range(i.map(o=>({...rZ,...a[o]}))).unknown(rZ),n},{})}render(e,t,n,r,a,i,o,s,c,f,A,h,v,g){var le;let{meta:C,facets:b}=a,{facetKeys:x,xGroupKeys:B,yGroupKeys:k,valueExtent:P}=C,{xAxis:I,yAxis:$,title:N,size:F,valueType:Z}=t;this.updateChartsSizes(F),this.updateAesScale(Z,P,r,i,a,h,v),this.updateScales(x,a,r.groupGap,n,F,t.xAxis,t.yAxis,s,c),this.updateCaptionsSize(a,I,$,n),this.updateChartDimensions(F,x,B,k,n,I,$,i,s,c),this.updateLegendSize(Z,t.legend,i,o,P),this.updateMargins(N),this.updateDendrogram(x,B,k,b,f,s,c),this.updateDendrogramAesScales(A);let ee=ie.jsx(h9t,{aes:r,annotations:i,annotationColorScales:this.annotationColorScales,captionsSizes:this.captionsSizes,cellsMeta:C,columnsCount:this.columnsCount,chartsDimensions:this.chartsDimensions,chartSettings:t,chartSizes:this.chartSizes,colorScale:this.colorScale,dendrogramAesScales:this.dendrogramAesScales,dendrograms:this.dendrograms,facetKeys:x,facetSettings:n,groupedCells:b,labelAngles:this.labelAngles,legend:this.legend,margins:this.margins,scales:this.scales,settingsId:e,step:this.step,xGroupKeys:B,yGroupKeys:k,onTooltipHintSwitch:g});this.component=ee,(le=this.reactRoot)==null||le.render(ee)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},m9t=v9t,UM={lineColor:Vt,dotShape:"21",dotFill:Vt,dotSize:3,lineShape:"solid",lineWidth:1},AZ={size:150,distance:"euclidean",linkage:"average",fillNA:0,showNodes:!0,hidden:!1,edgeInheritance:"up",aes:UM},hZ=class{constructor(e){Be(this,"id");Be(this,"type","heatmap");Be(this,"facetSettings");Be(this,"xColumn");Be(this,"xGroupBy");Be(this,"yColumn");Be(this,"yGroupBy");Be(this,"valueColumn");Be(this,"facetBy");Be(this,"normalization");Be(this,"chartSettings");Be(this,"aes");Be(this,"annotations");Be(this,"dendrogramX");Be(this,"dendrogramY");Be(this,"inheritedDendrogramAes");Be(this,"NAValueAs");var t,n,r,a,i,o,s,c,f,A,h,v,g;if(j3t.parse(e),this.id=Zn.uniqueId("settings"),this.facetSettings={sharedX:(e.facetBy??[]).length>0,sharedY:(e.facetBy??[]).length>0,...e.facetSettings},this.xColumn=e.xColumn,this.xGroupBy=e.xGroupBy??[],this.yColumn=e.yColumn,this.yGroupBy=e.yGroupBy??[],this.valueColumn=e.valueColumn,this.facetBy=e.facetBy??[],this.chartSettings={title:{position:"left",show:!0,...e.title,name:((t=e.title)==null?void 0:t.name)??"Chart"},size:{width:((n=e==null?void 0:e.size)==null?void 0:n.width)??(this.facetBy.length?400:600),height:((r=e==null?void 0:e.size)==null?void 0:r.height)??(this.facetBy.length?250:350)},frame:{type:((a=e.frame)==null?void 0:a.type)??"none"},valueType:e.valueType??"continuous",yAxis:{title:e.yColumn.label??e.yColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,showGroupLabels:!0,position:"left",groupingPosition:"left",axisLabelsAngle:90,groupLabelsAngle:0,sorting:"asc",...e.yAxis},xAxis:{title:e.xColumn.label??e.xColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,showGroupLabels:!0,position:"bottom",groupingPosition:"bottom",axisLabelsAngle:90,groupLabelsAngle:0,sorting:"asc",...e.xAxis},legend:{show:!0,position:"right",...e.legend},tooltips:{show:!0,...e.tooltips}},this.normalization=this.chartSettings.valueType==="continuous"?e.normalization??null:null,this.NAValueAs=e.NAValueAs??null,this.aes={colorsList:((i=e.aes)==null?void 0:i.colorsList)??["black","white","red"],colorsMap:((o=e.aes)==null?void 0:o.colorsMap)??null,valueColors:((s=e.aes)==null?void 0:s.valueColors)??null,valuesByColors:((c=e.aes)==null?void 0:c.valuesByColors)??null,cellStrokeColor:((f=e.aes)==null?void 0:f.cellStrokeColor)??"none",groupGap:((A=e.aes)==null?void 0:A.groupGap)??3,emptyCellColor:((h=e.aes)==null?void 0:h.emptyCellColor)??"white"},this.annotations=(e.annotations??[]).map(C=>C.axis==="x"?{id:Zn.uniqueId("annotation"),axis:"x",valueColumn:C.valueColumn,position:C.position??this.chartSettings.xAxis.position,titlePosition:C.titlePosition??"right",showTitle:C.showTitle??!0,type:C.type,colors:C.colors??["white","black"]}:{id:Zn.uniqueId("annotation"),axis:"y",valueColumn:C.valueColumn,position:C.position??this.chartSettings.yAxis.position,titlePosition:C.titlePosition??"top",showTitle:C.showTitle??!0,type:C.type,colors:C.colors??["white","black"]}),e.valueType==="discrete"&&(e.dendrogramX||e.dendrogramY))throw Error("Dendrogram is not available with discrete cells values");this.dendrogramX=e.dendrogramX?{...AZ,position:"top",...e.dendrogramX,aes:{...UM,...(v=e.dendrogramX)==null?void 0:v.aes}}:null,this.dendrogramY=e.dendrogramY?{...AZ,position:"left",...e.dendrogramY,aes:{...UM,...(g=e.dendrogramY)==null?void 0:g.aes}}:null,this.inheritedDendrogramAes=e.inheritedDendrogramAes??null}},g9t=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new m9t);Be(this,"onTooltipHintSwitch",()=>{});Be(this,"calculatedData",null);this.settings=new hZ(n),r&&(this.onTooltipHintSwitch=r[0])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new hZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){console.warn("no chart state for heatmap")}export(){return this._updateChart(),b5(this.chartRenderer.component)}_needUpdateCalculatedDataBySettings(t,n){var $,N,F,Z,ee,le,Q,j,U,Y,X,te;let{xColumn:r,yColumn:a,valueColumn:i,xGroupBy:o,yGroupBy:s,facetBy:c,annotations:f,chartSettings:A,facetSettings:h,dendrogramX:v,dendrogramY:g,normalization:C,NAValueAs:b}=n,x=Object.values((($=t.dendrogramX)==null?void 0:$.aes)||{}).filter(y9),B=Object.values((v==null?void 0:v.aes)||{}).filter(y9),k=Object.values(((N=t.dendrogramY)==null?void 0:N.aes)||{}).filter(y9),P=Object.values((g==null?void 0:g.aes)||{}).filter(y9);function I(pe,ae){return pe.length!==ae.length||pe.some((ge,me)=>ge.value!==ae[me].value)}return t.xColumn.value!==r.value||t.yColumn.value!==a.value||t.valueColumn.value!==i.value||I(t.xGroupBy,o)||I(t.yGroupBy,s)||I(t.facetBy,c)||I(t.annotations.map(pe=>pe.valueColumn),f.map(pe=>pe.valueColumn))||I(x,B)||I(k,P)||(n.dendrogramX||t.dendrogramX)&&(((F=t.dendrogramX)==null?void 0:F.distance)!==((Z=n.dendrogramX)==null?void 0:Z.distance)||((ee=t.dendrogramX)==null?void 0:ee.linkage)!==((le=n.dendrogramX)==null?void 0:le.linkage))||(n.dendrogramY||t.dendrogramY)&&(((Q=t.dendrogramY)==null?void 0:Q.distance)!==((j=n.dendrogramY)==null?void 0:j.distance)||((U=t.dendrogramY)==null?void 0:U.linkage)!==((Y=n.dendrogramY)==null?void 0:Y.linkage))||t.chartSettings.valueType!==A.valueType||t.facetSettings.sharedX!==h.sharedX||t.facetSettings.sharedY!==h.sharedY||((X=t.normalization)==null?void 0:X.method)!==(C==null?void 0:C.method)||((te=t.normalization)==null?void 0:te.direction)!==(C==null?void 0:C.direction)||t.NAValueAs!==b}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{xColumn:t,yColumn:n,valueColumn:r,xGroupBy:a,yGroupBy:i,facetBy:o,chartSettings:s,facetSettings:c,annotations:f,dendrogramX:A,dendrogramY:h,normalization:v,NAValueAs:g}=this.settings,C=z7t(this.data,t,n,r,o,a,i,f,A,h,v,g),b=U7t(C,A,h,c),x=s.valueType==="discrete"?this.data.getColumnCategories(r.value):[];this.calculatedData={groupedCellsData:C,dendrogramsData:b,cellUniqValues:x}}_updateAesInData(){}_updateChart(){if(!this.calculatedData)return;let{id:t,valueColumn:n,chartSettings:r,facetSettings:a,aes:i,annotations:o,dendrogramX:s,dendrogramY:c,inheritedDendrogramAes:f,normalization:A}=this.settings;this.chartRenderer.render(t,r,a,i,this.calculatedData.groupedCellsData,o,n,s,c,this.calculatedData.dendrogramsData,f,this.calculatedData.cellUniqValues,A,this.onTooltipHintSwitch)}},pZ=(e,t)=>{let n=Math.min(...t),r=Math.max(...t);if(n===r)return[n];if(e<2)return[(n+r)/2];let a=(r-n)/e,i=[];for(let o=1;o<e;o++)i.push(n+a*o);return i};function vZ(e,t,n){return e.map(r=>({count:r.length,y:{straight:r.length,reverse:r.length},rows:r,x:r.x0??0,groupingKey:t,groupingKeyIdx:n,width:(r.x1??0)-(r.x0??0)}))}function y9t(e,t,n,r,a,i){let o=pZ(n,r),s=MI().domain(r).thresholds(o).value(c=>c[t.value])(e);return{bins:vZ(s,a,i),maxCount:Dh(s,c=>c.length)??0}}function w9t(e,t,n,r,a,i){let o=pZ(n,r),s=nv().domain(r).range(r),c=o.map(A=>s.invert(A)),f=MI().domain(r).thresholds(c).value(A=>A[t.value])(e);return{bins:vZ(f,a,i),maxCount:Dh(f,A=>A.length)??0}}function b9t(e,t,n,r,a,i){let o={};return t.forEach(s=>{var b,x;let c=s.join("_");o[c]={groupingKeys:n,histogramByGroupingKey:{},minX:1/0,maxX:-1/0,maxCount:0,maxCountFromGroups:0};let f=e.getRowsByGrouping([...s]),[A,h]=M0(f,B=>B[r.value]);A=A??((b=f[0])==null?void 0:b[r.value])??0,h=h??((x=f[0])==null?void 0:x[r.value])??0;let v=[A,h],g=[...n].reverse();g.forEach((B,k)=>{let P=e.getRowsByGrouping([...s,B]),I=i==="linear"?y9t(P,r,a,v,B,k):w9t(P,r,a,v,B,k);o[c].histogramByGroupingKey[B]=I,o[c].minX=v[0],o[c].maxX=v[1],o[c].maxCountFromGroups=Math.max(o[c].maxCountFromGroups,I.maxCount);let $=k>0?g[k-1]:null,N=$!==null?o[c].histogramByGroupingKey[$]:null;I.bins.forEach((F,Z)=>{F.y.straight=((N==null?void 0:N.bins[Z].y.straight)??0)+F.count,o[c].maxCount=Math.max(o[c].maxCount,F.y.straight)})});let C=n;C.forEach((B,k)=>{let P=k>0?C[k-1]:null,I=o[c].histogramByGroupingKey[B],$=P!==null?o[c].histogramByGroupingKey[P]:null;I.bins.forEach((N,F)=>{N.y.reverse=(($==null?void 0:$.bins[F].y.reverse)??0)+N.count})})}),o}var C9t={TOP:30,BOTTOM:0,LEFT:10,RIGHT:10};function _9(e,t,n=!1){let r=Math.abs(e.range()[0]-e.range()[1]),a=n?Math.min(Math.floor(r/45),10):10,i=e.ticks(a).filter(c=>t&&c>=0||!t),o=new Set(i);if(!n&&i.length>1){let c=e(i[0]),f=e(i[0]);for(let A=1;A<i.length;A++)f=e(i[A]),Math.abs(f-c)>=20?c=f:o.delete(i[A])}n&&i.length>2&&Math.abs(e(i[1])-e(i[0]))<45&&(i=i.filter((c,f)=>f%2===0));let s=i.some(c=>Math.abs(c)<1e-4&&c!==0||c>1e4)?",e":",f";return{ticks:i,format:c=>o.has(c)?e.tickFormat(a,s)(c):""}}var mZ=(e,t)=>{let n=Math.min(...t),r=Math.max(...t);if(n===r){let o=e%2===0?[]:[n];for(let s=1;s<e/2+1;s++)o.push(n+s),o.unshift(n-s);return o}if(e<2)return[n,r];let a=(r-n)/(e-1),i=[];for(let o=0;o<e-1;o++)i.push(n+a*o);return i.push(r),i};function S9t(e,t,n){if(n==="linear")return mZ(e,t);if(n==="log"){let r=mZ(e,t),a=nv(t,t),i=r.map(o=>a.invert(o));return i[0]=t[0],i[i.length-1]=t[1],i}return[]}function T9(e,t,n){return(n==="log"?nv():Zr()).domain(S9t(e.length,t,n)).range(e)}function x9t(e){return`translate(${e},0)`}function E9t(e){return`translate(0,${e})`}function B9t(e){return e==="bottom"?`translate(0,${zf})`:`translate(${-zf},0)`}function _9t(e){return e==="bottom"?"hanging":"central"}function T9t(e){return e==="bottom"?"middle":"end"}var gZ=({scale:e,tickSize:t=6,tickPadding:n=zf,orient:r="bottom",onlyPositive:a=!1,hiddenLabels:i=!1,offset:o=typeof window<"u"&&window.devicePixelRatio>1?0:.5})=>{function s(x){return B=>{let k=x(B);return k===void 0?0:+k}}let{ticks:c,format:f}=i?{ticks:[],format:x=>x}:_9(e,a,r==="bottom"),A=Math.max(t,0)+n,h=s(e.copy()),v=r==="bottom"?x9t:E9t,g=r==="left"?-1:1,C={[(r==="left"?"x":"y")+"2"]:g*t},b={[r==="left"?"x":"y"]:g*A};return ie.jsx("g",{children:c.map((x,B)=>ie.jsxs("g",{className:"tick",transform:v(h(x)+o),children:[ie.jsx("line",{stroke:Vt,...C}),ie.jsx("g",{transform:B9t(r),children:ie.jsx("text",{fill:Vt,fontSize:"14px",fontWeight:"500",fontFamily:"Manrope",dominantBaseline:_9t(r),textAnchor:T9t(r),...b,children:f(x)})})]},B))})},k9t=1;function yZ({scaleX:e,scaleY:t,width:n,height:r,axisX:a,axisY:i,frameType:o,updatingKey:s=""}){let[c,f]=tn.useState(e.ticks()),[A,h]=tn.useState(t.ticks()),{significantLines:v=[]}=a,{significantLines:g=[]}=i;return tn.useEffect(()=>{let C=e.ticks().filter(x=>!v.includes(x)),b=t.ticks().filter(x=>!g.includes(x));f(C),h(b)},[e,t,s]),ie.jsxs("g",{stroke:Nf,children:[a.showGrid&&c.map(C=>{let b=e(C);return ie.jsx("line",{x1:b,x2:b,y1:0,y2:r},`x_${b}_${r}`)}),i.showGrid&&A.map(C=>{let b=t(C);return ie.jsx("line",{x1:0,x2:n,y1:b,y2:b},`y_${b}_${n}`)}),ie.jsx("g",{strokeDasharray:Of(a.significantLinesStyle),stroke:Vt,children:v.map(C=>{let b=e(C);return b<0||b>n?null:ie.jsx("line",{x1:b,x2:b,y1:0,y2:r},`significant_${b}_${r}`)})}),ie.jsx("g",{strokeDasharray:Of(i.significantLinesStyle),stroke:Vt,children:g.map(C=>{let b=t(C);return b<0||b>r?null:ie.jsx("line",{x1:0,x2:n,y1:b,y2:b},`significant_${b}_${n}`)})}),o!=="empty"&&ie.jsxs("g",{strokeWidth:k9t,children:[(a.showGrid||o!=="left")&&ie.jsx("line",{stroke:o==="left"?Nf:Vt,x1:"0",x2:n,y1:r,y2:r}),(a.showGrid||o!=="bottom")&&ie.jsx("line",{stroke:o==="bottom"?Nf:Vt,x1:"0",x2:"0",y1:"0",y2:r}),(a.showGrid||o==="full")&&ie.jsx("line",{stroke:o==="full"?Vt:Nf,x1:n,x2:n,y1:"0",y2:r}),(i.showGrid||o==="full")&&ie.jsx("line",{stroke:o==="full"?Vt:Nf,x1:"0",x2:n,y1:"0",y2:"0"})]})]})}function M9t(e){return typeof e=="string"?e:e.value}function P9t(e,t){let n=[`Amount: ${e.count}`,`(from ${ni(e.x)}, to ${ni(e.x+e.width)})`];return e.groupingKey!=="null"&&n.push(`${t[e.groupingKey]??e.groupingKey}`),n}function wZ(e,t,n,r){return t==="vertical"?e:e+n*r}function bZ(e,t,n,r){return t(n==="vertical"?r==="straight"?e.y.straight:e.y.reverse:e.count)}function H9t({facetKey:e,width:t,height:n,dimensions:r,scales:a,xAxis:i,yAxis:o,frameType:s,histogramData:c,facetSettings:f,captionsSizes:A,facetTitle:h,layers:v,aesColorGetter:g,groupingDirection:C,groupingStack:b,groupingLabels:x,chartSizes:B,margins:k,tooltipsContainer:P,tooltipsData:I}){let[$,N]=tn.useState(),{padding:F}=r,Z=i.showTicks?4:0,ee=o.showTicks?4:0,le=r.chartEdgeSides.includes("left")||!(f!=null&&f.sharedY),Q=r.chartEdgeSides.includes("bottom")||!(f!=null&&f.sharedX),j=r.chartEdgeSides.includes("bottom"),U=c.groupingKeys,Y=c.histogramByGroupingKey[U[0]].bins[0],X=a.x(Y.width)-a.x(0),te=b==="vertical"?X:X/U.length,pe={left:k.left+r.left+F.left,right:B.totalWidth-(k.left+r.left+F.left),top:k.top+r.top+F.top,bottom:B.totalHeight-(k.top+r.top+F.top)},ae=$&&I.fixed,ge=!1;return ie.jsxs("g",{transform:`translate(${r.left+F.left},${r.top+F.top})`,children:[ge,h.length&&ie.jsxs("g",{children:[s==="full"&&ie.jsx("rect",{x:"0",y:-F.top,height:F.top,width:t,fill:"#F7F8FA",stroke:Vt}),h.map((me,fe)=>{let Ce=h.length,De=(F.top-20*Ce)/2;return ie.jsx("text",{fontSize:"14px",fontWeight:"500",fill:Vt,x:t/2,dy:De+20/2-F.top,y:fe*20,textAnchor:"middle",dominantBaseline:"central",children:me},fe)})]}),ie.jsxs("g",{dominantBaseline:"central",textAnchor:"middle",fontWeight:"500",fontSize:"14px",fill:Vt,children:[j&&i.title&&ie.jsx("text",{x:t/2,y:n+F.bottom-20/2,children:M9t(i.title)}),ge]}),ie.jsx(yZ,{width:t,height:n,scaleX:a.x,scaleY:a.y,axisX:i,axisY:o,frameType:s}),Q&&ie.jsxs("g",{transform:`translate(0,${n})`,children:[ie.jsx(gZ,{scale:a.x,orient:"bottom",tickSize:Z,hiddenLabels:i.hiddenLabels}),ge]}),le&&ie.jsxs("g",{children:[ie.jsx(gZ,{scale:a.y,orient:"left",tickSize:ee,hiddenLabels:o.hiddenLabels}),ge]}),v.map(me=>U.map((fe,Ce)=>c.histogramByGroupingKey[fe].bins.map(De=>{let ke=ae&&I.selectedData===De,$e=ie.jsx("rect",{x:wZ(a.x(De.x),b,Ce,te),y:bZ(De,a.y,b,C),fill:De.rows[0]?g(me.aes.fillColor,De.rows[0],De.count):"",stroke:me.aes.lineColor,width:te,height:a.y(0)-a.y(De.count),opacity:me.aes.opacity??1,onMouseOver:()=>I.onMouseOver(De,e),onMouseLeave:()=>I.onMouseLeave()},De.x);return ke?cu.createPortal($e,$):$e}))),I.fixed&&ie.jsx("rect",{width:B.chartWidth,height:B.chartHeight,fill:"rgba(255,255,255,0.8)"}),ie.jsx("g",{ref:me=>{me&&!$&&N(me)}}),I.selectedData&&I.currentFacet===e&&ie.jsx(fu,{content:P9t(I.selectedData,x),x:wZ(a.x(I.selectedData.x),b,I.selectedData.groupingKeyIdx,te)+te,y:bZ(I.selectedData,a.y,b,C)+a.y(0)-a.y(I.selectedData.count/2),offset:0,active:!0,fixed:I.fixed,sideDistances:pe,container:P,onClose:I.onClose})]})}function D9t({settingsId:e,chartSettings:t,chartSizes:n,chartsDimensions:r,columnsCount:a,facetKeys:i,facetSettings:o,scales:s,margins:c,mainTitle:f,facetTitles:A,captionsSizes:h,histogramDataByFacets:v,layers:g,aesColorGetter:C,groupingDirection:b,groupingStack:x,groupingLabels:B,legend:k,onTooltipHintSwitch:P}){let I=p3(P),{xAxis:$,yAxis:N,title:F,frame:Z}=t,ee=r[i[0]].padding,le=r[i[a-1]].padding,[Q,j]=tn.useState(),U=tn.useRef(null);tn.useEffect(()=>{U.current&&j(U.current)},[]);let Y=c.left+n.chartsWidth+FM,X=c.top+ee.top;return ie.jsx(y3,{dataId:e,children:ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${n.totalWidth} ${n.totalHeight}`,width:n.totalWidth,height:n.totalHeight,children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${c.left},${c.top})`,fontFamily:"Manrope",children:[ie.jsx(w3,{title:f,show:F.show,position:F.position,leftPadding:ee.left,rightPadding:le.right,chartsWidth:n.chartsWidth}),i.map(te=>ie.jsx(H9t,{facetKey:te,scales:{x:s.x[te],y:s.y[te]},width:n.chartWidth,height:n.chartHeight,dimensions:r[te],margins:c,chartSizes:n,facetSettings:o,xAxis:$,yAxis:N,frameType:Z.type,facetTitle:A[te],captionsSizes:h,histogramData:v[te],layers:g,aesColorGetter:C,groupingDirection:b,groupingStack:x,groupingLabels:B,tooltipsContainer:Q,tooltipsData:I},te))]}),ie.jsx("g",{transform:`translate(${Y},${X})`,children:ie.jsx(b3,{legendData:k})}),ie.jsx("g",{ref:U,style:{outline:"none"}})]})})}function $9t(e,t,n,r){let a=[];return e%n===n-1&&a.push("right"),e%n===0&&a.push("left"),e<n&&a.push("top"),(Math.ceil((e+1)/n)===r||Math.ceil((e+1)/n)===r-1&&e%n>(t-1)%n)&&a.push("bottom"),a}function I9t(e,t,n,r,a,i,o,s){let c=i.includes("left")||!(s!=null&&s.sharedY),f=i.includes("bottom")||!(s!=null&&s.sharedX),A=i.includes("bottom")&&e.title!=="",h=n.yAxisCaptionsWidth,v=(t.showTicks?4:0)+(t.hiddenLabels?0:6),g=n.xAxisCaptionsWidth,C=(e.showTicks?4:0)+(e.hiddenLabels?0:6),b=A?20:0,x=h+v,B=C+g+b,k=Math.max(...r.map(P=>a[P].length));return{left:c?x:12,top:k===0?0:6*2+k*20,bottom:f?B:12,right:o?0:12}}function L9t(e,t,n){let r=[];for(let a=0;a<t;a++)r.push(e.slice(a*n,a*n+n));return r}function R9t(e,t){let n=Math.floor(e/t),r=e-n*t;return[n,r]}function CZ(e){return typeof e=="object"&&e!==null&&"type"in e&&"value"in e&&e.type==="grouping"}function V9t(e){return typeof e=="object"&&e!==null&&"range"in e}function N9t(e,t,n){return function(r,a,i){var o,s;if(V9t(r)){let{domain:c=n,range:f,type:A="linear"}=r,h=T9(f,c,A);return h.clamp(!0),h(i)}if(CZ(r)){let c=r.value;return(s=((o=e[c])==null?void 0:o[String(a[c])])??EM)==null?void 0:s[t]}return r}}var z9t=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"component",ie.jsx(ie.Fragment,{}));Be(this,"margins",{top:24,bottom:24,left:24,right:24});Be(this,"chartsDimensions",{});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,chartsWidth:600,chartsHeight:350,totalWidth:600,totalHeight:350});Be(this,"columnsCount",1);Be(this,"rowsCount",1);Be(this,"scales",{x:{null:Zr().domain([0,10]).range([0,600])},y:{null:Zr().domain([0,10]).range([350,0])}});Be(this,"captionsSizes",{xAxisCaptionsWidth:30,yAxisCaptionsWidth:100});Be(this,"facetTitles",{});Be(this,"mainTitle",[]);Be(this,"legend",{width:0,height:0,items:[]})}clear(){var e;this.parentNode&&this.rootNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),this.parentNode=null,this.rootNode=null),setTimeout(()=>{var t;(t=this.reactRoot)==null||t.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.reactRoot=Qh(this.rootNode))}updateChartSizes(e){this.chartSizes.chartWidth=e.width,this.chartSizes.chartHeight=e.height}updateChartDimensions(e,t,n,r){let{chartWidth:a,chartHeight:i}=this.chartSizes,o=0,s=0;this.chartsDimensions=e.reduce((A,h,v)=>{let[g,C]=R9t(v,this.columnsCount),b=$9t(v,e.length,this.columnsCount,this.rowsCount),x=I9t(n,r,this.captionsSizes,L9t(e,this.rowsCount,this.columnsCount)[g],this.facetTitles,b,C===this.columnsCount-1,t),B=a+x.left+x.right,k=i+x.top+x.bottom;return A[h]={left:o,top:s,chartEdgeSides:b,padding:x,inner:{width:a,height:i},outer:{width:B,height:k}},o+=B,C===this.columnsCount-1&&(o=0,s+=k),A},{});let c=Math.max(...e.map(A=>this.chartsDimensions[A].outer.width+this.chartsDimensions[A].left)),f=Math.max(...e.map(A=>this.chartsDimensions[A].outer.height+this.chartsDimensions[A].top));this.chartSizes.chartsWidth=c,this.chartSizes.chartsHeight=f}updateViewport(e,t,n,r,a,i,o){let s=e.length,c=Math.min(t.nRows??s,s),f=Math.min(t.nCols??s,s);this.columnsCount=t.nRows?Math.ceil(s/c):f,this.rowsCount=Math.ceil(s/this.columnsCount);let[A,h]=[1/0,-1/0],v=-1/0,g=e.reduce((C,b)=>{let x=a[b],{minX:B,maxX:k,maxCount:P,maxCountFromGroups:I}=x;return A=Math.min(A,B),h=Math.max(h,k),v=Math.max(v,o==="vertical"?P:I),C[b]={minX:B,maxX:k,maxY:o==="vertical"?P:I},C},{});e.forEach(C=>{let b=n.scale==="log"?nv():Zr(),x=g[C],B=t.sharedX?A:x.minX,k=t.sharedX?h:x.maxX;b.domain([B,k]).range([0,this.chartSizes.chartWidth]),this.scales.x[C]=b}),e.forEach(C=>{let b=r.scale==="log"?nv():Zr(),x=g[C],B=0,k=t.sharedY?v:x.maxY,P=[this.chartSizes.chartHeight,0],I=b.copy().domain([B,k]).range([this.chartSizes.chartHeight,i.innerOffset]);b.domain([I.invert(this.chartSizes.chartHeight),I.invert(0)]).range(P),this.scales.y[C]=b})}updateCaptionsSize(e,t){let n=new hc("600 14px Arial"),r=0;function a(i){return Math.max(...i.map(o=>n.getTextWidth(o)))}t.hiddenLabels||Object.values(this.scales.y).forEach(i=>{let{ticks:o,format:s}=_9(i,!1);r=Math.max(r,a(o.map(s)))}),this.captionsSizes={xAxisCaptionsWidth:e.hiddenLabels?0:20,yAxisCaptionsWidth:r}}createMainTitle(e,t){let n=this.chartsDimensions[e[0]],r=this.chartsDimensions[e[e.length-1]];this.mainTitle=jv(t.name,this.chartSizes.chartsWidth-n.padding.left-r.padding.right,20)}createFacetTitles(e,t){this.facetTitles=e.reduce((n,r,a)=>(t[a].length===1&&t[a][0]==="null"?n[r]=[]:n[r]=jv(t[a].join(", "),this.chartSizes.chartWidth,14),n),{})}updateLegendSize(e,t,n,r){if(!e.show){this.legend={width:0,height:0,items:[]};return}let a=[],i={width:0,height:0,left:0,top:0};if(r.forEach(A=>{if(CZ(A.aes.fillColor)&&n){let h=A.aes.fillColor.value,v=t[n.value],g=n.label??n.value,C=Qo().domain(v.values).range(v.values.map(b=>v.aesMap[b].fillColor));a.push({...i,id:h,type:"discreteColor",title:g,scale:C,values:v.values,labels:v.labels})}}),!a.length){this.legend={width:0,height:0,items:[]};return}let o=S3(a,this.chartSizes.chartHeight),s=o[o.length-1],c=s.left+s.width+WC,f=this.chartSizes.chartHeight;this.legend={width:c,height:f,items:o}}updateMargins(e){let t=24*this.mainTitle.length,n=t>0?t+24*2:0,r=e.outerOffset;this.margins={top:Math.max(n,r),bottom:r,left:r,right:this.legend.width+r},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartsWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+this.chartSizes.chartsHeight+this.margins.bottom}render(e,t,n,r,a,i,o,s,c,f,A,h,v){var I;let{xAxis:g,yAxis:C,size:b,title:x}=t;this.updateChartSizes(b),this.updateViewport(r,n,g,C,i,b,A),this.updateCaptionsSize(g,C),this.createFacetTitles(r,a),this.updateChartDimensions(r,n,g,C),this.createMainTitle(r,x),this.updateLegendSize(t.legend,o,f,s),this.updateMargins(b);let B=r.reduce(($,N)=>Math.min($,i[N].minX),1/0),k=r.reduce(($,N)=>Math.max($,i[N].maxX),-1/0),P=ie.jsx(D9t,{settingsId:e,chartSettings:t,facetKeys:r,facetSettings:n,chartSizes:this.chartSizes,chartsDimensions:this.chartsDimensions,scales:this.scales,columnsCount:this.columnsCount,margins:this.margins,mainTitle:this.mainTitle,facetTitles:this.facetTitles,captionsSizes:this.captionsSizes,histogramDataByFacets:i,layers:s,aesColorGetter:N9t(c,"fillColor",[B,k]),groupingDirection:h,groupingStack:A,groupingLabels:f?o[f.value].labels:{},legend:this.legend,onTooltipHintSwitch:v});this.component=P,(I=this.reactRoot)==null||I.render(P)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},O9t=z9t,F9t=10,Q9t=class{constructor(e){Be(this,"type","bins");Be(this,"aes",{fillColor:"white",lineColor:Vt,opacity:1});this.aes={...this.aes,...e.aes}}},j9t=class{constructor(e){Be(this,"type","binsLine");Be(this,"aes",{opacity:1});this.aes={...this.aes,...e.aes}}},SZ=class{constructor(e){Be(this,"id");Be(this,"type","histogram");Be(this,"valueColumn");Be(this,"binsCount");Be(this,"facetSettings");Be(this,"facetBy");Be(this,"grouping");Be(this,"groupingStack");Be(this,"groupingDirection");Be(this,"groupingOrder");Be(this,"chartSettings");Be(this,"inheritedAes");Be(this,"layers");var t,n,r,a,i,o,s,c,f,A,h;J3t.parse(e),this.id=Zn.uniqueId("settings"),this.facetSettings={sharedX:!0,sharedY:!0,titlePosition:"left",...e.facetSettings},this.valueColumn=e.valueColumn,this.binsCount=e.binsCount??F9t,this.facetBy=e.facetBy??[],this.grouping=e.grouping??null,this.groupingStack=e.groupingStack??"vertical",this.groupingDirection=e.groupingDirection??"straight",this.groupingOrder=e.groupingOrder??null,this.chartSettings={size:{width:((t=e==null?void 0:e.size)==null?void 0:t.width)??(this.facetBy.length?400:600),height:((n=e==null?void 0:e.size)==null?void 0:n.height)??(this.facetBy.length?250:350),outerOffset:((r=e==null?void 0:e.size)==null?void 0:r.outerOffset)??24,innerOffset:((a=e==null?void 0:e.size)==null?void 0:a.innerOffset)??C9t.TOP},title:{position:"center",show:!0,...e.title,name:((i=e.title)==null?void 0:i.name)??"Chart"},yAxis:{showGrid:!0,showTicks:!0,scale:((o=e.xAxis)==null?void 0:o.scale)??"linear",hiddenLabels:!1,...e.yAxis},xAxis:{title:e.valueColumn.label??e.valueColumn.value??"",scale:((s=e.xAxis)==null?void 0:s.scale)??"linear",showGrid:((c=e.xAxis)==null?void 0:c.showGrid)??!0,showTicks:((f=e.xAxis)==null?void 0:f.showTicks)??!0,hiddenLabels:((A=e.xAxis)==null?void 0:A.hiddenLabels)??!1,...e.xAxis},frame:{type:((h=e.frame)==null?void 0:h.type)??"full"},legend:{show:!0,position:"right",...e.legend}},this.inheritedAes=e.inheritedAes??{},this.layers=e.layers.map(v=>{if(v.type==="bins")return new Q9t(v);if(v.type==="binsLine")return new j9t(v);f1(v,"Unknown layer type")}).filter(Boolean)}};function xZ(e){if(!e.length)return[];let t=[[]];return e.forEach(n=>{let r=[];n.forEach(a=>{r.push(...t.map(i=>[...i,a]))}),t=r}),t}function U9t(e,t,n){return t.reduce((r,a)=>{let i=Zn.uniqBy(e.rows,f=>f[a.value]),o=f=>String(f[a.value]),s=f=>a.valueLabels?String(f[a.valueLabels]):o(f),c=i.reduce((f,A)=>(f[o(A)]=s(A),f),{});return r[a.value]={values:i.map(o).filter(f=>f!=="null").sort((f,A)=>c[f].localeCompare(c[A],"en",{numeric:!0})),aesMap:n[a.value],labels:c},r},{})}var G9t=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new O9t);Be(this,"onTooltipHintSwitch",()=>{});Be(this,"calculatedData",null);this.settings=new SZ(n),r&&(this.onTooltipHintSwitch=r[0])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new SZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){console.warn("no chart state for histogram")}export(){return this._updateChart(),b5(this.chartRenderer.component)}_needUpdateCalculatedDataBySettings(t,n){var r,a,i,o;return t.valueColumn.value!==n.valueColumn.value||t.facetBy.some((s,c)=>{var f;return s.value!==((f=n.facetBy[c])==null?void 0:f.value)})||((r=t.grouping)==null?void 0:r.value)!==((a=n.grouping)==null?void 0:a.value)||t.layers.length!==n.layers.length||t.layers.some((s,c)=>s.type!==n.layers[c].type)||t.binsCount!==n.binsCount||t.chartSettings.xAxis.scale!==n.chartSettings.xAxis.scale||((i=t.groupingOrder)==null?void 0:i.some((s,c)=>{var f;return s!==((f=n.groupingOrder)==null?void 0:f[c])}))||((o=n.groupingOrder)==null?void 0:o.some((s,c)=>{var f;return s!==((f=t.groupingOrder)==null?void 0:f[c])}))}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{valueColumn:t,facetBy:n,grouping:r,binsCount:a,chartSettings:i,inheritedAes:o,groupingOrder:s}=this.settings,c=n.map(C=>this.data.getColumnCategories(C.value)),f=c.length?xZ([...c]):[["null"]],A=n.map(C=>C.value)??null,h=r?[r.value]:[],v=r?this.data.getColumnCategories(r.value):["null"];s&&(v=Zn.intersection(s,v)),this.data.setGrouping([...A,...h]);let g=b9t(this.data,f,v,t,a,i.xAxis.scale);this.calculatedData={facetKeys:f.map(C=>C.join(", ")),facetKeysCombinations:f,histogramDataByFacets:g,legendInfo:U9t(this.data,r?[r]:[],o)}}_updateAesInData(){this.calculatedData}_updateChart(){if(!this.calculatedData)return;let{id:t,chartSettings:n,facetSettings:r,inheritedAes:a,layers:i,grouping:o,groupingDirection:s,groupingStack:c}=this.settings;this.chartRenderer.render(t,n,r,this.calculatedData.facetKeys,this.calculatedData.facetKeysCombinations,this.calculatedData.histogramDataByFacets,this.calculatedData.legendInfo,i,a,o,c,s,this.onTooltipHintSwitch)}};function Y9t(e,t,n,r,a,i,o){let s={};return t.forEach(c=>{let f=[],A=1/0,h=1/0,v=-1/0,g=-1/0;o.forEach(C=>{e.getRowsByGrouping([...c,C]).forEach(b=>{let x=b[n.value],B=b[r.value];A=Math.min(A,x),h=Math.min(h,B),v=Math.max(v,x),g=Math.max(g,B),x!==null&&B!==null&&f.push({id:`${Object.values(b)}`,x,y:B,label:a?b[a.valueLabels??a.value]:null,dimmed:i?!b[i.value]:!1,data:b})})}),f.sort((C,b)=>C.x-b.x),s[c.join("_")]={minX:A,maxX:v,minY:h,maxY:g,dots:f}}),s}function W9t(e,t,n,r,a){return t.reduce((i,o)=>{let s=n[o].dots;return i[o]=e.map(c=>{if(c.type==="curve")return{type:"curve",info:c,geoms:r.map(f=>{let A=s.filter(v=>a.every((g,C)=>v.data[g.value]===f[C])),h=a.reduce((v,g,C)=>(v[g.value]=f[C],v),{});return{dots:A,data:h}})};if(c.type==="dots")return{type:"dots",info:c,geoms:s};f1(c,"Unknown scatterplot layer type")}),i},{})}function GM(e){let t=e.xPosition!=="middle"&&e.yPosition!=="middle",n=e.padding*(t?.7:1);return e.xPosition==="right"?e.x+n:e.xPosition==="middle"?e.x-e.width/2:e.x-e.width-n}function EZ(e){let t=e.xPosition!=="middle"&&e.yPosition!=="middle",n=e.padding*(t?.7:1);return e.yPosition==="middle"?e.y-e.height/2:e.yPosition==="top"?e.y-n-e.height:e.y+n}function X9t(e,t){return GM(e)-t}function K9t(e,t){return EZ(e)-t}function BZ(e){let t=GM(e),n=t+e.width,r=EZ(e),a=r+e.height;return{minX:t,maxX:n,minY:r,maxY:a}}function _Z(e,t,n){let r=X9t(e,n),a=GM(e)+e.width+n,i=K9t(e,t),o=i+e.height+2*t;return{minX:r,maxX:a,minY:i,maxY:o}}function Z9t(e,t,n){return e.minX>=0&&e.maxX<=t&&e.minY>=0&&e.maxY<=n}var dS=2;function J9t(e,t=dS,n=dS){e.forEach(r=>{r.bbox=BZ(r),r.outerBBox=_Z(r,t,n)})}function AS(e,t,n,r=dS,a=dS){let i=[],o=new bdt,s=[["middle","right"],["top","right"],["bottom","right"],["middle","left"],["top","left"],["bottom","left"],["top","middle"],["bottom","middle"]];for(let c of e)for(let[f,A]of s){let h={...c,yPosition:f,xPosition:A};if(h.bbox=BZ(h),h.outerBBox=_Z(h,r,a),Z9t(h.outerBBox,t,n)&&!o.collides(h.outerBBox)){i.push(h),o.insert(h.outerBBox);break}}return i}function q9t(e){return`translate(${e},0)`}function e6t(e){return`translate(0,${e})`}function t6t(e){return e==="bottom"?`translate(0,${zf})`:`translate(${-zf},0)`}function n6t(e){return e==="bottom"?"hanging":"central"}function r6t(e){return e==="bottom"?"middle":"end"}var hS=({scale:e,tickSize:t=6,tickPadding:n=zf,orient:r="bottom",onlyPositive:a=!1,offset:i=typeof window<"u"&&window.devicePixelRatio>1?0:.5})=>{function o(b){return x=>{let B=b(x);return B===void 0?0:+B}}let{ticks:s,format:c}=_9(e,a,r==="bottom"),f=Math.max(t,0)+n,A=o(e.copy()),h=r==="bottom"?q9t:e6t,v=r==="left"?-1:1,g={[(r==="left"?"x":"y")+"2"]:v*t},C={[r==="left"?"x":"y"]:v*f};return ie.jsx("g",{children:s.map((b,x)=>ie.jsxs("g",{className:"tick",transform:h(A(b)+i),children:[ie.jsx("line",{stroke:Vt,...g}),ie.jsx("g",{transform:t6t(r),children:ie.jsx("text",{fill:Vt,fontSize:"14px",fontWeight:"500",fontFamily:"Manrope",dominantBaseline:n6t(r),textAnchor:r6t(r),...C,children:c(b)})})]},x))})},a6t=1;function i6t({scaleX:e,scaleY:t,width:n,height:r,axisX:a,axisY:i,frameType:o,updatingKey:s=""}){let[c,f]=tn.useState(e.ticks()),[A,h]=tn.useState(t.ticks()),{significantLines:v=[]}=a,{significantLines:g=[]}=i;return tn.useEffect(()=>{let C=e.ticks().filter(x=>!v.includes(x)),b=t.ticks().filter(x=>!g.includes(x));f(C),h(b)},[e,t,s]),ie.jsxs("g",{stroke:Nf,children:[a.showGrid&&c.map(C=>{let b=e(C);return ie.jsx("line",{x1:b,x2:b,y1:0,y2:r},`x_${b}_${r}`)}),i.showGrid&&A.map(C=>{let b=t(C);return ie.jsx("line",{x1:0,x2:n,y1:b,y2:b},`y_${b}_${n}`)}),ie.jsx("g",{strokeDasharray:Of(a.significantLinesStyle),stroke:Vt,children:v.map(C=>{let b=e(C);return ie.jsx("line",{x1:b,x2:b,y1:0,y2:r},`significant_${b}_${r}`)})}),ie.jsx("g",{strokeDasharray:Of(i.significantLinesStyle),stroke:Vt,children:g.map(C=>{let b=t(C);return ie.jsx("line",{x1:0,x2:n,y1:b,y2:b},`significant_${b}_${n}`)})}),o!=="empty"&&ie.jsxs("g",{strokeWidth:a6t,children:[(a.showGrid||o!=="left")&&ie.jsx("line",{stroke:o==="left"?Nf:Vt,x1:"0",x2:n,y1:r,y2:r}),(a.showGrid||o!=="bottom")&&ie.jsx("line",{stroke:o==="bottom"?Nf:Vt,x1:"0",x2:"0",y1:"0",y2:r}),(a.showGrid||o==="full")&&ie.jsx("line",{stroke:o==="full"?Vt:Nf,x1:n,x2:n,y1:"0",y2:r}),(i.showGrid||o==="full")&&ie.jsx("line",{stroke:o==="full"?Vt:Nf,x1:"0",x2:n,y1:"0",y2:"0"})]})]})}var o6t=new hc("16px Manrope");function TZ(e,t){return typeof e=="string"?e:t.length?t[0].data[e.value]:""}function l6t(e,t,n=[]){let r=e.data,a=[`x: ${ni(e.x)}`,`y: ${ni(e.y)}`];t.label&&a.unshift(`${t.label}: ${r[t.label]}`);for(let i of n)a.push(`${i.label}: ${r[i.valueLabels??i.value]}`);return a}function s6t(e){return typeof e.r2>"u"?null:ie.jsxs(ie.Fragment,{children:[ie.jsx("tspan",{children:"R"}),ie.jsx("tspan",{fontSize:"10px",dy:"-8",children:"2"}),ie.jsx("tspan",{dy:"8",children:` = ${ni(e.r2)}`})]})}function u6t(e){return typeof e.pValue>"u"?null:ie.jsx("tspan",{children:`p-value = ${ni(e.pValue)}`})}function c6t(e){if(typeof e.coefficients>"u")return null;let{slope:t,slopeError:n,intercept:r,interceptError:a}=e.coefficients;return ie.jsx("tspan",{children:ie.jsx("tspan",{children:`slope = ${ni(t)} ± ${ni(n)}, intercept = ${ni(r)} ± ${ni(a)}`})})}function f6t(e){let t=[s6t(e),u6t(e),c6t(e)].filter(n=>n!==null);return ie.jsx(ie.Fragment,{children:t.map((n,r)=>ie.jsxs("tspan",{children:[n,ie.jsx("tspan",{children:r<t.length-1&&", "})]},r))})}var YM=3;function kZ(e,t,n,r){if(!r)return[];let a=[];for(let i of e){let o=i.label;if(!o)continue;let s=o6t.getTextMetrics(String(o));a.push({name:String(o),width:(s==null?void 0:s.width)??0,height:((s==null?void 0:s.actualBoundingBoxAscent)??0)+((s==null?void 0:s.actualBoundingBoxDescent)??0),x:t.x(i.x),y:t.y(i.y),xPosition:"right",yPosition:"middle",bbox:{minX:0,maxX:0,minY:0,maxY:0},dot:i,padding:n.dotSize(r.info.aes.dotSize,i.data)+YM})}return a}function d6t({facetKey:e,width:t,height:n,dimensions:r,scales:a,xAxis:i,yAxis:o,frameType:s,dotsData:c,facetSettings:f,trendsData:A,keyColumn:h,margins:v,chartSizes:g,tooltips:C,tooltipsContainer:b,captionsSizes:x,facetTitle:B,onlyPositive:k,layersData:P,aesGetters:I,tooltipsData:$}){let[N,F]=tn.useState(),{padding:Z}=r,{dots:ee}=c,le=i.showTicks?f3:0,Q=o.showTicks?f3:0,j=TZ(i.title,ee),U=TZ(o.title,ee),Y=r.chartEdgeSides.includes("left")||!(f!=null&&f.sharedY),X=r.chartEdgeSides.includes("bottom")||!(f!=null&&f.sharedX),te=r.chartEdgeSides.includes("left"),pe=r.chartEdgeSides.includes("bottom"),ae={left:v.left+r.left+Z.left,right:g.totalWidth-(v.left+r.left+Z.left),top:v.top+r.top+Z.top,bottom:g.totalHeight-(v.top+r.top+Z.top)},ge=!1,[me,fe]=tn.useState(()=>kZ(ee,a,I,P.find(Oe=>Oe.type==="dots"))),[Ce,De]=tn.useState(()=>AS(me,t,n,YM,YM)),[ke,$e]=tn.useState(null);tn.useEffect(()=>{fe(kZ(ee,a,I,P.find(Oe=>Oe.type==="dots")))},[ee,a,I,P]),tn.useEffect(()=>{let Oe=AS(me,t,n);De(Oe)},[me,t,n]);let je=N&&$.fixed;return ie.jsxs("g",{transform:`translate(${r.left+Z.left},${r.top+Z.top})`,children:[ge,B.length&&ie.jsxs("g",{children:[s==="full"&&ie.jsx("rect",{x:"0",y:-Z.top,height:Z.top,width:t,fill:"#F7F8FA",stroke:Vt}),B.map((Oe,ft)=>{let ze=B.length,Xe=(Z.top-BM*ze)/2;return ie.jsx("text",{fontSize:"14px",fontWeight:"500",fill:Vt,x:t/2,dy:Xe+BM/2-Z.top,y:ft*BM,textAnchor:"middle",dominantBaseline:"central",children:Oe},ft)})]}),ie.jsxs("g",{dominantBaseline:"central",textAnchor:"middle",fontWeight:"500",fontSize:"14px",fill:Vt,children:[pe&&ie.jsx("text",{x:t/2,y:n+Z.bottom-Ov-m9/2,children:j}),ge,te&&ie.jsx("text",{x:-Z.left+Ov+m9/2,y:n/2,transform:`rotate(-90,${-Z.left+Ov+m9/2},${n/2})`,children:U}),ge]}),ie.jsx(i6t,{width:t,height:n,scaleX:a.x,scaleY:a.y,axisX:i,axisY:o,frameType:s}),X&&ie.jsxs("g",{transform:`translate(0,${n})`,children:[ie.jsx(hS,{scale:a.x,orient:"bottom",onlyPositive:k.x,tickSize:le}),ge]}),Y&&ie.jsxs("g",{children:[ie.jsx(hS,{scale:a.y,orient:"left",onlyPositive:k.y,tickSize:Q}),ge]}),A&&A.map(({predict:Oe,getArea:ft,color:ze,data:Xe,bounded:tt,xBounds:qe,stats:gt},wt)=>{let[Xt,rr]=tt?qe:a.x.domain(),sr=(rr-Xt)/15,ra=Oe(Xt),vi=Oe(rr);if(isNaN(ra)||isNaN(vi))return null;let ea=I.dotColor(ze,Xe);return ie.jsxs("g",{children:[ie.jsx("text",{y:wt*20+20,fill:ea,x:t-8,textAnchor:"end",children:f6t(gt)}),ie.jsx("path",{d:ft(a.x,a.y,Zn.range(Xt,rr+sr/2,sr)),fill:ea,opacity:.2}),ie.jsx("line",{x1:a.x(Xt),x2:a.x(rr),y1:a.y(ra),y2:a.y(vi),stroke:ea})]},wt)}),P.map((Oe,ft)=>{if(Oe.type==="dots")return ie.jsxs("g",{children:[ee.map(ze=>{let Xe=je&&$.selectedData===ze,tt=ie.jsx("g",{transform:`translate(${a.x(ze.x)},${a.y(ze.y)})`,opacity:ze.dimmed?.3:1,onMouseOver:()=>$.onMouseOver(ze,e),onMouseLeave:()=>$.onMouseLeave(),children:Yc(I.dotShape(Oe.info.aes.dotShape,ze.data),I.dotSize(Oe.info.aes.dotSize,ze.data),I.dotColor(Oe.info.aes.dotFill,ze.data))},ze.id);return Xe?cu.createPortal(tt,N):tt}),Ce.map(ze=>{let{name:Xe,height:tt,bbox:qe,width:gt}=ze;return ie.jsx("g",{children:ie.jsxs("g",{transform:`translate(${qe.minX},${qe.minY})`,children:[ie.jsx("rect",{x:"0",y:"0",width:gt,height:tt,fill:"transparent",stroke:"none",onMouseOver:()=>$e(ze.dot),onMouseLeave:()=>$e(null)}),ie.jsx("text",{x:0,y:tt/2,stroke:"white",strokeWidth:2,paintOrder:"stroke",style:{pointerEvents:"none"},fontFamily:"Manrope",fontSize:"16px",dominantBaseline:"middle",children:Xe})]})},ze.dot.id)}),ke&&ie.jsxs("g",{transform:`translate(${a.x(ke.x)},${a.y(ke.y)})`,children:[Yc(I.dotShape(Oe.info.aes.dotShape,ke.data),I.dotSize(Oe.info.aes.dotSize,ke.data)+1,"white","white"),Yc(I.dotShape(Oe.info.aes.dotShape,ke.data),I.dotSize(Oe.info.aes.dotSize,ke.data),I.dotColor(Oe.info.aes.dotFill,ke.data))]},"activeDot")]},ft);if(Oe.type==="curve"&&!Oe.info.smoothing)return Oe.geoms.map((ze,Xe)=>ie.jsx("g",{children:ie.jsx("polyline",{points:ze.dots.map(tt=>`${a.x(tt.x)},${a.y(tt.y)}`).join(" "),fill:"none",stroke:I.lineColor(Oe.info.aes.lineColor,ze.data),strokeWidth:Oe.info.aes.lineWidth,strokeDasharray:Of(Oe.info.aes.lineShape)})},Xe));if(Oe.type==="curve"&&Oe.info.smoothing)return Oe.geoms.map((ze,Xe)=>ie.jsx("g",{children:ie.jsx("path",{d:C5().curve(S5).x(tt=>a.x(tt.x)).y(tt=>a.y(tt.y))(ze.dots)??"",fill:"none",stroke:I.lineColor(Oe.info.aes.lineColor,ze.data),strokeWidth:Oe.info.aes.lineWidth,strokeDasharray:Of(Oe.info.aes.lineShape)})},Xe))}),C.show&&$.selectedData&&$.currentFacet===e&&ie.jsx(fu,{content:l6t($.selectedData,h,C==null?void 0:C.content),x:a.x($.selectedData.x),y:a.y($.selectedData.y),active:!0,sideDistances:ae,fixed:$.fixed,onClose:$.onClose,container:b}),ie.jsxs("g",{children:[$.fixed&&ie.jsx("rect",{width:g.chartWidth,height:g.chartHeight,fill:"rgba(255, 255, 255, 0.8)"}),ie.jsx("g",{ref:Oe=>{Oe&&!N&&F(Oe)}})]})]})}function A6t({settingsId:e,chartSettings:t,chartSizes:n,chartsDimensions:r,facetKeys:a,facetSettings:i,scales:o,groupedDots:s,legendData:c,trendsData:f,columnsCount:A,margins:h,keyColumn:v,mainTitle:g,facetTitles:C,captionsSizes:b,onlyPositive:x,layersData:B,aesGetters:k,onTooltipHintSwitch:P}){let I=p3(P),[$,N]=tn.useState(),F=tn.useRef(null);tn.useEffect(()=>{F.current&&N(F.current)},[]);let{xAxis:Z,yAxis:ee,title:le,frame:Q,legend:j,tooltips:U}=t,Y=r[a[0]].padding,X=r[a[A-1]].padding,te=n.chartsWidth+WC,pe=Y.top;return ie.jsx(y3,{dataId:e,children:ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${n.totalWidth} ${n.totalHeight}`,width:n.totalWidth,height:n.totalHeight,children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${h.left},${h.top})`,fontFamily:"Manrope",children:[ie.jsx(w3,{title:g,show:le.show,position:le.position,leftPadding:Y.left,rightPadding:X.right,chartsWidth:n.chartsWidth}),a.map(ae=>ie.jsx(d6t,{facetKey:ae,scales:{x:o.x[ae],y:o.y[ae]},width:n.chartWidth,height:n.chartHeight,dimensions:r[ae],margins:h,chartSizes:n,facetSettings:i,xAxis:Z,yAxis:ee,frameType:Q.type,dotsData:s[ae],trendsData:f?f[ae]:null,tooltips:U,tooltipsContainer:$,keyColumn:v,facetTitle:C[ae],captionsSizes:b,layersData:B[ae],onlyPositive:x,aesGetters:k,tooltipsData:I},ae)),j.show&&ie.jsx("g",{transform:`translate(${te},${pe})`,children:ie.jsx(b3,{legendData:c})})]}),ie.jsx("g",{ref:F,style:{outline:"none"}})]})})}function h6t(e,t,n,r){let a=[];return e%n===n-1&&a.push("right"),e%n===0&&a.push("left"),e<n&&a.push("top"),(Math.ceil((e+1)/n)===r||Math.ceil((e+1)/n)===r-1&&e%n>(t-1)%n)&&a.push("bottom"),a}function p6t(e,t,n,r,a,i,o){let s=i.includes("left")||!(o!=null&&o.sharedY),c=i.includes("left")&&t.title!=="",f=i.includes("bottom")||!(o!=null&&o.sharedX),A=i.includes("bottom")&&e.title!=="",h=n.yAxisCaptionsWidth+2*_M,v=(t.showTicks?f3:0)+_M,g=c?m9+Ov:0,C=n.xAxisCaptionsWidth+2*_M,b=e.showTicks?f3:0,x=A?m9+Ov:0,B=h+v+g+YX,k=C+b+x+YX,P=Math.max(...r.map(I=>a[I].length));return{left:s?B:Ov,top:P===0?0:r3t*2+P*S9,bottom:f?k+8:Ov,right:Ov}}function v6t(e,t,n){let r=[];for(let a=0;a<t;a++)r.push(e.slice(a*n,a*n+n));return r}function m6t(e,t){let n=Math.floor(e/t),r=e-n*t;return[n,r]}function g6t(e){return typeof e=="object"&&e!==null&&"type"in e&&"value"in e&&e.type==="grouping"}function M3(e,t){return function(n,r){var a,i;if(th(n)&&t==="dotSize"){let{domain:o,range:s}=n,c=rv().domain(o).range(s)(Number(r[n.columnName.value]));return Math.max(1,c)}if(th(n)&&(t==="dotFill"||t==="lineColor")){let{domain:o,range:s,type:c="linear"}=n,f=T9(s,o,c),A=r[n.columnName.value];return A===null?zv.color:f(Number(A))}if(g6t(n)){let o=n.value;return(i=((a=e[o])==null?void 0:a[String(r[o])])??EM)==null?void 0:i[t]}return n}}function y6t(e){return{dotShape:M3(e,"dotShape"),dotColor:M3(e,"dotFill"),dotSize:M3(e,"dotSize"),lineShape:M3(e,"lineShape"),lineColor:M3(e,"lineColor"),trendColor:M3(e,"dotFill")}}var w6t=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"component",ie.jsx(ie.Fragment,{}));Be(this,"margins",{top:Gc,bottom:Gc,left:Gc,right:Gc});Be(this,"chartsDimensions",{});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,chartsWidth:600,chartsHeight:350,totalWidth:600,totalHeight:350});Be(this,"columnsCount",1);Be(this,"rowsCount",1);Be(this,"scales",{x:{null:Zr().domain([0,10]).range([0,600])},y:{null:Zr().domain([0,10]).range([350,0])}});Be(this,"captionsSizes",{xAxisCaptionsWidth:30,yAxisCaptionsWidth:100});Be(this,"facetTitles",{});Be(this,"mainTitle",[]);Be(this,"legend",{width:0,height:0,items:[]})}clear(){var e;this.parentNode&&this.rootNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),this.parentNode=null,this.rootNode=null),setTimeout(()=>{var t;(t=this.reactRoot)==null||t.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.reactRoot=Qh(this.rootNode))}updateChartSizes(e){this.chartSizes.chartWidth=e.width,this.chartSizes.chartHeight=e.height}updateChartDimensions(e,t,n,r){let{chartWidth:a,chartHeight:i}=this.chartSizes,o=0,s=0;this.chartsDimensions=e.reduce((A,h,v)=>{let[g,C]=m6t(v,this.columnsCount),b=h6t(v,e.length,this.columnsCount,this.rowsCount),x=p6t(n,r,this.captionsSizes,v6t(e,this.rowsCount,this.columnsCount)[g],this.facetTitles,b,t),B=a+x.left+x.right,k=i+x.top+x.bottom;return A[h]={left:o,top:s,chartEdgeSides:b,padding:x,inner:{width:a,height:i},outer:{width:B,height:k}},o+=B,C===this.columnsCount-1&&(o=0,s+=k),A},{});let c=Math.max(...e.map(A=>this.chartsDimensions[A].outer.width+this.chartsDimensions[A].left)),f=Math.max(...e.map(A=>this.chartsDimensions[A].outer.height+this.chartsDimensions[A].top));this.chartSizes.chartsWidth=c,this.chartSizes.chartsHeight=f}updateViewport(e,t,n,r,a,i){let o=e.length,s=Math.min(t.nRows??o,o),c=Math.min(t.nCols??o,o);this.columnsCount=t.nRows?Math.ceil(o/s):c,this.rowsCount=Math.ceil(o/this.columnsCount);let[f,A]=[1/0,-1/0],[h,v]=[1/0,-1/0],g=e.reduce((b,x)=>{let B=a[x],{minX:k,minY:P,maxX:I,maxY:$}=B;return f=Math.min(f,k),h=Math.min(h,P),A=Math.max(A,I),v=Math.max(v,$),b[x]={minX:k,maxX:I,minY:P,maxY:$},b},{});e.forEach(b=>{let x=n.scale==="log"?j2():Zr(),B=g[b],k=n.lowerValue?Number(n.lowerValue):t.sharedX?f:B.minX,P=n.upperValue?Number(n.upperValue):t.sharedX?A:B.maxX;if(typeof n.symmetricRange<"u"){let N=n.symmetricRange;if(N>=k&&N<=P){let F=Math.max(N-k,P-N);k=N-F,P=N+F}}let I=[0,this.chartSizes.chartWidth],$=x.copy().domain([k,P]).range([YC.LEFT,this.chartSizes.chartWidth-YC.RIGHT]);x.domain([$.invert(0),$.invert(this.chartSizes.chartWidth)]).range(I).nice(),this.scales.x[b]=x});let C=e.reduce((b,x)=>{let B=i?i[x]:[];return b[x]=B.reduce((k,P)=>{let I=P.bounded?P.xBounds:this.scales.x[x].domain(),$=P.getInterval(I[0]),N=P.getInterval(I[1]);return k.minY=Math.min(k.minY,isNaN($.left)?k.minY:$.left,isNaN(N.left)?k.minY:N.left),k.maxY=Math.max(k.maxY,isNaN($.right)?k.maxY:$.right,isNaN(N.right)?k.maxY:N.right),k},{minY:1/0,maxY:-1/0}),h=Math.min(h,b[x].minY),v=Math.max(v,b[x].maxY),b},{});e.forEach(b=>{let x=r.scale==="log"?j2():Zr(),B=g[b],k=C[b],P=r.lowerValue?Number(r.lowerValue):t.sharedY?h:Math.min(B.minY,k.minY),I=r.upperValue?Number(r.upperValue):t.sharedY?v:Math.max(B.maxY,k.maxY);if(typeof r.symmetricRange<"u"){let F=r.symmetricRange;if(F>=P&&F<=I){let Z=Math.max(F-P,I-F);P=F-Z,I=F+Z}}let $=[this.chartSizes.chartHeight,0],N=x.copy().domain([P,I]).range([this.chartSizes.chartHeight-YC.BOTTOM,YC.TOP]);x.domain([N.invert(this.chartSizes.chartHeight),N.invert(0)]).range($).nice(),this.scales.y[b]=x})}updateCaptionsSize(e){let t=new hc("600 14px Arial"),n=0;function r(a){return Math.max(...a.map(i=>t.getTextWidth(i)))}Object.values(this.scales.y).forEach(a=>{let{ticks:i,format:o}=_9(a,e);n=Math.max(n,r(i.map(o)))}),this.captionsSizes={xAxisCaptionsWidth:20,yAxisCaptionsWidth:n}}createMainTitle(e,t){let n=this.chartsDimensions[e[0]],r=this.chartsDimensions[e[e.length-1]];this.mainTitle=jv(t.name,this.chartSizes.chartsWidth-n.padding.left-r.padding.right,20)}createFacetTitles(e,t){this.facetTitles=e.reduce((n,r,a)=>(t[a].length===1&&t[a][0]==="null"?n[r]=[]:n[r]=jv(t[a].join(", "),this.chartSizes.chartWidth,14),n),{})}updateMargins(){let e=24*this.mainTitle.length,t=e>0?e+24*2:0;this.margins={top:Math.max(t,Gc),bottom:Gc,left:Gc,right:this.legend.width+Gc},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartsWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+Math.max(this.chartSizes.chartsHeight,this.legend.height)+this.margins.bottom}updateLegendSize(e,t,n,r){if(!e.show){this.legend={width:0,height:0,items:[]};return}let a=[],i={width:0,height:0,left:0,top:0};if(n.forEach(A=>{let h=t[A.value];if(h.usedAes.length===0||!h.aesMap)return;let v={};h.values.forEach(b=>{v[b]||(v[b]={...zv}),h.usedAes.forEach(x=>{var B,k,P;(x==="dotFill"||x==="lineColor")&&(v[b].color=((B=h.aesMap[b])==null?void 0:B[x])??Vt),x==="dotShape"&&(v[b].shape=((k=h.aesMap[b])==null?void 0:k[x])??"21"),x==="dotSize"&&(v[b].size=((P=h.aesMap[b])==null?void 0:P[x])??3)})});let g=A.label??A.value,C=Qo().domain(h.values).range(h.values.map(b=>v[b])).unknown(zv);a.push({...i,id:A.value,type:"dots",title:g,scale:C,values:h.values,labels:h.labels})}),r.forEach(A=>{if(A.type==="dots"&&th(A.aes.dotFill)){let{domain:h,range:v,columnName:g,type:C="linear"}=A.aes.dotFill,b=g.label??g.value,x=T9(v,h,"linear"),B=(C==="log"?nv():Zr()).domain(h).range([this.chartSizes.chartHeight,0]),k=h3(B,h);a.push({...i,id:"dotFill",type:"continuous",title:b,scale:x,tickPositionScale:B,values:k})}if(A.type==="dots"&&th(A.aes.dotSize)){let{columnName:h,domain:v,range:g}=A.aes.dotSize,C=h.label??h.value,b=rv(v,g),x=b.ticks(3),B=b.tickFormat(3),k=x.reduce((P,I)=>(P[String(I)]=B(I),P),{});a.push({...i,id:h.value,type:"size",title:C,scale:b,values:x,labels:k})}}),!a.length){this.legend={width:0,height:0,items:[]};return}let o=S3(a,this.chartSizes.chartHeight),s=o[o.length-1],c=s.left+s.width+WC,f=this.chartSizes.chartHeight;this.legend={width:c,height:f,items:o}}render(e,t,n,r,a,i,o,s,c,f,A,h,v,g,C){var $;let{xAxis:b,yAxis:x,size:B,title:k,legend:P}=t;this.updateChartSizes(B),this.updateViewport(r,n,b,x,i,o),this.updateCaptionsSize(c.y),this.createFacetTitles(r,a),this.updateChartDimensions(r,n,b,x),this.updateLegendSize(P,f,v,g),this.createMainTitle(r,k),this.updateMargins();let I=ie.jsx(A6t,{settingsId:e,chartSettings:t,facetKeys:r,facetSettings:n,chartSizes:this.chartSizes,chartsDimensions:this.chartsDimensions,scales:this.scales,groupedDots:i,trendsData:o,legendData:this.legend,columnsCount:this.columnsCount,margins:this.margins,keyColumn:s,mainTitle:this.mainTitle,facetTitles:this.facetTitles,captionsSizes:this.captionsSizes,onlyPositive:c,layersData:A,aesGetters:y6t(h),onTooltipHintSwitch:C});this.component=I,($=this.reactRoot)==null||$.render(I)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},b6t=w6t,C6t=class{constructor(e){Be(this,"type","dots");Be(this,"aes",{dotFill:Vt,dotShape:"21",dotSize:3,opacity:1});this.aes={...this.aes,...e.aes}}},S6t=class{constructor(e){Be(this,"type","curve");Be(this,"smoothing");Be(this,"aes",{lineColor:Vt,lineWidth:1,lineShape:"solid",opacity:1});this.smoothing=e.smoothing??!1,this.aes={...this.aes,...e.aes}}},MZ=class{constructor(e){Be(this,"id");Be(this,"type","scatterplot");Be(this,"keyColumn");Be(this,"facetSettings");Be(this,"x");Be(this,"y");Be(this,"facetBy");Be(this,"grouping");Be(this,"label");Be(this,"highlight");Be(this,"chartSettings");Be(this,"inheritedAes");Be(this,"trend");Be(this,"layers");var t,n,r,a;R3t.parse(e),this.id=Zn.uniqueId("settings"),this.keyColumn=e.keyColumn,this.facetSettings={sharedX:!0,sharedY:!0,titlePosition:"left",...e.facetSettings},this.x=e.x,this.y=e.y,this.facetBy=e.facetBy??[],this.grouping=e.grouping??[],this.label=e.label??null,this.highlight=e.highlight??null,this.chartSettings={size:{width:((t=e==null?void 0:e.size)==null?void 0:t.width)??(this.facetBy.length?400:600),height:((n=e==null?void 0:e.size)==null?void 0:n.height)??(this.facetBy.length?250:350)},title:{position:"center",show:!0,...e.title,name:((r=e.title)==null?void 0:r.name)??"Chart"},yAxis:{title:e.y.label??e.y.value,scale:"linear",showGrid:!0,showTicks:!0,...e.yAxis},xAxis:{title:e.x.label??e.x.value,scale:"linear",showGrid:!0,showTicks:!0,...e.xAxis},frame:{type:((a=e.frame)==null?void 0:a.type)??"full"},legend:{show:!0,position:"right",...e.legend},tooltips:{show:!0,...e.tooltips}},this.inheritedAes=e.inheritedAes??{},this.trend=e!=null&&e.trend?{bounded:e.trend.bounded??!1,color:e.trend.color??Vt}:null,this.layers=e.layers.map(i=>{if(i.type==="dots")return new C6t(i);if(i.type==="curve")return new S6t(i);f1(i,"Unknown layer type")}).filter(Boolean)}},x6t=Xht(G5t()),PZ=.05;function E6t(e){let t=3.3871328727963665,n=133.14166789178438,r=1971.5909503065513,a=13731.69376550946,i=45921.95393154987,o=67265.7709270087,s=33430.57558358813,c=2509.0809287301227,f=42.31333070160091,A=687.1870074920579,h=5394.196021424751,v=21213.794301586597,g=39307.89580009271,C=28729.085735721943,b=5226.495278852854,x=1.4234371107496835,B=4.630337846156546,k=5.769497221460691,P=3.6478483247632045,I=1.2704582524523684,$=.2417807251774506,N=.022723844989269184,F=.0007745450142783414,Z=2.053191626637759,ee=1.6763848301838038,le=.6897673349851,Q=.14810397642748008,j=.015198666563616457,U=.0005475938084995345,Y=10507500716444169e-25,X=6.657904643501103,te=5.463784911164114,pe=1.7848265399172913,ae=.29656057182850487,ge=.026532189526576124,me=.0012426609473880784,fe=27115555687434876e-21,Ce=20103343992922881e-23,De=.599832206555888,ke=.1369298809227358,$e=.014875361290850615,je=.0007868691311456133,Oe=18463183175100548e-21,ft=1421511758316446e-22,ze=20442631033899397e-31,Xe=e-.5,tt,qe;return Math.abs(Xe)<=.425?(tt=.180625-Xe*Xe,qe=Xe*(((((((c*tt+s)*tt+o)*tt+i)*tt+a)*tt+r)*tt+n)*tt+t)/(((((((b*tt+C)*tt+g)*tt+v)*tt+h)*tt+A)*tt+f)*tt+1),qe):(tt=e,tt=Math.sqrt(-Math.log(tt)),tt<=5?(tt+=-1.6,qe=(((((((F*tt+N)*tt+$)*tt+I)*tt+P)*tt+k)*tt+B)*tt+x)/(((((((Y*tt+U)*tt+j)*tt+Q)*tt+le)*tt+ee)*tt+Z)*tt+1)):(tt+=-5,qe=(((((((Ce*tt+fe)*tt+me)*tt+ge)*tt+ae)*tt+pe)*tt+te)*tt+X)/(((((((ze*tt+ft)*tt+Oe)*tt+je)*tt+$e)*tt+ke)*tt+De)*tt+1)),qe=-qe,qe)}function HZ(e,t){let{sin:n,cos:r,sqrt:a,pow:i,exp:o,PI:s}=Math,c,f;if(t==1)return r(e*s/2)/n(e*s/2);if(t==2)return a(2/(e*(2-e))-2);let A=1/(t-.5),h=48/(A*A),v=((20700*A/h-98)*A-16)*A+96.36,g=((94.5/(h+v)-3)/h+1)*a(A*s*.5)*t;return c=g*e,f=i(c,2/t),f>.05+A?(c=E6t(e/2),f=c*c,t<5&&(v=v+.3*(t-4.5)*(c+.6)),v=(((.05*g*c-5)*c-7)*c-2)*c+h+v,f=(((((.4*f+6.3)*f+36)*f+94.5)/v-f-3)/h+1)*c,f=A*f*f,f>.002?f=o(f)-1:f=.5*f*f+f):f=((1/(((t+6)/(t*f)-.089*g-.822)*(t+2)*3)+.5/(t+4))*f-1)*(t+1)/(t+2)+1/f,a(t*f)}function B6t(e){let t=e.length,n=0,r=0,a=0,i=0;for(let c=0;c<e.length;++c){let f=e[c].x,A=e[c].y;if(!Number.isFinite(f)||!Number.isFinite(A)){--t;continue}n+=f,r+=A,a+=f*A,i+=f*f}let o=(t*a-n*r)/(t*i-n*n),s=(r-o*n)/t;return[o,s]}function _6t(e,t,n){let r=A=>A*t+n,a=e.length,i=lc(e,A=>A.x)/e.length,o=HZ(PZ,a-2),s=Math.sqrt(lc(e,A=>(A.y-r(A.x))**2)/(a-2)/lc(e,A=>(A.x-i)**2)),c=s*o,f=s*Math.sqrt(lc(e,A=>A.x**2)/a)*o;return{slope:t,intercept:n,slopeError:c,interceptError:f}}function T6t(e,t){let n=lc(e,s=>s.x)/e.length,r=0,a=0;for(let s=0;s<e.length;++s)r+=Math.pow(e[s].x-n,2),a+=Math.pow(e[s].y-t(e[s].x),2);let i=Math.sqrt(a/(e.length-2)),o=HZ(PZ,e.length-2);return function(s){let c=t(s),f=i*Math.sqrt(1/e.length+Math.pow(s-n,2)/r),A=c-o*f,h=c+o*f;return{x:s,y:c,left:isNaN(A)?c:A,right:isNaN(h)?c:h}}}function k6t(e){let t=e.length;return Math.pow((t*lc(e,n=>n.x*n.y)-lc(e,n=>n.x)*lc(e,n=>n.y))/(Math.sqrt(t*lc(e,n=>n.x*n.x)-Math.pow(lc(e,n=>n.x),2))*Math.sqrt(t*lc(e,n=>n.y*n.y)-Math.pow(lc(e,n=>n.y),2))),2)}function M6t(e,t){let n=Vs(e,t);return Vs(e.map(r=>(t(r)-n)**2))}function DZ(e,t){return Math.sqrt(M6t(e,t))}function P6t(e,t,n){let r=Vs(e,t),a=Vs(e,n),i=e.length;return lc(e,o=>(o.x-r)*(o.y-a))/i}function H6t(e){let t=P6t(e,a=>a.x,a=>a.y),n=DZ(e,a=>a.x),r=DZ(e,a=>a.y);return t/(n*r)}function D6t(e,t){let n=e.length,r=1,a=1,i=n-r-1,o=Vs(e,v=>v.y),s=lc(e,v=>(t(v.x)-o)**2),c=lc(e,v=>(t(v.x)-v.y)**2),f=s/a,A=c/i,h=f/A;return 1-(0,x6t.default)(h,a,i)}function $6t(e,t,n,r,a){return a?t.reduce((i,o)=>{let s=e[o].dots;return i[o]=n.map(c=>{let f=s.filter(x=>r.every((B,k)=>String(x.data[B.value])===c[k])),[A=0,h=0]=M0(f,x=>x.x),[v,g]=B6t(f),C=x=>v*x+g,b=T6t(f,C);return{predict:C,getInterval:b,getArea:(x,B,k)=>KB().x(P=>x(P.x)).y0(P=>B(P.left)).y1(P=>B(P.right))(k.map(b))??"",color:a.color,bounded:a.bounded,data:f[0].data,showStats:!0,xBounds:[A,h],stats:{r2:k6t(f),r:H6t(f),pValue:D6t(f,C),coefficients:_6t(f,v,g)}}}),i},{}):null}function $Z(e){if(!e.length)return[];let t=[[]];return e.forEach(n=>{let r=[];n.forEach(a=>{r.push(...t.map(i=>[...i,a]))}),t=r}),t}function IZ(e){return typeof e=="object"&&"type"in e&&e.type==="grouping"}function I6t(e,t,n,r){return t.reduce((a,i)=>{let o=Zn.uniqBy(e.rows,h=>h[i.value]),s=h=>String(h[i.value]),c=h=>i.valueLabels?String(h[i.valueLabels]):s(h),f=new Set;n.forEach(h=>{h.aes&&Object.entries(h.aes).forEach(([v,g])=>{IZ(g)&&g.value===i.value&&f.add(v)})});let A=o.reduce((h,v)=>(h[s(v)]=c(v),h),{});return a[i.value]={values:o.map(s).filter(h=>h!=="null").sort((h,v)=>A[h].localeCompare(A[v],"en",{numeric:!0})),usedAes:[...f],aesMap:r[i.value],labels:A},a},{})}var L6t=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new b6t);Be(this,"onTooltipHintSwitch",()=>{});Be(this,"calculatedData",null);this.settings=new MZ(n),r&&(this.onTooltipHintSwitch=r[1])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new MZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){console.warn("no chart state for scatterplot")}export(){return this._updateChart(),b5(this.chartRenderer.component)}_needUpdateCalculatedDataBySettings(t,n){var r,a,i,o;return t.facetBy.some((s,c)=>{var f;return s.value!==((f=n.facetBy[c])==null?void 0:f.value)})||t.grouping.length!==n.grouping.length||t.grouping.some((s,c)=>{var f;return s.value!==((f=n.grouping[c])==null?void 0:f.value)})||(((r=t.label)==null?void 0:r.value)||((a=n.label)==null?void 0:a.value))&&((i=t.label)==null?void 0:i.value)!==((o=n.label)==null?void 0:o.value)||t.layers.length!==n.layers.length||t.layers.some((s,c)=>s.type!==n.layers[c].type)||!!t.trend!=!!n.trend}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{x:t,y:n,facetBy:r,grouping:a,keyColumn:i,trend:o,layers:s,inheritedAes:c,label:f,highlight:A}=this.settings,h=this.data.getColumnCategories(i.value),v=r.map(F=>this.data.getColumnCategories(F.value)),g=a.map(F=>this.data.getColumnCategories(F.value)),C=v.length?$Z([...v]):[["null"]],b=g.length?$Z([...g]):[["null"]],x=r.map(F=>F.value)??null;this.data.setGrouping([...x,i.value]);let B={x:this.data.rows.every(F=>{let Z=F[t.value];return Z===null||!(Number(Z)<0)}),y:this.data.rows.every(F=>{let Z=F[n.value];return Z===null||!(Number(Z)<0)})},k=Y9t(this.data,C,t,n,f,A,h),P=Object.keys(k),I=$6t(k,P,b,a,o),$=I6t(this.data,a,s,c),N=W9t(s,P,k,b,a);this.calculatedData={onlyPositive:B,dotsByFacets:k,facetKeys:P,facetKeysCombinations:C,trendsData:I,legendLabels:$,layersData:N}}_updateAesInData(){let t=this.calculatedData;if(!t)return;let{grouping:n,trend:r,layers:a,inheritedAes:i}=this.settings,{facetKeys:o,trendsData:s}=t;o.forEach(c=>{for(let f=0;f<a.length;f++)t.layersData[c][f].info=a[f]}),n.forEach(c=>{let f=new Set;a.forEach(A=>{A.aes&&Object.entries(A.aes).forEach(([h,v])=>{IZ(v)&&v.value===c.value&&f.add(h)})}),t.legendLabels[c.value].usedAes=[...f],t.legendLabels[c.value].aesMap=i[c.value]}),s&&r&&Object.keys(s).forEach(c=>{s[c].forEach(f=>{f.color=r.color,f.bounded=r.bounded})})}_updateChart(){if(!this.calculatedData)return;let{id:t,chartSettings:n,facetSettings:r,grouping:a,keyColumn:i,inheritedAes:o,layers:s}=this.settings;this.chartRenderer.render(t,n,r,this.calculatedData.facetKeys,this.calculatedData.facetKeysCombinations,this.calculatedData.dotsByFacets,this.calculatedData.trendsData,i,this.calculatedData.onlyPositive,this.calculatedData.legendLabels,this.calculatedData.layersData,o,a,s,this.onTooltipHintSwitch)}},pS={TOP:30,BOTTOM:30,LEFT:30,RIGHT:30},k9=20,LZ=4,RZ=24;function R6t(e,t,n=[]){let r=e.data,a=[`x: ${ni(e.x)}`,`y: ${ni(e.y)}`];t.label&&a.unshift(`${t.label}: ${r[t.label]}`);for(let i of n)a.push(`${i.label}: ${r[i.valueLabels??i.value]}`);return a}function VZ(e){return typeof e=="string"?e:e.label??e.value}var NZ=C5().curve(S5);function V6t({scales:e,chartSettings:t,mainTitle:n,keyColumn:r,margins:a,chartSizes:i,onlyPositive:o,container:s,zoomStateKey:c,legendData:f,dotsByGrouping:A,layers:h,aesGetters:v,tooltipData:g}){var j;let{title:C,xAxis:b,yAxis:x,frame:B,legend:k}=t,P=b.showTicks?LZ:0,I=x.showTicks?LZ:0,$=b.title,N=x.title,F={left:0,right:i.chartWidth,top:0,bottom:i.chartHeight};if(!s)return null;let Z=h.find(U=>U.type==="curve"),[ee,le]=tn.useState([]);function Q(){let U=Object.entries(A).map(([Y,X])=>({key:Y,d:Z!=null&&Z.smoothing?NZ(X)??"":X.map(te=>`${e.x(te.x)},${e.y(te.y)}`).join(" "),dot:X[0]}));le(U)}return tn.useEffect(()=>{Z&&(NZ.x(U=>e.x(U.x)).y(U=>e.y(U.y)),Q())},[c]),tn.useEffect(()=>{Z&&Q()},[Z==null?void 0:Z.smoothing]),ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${i.totalWidth} ${i.totalHeight}`,width:i.totalWidth,height:i.totalHeight,style:{pointerEvents:"none"},children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${a.left},${a.top})`,fontFamily:"Manrope",children:[ie.jsx("clipPath",{id:"viewportClipPath",children:ie.jsx("rect",{x:"0",y:"0",width:i.chartWidth,height:i.chartHeight})}),ie.jsx(w3,{title:n,show:C.show,position:C.position,leftPadding:a.left,rightPadding:a.right,chartsWidth:i.chartWidth}),ie.jsxs("g",{dominantBaseline:"central",textAnchor:"middle",fontWeight:"500",fontSize:"14px",fill:Vt,children:[$&&ie.jsx("text",{x:i.chartWidth/2,y:i.chartHeight+a.bottom-k9/2,children:VZ($)}),N&&ie.jsx("text",{x:-a.left+k9/2,y:i.chartHeight/2,transform:`rotate(-90,${-a.left+k9/2},${i.chartHeight/2})`,children:VZ(N)})]}),ie.jsx(yZ,{width:i.chartWidth,height:i.chartHeight,scaleX:e.x,scaleY:e.y,axisX:b,axisY:x,updatingKey:c,frameType:B.type}),ie.jsx("g",{transform:`translate(0,${i.chartHeight})`,children:ie.jsx(hS,{scale:e.x,orient:"bottom",onlyPositive:o.x,tickSize:P})}),ie.jsx("g",{children:ie.jsx(hS,{scale:e.y,orient:"left",onlyPositive:o.y,tickSize:I})}),Z&&Z.smoothing&&ie.jsx("g",{clipPath:"url(#viewportClipPath)",children:ee.map(({key:U,d:Y,dot:X})=>{var te;return ie.jsx("path",{d:Y,fill:"none",stroke:v.dotFill(X.data),strokeWidth:(te=Z.aes)==null?void 0:te.lineWidth,strokeDasharray:v.lineType(X.data)},U)})}),Z&&!Z.smoothing&&ie.jsx("g",{clipPath:"url(#viewportClipPath)",children:ee.map(({key:U,d:Y,dot:X})=>{var te;return ie.jsx("polyline",{points:Y,fill:"none",stroke:v.dotFill(X.data),strokeWidth:(te=Z.aes)==null?void 0:te.lineWidth,strokeDasharray:v.lineType(X.data)},U)})}),g.selectedData&&ie.jsx(fu,{content:R6t(g.selectedData,r,(j=t.tooltips)==null?void 0:j.content),x:e.x(g.selectedData.x),y:e.y(g.selectedData.y),active:!0,fixed:g.fixed,sideDistances:F,container:s,onClose:g.onClose}),k.show&&ie.jsx("g",{transform:`translate(${i.chartWidth+RZ},0)`,children:ie.jsx(b3,{legendData:f})})]})]})}var N6t=k8.memo(V6t),z6t=20;function O6t({scales:e,chartSizes:t,disabled:n,onPolygonUpdate:r}){let[a,i]=tn.useState([]),[o,s]=tn.useState(null),[c,f]=tn.useState(null),A=tn.useRef(null),h=tn.useRef(null),v=tn.useRef(null),g=tn.useRef(a);function C(){A.current=null,h.current=null,v.current=null,g.current=[],i([]),s(null)}function b(k){n||k.key!=="Escape"||C()}tn.useEffect(()=>{n&&(A.current=null,h.current=null,v.current=null,s(null))},[n]),tn.useEffect(()=>(document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)),[]),tn.useEffect(()=>{if(o&&c)return;if(a.length===0){r([]);return}let k=a.map(P=>P[0]);k.push(a[a.length-1][1]),r(k)},[a]);function x(){if(!A.current||n)return;let k=[...A.current],P=e.x.invert(k[0]),I=e.y.invert(k[1]),$=g.current,N=v.current,F=h.current&&$.length>1?Math.sqrt((k[0]-h.current[0])**2+(k[1]-h.current[1])**2):1/0;v.current?v.current&&F>z6t?($=[...$,[v.current,[P,I]]],N=[P,I]):($=[...$,[v.current,[P,I]]],$.length>2&&($=[...$,[$[$.length-1][1],$[0][0]]]),N=null,$.length<=2?r([]):r($.map(Z=>Z[0])),h.current=null):(h.current=k,$=[],N=[P,I],r([])),i($),s(N),g.current=$,v.current=N}function B(k){let P=[k.nativeEvent.offsetX,k.nativeEvent.offsetY];f(P),A.current=P}return ie.jsxs("g",{children:[ie.jsx("rect",{fill:"transparent",width:t.chartWidth,height:t.chartHeight,onMouseMove:B,onClick:x}),a.map(([k,P],I)=>ie.jsx("line",{x1:e.x(k[0]),y1:e.y(k[1]),x2:e.x(P[0]),y2:e.y(P[1]),stroke:Vt,style:{pointerEvents:"none"}},I)),o&&c&&ie.jsx("line",{x1:e.x(o[0]),y1:e.y(o[1]),x2:c[0],y2:c[1],stroke:Vt,style:{pointerEvents:"none"}},"lastLine")]})}function F6t({scales:e,container:t,labels:n,aesGetters:r,chartSizes:a,onPolygonUpdate:i,lassoMode:o,tooltipData:s}){return t?ie.jsxs("g",{children:[n.map(c=>{let{name:f,height:A,bbox:h,width:v}=c;return ie.jsx("g",{children:ie.jsxs("g",{transform:`translate(${h.minX},${h.minY})`,children:[ie.jsx("rect",{x:"0",y:"0",width:v,height:A,fill:"transparent",stroke:"none"}),ie.jsx("text",{x:0,y:A/2,stroke:"white",strokeWidth:2,paintOrder:"stroke",style:{pointerEvents:"none"},fontFamily:"Manrope",fontSize:"16px",dominantBaseline:"middle",children:f})]})},c.dot.id)}),ie.jsx(O6t,{scales:e,chartSizes:a,disabled:!o,onPolygonUpdate:i}),s.fixed&&ie.jsx("rect",{width:a.chartWidth,height:a.chartHeight,fill:"rgba(255,255,255,0.8)"}),s.selectedData&&ie.jsx("circle",{cx:e.x(s.selectedData.x),cy:e.y(s.selectedData.y),r:Math.max(r.dotSize(s.selectedData.data)*1.2,5),fill:r.dotFill(s.selectedData.data)})]}):null}var Q6t=F6t;function j6t({settingsId:e,scales:t,chartSettings:n,mainTitle:r,keyColumn:a,margins:i,chartSizes:o,captionsSizes:s,onlyPositive:c,container:f,zoomStateKey:A,aesGetters:h,legendData:v,labels:g,onPolygonUpdate:C,onTooltipHintSwitch:b,lassoMode:x,dotsByGrouping:B,layers:k,selectedDot:P=null}){if(!f)return null;let I=p3(b);return tn.useEffect(()=>{P?I.onMouseOver(P):I.onMouseLeave()},[P]),ie.jsx("div",{children:ie.jsxs(y3,{dataId:e,children:[ie.jsx(N6t,{aesGetters:h,dotsByGrouping:B,layers:k,scales:t,keyColumn:a,margins:i,mainTitle:r,captionsSizes:s,chartSettings:n,chartSizes:o,onlyPositive:c,container:f,zoomStateKey:A,legendData:v,tooltipData:I}),cu.createPortal(ie.jsx(Q6t,{scales:t,container:f,aesGetters:h,labels:g,chartSizes:o,selectedDot:P,onPolygonUpdate:C,lassoMode:x,tooltipData:I}),f)]})})}var zZ=e=>e.selection()!==e,OZ=(e,t)=>{e=e||"g";let n=(i,o)=>o,r=null,a=function(i,o){o=o||(g=>g);let s=i.selection(),c=zZ(i)?i:null,f=s.selectChildren(t==null?e:`${e}.${t}`).data(o,n),A=f.enter().append(e).attr("class",t),h=f.exit();f=f.merge(A);let v=c||r;return v&&(f=f.transition(v).style("opacity",1),A.style("opacity",1e-6),h=h.transition(v).style("opacity",1e-6)),h.remove(),f.enter=()=>A,f.exit=()=>h,f};return a.element=(...i)=>i.length?(e=i[0],a):e,a.className=(...i)=>i.length?(t=i[0],a):t,a.key=(...i)=>i.length?(n=i[0],a):n,a.transition=(...i)=>i.length?(r=i[0],a):r,a},FZ=(e,t,n)=>{let r=t[n];if(typeof r!="function")throw new Error(`Attempt to rebind ${n} which isn't a function on the source object`);return(...a)=>{var i=r.apply(t,a);return i===t?e:i}},QZ=(e,t,...n)=>{for(let r of n)e[r]=FZ(e,t,r);return e},U6t=e=>t=>e.reduce((n,r)=>n&&r(n),t),WM=(e,t,...n)=>{let r=U6t(n);for(let a of Object.keys(t)){let i=r(a);i&&(e[i]=FZ(e,t,a))}return e},G6t=e=>e.map(t=>typeof t=="string"?new RegExp(`^${t}$`):t),Y6t=(...e)=>(e=G6t(e),t=>e.every(n=>!n.test(t))&&t),P3=e=>typeof e=="function"?e:()=>e;function W6t(){let e=arguments;return function(t,n){for(let r=0,a=e.length;r<a;r++)if(e[r](t,n)==null)return!1;return!0}}var X6t=(e,t)=>{switch(e){case"left":return t/2;case"right":return-t/2;default:return 0}},jZ=e=>{let t=Object.assign({},e),n=()=>{};return Object.keys(t).forEach(r=>{n[r]=(...a)=>a.length?(t[r]=a[0],n):t[r]}),n},K6t=()=>{let e=()=>0,t=s=>s.x,n=s=>s.y,r="center",a=()=>5,i="vertical",o=jZ({decorate:()=>{},defined:(s,c)=>W6t(e,t,n)(s,c),xScale:tv(),yScale:tv()});return o.values=(s,c)=>{let f=a(s,c),A=X6t(r,f),h=o.xScale(),v=o.yScale();if(i==="vertical"){let g=v(n(s,c),c),C=v(e(s,c),c),b=h(t(s,c),c)+A;return{d:s,x:b,y:g,y0:C,width:f,height:g-C,origin:[b,g],baseOrigin:[b,C],transposedX:b,transposedY:g}}else{let g=h(n(s,c),c),C=h(e(s,c),c),b=v(t(s,c),c)+A;return{d:s,x:b,y:g,y0:C,width:f,height:g-C,origin:[g,b],baseOrigin:[C,b],transposedX:g,transposedY:b}}},o.xValues=()=>i==="vertical"?[t]:[e,n],o.yValues=()=>i!=="vertical"?[t]:[e,n],o.baseValue=(...s)=>s.length?(e=P3(s[0]),o):e,o.crossValue=(...s)=>s.length?(t=P3(s[0]),o):t,o.mainValue=(...s)=>s.length?(n=P3(s[0]),o):n,o.bandwidth=(...s)=>s.length?(a=P3(s[0]),o):a,o.align=(...s)=>s.length?(r=s[0],o):r,o.orient=(...s)=>s.length?(i=s[0],o):i,o},Z6t=()=>{let e=K6t(),t=P3(64),n=uN,r=l9(),a=l9(),i=l9().type(eh.UNSIGNED_SHORT),o=l9().type(eh.UNSIGNED_BYTE),s=xht().crossValueAttribute(r).mainValueAttribute(a).sizeAttribute(i).definedAttribute(o),c=(C,b)=>!1,f=Hht,A=[],h=null,v=null,g=C=>{let b=f(e.xScale()),x=f(e.yScale()),B=!c(A,C);B&&(A=C,i.value((k,P)=>t(k,P)).data(C),o.value((k,P)=>e.defined()(k,P)).data(C)),(B||b.scale!==h)&&(h=b.scale,e.orient()==="vertical"?r.value((k,P)=>b.scale(e.crossValue()(k,P))).data(C):r.value((k,P)=>b.scale(e.mainValue()(k,P))).data(C)),(B||x.scale!==v)&&(v=x.scale,e.orient()==="vertical"?a.value((k,P)=>x.scale(e.mainValue()(k,P))).data(C):a.value((k,P)=>x.scale(e.crossValue()(k,P))).data(C)),s.xScale(b.webglScale).yScale(x.webglScale).type(Nht(n)).decorate(k=>e.decorate()(k,C,0)),s(C.length)};return g.size=(...C)=>C.length?(t=P3(C[0]),g):t,g.type=(...C)=>C.length?(n=C[0],g):n,g.equals=(...C)=>C.length?(c=C[0],g):c,g.scaleMapper=(...C)=>C.length?(f=C[0],g):f,WM(g,e,Y6t("baseValue","bandwidth","align")),QZ(g,s,"context","pixelRatio"),g},UZ=()=>{let e=[],t=a=>a,n=(a,i)=>i,r=jZ({decorate:()=>{},xScale:tv(),yScale:tv()});return r.xValues=()=>e.map(a=>a.xValues()).reduce((a,i)=>a.concat(i)),r.yValues=()=>e.map(a=>a.yValues()).reduce((a,i)=>a.concat(i)),r.mapping=(...a)=>a.length?(t=a[0],r):t,r.key=(...a)=>a.length?(n=a[0],r):n,r.series=(...a)=>a.length?(e=a[0],r):e,r},J6t=()=>{let e=UZ(),t=OZ("g"),n=OZ("g","multi"),r=a=>{zZ(a)&&(n.transition(a),t.transition(a));let i=e.mapping(),o=e.series(),s=e.xScale(),c=e.yScale();a.each((f,A,h)=>{let v=n(bs(h[A]),o);v.each((g,C,b)=>{g.xScale(s).yScale(c);let x=i(f,C,o);t(bs(b[C]),[x]).call(g)}),v.selection().order(),e.decorate()(v,f,A)})};return WM(r,e),QZ(r,n,"key"),r},q6t=()=>{let e=null,t=1,n=UZ(),r=a=>{let i=n.mapping(),o=n.series(),s=n.xScale(),c=n.yScale();o.forEach((f,A)=>{let h=i(a,A,o);f.context(e).pixelRatio(t).xScale(s).yScale(c);let v;f.decorate?(v=f.decorate(),f.decorate((g,C,b)=>{n.decorate()(g,a,A),v(g,C,b)})):n.decorate()(e,a,A),f(h),v&&f.decorate(v)})};return r.context=(...a)=>a.length?(e=a[0],r):e,r.pixelRatio=(...a)=>a.length?(t=a[0],r):t,WM(r,n),r};function GZ(e){return e/2.35*(e/2.35)*64}function XM(e,t){return e+(1-e)*(1-t)}function KM(e,t){return[XM(e.r/255,t),XM(e.g/255,t),XM(e.b/255,t),1]}function ewt(e){return typeof e=="object"&&e!==null&&"type"in e&&"value"in e&&e.type==="grouping"}function ZM(e={},t,n){return function(r){var a,i;if(ewt(n)){let o=n.value,s=r[o];return(i=((a=e[o])==null?void 0:a[String(s)])??EM)==null?void 0:i[t]}if(th(n)&&t==="dotFill"){let{domain:o,range:s,type:c="linear"}=n,f=T9(s,o,c),A=r[n.columnName.value];return A===null?zv.color:f(Number(A))}if(th(n)&&t==="dotSize"){let{domain:o,range:s}=n,c=rv().domain(o).range(s)(Number(r[n.columnName.value]));return Math.max(1,c)}return n}}function YZ(e,t){let n=t.find(a=>a.type==="dots"),r=t.find(a=>a.type==="curve");return{dotFill:ZM(e,"dotFill",(n==null?void 0:n.aes.dotFill)??zv.color),dotSize:ZM(e,"dotSize",(n==null?void 0:n.aes.dotSize)??zv.size),lineType:ZM(e,"lineShape",(r==null?void 0:r.aes.lineShape)??"solid")}}var twt=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"canvasNode",null);Be(this,"svgLayerElement",null);Be(this,"svgLayerComponent",ie.jsx(ie.Fragment,{}));Be(this,"aesGetters",{dotSize:()=>2,dotFill:()=>Vt,lineType:()=>"solid"});Be(this,"tools",null);Be(this,"margins",{top:Gc,bottom:Gc,left:Gc,right:Gc});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,totalWidth:600,totalHeight:350});Be(this,"scales",{x:Zr().domain([0,10]).range([0,600]),y:Zr().domain([0,10]).range([350,0]),xOriginal:Zr().domain([0,10]).range([0,600]),yOriginal:Zr().domain([0,10]).range([350,0])});Be(this,"polygon",[]);Be(this,"onPolygonUpdateOutside",()=>{});Be(this,"onTooltipHintSwitch",()=>{});Be(this,"zoomStateKey","");Be(this,"selectedDot",null);Be(this,"captionsSizes",{xAxisCaptionsWidth:30,yAxisCaptionsWidth:100});Be(this,"mainTitle",[]);Be(this,"legend",{width:0,height:0,items:[]});Be(this,"notCalculatedProps",{});Be(this,"allDots",[]);Be(this,"allPossibleLabels",[]);Be(this,"visibleLabels",[]);Be(this,"lassoMode",!1);Be(this,"onPolygonUpdate",e=>{this.polygon=e,this.updateByLasso();let t=this.allDots.filter(n=>this.polygon.length>2&&VC(this.polygon,[n.x,n.y])).map(n=>n.data.key);this.onPolygonUpdateOutside(t)})}clear(){var e,t;this.parentNode&&this.rootNode&&this.canvasNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),(t=this.parentNode)==null||t.removeChild(this.canvasNode),this.parentNode=null,this.rootNode=null,this.canvasNode=null,this.svgLayerElement=null,this.tools=null),setTimeout(()=>{var n;(n=this.reactRoot)==null||n.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.canvasNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.parentNode.appendChild(this.canvasNode),this.reactRoot=Qh(this.rootNode))}updateChartSizes(e){this.chartSizes.chartWidth=e.width,this.chartSizes.chartHeight=e.height}updateViewport(e,t,n){let r=e.scale==="log"?j2():Zr(),{minX:a,minY:i,maxX:o,maxY:s}=n;if(e.lowerValue!==void 0&&(a=Math.max(a,e.lowerValue)),e.upperValue!==void 0&&(o=Math.min(o,e.upperValue)),t.lowerValue!==void 0&&(i=Math.max(i,t.lowerValue)),t.upperValue!==void 0&&(s=Math.min(s,t.upperValue)),e.symmetricRange!==void 0){let g=e.symmetricRange;if(g>=a&&g<=o){let C=Math.max(g-a,o-g);a=g-C,o=g+C}}if(typeof t.symmetricRange<"u"){let g=t.symmetricRange;if(g>=i&&g<=s){let C=Math.max(g-i,s-g);i=g-C,s=g+C}}let c=[0,this.chartSizes.chartWidth],f=r.copy().domain([a,o]).range([pS.LEFT,this.chartSizes.chartWidth-pS.RIGHT]);r.domain([f.invert(0),f.invert(this.chartSizes.chartWidth)]).range(c).nice(),this.scales.x=r,this.scales.xOriginal=r.copy();let A=t.scale==="log"?j2():Zr(),h=[this.chartSizes.chartHeight,0],v=A.copy().domain([i,s]).range([this.chartSizes.chartHeight-pS.BOTTOM,pS.TOP]);A.domain([v.invert(this.chartSizes.chartHeight),v.invert(0)]).range(h).nice(),this.scales.y=A,this.scales.yOriginal=A.copy()}updateCaptionsSize(e){let t=new hc("600 14px Arial");function n(o){return Math.max(...o.map(s=>t.getTextWidth(s)))}let{ticks:r,format:a}=_9(this.scales.y,e),i=n(r.map(a));this.captionsSizes={xAxisCaptionsWidth:20,yAxisCaptionsWidth:i}}createMainTitle(e){this.mainTitle=jv(e.name,this.chartSizes.totalWidth-this.margins.left-this.margins.right,20)}updateMargins(){let e=24*this.mainTitle.length,t=e>0?e+24*2:0;this.margins={top:Math.max(t,Gc),bottom:Gc+this.captionsSizes.xAxisCaptionsWidth+k9,left:Gc+this.captionsSizes.yAxisCaptionsWidth+k9,right:this.legend.width+Gc},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+Math.max(this.chartSizes.chartHeight,this.legend.height)+this.margins.bottom,bs(this.canvasNode).style("width",this.chartSizes.chartWidth+"px").style("height",this.chartSizes.chartHeight+"px").style("top",this.margins.top+"px").style("left",this.margins.left+"px")}updateLegendSize(e,t,n,r){if(!e.show){this.legend={width:0,height:0,items:[]};return}let a=[],i={width:0,height:0,left:0,top:0};if(n.forEach(A=>{let h=t[A.value];if(h.usedAes.length===0||!h.aesMap)return;let v={};h.values.forEach(b=>{v[b]||(v[b]={...zv}),h.usedAes.forEach(x=>{var B,k;x==="dotFill"&&(v[b].color=((B=h.aesMap[b])==null?void 0:B[x])??Vt),x==="dotSize"&&(v[b].size=((k=h.aesMap[b])==null?void 0:k[x])??3)})});let g=A.label??A.value,C=Qo().domain(h.values).range(h.values.map(b=>v[b]));a.push({...i,id:A.value,type:"dots",title:g,scale:C,values:h.values,labels:h.labels})}),r.forEach(A=>{if(A.type==="dots"&&th(A.aes.dotFill)){let{domain:h,range:v,columnName:g,type:C="linear"}=A.aes.dotFill,b=g.label??g.value,x=T9(v,h,"linear"),B=(C==="log"?nv():Zr()).domain(h).range([this.chartSizes.chartHeight,0]),k=h3(B,h);a.push({...i,id:"dotFill",type:"continuous",title:b,scale:x,tickPositionScale:B,values:k})}if(A.type==="dots"&&th(A.aes.dotSize)){let{columnName:h,domain:v,range:g}=A.aes.dotSize,C=h.label??h.value,b=rv(v,g),x=b.ticks(3),B=b.tickFormat(3),k=x.reduce((P,I)=>(P[String(I)]=B(I),P),{});a.push({...i,id:h.value,type:"size",title:C,scale:b,values:x,labels:k})}}),!a.length){this.legend={width:0,height:0,items:[]};return}let o=S3(a,this.chartSizes.chartHeight),s=o[o.length-1],c=s.left+s.width+RZ,f=this.chartSizes.chartHeight;this.legend={width:c,height:f,items:o}}initSettings(e,t,n,r,a,i,o,s){let{xAxis:c,yAxis:f,size:A,title:h,legend:v}=t;this.updateChartSizes(A),this.updateViewport(c,f,n),this.updateCaptionsSize(r.y),this.updateLegendSize(v,o,s,i),this.createMainTitle(h),this.updateMargins(),this.aesGetters=YZ(a,i);let g=Oht().data(e).value(P=>{let I=Qg(this.aesGetters.dotFill(P.data)),$=!P.dimmed&&(this.polygon.length<2||VC(this.polygon,[P.x,P.y]))?1:.4;return KM(I,$)}),C=Z6t().equals((P,I)=>P===I).size(P=>GZ(this.aesGetters.dotSize(P.data))).crossValue(P=>P.x).mainValue(P=>P.y).decorate(P=>g(P)),b=jAt().scaleExtent([.1,1e3]).filter(()=>!this.lassoMode).on("start",()=>{this.selectedDot=null}).on("zoom",P=>{let I=P.transform,$=I.rescaleX(this.scales.xOriginal),N=I.rescaleY(this.scales.yOriginal);this.scales.x.domain($.domain()),this.scales.y.domain(N.domain()),this.zoomStateKey=`${I.x}_${I.y}_${I.k}`,this.renderSvgLayer(),this.renderWebglLayer()}).on("end",()=>{this.allPossibleLabels.forEach(P=>{P.x=this.scales.x(P.dot.x),P.y=this.scales.y(P.dot.y)}),this.visibleLabels=AS(this.allPossibleLabels,this.chartSizes.chartWidth,this.chartSizes.chartHeight),this.renderSvgLayer()}),x=Yk().x(P=>P.x).y(P=>P.y).addAll(e),B=Fht().on("point",([P])=>{var Z,ee;if(!P){this.selectedDot=null,this.renderSvgLayer();return}let I=this.scales.x.invert(P.x),$=this.scales.y.invert(P.y),N=(Z=this.tools)==null?void 0:Z.qt.find(I,$),F=this.selectedDot&&!N||!this.selectedDot&&N||((ee=this.selectedDot)==null?void 0:ee.id)!==(N==null?void 0:N.id);this.selectedDot=N??null,F&&this.renderSvgLayer()}),k=ght({xScale:this.scales.x,yScale:this.scales.y}).xAxisHeight(()=>"0").yAxisWidth(()=>"0").svgPlotArea(J6t()).webglPlotArea(q6t().series([C]).mapping(P=>P)).decorate(P=>{let I=P.enter();I&&!this.svgLayerElement&&(I.style("grid-template-columns","0 auto 1fr auto 0"),I.style("grid-template-rows","0 auto 1fr auto 0"),this.svgLayerElement=I.select(".svg-plot-area.plot-area svg").node()),I.select(".svg-plot-area.plot-area").call(b).call(B)});this.tools={webglChart:k,zoom:b,qt:x,fillColor:g,pointSeries:C},bs(this.canvasNode).datum(e).style("position","absolute").style("width",this.chartSizes.chartWidth+"px").style("height",this.chartSizes.chartHeight+"px").style("top",this.margins.top+"px").style("left",this.margins.left+"px")}updateAes(e,t){this.tools!==null&&(this.aesGetters=YZ(e,t),this.tools.fillColor.value(n=>{let r=this.aesGetters.dotFill??(()=>Vt),a=Qg(r(n.data)),i=!n.dimmed&&(this.polygon.length<2||VC(this.polygon,[n.x,n.y]))?1:.4;return KM(a,i)}))}updatePointSize(){this.tools!==null&&(bs(this.canvasNode).datum([...this.allDots]),this.tools.pointSeries.size(e=>GZ(this.aesGetters.dotSize(e.data))))}updateByLasso(){var e;this.tools!==null&&((e=this.tools)==null||e.fillColor.value(t=>{let n=this.aesGetters.dotFill??(()=>Vt),r=Qg(n(t.data)),a=!t.dimmed&&(this.polygon.length<2||VC(this.polygon,[t.x,t.y]))?1:.4;return KM(r,a)}),this.renderWebglLayer())}updateData(e){this.tools!==null&&(bs(this.canvasNode).datum(e),this.tools.fillColor.data(e),this.tools.qt=Yk().x(t=>t.x).y(t=>t.y).addAll(e))}render(e,t,n,r,a,i,o,s,c,f,A,h,v,g,C){if(this.lassoMode=g,this.tools===null)this.initSettings(a,t,i,r,s,c,f,A),this.onPolygonUpdateOutside=v,this.onTooltipHintSwitch=C;else{let{title:b,legend:x}=t;this.updateLegendSize(x,f,A,c),this.createMainTitle(b),this.updateMargins(),this.updateAes(s,c)}this.allDots=a,this.allPossibleLabels=h,this.allPossibleLabels.forEach(b=>{b.x=this.scales.x(b.dot.x),b.y=this.scales.y(b.dot.y)}),this.visibleLabels=AS(this.allPossibleLabels,this.chartSizes.chartWidth,this.chartSizes.chartHeight),this.notCalculatedProps={settingsId:e,chartSettings:t,onlyPositive:r,keyColumn:n,dotsByGrouping:o,layers:c},this.renderWebglLayer(),this.renderSvgLayer()}renderWebglLayer(){var e,t;(e=this.tools)!=null&&e.webglChart&&bs(this.canvasNode).call((t=this.tools)==null?void 0:t.webglChart)}renderSvgLayer(){var t;this.visibleLabels.forEach(n=>{n.x=this.scales.x(n.dot.x),n.y=this.scales.y(n.dot.y)}),J9t(this.visibleLabels);let e={settingsId:this.notCalculatedProps.settingsId,chartSettings:this.notCalculatedProps.chartSettings,onlyPositive:this.notCalculatedProps.onlyPositive,keyColumn:this.notCalculatedProps.keyColumn,dotsByGrouping:this.notCalculatedProps.dotsByGrouping,layers:this.notCalculatedProps.layers,chartSizes:this.chartSizes,scales:this.scales,margins:this.margins,mainTitle:this.mainTitle,captionsSizes:this.captionsSizes,container:this.svgLayerElement,zoomStateKey:this.zoomStateKey,selectedDot:this.selectedDot,aesGetters:this.aesGetters,legendData:this.legend,labels:this.visibleLabels,onPolygonUpdate:this.onPolygonUpdate,onTooltipHintSwitch:this.onTooltipHintSwitch,lassoMode:this.lassoMode};this.svgLayerComponent=ie.jsx(j6t,{...e}),(t=this.reactRoot)==null||t.render(this.svgLayerComponent)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},nwt=twt,JM=D.object({type:D.literal("grouping"),value:D.string()}),rwt=D.object({type:D.literal("dots"),aes:D.optional(D.object({dotFill:D.optional(D.union([D.string(),JM,Z0(D.string())])),dotShape:D.optional(D.union([kd,JM])),dotSize:D.optional(D.union([D.number(),Z0(D.number())]))}))}),awt=D.object({type:D.literal("curve"),smoothing:D.optional(D.boolean()),aes:D.optional(D.object({lineWidth:D.optional(D.number()),lineShape:D.optional(K1),lineColor:D.optional(D.union([D.string(),JM,Z0(D.string())])),opacity:D.optional(D.number())}))}),iwt=D.union([rwt,awt]),owt=D.object({type:D.literal("scatterplot-umap"),title:D.object({name:D.string(),show:D.optional(D.boolean()),position:D.optional(Fv)}),size:D.optional(D.object({width:D.optional(D.number()),height:D.optional(D.number())})),legend:D.optional(D.object({show:D.optional(D.boolean()),position:D.optional(Rm)})),tooltips:D.optional(D.object({show:D.optional(D.boolean()),content:D.optional(D.array(Yn))})),frame:D.optional(D.object({type:D.optional(g9)})),keyColumn:Yn,x:Yn,y:Yn,xAxis:D.optional(A3),yAxis:D.optional(A3),grouping:D.optional(D.array(Yn)),label:D.optional(Yn),highlight:D.optional(Yn),inheritedAes:D.optional(D.record(D.string(),d3)),layers:D.array(iwt),lassoMode:D.optional(D.boolean())}),lwt=class{constructor(e){Be(this,"type","dots");Be(this,"aes",{dotFill:Vt,dotShape:"21",dotSize:3,opacity:1});this.aes={...this.aes,...e.aes}}},swt=class{constructor(e){Be(this,"type","curve");Be(this,"smoothing");Be(this,"aes",{lineColor:Vt,lineWidth:1,lineShape:"solid",opacity:1});this.smoothing=e.smoothing??!1,this.aes={...this.aes,...e.aes}}},WZ=class{constructor(e){Be(this,"id");Be(this,"type","scatterplot-umap");Be(this,"keyColumn");Be(this,"x");Be(this,"y");Be(this,"grouping");Be(this,"label");Be(this,"highlight");Be(this,"chartSettings");Be(this,"inheritedAes");Be(this,"layers");Be(this,"lassoMode");var t,n,r,a;owt.parse(e),this.id=Zn.uniqueId("settings"),this.keyColumn=e.keyColumn,this.x=e.x,this.y=e.y,this.grouping=e.grouping??[],this.label=e.label??null,this.highlight=e.highlight??null,this.chartSettings={size:{width:((t=e==null?void 0:e.size)==null?void 0:t.width)??600,height:((n=e==null?void 0:e.size)==null?void 0:n.height)??350},title:{position:"center",show:!0,...e.title,name:((r=e.title)==null?void 0:r.name)??"Chart"},yAxis:{title:e.y.label??e.y.value,scale:"linear",showGrid:!0,showTicks:!0,...e.yAxis},xAxis:{title:e.x.label??e.x.value,scale:"linear",showGrid:!0,showTicks:!0,...e.xAxis},frame:{type:((a=e.frame)==null?void 0:a.type)??"full"},legend:{show:!0,position:"right",...e.legend},tooltips:{show:!0,...e.tooltips}},this.inheritedAes=e.inheritedAes??{},this.layers=e.layers.map(i=>{if(i.type==="dots")return new lwt(i);if(i.type==="curve")return new swt(i);throw new Error("Unknown layer type")}).filter(Boolean),this.lassoMode=e.lassoMode??!1}};function XZ(e){return typeof e=="object"&&"type"in e&&e.type==="grouping"}function uwt(e,t,n,r){return t.reduce((a,i)=>{let o=Zn.uniqBy(e.rows,h=>h[i.value]),s=h=>String(h[i.value]),c=h=>i.valueLabels?String(h[i.valueLabels]):s(h),f=new Set;n.forEach(h=>{h.aes&&Object.entries(h.aes).forEach(([v,g])=>{XZ(g)&&g.value===i.value&&f.add(v)})});let A=o.reduce((h,v)=>(h[s(v)]=c(v),h),{});return a[i.value]={values:o.map(s).sort((h,v)=>A[h].localeCompare(A[v],"en",{numeric:!0})),usedAes:[...f],aesMap:r[i.value],labels:A},a},{})}var cwt=10;function fwt(e){let t=[],n=new hc("16px Manrope");for(let r of e){let a=r.label;if(!a)continue;let i=n.getTextMetrics(String(a));t.push({name:String(a),width:(i==null?void 0:i.width)??0,height:((i==null?void 0:i.actualBoundingBoxAscent)??0)+((i==null?void 0:i.actualBoundingBoxDescent)??0),x:0,y:0,xPosition:"right",yPosition:"middle",bbox:{minX:0,maxX:0,minY:0,maxY:0},dot:r,padding:cwt})}return t}var dwt=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new nwt);Be(this,"onPolygonUpdate",()=>fw);Be(this,"onTooltipHintSwitch",()=>fw);Be(this,"calculatedData",null);this.settings=new WZ(n),r&&(this.onPolygonUpdate=r[0],this.onTooltipHintSwitch=r[1])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new WZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData();let i=r.layers.find(s=>s.type==="dots"),o=this.settings.layers.find(s=>s.type==="dots");i&&o&&i.aes.dotSize!==o.aes.dotSize&&typeof i.aes.dotSize=="number"&&typeof o.aes.dotSize=="number"&&this.chartRenderer.updatePointSize(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){t==="polygon"&&(this.chartRenderer.polygon=n,this._updateChart())}export(){return console.warn("export not implemented"),""}_needUpdateCalculatedDataBySettings(t,n){var r,a,i,o;return t.grouping.length!==n.grouping.length||t.grouping.some((s,c)=>{var f;return s.value!==((f=n.grouping[c])==null?void 0:f.value)})||(((r=t.label)==null?void 0:r.value)||((a=n.label)==null?void 0:a.value))&&((i=t.label)==null?void 0:i.value)!==((o=n.label)==null?void 0:o.value)}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{x:t,y:n,keyColumn:r,label:a,highlight:i,grouping:o,layers:s,inheritedAes:c}=this.settings,f={x:!0,y:!0},A={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0},h=s.some(B=>B.type==="curve"),v=new Set,g={},C=this.data.rows.reduce((B,k)=>{if(k[t.value]===null||k[n.value]===null)return B;let P=Number(k[t.value]),I=Number(k[n.value]);f.x&&P!==null&&P<0&&(f.x=!1),f.y&&I!==null&&I<0&&(f.y=!1),P!==null&&P<A.minX&&(A.minX=P),P!==null&&P>A.maxX&&(A.maxX=P),I!==null&&I<A.minY&&(A.minY=I),I!==null&&I>A.maxY&&(A.maxY=I);let $=(a==null?void 0:a.valueLabels)??(a==null?void 0:a.value),N={x:P,y:I,id:String(k[r.value]),dimmed:i?!k[i.value]:!1,label:$&&k[$]?String(k[$]):null,data:k};if(h){let F=o.map(Z=>k[Z.value]).join("_");v.add(F),g[F]||(g[F]=[]),g[F].push(N)}return B.push(N),B},[]);C.sort((B,k)=>Number(k.dimmed)-Number(B.dimmed));let b=[...v];h&&b.forEach(B=>{g[B].sort((k,P)=>k.x-P.x)});let x=uwt(this.data,o,s,c);this.calculatedData={onlyPositive:f,dots:C,dotsByGrouping:g,groupingKeys:b,allPossibleLabels:fwt(C),dotsExtents:A,legendLabels:x},this.chartRenderer.updateData(C)}_updateAesInData(){let t=this.calculatedData;if(!t)return;let{layers:n,inheritedAes:r,grouping:a}=this.settings;a.forEach(i=>{let o=new Set;n.forEach(s=>{s.aes&&Object.entries(s.aes).forEach(([c,f])=>{XZ(f)&&f.value===i.value&&o.add(c)})}),t.legendLabels[i.value].usedAes=[...o],t.legendLabels[i.value].aesMap=r[i.value]})}_updateChart(){if(!this.calculatedData)return;let{id:t,chartSettings:n,keyColumn:r,inheritedAes:a,layers:i,grouping:o,lassoMode:s}=this.settings;this.chartRenderer.render(t,n,r,this.calculatedData.onlyPositive,this.calculatedData.dots,this.calculatedData.dotsExtents,this.calculatedData.dotsByGrouping,a,i,this.calculatedData.legendLabels,o,this.calculatedData.allPossibleLabels,this.onPolygonUpdate,s,this.onTooltipHintSwitch)}},Awt=1e6;function hwt(e){let t=BI(e),n=Vs(e);return t===void 0||n===void 0||t===0?r=>r:r=>(r-n)/t}function pwt(e){let t=Vs(e),[n,r]=M0(e);return t===void 0||n===void 0||r===void 0?a=>a:a=>(a-t)/(r-n)}function vwt(e,t){return e==="standardScaling"?hwt(t):e==="meanNormalization"?pwt(t):n=>n}function mwt(e,t,n,r,a,i,o,s,c){let f=o.map(b=>b.join("_")),A={meta:{facetKeys:f,xKeys:[],yKeys:[],xLabels:{},yLabels:{},facetKeyValues:f.reduce((b,x,B)=>(b[x]=o[B],b),{}),valueExtentSize:[1/0,-1/0],valueExtentColor:[1/0,-1/0]},facets:{}},h=new Set,v=new Set,g=t.valueLabels??t.value,C=n.valueLabels??n.value;if(e.rows.forEach(b=>{let x=i.length?i.map($=>b[$.value]).join("_"):"null",B=b[t.value],k=b[n.value],P=b[r.value]??c,I=b[a.value]??c;if(!(B===null||k===null||P===null||I===null)){if(A.facets[x]||(A.facets[x]={xKeys:[],yKeys:[],cells:{}}),A.facets[x].xKeys.push(B),A.facets[x].yKeys.push(k),h.has(B)||(h.add(B),A.meta.xKeys.push(B)),v.has(k)||(v.add(k),A.meta.yKeys.push(k)),A.facets[x].cells[B]||(A.facets[x].cells[B]={}),A.meta.valueExtentSize[0]=Math.min(P,A.meta.valueExtentSize[0]),A.meta.valueExtentSize[1]=Math.max(P,A.meta.valueExtentSize[1]),A.meta.valueExtentColor[0]=Math.min(I,A.meta.valueExtentColor[0]),A.meta.valueExtentColor[1]=Math.max(I,A.meta.valueExtentColor[1]),A.facets[x].cells[B][k])throw Error(`More than 1 value for x=${B}, y=${k}`);if(A.meta.xLabels[B]&&String(b[g])!==A.meta.xLabels[B])throw Error(`More than 1 x-label value for x=${B}`);if(A.meta.yLabels[k]&&String(b[C])!==A.meta.yLabels[k])throw Error(`More than 1 y-label value for y=${k}`);A.meta.xLabels[B]=String(b[g]),A.meta.yLabels[k]=String(b[C]),A.meta&&(A.facets[x].cells[B][k]={id:`${B}_${k}`,x:B,y:k,sizeValue:P,normalizedSizeValue:P,colorValue:I,normalizedColorValue:I,data:b})}}),A.meta.facetKeys=A.meta.facetKeys.filter(b=>A.facets[b]),A.meta.facetKeys.forEach(b=>{let x=A.facets[b];if(x.xKeys=Zn.uniq(x.xKeys),x.yKeys=Zn.uniq(x.yKeys),x.xKeys.length*x.yKeys.length>Awt)throw Error(`Too many cells for graph rendering (${x.xKeys.length*x.yKeys.length})`)}),s){let b=[1/0,-1/0];A.meta.facetKeys.forEach(x=>{if(!A.facets[x])return;let{xKeys:B,yKeys:k,cells:P}=A.facets[x],I=s.direction==="row"?B:k,$=s.direction==="row"?k:B,N=s.direction==="row"?(F,Z)=>{var ee;return(ee=P[F])==null?void 0:ee[Z]}:(F,Z)=>{var ee;return(ee=P[Z])==null?void 0:ee[F]};$.forEach(F=>{let Z=[];I.forEach(le=>{var j;let Q=(j=N(le,F))==null?void 0:j.colorValue;Q!==void 0&&Z.push(Q)});let ee=vwt(s.method,Z);I.forEach(le=>{let Q=N(le,F);Q!==void 0&&(Q.normalizedColorValue=ee(Q.colorValue),b[0]=Math.min(Q.normalizedColorValue,b[0]),b[1]=Math.max(Q.normalizedColorValue,b[1]))})})}),A.meta.valueExtentColor=b}return A.meta.valueExtentSize[0]===1/0&&(A.meta.valueExtentSize[0]=0),A.meta.valueExtentSize[1]===-1/0&&(A.meta.valueExtentSize[1]=0),A.meta.valueExtentColor[0]===1/0&&(A.meta.valueExtentColor[0]=0),A.meta.valueExtentColor[1]===-1/0&&(A.meta.valueExtentColor[1]=0),A}var gwt=15,Om=8,vS=30,ywt=48,wwt=24,mS=16,H3=4,gS=4,KZ=20,bwt=16,up={left:["axis","axisTitle"],right:["axis","axisTitle"],top:["axis","axisTitle","facetTitle"],bottom:["axis","axisTitle"]};function Cwt(e,t,n,r,a,i,o){let s=r.includes(t.position),c=r.includes(e.position),f=a.length>1,A=e.showTicks?gS:0,h=t.showTicks?gS:0,v=c&&e.showTitle?vS:0,g=s&&t.showTitle?vS:0,C=c&&e.showAxisLabels&&i>mS?n.xAxisCaptions+A+H3:0,b=s&&t.showAxisLabels&&o>mS?n.yAxisCaptions+h+H3:0;return{left:{axisTitle:t.position==="left"?g:0,axis:t.position==="left"?b:0},right:{axisTitle:t.position==="right"?g:0,axis:t.position==="right"?b:0},top:{facetTitle:f?ywt:0,axisTitle:e.position==="top"?v:0,axis:e.position==="top"?C:0},bottom:{axisTitle:e.position==="bottom"?v:0,axis:e.position==="bottom"?C:0}}}function Swt(e,t,n){return{left:up.left.reduce((r,a,i)=>{let o=i>0?up.left[i-1]:null,s=e.left[a];return r[a]={x:o?r[o].x-s:-s,y:0,width:s,height:n,isVisible:s>0},r},{}),right:up.right.reduce((r,a,i)=>{let o=i>0?up.right[i-1]:null,s=e.right[a];return r[a]={x:o?r[o].x+r[o].width:t,y:0,width:s,height:n,isVisible:s>0},r},{}),top:up.top.reduce((r,a,i)=>{let o=i>0?up.top[i-1]:null,s=e.top[a];return r[a]={x:0,y:o?r[o].y-s:-s,width:t,height:s,isVisible:s>0},r},{}),bottom:up.bottom.reduce((r,a,i)=>{let o=i>0?up.bottom[i-1]:null,s=e.bottom[a];return r[a]={x:0,y:o?r[o].y+r[o].height:n,width:t,height:s,isVisible:s>0},r},{})}}function xwt(e,t,n,r){let{xLabels:a,yLabels:i}=n.meta,o=e.xAxisLabels/180*Math.PI,s=e.yAxisLabels/180*Math.PI,c=0,f=0,A=e.xAxisLabels===45;if(A){let v=n.meta.xKeys,g=t.x,C=g>mS,b=a[v[0]];c=Math.max(c,(A&&C?r.getTextWidth(b)*Math.cos(o):0)-g/2)}let h=e.yAxisLabels===45;if(h){let v=n.meta.yKeys;if(v.length){let g=t.y,C=g>mS,b=i[v[v.length-1]];f=Math.max(f,(h&&C?r.getTextWidth(b)*Math.cos(s):0)-g/2)}}return{xCaptionTail:c,yCaptionTail:f}}function Ewt({sideElementBBoxes:e,debug:t,xKeys:n,yKeys:r,scales:a,xAxis:i,yAxis:o,stepX:s,stepY:c,labelAngles:f,xLabels:A,yLabels:h}){let v=i.showTicks?gS:0,g=o.showTicks?gS:0,C=e.top.axis.isVisible||e.bottom.axis.isVisible,b=e.top.axisTitle.isVisible?e.top.axisTitle:e.bottom.axisTitle,x=e.top.axis.isVisible?e.top.axis:e.bottom.axis,B=e.left.axis.isVisible||e.right.axis.isVisible,k=e.left.axisTitle.isVisible?e.left.axisTitle:e.right.axisTitle,P=e.left.axis.isVisible?e.left.axis:e.right.axis;return ie.jsxs("g",{children:[ie.jsxs("g",{children:[b.isVisible&&ie.jsxs("g",{transform:`translate(${b.x},${b.y})`,children:[ie.jsx("text",{x:b.width/2,y:b.height/2,textAnchor:"middle",dominantBaseline:"central",children:i.title}),t&&ie.jsx("rect",{width:b.width,height:b.height,stroke:Vt,fill:"none"})]}),C&&ie.jsxs("g",{fontSize:"14px",transform:`translate(${x.x},${x.y})`,children:[n.map(I=>{let $=f.xAxisLabels!==0,N=i.position==="bottom",F=N?0:x.height,Z=N?F+v:F-v,ee=N?Z+H3:Z-H3,le=a.x(I)+s/2,Q=-f.xAxisLabels;return ie.jsxs("g",{children:[ie.jsx("line",{x1:le,x2:le,y1:F,y2:Z,stroke:Vt}),ie.jsx("text",{x:le,y:ee,textAnchor:$?N?"end":"start":"middle",transform:`rotate(${Q},${le},${ee})`,dominantBaseline:$?"central":N?"hanging":"auto",children:A[I]})]},I)}),t&&ie.jsx("rect",{width:x.width,height:x.height,stroke:Vt,fill:"none"})]})]}),ie.jsxs("g",{children:[k.isVisible&&ie.jsx("g",{transform:`translate(
15129
15129
  ${k.x+k.width/2},
15130
- ${k.y+k.height/2})`,children:ie.jsx("text",{transform:`rotate(${o.position==="left"?-90:90})`,dominantBaseline:"central",textAnchor:"middle",children:o.title})}),t&&ie.jsx("rect",{x:k.x,y:k.y,width:k.width,height:k.height,stroke:Vt,fill:"none"}),B&&ie.jsx("g",{fontSize:"14px",transform:`translate(${P.x},${P.y})`,children:r.map(I=>{let $=f.yAxisLabels!==0,N=o.position==="left",F=-(90-f.yAxisLabels),Z=f.yAxisLabels===0?"middle":N?"end":"start",ee=$?"central":N?"auto":"hanging",le=N?P.width:0,Q=N?le-g:le+g,j=N?Q-H3:Q+H3,U=a.y(I)+c/2;return ie.jsxs("g",{children:[ie.jsx("line",{x1:le,x2:Q,y1:U,y2:U,stroke:Vt}),ie.jsx("text",{x:j,y:U,textAnchor:Z,transform:`rotate(${F},${j},${U})`,dominantBaseline:ee,children:h[I]})]},I)})}),t&&ie.jsx("rect",{x:P.x,y:P.y,height:P.height,width:P.width,stroke:Vt,fill:"none"})]})]})}function yS(e){if(e===null)return"null";if(typeof e=="number"){let t=e>0?Math.floor(e):Math.ceil(e),n=e-t;return t+Number(n.toPrecision(2))}return e}function Bwt(e,t,n=[]){let r=e.data,a=[`X: ${t.xLabels[e.x]}`,`Y: ${t.yLabels[e.y]}`,`Value (color): ${yS(e.colorValue)}${e.colorValue!==e.normalizedColorValue?` (${yS(e.normalizedColorValue)})`:""}`,`Value (size): ${yS(e.sizeValue)}${e.sizeValue!==e.normalizedSizeValue?` (${yS(e.normalizedSizeValue)})`:""}`];for(let i of n)a.push(`${i.label}: ${r[i.valueLabels??i.value]}`);return a}function _wt({facetKey:e,dimensions:t,scales:n,cells:r,colorScale:a,sizeScale:i,chartSettings:o,cellsMeta:s,stepX:c,stepY:f,aes:A,labelAngles:h,chartSizes:v,margins:g,tooltipsContainer:C,tooltipsData:b}){let[x,B]=tn.useState(),{xAxis:k,yAxis:P,tooltips:I}=o,{width:$,height:N}=t.inner,{padding:F,sideElementBBoxes:Z}=t,{xLabels:ee,yLabels:le}=s,Q=n.x.domain(),j=n.y.domain(),U={left:g.left+t.left+F.left,right:v.totalWidth-(g.left+t.left+F.left),top:g.top+t.top+F.top,bottom:v.totalHeight-(g.top+t.top+F.top)},Y=!1,X=b.fixed&&x;return ie.jsxs("g",{transform:`translate(${t.left},${t.top})`,fontSize:bwt,children:[ie.jsxs("g",{transform:`translate(${F.left},${F.top})`,children:[Z.top.facetTitle.isVisible&&ie.jsx("text",{x:Z.top.facetTitle.x,y:Z.top.facetTitle.y+Z.top.facetTitle.height-wwt,fontWeight:"500",fontSize:"20px",children:s.facetKeyValues[e].join(", ")}),Y,Q.map(te=>j.map(pe=>{var fe;let ae=(fe=r==null?void 0:r[te])==null?void 0:fe[pe],ge=X&&ae&&b.selectedData===ae,me=ae?ie.jsx("circle",{cx:n.x(te)+c/2,cy:n.y(pe)+f/2,r:i(ae.normalizedSizeValue),stroke:A.cellStrokeColor,fill:ae.colorValue===null?A.emptyCellColor:a(ae.normalizedColorValue),onMouseOver:()=>b.onMouseOver(ae,e),onMouseLeave:()=>b.onMouseLeave()},ae?ae.id:`${te}_${pe}`):null;return ge?cu.createPortal(me,x):me})),ie.jsx("g",{children:o.frame.type==="full"&&ie.jsx("rect",{fill:"none",stroke:Vt,x:"0",y:"0",width:$,height:N})}),ie.jsx("g",{fontWeight:"500",children:ie.jsx(Ewt,{sideElementBBoxes:Z,xKeys:Q,yKeys:j,scales:n,xAxis:k,yAxis:P,stepX:c,stepY:f,labelAngles:h,xLabels:ee,yLabels:le,debug:Y})}),b.fixed&&ie.jsx("rect",{width:v.chartWidth,height:v.chartHeight,fill:"rgba(255,255,255,0.8)"}),ie.jsx("g",{ref:te=>{te&&!x&&B(te)}})]}),o.tooltips.show&&b.selectedData&&b.currentFacet===e&&ie.jsx(fu,{content:Bwt(b.selectedData,s,I==null?void 0:I.content),x:n.x(String(b.selectedData.x))+c/2,y:n.y(String(b.selectedData.y))+f/2,offset:Q.length>1?c/2:0,active:!0,sideDistances:U,container:C,onClose:b.onClose,fixed:b.fixed})]})}function Twt({margins:e,captionsSizes:t,settingsId:n,chartSettings:r,chartSizes:a,chartsDimensions:i,facetKeys:o,scales:s,colorScale:c,sizeScale:f,groupedCells:A,cellsMeta:h,step:v,legend:g,aes:C,columnsCount:b,labelAngles:x,onTooltipHintSwitch:B}){let k=p3(B),[P,I]=tn.useState(),$=tn.useRef(null);tn.useEffect(()=>{$.current&&I($.current)},[]);let N=i[o[0]].padding,F=i[o[b-1]].padding,Z=e.left+a.chartsWidth+KZ,ee=e.top+N.top;return ie.jsx(y3,{dataId:n,children:ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${a.totalWidth} ${a.totalHeight}`,width:a.totalWidth,height:a.totalHeight,fontFamily:"Manrope",children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${e.left},${e.top})`,children:[ie.jsx(w3,{title:[r.title.name],show:r.title.show,position:r.title.position,leftPadding:N.left,rightPadding:F.right,chartsWidth:a.chartsWidth}),o.map(le=>{let{cells:Q}=A[le];return ie.jsx(_wt,{captionsSizes:t,facetKey:le,dimensions:i[le],scales:s,cells:Q,cellsMeta:h,stepX:v.x,stepY:v.y,colorScale:c,sizeScale:f,chartSettings:r,aes:C,labelAngles:x,margins:e,chartSizes:a,tooltipsData:k,tooltipsContainer:P},le)})]}),ie.jsx("g",{transform:`translate(${Z},${ee})`,children:ie.jsx(b3,{legendData:g})}),ie.jsx("g",{ref:$,style:{outline:"none"}})]})})}var kwt=(e,t)=>{let n=Math.min(...t),r=Math.max(...t);if(n===r){let o=e%2===0?[]:[n];for(let s=1;s<e/2+1;s++)o.push(n+s),o.unshift(n-s);return o}if(e<2)return[n,r];let a=(r-n)/(e-1),i=[];for(let o=0;o<e-1;o++)i.push(n+a*o);return i.push(r),i};function Mwt(e,t,n){let r=n;return e&&(e.colorRange&&(r=e.colorRange),e.method==="standardScaling"&&(r=[-2,2]),e.method==="meanNormalization"&&(r=[-.75,.75])),kwt(t,r)}var Pwt=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"component",ie.jsx(ie.Fragment,{}));Be(this,"chartsDimensions",{});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,chartsWidth:600,chartsHeight:350,totalWidth:600,totalHeight:350});Be(this,"margins",{top:Om,bottom:Om,left:Om,right:Om});Be(this,"captionsSizes",{xAxisCaptions:100,yAxisCaptions:100,xCaptionTail:0,yCaptionTail:0});Be(this,"labelAngles",{xAxisLabels:0,yAxisLabels:0});Be(this,"columnsCount",1);Be(this,"rowsCount",1);Be(this,"scales",{x:Qo().domain(["null"]).range([1]),y:Qo().domain(["null"]).range([1])});Be(this,"step",{x:10,y:10});Be(this,"colorScale",Zr().domain([0,1]).range(["white","black"]));Be(this,"sizeScale",rv().domain([0,1]).range([3,20]));Be(this,"legend",{width:0,height:0,items:[]})}clear(){var e;this.parentNode&&this.rootNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),this.parentNode=null,this.rootNode=null),setTimeout(()=>{var t;(t=this.reactRoot)==null||t.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.reactRoot=Qh(this.rootNode))}updateMargins(e){this.margins={top:e.show?24+24*2:Om,bottom:Om,left:Om,right:this.legend.width},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartsWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+Math.max(this.chartSizes.chartsHeight,this.legend.height)+this.margins.bottom}updateLegendSize(e,t,n,r){if(!e.show){this.legend={width:0,height:0,items:[]};return}let a=[],i=Math.min(Math.max(this.chartSizes.chartHeight,250),350),o=Math.max(this.chartSizes.chartHeight,i),s={width:0,height:0,left:0,top:0},c=this.colorScale.domain(),f=h3(this.colorScale,[c[0],c[c.length-1]]),A=t.label??t.value,h=Zr([f[0],f[f.length-1]],[i,0]);a.push({id:"colorValue",type:"continuous",scale:this.colorScale,tickPositionScale:h,values:f,title:A,...s});let v=n.label??n.value,g=this.sizeScale.ticks(3),C=this.sizeScale.tickFormat(3),b=g.reduce((I,$)=>(I[String($)]=C($),I),{});if(a.push({id:"sizeValue",type:"size",title:v,scale:this.sizeScale,values:g,labels:b,...s}),!a.length){this.legend={width:0,height:0,items:[]};return}let x=S3(a,o,i),B=x[x.length-1],k=B.left+B.width+2*KZ,P=this.chartsDimensions[r[0]].padding;this.legend={width:k,height:o+P.top,items:x}}updateCaptionsSize(e,t,n){let r=new hc("bold 14px Arial"),{xKeys:a,yKeys:i,xLabels:o,yLabels:s}=e.meta;this.labelAngles={xAxisLabels:t.axisLabelsAngle,yAxisLabels:n.axisLabelsAngle};let c=0,f=0;for(let C of a){let b=r.getTextWidth(o[C]);b>c&&(c=b)}for(let C of i){let b=r.getTextWidth(s[C]);b>f&&(f=b)}let{xCaptionTail:A,yCaptionTail:h}=xwt(this.labelAngles,this.step,e,r),v=this.labelAngles.xAxisLabels/180*Math.PI,g=this.labelAngles.yAxisLabels/180*Math.PI;this.captionsSizes={xCaptionTail:A,yCaptionTail:h,xAxisCaptions:c*Math.sin(v)||vS,yAxisCaptions:f*Math.sin(g)||vS}}updateChartDimensions(e,t,n,r){let a=e.length,i=Math.min(t.nRows??a,a),o=Math.min(t.nCols??a,a);this.columnsCount=t.nRows?Math.ceil(a/i):o,this.rowsCount=Math.ceil(a/this.columnsCount),this.chartsDimensions={};let s=0,c=0;e.forEach((h,v)=>{let g=v%this.columnsCount+1,C=iZ(v,e.length,this.columnsCount,this.rowsCount),b=this.chartSizes.chartWidth,x=this.chartSizes.chartHeight,B=Cwt(n,r,this.captionsSizes,C,e,this.step.x,this.step.y);function k(F){return Math.max(up[F].reduce((Z,ee)=>Z+B[F][ee],0),gwt)}let P={left:k("left"),right:k("right"),top:k("top"),bottom:k("bottom")};P.left<this.captionsSizes.xCaptionTail&&(P.left=this.captionsSizes.xCaptionTail),P.bottom<this.captionsSizes.yCaptionTail&&(P.bottom=this.captionsSizes.yCaptionTail);let I=Swt(B,b,x),$=b+P.left+P.right,N=x+P.top+P.bottom;this.chartsDimensions[h]={left:s,top:c,inner:{width:b,height:x},outer:{width:$,height:N},padding:P,sideElementBBoxes:I,chartEdgeSides:C},s+=$,g===this.columnsCount&&(s=0,c+=N)});let f=e.slice(0,this.columnsCount).reduce((h,v)=>h+this.chartsDimensions[v].outer.width,0),A=e.filter((h,v)=>v%this.columnsCount===0).reduce((h,v)=>h+this.chartsDimensions[v].outer.height,0);this.chartSizes.chartsWidth=f,this.chartSizes.chartsHeight=A}updateChartsSizes(e,t){let{width:n,height:r,cellSize:a}=t;a&&(this.chartSizes.chartWidth=e.meta.xKeys.length*a,this.chartSizes.chartHeight=e.meta.yKeys.length*a),n&&r&&(this.chartSizes.chartWidth=n,this.chartSizes.chartHeight=r)}updateScales(e,t,n,r){let{width:a,height:i,cellSize:o}=t,{meta:s}=e,c=(C,b={})=>[...C].sort((x,B)=>n.sorting==="asc"?(b[x]??x).localeCompare(b[B]??B,"en",{numeric:!0}):(b[B]??B).localeCompare(b[x]??x,"en",{numeric:!0})),f=(C,b={})=>[...C].sort((x,B)=>r.sorting==="asc"?(b[x]??x).localeCompare(b[B]??B,"en",{numeric:!0}):(b[B]??B).localeCompare(b[x]??x,"en",{numeric:!0})),A=c(s.xKeys,s.xLabels),h=f(s.yKeys,s.yLabels);o?(this.step.x=o,this.step.y=o):a&&i&&(this.step.x=a/A.length,this.step.y=i/h.length);let v=new Array(A.length).fill(null).map((C,b)=>b*this.step.x),g=new Array(h.length).fill(null).map((C,b)=>b*this.step.y);this.scales.x=Qo().domain(A).range(v),this.scales.y=Qo().domain(h).range(g)}updateAesScale(e,t,n,r){this.colorScale=Zr().domain(Mwt(r,e.colorsList.length,n)).range(e.colorsList),this.sizeScale=rv(t,[e.minRadius,e.maxRadius])}render(e,t,n,r,a,i,o,s,c,f){var P;let{meta:A,facets:h}=a,{valueExtentSize:v,valueExtentColor:g}=A,{xAxis:C,yAxis:b,title:x,size:B}=t;this.updateChartsSizes(a,B),this.updateAesScale(c,v,g,s),this.updateScales(a,B,t.xAxis,t.yAxis),this.updateCaptionsSize(a,C,b),this.updateChartDimensions(r,n,C,b),this.updateLegendSize(t.legend,i,o,r),this.updateMargins(x);let k=ie.jsx(Twt,{aes:c,captionsSizes:this.captionsSizes,cellsMeta:A,columnsCount:this.columnsCount,chartsDimensions:this.chartsDimensions,chartSettings:t,chartSizes:this.chartSizes,sizeScale:this.sizeScale,colorScale:this.colorScale,facetKeys:r,facetSettings:n,groupedCells:h,labelAngles:this.labelAngles,legend:this.legend,margins:this.margins,scales:this.scales,settingsId:e,step:this.step,onTooltipHintSwitch:f});this.component=k,(P=this.reactRoot)==null||P.render(k)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},Hwt=Pwt,ZZ=class{constructor(e){Be(this,"id");Be(this,"type","bubble");Be(this,"facetSettings");Be(this,"valueColumnSize");Be(this,"valueColumnColor");Be(this,"xColumn");Be(this,"yColumn");Be(this,"facetBy");Be(this,"normalization");Be(this,"NAValueAs");Be(this,"chartSettings");Be(this,"aes");var a,i,o,s,c,f,A,h,v,g;q3t.parse(e),this.id=Zn.uniqueId("settings"),this.facetSettings={titlePosition:"left",...e.facetSettings},this.facetBy=e.facetBy??[],this.valueColumnSize=e.valueSize,this.valueColumnColor=e.valueColor,this.xColumn=e.xColumn,this.yColumn=e.yColumn,this.NAValueAs=e.NAValueAs??null,this.normalization=e.normalization??null;let t=((a=e.size)==null?void 0:a.cellSize)??null,n=t?null:((i=e==null?void 0:e.size)==null?void 0:i.width)??(this.facetBy.length?400:600),r=t?null:((o=e==null?void 0:e.size)==null?void 0:o.height)??(this.facetBy.length?250:350);this.chartSettings={size:{width:n,height:r,cellSize:t},title:{position:"center",show:!0,...e.title,name:((s=e.title)==null?void 0:s.name)??"Chart"},yAxis:{title:e.yColumn.label??e.yColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,position:"left",axisLabelsAngle:90,sorting:"asc",...e.yAxis},xAxis:{title:e.xColumn.label??e.xColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,position:"bottom",axisLabelsAngle:90,sorting:"asc",...e.xAxis},frame:{type:((c=e.frame)==null?void 0:c.type)??"full"},legend:{show:!0,position:"right",...e.legend},tooltips:{show:!0,...e.tooltips}},this.aes={minRadius:((f=e.aes)==null?void 0:f.minRadius)??3,maxRadius:((A=e.aes)==null?void 0:A.maxRadius)??20,colorsList:((h=e.aes)==null?void 0:h.colorsList)??["black","white","red"],cellStrokeColor:((v=e.aes)==null?void 0:v.cellStrokeColor)??Vt,emptyCellColor:((g=e.aes)==null?void 0:g.emptyCellColor)??"white"}}},Dwt=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new Hwt);Be(this,"onTooltipHintSwitch",()=>{});Be(this,"calculatedData",null);this.settings=new ZZ(n),r&&(this.onTooltipHintSwitch=r[0])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new ZZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){console.warn("no chart state for bubble chart")}export(){return this._updateChart(),b5(this.chartRenderer.component)}_needUpdateCalculatedDataBySettings(t,n){var r,a,i,o;return t.facetBy.some((s,c)=>{var f;return s.value!==((f=n.facetBy[c])==null?void 0:f.value)})||((r=t.normalization)==null?void 0:r.method)!==((a=n.normalization)==null?void 0:a.method)||((i=t.normalization)==null?void 0:i.direction)!==((o=n.normalization)==null?void 0:o.direction)||t.xColumn.value!==n.xColumn.value||t.yColumn.value!==n.yColumn.value||t.valueColumnColor.value!==n.valueColumnColor.value||t.valueColumnSize.value!==n.valueColumnSize.value||t.NAValueAs!==n.NAValueAs}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{facetBy:t,xColumn:n,yColumn:r,valueColumnSize:a,valueColumnColor:i,normalization:o,NAValueAs:s}=this.settings,c=t.map(v=>this.data.getColumnCategories(v.value)),f=c.length?xZ([...c]):[["null"]],A=t.map(v=>v.value)??null;this.data.setGrouping([...A]);let h=mwt(this.data,n,r,a,i,t,f,o,s);this.calculatedData={facetKeys:h.meta.facetKeys,groupedCellsData:h}}_updateAesInData(){this.calculatedData}_updateChart(){if(!this.calculatedData)return;let{id:t,chartSettings:n,facetSettings:r,valueColumnColor:a,valueColumnSize:i,normalization:o,aes:s}=this.settings;this.chartRenderer.render(t,n,r,this.calculatedData.facetKeys,this.calculatedData.groupedCellsData,a,i,o,s,this.onTooltipHintSwitch)}};function $wt(e){return"type"in e&&e.type==="columns"}var JZ=class j${constructor(t,n){Be(this,"id");Be(this,"data");Be(this,"rowsCount");Be(this,"columnNames");Be(this,"rowsGrouped");this.id=t,this.data=n,this.columnNames=Object.keys(n),this.rowsCount=this.columnNames.length?n[this.columnNames[0]].length:0}static from(t){if(t instanceof j$)return t;if($wt(t))return new j$(t.id,t.values);f1(t,"Unknown input data format")}get rows(){let t=this.columnNames,n=[];for(let r=0;r<this.rowsCount;r++)n.push(t.reduce((a,i)=>(a[i]=this.data[i][r],a),{}));return n}getColumn(t){return this.data[t]}getColumnCategories(t){if(!this.columnNames.includes(t))throw new Error(`Column ${t} does not exist`);return Zn.uniq(this.getColumn(t)).map(String)}setGrouping(t){let n={grouped:{},rows:this.rows},r=[n];t.forEach(a=>{let i=a===null?["null"]:this.getColumnCategories(a),o=[];r.forEach(s=>{if(a===null)s.grouped={null:{rows:s.rows,grouped:{}}},o.push(s.grouped.null);else{let c=Zn.groupBy(s.rows,f=>String(f[a]));s.grouped=i.reduce((f,A)=>(f[A]={rows:c[A]??[],grouped:{}},o.push(f[A]),f),{})}}),r=o}),this.rowsGrouped=n.grouped}getColumnByGrouping(t,n){if(!this.rowsGrouped)return[];if(!t.length)return this.rows.map(a=>Number(a[n]));let r={grouped:this.rowsGrouped,rows:this.rows};return t.forEach(a=>{let i=r.grouped[a??"null"];if(!i)return[];r=i}),r.rows.map(a=>Number(a[n]))}getRowsByGrouping(t){if(!this.rowsGrouped)return[];if(!t.length)return this.rows;let n={grouped:this.rowsGrouped,rows:this.rows};return t.forEach(r=>{let a=n.grouped[r??"null"];if(!a)return[];n=a}),n==null?void 0:n.rows}},Iwt=class U${constructor(t){Be(this,"node");Be(this,"chart");this.chart=t}static createChart(t,n,r){let{type:a}=n;if(a==="discrete")return new I7t(t,n,r);if(a==="dendro")return new M4t(t,n,r);if(a==="scatterplot")return new L6t(t,n,r);if(a==="scatterplot-umap")return new dwt(t,n,r);if(a==="heatmap")return new g9t(t,n,r);if(a==="histogram")return new G9t(t,n,r);if(a==="bubble")return new Dwt(t,n,r);f1(a,`Unknown chart type: ${a}`)}static newPlot(t,n,r){let a=JZ.from(t);return new this(U$.createChart(a,n,r))}get calculatedData(){return this.chart.calculatedData}mount(t){this.node=t,this.chart.mount(t)}unmount(){delete this.node,this.chart.unmount()}updateSettingsAndData(t,n){if(n.type!==this.chart.settings.type){let r=U$.createChart(this.chart.data,n);this.node?(this.chart.unmount(),this.chart=r,this.chart.mount(this.node)):this.chart=r}else this.chart.updateSettingsAndData(JZ.from(t),n)}updateChartState(t,n){this.chart.updateChartState(t,n)}export(){return this.chart.export()}};/*! Bundled license information:
15130
+ ${k.y+k.height/2})`,children:ie.jsx("text",{transform:`rotate(${o.position==="left"?-90:90})`,dominantBaseline:"central",textAnchor:"middle",children:o.title})}),t&&ie.jsx("rect",{x:k.x,y:k.y,width:k.width,height:k.height,stroke:Vt,fill:"none"}),B&&ie.jsx("g",{fontSize:"14px",transform:`translate(${P.x},${P.y})`,children:r.map(I=>{let $=f.yAxisLabels!==0,N=o.position==="left",F=-(90-f.yAxisLabels),Z=f.yAxisLabels===0?"middle":N?"end":"start",ee=$?"central":N?"auto":"hanging",le=N?P.width:0,Q=N?le-g:le+g,j=N?Q-H3:Q+H3,U=a.y(I)+c/2;return ie.jsxs("g",{children:[ie.jsx("line",{x1:le,x2:Q,y1:U,y2:U,stroke:Vt}),ie.jsx("text",{x:j,y:U,textAnchor:Z,transform:`rotate(${F},${j},${U})`,dominantBaseline:ee,children:h[I]})]},I)})}),t&&ie.jsx("rect",{x:P.x,y:P.y,height:P.height,width:P.width,stroke:Vt,fill:"none"})]})]})}function yS(e){if(e===null)return"null";if(typeof e=="number"){let t=e>0?Math.floor(e):Math.ceil(e),n=e-t;return t+Number(n.toPrecision(2))}return e}function Bwt(e,t,n=[]){let r=e.data,a=[`X: ${t.xLabels[e.x]}`,`Y: ${t.yLabels[e.y]}`,`Value (color): ${yS(e.colorValue)}${e.colorValue!==e.normalizedColorValue?` (${yS(e.normalizedColorValue)})`:""}`,`Value (size): ${yS(e.sizeValue)}${e.sizeValue!==e.normalizedSizeValue?` (${yS(e.normalizedSizeValue)})`:""}`];for(let i of n)a.push(`${i.label}: ${r[i.valueLabels??i.value]}`);return a}function _wt({facetKey:e,dimensions:t,scales:n,cells:r,colorScale:a,sizeScale:i,chartSettings:o,cellsMeta:s,stepX:c,stepY:f,aes:A,labelAngles:h,chartSizes:v,margins:g,tooltipsContainer:C,tooltipsData:b}){let[x,B]=tn.useState(),{xAxis:k,yAxis:P,tooltips:I}=o,{width:$,height:N}=t.inner,{padding:F,sideElementBBoxes:Z}=t,{xLabels:ee,yLabels:le}=s,Q=n.x.domain(),j=n.y.domain(),U={left:g.left+t.left+F.left,right:v.totalWidth-(g.left+t.left+F.left),top:g.top+t.top+F.top,bottom:v.totalHeight-(g.top+t.top+F.top)},Y=!1,X=b.fixed&&x;return ie.jsxs("g",{transform:`translate(${t.left},${t.top})`,fontSize:bwt,children:[ie.jsxs("g",{transform:`translate(${F.left},${F.top})`,children:[Z.top.facetTitle.isVisible&&ie.jsx("text",{x:Z.top.facetTitle.x,y:Z.top.facetTitle.y+Z.top.facetTitle.height-wwt,fontWeight:"500",fontSize:"20px",children:s.facetKeyValues[e].join(", ")}),Y,Q.map(te=>j.map(pe=>{var fe;let ae=(fe=r==null?void 0:r[te])==null?void 0:fe[pe],ge=X&&ae&&b.selectedData===ae,me=ae?ie.jsx("circle",{cx:n.x(te)+c/2,cy:n.y(pe)+f/2,r:i(ae.normalizedSizeValue),stroke:A.cellStrokeColor,fill:ae.colorValue===null?A.emptyCellColor:a(ae.normalizedColorValue),onMouseOver:()=>b.onMouseOver(ae,e),onMouseLeave:()=>b.onMouseLeave()},ae?ae.id:`${te}_${pe}`):null;return ge?cu.createPortal(me,x):me})),ie.jsx("g",{children:o.frame.type==="full"&&ie.jsx("rect",{fill:"none",stroke:Vt,x:"0",y:"0",width:$,height:N})}),ie.jsx("g",{fontWeight:"500",children:ie.jsx(Ewt,{sideElementBBoxes:Z,xKeys:Q,yKeys:j,scales:n,xAxis:k,yAxis:P,stepX:c,stepY:f,labelAngles:h,xLabels:ee,yLabels:le,debug:Y})}),b.fixed&&ie.jsx("rect",{width:v.chartWidth,height:v.chartHeight,fill:"rgba(255,255,255,0.8)"}),ie.jsx("g",{ref:te=>{te&&!x&&B(te)}})]}),o.tooltips.show&&b.selectedData&&b.currentFacet===e&&ie.jsx(fu,{content:Bwt(b.selectedData,s,I==null?void 0:I.content),x:n.x(String(b.selectedData.x))+c/2,y:n.y(String(b.selectedData.y))+f/2,offset:Q.length>1?c/2:0,active:!0,sideDistances:U,container:C,onClose:b.onClose,fixed:b.fixed})]})}function Twt({margins:e,captionsSizes:t,settingsId:n,chartSettings:r,chartSizes:a,chartsDimensions:i,facetKeys:o,scales:s,colorScale:c,sizeScale:f,groupedCells:A,cellsMeta:h,step:v,legend:g,aes:C,columnsCount:b,labelAngles:x,onTooltipHintSwitch:B}){let k=p3(B),[P,I]=tn.useState(),$=tn.useRef(null);tn.useEffect(()=>{$.current&&I($.current)},[]);let N=i[o[0]].padding,F=i[o[b-1]].padding,Z=e.left+a.chartsWidth+KZ,ee=e.top+N.top;return ie.jsx(y3,{dataId:n,children:ie.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:`0 0 ${a.totalWidth} ${a.totalHeight}`,width:a.totalWidth,height:a.totalHeight,fontFamily:"Manrope",children:[ie.jsx("defs",{children:Nm}),ie.jsxs("g",{transform:`translate(${e.left},${e.top})`,children:[ie.jsx(w3,{title:[r.title.name],show:r.title.show,position:r.title.position,leftPadding:N.left,rightPadding:F.right,chartsWidth:a.chartsWidth}),o.map(le=>{let{cells:Q}=A[le];return ie.jsx(_wt,{captionsSizes:t,facetKey:le,dimensions:i[le],scales:s,cells:Q,cellsMeta:h,stepX:v.x,stepY:v.y,colorScale:c,sizeScale:f,chartSettings:r,aes:C,labelAngles:x,margins:e,chartSizes:a,tooltipsData:k,tooltipsContainer:P},le)})]}),ie.jsx("g",{transform:`translate(${Z},${ee})`,children:ie.jsx(b3,{legendData:g})}),ie.jsx("g",{ref:$,style:{outline:"none"}})]})})}var kwt=(e,t)=>{let n=Math.min(...t),r=Math.max(...t);if(n===r){let o=e%2===0?[]:[n];for(let s=1;s<e/2+1;s++)o.push(n+s),o.unshift(n-s);return o}if(e<2)return[n,r];let a=(r-n)/(e-1),i=[];for(let o=0;o<e-1;o++)i.push(n+a*o);return i.push(r),i};function Mwt(e,t,n){let r=n;return e&&(e.colorRange&&(r=e.colorRange),e.method==="standardScaling"&&(r=[-2,2]),e.method==="meanNormalization"&&(r=[-.75,.75])),kwt(t,r)}var Pwt=class{constructor(){Be(this,"reactRoot",null);Be(this,"parentNode",null);Be(this,"rootNode",null);Be(this,"component",ie.jsx(ie.Fragment,{}));Be(this,"chartsDimensions",{});Be(this,"chartSizes",{chartWidth:600,chartHeight:350,chartsWidth:600,chartsHeight:350,totalWidth:600,totalHeight:350});Be(this,"margins",{top:Om,bottom:Om,left:Om,right:Om});Be(this,"captionsSizes",{xAxisCaptions:100,yAxisCaptions:100,xCaptionTail:0,yCaptionTail:0});Be(this,"labelAngles",{xAxisLabels:0,yAxisLabels:0});Be(this,"columnsCount",1);Be(this,"rowsCount",1);Be(this,"scales",{x:Qo().domain(["null"]).range([1]),y:Qo().domain(["null"]).range([1])});Be(this,"step",{x:10,y:10});Be(this,"colorScale",Zr().domain([0,1]).range(["white","black"]));Be(this,"sizeScale",rv().domain([0,1]).range([3,20]));Be(this,"legend",{width:0,height:0,items:[]})}clear(){var e;this.parentNode&&this.rootNode&&((e=this.parentNode)==null||e.removeChild(this.rootNode),this.parentNode=null,this.rootNode=null),setTimeout(()=>{var t;(t=this.reactRoot)==null||t.unmount(),this.reactRoot=null})}init(e){this.parentNode===null&&(this.parentNode=e,this.rootNode=document.createElement("div"),this.parentNode.appendChild(this.rootNode),this.reactRoot=Qh(this.rootNode))}updateMargins(e){this.margins={top:e.show?24+24*2:Om,bottom:Om,left:Om,right:this.legend.width},this.chartSizes.totalWidth=this.margins.left+this.chartSizes.chartsWidth+this.margins.right,this.chartSizes.totalHeight=this.margins.top+Math.max(this.chartSizes.chartsHeight,this.legend.height)+this.margins.bottom}updateLegendSize(e,t,n,r){if(!e.show){this.legend={width:0,height:0,items:[]};return}let a=[],i=Math.min(Math.max(this.chartSizes.chartHeight,250),350),o=Math.max(this.chartSizes.chartHeight,i),s={width:0,height:0,left:0,top:0},c=this.colorScale.domain(),f=h3(this.colorScale,[c[0],c[c.length-1]]),A=t.label??t.value,h=Zr([f[0],f[f.length-1]],[i,0]);a.push({id:"colorValue",type:"continuous",scale:this.colorScale,tickPositionScale:h,values:f,title:A,...s});let v=n.label??n.value,g=this.sizeScale.ticks(3),C=this.sizeScale.tickFormat(3),b=g.reduce((I,$)=>(I[String($)]=C($),I),{});if(a.push({id:"sizeValue",type:"size",title:v,scale:this.sizeScale,values:g,labels:b,...s}),!a.length){this.legend={width:0,height:0,items:[]};return}let x=S3(a,o,i),B=x[x.length-1],k=B.left+B.width+2*KZ,P=this.chartsDimensions[r[0]].padding;this.legend={width:k,height:o+P.top,items:x}}updateCaptionsSize(e,t,n){let r=new hc("bold 14px Arial"),{xKeys:a,yKeys:i,xLabels:o,yLabels:s}=e.meta;this.labelAngles={xAxisLabels:t.axisLabelsAngle,yAxisLabels:n.axisLabelsAngle};let c=0,f=0;for(let C of a){let b=r.getTextWidth(o[C]);b>c&&(c=b)}for(let C of i){let b=r.getTextWidth(s[C]);b>f&&(f=b)}let{xCaptionTail:A,yCaptionTail:h}=xwt(this.labelAngles,this.step,e,r),v=this.labelAngles.xAxisLabels/180*Math.PI,g=this.labelAngles.yAxisLabels/180*Math.PI;this.captionsSizes={xCaptionTail:A,yCaptionTail:h,xAxisCaptions:c*Math.sin(v)||vS,yAxisCaptions:f*Math.sin(g)||vS}}updateChartDimensions(e,t,n,r){let a=e.length,i=Math.min(t.nRows??a,a),o=Math.min(t.nCols??a,a);this.columnsCount=t.nRows?Math.ceil(a/i):o,this.rowsCount=Math.ceil(a/this.columnsCount),this.chartsDimensions={};let s=0,c=0;e.forEach((h,v)=>{let g=v%this.columnsCount+1,C=iZ(v,e.length,this.columnsCount,this.rowsCount),b=this.chartSizes.chartWidth,x=this.chartSizes.chartHeight,B=Cwt(n,r,this.captionsSizes,C,e,this.step.x,this.step.y);function k(F){return Math.max(up[F].reduce((Z,ee)=>Z+B[F][ee],0),gwt)}let P={left:k("left"),right:k("right"),top:k("top"),bottom:k("bottom")};P.left<this.captionsSizes.xCaptionTail&&(P.left=this.captionsSizes.xCaptionTail),P.bottom<this.captionsSizes.yCaptionTail&&(P.bottom=this.captionsSizes.yCaptionTail);let I=Swt(B,b,x),$=b+P.left+P.right,N=x+P.top+P.bottom;this.chartsDimensions[h]={left:s,top:c,inner:{width:b,height:x},outer:{width:$,height:N},padding:P,sideElementBBoxes:I,chartEdgeSides:C},s+=$,g===this.columnsCount&&(s=0,c+=N)});let f=e.slice(0,this.columnsCount).reduce((h,v)=>h+this.chartsDimensions[v].outer.width,0),A=e.filter((h,v)=>v%this.columnsCount===0).reduce((h,v)=>h+this.chartsDimensions[v].outer.height,0);this.chartSizes.chartsWidth=f,this.chartSizes.chartsHeight=A}updateChartsSizes(e,t){let{width:n,height:r,cellSize:a}=t;a&&(this.chartSizes.chartWidth=e.meta.xKeys.length*a,this.chartSizes.chartHeight=e.meta.yKeys.length*a),n&&r&&(this.chartSizes.chartWidth=n,this.chartSizes.chartHeight=r)}updateScales(e,t,n,r){let{width:a,height:i,cellSize:o}=t,{meta:s}=e,c=(C,b={})=>[...C].sort((x,B)=>n.sorting==="asc"?(b[x]??x).localeCompare(b[B]??B,"en",{numeric:!0}):(b[B]??B).localeCompare(b[x]??x,"en",{numeric:!0})),f=(C,b={})=>[...C].sort((x,B)=>r.sorting==="asc"?(b[x]??x).localeCompare(b[B]??B,"en",{numeric:!0}):(b[B]??B).localeCompare(b[x]??x,"en",{numeric:!0})),A=c(s.xKeys,s.xLabels),h=f(s.yKeys,s.yLabels);o?(this.step.x=o,this.step.y=o):a&&i&&(this.step.x=a/A.length,this.step.y=i/h.length);let v=new Array(A.length).fill(null).map((C,b)=>b*this.step.x),g=new Array(h.length).fill(null).map((C,b)=>b*this.step.y);this.scales.x=Qo().domain(A).range(v),this.scales.y=Qo().domain(h).range(g)}updateAesScale(e,t,n,r){this.colorScale=Zr().domain(Mwt(r,e.colorsList.length,n)).range(e.colorsList),this.sizeScale=rv(t,[e.minRadius,e.maxRadius])}render(e,t,n,r,a,i,o,s,c,f){var P;let{meta:A,facets:h}=a,{valueExtentSize:v,valueExtentColor:g}=A,{xAxis:C,yAxis:b,title:x,size:B}=t;this.updateChartsSizes(a,B),this.updateAesScale(c,v,g,s),this.updateScales(a,B,t.xAxis,t.yAxis),this.updateCaptionsSize(a,C,b),this.updateChartDimensions(r,n,C,b),this.updateLegendSize(t.legend,i,o,r),this.updateMargins(x);let k=ie.jsx(Twt,{aes:c,captionsSizes:this.captionsSizes,cellsMeta:A,columnsCount:this.columnsCount,chartsDimensions:this.chartsDimensions,chartSettings:t,chartSizes:this.chartSizes,sizeScale:this.sizeScale,colorScale:this.colorScale,facetKeys:r,facetSettings:n,groupedCells:h,labelAngles:this.labelAngles,legend:this.legend,margins:this.margins,scales:this.scales,settingsId:e,step:this.step,onTooltipHintSwitch:f});this.component=k,(P=this.reactRoot)==null||P.render(k)}renderError(e){var t;(t=this.reactRoot)==null||t.render(ie.jsx(Qv,{message:e}))}},Hwt=Pwt,ZZ=class{constructor(e){Be(this,"id");Be(this,"type","bubble");Be(this,"facetSettings");Be(this,"valueColumnSize");Be(this,"valueColumnColor");Be(this,"xColumn");Be(this,"yColumn");Be(this,"facetBy");Be(this,"normalization");Be(this,"NAValueAs");Be(this,"chartSettings");Be(this,"aes");var a,i,o,s,c,f,A,h,v,g;q3t.parse(e),this.id=Zn.uniqueId("settings"),this.facetSettings={titlePosition:"left",...e.facetSettings},this.facetBy=e.facetBy??[],this.valueColumnSize=e.valueSize,this.valueColumnColor=e.valueColor,this.xColumn=e.xColumn,this.yColumn=e.yColumn,this.NAValueAs=e.NAValueAs??null,this.normalization=e.normalization??null;let t=((a=e.size)==null?void 0:a.cellSize)??null,n=t?null:((i=e==null?void 0:e.size)==null?void 0:i.width)??(this.facetBy.length?400:600),r=t?null:((o=e==null?void 0:e.size)==null?void 0:o.height)??(this.facetBy.length?250:350);this.chartSettings={size:{width:n,height:r,cellSize:t},title:{position:"center",show:!0,...e.title,name:((s=e.title)==null?void 0:s.name)??"Chart"},yAxis:{title:e.yColumn.label??e.yColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,position:"left",axisLabelsAngle:90,sorting:"asc",...e.yAxis},xAxis:{title:e.xColumn.label??e.xColumn.value,showTicks:!0,showTitle:!0,showAxisLabels:!0,position:"bottom",axisLabelsAngle:90,sorting:"asc",...e.xAxis},frame:{type:((c=e.frame)==null?void 0:c.type)??"full"},legend:{show:!0,position:"right",...e.legend},tooltips:{show:!0,...e.tooltips}},this.aes={minRadius:((f=e.aes)==null?void 0:f.minRadius)??3,maxRadius:((A=e.aes)==null?void 0:A.maxRadius)??20,colorsList:((h=e.aes)==null?void 0:h.colorsList)??["black","white","red"],cellStrokeColor:((v=e.aes)==null?void 0:v.cellStrokeColor)??Vt,emptyCellColor:((g=e.aes)==null?void 0:g.emptyCellColor)??"white"}}},Dwt=class extends Lm{constructor(t,n,r){super(t,n);Be(this,"settings");Be(this,"chartRenderer",new Hwt);Be(this,"onTooltipHintSwitch",()=>{});Be(this,"calculatedData",null);this.settings=new ZZ(n),r&&(this.onTooltipHintSwitch=r[0])}mount(t){try{this.chartRenderer.init(t),this._updateData(),this._updateChart()}catch(n){n instanceof Error&&this.chartRenderer.renderError(n.message)}}unmount(){this.chartRenderer.clear()}updateSettingsAndData(t,n){try{let r=this.settings,a=this.data;this.settings=new ZZ(n),this.data=t,this._needUpdateCalculatedDataBySettings(r,this.settings)||this._needUpdateCalculatedDataByData(a,this.data)?this._updateData():this._updateAesInData(),this._updateChart()}catch(r){r instanceof Error&&this.chartRenderer.renderError(r.message)}}updateChartState(t,n){console.warn("no chart state for bubble chart")}export(){return this._updateChart(),b5(this.chartRenderer.component)}_needUpdateCalculatedDataBySettings(t,n){var r,a,i,o;return t.facetBy.some((s,c)=>{var f;return s.value!==((f=n.facetBy[c])==null?void 0:f.value)})||((r=t.normalization)==null?void 0:r.method)!==((a=n.normalization)==null?void 0:a.method)||((i=t.normalization)==null?void 0:i.direction)!==((o=n.normalization)==null?void 0:o.direction)||t.xColumn.value!==n.xColumn.value||t.yColumn.value!==n.yColumn.value||t.valueColumnColor.value!==n.valueColumnColor.value||t.valueColumnSize.value!==n.valueColumnSize.value||t.NAValueAs!==n.NAValueAs}_needUpdateCalculatedDataByData(t,n){let r=Object.keys(t.data),a=Object.keys(n.data);return t.id!==n.id||r.length!==a.length||r.some(i=>{var o;return t.data[i].length!==((o=n.data[i])==null?void 0:o.length)})}_updateData(){let{facetBy:t,xColumn:n,yColumn:r,valueColumnSize:a,valueColumnColor:i,normalization:o,NAValueAs:s}=this.settings,c=t.map(v=>this.data.getColumnCategories(v.value)),f=c.length?xZ([...c]):[["null"]],A=t.map(v=>v.value)??null;this.data.setGrouping([...A]);let h=mwt(this.data,n,r,a,i,t,f,o,s);this.calculatedData={facetKeys:h.meta.facetKeys,groupedCellsData:h}}_updateAesInData(){this.calculatedData}_updateChart(){if(!this.calculatedData)return;let{id:t,chartSettings:n,facetSettings:r,valueColumnColor:a,valueColumnSize:i,normalization:o,aes:s}=this.settings;this.chartRenderer.render(t,n,r,this.calculatedData.facetKeys,this.calculatedData.groupedCellsData,a,i,o,s,this.onTooltipHintSwitch)}};function $wt(e){return"type"in e&&e.type==="columns"}var JZ=class j${constructor(t,n){Be(this,"id");Be(this,"data");Be(this,"rowsCount");Be(this,"columnNames");Be(this,"rowsGrouped");this.id=t,this.data=n,this.columnNames=Object.keys(n),this.rowsCount=this.columnNames.length?n[this.columnNames[0]].length:0}static from(t){if(t instanceof j$)return t;if($wt(t))return new j$(t.id,t.values);f1(t,"Unknown input data format")}get rows(){let t=this.columnNames,n=[];for(let r=0;r<this.rowsCount;r++)n.push(t.reduce((a,i)=>(a[i]=this.data[i][r],a),{}));return n}getColumn(t){return this.data[t]}getColumnCategories(t){if(!this.columnNames.includes(t))throw new Error(`Column ${t} does not exist`);return Zn.uniq(this.getColumn(t)).filter(n=>n!==null).map(String)}setGrouping(t){let n={grouped:{},rows:this.rows},r=[n];t.forEach(a=>{let i=a===null?["null"]:this.getColumnCategories(a),o=[];r.forEach(s=>{if(a===null)s.grouped={null:{rows:s.rows,grouped:{}}},o.push(s.grouped.null);else{let c=Zn.groupBy(s.rows,f=>String(f[a]));s.grouped=i.reduce((f,A)=>(f[A]={rows:c[A]??[],grouped:{}},o.push(f[A]),f),{})}}),r=o}),this.rowsGrouped=n.grouped}getColumnByGrouping(t,n){if(!this.rowsGrouped)return[];if(!t.length)return this.rows.map(a=>Number(a[n]));let r={grouped:this.rowsGrouped,rows:this.rows};return t.forEach(a=>{let i=r.grouped[a??"null"];if(!i)return[];r=i}),r.rows.map(a=>Number(a[n]))}getRowsByGrouping(t){if(!this.rowsGrouped)return[];if(!t.length)return this.rows;let n={grouped:this.rowsGrouped,rows:this.rows};return t.forEach(r=>{let a=n.grouped[r??"null"];if(!a)return[];n=a}),n==null?void 0:n.rows}},Iwt=class U${constructor(t){Be(this,"node");Be(this,"chart");this.chart=t}static createChart(t,n,r){let{type:a}=n;if(a==="discrete")return new I7t(t,n,r);if(a==="dendro")return new M4t(t,n,r);if(a==="scatterplot")return new L6t(t,n,r);if(a==="scatterplot-umap")return new dwt(t,n,r);if(a==="heatmap")return new g9t(t,n,r);if(a==="histogram")return new G9t(t,n,r);if(a==="bubble")return new Dwt(t,n,r);f1(a,`Unknown chart type: ${a}`)}static newPlot(t,n,r){let a=JZ.from(t);return new this(U$.createChart(a,n,r))}get calculatedData(){return this.chart.calculatedData}mount(t){this.node=t,this.chart.mount(t)}unmount(){delete this.node,this.chart.unmount()}updateSettingsAndData(t,n){if(n.type!==this.chart.settings.type){let r=U$.createChart(this.chart.data,n);this.node?(this.chart.unmount(),this.chart=r,this.chart.mount(this.node)):this.chart=r}else this.chart.updateSettingsAndData(JZ.from(t),n)}updateChartState(t,n){this.chart.updateChartState(t,n)}export(){return this.chart.export()}};/*! Bundled license information:
15131
15131
 
15132
15132
  @stdlib/utils-define-property/lib/define_property.js:
15133
15133
  (**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/graph-maker",
3
- "version": "1.1.117",
3
+ "version": "1.1.118",
4
4
  "type": "module",
5
5
  "main": "dist/graph-maker.umd.cjs",
6
6
  "module": "dist/graph-maker.js",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@ag-grid-community/core": "^32.3.3",
34
34
  "@milaboratories/helpers": "^1.6.11",
35
- "@milaboratories/miplots4": "^1.0.111",
35
+ "@milaboratories/miplots4": "^1.0.112",
36
36
  "@milaboratories/pf-plots": "^1.1.18",
37
37
  "@platforma-sdk/model": "^1.34.10",
38
38
  "@platforma-sdk/ui-vue": "^1.34.15",