UNPKG

@groww-tech/react-charts

Version:
2 lines (1 loc) 3 kB
import e,{useState as t}from"react";import{i as n}from"./index-aa089771.js";import{m as o,a as r,l as a,b as l}from"./localPoint-1ddfe424.js";var i=null,u=function(u){var c=t(),s=c[0],m=c[1],d=u.currentGraphData,f=u.toolTipFormatter,h=u.paddingVert,E=u.paddingHorz,v=u.height,p=u.width,x=u.allowTooltip,M=u.showVolumeBars,N=u.candleWidth,g=u.candleColor,T=u.volumeBarMaxHeight,y=u.toolTipHeight,k=u.minX,_=u.maxX,b=u.minY,A=u.maxY;if(n(d))return null;var F=null!=d?d:[],I=function(e){return e[0]},S=function(e){return e[5]},G=null!=b?b:Number.MAX_SAFE_INTEGER,L=null!=A?A:Number.MIN_SAFE_INTEGER,R=null!=k?k:Number.MAX_SAFE_INTEGER,w=null!=_?_:Number.MIN_SAFE_INTEGER,W=Number.MIN_SAFE_INTEGER,C=Number.MAX_SAFE_INTEGER,X=o(d,function(e){return e[3]}),H=r(d,function(e){return e[2]}),B=o(d,I),V=r(d,I),j=o(d,S),D=r(d,S);void 0!==X&&(G=Math.min(G,X)),void 0!==H&&(L=Math.max(L,H)),void 0!==B&&(R=Math.min(R,B)),void 0!==V&&(w=Math.max(w,V)),void 0!==j&&(C=Math.min(C,j)),void 0!==D&&(W=Math.max(W,D));var P=[R,w],Y=[0+E,p-E],z=[G,L],O=[v-h,h],q=[C,W],J=[v,v-h-T],K=function(e){return O[0]+(e-z[0])*(O[1]-O[0])/(z[1]-z[0]||z[1])},Q=function(e){return Y[0]+(e-P[0])*(Y[1]-Y[0])/(P[1]-P[0]||P[1])},U=function(){var e=u.onMouseLeave;m(void 0),null==e||e()},Z=function(e){e.preventDefault();var t=u.onMouseEnter,n=function(e){return P[0]+(e-Y[0])*(P[1]-P[0])/(Y[1]-Y[0])}((a(e)||{x:0}).x),o=(0,l(I).left)(F,n,0);o===F.length&&(o=F.length-1);var r=F[o];m({candle:r,tooltipLeft:Q(I(r)),tooltipTop:0}),null==t||t(r)};return e.createElement(e.Fragment,null,e.createElement("svg",{width:p,height:v,onMouseMove:Z,onMouseLeave:U,onTouchMove:Z,onTouchStart:Z,onTouchEnd:U,onTouchCancel:U},e.createElement("g",{key:"linesxssedc"},s&&x&&e.createElement("line",{x1:s.tooltipLeft,y1:0,x2:s.tooltipLeft,y2:v,stroke:"var(--gray150)",strokeWidth:1,pointerEvents:"none"}),F.map(function(t,n){var o,r=t[0],a=t[1],l=t[2],i=t[3],u=t[4],c=t[5],s=Q(r),m=a>u?g[1]:g[0],d=(o=c,J[0]+(o-q[0])*(J[1]-J[0])/(q[1]-q[0]||q[1])),f=K(a),h=K(l),E=K(i),p=a===u?f+1:K(u);return e.createElement(e.Fragment,null,e.createElement("line",{className:"cc41Candle",key:n,x1:s,x2:s,y1:h,y2:E,stroke:m,strokeWidth:N[0],pointerEvents:"none"}),e.createElement("line",{className:"cc41Candle",key:"fad"+n,x1:s,x2:s,y1:f,y2:p,stroke:m,strokeWidth:N[1],pointerEvents:"none"}),M&&e.createElement("line",{className:"cc41Opacity3",key:"asd"+n,x1:s,x2:s,y1:v,y2:d,stroke:m,strokeWidth:N[2]}))}))),s&&x&&function(){var t;if(!s)return null;var n=null!==(t=null==i?void 0:i.offsetWidth)&&void 0!==t?t:0,o=p-n-15,r=Math.min(o,Math.max(0,(null==s?void 0:s.tooltipLeft)-n/2)),a={top:0,left:0,boxShadow:"none",padding:0,backgroundColor:"transparent",position:"absolute",borderRadius:"3px",transform:"translate(".concat(r,"px, ").concat(-1*y,"px)")};return e.createElement("div",{ref:function(e){i=e},style:a},f(s))}())};u.defaultProps={toolTipHeight:10,onMouseEnter:function(){},onMouseLeave:function(){},onTouchEnd:function(){},showVolumeBars:!0};export default u;