PageSourceSearch

https://magnos.ai/assets/scatter-plot-ChHIBh__.js

js magnos.ai collected 2026-10-05 13:12:46 UTC 14,974 bytes, 1 lines download raw bytes

1import{j as n}from"./ui-radix-DkUivN35.js";import{a as j}from"./react-vendor-BfJJLrXf.js";import{cp as Re,cq as De,co as Xe,bm as Ee,cN as Ye,C as W,d as V,aa as _,g as O,e as Q,ak as ge,al as pe,am as be,an as ye,ao as je,b5 as Be,av as qe,aw as He,ax as Ue,cn as Ge,cI as ke}from"./index-DTzqVQuj.js";import{R as Ze,r as Je,C as Qe,X as Ke,Y as et,d as K,s as tt,T as rt}from"./charts-BUgAcd3n.js";import"./firebase-ArwW0mss.js";import"./dnd-aFKre6kL.js";function Me(e,t="",r=""){var a,f;const s=e.some(u=>u.id===t)?t:((a=e[0])==null?void 0:a.id)??"",o=e.some(u=>u.id===r)&&(r!==s||e.length===1)?r:((f=e.find(u=>u.id!==s))==null?void 0:f.id)??s;return{xMetric:s,yMetric:o}}const nt=e=>{if(e==null)return null;if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"){const t=e.trim();if(!t)return null;const r=Number(t);return Number.isFinite(r)?r:null}return null};function Se(e,t){return Ge(e,{metric:t,percentInput:(t==null?void 0:t.unit)==="percent"?"ratio":"points"})}function Ne(e,t){const r=e[t],s=nt(r);return s===null&&r!==null&&r!==void 0&&console.warn("[scatter-plot] Non-numeric backend value for metric %s on %s: %o",t,e.date_key,r),s}function st(e){const t=e.length;if(t<2)return null;const r=e.reduce((d,l)=>d+l.x,0),s=e.reduce((d,l)=>d+l.y,0),o=e.reduce((d,l)=>d+l.x*l.y,0),a=e.reduce((d,l)=>d+l.x*l.x,0),f=t*a-r*r;if(f===0)return null;const u=(t*o-r*s)/f,m=(s-u*r)/t;return{slope:u,intercept:m}}function ot(e){const t=e.length;if(t<2)return 0;const r=e.reduce((d,l)=>d+l.x,0),s=e.reduce((d,l)=>d+l.y,0),o=e.reduce((d,l)=>d+l.x*l.y,0),a=e.reduce((d,l)=>d+l.x*l.x,0),f=e.reduce((d,l)=>d+l.y*l.y,0),u=t*o-r*s,m=Math.sqrt((t*a-r*r)*(t*f-s*s));return m===0?0:u/m}function it(e){try{let t=e;e.includes("T")&&(t=e.split("T")[0]);const r=t.split("-");if(r.length===3){const[s,o,a]=r.map(Number);return Number.isNaN(s)||Number.isNaN(o)||Number.isNaN(a)||s<1900||o<1||a<1?e:at(s,o,a,{month:"long",day:"numeric",year:"numeric"})}return e}catch(t){return console.error("Date formatting error:",t,"Date key:",e),e}}function at(e,t,r,s){return new Date(Date.UTC(e,t-1,r,12)).toLocaleDateString("en-US",{timeZone:"America/Los_Angeles",...s})}function lt({active:e,payload:t}){if(e&&t&&t.length>0){const r=t[0].payload;return n.jsxs("div",{className:"bg-background border border-border rounded-lg p-3 shadow-md",children:[n.jsx("p",{className:"font-semibold",children:it(r.date)}),n.jsxs("p",{className:"text-sm",children:[n.jsx("span",{className:"text-muted-foreground",children:"X:"})," ",n.jsx(ke,{display:r.xFormatted})]}),n.jsxs("p",{className:"text-sm",children:[n.jsx("span",{className:"text-muted-foreground",children:"Y:"})," ",n.jsx(ke,{display:r.yFormatted})]})]})}return null}function ct(e,t,r){if(e===0)return r[0];let s=r[0],o=1/0;for(const a of r){const f=Math.ceil(e/a)+1;if(f>=4&&f<=12){const u=Math.abs(f-t);u<o&&(o=u,s=a)}}return s}function ee(e){return(e==null?void 0:e.unit)==="percent"}function te(e){return(e==null?void 0:e.unit)==="usd"}function dt(e){return(e==null?void 0:e.unit)==="ratio"}function ut(e){return e<10?[.01,.02,.05,.1,.2,.25,.5,1,2,2.5,5]:e<100?[1,2,5,10,20,25,50]:e<1e4?[10,20,25,50,100,200,250,500,1e3,2e3,2500,5e3]:e<1e6?[100,200,250,500,1e3,2e3,2500,5e3,1e4,2e4,25e3,5e4,1e5,2e5,25e4,5e5]:[1e4,2e4,5e4,1e5,2e5,25e4,5e5,1e6,2e6,25e5,5e6]}function ft(e){return e<100?[1,2,5,10,20,25,50]:e<1e4?[10,25,50,100,250,500,1e3,2500,5e3]:[100,250,500,1e3,2500,5e3,1e4,25e3,5e4]}function xt(e,t){let r;ee(t)?r=.01:te(t)?r=Math.max(100,Math.ceil(e*.1/100)*100):r=Math.max(1,Math.ceil(e*.1));const s=Math.max(0,e-r*2),o=e+r*2;return{domain:[s,o],ticks:[s,s+r,e,o-r,o].filter((a,f,u)=>u.indexOf(a)===f)}}function mt(e,t,r){const s=[];let o=e;for(;o<=t*(1+Number.EPSILON);){const a=Math.round(o/r)*r;if(s.push(a),o+=r,s.length>20)break}return s}function ht(e){if(e.length>=5||e.length<=1)return e;const r=(e[1]-e[0])/2,s=[];for(let a=0;a<e.length-1;a++)s.push(e[a],e[a]+r);const o=e.at(-1);return o!==void 0&&s.push(o),s}function ve(e,t,r,s){if(Math.abs(t-e)<Number.EPSILON)return xt(e,s);let o,a=!1,f=!1;if(ee(s))o=[.001,.0025,.005,.01,.02,.025,.05,.1,.2,.25,.5],a=!0;else if(te(s)){const b=Math.max(Math.abs(e),Math.abs(t));o=ut(b),f=!0}else{const b=Math.max(Math.abs(e),Math.abs(t));o=ft(b)}const u=t-e,m=ct(u,r,o);let d=Math.floor(e/m)*m,l=Math.ceil(t/m)*m;d===e&&(d=d-m),l===t&&(l=l+m),a?(d=Math.max(0,d),l=Math.min(1,l)):(f||e>=0)&&(d=Math.max(0,d));const T=mt(d,l,m),D=ht(T);return{domain:[d,l],ticks:D}}function Fe(e,t){const r=te(t),s=ee(t),o=dt(t);if(s||o)return"full";const a=Math.max(...e);return a>=1e6||a>=1e4?"compact":"full"}function gt(e){if(e>=1e6){const t=e/1e6;return`$${t.toFixed(t>=10?0:1)}m`}else{const t=e/1e3;return`$${t.toFixed(t>=100?0:1)}k`}}function Ce(e){if(e>=1e6){const t=e/1e6;return`${t.toFixed(t>=10?0:1)}m`}else{const t=e/1e3;return`${t.toFixed(t>=100?0:1)}k`}}function pt(e,t){return`${(e*100).toFixed(t)}%`}function R(e,t,r="full"){if(!t)return r==="compact"?Ce(e):Math.round(e).toLocaleStr
1ing();if(t.unit==="usd")return r==="compact"?gt(e):`$${Math.round(e).toLocaleString()}`;if(t.unit==="percent"){const s=t.format_spec==="percent2"?2:1;return pt(e,s)}return t.unit==="ratio"?`${e.toFixed(e>=1?1:2)}x`:r==="compact"?Ce(e):Math.round(e).toLocaleString()}function bt(e,t){const r=e.x-t.x,s=e.y-t.y;return r*r+s*s}function yt(e){let t=e[0],r=e[1],s=0;for(let o=0;o<e.length;o++)for(let a=o+1;a<e.length;a++){const f=bt(e[o],e[a]);f>s&&(s=f,t=e[o],r=e[a])}return[t,r]}function jt(e,t,r,s){const o=[];for(const u of r){const m=e*u+t;m>=s[0]&&m<=s[1]&&o.push({x:u,y:m})}if(e!==0)for(const u of s){const m=(u-t)/e;m>=r[0]&&m<=r[1]&&o.push({x:m,y:u})}if(o.length<2)return null;const[a,f]=yt(o);return{x1:a.x,y1:a.y,x2:f.x,y2:f.y}}function kt(e){const t=Math.abs(e);let r="",s="";return t>=.7?(r=e>0?"Strong Positive":"Strong Negative",s=e>0?"text-green-600":"text-red-600"):t>=.3?(r=e>0?"Moderate Positive":"Moderate Negative",s="text-yellow-600"):(r="Weak",s="text-gray-600"),{strength:r,colorClass:s}}function Tt({granularity:e,selectedMetrics:t=[]}){var fe,xe;const r=Re(),{breakdownData:s,breakdownProjections:o,isBreakdownLoading:a,isLoading:f,isInitializing:u,isDateRangeResolved:m=!0,metadataDataset:d,metricIds:l,sourceId:T}=De(),{selectedScopeId:D}=Xe(),{data:b,isLoading:Le}=Ee(d,D),X=j.useMemo(()=>{const i=new Set(l);return((b==null?void 0:b.metrics)??[]).filter(c=>i.has(c.metric_id)).filter(c=>T===Ye||c.is_funnel_eligible!==!1).toSorted((c,M)=>(c.display_order??999999)-(M.display_order??999999)).map(c=>({id:c.metric_id,label:c.label}))},[l,b==null?void 0:b.metrics,T]),k=j.useMemo(()=>{if(t.length===0)return X;const i=new Set(t);return X.filter(c=>i.has(c.id))},[X,t]),N=j.useMemo(()=>{const i=new Map;for(const c of(b==null?void 0:b.metrics)??[])i.set(c.metric_id,c);return i},[b]),re=Me(k),[E,ne]=j.useState(re.xMetric),[Y,se]=j.useState(re.yMetric),oe=Me(k,E,Y),g=oe.xMetric,p=oe.yMetric,P=e??"daily";j.useEffect(()=>{E!==g&&ne(g),Y!==p&&se(p)},[g,p,E,Y]);const z=j.useMemo(()=>{const i=o.total,c=[g,p].filter(Boolean);return c.length>0&&(i==null?void 0:i.granularity)===P&&c.every(M=>{var y;return(y=i==null?void 0:i.metricIds)==null?void 0:y.includes(M)})},[o,P,g,p]),B=j.useMemo(()=>{var c;const i=o.total;return z&&i&&i.data.length>0?i.data:(s&&s.length>0&&console.debug("[scatter-plot] Total projection unavailable, stale metric set, or granularity mismatch (requested=%s, available=%s); scatter plot requires a current total projection.",P,((c=o.total)==null?void 0:c.granularity)??"none"),[])},[o,s,P,z]),we=j.useMemo(()=>{const i={data:[],regression:null,correlation:0,averages:{x:0,y:0},domain:{x:[0,100],y:[0,100]},ticks:{x:[],y:[]},trendlineSegment:null,xFormat:"full",yFormat:"full"};if(B.length===0||!g||!p)return i;const c=N.get(g),M=N.get(p);if(!c||!M)return console.error("[scatter-plot] Missing metric metadata for",{xMetric:g,yMetric:p}),i;const y=B.map(x=>{const S=Ne(x,g),J=Ne(x,p);return S===null&&console.debug("[scatter-plot] Missing backend value for x-metric %s on %s",g,x.date_key),J===null&&console.debug("[scatter-plot] Missing backend value for y-metric %s on %s",p,x.date_key),{date:x.date_key,x:S,y:J,xFormatted:Se(S,c),yFormatted:Se(J,M)}}).filter(x=>typeof x.x=="number"&&typeof x.y=="number"&&Number.isFinite(x.x)&&Number.isFinite(x.y));if(y.length===0)return i;const I=st(y),Pe=ot(y),me=y.length,ze={x:y.reduce((x,S)=>x+S.x,0)/me,y:y.reduce((x,S)=>x+S.y,0)/me},H=y.map(x=>x.x),U=y.map(x=>x.y),Ae=Math.min(...H),$e=Math.max(...H),Ie=Math.min(...U),We=Math.max(...U),G=ve(Ae,$e,8,c),Z=ve(Ie,We,8,M),Ve=Fe(H,c),_e=Fe(U,M),w={x:G.domain,y:Z.domain},Oe={x:G.ticks.filter(x=>x>=w.x[0]&&x<=w.x[1]),y:Z.ticks.filter(x=>x>=w.y[0]&&x<=w.y[1])};let he=null;return I&&(he=jt(I.slope,I.intercept,G.domain,Z.domain)),{data:y,regression:I,correlation:Pe,averages:ze,domain:w,ticks:Oe,trendlineSegment:he,xFormat:Ve,yFormat:_e}},[B,g,p,N]),{data:q,correlation:v,averages:A,domain:ie,ticks:$,trendlineSegment:F,xFormat:ae,yFormat:le}=we,ce=N.get(g),de=N.get(p),C=((fe=k.find(i=>i.id===g))==null?void 0:fe.label)||g,L=((xe=k.find(i=>i.id===p))==null?void 0:xe.label)||p,ue=kt(v),Te=!!(o.total&&!z);if(u||!m||Le||(!s||s.length===0)&&(f||a)||a&&!z||Te)return n.jsxs(W,{className:"w-full",children:[n.jsx(V,{children:n.jsx(_,{variant:"wave",className:"h-5 w-40"})}),n.jsx(O,{children:n.jsxs("div",{className:"h-80 flex flex-col p-4",children:[n.jsxs("div",{className:"flex flex-1 gap-2",children:[n.jsx("div",{className:"flex flex-col justify-between py-2",children:Array.from({length:5}).map((i,c)=>n.jsx(_,{variant:"wave",className:"h-3 w-8"},c))}),n.jsx("div",{className:"flex-1 relative",children:[{left:"15%",top:"60%"},{left:"25%",top:"45%"},{left:"35%",top:"55%"},{left:"40%",top:"30%"},{left:"50%",top:"40%"},{left:"55%",top:"25%"},{left:"65%",top:"35%"},{left:"70%",top:"50%"},{left:"80%",top:"20%"},{left:"85%",top:"45%"},{left:"20%",top:"70%"},{left:"60%",top:"60%"}].map((i,c)=>n.jsx(_,{variant:"wave",className:"absolute size-3 rounded-full",style:i},c))})]}),n.jsx("div",{className:"flex gap-4 mt-2 ml-10 justify-between",children:Array.from({length:5}).map((i,c)=>n.jsx(_,{variant:"wave",className:"h-3 w-10"},c))})]})})]});if(k.length===0)return n.jsxs(W,{className:"w-full",children:[n.jsx(V,{children:n.jsx(Q,{children:"Correlation Analysis"})}),n.jsx(O,{children:n.jsx("div",{className:"h-80 flex items-center justify-center text-muted-foreground",children:"No metrics available for correlation analysis."})})]});const h=r?{selectWidth:"w-28",corrTextSize:"text-sm",chartHeight:"h-72",chartMargin:{top:0,right:5,left:0,bottom:30},tickFontSize:10,tickMarginPx:4,yAxisWidth:45,labelFontSize:"11px",xLabelOffset:-20,yLabelOffset:-5,refLabelFontSize:"10px",refLabelOffset:8,headerFlexClass:"flex flex-col gap-3",titleFlexClass:"flex flex-col gap-2"}:{selectWidth:"w-32",corrTextSize:"text-base",chartHeight:"h-96",chartMargin:{top:0,right:20,left
1:20,bottom:40},tickFontSize:12,tickMarginPx:8,yAxisWidth:70,labelFontSize:"14px",xLabelOffset:-30,yLabelOffset:-10,refLabelFontSize:"14px",refLabelOffset:15,headerFlexClass:"flex items-center justify-between",titleFlexClass:"flex items-center gap-4"};return q.length===0?n.jsxs(W,{className:"w-full",children:[n.jsx(V,{children:n.jsx(Q,{children:"Correlation Analysis"})}),n.jsx(O,{children:n.jsx("div",{className:"h-80 flex items-center justify-center text-muted-foreground",children:"No data available for the selected period and filters"})})]}):n.jsxs(W,{className:"w-full",children:[n.jsx(V,{children:n.jsxs("div",{className:h.headerFlexClass,children:[n.jsxs("div",{className:h.titleFlexClass,children:[n.jsx(Q,{children:"Correlation Analysis"}),k.length>1&&n.jsxs("div",{className:"flex items-center gap-2 p-1",children:[n.jsxs(ge,{value:g,onValueChange:ne,children:[n.jsx(pe,{className:`${h.selectWidth} h-8 bg-background`,children:n.jsx(be,{})}),n.jsx(ye,{children:k.map(i=>n.jsx(je,{value:i.id,disabled:i.id===p,children:i.label},i.id))})]}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"vs"}),n.jsxs(ge,{value:p,onValueChange:se,children:[n.jsx(pe,{className:`${h.selectWidth} h-8 bg-background`,children:n.jsx(be,{})}),n.jsx(ye,{children:k.map(i=>n.jsx(je,{value:i.id,disabled:i.id===g,children:i.label},i.id))})]})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Be,{children:n.jsxs(qe,{children:[n.jsx(He,{asChild:!0,children:n.jsx("span",{className:"text-xs text-muted-foreground cursor-help",children:"ⓘ"})}),n.jsx(Ue,{className:"bg-background border border-border text-foreground shadow-md max-w-xs p-3 rounded-md",children:n.jsxs("p",{className:"max-w-xs",children:["Correlation Coefficient (r) = ",v.toFixed(3),": As ",C," ",v>0?"increases":"decreases",", ",L," tends to ",v>0?"increase":"decrease","."]})})]})}),n.jsxs("span",{className:`${h.corrTextSize} font-medium ${ue.colorClass}`,children:["Correlation (r): ",v.toFixed(3)," (",ue.strength,")"]})]})]})}),n.jsx(O,{children:n.jsx("div",{className:`${h.chartHeight} w-full`,children:n.jsx(Ze,{width:"100%",height:"100%",children:n.jsxs(Je,{data:q,margin:h.chartMargin,children:[n.jsx(Qe,{strokeDasharray:"3 3",stroke:"rgb(var(--border))",opacity:.2,horizontalPoints:$.y,verticalPoints:$.x}),n.jsx(Ke,{type:"number",dataKey:"x",name:C,domain:ie.x,ticks:$.x,tickMargin:h.tickMarginPx,interval:"preserveStartEnd",tick:{fontSize:h.tickFontSize,fill:"rgb(var(--muted-foreground))"},tickFormatter:i=>R(i,ce,ae),axisLine:{stroke:"rgb(var(--border))",strokeWidth:1},tickLine:{stroke:"rgb(var(--border))",strokeWidth:1},label:{value:C,position:"insideBottom",offset:h.xLabelOffset,style:{fontSize:h.labelFontSize,fontWeight:600,fill:"rgb(var(--foreground))",textAnchor:"middle"}}}),n.jsx(et,{type:"number",dataKey:"y",name:L,domain:ie.y,ticks:$.y,tickMargin:h.tickMarginPx,width:h.yAxisWidth,interval:"preserveStartEnd",tick:{fontSize:h.tickFontSize,fill:"rgb(var(--muted-foreground))"},tickFormatter:i=>R(i,de,le),axisLine:{stroke:"rgb(var(--border))",strokeWidth:1},tickLine:{stroke:"rgb(var(--border))",strokeWidth:1},label:{value:L,angle:-90,position:"insideLeft",offset:h.yLabelOffset,style:{fontSize:h.labelFontSize,fontWeight:600,fill:"rgb(var(--foreground))",textAnchor:"middle"}}}),n.jsx(K,{x:A.x,stroke:"rgb(var(--muted-foreground))",strokeDasharray:"5 5",opacity:.6,label:{value:`Avg. ${C}: ${R(A.x,ce,ae)}`,position:"insideTopLeft",offset:h.refLabelOffset,style:{fontSize:h.refLabelFontSize,fill:"rgb(var(--muted-foreground))",fontWeight:"600"}}}),n.jsx(K,{y:A.y,stroke:"rgb(var(--muted-foreground))",strokeDasharray:"5 5",opacity:.6,label:{value:`Avg. ${L}: ${R(A.y,de,le)}`,position:"insideBottomRight",offset:h.refLabelOffset,style:{fontSize:h.refLabelFontSize,fill:"rgb(var(--muted-foreground))",fontWeight:"600"}}}),n.jsx(tt,{name:`${L} vs ${C}`,data:q,fill:"rgb(var(--chart-1))",r:4}),F&&n.jsx(K,{segment:[{x:F.x1,y:F.y1},{x:F.x2,y:F.y2}],stroke:"rgb(var(--muted-foreground))",strokeWidth:2}),n.jsx(rt,{content:n.jsx(lt,{})})]})})})})]})}export{Tt as ScatterPlot};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.