@groww-tech/react-charts
Version:
React charts library tailored as per Groww needs
2 lines (1 loc) • 7.51 kB
JavaScript
import{_ as e,a as t}from"./tslib.es6-fef9fe46.js";import l,{useState as n}from"react";import{i as o}from"./index-aa089771.js";import{m as i,a as r,l as a,b as u}from"./localPoint-1ddfe424.js";import{a as s}from"./D3ShapeFactories-c73bea6f.js";export default function(d){var v,c=n(null),f=c[0],p=c[1],g=n(null),h=g[0],m=g[1],y=d.paddingVert,E=d.paddingHorz,P=d.height,k=d.width,x=d.linePaths,S=d.onMouseLeave;if(o(x))return null;var T=function(e){return null==e?void 0:e[0]},b=function(e){return null==e?void 0:e[1]},M=Number.MAX_SAFE_INTEGER,D=Number.MIN_SAFE_INTEGER,L=Number.MAX_SAFE_INTEGER,W=Number.MIN_SAFE_INTEGER;x.forEach(function(e){if(e.isSeriesToScale){var t=i(e.series,b),l=r(e.series,b),n=i(e.series,T),o=r(e.series,T);void 0!==t&&(M=Math.min(M,t)),void 0!==l&&(D=Math.max(D,l)),void 0!==n&&(L=Math.min(L,n)),void 0!==o&&(W=Math.max(W,o))}});var N,w,R,A,F,I=[L,W],_=[0+E,k-E],O=[M,D],C=[P-y,y],U=function(e){return C[0]+(e-O[0])*(C[1]-C[0])/(O[1]-O[0])},j=function(e){return _[0]+(e-I[0])*(_[1]-_[0])/(I[1]-I[0])},B=function(e){return I[0]+(e-_[0])*(I[1]-I[0])/(_[1]-_[0])},G=function(e,t){return(0,u(T).left)(t,B(e),0)},X=function(e){var t,l,n,o,i,r,a=null!=h?h:{},u=a.startPoint,s=a.endPoint,d=null!==(t=null==e?void 0:e.draggableConfig)&&void 0!==t?t:{},v=d.fill,c=void 0===v?null==e?void 0:e.color:v,f=d.lineColor,p=d.negativeLineColor;if(void 0===u||void 0===s)return null==e?void 0:e.color;var g=null===(n=null===(l=null==e?void 0:e.series)||void 0===l?void 0:l[G(u,e.series)])||void 0===n?void 0:n[1],m=null===(i=null===(o=null==e?void 0:e.series)||void 0===o?void 0:o[G(s,e.series)])||void 0===i?void 0:i[1],y=null!=f?f:c,E=null!==(r=null!=p?p:f)&&void 0!==r?r:c;return u<s?g<m?y:E:g>m?y:E},V=function(){null==S||S(),p(null)},Y=function(l){l.preventDefault();var n=d.onMouseEnter,i=a(l)||{x:0,y:0},r=i.x,u=i.y,s=B(r),v=function(e){return O[0]+(e-C[0])*(O[1]-O[0])/(C[1]-C[0])}(u),c=[];null==x||x.map(function(l){var n,i,a=l.isDraggable,u=t([],l.series,!0),d=u.length,v=G(r,u),f=0!==v&&!o(null===(n=null==u?void 0:u[v])||void 0===n?void 0:n[0])&&(null===(i=null==u?void 0:u[v])||void 0===i?void 0:i[0])>=s;v===d&&(v=d-1);var p=u[v],g=u[v>0?v-1:v],y=(p[1]-g[1])/(p[0]-g[0])*(s-g[0])+g[1],E={point:p,tooltipLeft:(null==l?void 0:l.isSeriesToScale)?j(T(p)):T(p),tooltipTop:(null==l?void 0:l.isSeriesToScale)?U(b(p)):b(p),isPerfectIntersection:f,intersectionPointOnLine:{coords:{x:j(s),y:U(y)},invertedValues:{x:s,y:y}}};if(a&&h){var P=u[G(null==h?void 0:h.startPoint,u)];c.push(e(e({},E),{dragStartPoint:P,dragTooltipLeft:null==h?void 0:h.startPoint})),P||m(null),s<d-1&&void 0!==h.startPoint&&m(e(e({},h),{endPoint:r}))}else c.push(E)});var f={seriesData:c,otherData:{coords:{x:r,y:u},invertedValues:{x:s,y:v}}};null==n||n(f),p(f)},H=function(e,t,n,o,i){var r=null!=i?i:1.5;return l.createElement(l.Fragment,null,l.createElement("circle",{cx:e,cy:t,r:o*r,fill:n,stroke:"var(--dangerouslySetPrimaryBg)",strokeWidth:o,pointerEvents:"none"}),l.createElement("circle",{cx:e,cy:t,r:o*r,fill:"rgba(0, 0, 0, 0)",stroke:n,className:"lg43Opacity3",strokeWidth:o*r/2,pointerEvents:"none"}))};return l.createElement(l.Fragment,null,l.createElement("svg",{width:k,height:P,onTouchMove:Y,onMouseMove:Y,onTouchStart:Y,onTouchEnd:V,onMouseLeave:V,onMouseUp:function(){var e;null===(e=d.onMouseUp)||void 0===e||e.call(d),m(null)},onMouseDown:function(e){var t;if(null===(t=d.onMouseDown)||void 0===t||t.call(d),d.isDragAllowed){var l=(a(e)||{x:0}).x;m({startPoint:l})}}},null===(v=d.getDefs)||void 0===v?void 0:v.call(d),l.createElement("g",null,x.map(function(t){var n,i,r,a,u,d=function(e){return t.isSeriesToScale?j(T(e)):T(e)},v=function(e){return t.isSeriesToScale?U(b(e)):b(e)},c=(t||{}).areaProps,f=c&&(!o(null==c?void 0:c.toX)||!o(null==c?void 0:c.toY)),p=s({}),g=s({x:d,y:v}),m=c||{},y=m.toX,E=m.toY;o(y)?o(E)||(p.x(d),p.y0(U(null!=E?E:0)),p.y1(v)):(p.y(v),p.x0(j(null!=y?y:0)),p.x1(d));var x=t.isDraggable&&(null==h?void 0:h.endPoint),S=x?function(e){var t,l=null!=h?h:{},n=l.startPoint,o=l.endPoint;if(void 0===n||void 0===o)return[];n>o&&(n=(t=[o,n])[0],o=t[1]),o+=1;var i=G(n,e),r=G(o,e);return null==e?void 0:e.slice(i,r)}(null==t?void 0:t.series):[],M=X(t),D=s({}),L=null!==(n=null==t?void 0:t.labelData)&&void 0!==n?n:{},W=L.showLabel,N=L.labelText,w=L.labelRefs,R=L.rectSvgProps,A=L.textSvgProps,F=L.labelPosition,I=null!=w?w:{},_=I.underlyinglabelTextRef,O=I.underlyinglabelRectRef;return(null===(i=null==t?void 0:t.draggableConfig)||void 0===i?void 0:i.toY)?(D.y(d),D.x0(k),D.x1(v)):(D.x(d),D.y0(P),D.y1(v)),l.createElement(l.Fragment,null,f&&l.createElement("path",{d:p(t.series)||"",fill:null==c?void 0:c.fill,opacity:null==c?void 0:c.opacity,style:e({},c.style),key:t.key+"Area"}),l.createElement("path",{d:g(t.series)||"",opacity:null==c?void 0:c.opacity,stroke:t.color,style:e({},t.style),key:t.key,strokeOpacity:t.strokeOpacity,shapeRendering:"geometricPrecision",strokeWidth:t.strokeWidth}),W&&l.createElement("g",null,l.createElement("rect",e({ref:O},R)),l.createElement("text",e({x:j(null!==(r=null==F?void 0:F.x)&&void 0!==r?r:0),y:U(null!==(a=null==F?void 0:F.y)&&void 0!==a?a:0),ref:_},A),N)),x&&l.createElement(l.Fragment,null,l.createElement("path",{d:D(S)||"",fill:null===(u=null==t?void 0:t.draggableConfig)||void 0===u?void 0:u.fill,key:t.key+"DragArea"}),l.createElement("path",{d:g(S)||"",stroke:M,style:e({},t.style),key:t.key+"DragLine",strokeOpacity:t.strokeOpacity,shapeRendering:"geometricPrecision",strokeWidth:t.strokeWidth})))}),x.map(function(e,t){return l.createElement(l.Fragment,null,function(e){var t=e.series[e.series.length-1],n=U(b(t)),o=j(T(t));return e.showLastPointBlinking?l.createElement("g",null,l.createElement("circle",{cx:o,cy:n,r:1.5*e.strokeWidth,fill:e.color,stroke:"var(--dangerouslySetPrimaryBg)",strokeWidth:e.strokeWidth/2,pointerEvents:"none",style:e.style,className:"lg430LastPointBlinking"})):null}(e),function(e){var t;if(e.hasHighlightedPoints){var n=null!==(t=e.highlightPointStrokeMultiplier)&&void 0!==t?t:1.5;return l.createElement("g",null,e.series.map(function(t){var o;if(null===(o=null==t?void 0:t[3])||void 0===o?void 0:o.highlightPoint)return l.createElement("circle",{cx:j(T(t)),cy:U(b(t)),r:e.strokeWidth*n,fill:e.color,stroke:e.color,strokeWidth:e.strokeWidth*n/2,pointerEvents:"none"})}))}}(e),function(e,t){var l;if(!e.allowToolTip||o(f))return null;var n=e.hoverPointStrokeMultiplier,i=e.strokeWidth,r=e.hoverExactPoint,a=null===(l=null==f?void 0:f.seriesData)||void 0===l?void 0:l[t],u=0,s=0;if(r){if(!(null==a?void 0:a.isPerfectIntersection))return;u=a.intersectionPointOnLine.coords.x,s=a.intersectionPointOnLine.coords.y}else u=null==a?void 0:a.tooltipLeft,s=null==a?void 0:a.tooltipTop;var d=(null==h?void 0:h.endPoint)?X(e):null==e?void 0:e.color;return _[0]<=u&&u<=_[1]&&C[1]<=s&&s<=C[0]?H(u,s,d,i,n):void 0}(e,t),function(e){var t,l;if(!e.allowToolTip||!(null==h?void 0:h.endPoint))return null;var n=e.hoverPointStrokeMultiplier,o=e.strokeWidth,i=null==h?void 0:h.startPoint,r=U(null===(l=null===(t=e.series)||void 0===t?void 0:t[G(h.startPoint,null==e?void 0:e.series)])||void 0===l?void 0:l[1]),a=X(e);return _[0]<=i&&i<=_[1]&&C[1]<=r&&r<=C[0]?H(i,r,a,o,n):void 0}(e))}))),(N=d.getTooltipUI,w=d.toolTipLeftUpdated,R=d.toolTipTopUpdated,A=d.isDragAllowed,F={top:0,left:0,boxShadow:"none",padding:0,backgroundColor:"transparent",position:"absolute",borderRadius:"3px",transform:"translate(".concat(w,"px, ").concat(R,"px)")},f&&N?A&&(null==h?void 0:h.endPoint)?N(f):l.createElement("div",{style:F},N(f)):null))}