@gearbox-protocol/ui-kit 4.0.0-next.55 → 4.0.0-next.56
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./constants.cjs");function r({chart:i,side:a}){return e.jsxs("div",{className:"flex w-full flex-wrap gap-4","data-testid":t.ChartWithSideCardTest.root,children:[e.jsx("div",{className:"min-w-[min(100%,40rem)] grow-[999] basis-0","data-testid":t.ChartWithSideCardTest.chart,children:i}),e.jsx("div",{className:"min-w-[min(100%,300px)] grow
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./constants.cjs");function r({chart:i,side:a}){return e.jsxs("div",{className:"flex w-full flex-wrap gap-4","data-testid":t.ChartWithSideCardTest.root,children:[e.jsx("div",{className:"min-w-[min(100%,40rem)] grow-[999] basis-0","data-testid":t.ChartWithSideCardTest.chart,children:i}),e.jsx("div",{className:"min-w-[min(100%,300px)] grow basis-[22.5rem]","data-testid":t.ChartWithSideCardTest.side,children:a})]})}exports.ChartWithSideCardTest=t.ChartWithSideCardTest;exports.ChartWithSideCard=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),Z=require("lightweight-charts"),p=require("react"),ct=require("../../hooks/use-media-query.cjs"),H=require("../../utils/cn.cjs"),X=require("../../utils/colors.cjs"),D=require("./default-config.cjs"),ne=require("./formatters.cjs"),ut=require("./graph-current-value.cjs"),ft=require("./graph-tooltip.cjs"),ht=require("./plugins/vertical-line.cjs"),He=require("./y-axis-scale.cjs");function gt(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const u=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,u.get?u:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const Te=gt(p);function re(e){return e.id??e.label}function Ze(e,n,a){if(!a)return e.values().next().value;const u=e.get(a);if(u)return u;const h=n.find(f=>f.id===a||f.label===a);return h?e.get(re(h)):void 0}class dt{_yTop;_yBottom;_color;constructor(n,a,u){this._yTop=n,this._yBottom=a,this._color=u}draw(n){n.useBitmapCoordinateSpace(a=>{const u=a.context,h=a.verticalPixelRatio,f=this._yTop===null?0:this._yTop*h,x=this._yBottom===null?a.bitmapSize.height:this._yBottom*h,P=Math.min(f,x),k=Math.max(f,x);u.fillStyle=this._color,u.fillRect(0,P,a.bitmapSize.width,k-P)})}}class pt{_source;_yTop=null;_yBottom=null;constructor(n){this._source=n}update(){const n=this._source.series;this._yTop=this._source.priceTop===void 0?null:n.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:n.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new dt(this._yTop,this._yBottom,this._source.color)}}class mt{series;priceTop;priceBottom;color;_paneViews;constructor(n,a,u,h){this.series=n,this.priceTop=a,this.priceBottom=u,this.color=h,this._paneViews=[new pt(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function bt(e,n){switch(e){case Z.LineStyle.Dotted:return[n,n];case Z.LineStyle.Dashed:return[2*n,2*n];case Z.LineStyle.LargeDashed:return[6*n,6*n];case Z.LineStyle.SparseDotted:return[n,4*n];default:return[]}}class St{_y;_color;_lineWidth;_lineStyle;constructor(n,a,u,h){this._y=n,this._color=a,this._lineWidth=u,this._lineStyle=h}draw(n){n.useBitmapCoordinateSpace(a=>{if(this._y===null)return;const u=a.context,h=a.verticalPixelRatio,f=Math.max(1,Math.round(this._lineWidth*h)),x=Math.round(this._y*h);u.save(),u.strokeStyle=this._color,u.lineWidth=f,u.setLineDash(bt(this._lineStyle,f)),u.beginPath(),u.moveTo(0,x),u.lineTo(a.bitmapSize.width,x),u.stroke(),u.restore()})}}class Ct{_source;_y=null;constructor(n){this._source=n}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new St(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class xt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(n,a,u,h,f){this.series=n,this.price=a,this.color=u,this.lineWidth=h,this.lineStyle=f,this._paneViews=[new Ct(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function Qe(e,n,a){const u=e.labelText??"",h=e.value,f=h===void 0?"":typeof h=="number"?n==="$"?`$${ne.formatExactValue(h,void 0,a)}`:n==="%"?`${ne.formatExactValue(h,void 0,a)}%`:ne.formatExactValue(h,n!=="none"&&n!=="%"&&n!=="$"&&!ne.isRatioUnit(n)?n:void 0,a):String(h);return{labelText:u,valueStr:f}}const Le=4;function Ye(e,n,a){const u={left:e,transform:"translateX(-50%)"};if(n<=0||!a||a<=0)return u;const h=a/2,f=Le+h,x=n-Le-h;return x<f?{left:n/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,f),x),transform:"translateX(-50%)"}}function Je(e,n){for(let a=e.length-1;a>=0;a--)if(Number(e[a].time)<=n)return e[a].value;return 0}const Se=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],vt=137.5;function Ne(e){if(e<Se.length)return Se[e];const a=(e-Se.length)*vt%360,u=X.hslToHex(a,70,50),{topColor:h,bottomColor:f}=X.generateColorsFromBase(u);return{line:u,top:h,bottom:f}}function yt({series:e,className:n,showLegend:a=!1,onUnselectSeries:u,xMeasureUnit:h="time",yMeasureUnit:f="token",optionsOverrides:x,verticalLineOptions:P,priceLineOptions:k,zoneOptions:F,currentValueDecimals:ae,useSharedPriceScale:Q=!1,dualYAxis:A=!1,defaultVisiblePriceScaleId:Ve="right",leftPriceScaleTitle:Ee,rightPriceScaleTitle:_t,showCurrentValue:et=!0,graphTitle:Ce,yScaleMin:Ie,yScaleMinMultiple:De,visibleTimeFrom:ee,disableZoom:Me=!1,hideDefaultTooltip:xe=!1}){const j=p.useRef(null),E=p.useRef(new Map),ve=p.useRef(!1),ke=p.useRef(!0),Ae=p.useRef([]),le=p.useRef(0),B=p.useRef(null),ye=p.useRef(null),je=p.useRef(null),T=ct.useIsMobile(),ce=Te.useMemo(()=>e.flatMap(t=>t.data),[e]),tt=Te.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[Be,_e]=p.useState(()=>{if(!tt)return;const t=new Map;for(const l of e)l.data.length>0&&t.set(l.label,l.data[l.data.length-1]);return t}),[Fe,J]=p.useState(null),[ze,Ge]=p.useState([]),[ot,Xe]=p.useState(0),qe=p.useRef(new Map),[rt,nt]=p.useState({}),[te,it]=p.useState(0);p.useEffect(()=>{const t=()=>{try{if(B.current&&Xe(B.current.clientWidth),j.current&&B.current){const s=B.current.clientWidth,c=B.current.clientHeight;j.current.resize(s,c);try{le.current=j.current.paneSize().height}catch{}}}catch{}},l=B.current,i=l?new ResizeObserver(t):null;return je.current=i,l&&i?.observe(l),()=>{l&&i?.unobserve(l),i?.disconnect(),je.current=null}},[]),p.useEffect(()=>{if(!ye.current||ve.current)return;const t=D.getDefaultOptions(),l=X.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),i=Z.createChart(ye.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:l},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:l},...T&&{crosshair:{...t.crosshair,mode:Z.CrosshairMode.Magnet}}});j.current=i,ve.current=!0;try{le.current=i.paneSize().height}catch{le.current=0}return it(s=>s+1),()=>{i.remove(),j.current=null,ve.current=!1,E.current.clear()}},[T]),p.useEffect(()=>{const t=j.current;t&&t.applyOptions(Me?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[te,Me]),p.useEffect(()=>{const t=j.current;!t||!x||t.applyOptions(x)},[te,x]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const i=e.filter(r=>r.data.length>0).length<=1?Ie:De,s=h==="time"?ne.getXFormatters(h,ce):ne.getXFormatters(h),c=new Map;{let r=0;for(const o of e)o.data.length!==0&&(c.set(o.label,o.priceScaleId??(r===0?"left":"right")),r++)}const g=(r,o,d)=>{const{formatter:z,tickmarksFormatter:N,updateVisibleRange:V}=ne.createAdaptiveYAxisFormatter(r,o,{yScaleMin:i});return{formatter:z,tickmarksFormatter:N,updateVisibleRange:V,labels:d}},m=[];if(A)for(const r of["left","right"]){const o=new Set,d=[];let z=f;for(const N of e)if(N.data.length!==0&&c.get(N.label)===r){o.size===0&&N.yMeasureUnit&&(z=N.yMeasureUnit),o.add(N.label);for(const V of N.data)d.push(V.value)}o.size>0&&m.push(g(d,z,o))}else{const r=ce.map(d=>d.value),o=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));m.push(g(r,f,o))}Ae.current=m;const _=new Map;for(const r of m)for(const o of r.labels)_.set(o,r);const w=D.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:r=>s.timeFormatter(parseFloat(r),void 0)},timeScale:{...w.timeScale||{},...x?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const v=!A&&e.length>1&&!Q,q=A?T:e.length>1&&!Q||T,I=X.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...A&&{defaultVisiblePriceScaleId:Ve},leftPriceScale:{...w.leftPriceScale||{},...x?.leftPriceScale,visible:A&&!T,textColor:I,...A&&Ee&&{}},rightPriceScale:{...w.rightPriceScale||{},...x?.rightPriceScale,visible:A?!T:!q,textColor:I}});const oe=new Set(E.current.keys()),W=new Set(e.map(re));for(const r of oe)if(!W.has(r)){const o=E.current.get(r);o&&(t.removeSeries(o),E.current.delete(r))}const b=D.getDefaultSeries(),M=[];let L=0;const K=e.find(r=>r.data.length>0),y=new Map;if(k&&k.length>0)for(const r of k){if(!Number.isFinite(r.price))continue;const o=r.seriesLabel??K?.label;if(!o)continue;const d=y.get(o)??[];d.push(r.price),y.set(o,d)}if(F&&F.length>0)for(const r of F){const o=r.seriesLabel??K?.label;if(!o)continue;const d=y.get(o)??[];Number.isFinite(r.priceTop)&&d.push(r.priceTop),Number.isFinite(r.priceBottom)&&d.push(r.priceBottom),y.set(o,d)}for(let r=0;r<e.length;r++){const o=e[r],d=re(o),z=Ne(r),N=o.lineColor??o.color??z.line;let V,U;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)V=o.topColor,U=o.bottomColor;else if(o.topColor){const S=X.generateColorsFromBase(N);V=o.topColor,U=S.bottomColor}else if(o.bottomColor)V=X.generateColorsFromBase(N).topColor,U=o.bottomColor;else{const S=X.generateColorsFromBase(N);V=S.topColor,U=S.bottomColor}else V=o.topColor||z.top,U=o.bottomColor||z.bottom;if(o.data.length===0){const S=E.current.get(d);S&&(t.removeSeries(S),E.current.delete(d));continue}const pe=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,ue=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,fe=pe<0,Y=o.data.some(S=>S.value===0),me=!fe&&Y,he=He.pickMinMove(ue-pe),ge=A?o.priceScaleId??(L===0?"left":"right"):Q||!v||L===0?"right":`scale-${L}`;v&&M.push({priceScaleId:ge||"right",seriesIndex:L});const we=(Q||!v)&&i!==void 0&&typeof i=="number",st=y.get(o.label)??[],at=S=>{const R=S();if(R?.priceRange){we&&(R.priceRange.minValue=i);for(const O of st)O<R.priceRange.minValue&&(R.priceRange.minValue=O),O>R.priceRange.maxValue&&(R.priceRange.maxValue=O);const se=we?i:me&&R.priceRange.minValue>=0?0:void 0,be=le.current>0?le.current:B.current?.clientHeight??0;if(be>0){const O=He.niceAxisRange({min:R.priceRange.minValue,max:R.priceRange.maxValue,floor:se,scaleHeightPx:be,fontSizePx:D.AXIS_FONT_SIZE,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,minMove:he,edgePaddingPx:D.AXIS_EDGE_LABEL_PADDING_PX,edgePaddingTopPx:D.AXIS_TOP_LABEL_PADDING_PX});R.priceRange.minValue=O.min,R.priceRange.maxValue=O.max}R.margins={above:D.AXIS_TOP_LABEL_PADDING_PX,below:D.AXIS_EDGE_LABEL_PADDING_PX}}return R},Ke=_.get(o.label)??m[0],$e=Ke.formatter,lt=Ke.tickmarksFormatter,Re={lineColor:N,topColor:V,bottomColor:U,priceScaleId:ge,...o.seriesType==="line"&&{lineStyle:o.lineStyle??Z.LineStyle.Solid},priceFormat:{type:"custom",minMove:he,formatter:we&&typeof i=="number"?S=>$e(S<i?i:S):$e,tickmarksFormatter:lt},autoscaleInfoProvider:at},Oe=o.seriesType==="line";let G=E.current.get(d);const ie=o.data.map(S=>({...S,time:S.time}));if(ee!==void 0&&ie.length>0&&Number(ie[0].time)>ee){const S=Number(ie[0].time),R=S-ee,se=86400,be=R>180*se?7*se:R>30*se?se:6*3600,O=[];for(let Pe=ee;Pe<S;Pe+=be)O.push({time:Pe});ie.unshift(...O)}G&&G.seriesType()!==(Oe?"Line":"Area")&&(t.removeSeries(G),E.current.delete(d),G=void 0),G?(G.applyOptions(Re),G.setData(ie)):(Oe?G=t.addSeries(Z.LineSeries,{...b,...Re}):G=t.addSeries(Z.AreaSeries,{...b,...Re}),G.setData(ie),E.current.set(d,G)),L++}if(A)try{const r=t.priceScale("left"),o=t.priceScale("right"),d={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...x?.rightPriceScale};r?.applyOptions(d),o?.applyOptions(d)}catch{}else if(v&&M.length>0)for(const r of M)try{const o=t.priceScale(r.priceScaleId);o&&o.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I})}catch(o){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,o)}else if(!v)try{const r=t.priceScale("right");r&&r.applyOptions({visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...x?.rightPriceScale})}catch{}if(i!==void 0&&!T&&(Q||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),ce.length>0){const r=ce.map(o=>Number(o.time)).filter(o=>Number.isFinite(o));if(r.length>0){const o=Math.min(...r),d=ee!==void 0?Math.min(ee,o):o,z=Math.max(...r);if(Number(d)<=Number(z)){const N=()=>{const V=t.timeScale();if(h!=="time"){V.applyOptions({fixLeftEdge:!0,fixRightEdge:!0});return}const U=A&&!T,pe=A?!T:!q,ue=!U,fe=!pe;if(V.applyOptions({fixLeftEdge:!ue,fixRightEdge:!fe}),!ue&&!fe)return;const Y=V.getVisibleLogicalRange(),me=V.width();if(!Y||!(me>0))return;const he=Y.to-Y.from;if(!(he>0))return;const ge=D.AXIS_TIME_EDGE_PADDING_PX*he/me;V.setVisibleLogicalRange({from:ue?Y.from-ge:Y.from,to:fe?Y.to+ge:Y.to})};try{t.timeScale().setVisibleRange({from:d,to:z}),N()}catch{try{t.timeScale().fitContent(),N()}catch{}}}}}ke.current&&(ke.current=!1),x&&t.applyOptions(x);const $=new Map;for(const r of e)r.data.length>0&&$.set(r.label,r.data[r.data.length-1]);_e($.size>0?$:void 0)},[te,e,ce,h,f,T,Q,A,Ve,Ee,Ie,De,ee,k,F,x]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const l=e.length===1;let i;for(const c of e)if(c.data.length>0){i=c.data[c.data.length-1].time;break}if(!i)return;const s=c=>{const{time:g=i,seriesData:m,point:_}=c||{},w=e[0],v=w?E.current.get(re(w)):void 0;if(!_||!g){const W=new Map;for(const b of e)b.data.length>0&&W.set(b.label,b.data[b.data.length-1]);if(_e(W.size>0?W:void 0),l||Q||xe)J(null);else if(v&&i){const b=e[0];if(b&&b.data.length>0){const L=t.timeScale().timeToCoordinate(i),K=b.data[b.data.length-1].value,y=v.priceToCoordinate(K);L!==null&&y!==null&&J({x:L,y})}}return}const q=new Map;let I,oe=v;for(let W=0;W<e.length;W++){const b=e[W],M=E.current.get(re(b));if(!M)continue;const L=m?.get(M),K=L&&"value"in L?L.value:void 0;let y;if(K!==void 0)y=K;else if(l){const $=Number(g),r=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;$<r?y=Number.NaN:y=b.data[b.data.length-1]?.value??0}else{const $=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;if(Number(g)<$)continue;y=Je(b.data,Number(g))}Number.isNaN(y)||(I===void 0&&(I=y,oe=M),q.set(b.label,{value:y,time:g}))}if(_e(q),I!==void 0&&oe){const b=t.timeScale().timeToCoordinate(g),M=oe.priceToCoordinate(I);if(b!==null&&M!==null){const L=B.current;if(L){const K=L.querySelector(".LightweightChart");if(K){const y=K.getBoundingClientRect(),$=L.getBoundingClientRect(),r=b+(y.left-$.left),o=M+(y.top-$.top);J({x:r,y:o})}else J({x:b,y:M})}else J({x:b,y:M})}else J(null)}else J(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!l&&!Q&&!xe&&requestAnimationFrame(()=>{const c=e[0],g=c?E.current.get(re(c)):void 0;if(g&&i&&c.data.length>0){const _=t.timeScale().timeToCoordinate(i),w=c.data[c.data.length-1].value,v=g.priceToCoordinate(w);_!==null&&v!==null&&J({x:_,y:v})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,Q,T,xe]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const l=t.timeScale(),i=()=>{const s=Ae.current;if(s.length===0)return;const c=l.getVisibleRange();if(!c)return;const g=Number(c.from),m=Number(c.to);for(const _ of s){const w=[];for(const v of e)if(_.labels.has(v.label))for(const q of v.data){const I=Number(q.time);I>=g&&I<=m&&w.push(q.value)}w.length>0&&_.updateVisibleRange(w)}};return l.subscribeVisibleLogicalRangeChange(i),()=>{l.unsubscribeVisibleLogicalRangeChange(i)}},[e]),p.useEffect(()=>{const t=j.current,l=Array.from(E.current.values()),i=[];if(t&&l.length>0&&P){const s=D.getDefaultVerticalLine(),c=l[0];for(const g of P){const m={...s,...g.options||{}};m.color&&(m.color=X.resolveCSSColor(m.color,m.color));const _=new ht.VertLine(t,c,g.xCoordinate,m);c.attachPrimitive(_),i.push(_)}}return()=>{if(l.length>0){const s=l[0];for(const c of i)try{s.detachPrimitive(c)}catch{}}}},[P,e,te]),p.useEffect(()=>{const t=[],l=[];if(k&&k.length>0){const i=X.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of k){if(!Number.isFinite(s.price))continue;const c=Ze(E.current,e,s.seriesLabel);if(!c)continue;const g=s.color?X.resolveCSSColor(s.color,s.color):i,m=s.lineWidth??1,_=s.lineStyle??Z.LineStyle.Dashed,w=c.createPriceLine({price:s.price,color:g,lineWidth:m,lineStyle:_,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:c,line:w});const v=new xt(c,s.price,g,m,_);c.attachPrimitive(v),l.push({series:c,primitive:v})}}return()=>{for(const{series:i,primitive:s}of l)try{i.detachPrimitive(s)}catch{}for(const{series:i,line:s}of t)try{i.removePriceLine(s)}catch{}}},[k,e,te]),p.useEffect(()=>{const t=[];if(F&&F.length>0){const l="rgba(239, 68, 68, 0.12)";for(const i of F){const s=Ze(E.current,e,i.seriesLabel);if(!s)continue;const c=i.color?X.resolveCSSColor(i.color,l):l,g=new mt(s,i.priceTop,i.priceBottom,c);s.attachPrimitive(g),t.push({series:s,zone:g})}}return()=>{for(const{series:l,zone:i}of t)try{l.detachPrimitive(i)}catch{}}},[F,e,te]),p.useEffect(()=>{const t=j.current;if(!t||!P?.length){Ge([]);return}const l=()=>{const c=t.timeScale(),g=P.map(m=>c.timeToCoordinate(m.xCoordinate)??null);Ge(g),B.current&&Xe(B.current.clientWidth)};l();const i=t.timeScale(),s=()=>{l()};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[P,e,te]),p.useLayoutEffect(()=>{nt(t=>{const l={};let i=!1;for(const[s,c]of qe.current){if(!c)continue;const g=c.offsetWidth;l[s]=g,t[s]!==g&&(i=!0)}return Object.keys(t).length!==Object.keys(l).length&&(i=!0),i?l:t})});const de=e.length===1,We=Te.useMemo(()=>{if(de&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[de,e]);return C.jsxs("div",{ref:B,className:H.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[Ce!=null&&Ce!==!1&&de?C.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:C.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Ce})}):et&&de&&We&&C.jsx(ut.GraphCurrentValue,{point:We,xMeasureUnit:h,yMeasureUnit:f,decimals:ae}),Be&&Fe&&C.jsx(ft.GraphTooltip,{points:Be,xMeasureUnit:h,yMeasureUnit:f,series:e,position:Fe,containerRef:B,decimals:ae}),a&&C.jsx(Ue,{series:e,onUnselect:u}),P&&P.length>0&&ze.length===P.length&&C.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:P.map((t,l)=>{const i=ze[l],s=t.options??{};if(i===null)return null;const{labelText:c,valueStr:g}=Qe(s,f,ae),m=s.tooltipText??"";if(!(c||g||m))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",v=s.labelTextColor??"hsl(var(--foreground))",q=`${String(t.xCoordinate)}-${c}-${m}`,I=Ye(i,ot,rt[l]);return C.jsxs("div",{ref:oe=>{qe.current.set(l,oe)},className:H.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",m&&"pointer-events-auto cursor-default"),style:{...I,backgroundColor:w,color:v},children:[c&&C.jsx("span",{className:"block",children:c}),g&&C.jsx("span",{className:H.cn("block",c&&"mt-0.5"),children:g}),m&&C.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:m})]},q)})}),C.jsx("div",{ref:ye,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ue({series:e,markers:n,onUnselect:a,inline:u=!1}){const h=e.every(f=>f.data.length===0);return C.jsxs("div",{className:H.cn("flex flex-wrap",u?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:[e.map((f,x)=>{const P=Ne(x),k=(f.lineColor??f.color)||P.line,F=!h&&f.data.length===0;return C.jsxs("div",{className:H.cn("flex items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",F&&"opacity-50"),children:[C.jsx("div",{className:H.cn(u?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:k}}),C.jsxs("span",{className:H.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:[f.label,F&&" (no data)"]}),a&&C.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),a(f.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${f.label}`,children:C.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[C.jsx("title",{children:"Close"}),C.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),C.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f.id??f.label)}),n?.map(f=>C.jsxs("div",{className:H.cn("flex items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border"),children:[C.jsx("div",{className:H.cn("w-0.5","h-3"),style:{backgroundColor:f.color}}),C.jsx("span",{className:H.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:f.label})]},f.id))]})}exports.DEFAULT_SERIES_COLORS=Se;exports.Graph=yt;exports.GraphLegend=Ue;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=Le;exports.getSeriesColorPalette=Ne;exports.getStepForwardValue=Je;exports.getVerticalLineLabelStyle=Ye;exports.getVerticalLineTooltipContent=Qe;exports.seriesIdentity=re;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),H=require("lightweight-charts"),p=require("react"),ct=require("../../hooks/use-media-query.cjs"),Y=require("../../utils/cn.cjs"),X=require("../../utils/colors.cjs"),D=require("./default-config.cjs"),ne=require("./formatters.cjs"),ut=require("./graph-current-value.cjs"),ft=require("./graph-tooltip.cjs"),ht=require("./plugins/vertical-line.cjs"),He=require("./y-axis-scale.cjs");function gt(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const u=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,u.get?u:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const Te=gt(p);function re(e){return e.id??e.label}function Ze(e,n,a){if(!a)return e.values().next().value;const u=e.get(a);if(u)return u;const h=n.find(f=>f.id===a||f.label===a);return h?e.get(re(h)):void 0}class dt{_yTop;_yBottom;_color;constructor(n,a,u){this._yTop=n,this._yBottom=a,this._color=u}draw(n){n.useBitmapCoordinateSpace(a=>{const u=a.context,h=a.verticalPixelRatio,f=this._yTop===null?0:this._yTop*h,x=this._yBottom===null?a.bitmapSize.height:this._yBottom*h,P=Math.min(f,x),k=Math.max(f,x);u.fillStyle=this._color,u.fillRect(0,P,a.bitmapSize.width,k-P)})}}class pt{_source;_yTop=null;_yBottom=null;constructor(n){this._source=n}update(){const n=this._source.series;this._yTop=this._source.priceTop===void 0?null:n.priceToCoordinate(this._source.priceTop),this._yBottom=this._source.priceBottom===void 0?null:n.priceToCoordinate(this._source.priceBottom)}zOrder(){return"bottom"}renderer(){return new dt(this._yTop,this._yBottom,this._source.color)}}class mt{series;priceTop;priceBottom;color;_paneViews;constructor(n,a,u,h){this.series=n,this.priceTop=a,this.priceBottom=u,this.color=h,this._paneViews=[new pt(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function bt(e,n){switch(e){case H.LineStyle.Dotted:return[n,n];case H.LineStyle.Dashed:return[2*n,2*n];case H.LineStyle.LargeDashed:return[6*n,6*n];case H.LineStyle.SparseDotted:return[n,4*n];default:return[]}}class St{_y;_color;_lineWidth;_lineStyle;constructor(n,a,u,h){this._y=n,this._color=a,this._lineWidth=u,this._lineStyle=h}draw(n){n.useBitmapCoordinateSpace(a=>{if(this._y===null)return;const u=a.context,h=a.verticalPixelRatio,f=Math.max(1,Math.round(this._lineWidth*h)),x=Math.round(this._y*h);u.save(),u.strokeStyle=this._color,u.lineWidth=f,u.setLineDash(bt(this._lineStyle,f)),u.beginPath(),u.moveTo(0,x),u.lineTo(a.bitmapSize.width,x),u.stroke(),u.restore()})}}class Ct{_source;_y=null;constructor(n){this._source=n}update(){this._y=this._source.series.priceToCoordinate(this._source.price)}zOrder(){return"top"}renderer(){return new St(this._y,this._source.color,this._source.lineWidth,this._source.lineStyle)}}class xt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(n,a,u,h,f){this.series=n,this.price=a,this.color=u,this.lineWidth=h,this.lineStyle=f,this._paneViews=[new Ct(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function Qe(e,n,a){const u=e.labelText??"",h=e.value,f=h===void 0?"":typeof h=="number"?n==="$"?`$${ne.formatExactValue(h,void 0,a)}`:n==="%"?`${ne.formatExactValue(h,void 0,a)}%`:ne.formatExactValue(h,n!=="none"&&n!=="%"&&n!=="$"&&!ne.isRatioUnit(n)?n:void 0,a):String(h);return{labelText:u,valueStr:f}}const Le=4;function Ye(e,n,a){const u={left:e,transform:"translateX(-50%)"};if(n<=0||!a||a<=0)return u;const h=a/2,f=Le+h,x=n-Le-h;return x<f?{left:n/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,f),x),transform:"translateX(-50%)"}}function Je(e,n){for(let a=e.length-1;a>=0;a--)if(Number(e[a].time)<=n)return e[a].value;return 0}const Se=[{line:"#02c39a",top:"rgba(2, 195, 154, 0.56)",bottom:"rgba(2, 195, 154, 0.04)"},{line:"#3b82f6",top:"rgba(59, 130, 246, 0.56)",bottom:"rgba(59, 130, 246, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 0.04)"},{line:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#8b5cf6",top:"rgba(139, 92, 246, 0.56)",bottom:"rgba(139, 92, 246, 0.04)"},{line:"#ec4899",top:"rgba(236, 72, 153, 0.56)",bottom:"rgba(236, 72, 153, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"},{line:"#ea580c",top:"rgba(234, 88, 12, 0.56)",bottom:"rgba(234, 88, 12, 0.04)"},{line:"#84cc16",top:"rgba(132, 204, 22, 0.56)",bottom:"rgba(132, 204, 22, 0.04)"},{line:"#d946ef",top:"rgba(217, 70, 239, 0.56)",bottom:"rgba(217, 70, 239, 0.04)"},{line:"#0ea5e9",top:"rgba(14, 165, 233, 0.56)",bottom:"rgba(14, 165, 233, 0.04)"},{line:"#14b8a6",top:"rgba(20, 184, 166, 0.56)",bottom:"rgba(20, 184, 166, 0.04)"},{line:"#eab308",top:"rgba(234, 179, 8, 0.56)",bottom:"rgba(234, 179, 8, 0.04)"},{line:"#f43f5e",top:"rgba(244, 63, 94, 0.56)",bottom:"rgba(244, 63, 94, 0.04)"},{line:"#6366f1",top:"rgba(99, 102, 241, 0.56)",bottom:"rgba(99, 102, 241, 0.04)"},{line:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#78716c",top:"rgba(120, 113, 108, 0.56)",bottom:"rgba(120, 113, 108, 0.04)"},{line:"#64748b",top:"rgba(100, 116, 139, 0.56)",bottom:"rgba(100, 116, 139, 0.04)"},{line:"#475569",top:"rgba(71, 85, 105, 0.56)",bottom:"rgba(71, 85, 105, 0.04)"}],vt=137.5;function Ne(e){if(e<Se.length)return Se[e];const a=(e-Se.length)*vt%360,u=X.hslToHex(a,70,50),{topColor:h,bottomColor:f}=X.generateColorsFromBase(u);return{line:u,top:h,bottom:f}}function yt({series:e,className:n,showLegend:a=!1,onUnselectSeries:u,xMeasureUnit:h="time",yMeasureUnit:f="token",optionsOverrides:x,verticalLineOptions:P,priceLineOptions:k,zoneOptions:F,currentValueDecimals:ae,useSharedPriceScale:Z=!1,dualYAxis:A=!1,defaultVisiblePriceScaleId:Ve="right",leftPriceScaleTitle:Ee,rightPriceScaleTitle:_t,showCurrentValue:et=!0,graphTitle:Ce,yScaleMin:Ie,yScaleMinMultiple:De,visibleTimeFrom:ee,disableZoom:Me=!1,hideDefaultTooltip:xe=!1}){const j=p.useRef(null),E=p.useRef(new Map),ve=p.useRef(!1),ke=p.useRef(!0),Ae=p.useRef([]),le=p.useRef(0),B=p.useRef(null),ye=p.useRef(null),je=p.useRef(null),T=ct.useIsMobile(),ce=Te.useMemo(()=>e.flatMap(t=>t.data),[e]),tt=Te.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[Be,_e]=p.useState(()=>{if(!tt)return;const t=new Map;for(const l of e)l.data.length>0&&t.set(l.label,l.data[l.data.length-1]);return t}),[Fe,J]=p.useState(null),[ze,Ge]=p.useState([]),[ot,Xe]=p.useState(0),qe=p.useRef(new Map),[rt,nt]=p.useState({}),[te,it]=p.useState(0);p.useEffect(()=>{const t=()=>{try{if(B.current&&Xe(B.current.clientWidth),j.current&&B.current){const s=B.current.clientWidth,c=B.current.clientHeight;j.current.resize(s,c);try{le.current=j.current.paneSize().height}catch{}}}catch{}},l=B.current,i=l?new ResizeObserver(t):null;return je.current=i,l&&i?.observe(l),()=>{l&&i?.unobserve(l),i?.disconnect(),je.current=null}},[]),p.useEffect(()=>{if(!ye.current||ve.current)return;const t=D.getDefaultOptions(),l=X.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),i=H.createChart(ye.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:l},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:l},...T&&{crosshair:{...t.crosshair,mode:H.CrosshairMode.Magnet}}});j.current=i,ve.current=!0;try{le.current=i.paneSize().height}catch{le.current=0}return it(s=>s+1),()=>{i.remove(),j.current=null,ve.current=!1,E.current.clear()}},[T]),p.useEffect(()=>{const t=j.current;t&&t.applyOptions(Me?{handleScale:{mouseWheel:!1,pinch:!1,axisPressedMouseMove:!1,axisDoubleClickReset:!1},handleScroll:{mouseWheel:!1,pressedMouseMove:!1,horzTouchDrag:!1,vertTouchDrag:!1}}:{handleScale:{mouseWheel:!0,pinch:!0,axisPressedMouseMove:!0,axisDoubleClickReset:!0},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0}})},[te,Me]),p.useEffect(()=>{const t=j.current;!t||!x||t.applyOptions(x)},[te,x]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const i=e.filter(r=>r.data.length>0).length<=1?Ie:De,s=h==="time"?ne.getXFormatters(h,ce):ne.getXFormatters(h),c=new Map;{let r=0;for(const o of e)o.data.length!==0&&(c.set(o.label,o.priceScaleId??(r===0?"left":"right")),r++)}const g=(r,o,d)=>{const{formatter:z,tickmarksFormatter:N,updateVisibleRange:V}=ne.createAdaptiveYAxisFormatter(r,o,{yScaleMin:i});return{formatter:z,tickmarksFormatter:N,updateVisibleRange:V,labels:d}},m=[];if(A)for(const r of["left","right"]){const o=new Set,d=[];let z=f;for(const N of e)if(N.data.length!==0&&c.get(N.label)===r){o.size===0&&N.yMeasureUnit&&(z=N.yMeasureUnit),o.add(N.label);for(const V of N.data)d.push(V.value)}o.size>0&&m.push(g(d,z,o))}else{const r=ce.map(d=>d.value),o=new Set(e.filter(d=>d.data.length>0).map(d=>d.label));m.push(g(r,f,o))}Ae.current=m;const _=new Map;for(const r of m)for(const o of r.labels)_.set(o,r);const w=D.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:r=>s.timeFormatter(parseFloat(r),void 0)},timeScale:{...w.timeScale||{},...x?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const v=!A&&e.length>1&&!Z,q=A?T:e.length>1&&!Z||T,I=X.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...A&&{defaultVisiblePriceScaleId:Ve},leftPriceScale:{...w.leftPriceScale||{},...x?.leftPriceScale,visible:A&&!T,textColor:I,...A&&Ee&&{}},rightPriceScale:{...w.rightPriceScale||{},...x?.rightPriceScale,visible:A?!T:!q,textColor:I}});const oe=new Set(E.current.keys()),W=new Set(e.map(re));for(const r of oe)if(!W.has(r)){const o=E.current.get(r);o&&(t.removeSeries(o),E.current.delete(r))}const b=D.getDefaultSeries(),M=[];let L=0;const K=e.find(r=>r.data.length>0),y=new Map;if(k&&k.length>0)for(const r of k){if(!Number.isFinite(r.price))continue;const o=r.seriesLabel??K?.label;if(!o)continue;const d=y.get(o)??[];d.push(r.price),y.set(o,d)}if(F&&F.length>0)for(const r of F){const o=r.seriesLabel??K?.label;if(!o)continue;const d=y.get(o)??[];Number.isFinite(r.priceTop)&&d.push(r.priceTop),Number.isFinite(r.priceBottom)&&d.push(r.priceBottom),y.set(o,d)}for(let r=0;r<e.length;r++){const o=e[r],d=re(o),z=Ne(r),N=o.lineColor??o.color??z.line;let V,U;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)V=o.topColor,U=o.bottomColor;else if(o.topColor){const S=X.generateColorsFromBase(N);V=o.topColor,U=S.bottomColor}else if(o.bottomColor)V=X.generateColorsFromBase(N).topColor,U=o.bottomColor;else{const S=X.generateColorsFromBase(N);V=S.topColor,U=S.bottomColor}else V=o.topColor||z.top,U=o.bottomColor||z.bottom;if(o.data.length===0){const S=E.current.get(d);S&&(t.removeSeries(S),E.current.delete(d));continue}const pe=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,ue=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,fe=pe<0,Q=o.data.some(S=>S.value===0),me=!fe&&Q,he=He.pickMinMove(ue-pe),ge=A?o.priceScaleId??(L===0?"left":"right"):Z||!v||L===0?"right":`scale-${L}`;v&&M.push({priceScaleId:ge||"right",seriesIndex:L});const we=(Z||!v)&&i!==void 0&&typeof i=="number",st=y.get(o.label)??[],at=S=>{const R=S();if(R?.priceRange){we&&(R.priceRange.minValue=i);for(const O of st)O<R.priceRange.minValue&&(R.priceRange.minValue=O),O>R.priceRange.maxValue&&(R.priceRange.maxValue=O);const se=we?i:me&&R.priceRange.minValue>=0?0:void 0,be=le.current>0?le.current:B.current?.clientHeight??0;if(be>0){const O=He.niceAxisRange({min:R.priceRange.minValue,max:R.priceRange.maxValue,floor:se,scaleHeightPx:be,fontSizePx:D.AXIS_FONT_SIZE,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,minMove:he,edgePaddingPx:D.AXIS_EDGE_LABEL_PADDING_PX,edgePaddingTopPx:D.AXIS_TOP_LABEL_PADDING_PX});R.priceRange.minValue=O.min,R.priceRange.maxValue=O.max}R.margins={above:D.AXIS_TOP_LABEL_PADDING_PX,below:D.AXIS_EDGE_LABEL_PADDING_PX}}return R},Ke=_.get(o.label)??m[0],$e=Ke.formatter,lt=Ke.tickmarksFormatter,Re={lineColor:N,topColor:V,bottomColor:U,priceScaleId:ge,...o.seriesType==="line"&&{lineStyle:o.lineStyle??H.LineStyle.Solid},priceFormat:{type:"custom",minMove:he,formatter:we&&typeof i=="number"?S=>$e(S<i?i:S):$e,tickmarksFormatter:lt},autoscaleInfoProvider:at},Oe=o.seriesType==="line";let G=E.current.get(d);const ie=o.data.map(S=>({...S,time:S.time}));if(ee!==void 0&&ie.length>0&&Number(ie[0].time)>ee){const S=Number(ie[0].time),R=S-ee,se=86400,be=R>180*se?7*se:R>30*se?se:6*3600,O=[];for(let Pe=ee;Pe<S;Pe+=be)O.push({time:Pe});ie.unshift(...O)}G&&G.seriesType()!==(Oe?"Line":"Area")&&(t.removeSeries(G),E.current.delete(d),G=void 0),G?(G.applyOptions(Re),G.setData(ie)):(Oe?G=t.addSeries(H.LineSeries,{...b,...Re}):G=t.addSeries(H.AreaSeries,{...b,...Re}),G.setData(ie),E.current.set(d,G)),L++}if(A)try{const r=t.priceScale("left"),o=t.priceScale("right"),d={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...x?.rightPriceScale};r?.applyOptions(d),o?.applyOptions(d)}catch{}else if(v&&M.length>0)for(const r of M)try{const o=t.priceScale(r.priceScaleId);o&&o.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I})}catch(o){console.warn(`Failed to configure price scale ${r.priceScaleId} for series ${r.seriesIndex}:`,o)}else if(!v)try{const r=t.priceScale("right");r&&r.applyOptions({visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...x?.rightPriceScale})}catch{}if(i!==void 0&&!T&&(Z||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),ce.length>0){const r=ce.map(o=>Number(o.time)).filter(o=>Number.isFinite(o));if(r.length>0){const o=Math.min(...r),d=ee!==void 0?Math.min(ee,o):o,z=Math.max(...r);if(Number(d)<=Number(z)){const N=()=>{const V=t.timeScale();if(h!=="time"){V.applyOptions({fixLeftEdge:!0,fixRightEdge:!0});return}const U=A&&!T,pe=A?!T:!q,ue=!U,fe=!pe;if(V.applyOptions({fixLeftEdge:!ue,fixRightEdge:!fe}),!ue&&!fe)return;const Q=V.getVisibleLogicalRange(),me=V.width();if(!Q||!(me>0))return;const he=Q.to-Q.from;if(!(he>0))return;const ge=D.AXIS_TIME_EDGE_PADDING_PX*he/me;V.setVisibleLogicalRange({from:ue?Q.from-ge:Q.from,to:fe?Q.to+ge:Q.to})};try{t.timeScale().setVisibleRange({from:d,to:z}),N()}catch{try{t.timeScale().fitContent(),N()}catch{}}}}}ke.current&&(ke.current=!1),x&&t.applyOptions(x);const $=new Map;for(const r of e)r.data.length>0&&$.set(r.label,r.data[r.data.length-1]);_e($.size>0?$:void 0)},[te,e,ce,h,f,T,Z,A,Ve,Ee,Ie,De,ee,k,F,x]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const l=e.length===1;let i;for(const c of e)if(c.data.length>0){i=c.data[c.data.length-1].time;break}if(!i)return;const s=c=>{const{time:g=i,seriesData:m,point:_}=c||{},w=e[0],v=w?E.current.get(re(w)):void 0;if(!_||!g){const W=new Map;for(const b of e)b.data.length>0&&W.set(b.label,b.data[b.data.length-1]);if(_e(W.size>0?W:void 0),l||Z||xe)J(null);else if(v&&i){const b=e[0];if(b&&b.data.length>0){const L=t.timeScale().timeToCoordinate(i),K=b.data[b.data.length-1].value,y=v.priceToCoordinate(K);L!==null&&y!==null&&J({x:L,y})}}return}const q=new Map;let I,oe=v;for(let W=0;W<e.length;W++){const b=e[W],M=E.current.get(re(b));if(!M)continue;const L=m?.get(M),K=L&&"value"in L?L.value:void 0;let y;if(K!==void 0)y=K;else if(l){const $=Number(g),r=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;$<r?y=Number.NaN:y=b.data[b.data.length-1]?.value??0}else{const $=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;if(Number(g)<$)continue;y=Je(b.data,Number(g))}Number.isNaN(y)||(I===void 0&&(I=y,oe=M),q.set(b.label,{value:y,time:g}))}if(_e(q),I!==void 0&&oe){const b=t.timeScale().timeToCoordinate(g),M=oe.priceToCoordinate(I);if(b!==null&&M!==null){const L=B.current;if(L){const K=L.querySelector(".LightweightChart");if(K){const y=K.getBoundingClientRect(),$=L.getBoundingClientRect(),r=b+(y.left-$.left),o=M+(y.top-$.top);J({x:r,y:o})}else J({x:b,y:M})}else J({x:b,y:M})}else J(null)}else J(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!l&&!Z&&!xe&&requestAnimationFrame(()=>{const c=e[0],g=c?E.current.get(re(c)):void 0;if(g&&i&&c.data.length>0){const _=t.timeScale().timeToCoordinate(i),w=c.data[c.data.length-1].value,v=g.priceToCoordinate(w);_!==null&&v!==null&&J({x:_,y:v})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,Z,T,xe]),p.useEffect(()=>{const t=j.current;if(!t||e.length===0)return;const l=t.timeScale(),i=()=>{const s=Ae.current;if(s.length===0)return;const c=l.getVisibleRange();if(!c)return;const g=Number(c.from),m=Number(c.to);for(const _ of s){const w=[];for(const v of e)if(_.labels.has(v.label))for(const q of v.data){const I=Number(q.time);I>=g&&I<=m&&w.push(q.value)}w.length>0&&_.updateVisibleRange(w)}};return l.subscribeVisibleLogicalRangeChange(i),()=>{l.unsubscribeVisibleLogicalRangeChange(i)}},[e]),p.useEffect(()=>{const t=j.current,l=Array.from(E.current.values()),i=[];if(t&&l.length>0&&P){const s=D.getDefaultVerticalLine(),c=l[0];for(const g of P){const m={...s,...g.options||{}};m.color&&(m.color=X.resolveCSSColor(m.color,m.color));const _=new ht.VertLine(t,c,g.xCoordinate,m);c.attachPrimitive(_),i.push(_)}}return()=>{if(l.length>0){const s=l[0];for(const c of i)try{s.detachPrimitive(c)}catch{}}}},[P,e,te]),p.useEffect(()=>{const t=[],l=[];if(k&&k.length>0){const i=X.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of k){if(!Number.isFinite(s.price))continue;const c=Ze(E.current,e,s.seriesLabel);if(!c)continue;const g=s.color?X.resolveCSSColor(s.color,s.color):i,m=s.lineWidth??1,_=s.lineStyle??H.LineStyle.Dashed,w=c.createPriceLine({price:s.price,color:g,lineWidth:m,lineStyle:_,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:c,line:w});const v=new xt(c,s.price,g,m,_);c.attachPrimitive(v),l.push({series:c,primitive:v})}}return()=>{for(const{series:i,primitive:s}of l)try{i.detachPrimitive(s)}catch{}for(const{series:i,line:s}of t)try{i.removePriceLine(s)}catch{}}},[k,e,te]),p.useEffect(()=>{const t=[];if(F&&F.length>0){const l="rgba(239, 68, 68, 0.12)";for(const i of F){const s=Ze(E.current,e,i.seriesLabel);if(!s)continue;const c=i.color?X.resolveCSSColor(i.color,l):l,g=new mt(s,i.priceTop,i.priceBottom,c);s.attachPrimitive(g),t.push({series:s,zone:g})}}return()=>{for(const{series:l,zone:i}of t)try{l.detachPrimitive(i)}catch{}}},[F,e,te]),p.useEffect(()=>{const t=j.current;if(!t||!P?.length){Ge([]);return}const l=()=>{const c=t.timeScale(),g=P.map(m=>c.timeToCoordinate(m.xCoordinate)??null);Ge(g),B.current&&Xe(B.current.clientWidth)};l();const i=t.timeScale(),s=()=>{l()};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[P,e,te]),p.useLayoutEffect(()=>{nt(t=>{const l={};let i=!1;for(const[s,c]of qe.current){if(!c)continue;const g=c.offsetWidth;l[s]=g,t[s]!==g&&(i=!0)}return Object.keys(t).length!==Object.keys(l).length&&(i=!0),i?l:t})});const de=e.length===1,We=Te.useMemo(()=>{if(de&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[de,e]);return C.jsxs("div",{ref:B,className:Y.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[Ce!=null&&Ce!==!1&&de?C.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:C.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Ce})}):et&&de&&We&&C.jsx(ut.GraphCurrentValue,{point:We,xMeasureUnit:h,yMeasureUnit:f,decimals:ae}),Be&&Fe&&C.jsx(ft.GraphTooltip,{points:Be,xMeasureUnit:h,yMeasureUnit:f,series:e,position:Fe,containerRef:B,decimals:ae}),a&&C.jsx(Ue,{series:e,onUnselect:u}),P&&P.length>0&&ze.length===P.length&&C.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:P.map((t,l)=>{const i=ze[l],s=t.options??{};if(i===null)return null;const{labelText:c,valueStr:g}=Qe(s,f,ae),m=s.tooltipText??"";if(!(c||g||m))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",v=s.labelTextColor??"hsl(var(--foreground))",q=`${String(t.xCoordinate)}-${c}-${m}`,I=Ye(i,ot,rt[l]);return C.jsxs("div",{ref:oe=>{qe.current.set(l,oe)},className:Y.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",m&&"pointer-events-auto cursor-default"),style:{...I,backgroundColor:w,color:v},children:[c&&C.jsx("span",{className:"block",children:c}),g&&C.jsx("span",{className:Y.cn("block",c&&"mt-0.5"),children:g}),m&&C.jsx("span",{className:"pointer-events-none absolute right-0 top-full z-10 mt-1 hidden w-[280px] whitespace-normal rounded border border-border bg-popover px-2.5 py-1.5 text-left leading-snug text-popover-foreground shadow-md group-hover:block",role:"tooltip",children:m})]},q)})}),C.jsx("div",{ref:ye,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ue({series:e,markers:n,onUnselect:a,inline:u=!1}){const h=e.every(f=>f.data.length===0);return C.jsxs("div",{className:Y.cn("flex flex-wrap",u?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:[e.map((f,x)=>{const P=Ne(x),k=(f.lineColor??f.color)||P.line,F=!h&&f.data.length===0;return C.jsxs("div",{className:Y.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",F&&"opacity-50"),children:[C.jsx("div",{className:Y.cn("shrink-0",u?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:k}}),C.jsxs("span",{className:Y.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:[f.label,F&&" (no data)"]}),a&&C.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),a(f.label)},className:"ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer","aria-label":`Remove ${f.label}`,children:C.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-muted-foreground hover:text-foreground","aria-hidden":"true",children:[C.jsx("title",{children:"Close"}),C.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),C.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f.id??f.label)}),n?.map(f=>C.jsxs("div",{className:Y.cn("flex shrink-0 items-center gap-1.5",!u&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border"),children:[C.jsx("div",{className:"h-3 w-0.5 shrink-0",style:{backgroundColor:f.color}}),C.jsx("span",{className:Y.cn("font-medium text-foreground",u?"text-sm":"text-[10px] sm:text-xs"),children:f.label})]},f.id))]})}exports.DEFAULT_SERIES_COLORS=Se;exports.Graph=yt;exports.GraphLegend=Ue;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=Le;exports.getSeriesColorPalette=Ne;exports.getStepForwardValue=Je;exports.getVerticalLineLabelStyle=Ye;exports.getVerticalLineTooltipContent=Qe;exports.seriesIdentity=re;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsxs as e, jsx as
|
|
1
|
+
import { jsxs as e, jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import { ChartWithSideCardTest as i } from "./constants.js";
|
|
3
3
|
function m({
|
|
4
|
-
chart:
|
|
4
|
+
chart: r,
|
|
5
5
|
side: t
|
|
6
6
|
}) {
|
|
7
7
|
return /* @__PURE__ */ e(
|
|
@@ -10,18 +10,18 @@ function m({
|
|
|
10
10
|
className: "flex w-full flex-wrap gap-4",
|
|
11
11
|
"data-testid": i.root,
|
|
12
12
|
children: [
|
|
13
|
-
/* @__PURE__ */
|
|
13
|
+
/* @__PURE__ */ a(
|
|
14
14
|
"div",
|
|
15
15
|
{
|
|
16
16
|
className: "min-w-[min(100%,40rem)] grow-[999] basis-0",
|
|
17
17
|
"data-testid": i.chart,
|
|
18
|
-
children:
|
|
18
|
+
children: r
|
|
19
19
|
}
|
|
20
20
|
),
|
|
21
|
-
/* @__PURE__ */
|
|
21
|
+
/* @__PURE__ */ a(
|
|
22
22
|
"div",
|
|
23
23
|
{
|
|
24
|
-
className: "min-w-[min(100%,300px)] grow
|
|
24
|
+
className: "min-w-[min(100%,300px)] grow basis-[22.5rem]",
|
|
25
25
|
"data-testid": i.side,
|
|
26
26
|
children: t
|
|
27
27
|
}
|
|
@@ -3,7 +3,7 @@ import { createChart as ht, CrosshairMode as dt, LineStyle as le, LineSeries as
|
|
|
3
3
|
import * as Ve from "react";
|
|
4
4
|
import { useRef as K, useState as ne, useEffect as G, useLayoutEffect as pt } from "react";
|
|
5
5
|
import { useIsMobile as bt } from "../../hooks/use-media-query.js";
|
|
6
|
-
import { cn as
|
|
6
|
+
import { cn as O } from "../../utils/cn.js";
|
|
7
7
|
import { hslToHex as St, generateColorsFromBase as Ce, resolveCSSColor as ie } from "../../utils/colors.js";
|
|
8
8
|
import { getDefaultOptions as Je, getDefaultSeries as vt, AXIS_TICK_MARK_DENSITY as ve, getDefaultVerticalLine as Ct, AXIS_FONT_SIZE as xt, AXIS_EDGE_LABEL_PADDING_PX as Qe, AXIS_TOP_LABEL_PADDING_PX as Ye, AXIS_TIME_EDGE_PADDING_PX as yt } from "./default-config.js";
|
|
9
9
|
import { formatExactValue as Le, isRatioUnit as _t, getXFormatters as Ue, createAdaptiveYAxisFormatter as wt } from "./formatters.js";
|
|
@@ -36,7 +36,7 @@ class Lt {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class kt {
|
|
40
40
|
_source;
|
|
41
41
|
_yTop = null;
|
|
42
42
|
_yBottom = null;
|
|
@@ -55,14 +55,14 @@ class Mt {
|
|
|
55
55
|
return new Lt(this._yTop, this._yBottom, this._source.color);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
class
|
|
58
|
+
class Mt {
|
|
59
59
|
series;
|
|
60
60
|
priceTop;
|
|
61
61
|
priceBottom;
|
|
62
62
|
color;
|
|
63
63
|
_paneViews;
|
|
64
64
|
constructor(i, c, u, h) {
|
|
65
|
-
this.series = i, this.priceTop = c, this.priceBottom = u, this.color = h, this._paneViews = [new
|
|
65
|
+
this.series = i, this.priceTop = c, this.priceBottom = u, this.color = h, this._paneViews = [new kt(this)];
|
|
66
66
|
}
|
|
67
67
|
updateAllViews() {
|
|
68
68
|
for (const i of this._paneViews) i.update();
|
|
@@ -167,7 +167,7 @@ function At(e, i) {
|
|
|
167
167
|
return e[c].value;
|
|
168
168
|
return 0;
|
|
169
169
|
}
|
|
170
|
-
const
|
|
170
|
+
const ke = [
|
|
171
171
|
// 0 green (emerald)
|
|
172
172
|
{
|
|
173
173
|
line: "#02c39a",
|
|
@@ -284,9 +284,9 @@ const Me = [
|
|
|
284
284
|
}
|
|
285
285
|
], Gt = 137.5;
|
|
286
286
|
function ot(e) {
|
|
287
|
-
if (e <
|
|
288
|
-
return
|
|
289
|
-
const c = (e -
|
|
287
|
+
if (e < ke.length)
|
|
288
|
+
return ke[e];
|
|
289
|
+
const c = (e - ke.length) * Gt % 360, u = St(c, 70, 50), { topColor: h, bottomColor: f } = Ce(u);
|
|
290
290
|
return { line: u, top: h, bottom: f };
|
|
291
291
|
}
|
|
292
292
|
function oo({
|
|
@@ -301,9 +301,9 @@ function oo({
|
|
|
301
301
|
priceLineOptions: I,
|
|
302
302
|
zoneOptions: F,
|
|
303
303
|
currentValueDecimals: se,
|
|
304
|
-
useSharedPriceScale:
|
|
304
|
+
useSharedPriceScale: Z = !1,
|
|
305
305
|
dualYAxis: D = !1,
|
|
306
|
-
defaultVisiblePriceScaleId:
|
|
306
|
+
defaultVisiblePriceScaleId: Me = "right",
|
|
307
307
|
leftPriceScaleTitle: Ie,
|
|
308
308
|
rightPriceScaleTitle: Xt,
|
|
309
309
|
showCurrentValue: rt = !0,
|
|
@@ -469,19 +469,19 @@ function oo({
|
|
|
469
469
|
minBarSpacing: 0
|
|
470
470
|
}
|
|
471
471
|
});
|
|
472
|
-
const v = !D && e.length > 1 && !
|
|
472
|
+
const v = !D && e.length > 1 && !Z, W = D ? N : e.length > 1 && !Z || N, k = ie(
|
|
473
473
|
"hsl(var(--muted-foreground))",
|
|
474
474
|
"rgb(163, 163, 163)"
|
|
475
475
|
);
|
|
476
476
|
t.applyOptions({
|
|
477
477
|
...D && {
|
|
478
|
-
defaultVisiblePriceScaleId:
|
|
478
|
+
defaultVisiblePriceScaleId: Me
|
|
479
479
|
},
|
|
480
480
|
leftPriceScale: {
|
|
481
481
|
...y.leftPriceScale || {},
|
|
482
482
|
...S?.leftPriceScale,
|
|
483
483
|
visible: D && !N,
|
|
484
|
-
textColor:
|
|
484
|
+
textColor: k,
|
|
485
485
|
...D && Ie && {
|
|
486
486
|
// lightweight-charts uses scale margins; title shown via localization if needed
|
|
487
487
|
}
|
|
@@ -490,7 +490,7 @@ function oo({
|
|
|
490
490
|
...y.rightPriceScale || {},
|
|
491
491
|
...S?.rightPriceScale,
|
|
492
492
|
visible: D ? !N : !W,
|
|
493
|
-
textColor:
|
|
493
|
+
textColor: k
|
|
494
494
|
}
|
|
495
495
|
});
|
|
496
496
|
const ee = new Set(L.current.keys()), X = new Set(e.map(ae));
|
|
@@ -499,7 +499,7 @@ function oo({
|
|
|
499
499
|
const o = L.current.get(r);
|
|
500
500
|
o && (t.removeSeries(o), L.current.delete(r));
|
|
501
501
|
}
|
|
502
|
-
const p = vt(),
|
|
502
|
+
const p = vt(), M = [];
|
|
503
503
|
let R = 0;
|
|
504
504
|
const $ = e.find((r) => r.data.length > 0), C = /* @__PURE__ */ new Map();
|
|
505
505
|
if (I && I.length > 0)
|
|
@@ -539,12 +539,12 @@ function oo({
|
|
|
539
539
|
b && (t.removeSeries(b), L.current.delete(m));
|
|
540
540
|
continue;
|
|
541
541
|
}
|
|
542
|
-
const pe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, fe = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, he = pe < 0,
|
|
543
|
-
v &&
|
|
542
|
+
const pe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, fe = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, he = pe < 0, q = o.data.some((b) => b.value === 0), be = !he && q, de = Tt(fe - pe), me = D ? o.priceScaleId ?? (R === 0 ? "left" : "right") : Z || !v || R === 0 ? "right" : `scale-${R}`;
|
|
543
|
+
v && M.push({
|
|
544
544
|
priceScaleId: me || "right",
|
|
545
545
|
seriesIndex: R
|
|
546
546
|
});
|
|
547
|
-
const Ne = (
|
|
547
|
+
const Ne = (Z || !v) && n !== void 0 && typeof n == "number", ct = C.get(o.label) ?? [], ut = (b) => {
|
|
548
548
|
const _ = b();
|
|
549
549
|
if (_?.priceRange) {
|
|
550
550
|
Ne && (_.priceRange.minValue = n);
|
|
@@ -617,14 +617,14 @@ function oo({
|
|
|
617
617
|
alignLabels: !0,
|
|
618
618
|
entireTextOnly: !1,
|
|
619
619
|
tickMarkDensity: ve,
|
|
620
|
-
textColor:
|
|
620
|
+
textColor: k,
|
|
621
621
|
...S?.rightPriceScale
|
|
622
622
|
};
|
|
623
623
|
r?.applyOptions(m), o?.applyOptions(m);
|
|
624
624
|
} catch {
|
|
625
625
|
}
|
|
626
|
-
else if (v &&
|
|
627
|
-
for (const r of
|
|
626
|
+
else if (v && M.length > 0)
|
|
627
|
+
for (const r of M)
|
|
628
628
|
try {
|
|
629
629
|
const o = t.priceScale(r.priceScaleId);
|
|
630
630
|
o && o.applyOptions({
|
|
@@ -637,7 +637,7 @@ function oo({
|
|
|
637
637
|
alignLabels: !0,
|
|
638
638
|
entireTextOnly: !1,
|
|
639
639
|
tickMarkDensity: ve,
|
|
640
|
-
textColor:
|
|
640
|
+
textColor: k
|
|
641
641
|
});
|
|
642
642
|
} catch (o) {
|
|
643
643
|
console.warn(
|
|
@@ -658,12 +658,12 @@ function oo({
|
|
|
658
658
|
alignLabels: !0,
|
|
659
659
|
entireTextOnly: !1,
|
|
660
660
|
tickMarkDensity: ve,
|
|
661
|
-
textColor:
|
|
661
|
+
textColor: k,
|
|
662
662
|
...S?.rightPriceScale
|
|
663
663
|
});
|
|
664
664
|
} catch {
|
|
665
665
|
}
|
|
666
|
-
if (n !== void 0 && !N && (
|
|
666
|
+
if (n !== void 0 && !N && (Z || !v) && t.applyOptions({
|
|
667
667
|
handleScroll: {
|
|
668
668
|
vertTouchDrag: !1
|
|
669
669
|
}
|
|
@@ -686,14 +686,14 @@ function oo({
|
|
|
686
686
|
fixLeftEdge: !fe,
|
|
687
687
|
fixRightEdge: !he
|
|
688
688
|
}), !fe && !he) return;
|
|
689
|
-
const
|
|
690
|
-
if (!
|
|
691
|
-
const de =
|
|
689
|
+
const q = V.getVisibleLogicalRange(), be = V.width();
|
|
690
|
+
if (!q || !(be > 0)) return;
|
|
691
|
+
const de = q.to - q.from;
|
|
692
692
|
if (!(de > 0)) return;
|
|
693
693
|
const me = yt * de / be;
|
|
694
694
|
V.setVisibleLogicalRange({
|
|
695
|
-
from: fe ?
|
|
696
|
-
to: he ?
|
|
695
|
+
from: fe ? q.from - me : q.from,
|
|
696
|
+
to: he ? q.to + me : q.to
|
|
697
697
|
});
|
|
698
698
|
};
|
|
699
699
|
try {
|
|
@@ -719,9 +719,9 @@ function oo({
|
|
|
719
719
|
h,
|
|
720
720
|
f,
|
|
721
721
|
N,
|
|
722
|
-
|
|
722
|
+
Z,
|
|
723
723
|
D,
|
|
724
|
-
|
|
724
|
+
Me,
|
|
725
725
|
Ie,
|
|
726
726
|
De,
|
|
727
727
|
Ee,
|
|
@@ -746,7 +746,7 @@ function oo({
|
|
|
746
746
|
const X = /* @__PURE__ */ new Map();
|
|
747
747
|
for (const p of e)
|
|
748
748
|
p.data.length > 0 && X.set(p.label, p.data[p.data.length - 1]);
|
|
749
|
-
if (Pe(X.size > 0 ? X : void 0), l ||
|
|
749
|
+
if (Pe(X.size > 0 ? X : void 0), l || Z || ye)
|
|
750
750
|
J(null);
|
|
751
751
|
else if (v && n) {
|
|
752
752
|
const p = e[0];
|
|
@@ -758,11 +758,11 @@ function oo({
|
|
|
758
758
|
return;
|
|
759
759
|
}
|
|
760
760
|
const W = /* @__PURE__ */ new Map();
|
|
761
|
-
let
|
|
761
|
+
let k, ee = v;
|
|
762
762
|
for (let X = 0; X < e.length; X++) {
|
|
763
|
-
const p = e[X],
|
|
764
|
-
if (!
|
|
765
|
-
const R = g?.get(
|
|
763
|
+
const p = e[X], M = L.current.get(ae(p));
|
|
764
|
+
if (!M) continue;
|
|
765
|
+
const R = g?.get(M), $ = R && "value" in R ? R.value : void 0;
|
|
766
766
|
let C;
|
|
767
767
|
if ($ !== void 0)
|
|
768
768
|
C = $;
|
|
@@ -774,29 +774,29 @@ function oo({
|
|
|
774
774
|
if (Number(d) < H) continue;
|
|
775
775
|
C = At(p.data, Number(d));
|
|
776
776
|
}
|
|
777
|
-
Number.isNaN(C) || (
|
|
777
|
+
Number.isNaN(C) || (k === void 0 && (k = C, ee = M), W.set(p.label, { value: C, time: d }));
|
|
778
778
|
}
|
|
779
|
-
if (Pe(W),
|
|
780
|
-
const p = t.timeScale().timeToCoordinate(d),
|
|
781
|
-
if (p !== null &&
|
|
779
|
+
if (Pe(W), k !== void 0 && ee) {
|
|
780
|
+
const p = t.timeScale().timeToCoordinate(d), M = ee.priceToCoordinate(k);
|
|
781
|
+
if (p !== null && M !== null) {
|
|
782
782
|
const R = B.current;
|
|
783
783
|
if (R) {
|
|
784
784
|
const $ = R.querySelector(
|
|
785
785
|
".LightweightChart"
|
|
786
786
|
);
|
|
787
787
|
if ($) {
|
|
788
|
-
const C = $.getBoundingClientRect(), H = R.getBoundingClientRect(), r = p + (C.left - H.left), o =
|
|
788
|
+
const C = $.getBoundingClientRect(), H = R.getBoundingClientRect(), r = p + (C.left - H.left), o = M + (C.top - H.top);
|
|
789
789
|
J({ x: r, y: o });
|
|
790
790
|
} else
|
|
791
|
-
J({ x: p, y:
|
|
791
|
+
J({ x: p, y: M });
|
|
792
792
|
} else
|
|
793
|
-
J({ x: p, y:
|
|
793
|
+
J({ x: p, y: M });
|
|
794
794
|
} else
|
|
795
795
|
J(null);
|
|
796
796
|
} else
|
|
797
797
|
J(null);
|
|
798
798
|
};
|
|
799
|
-
return t.subscribeCrosshairMove(a), N && t.subscribeClick(a), !l && !
|
|
799
|
+
return t.subscribeCrosshairMove(a), N && t.subscribeClick(a), !l && !Z && !ye && requestAnimationFrame(() => {
|
|
800
800
|
const s = e[0], d = s ? L.current.get(ae(s)) : void 0;
|
|
801
801
|
if (d && n && s.data.length > 0) {
|
|
802
802
|
const x = t.timeScale().timeToCoordinate(n), y = s.data[s.data.length - 1].value, v = d.priceToCoordinate(y);
|
|
@@ -805,7 +805,7 @@ function oo({
|
|
|
805
805
|
}), () => {
|
|
806
806
|
t.unsubscribeCrosshairMove(a), N && t.unsubscribeClick(a);
|
|
807
807
|
};
|
|
808
|
-
}, [e,
|
|
808
|
+
}, [e, Z, N, ye]), G(() => {
|
|
809
809
|
const t = E.current;
|
|
810
810
|
if (!t || e.length === 0) return;
|
|
811
811
|
const l = t.timeScale(), n = () => {
|
|
@@ -819,8 +819,8 @@ function oo({
|
|
|
819
819
|
for (const v of e)
|
|
820
820
|
if (x.labels.has(v.label))
|
|
821
821
|
for (const W of v.data) {
|
|
822
|
-
const
|
|
823
|
-
|
|
822
|
+
const k = Number(W.time);
|
|
823
|
+
k >= d && k <= g && y.push(W.value);
|
|
824
824
|
}
|
|
825
825
|
y.length > 0 && x.updateVisibleRange(y);
|
|
826
826
|
}
|
|
@@ -911,7 +911,7 @@ function oo({
|
|
|
911
911
|
n.seriesLabel
|
|
912
912
|
);
|
|
913
913
|
if (!a) continue;
|
|
914
|
-
const s = n.color ? ie(n.color, l) : l, d = new
|
|
914
|
+
const s = n.color ? ie(n.color, l) : l, d = new Mt(
|
|
915
915
|
a,
|
|
916
916
|
n.priceTop,
|
|
917
917
|
n.priceBottom,
|
|
@@ -967,7 +967,7 @@ function oo({
|
|
|
967
967
|
"div",
|
|
968
968
|
{
|
|
969
969
|
ref: B,
|
|
970
|
-
className:
|
|
970
|
+
className: O(
|
|
971
971
|
"relative z-[1] w-full h-full overflow-hidden p-0",
|
|
972
972
|
i
|
|
973
973
|
),
|
|
@@ -1008,7 +1008,7 @@ function oo({
|
|
|
1008
1008
|
se
|
|
1009
1009
|
), g = a.tooltipText ?? "";
|
|
1010
1010
|
if (!(s || d || g)) return null;
|
|
1011
|
-
const y = a.labelBackgroundColor ?? a.color ?? "hsl(var(--background))", v = a.labelTextColor ?? "hsl(var(--foreground))", W = `${String(t.xCoordinate)}-${s}-${g}`,
|
|
1011
|
+
const y = a.labelBackgroundColor ?? a.color ?? "hsl(var(--background))", v = a.labelTextColor ?? "hsl(var(--foreground))", W = `${String(t.xCoordinate)}-${s}-${g}`, k = zt(
|
|
1012
1012
|
n,
|
|
1013
1013
|
it,
|
|
1014
1014
|
at[l]
|
|
@@ -1019,18 +1019,18 @@ function oo({
|
|
|
1019
1019
|
ref: (ee) => {
|
|
1020
1020
|
je.current.set(l, ee);
|
|
1021
1021
|
},
|
|
1022
|
-
className:
|
|
1022
|
+
className: O(
|
|
1023
1023
|
"group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
|
|
1024
1024
|
g && "pointer-events-auto cursor-default"
|
|
1025
1025
|
),
|
|
1026
1026
|
style: {
|
|
1027
|
-
...
|
|
1027
|
+
...k,
|
|
1028
1028
|
backgroundColor: y,
|
|
1029
1029
|
color: v
|
|
1030
1030
|
},
|
|
1031
1031
|
children: [
|
|
1032
1032
|
s && /* @__PURE__ */ w("span", { className: "block", children: s }),
|
|
1033
|
-
d && /* @__PURE__ */ w("span", { className:
|
|
1033
|
+
d && /* @__PURE__ */ w("span", { className: O("block", s && "mt-0.5"), children: d }),
|
|
1034
1034
|
g && /* @__PURE__ */ w(
|
|
1035
1035
|
"span",
|
|
1036
1036
|
{
|
|
@@ -1067,7 +1067,7 @@ function Wt({
|
|
|
1067
1067
|
return /* @__PURE__ */ te(
|
|
1068
1068
|
"div",
|
|
1069
1069
|
{
|
|
1070
|
-
className:
|
|
1070
|
+
className: O(
|
|
1071
1071
|
"flex flex-wrap",
|
|
1072
1072
|
u ? "items-center justify-center gap-6" : "absolute top-0 left-2 z-[10] gap-2"
|
|
1073
1073
|
),
|
|
@@ -1077,8 +1077,8 @@ function Wt({
|
|
|
1077
1077
|
return /* @__PURE__ */ te(
|
|
1078
1078
|
"div",
|
|
1079
1079
|
{
|
|
1080
|
-
className:
|
|
1081
|
-
"flex items-center gap-1.5",
|
|
1080
|
+
className: O(
|
|
1081
|
+
"flex shrink-0 items-center gap-1.5",
|
|
1082
1082
|
!u && "px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
|
|
1083
1083
|
F && "opacity-50"
|
|
1084
1084
|
),
|
|
@@ -1086,7 +1086,8 @@ function Wt({
|
|
|
1086
1086
|
/* @__PURE__ */ w(
|
|
1087
1087
|
"div",
|
|
1088
1088
|
{
|
|
1089
|
-
className:
|
|
1089
|
+
className: O(
|
|
1090
|
+
"shrink-0",
|
|
1090
1091
|
u ? "size-2 rounded-full" : "h-3 w-3 rounded-sm"
|
|
1091
1092
|
),
|
|
1092
1093
|
style: { backgroundColor: I }
|
|
@@ -1095,7 +1096,7 @@ function Wt({
|
|
|
1095
1096
|
/* @__PURE__ */ te(
|
|
1096
1097
|
"span",
|
|
1097
1098
|
{
|
|
1098
|
-
className:
|
|
1099
|
+
className: O(
|
|
1099
1100
|
"font-medium text-foreground",
|
|
1100
1101
|
u ? "text-sm" : "text-[10px] sm:text-xs"
|
|
1101
1102
|
),
|
|
@@ -1145,22 +1146,22 @@ function Wt({
|
|
|
1145
1146
|
i?.map((f) => /* @__PURE__ */ te(
|
|
1146
1147
|
"div",
|
|
1147
1148
|
{
|
|
1148
|
-
className:
|
|
1149
|
-
"flex items-center gap-1.5",
|
|
1149
|
+
className: O(
|
|
1150
|
+
"flex shrink-0 items-center gap-1.5",
|
|
1150
1151
|
!u && "px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border"
|
|
1151
1152
|
),
|
|
1152
1153
|
children: [
|
|
1153
1154
|
/* @__PURE__ */ w(
|
|
1154
1155
|
"div",
|
|
1155
1156
|
{
|
|
1156
|
-
className:
|
|
1157
|
+
className: "h-3 w-0.5 shrink-0",
|
|
1157
1158
|
style: { backgroundColor: f.color }
|
|
1158
1159
|
}
|
|
1159
1160
|
),
|
|
1160
1161
|
/* @__PURE__ */ w(
|
|
1161
1162
|
"span",
|
|
1162
1163
|
{
|
|
1163
|
-
className:
|
|
1164
|
+
className: O(
|
|
1164
1165
|
"font-medium text-foreground",
|
|
1165
1166
|
u ? "text-sm" : "text-[10px] sm:text-xs"
|
|
1166
1167
|
),
|
|
@@ -1176,7 +1177,7 @@ function Wt({
|
|
|
1176
1177
|
);
|
|
1177
1178
|
}
|
|
1178
1179
|
export {
|
|
1179
|
-
|
|
1180
|
+
ke as DEFAULT_SERIES_COLORS,
|
|
1180
1181
|
oo as Graph,
|
|
1181
1182
|
Wt as GraphLegend,
|
|
1182
1183
|
tt as VERTICAL_LINE_LABEL_EDGE_PADDING,
|