"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6619],{311:function(e,t,n){n.d(t,{Z:function(){return l}});function l(e,t){let n=URL.createObjectURL(e),l=document.createElement("a");l.setAttribute("href",n),l.setAttribute("download",t),l.click(),l.remove(),URL.revokeObjectURL(n)}},86619:function(e,t,n){n.d(t,{Z:function(){return P}});var l=n(85893),r=n(12498),s=n(204),a=n(88911),o=n(33838),c=n(93344),i=n(7754),u=n(23100),d=n(47523),m=n(89154),x=n(66303),h=n(6450),f=n(46887),j=n(23428),b=n(54232),g=n(29306),k=n.n(g),y=n(67294),p=n(3749),C=n(38459),S=n(57460),v=n(311),w=n(40402),Z=n(21967),_=n(34629),X=n(43818),z=n(20809),Y=n(56710),R=y.memo(e=>{let{type:t,scale:n,ticks:s,tickFormatGenerator:a,noAnimation:o,anchorEl:c,...i}=e,u=y.useRef(null),d=(0,r.ff)("blackAlpha.600","whiteAlpha.500"),m=(0,_.dQ)("colors",d);return y.useEffect(()=>{if(!u.current)return;let e=("left"===t?X.y4O:X.LLu)(n).ticks(s);a&&e.tickFormat(a(e));let l=X.Ys(u.current);o?l.call(e):l.transition().duration(750).ease(X.Nyw).call(e),l.select(".domain").remove(),l.selectAll("line").remove(),l.selectAll("text").attr("opacity",1).attr("color",m).attr("font-size","0.75rem")},[n,s,a,o,t,m]),y.useEffect(()=>{if(!c)return;let e=X.Ys(c);return e.on("mouseout.axisX",()=>{X.Ys(u.current).selectAll("text").style("font-weight","normal")}).on("mousemove.axisX",e=>{let[t]=X.cx$(e,c),l=n.invert(t),r=X.Ys(u.current).selectAll("text"),s=r.data(),a=X.YFb(e=>e).left(s,l);r.style("font-weight",(e,t)=>t===a-1?"bold":"normal")}),()=>{e.on("mouseout.axisX mousemove.axisX",null)}},[c,n]),(0,l.jsx)("g",{ref:u,...i})}),A=y.memo(e=>{let{type:t,scale:n,ticks:r,size:s,noAnimation:a,...o}=e,c=y.useRef(null),i=(0,_.dQ)("colors","divider");return y.useEffect(()=>{if(!c.current)return;let e=("vertical"===t?X.LLu:X.y4O)(n).ticks(r).tickSize(-s),l=X.Ys(c.current);a?l.call(e):l.transition().duration(750).ease(X.Nyw).call(e),l.select(".domain").remove(),l.selectAll("text").remove(),l.selectAll("line").attr("stroke",i)},[n,r,s,a,t,i]),(0,l.jsx)("g",{ref:c,...o})}),E=n(74873),N=n(46187),G=y.memo(e=>{let{anchorEl:t,height:n,scale:r,data:s,onSelect:a}=e,o=(0,_.dQ)("colors","blue.200"),c=y.useRef(null),i=y.useRef(!1),u=y.useRef(),d=y.useRef(),m=y.useCallback(e=>{let t=r.invert(e);return(0,X.YFb(e=>e.date).left)(s[0].items,t,1)},[s,r]),x=y.useCallback((e,t)=>{let n=t-e;X.Ys(c.current).attr("opacity",1),X.Ys(c.current).select(".ChartSelectionX__line_left").attr("x1",e).attr("x2",e),X.Ys(c.current).select(".ChartSelectionX__line_right").attr("x1",t).attr("x2",t),X.Ys(c.current).select(".ChartSelectionX__rect").attr("x",n>0?e:n+e).attr("width",Math.abs(n))},[]),h=y.useCallback((e,t)=>{let n=r.invert(e),l=r.invert(t);Math.abs((0,p.Z)(n).diff(l,"day"))>2&&a([p.Z.min((0,p.Z)(n),(0,p.Z)(l)).toDate(),p.Z.max((0,p.Z)(n),(0,p.Z)(l)).toDate()])},[a,r]),f=y.useCallback(()=>{i.current=!1,u.current=void 0,d.current=void 0,X.Ys(c.current).attr("opacity",0)},[]),j=y.useCallback(()=>{i.current&&(u.current&&d.current&&h(u.current,d.current),f())},[f,h]);return y.useEffect(()=>{if(!t)return;let e=X.Ys(t);return e.on("mousedown.selectionX",e=>{let[n]=X.cx$(e,t);i.current=!0,u.current=n}).on("mousemove.selectionX",e=>{if(i.current){let[n]=X.cx$(e,t);u.current&&x(u.current,n),d.current=n}}).on("mouseup.selectionX",j).on("touchstart.selectionX",e=>{let n=X.daD(e,t);i.current=2===n.length}).on("touchmove.selectionX",e=>{if(i.current){let n=X.daD(e,t);2===n.length&&Math.abs(n[0][0]-n[1][0])>5&&(x(n[0][0],n[1][0]),u.current=n[0][0],d.current=n[1][0])}}).on("touchend.selectionX",j),X.Ys("body").on("mouseup.selectionX",function(t){void 0!==u.current&&t.target!==e.node()&&j()}),()=>{e.on(".selectionX",null),X.Ys("body").on(".selectionX",null)}},[t,f,x,m,j,h]),(0,l.jsxs)("g",{className:"ChartSelectionX",ref:c,opacity:0,children:[(0,l.jsx)("rect",{className:"ChartSelectionX__rect",width:0,height:n,fill:"rgba(66, 153, 225, 0.1)"}),(0,l.jsx)("line",{className:"ChartSelectionX__line ChartSelectionX__line_left",x1:0,x2:0,y1:0,y2:n,stroke:o}),(0,l.jsx)("line",{className:"ChartSelectionX__line ChartSelectionX__line_right",x1:0,x2:0,y1:0,y2:n,stroke:o})]})}),L=n(25007),O=n(8048);let M={bottom:20,left:10,right:20,top:10};var I=y.memo(e=>{let{isEnlarged:t,items:n,onZoom:r,isZoomResetInitial:s,title:a,margin:o,units:c,noAnimation:i}=e,u=(0,z.Z)(),d=(0,_.dQ)("colors","mantleGreen.400"),m="chart-".concat(a.split(" ").join(""),"-").concat(t?"fullscreen":"small"),x=y.useRef(null),[h,f]=y.useState([n[0].date,n[n.length-1].date]),j=y.useMemo(()=>n.filter(e=>e.date>=h[0]&&e.date<=h[1]),[n,h]),b=j.length>1e11,g=y.useMemo(()=>b?X.Q3u(j,e=>({date:e[0].date,value:X.Smz(e,e=>e.value),dateLabel:"".concat(X.i$Z("%e %b %Y")(e[0].date)," – ").concat(X.i$Z("%e %b %Y")(e[e.length-1].date))}),e=>"".concat((0,p.Z)(e.date).week()," / ").concat((0,p.Z)(e.date).year())).map(e=>{let[,t]=e;return t}):j,[b,j]),k=y.useMemo(()=>[{items:g,name:"Value",color:d,units:c}],[d,g,c]),C=y.useMemo(()=>({...M,...o}),[o]),S=y.useMemo(()=>({x:{ticks:t?8:4},y:{ticks:t?6:3,nice:!0}}),[t]),{ref:v,rect:w,innerWidth:Z,innerHeight:I,chartMargin:D,axes:F}=(0,O.Z)({data:k,margin:C,axesConfig:S}),Q=y.useCallback(e=>{f([e[0],e[1]]),r()},[r]);return y.useEffect(()=>{s&&f([n[0].date,n[n.length-1].date])},[s,n]),(0,l.jsx)("svg",{width:"100%",height:"100%",ref:v,cursor:"pointer",id:m,opacity:w?1:0,children:(0,l.jsxs)("g",{transform:"translate(".concat((null==D?void 0:D.left)||0,",").concat((null==D?void 0:D.top)||0,")"),children:[(0,l.jsx)(A,{type:"horizontal",scale:F.y.scale,ticks:S.y.ticks,size:Z,noAnimation:!0}),(0,l.jsx)(Y.Z,{id:m,data:g,color:d,xScale:F.x.scale,yScale:F.y.scale,noAnimation:i}),(0,l.jsx)(E.Z,{data:g,xScale:F.x.scale,yScale:F.y.scale,stroke:d,animation:"none",strokeWidth:u?1:2}),(0,l.jsx)(R,{type:"left",scale:F.y.scale,ticks:S.y.ticks,tickFormatGenerator:F.y.tickFormatter,noAnimation:!0}),(0,l.jsx)(R,{type:"bottom",scale:F.x.scale,transform:"translate(0, ".concat(I,")"),ticks:S.x.ticks,anchorEl:x.current,tickFormatGenerator:F.x.tickFormatter,noAnimation:!0}),(0,l.jsxs)(N.Z,{ref:x,width:Z,height:I,children:[(0,l.jsx)(L.Z,{anchorEl:x.current,width:Z,tooltipWidth:b?280:200,height:I,xScale:F.x.scale,yScale:F.y.scale,data:k,noAnimation:i}),(0,l.jsx)(G,{anchorEl:x.current,height:I,scale:F.x.scale,data:k,onSelect:Q})]})]})})}),D=n(34151),F=n(65291),Q=n(77374),T=n(31708),U=n(14418),W=n(96272),$=n(23438),B=n(56880),V=e=>{let{isOpen:t,title:n,description:r,items:s,units:o,onClose:c}=e,[i,d]=y.useState(!0),m=(0,y.useCallback)(()=>{d(!1)},[]),x=(0,y.useCallback)(()=>{d(!0)},[]);return(0,l.jsxs)(D.u_,{isOpen:t,onClose:c,size:"full",isCentered:!0,children:[(0,l.jsx)(F.Z,{}),(0,l.jsxs)(Q.h,{children:[(0,l.jsx)(u.xu,{mb:1,children:(0,l.jsxs)(T.r,{gridColumnGap:2,children:[(0,l.jsx)(U.X,{mb:1,size:{base:"xs",sm:"md"},children:n}),r&&(0,l.jsx)(a.x,{gridColumn:1,as:"p",variant:"secondary",fontSize:"xs",children:r}),!i&&(0,l.jsx)(W.z,{leftIcon:(0,l.jsx)(Z.Z,{name:"repeat",w:4,h:4}),colorScheme:"blue",gridColumn:2,justifySelf:"end",alignSelf:"top",gridRow:"1/3",size:"sm",variant:"outline",onClick:x,children:"Reset zoom"})]})}),(0,l.jsx)($.o,{}),(0,l.jsx)(B.f,{h:"100%",children:(0,l.jsx)(I,{margin:{bottom:60},isEnlarged:!0,items:s,units:o,onZoom:m,isZoomResetInitial:i,title:n})})]})]})},P=y.memo((0,b.m)(e=>{let{items:t,title:n,description:b,isLoading:g,className:_,isError:X,units:z,emptyText:Y,noAnimation:R}=e,A=(0,y.useRef)(null),[E,N]=(0,y.useState)(!1),[G,L]=y.useState(!0),O=(0,r.ff)("white","black"),M=(0,r.ff)("gray.200","gray.600"),D=(0,y.useCallback)(()=>{L(!1)},[]),F=(0,y.useCallback)(()=>{L(!0)},[]),Q=(0,y.useCallback)(()=>{N(!0)},[]),T=(0,y.useCallback)(()=>{N(!1)},[]),U=(0,y.useCallback)(()=>{setTimeout(()=>{A.current&&k().toPng(A.current,{quality:100,bgcolor:O,width:5*A.current.offsetWidth,height:5*A.current.offsetHeight,filter:e=>"BUTTON"!==e.nodeName,style:{borderColor:"transparent",transform:"scale(".concat(5,")"),"transform-origin":"top left"}}).then(e=>{let t=document.createElement("a");t.download="".concat(n," (Blockscout chart).png"),t.href=e,t.click(),t.remove()})},100)},[O,n]),W=(0,y.useCallback)(()=>{t&&function(e,t,n){let l=new Blob([(0,S.unparse)([e,...t])],{type:"text/csv;charset=utf-8;"});(0,v.Z)(l,n)}(["Date","Value"],t.map(e=>[(0,p.Z)(e.date).format("YYYY-MM-DD"),String(e.value)]),"".concat(n," (Blockscout stats)"))},[t,n]),$=t&&t.length>2,B=X?(0,l.jsx)(s.k,{alignItems:"center",justifyContent:"center",flexGrow:1,py:4,children:(0,l.jsxs)(a.x,{variant:"secondary",fontSize:"sm",textAlign:"center",children:["The data didn".concat(C.Iy,"t load. Please, "),(0,l.jsx)(o.r,{href:window.document.location.href,children:"try to reload the page."})]})}):g?(0,l.jsx)(c.O,{flexGrow:1,w:"100%"}):$?(0,l.jsx)(u.xu,{flexGrow:1,maxW:"100%",children:(0,l.jsx)(I,{items:t,onZoom:D,isZoomResetInitial:G,title:n,units:z,noAnimation:R})}):(0,l.jsx)(i.M,{flexGrow:1,children:(0,l.jsx)(a.x,{variant:"secondary",fontSize:"sm",children:Y||"No data"})});return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(s.k,{height:"100%",ref:A,flexDir:"column",padding:{base:3,lg:4},borderRadius:"md",border:"1px",borderColor:M,className:_,children:[(0,l.jsxs)(s.k,{columnGap:6,mb:1,alignItems:"flex-start",children:[(0,l.jsxs)(s.k,{flexGrow:1,flexDir:"column",alignItems:"flex-start",children:[(0,l.jsx)(c.O,{isLoaded:!g,fontWeight:600,size:{base:"xs",lg:"sm"},children:n}),b&&(0,l.jsx)(c.O,{isLoaded:!g,color:"text_secondary",fontSize:"xs",mt:1,children:(0,l.jsx)("span",{children:b})})]}),(0,l.jsxs)(s.k,{ml:"auto",columnGap:2,children:[(0,l.jsx)(d.u,{label:"Reset zoom",children:(0,l.jsx)(m.h,{hidden:G,"aria-label":"Reset zoom",colorScheme:"blue",w:9,h:8,size:"sm",variant:"outline",onClick:F,icon:(0,l.jsx)(Z.Z,{name:"repeat",w:4,h:4})})}),$&&(0,l.jsxs)(w.Z,{children:[(0,l.jsx)(c.O,{isLoaded:!g,borderRadius:"base",children:(0,l.jsx)(x.j,{w:"36px",h:"32px",icon:(0,l.jsx)(Z.Z,{name:"dots",boxSize:4,transform:"rotate(-90deg)"}),colorScheme:"gray",variant:"ghost",as:m.h,children:(0,l.jsx)(h.TX,{children:"Open chart options menu"})})}),(0,l.jsxs)(f.q,{children:[(0,l.jsxs)(j.s,{display:"flex",alignItems:"center",onClick:Q,children:[(0,l.jsx)(Z.Z,{name:"scope",boxSize:5,mr:3}),"View fullscreen"]}),(0,l.jsxs)(j.s,{display:"flex",alignItems:"center",onClick:U,children:[(0,l.jsx)(Z.Z,{name:"files/image",boxSize:5,mr:3}),"Save as PNG"]}),(0,l.jsxs)(j.s,{display:"flex",alignItems:"center",onClick:W,children:[(0,l.jsx)(Z.Z,{name:"files/csv",boxSize:5,mr:3}),"Save as CSV"]})]})]})]})]}),B]}),$&&(0,l.jsx)(V,{isOpen:E,items:t,title:n,description:b,onClose:T,units:z})]})}))}}]);
//# sourceMappingURL=6619-e5397ad47c717dee.js.map