@gearbox-protocol/ui-kit 4.0.0-next.31 → 4.0.0-next.32
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 x=require("react/jsx-runtime"),H=require("lightweight-charts"),p=require("react"),ct=require("../../hooks/use-media-query.cjs"),re=require("../../utils/cn.cjs"),G=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 f=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,f.get?f:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const Te=gt(p);function oe(e){return e.id??e.label}function Ze(e,n,a){if(!a)return e.values().next().value;const f=e.get(a);if(f)return f;const u=n.find(b=>b.id===a||b.label===a);return u?e.get(oe(u)):void 0}class pt{_yTop;_yBottom;_color;constructor(n,a,f){this._yTop=n,this._yBottom=a,this._color=f}draw(n){n.useBitmapCoordinateSpace(a=>{const f=a.context,u=a.verticalPixelRatio,b=this._yTop===null?0:this._yTop*u,C=this._yBottom===null?a.bitmapSize.height:this._yBottom*u,P=Math.min(b,C),M=Math.max(b,C);f.fillStyle=this._color,f.fillRect(0,P,a.bitmapSize.width,M-P)})}}class dt{_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 pt(this._yTop,this._yBottom,this._source.color)}}class mt{series;priceTop;priceBottom;color;_paneViews;constructor(n,a,f,u){this.series=n,this.priceTop=a,this.priceBottom=f,this.color=u,this._paneViews=[new dt(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,f,u){this._y=n,this._color=a,this._lineWidth=f,this._lineStyle=u}draw(n){n.useBitmapCoordinateSpace(a=>{if(this._y===null)return;const f=a.context,u=a.verticalPixelRatio,b=Math.max(1,Math.round(this._lineWidth*u)),C=Math.round(this._y*u);f.save(),f.strokeStyle=this._color,f.lineWidth=b,f.setLineDash(bt(this._lineStyle,b)),f.beginPath(),f.moveTo(0,C),f.lineTo(a.bitmapSize.width,C),f.stroke(),f.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 vt{series;price;color;lineWidth;lineStyle;_paneViews;constructor(n,a,f,u,b){this.series=n,this.price=a,this.color=f,this.lineWidth=u,this.lineStyle=b,this._paneViews=[new Ct(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function Qe(e,n,a){const f=e.labelText??"",u=e.value,b=u===void 0?"":typeof u=="number"?n==="$"?`$${ne.formatExactValue(u,void 0,a)}`:n==="%"?`${ne.formatExactValue(u,void 0,a)}%`:ne.formatExactValue(u,n!=="none"&&n!=="%"&&n!=="$"&&!ne.isRatioUnit(n)?n:void 0,a):String(u);return{labelText:f,valueStr:b}}const Le=4;function Ye(e,n,a){const f={left:e,transform:"translateX(-50%)"};if(n<=0||!a||a<=0)return f;const u=a/2,b=Le+u,C=n-Le-u;return C<b?{left:n/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,b),C),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 be=[{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)"}],xt=137.5;function Ne(e){if(e<be.length)return be[e];const a=(e-be.length)*xt%360,f=G.hslToHex(a,70,50),{topColor:u,bottomColor:b}=G.generateColorsFromBase(f);return{line:f,top:u,bottom:b}}function _t({series:e,className:n,showLegend:a=!1,onUnselectSeries:f,xMeasureUnit:u="time",yMeasureUnit:b="token",optionsOverrides:C,verticalLineOptions:P,priceLineOptions:M,zoneOptions:X,currentValueDecimals:Se,useSharedPriceScale:Z=!1,dualYAxis:A=!1,defaultVisiblePriceScaleId:Ve="right",leftPriceScaleTitle:Ie,rightPriceScaleTitle:yt,showCurrentValue:et=!0,graphTitle:Ce,yScaleMin:Ee,yScaleMinMultiple:De,visibleTimeFrom:U,disableZoom:Me=!1,hideDefaultTooltip:ve=!1}){const B=p.useRef(null),V=p.useRef(new Map),xe=p.useRef(!1),ke=p.useRef(!0),Ae=p.useRef([]),ae=p.useRef(0),j=p.useRef(null),_e=p.useRef(null),Be=p.useRef(null),T=ct.useIsMobile(),le=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]),[je,ye]=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,Y]=p.useState(null),[ze,Ge]=p.useState([]),[ot,Xe]=p.useState(0),qe=p.useRef(new Map),[rt,nt]=p.useState({}),[ee,it]=p.useState(0);p.useEffect(()=>{const t=()=>{try{if(j.current&&Xe(j.current.clientWidth),B.current&&j.current){const s=j.current.clientWidth,c=j.current.clientHeight;B.current.resize(s,c);try{ae.current=B.current.paneSize().height}catch{}}}catch{}},l=j.current,i=l?new ResizeObserver(t):null;return Be.current=i,l&&i?.observe(l),()=>{l&&i?.unobserve(l),i?.disconnect(),Be.current=null}},[]),p.useEffect(()=>{if(!_e.current||xe.current)return;const t=D.getDefaultOptions(),l=G.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),i=H.createChart(_e.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:l},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:l},...T&&{crosshair:{...t.crosshair,mode:H.CrosshairMode.Magnet}}});B.current=i,xe.current=!0;try{ae.current=i.paneSize().height}catch{ae.current=0}return it(s=>s+1),()=>{i.remove(),B.current=null,xe.current=!1,V.current.clear()}},[T]),p.useEffect(()=>{const t=B.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}})},[ee,Me]),p.useEffect(()=>{const t=B.current;!t||!C||t.applyOptions(C)},[ee,C]),p.useEffect(()=>{const t=B.current;if(!t||e.length===0)return;const i=e.filter(r=>r.data.length>0).length<=1?Ee:De,s=u==="time"?ne.getXFormatters(u,le):ne.getXFormatters(u),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 h=(r,o,g)=>{const{formatter:F,tickmarksFormatter:N,updateVisibleRange:E}=ne.createAdaptiveYAxisFormatter(r,o,{yScaleMin:i});return{formatter:F,tickmarksFormatter:N,updateVisibleRange:E,labels:g}},d=[];if(A)for(const r of["left","right"]){const o=new Set,g=[];let F=b;for(const N of e)if(N.data.length!==0&&c.get(N.label)===r){o.size===0&&N.yMeasureUnit&&(F=N.yMeasureUnit),o.add(N.label);for(const E of N.data)g.push(E.value)}o.size>0&&d.push(h(g,F,o))}else{const r=le.map(g=>g.value),o=new Set(e.filter(g=>g.data.length>0).map(g=>g.label));d.push(h(r,b,o))}Ae.current=d;const y=new Map;for(const r of d)for(const o of r.labels)y.set(o,r);const w=D.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:r=>s.timeFormatter(parseFloat(r),void 0)},timeScale:{...w.timeScale||{},...C?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const v=!A&&e.length>1&&!Z,q=A?T:e.length>1&&!Z||T,I=G.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...A&&{defaultVisiblePriceScaleId:Ve},leftPriceScale:{...w.leftPriceScale||{},...C?.leftPriceScale,visible:A&&!T,textColor:I,...A&&Ie&&{}},rightPriceScale:{...w.rightPriceScale||{},...C?.rightPriceScale,visible:A?!T:!q,textColor:I}});const te=new Set(V.current.keys()),W=new Set(e.map(oe));for(const r of te)if(!W.has(r)){const o=V.current.get(r);o&&(t.removeSeries(o),V.current.delete(r))}const m=D.getDefaultSeries(),k=[];let L=0;const K=e.find(r=>r.data.length>0),_=new Map;if(M&&M.length>0)for(const r of M){if(!Number.isFinite(r.price))continue;const o=r.seriesLabel??K?.label;if(!o)continue;const g=_.get(o)??[];g.push(r.price),_.set(o,g)}if(X&&X.length>0)for(const r of X){const o=r.seriesLabel??K?.label;if(!o)continue;const g=_.get(o)??[];Number.isFinite(r.priceTop)&&g.push(r.priceTop),Number.isFinite(r.priceBottom)&&g.push(r.priceBottom),_.set(o,g)}for(let r=0;r<e.length;r++){const o=e[r],g=oe(o),F=Ne(r),N=o.lineColor??o.color??F.line;let E,J;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)E=o.topColor,J=o.bottomColor;else if(o.topColor){const S=G.generateColorsFromBase(N);E=o.topColor,J=S.bottomColor}else if(o.bottomColor)E=G.generateColorsFromBase(N).topColor,J=o.bottomColor;else{const S=G.generateColorsFromBase(N);E=S.topColor,J=S.bottomColor}else E=o.topColor||F.top,J=o.bottomColor||F.bottom;if(o.data.length===0){const S=V.current.get(g);S&&(t.removeSeries(S),V.current.delete(g));continue}const pe=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,ce=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,ue=pe<0,Q=o.data.some(S=>S.value===0),de=!ue&&Q,fe=He.pickMinMove(ce-pe),he=A?o.priceScaleId??(L===0?"left":"right"):Z||!v||L===0?"right":`scale-${L}`;v&&k.push({priceScaleId:he||"right",seriesIndex:L});const we=(Z||!v)&&i!==void 0&&typeof i=="number",st=_.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:de&&R.priceRange.minValue>=0?0:void 0,me=ae.current>0?ae.current:j.current?.clientHeight??0;if(me>0){const O=He.niceAxisRange({min:R.priceRange.minValue,max:R.priceRange.maxValue,floor:se,scaleHeightPx:me,fontSizePx:D.AXIS_FONT_SIZE,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,minMove:fe,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=y.get(o.label)??d[0],$e=Ke.formatter,lt=Ke.tickmarksFormatter,Re={lineColor:N,topColor:E,bottomColor:J,priceScaleId:he,...o.seriesType==="line"&&{lineStyle:o.lineStyle??H.LineStyle.Solid},priceFormat:{type:"custom",minMove:fe,formatter:we&&typeof i=="number"?S=>$e(S<i?i:S):$e,tickmarksFormatter:lt},autoscaleInfoProvider:at},Oe=o.seriesType==="line";let z=V.current.get(g);const ie=o.data.map(S=>({...S,time:S.time}));if(U!==void 0&&ie.length>0&&Number(ie[0].time)>U){const S=Number(ie[0].time),R=S-U,se=86400,me=R>180*se?7*se:R>30*se?se:6*3600,O=[];for(let Pe=U;Pe<S;Pe+=me)O.push({time:Pe});ie.unshift(...O)}z&&z.seriesType()!==(Oe?"Line":"Area")&&(t.removeSeries(z),V.current.delete(g),z=void 0),z?(z.applyOptions(Re),z.setData(ie)):(Oe?z=t.addSeries(H.LineSeries,{...m,...Re}):z=t.addSeries(H.AreaSeries,{...m,...Re}),z.setData(ie),V.current.set(g,z)),L++}if(A)try{const r=t.priceScale("left"),o=t.priceScale("right"),g={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...C?.rightPriceScale};r?.applyOptions(g),o?.applyOptions(g)}catch{}else if(v&&k.length>0)for(const r of k)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,...C?.rightPriceScale})}catch{}if(i!==void 0&&!T&&(Z||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),le.length>0){const r=le.map(o=>Number(o.time)).filter(o=>Number.isFinite(o));if(r.length>0){const o=Math.min(...r),g=U!==void 0?Math.min(U,o):o,F=Math.max(...r);if(Number(g)<=Number(F)){const N=()=>{const E=t.timeScale(),J=A&&!T,pe=A?!T:!q,ce=!J,ue=!pe;if(E.applyOptions({fixLeftEdge:!ce,fixRightEdge:!ue}),!ce&&!ue)return;const Q=E.getVisibleLogicalRange(),de=E.width();if(!Q||!(de>0))return;const fe=Q.to-Q.from;if(!(fe>0))return;const he=D.AXIS_TIME_EDGE_PADDING_PX*fe/de;E.setVisibleLogicalRange({from:ce?Q.from-he:Q.from,to:ue?Q.to+he:Q.to})};try{t.timeScale().setVisibleRange({from:g,to:F}),N()}catch{try{t.timeScale().fitContent(),N()}catch{}}}}}ke.current&&(ke.current=!1),C&&t.applyOptions(C);const $=new Map;for(const r of e)r.data.length>0&&$.set(r.label,r.data[r.data.length-1]);ye($.size>0?$:void 0)},[ee,e,le,u,b,T,Z,A,Ve,Ie,Ee,De,U,M,X,C]),p.useEffect(()=>{const t=B.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:h=i,seriesData:d,point:y}=c||{},w=e[0],v=w?V.current.get(oe(w)):void 0;if(!y||!h){const W=new Map;for(const m of e)m.data.length>0&&W.set(m.label,m.data[m.data.length-1]);if(ye(W.size>0?W:void 0),l||Z||ve)Y(null);else if(v&&i){const m=e[0];if(m&&m.data.length>0){const L=t.timeScale().timeToCoordinate(i),K=m.data[m.data.length-1].value,_=v.priceToCoordinate(K);L!==null&&_!==null&&Y({x:L,y:_})}}return}const q=new Map;let I,te=v;for(let W=0;W<e.length;W++){const m=e[W],k=V.current.get(oe(m));if(!k)continue;const L=d?.get(k),K=L&&"value"in L?L.value:void 0;let _;if(K!==void 0)_=K;else if(l){const $=Number(h),r=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;$<r?_=Number.NaN:_=m.data[m.data.length-1]?.value??0}else{const $=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;if(Number(h)<$)continue;_=Je(m.data,Number(h))}Number.isNaN(_)||(I===void 0&&(I=_,te=k),q.set(m.label,{value:_,time:h}))}if(ye(q),I!==void 0&&te){const m=t.timeScale().timeToCoordinate(h),k=te.priceToCoordinate(I);if(m!==null&&k!==null){const L=j.current;if(L){const K=L.querySelector(".LightweightChart");if(K){const _=K.getBoundingClientRect(),$=L.getBoundingClientRect(),r=m+(_.left-$.left),o=k+(_.top-$.top);Y({x:r,y:o})}else Y({x:m,y:k})}else Y({x:m,y:k})}else Y(null)}else Y(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!l&&!Z&&!ve&&requestAnimationFrame(()=>{const c=e[0],h=c?V.current.get(oe(c)):void 0;if(h&&i&&c.data.length>0){const y=t.timeScale().timeToCoordinate(i),w=c.data[c.data.length-1].value,v=h.priceToCoordinate(w);y!==null&&v!==null&&Y({x:y,y:v})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,Z,T,ve]),p.useEffect(()=>{const t=B.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 h=Number(c.from),d=Number(c.to);for(const y of s){const w=[];for(const v of e)if(y.labels.has(v.label))for(const q of v.data){const I=Number(q.time);I>=h&&I<=d&&w.push(q.value)}w.length>0&&y.updateVisibleRange(w)}};return l.subscribeVisibleLogicalRangeChange(i),()=>{l.unsubscribeVisibleLogicalRangeChange(i)}},[e]),p.useEffect(()=>{const t=B.current,l=Array.from(V.current.values()),i=[];if(t&&l.length>0&&P){const s=D.getDefaultVerticalLine(),c=l[0];for(const h of P){const d={...s,...h.options||{}};d.color&&(d.color=G.resolveCSSColor(d.color,d.color));const y=new ht.VertLine(t,c,h.xCoordinate,d);c.attachPrimitive(y),i.push(y)}}return()=>{if(l.length>0){const s=l[0];for(const c of i)try{s.detachPrimitive(c)}catch{}}}},[P,e,ee]),p.useEffect(()=>{const t=[],l=[];if(M&&M.length>0){const i=G.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of M){if(!Number.isFinite(s.price))continue;const c=Ze(V.current,e,s.seriesLabel);if(!c)continue;const h=s.color?G.resolveCSSColor(s.color,s.color):i,d=s.lineWidth??1,y=s.lineStyle??H.LineStyle.Dashed,w=c.createPriceLine({price:s.price,color:h,lineWidth:d,lineStyle:y,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:c,line:w});const v=new vt(c,s.price,h,d,y);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{}}},[M,e,ee]),p.useEffect(()=>{const t=[];if(X&&X.length>0){const l="rgba(239, 68, 68, 0.12)";for(const i of X){const s=Ze(V.current,e,i.seriesLabel);if(!s)continue;const c=i.color?G.resolveCSSColor(i.color,l):l,h=new mt(s,i.priceTop,i.priceBottom,c);s.attachPrimitive(h),t.push({series:s,zone:h})}}return()=>{for(const{series:l,zone:i}of t)try{l.detachPrimitive(i)}catch{}}},[X,e,ee]),p.useEffect(()=>{const t=B.current;if(!t||!P?.length){Ge([]);return}const l=()=>{const c=t.timeScale(),h=P.map(d=>c.timeToCoordinate(d.xCoordinate)??null);Ge(h),j.current&&Xe(j.current.clientWidth)};l();const i=t.timeScale(),s=()=>{l()};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[P,e,ee]),p.useLayoutEffect(()=>{nt(t=>{const l={};let i=!1;for(const[s,c]of qe.current){if(!c)continue;const h=c.offsetWidth;l[s]=h,t[s]!==h&&(i=!0)}return Object.keys(t).length!==Object.keys(l).length&&(i=!0),i?l:t})});const ge=e.length===1,We=Te.useMemo(()=>{if(ge&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[ge,e]);return x.jsxs("div",{ref:j,className:re.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[Ce!=null&&Ce!==!1&&ge?x.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:x.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Ce})}):et&&ge&&We&&x.jsx(ut.GraphCurrentValue,{point:We,xMeasureUnit:u,yMeasureUnit:b,decimals:Se}),je&&Fe&&x.jsx(ft.GraphTooltip,{points:je,xMeasureUnit:u,yMeasureUnit:b,series:e,position:Fe,containerRef:j,decimals:Se}),a&&x.jsx(Ue,{series:e,onUnselect:f}),P&&P.length>0&&ze.length===P.length&&x.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:h}=Qe(s,b,Se),d=s.tooltipText??"";if(!(c||h||d))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",v=s.labelTextColor??"hsl(var(--foreground))",q=`${String(t.xCoordinate)}-${c}-${d}`,I=Ye(i,ot,rt[l]);return x.jsxs("div",{ref:te=>{qe.current.set(l,te)},className:re.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",d&&"pointer-events-auto cursor-default"),style:{...I,backgroundColor:w,color:v},children:[c&&x.jsx("span",{className:"block",children:c}),h&&x.jsx("span",{className:re.cn("block",c&&"mt-0.5"),children:h}),d&&x.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:d})]},q)})}),x.jsx("div",{ref:_e,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ue({series:e,onUnselect:n,inline:a=!1}){const f=e.every(u=>u.data.length===0);return x.jsx("div",{className:re.cn("flex flex-wrap",a?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:e.map((u,b)=>{const C=Ne(b),P=(u.lineColor??u.color)||C.line,M=!f&&u.data.length===0;return x.jsxs("div",{className:re.cn("flex items-center gap-1.5",!a&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",M&&"opacity-50"),children:[x.jsx("div",{className:re.cn(a?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:P}}),x.jsxs("span",{className:re.cn("font-medium text-foreground",a?"text-sm":"text-[10px] sm:text-xs"),children:[u.label,M&&" (no data)"]}),n&&x.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),n(u.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 ${u.label}`,children:x.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:[x.jsx("title",{children:"Close"}),x.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),x.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},u.id??u.label)})})}exports.DEFAULT_SERIES_COLORS=be;exports.Graph=_t;exports.GraphLegend=Ue;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=Le;exports.getSeriesColorPalette=Ne;exports.getStepForwardValue=Je;exports.getVerticalLineLabelStyle=Ye;exports.getVerticalLineTooltipContent=Qe;exports.seriesIdentity=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),H=require("lightweight-charts"),p=require("react"),ct=require("../../hooks/use-media-query.cjs"),re=require("../../utils/cn.cjs"),G=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 f=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,f.get?f:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const Te=gt(p);function oe(e){return e.id??e.label}function Ze(e,n,a){if(!a)return e.values().next().value;const f=e.get(a);if(f)return f;const c=n.find(b=>b.id===a||b.label===a);return c?e.get(oe(c)):void 0}class pt{_yTop;_yBottom;_color;constructor(n,a,f){this._yTop=n,this._yBottom=a,this._color=f}draw(n){n.useBitmapCoordinateSpace(a=>{const f=a.context,c=a.verticalPixelRatio,b=this._yTop===null?0:this._yTop*c,C=this._yBottom===null?a.bitmapSize.height:this._yBottom*c,P=Math.min(b,C),M=Math.max(b,C);f.fillStyle=this._color,f.fillRect(0,P,a.bitmapSize.width,M-P)})}}class dt{_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 pt(this._yTop,this._yBottom,this._source.color)}}class mt{series;priceTop;priceBottom;color;_paneViews;constructor(n,a,f,c){this.series=n,this.priceTop=a,this.priceBottom=f,this.color=c,this._paneViews=[new dt(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,f,c){this._y=n,this._color=a,this._lineWidth=f,this._lineStyle=c}draw(n){n.useBitmapCoordinateSpace(a=>{if(this._y===null)return;const f=a.context,c=a.verticalPixelRatio,b=Math.max(1,Math.round(this._lineWidth*c)),C=Math.round(this._y*c);f.save(),f.strokeStyle=this._color,f.lineWidth=b,f.setLineDash(bt(this._lineStyle,b)),f.beginPath(),f.moveTo(0,C),f.lineTo(a.bitmapSize.width,C),f.stroke(),f.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,f,c,b){this.series=n,this.price=a,this.color=f,this.lineWidth=c,this.lineStyle=b,this._paneViews=[new Ct(this)]}updateAllViews(){for(const n of this._paneViews)n.update()}paneViews(){return this._paneViews}}function Qe(e,n,a){const f=e.labelText??"",c=e.value,b=c===void 0?"":typeof c=="number"?n==="$"?`$${ne.formatExactValue(c,void 0,a)}`:n==="%"?`${ne.formatExactValue(c,void 0,a)}%`:ne.formatExactValue(c,n!=="none"&&n!=="%"&&n!=="$"&&!ne.isRatioUnit(n)?n:void 0,a):String(c);return{labelText:f,valueStr:b}}const Le=4;function Ye(e,n,a){const f={left:e,transform:"translateX(-50%)"};if(n<=0||!a||a<=0)return f;const c=a/2,b=Le+c,C=n-Le-c;return C<b?{left:n/2,transform:"translateX(-50%)"}:{left:Math.min(Math.max(e,b),C),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 be=[{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<be.length)return be[e];const a=(e-be.length)*vt%360,f=G.hslToHex(a,70,50),{topColor:c,bottomColor:b}=G.generateColorsFromBase(f);return{line:f,top:c,bottom:b}}function _t({series:e,className:n,showLegend:a=!1,onUnselectSeries:f,xMeasureUnit:c="time",yMeasureUnit:b="token",optionsOverrides:C,verticalLineOptions:P,priceLineOptions:M,zoneOptions:X,currentValueDecimals:Se,useSharedPriceScale:Z=!1,dualYAxis:A=!1,defaultVisiblePriceScaleId:Ve="right",leftPriceScaleTitle:Ee,rightPriceScaleTitle:yt,showCurrentValue:et=!0,graphTitle:Ce,yScaleMin:Ie,yScaleMinMultiple:De,visibleTimeFrom:U,disableZoom:Me=!1,hideDefaultTooltip:xe=!1}){const B=p.useRef(null),E=p.useRef(new Map),ve=p.useRef(!1),ke=p.useRef(!0),Ae=p.useRef([]),ae=p.useRef(0),j=p.useRef(null),_e=p.useRef(null),Be=p.useRef(null),T=ct.useIsMobile(),le=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]),[je,ye]=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,Y]=p.useState(null),[ze,Ge]=p.useState([]),[ot,Xe]=p.useState(0),qe=p.useRef(new Map),[rt,nt]=p.useState({}),[ee,it]=p.useState(0);p.useEffect(()=>{const t=()=>{try{if(j.current&&Xe(j.current.clientWidth),B.current&&j.current){const s=j.current.clientWidth,u=j.current.clientHeight;B.current.resize(s,u);try{ae.current=B.current.paneSize().height}catch{}}}catch{}},l=j.current,i=l?new ResizeObserver(t):null;return Be.current=i,l&&i?.observe(l),()=>{l&&i?.unobserve(l),i?.disconnect(),Be.current=null}},[]),p.useEffect(()=>{if(!_e.current||ve.current)return;const t=D.getDefaultOptions(),l=G.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)"),i=H.createChart(_e.current,{...t,leftPriceScale:{...t.leftPriceScale||{},visible:!1,textColor:l},rightPriceScale:{...t.rightPriceScale||{},visible:!T,textColor:l},...T&&{crosshair:{...t.crosshair,mode:H.CrosshairMode.Magnet}}});B.current=i,ve.current=!0;try{ae.current=i.paneSize().height}catch{ae.current=0}return it(s=>s+1),()=>{i.remove(),B.current=null,ve.current=!1,E.current.clear()}},[T]),p.useEffect(()=>{const t=B.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}})},[ee,Me]),p.useEffect(()=>{const t=B.current;!t||!C||t.applyOptions(C)},[ee,C]),p.useEffect(()=>{const t=B.current;if(!t||e.length===0)return;const i=e.filter(r=>r.data.length>0).length<=1?Ie:De,s=c==="time"?ne.getXFormatters(c,le):ne.getXFormatters(c),u=new Map;{let r=0;for(const o of e)o.data.length!==0&&(u.set(o.label,o.priceScaleId??(r===0?"left":"right")),r++)}const h=(r,o,g)=>{const{formatter:F,tickmarksFormatter:N,updateVisibleRange:V}=ne.createAdaptiveYAxisFormatter(r,o,{yScaleMin:i});return{formatter:F,tickmarksFormatter:N,updateVisibleRange:V,labels:g}},d=[];if(A)for(const r of["left","right"]){const o=new Set,g=[];let F=b;for(const N of e)if(N.data.length!==0&&u.get(N.label)===r){o.size===0&&N.yMeasureUnit&&(F=N.yMeasureUnit),o.add(N.label);for(const V of N.data)g.push(V.value)}o.size>0&&d.push(h(g,F,o))}else{const r=le.map(g=>g.value),o=new Set(e.filter(g=>g.data.length>0).map(g=>g.label));d.push(h(r,b,o))}Ae.current=d;const y=new Map;for(const r of d)for(const o of r.labels)y.set(o,r);const w=D.getDefaultOptions();t.applyOptions({localization:{...w.localization||{},timeFormatter:r=>s.timeFormatter(parseFloat(r),void 0)},timeScale:{...w.timeScale||{},...C?.timeScale,tickMarkFormatter:s.tickMarkFormatter,minBarSpacing:0}});const x=!A&&e.length>1&&!Z,q=A?T:e.length>1&&!Z||T,I=G.resolveCSSColor("hsl(var(--muted-foreground))","rgb(163, 163, 163)");t.applyOptions({...A&&{defaultVisiblePriceScaleId:Ve},leftPriceScale:{...w.leftPriceScale||{},...C?.leftPriceScale,visible:A&&!T,textColor:I,...A&&Ee&&{}},rightPriceScale:{...w.rightPriceScale||{},...C?.rightPriceScale,visible:A?!T:!q,textColor:I}});const te=new Set(E.current.keys()),W=new Set(e.map(oe));for(const r of te)if(!W.has(r)){const o=E.current.get(r);o&&(t.removeSeries(o),E.current.delete(r))}const m=D.getDefaultSeries(),k=[];let L=0;const K=e.find(r=>r.data.length>0),_=new Map;if(M&&M.length>0)for(const r of M){if(!Number.isFinite(r.price))continue;const o=r.seriesLabel??K?.label;if(!o)continue;const g=_.get(o)??[];g.push(r.price),_.set(o,g)}if(X&&X.length>0)for(const r of X){const o=r.seriesLabel??K?.label;if(!o)continue;const g=_.get(o)??[];Number.isFinite(r.priceTop)&&g.push(r.priceTop),Number.isFinite(r.priceBottom)&&g.push(r.priceBottom),_.set(o,g)}for(let r=0;r<e.length;r++){const o=e[r],g=oe(o),F=Ne(r),N=o.lineColor??o.color??F.line;let V,J;if(o.lineColor??o.color)if(o.topColor&&o.bottomColor)V=o.topColor,J=o.bottomColor;else if(o.topColor){const S=G.generateColorsFromBase(N);V=o.topColor,J=S.bottomColor}else if(o.bottomColor)V=G.generateColorsFromBase(N).topColor,J=o.bottomColor;else{const S=G.generateColorsFromBase(N);V=S.topColor,J=S.bottomColor}else V=o.topColor||F.top,J=o.bottomColor||F.bottom;if(o.data.length===0){const S=E.current.get(g);S&&(t.removeSeries(S),E.current.delete(g));continue}const pe=o.data.length>0?Math.min(...o.data.map(S=>S.value)):0,ce=o.data.length>0?Math.max(...o.data.map(S=>S.value)):0,ue=pe<0,Q=o.data.some(S=>S.value===0),de=!ue&&Q,fe=He.pickMinMove(ce-pe),he=A?o.priceScaleId??(L===0?"left":"right"):Z||!x||L===0?"right":`scale-${L}`;x&&k.push({priceScaleId:he||"right",seriesIndex:L});const we=(Z||!x)&&i!==void 0&&typeof i=="number",st=_.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:de&&R.priceRange.minValue>=0?0:void 0,me=ae.current>0?ae.current:j.current?.clientHeight??0;if(me>0){const O=He.niceAxisRange({min:R.priceRange.minValue,max:R.priceRange.maxValue,floor:se,scaleHeightPx:me,fontSizePx:D.AXIS_FONT_SIZE,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,minMove:fe,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=y.get(o.label)??d[0],$e=Ke.formatter,lt=Ke.tickmarksFormatter,Re={lineColor:N,topColor:V,bottomColor:J,priceScaleId:he,...o.seriesType==="line"&&{lineStyle:o.lineStyle??H.LineStyle.Solid},priceFormat:{type:"custom",minMove:fe,formatter:we&&typeof i=="number"?S=>$e(S<i?i:S):$e,tickmarksFormatter:lt},autoscaleInfoProvider:at},Oe=o.seriesType==="line";let z=E.current.get(g);const ie=o.data.map(S=>({...S,time:S.time}));if(U!==void 0&&ie.length>0&&Number(ie[0].time)>U){const S=Number(ie[0].time),R=S-U,se=86400,me=R>180*se?7*se:R>30*se?se:6*3600,O=[];for(let Pe=U;Pe<S;Pe+=me)O.push({time:Pe});ie.unshift(...O)}z&&z.seriesType()!==(Oe?"Line":"Area")&&(t.removeSeries(z),E.current.delete(g),z=void 0),z?(z.applyOptions(Re),z.setData(ie)):(Oe?z=t.addSeries(H.LineSeries,{...m,...Re}):z=t.addSeries(H.AreaSeries,{...m,...Re}),z.setData(ie),E.current.set(g,z)),L++}if(A)try{const r=t.priceScale("left"),o=t.priceScale("right"),g={visible:!T,autoScale:!0,scaleMargins:{top:0,bottom:0},alignLabels:!0,entireTextOnly:!1,tickMarkDensity:D.AXIS_TICK_MARK_DENSITY,textColor:I,...C?.rightPriceScale};r?.applyOptions(g),o?.applyOptions(g)}catch{}else if(x&&k.length>0)for(const r of k)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(!x)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,...C?.rightPriceScale})}catch{}if(i!==void 0&&!T&&(Z||!x)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),le.length>0){const r=le.map(o=>Number(o.time)).filter(o=>Number.isFinite(o));if(r.length>0){const o=Math.min(...r),g=U!==void 0?Math.min(U,o):o,F=Math.max(...r);if(Number(g)<=Number(F)){const N=()=>{const V=t.timeScale();if(c!=="time"){V.applyOptions({fixLeftEdge:!0,fixRightEdge:!0});return}const J=A&&!T,pe=A?!T:!q,ce=!J,ue=!pe;if(V.applyOptions({fixLeftEdge:!ce,fixRightEdge:!ue}),!ce&&!ue)return;const Q=V.getVisibleLogicalRange(),de=V.width();if(!Q||!(de>0))return;const fe=Q.to-Q.from;if(!(fe>0))return;const he=D.AXIS_TIME_EDGE_PADDING_PX*fe/de;V.setVisibleLogicalRange({from:ce?Q.from-he:Q.from,to:ue?Q.to+he:Q.to})};try{t.timeScale().setVisibleRange({from:g,to:F}),N()}catch{try{t.timeScale().fitContent(),N()}catch{}}}}}ke.current&&(ke.current=!1),C&&t.applyOptions(C);const $=new Map;for(const r of e)r.data.length>0&&$.set(r.label,r.data[r.data.length-1]);ye($.size>0?$:void 0)},[ee,e,le,c,b,T,Z,A,Ve,Ee,Ie,De,U,M,X,C]),p.useEffect(()=>{const t=B.current;if(!t||e.length===0)return;const l=e.length===1;let i;for(const u of e)if(u.data.length>0){i=u.data[u.data.length-1].time;break}if(!i)return;const s=u=>{const{time:h=i,seriesData:d,point:y}=u||{},w=e[0],x=w?E.current.get(oe(w)):void 0;if(!y||!h){const W=new Map;for(const m of e)m.data.length>0&&W.set(m.label,m.data[m.data.length-1]);if(ye(W.size>0?W:void 0),l||Z||xe)Y(null);else if(x&&i){const m=e[0];if(m&&m.data.length>0){const L=t.timeScale().timeToCoordinate(i),K=m.data[m.data.length-1].value,_=x.priceToCoordinate(K);L!==null&&_!==null&&Y({x:L,y:_})}}return}const q=new Map;let I,te=x;for(let W=0;W<e.length;W++){const m=e[W],k=E.current.get(oe(m));if(!k)continue;const L=d?.get(k),K=L&&"value"in L?L.value:void 0;let _;if(K!==void 0)_=K;else if(l){const $=Number(h),r=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;$<r?_=Number.NaN:_=m.data[m.data.length-1]?.value??0}else{const $=m.data.length>0?Number(m.data[0].time):Number.POSITIVE_INFINITY;if(Number(h)<$)continue;_=Je(m.data,Number(h))}Number.isNaN(_)||(I===void 0&&(I=_,te=k),q.set(m.label,{value:_,time:h}))}if(ye(q),I!==void 0&&te){const m=t.timeScale().timeToCoordinate(h),k=te.priceToCoordinate(I);if(m!==null&&k!==null){const L=j.current;if(L){const K=L.querySelector(".LightweightChart");if(K){const _=K.getBoundingClientRect(),$=L.getBoundingClientRect(),r=m+(_.left-$.left),o=k+(_.top-$.top);Y({x:r,y:o})}else Y({x:m,y:k})}else Y({x:m,y:k})}else Y(null)}else Y(null)};return t.subscribeCrosshairMove(s),T&&t.subscribeClick(s),!l&&!Z&&!xe&&requestAnimationFrame(()=>{const u=e[0],h=u?E.current.get(oe(u)):void 0;if(h&&i&&u.data.length>0){const y=t.timeScale().timeToCoordinate(i),w=u.data[u.data.length-1].value,x=h.priceToCoordinate(w);y!==null&&x!==null&&Y({x:y,y:x})}}),()=>{t.unsubscribeCrosshairMove(s),T&&t.unsubscribeClick(s)}},[e,Z,T,xe]),p.useEffect(()=>{const t=B.current;if(!t||e.length===0)return;const l=t.timeScale(),i=()=>{const s=Ae.current;if(s.length===0)return;const u=l.getVisibleRange();if(!u)return;const h=Number(u.from),d=Number(u.to);for(const y of s){const w=[];for(const x of e)if(y.labels.has(x.label))for(const q of x.data){const I=Number(q.time);I>=h&&I<=d&&w.push(q.value)}w.length>0&&y.updateVisibleRange(w)}};return l.subscribeVisibleLogicalRangeChange(i),()=>{l.unsubscribeVisibleLogicalRangeChange(i)}},[e]),p.useEffect(()=>{const t=B.current,l=Array.from(E.current.values()),i=[];if(t&&l.length>0&&P){const s=D.getDefaultVerticalLine(),u=l[0];for(const h of P){const d={...s,...h.options||{}};d.color&&(d.color=G.resolveCSSColor(d.color,d.color));const y=new ht.VertLine(t,u,h.xCoordinate,d);u.attachPrimitive(y),i.push(y)}}return()=>{if(l.length>0){const s=l[0];for(const u of i)try{s.detachPrimitive(u)}catch{}}}},[P,e,ee]),p.useEffect(()=>{const t=[],l=[];if(M&&M.length>0){const i=G.resolveCSSColor("hsl(var(--destructive))","rgb(239, 68, 68)");for(const s of M){if(!Number.isFinite(s.price))continue;const u=Ze(E.current,e,s.seriesLabel);if(!u)continue;const h=s.color?G.resolveCSSColor(s.color,s.color):i,d=s.lineWidth??1,y=s.lineStyle??H.LineStyle.Dashed,w=u.createPriceLine({price:s.price,color:h,lineWidth:d,lineStyle:y,axisLabelVisible:s.axisLabelVisible??!0,title:s.title??""});t.push({series:u,line:w});const x=new xt(u,s.price,h,d,y);u.attachPrimitive(x),l.push({series:u,primitive:x})}}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{}}},[M,e,ee]),p.useEffect(()=>{const t=[];if(X&&X.length>0){const l="rgba(239, 68, 68, 0.12)";for(const i of X){const s=Ze(E.current,e,i.seriesLabel);if(!s)continue;const u=i.color?G.resolveCSSColor(i.color,l):l,h=new mt(s,i.priceTop,i.priceBottom,u);s.attachPrimitive(h),t.push({series:s,zone:h})}}return()=>{for(const{series:l,zone:i}of t)try{l.detachPrimitive(i)}catch{}}},[X,e,ee]),p.useEffect(()=>{const t=B.current;if(!t||!P?.length){Ge([]);return}const l=()=>{const u=t.timeScale(),h=P.map(d=>u.timeToCoordinate(d.xCoordinate)??null);Ge(h),j.current&&Xe(j.current.clientWidth)};l();const i=t.timeScale(),s=()=>{l()};return i.subscribeVisibleLogicalRangeChange(s),()=>{i.unsubscribeVisibleLogicalRangeChange(s)}},[P,e,ee]),p.useLayoutEffect(()=>{nt(t=>{const l={};let i=!1;for(const[s,u]of qe.current){if(!u)continue;const h=u.offsetWidth;l[s]=h,t[s]!==h&&(i=!0)}return Object.keys(t).length!==Object.keys(l).length&&(i=!0),i?l:t})});const ge=e.length===1,We=Te.useMemo(()=>{if(ge&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[ge,e]);return v.jsxs("div",{ref:j,className:re.cn("relative z-[1] w-full h-full overflow-hidden p-0",n),children:[Ce!=null&&Ce!==!1&&ge?v.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:v.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Ce})}):et&&ge&&We&&v.jsx(ut.GraphCurrentValue,{point:We,xMeasureUnit:c,yMeasureUnit:b,decimals:Se}),je&&Fe&&v.jsx(ft.GraphTooltip,{points:je,xMeasureUnit:c,yMeasureUnit:b,series:e,position:Fe,containerRef:j,decimals:Se}),a&&v.jsx(Ue,{series:e,onUnselect:f}),P&&P.length>0&&ze.length===P.length&&v.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:u,valueStr:h}=Qe(s,b,Se),d=s.tooltipText??"";if(!(u||h||d))return null;const w=s.labelBackgroundColor??s.color??"hsl(var(--background))",x=s.labelTextColor??"hsl(var(--foreground))",q=`${String(t.xCoordinate)}-${u}-${d}`,I=Ye(i,ot,rt[l]);return v.jsxs("div",{ref:te=>{qe.current.set(l,te)},className:re.cn("group absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",d&&"pointer-events-auto cursor-default"),style:{...I,backgroundColor:w,color:x},children:[u&&v.jsx("span",{className:"block",children:u}),h&&v.jsx("span",{className:re.cn("block",u&&"mt-0.5"),children:h}),d&&v.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:d})]},q)})}),v.jsx("div",{ref:_e,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ue({series:e,onUnselect:n,inline:a=!1}){const f=e.every(c=>c.data.length===0);return v.jsx("div",{className:re.cn("flex flex-wrap",a?"items-center justify-center gap-6":"absolute top-0 left-2 z-[10] gap-2"),children:e.map((c,b)=>{const C=Ne(b),P=(c.lineColor??c.color)||C.line,M=!f&&c.data.length===0;return v.jsxs("div",{className:re.cn("flex items-center gap-1.5",!a&&"px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",M&&"opacity-50"),children:[v.jsx("div",{className:re.cn(a?"size-2 rounded-full":"h-3 w-3 rounded-sm"),style:{backgroundColor:P}}),v.jsxs("span",{className:re.cn("font-medium text-foreground",a?"text-sm":"text-[10px] sm:text-xs"),children:[c.label,M&&" (no data)"]}),n&&v.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),n(c.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 ${c.label}`,children:v.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:[v.jsx("title",{children:"Close"}),v.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),v.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},c.id??c.label)})})}exports.DEFAULT_SERIES_COLORS=be;exports.Graph=_t;exports.GraphLegend=Ue;exports.VERTICAL_LINE_LABEL_EDGE_PADDING=Le;exports.getSeriesColorPalette=Ne;exports.getStepForwardValue=Je;exports.getVerticalLineLabelStyle=Ye;exports.getVerticalLineTooltipContent=Qe;exports.seriesIdentity=oe;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { jsxs as ge, jsx as
|
|
1
|
+
import { jsxs as ge, jsx as V } from "react/jsx-runtime";
|
|
2
2
|
import { createChart as ht, CrosshairMode as gt, LineStyle as ae, LineSeries as mt, AreaSeries as pt } from "lightweight-charts";
|
|
3
3
|
import * as Ve from "react";
|
|
4
4
|
import { useRef as K, useState as re, useEffect as A, useLayoutEffect as dt } from "react";
|
|
5
5
|
import { useIsMobile as bt } from "../../hooks/use-media-query.js";
|
|
6
6
|
import { cn as ee } from "../../utils/cn.js";
|
|
7
7
|
import { resolveCSSColor as ne, generateColorsFromBase as ve, hslToHex as St } from "../../utils/colors.js";
|
|
8
|
-
import { getDefaultOptions as
|
|
8
|
+
import { getDefaultOptions as Je, getDefaultSeries as vt, AXIS_TICK_MARK_DENSITY as Se, getDefaultVerticalLine as Ct, AXIS_FONT_SIZE as yt, AXIS_EDGE_LABEL_PADDING_PX as Qe, AXIS_TOP_LABEL_PADDING_PX as Ye, AXIS_TIME_EDGE_PADDING_PX as xt } from "./default-config.js";
|
|
9
9
|
import { getXFormatters as Ue, formatExactValue as Le, isRatioUnit as _t, createAdaptiveYAxisFormatter as wt } from "./formatters.js";
|
|
10
10
|
import { GraphCurrentValue as Pt } from "./graph-current-value.js";
|
|
11
|
-
import { GraphTooltip as
|
|
12
|
-
import { VertLine as
|
|
11
|
+
import { GraphTooltip as Rt } from "./graph-tooltip.js";
|
|
12
|
+
import { VertLine as Tt } from "./plugins/vertical-line.js";
|
|
13
13
|
import { pickMinMove as Nt, niceAxisRange as Vt } from "./y-axis-scale.js";
|
|
14
14
|
function ie(e) {
|
|
15
15
|
return e.id ?? e.label;
|
|
@@ -19,8 +19,8 @@ function et(e, i, u) {
|
|
|
19
19
|
return e.values().next().value;
|
|
20
20
|
const f = e.get(u);
|
|
21
21
|
if (f) return f;
|
|
22
|
-
const
|
|
23
|
-
return
|
|
22
|
+
const s = i.find((d) => d.id === u || d.label === u);
|
|
23
|
+
return s ? e.get(ie(s)) : void 0;
|
|
24
24
|
}
|
|
25
25
|
class Lt {
|
|
26
26
|
_yTop;
|
|
@@ -31,7 +31,7 @@ class Lt {
|
|
|
31
31
|
}
|
|
32
32
|
draw(i) {
|
|
33
33
|
i.useBitmapCoordinateSpace((u) => {
|
|
34
|
-
const f = u.context,
|
|
34
|
+
const f = u.context, s = u.verticalPixelRatio, d = this._yTop === null ? 0 : this._yTop * s, S = this._yBottom === null ? u.bitmapSize.height : this._yBottom * s, w = Math.min(d, S), k = Math.max(d, S);
|
|
35
35
|
f.fillStyle = this._color, f.fillRect(0, w, u.bitmapSize.width, k - w);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -61,8 +61,8 @@ class kt {
|
|
|
61
61
|
priceBottom;
|
|
62
62
|
color;
|
|
63
63
|
_paneViews;
|
|
64
|
-
constructor(i, u, f,
|
|
65
|
-
this.series = i, this.priceTop = u, this.priceBottom = f, this.color =
|
|
64
|
+
constructor(i, u, f, s) {
|
|
65
|
+
this.series = i, this.priceTop = u, this.priceBottom = f, this.color = s, this._paneViews = [new Mt(this)];
|
|
66
66
|
}
|
|
67
67
|
updateAllViews() {
|
|
68
68
|
for (const i of this._paneViews) i.update();
|
|
@@ -90,13 +90,13 @@ class Dt {
|
|
|
90
90
|
_color;
|
|
91
91
|
_lineWidth;
|
|
92
92
|
_lineStyle;
|
|
93
|
-
constructor(i, u, f,
|
|
94
|
-
this._y = i, this._color = u, this._lineWidth = f, this._lineStyle =
|
|
93
|
+
constructor(i, u, f, s) {
|
|
94
|
+
this._y = i, this._color = u, this._lineWidth = f, this._lineStyle = s;
|
|
95
95
|
}
|
|
96
96
|
draw(i) {
|
|
97
97
|
i.useBitmapCoordinateSpace((u) => {
|
|
98
98
|
if (this._y === null) return;
|
|
99
|
-
const f = u.context,
|
|
99
|
+
const f = u.context, s = u.verticalPixelRatio, d = Math.max(1, Math.round(this._lineWidth * s)), S = Math.round(this._y * s);
|
|
100
100
|
f.save(), f.strokeStyle = this._color, f.lineWidth = d, f.setLineDash(It(this._lineStyle, d)), f.beginPath(), f.moveTo(0, S), f.lineTo(u.bitmapSize.width, S), f.stroke(), f.restore();
|
|
101
101
|
});
|
|
102
102
|
}
|
|
@@ -135,8 +135,8 @@ class Bt {
|
|
|
135
135
|
lineWidth;
|
|
136
136
|
lineStyle;
|
|
137
137
|
_paneViews;
|
|
138
|
-
constructor(i, u, f,
|
|
139
|
-
this.series = i, this.price = u, this.color = f, this.lineWidth =
|
|
138
|
+
constructor(i, u, f, s, d) {
|
|
139
|
+
this.series = i, this.price = u, this.color = f, this.lineWidth = s, this.lineStyle = d, this._paneViews = [new Et(this)];
|
|
140
140
|
}
|
|
141
141
|
updateAllViews() {
|
|
142
142
|
for (const i of this._paneViews) i.update();
|
|
@@ -146,11 +146,11 @@ class Bt {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
function Ft(e, i, u) {
|
|
149
|
-
const f = e.labelText ?? "",
|
|
150
|
-
|
|
149
|
+
const f = e.labelText ?? "", s = e.value, d = s === void 0 ? "" : typeof s == "number" ? i === "$" ? `$${Le(s, void 0, u)}` : i === "%" ? `${Le(s, void 0, u)}%` : Le(
|
|
150
|
+
s,
|
|
151
151
|
i !== "none" && i !== "%" && i !== "$" && !_t(i) ? i : void 0,
|
|
152
152
|
u
|
|
153
|
-
) : String(
|
|
153
|
+
) : String(s);
|
|
154
154
|
return { labelText: f, valueStr: d };
|
|
155
155
|
}
|
|
156
156
|
const tt = 4;
|
|
@@ -158,7 +158,7 @@ function zt(e, i, u) {
|
|
|
158
158
|
const f = { left: e, transform: "translateX(-50%)" };
|
|
159
159
|
if (i <= 0 || !u || u <= 0)
|
|
160
160
|
return f;
|
|
161
|
-
const
|
|
161
|
+
const s = u / 2, d = tt + s, S = i - tt - s;
|
|
162
162
|
return S < d ? { left: i / 2, transform: "translateX(-50%)" } : { left: Math.min(Math.max(e, d), S), transform: "translateX(-50%)" };
|
|
163
163
|
}
|
|
164
164
|
function At(e, i) {
|
|
@@ -286,15 +286,15 @@ const Me = [
|
|
|
286
286
|
function ot(e) {
|
|
287
287
|
if (e < Me.length)
|
|
288
288
|
return Me[e];
|
|
289
|
-
const u = (e - Me.length) * Gt % 360, f = St(u, 70, 50), { topColor:
|
|
290
|
-
return { line: f, top:
|
|
289
|
+
const u = (e - Me.length) * Gt % 360, f = St(u, 70, 50), { topColor: s, bottomColor: d } = ve(f);
|
|
290
|
+
return { line: f, top: s, bottom: d };
|
|
291
291
|
}
|
|
292
292
|
function oo({
|
|
293
293
|
series: e,
|
|
294
294
|
className: i,
|
|
295
295
|
showLegend: u = !1,
|
|
296
296
|
onUnselectSeries: f,
|
|
297
|
-
xMeasureUnit:
|
|
297
|
+
xMeasureUnit: s = "time",
|
|
298
298
|
yMeasureUnit: d = "token",
|
|
299
299
|
optionsOverrides: S,
|
|
300
300
|
verticalLineOptions: w,
|
|
@@ -314,7 +314,7 @@ function oo({
|
|
|
314
314
|
disableZoom: Be = !1,
|
|
315
315
|
hideDefaultTooltip: xe = !1
|
|
316
316
|
}) {
|
|
317
|
-
const E = K(null),
|
|
317
|
+
const E = K(null), L = K(/* @__PURE__ */ new Map()), _e = K(!1), Fe = K(!0), ze = K([]), le = K(0), B = K(null), we = K(null), Ae = K(null), P = bt(), se = Ve.useMemo(() => e.flatMap((t) => t.data), [e]), nt = Ve.useMemo(() => {
|
|
318
318
|
if (e.length > 0) {
|
|
319
319
|
const t = e[e.length - 1];
|
|
320
320
|
if (t.data.length > 0)
|
|
@@ -326,13 +326,13 @@ function oo({
|
|
|
326
326
|
for (const l of e)
|
|
327
327
|
l.data.length > 0 && t.set(l.label, l.data[l.data.length - 1]);
|
|
328
328
|
return t;
|
|
329
|
-
}), [We,
|
|
329
|
+
}), [We, O] = re(null), [Xe, $e] = re([]), [it, He] = re(0), je = K(/* @__PURE__ */ new Map()), [at, lt] = re({}), [Y, st] = re(0);
|
|
330
330
|
A(() => {
|
|
331
331
|
const t = () => {
|
|
332
332
|
try {
|
|
333
333
|
if (B.current && He(B.current.clientWidth), E.current && B.current) {
|
|
334
|
-
const a = B.current.clientWidth,
|
|
335
|
-
E.current.resize(a,
|
|
334
|
+
const a = B.current.clientWidth, c = B.current.clientHeight;
|
|
335
|
+
E.current.resize(a, c);
|
|
336
336
|
try {
|
|
337
337
|
le.current = E.current.paneSize().height;
|
|
338
338
|
} catch {
|
|
@@ -346,7 +346,7 @@ function oo({
|
|
|
346
346
|
};
|
|
347
347
|
}, []), A(() => {
|
|
348
348
|
if (!we.current || _e.current) return;
|
|
349
|
-
const t =
|
|
349
|
+
const t = Je(), l = ne(
|
|
350
350
|
"hsl(var(--muted-foreground))",
|
|
351
351
|
"rgb(163, 163, 163)"
|
|
352
352
|
), n = ht(we.current, {
|
|
@@ -375,7 +375,7 @@ function oo({
|
|
|
375
375
|
le.current = 0;
|
|
376
376
|
}
|
|
377
377
|
return st((a) => a + 1), () => {
|
|
378
|
-
n.remove(), E.current = null, _e.current = !1,
|
|
378
|
+
n.remove(), E.current = null, _e.current = !1, L.current.clear();
|
|
379
379
|
};
|
|
380
380
|
}, [P]), A(() => {
|
|
381
381
|
const t = E.current;
|
|
@@ -414,29 +414,29 @@ function oo({
|
|
|
414
414
|
}, [Y, S]), A(() => {
|
|
415
415
|
const t = E.current;
|
|
416
416
|
if (!t || e.length === 0) return;
|
|
417
|
-
const n = e.filter((r) => r.data.length > 0).length <= 1 ? De : Ee, a =
|
|
417
|
+
const n = e.filter((r) => r.data.length > 0).length <= 1 ? De : Ee, a = s === "time" ? Ue(s, se) : Ue(s), c = /* @__PURE__ */ new Map();
|
|
418
418
|
{
|
|
419
419
|
let r = 0;
|
|
420
420
|
for (const o of e)
|
|
421
|
-
o.data.length !== 0 && (
|
|
421
|
+
o.data.length !== 0 && (c.set(
|
|
422
422
|
o.label,
|
|
423
423
|
o.priceScaleId ?? (r === 0 ? "left" : "right")
|
|
424
424
|
), r++);
|
|
425
425
|
}
|
|
426
426
|
const h = (r, o, g) => {
|
|
427
|
-
const { formatter: F, tickmarksFormatter:
|
|
427
|
+
const { formatter: F, tickmarksFormatter: T, updateVisibleRange: N } = wt(r, o, {
|
|
428
428
|
yScaleMin: n
|
|
429
429
|
});
|
|
430
|
-
return { formatter: F, tickmarksFormatter:
|
|
430
|
+
return { formatter: F, tickmarksFormatter: T, updateVisibleRange: N, labels: g };
|
|
431
431
|
}, m = [];
|
|
432
432
|
if (D)
|
|
433
433
|
for (const r of ["left", "right"]) {
|
|
434
434
|
const o = /* @__PURE__ */ new Set(), g = [];
|
|
435
435
|
let F = d;
|
|
436
|
-
for (const
|
|
437
|
-
if (
|
|
438
|
-
o.size === 0 &&
|
|
439
|
-
for (const
|
|
436
|
+
for (const T of e)
|
|
437
|
+
if (T.data.length !== 0 && c.get(T.label) === r) {
|
|
438
|
+
o.size === 0 && T.yMeasureUnit && (F = T.yMeasureUnit), o.add(T.label);
|
|
439
|
+
for (const N of T.data) g.push(N.value);
|
|
440
440
|
}
|
|
441
441
|
o.size > 0 && m.push(h(g, F, o));
|
|
442
442
|
}
|
|
@@ -451,7 +451,7 @@ function oo({
|
|
|
451
451
|
for (const r of m)
|
|
452
452
|
for (const o of r.labels)
|
|
453
453
|
y.set(o, r);
|
|
454
|
-
const x =
|
|
454
|
+
const x = Je();
|
|
455
455
|
t.applyOptions({
|
|
456
456
|
localization: {
|
|
457
457
|
...x.localization || {},
|
|
@@ -469,7 +469,7 @@ function oo({
|
|
|
469
469
|
minBarSpacing: 0
|
|
470
470
|
}
|
|
471
471
|
});
|
|
472
|
-
const v = !D && e.length > 1 && !Z, W = D ? P : e.length > 1 && !Z || P,
|
|
472
|
+
const v = !D && e.length > 1 && !Z, W = D ? P : e.length > 1 && !Z || P, M = ne(
|
|
473
473
|
"hsl(var(--muted-foreground))",
|
|
474
474
|
"rgb(163, 163, 163)"
|
|
475
475
|
);
|
|
@@ -481,7 +481,7 @@ function oo({
|
|
|
481
481
|
...x.leftPriceScale || {},
|
|
482
482
|
...S?.leftPriceScale,
|
|
483
483
|
visible: D && !P,
|
|
484
|
-
textColor:
|
|
484
|
+
textColor: M,
|
|
485
485
|
...D && Ie && {
|
|
486
486
|
// lightweight-charts uses scale margins; title shown via localization if needed
|
|
487
487
|
}
|
|
@@ -490,17 +490,17 @@ function oo({
|
|
|
490
490
|
...x.rightPriceScale || {},
|
|
491
491
|
...S?.rightPriceScale,
|
|
492
492
|
visible: D ? !P : !W,
|
|
493
|
-
textColor:
|
|
493
|
+
textColor: M
|
|
494
494
|
}
|
|
495
495
|
});
|
|
496
|
-
const U = new Set(
|
|
496
|
+
const U = new Set(L.current.keys()), X = new Set(e.map(ie));
|
|
497
497
|
for (const r of U)
|
|
498
498
|
if (!X.has(r)) {
|
|
499
|
-
const o =
|
|
500
|
-
o && (t.removeSeries(o),
|
|
499
|
+
const o = L.current.get(r);
|
|
500
|
+
o && (t.removeSeries(o), L.current.delete(r));
|
|
501
501
|
}
|
|
502
502
|
const p = vt(), I = [];
|
|
503
|
-
let
|
|
503
|
+
let R = 0;
|
|
504
504
|
const $ = e.find((r) => r.data.length > 0), C = /* @__PURE__ */ new Map();
|
|
505
505
|
if (k && k.length > 0)
|
|
506
506
|
for (const r of k) {
|
|
@@ -518,39 +518,39 @@ function oo({
|
|
|
518
518
|
Number.isFinite(r.priceTop) && g.push(r.priceTop), Number.isFinite(r.priceBottom) && g.push(r.priceBottom), C.set(o, g);
|
|
519
519
|
}
|
|
520
520
|
for (let r = 0; r < e.length; r++) {
|
|
521
|
-
const o = e[r], g = ie(o), F = ot(r),
|
|
522
|
-
let
|
|
521
|
+
const o = e[r], g = ie(o), F = ot(r), T = o.lineColor ?? o.color ?? F.line;
|
|
522
|
+
let N, J;
|
|
523
523
|
if (o.lineColor ?? o.color)
|
|
524
524
|
if (o.topColor && o.bottomColor)
|
|
525
|
-
|
|
525
|
+
N = o.topColor, J = o.bottomColor;
|
|
526
526
|
else if (o.topColor) {
|
|
527
|
-
const b = ve(
|
|
528
|
-
|
|
527
|
+
const b = ve(T);
|
|
528
|
+
N = o.topColor, J = b.bottomColor;
|
|
529
529
|
} else if (o.bottomColor)
|
|
530
|
-
|
|
530
|
+
N = ve(T).topColor, J = o.bottomColor;
|
|
531
531
|
else {
|
|
532
|
-
const b = ve(
|
|
533
|
-
|
|
532
|
+
const b = ve(T);
|
|
533
|
+
N = b.topColor, J = b.bottomColor;
|
|
534
534
|
}
|
|
535
535
|
else
|
|
536
|
-
|
|
536
|
+
N = o.topColor || F.top, J = o.bottomColor || F.bottom;
|
|
537
537
|
if (o.data.length === 0) {
|
|
538
|
-
const b =
|
|
539
|
-
b && (t.removeSeries(b),
|
|
538
|
+
const b = L.current.get(g);
|
|
539
|
+
b && (t.removeSeries(b), L.current.delete(g));
|
|
540
540
|
continue;
|
|
541
541
|
}
|
|
542
|
-
const pe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, ce = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, ue = pe < 0, q = o.data.some((b) => b.value === 0), de = !ue && q, fe = Nt(ce - pe), he = D ? o.priceScaleId ?? (
|
|
542
|
+
const pe = o.data.length > 0 ? Math.min(...o.data.map((b) => b.value)) : 0, ce = o.data.length > 0 ? Math.max(...o.data.map((b) => b.value)) : 0, ue = pe < 0, q = o.data.some((b) => b.value === 0), de = !ue && q, fe = Nt(ce - pe), he = D ? o.priceScaleId ?? (R === 0 ? "left" : "right") : Z || !v || R === 0 ? "right" : `scale-${R}`;
|
|
543
543
|
v && I.push({
|
|
544
544
|
priceScaleId: he || "right",
|
|
545
|
-
seriesIndex:
|
|
545
|
+
seriesIndex: R
|
|
546
546
|
});
|
|
547
|
-
const
|
|
547
|
+
const Re = (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
|
+
Re && (_.priceRange.minValue = n);
|
|
551
551
|
for (const j of ct)
|
|
552
552
|
j < _.priceRange.minValue && (_.priceRange.minValue = j), j > _.priceRange.maxValue && (_.priceRange.maxValue = j);
|
|
553
|
-
const oe =
|
|
553
|
+
const oe = Re ? n : de && _.priceRange.minValue >= 0 ? 0 : void 0, be = le.current > 0 ? le.current : B.current?.clientHeight ?? 0;
|
|
554
554
|
if (be > 0) {
|
|
555
555
|
const j = Vt({
|
|
556
556
|
min: _.priceRange.minValue,
|
|
@@ -571,10 +571,10 @@ function oo({
|
|
|
571
571
|
};
|
|
572
572
|
}
|
|
573
573
|
return _;
|
|
574
|
-
}, Ze = y.get(o.label) ?? m[0], qe = Ze.formatter, ft = Ze.tickmarksFormatter,
|
|
575
|
-
lineColor:
|
|
576
|
-
topColor:
|
|
577
|
-
bottomColor:
|
|
574
|
+
}, Ze = y.get(o.label) ?? m[0], qe = Ze.formatter, ft = Ze.tickmarksFormatter, Te = {
|
|
575
|
+
lineColor: T,
|
|
576
|
+
topColor: N,
|
|
577
|
+
bottomColor: J,
|
|
578
578
|
priceScaleId: he,
|
|
579
579
|
...o.seriesType === "line" && {
|
|
580
580
|
lineStyle: o.lineStyle ?? ae.Solid
|
|
@@ -582,14 +582,14 @@ function oo({
|
|
|
582
582
|
priceFormat: {
|
|
583
583
|
type: "custom",
|
|
584
584
|
minMove: fe,
|
|
585
|
-
formatter:
|
|
585
|
+
formatter: Re && typeof n == "number" ? (b) => qe(
|
|
586
586
|
b < n ? n : b
|
|
587
587
|
) : qe,
|
|
588
588
|
tickmarksFormatter: ft
|
|
589
589
|
},
|
|
590
590
|
autoscaleInfoProvider: ut
|
|
591
|
-
},
|
|
592
|
-
let z =
|
|
591
|
+
}, Oe = o.seriesType === "line";
|
|
592
|
+
let z = L.current.get(g);
|
|
593
593
|
const te = o.data.map((b) => ({
|
|
594
594
|
...b,
|
|
595
595
|
time: b.time
|
|
@@ -600,13 +600,13 @@ function oo({
|
|
|
600
600
|
j.push({ time: Ne });
|
|
601
601
|
te.unshift(...j);
|
|
602
602
|
}
|
|
603
|
-
z && z.seriesType() !== (
|
|
603
|
+
z && z.seriesType() !== (Oe ? "Line" : "Area") && (t.removeSeries(z), L.current.delete(g), z = void 0), z ? (z.applyOptions(Te), z.setData(te)) : (Oe ? z = t.addSeries(mt, {
|
|
604
604
|
...p,
|
|
605
|
-
...
|
|
605
|
+
...Te
|
|
606
606
|
}) : z = t.addSeries(pt, {
|
|
607
607
|
...p,
|
|
608
|
-
...
|
|
609
|
-
}), z.setData(te),
|
|
608
|
+
...Te
|
|
609
|
+
}), z.setData(te), L.current.set(g, z)), R++;
|
|
610
610
|
}
|
|
611
611
|
if (D)
|
|
612
612
|
try {
|
|
@@ -617,7 +617,7 @@ function oo({
|
|
|
617
617
|
alignLabels: !0,
|
|
618
618
|
entireTextOnly: !1,
|
|
619
619
|
tickMarkDensity: Se,
|
|
620
|
-
textColor:
|
|
620
|
+
textColor: M,
|
|
621
621
|
...S?.rightPriceScale
|
|
622
622
|
};
|
|
623
623
|
r?.applyOptions(g), o?.applyOptions(g);
|
|
@@ -637,7 +637,7 @@ function oo({
|
|
|
637
637
|
alignLabels: !0,
|
|
638
638
|
entireTextOnly: !1,
|
|
639
639
|
tickMarkDensity: Se,
|
|
640
|
-
textColor:
|
|
640
|
+
textColor: M
|
|
641
641
|
});
|
|
642
642
|
} catch (o) {
|
|
643
643
|
console.warn(
|
|
@@ -658,7 +658,7 @@ function oo({
|
|
|
658
658
|
alignLabels: !0,
|
|
659
659
|
entireTextOnly: !1,
|
|
660
660
|
tickMarkDensity: Se,
|
|
661
|
-
textColor:
|
|
661
|
+
textColor: M,
|
|
662
662
|
...S?.rightPriceScale
|
|
663
663
|
});
|
|
664
664
|
} catch {
|
|
@@ -672,27 +672,35 @@ function oo({
|
|
|
672
672
|
if (r.length > 0) {
|
|
673
673
|
const o = Math.min(...r), g = Q !== void 0 ? Math.min(Q, o) : o, F = Math.max(...r);
|
|
674
674
|
if (Number(g) <= Number(F)) {
|
|
675
|
-
const
|
|
676
|
-
const
|
|
677
|
-
if (
|
|
675
|
+
const T = () => {
|
|
676
|
+
const N = t.timeScale();
|
|
677
|
+
if (s !== "time") {
|
|
678
|
+
N.applyOptions({
|
|
679
|
+
fixLeftEdge: !0,
|
|
680
|
+
fixRightEdge: !0
|
|
681
|
+
});
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const J = D && !P, pe = D ? !P : !W, ce = !J, ue = !pe;
|
|
685
|
+
if (N.applyOptions({
|
|
678
686
|
fixLeftEdge: !ce,
|
|
679
687
|
fixRightEdge: !ue
|
|
680
688
|
}), !ce && !ue) return;
|
|
681
|
-
const q =
|
|
689
|
+
const q = N.getVisibleLogicalRange(), de = N.width();
|
|
682
690
|
if (!q || !(de > 0)) return;
|
|
683
691
|
const fe = q.to - q.from;
|
|
684
692
|
if (!(fe > 0)) return;
|
|
685
693
|
const he = xt * fe / de;
|
|
686
|
-
|
|
694
|
+
N.setVisibleLogicalRange({
|
|
687
695
|
from: ce ? q.from - he : q.from,
|
|
688
696
|
to: ue ? q.to + he : q.to
|
|
689
697
|
});
|
|
690
698
|
};
|
|
691
699
|
try {
|
|
692
|
-
t.timeScale().setVisibleRange({ from: g, to: F }),
|
|
700
|
+
t.timeScale().setVisibleRange({ from: g, to: F }), T();
|
|
693
701
|
} catch {
|
|
694
702
|
try {
|
|
695
|
-
t.timeScale().fitContent(),
|
|
703
|
+
t.timeScale().fitContent(), T();
|
|
696
704
|
} catch {
|
|
697
705
|
}
|
|
698
706
|
}
|
|
@@ -708,7 +716,7 @@ function oo({
|
|
|
708
716
|
Y,
|
|
709
717
|
e,
|
|
710
718
|
se,
|
|
711
|
-
|
|
719
|
+
s,
|
|
712
720
|
d,
|
|
713
721
|
P,
|
|
714
722
|
Z,
|
|
@@ -726,35 +734,35 @@ function oo({
|
|
|
726
734
|
if (!t || e.length === 0) return;
|
|
727
735
|
const l = e.length === 1;
|
|
728
736
|
let n;
|
|
729
|
-
for (const
|
|
730
|
-
if (
|
|
731
|
-
n =
|
|
737
|
+
for (const c of e)
|
|
738
|
+
if (c.data.length > 0) {
|
|
739
|
+
n = c.data[c.data.length - 1].time;
|
|
732
740
|
break;
|
|
733
741
|
}
|
|
734
742
|
if (!n) return;
|
|
735
|
-
const a = (
|
|
736
|
-
const { time: h = n, seriesData: m, point: y } =
|
|
743
|
+
const a = (c) => {
|
|
744
|
+
const { time: h = n, seriesData: m, point: y } = c || {}, x = e[0], v = x ? L.current.get(ie(x)) : void 0;
|
|
737
745
|
if (!y || !h) {
|
|
738
746
|
const X = /* @__PURE__ */ new Map();
|
|
739
747
|
for (const p of e)
|
|
740
748
|
p.data.length > 0 && X.set(p.label, p.data[p.data.length - 1]);
|
|
741
749
|
if (Pe(X.size > 0 ? X : void 0), l || Z || xe)
|
|
742
|
-
|
|
750
|
+
O(null);
|
|
743
751
|
else if (v && n) {
|
|
744
752
|
const p = e[0];
|
|
745
753
|
if (p && p.data.length > 0) {
|
|
746
|
-
const
|
|
747
|
-
|
|
754
|
+
const R = t.timeScale().timeToCoordinate(n), $ = p.data[p.data.length - 1].value, C = v.priceToCoordinate($);
|
|
755
|
+
R !== null && C !== null && O({ x: R, y: C });
|
|
748
756
|
}
|
|
749
757
|
}
|
|
750
758
|
return;
|
|
751
759
|
}
|
|
752
760
|
const W = /* @__PURE__ */ new Map();
|
|
753
|
-
let
|
|
761
|
+
let M, U = v;
|
|
754
762
|
for (let X = 0; X < e.length; X++) {
|
|
755
|
-
const p = e[X], I =
|
|
763
|
+
const p = e[X], I = L.current.get(ie(p));
|
|
756
764
|
if (!I) continue;
|
|
757
|
-
const
|
|
765
|
+
const R = m?.get(I), $ = R && "value" in R ? R.value : void 0;
|
|
758
766
|
let C;
|
|
759
767
|
if ($ !== void 0)
|
|
760
768
|
C = $;
|
|
@@ -766,33 +774,33 @@ function oo({
|
|
|
766
774
|
if (Number(h) < H) continue;
|
|
767
775
|
C = At(p.data, Number(h));
|
|
768
776
|
}
|
|
769
|
-
Number.isNaN(C) || (
|
|
777
|
+
Number.isNaN(C) || (M === void 0 && (M = C, U = I), W.set(p.label, { value: C, time: h }));
|
|
770
778
|
}
|
|
771
|
-
if (Pe(W),
|
|
772
|
-
const p = t.timeScale().timeToCoordinate(h), I = U.priceToCoordinate(
|
|
779
|
+
if (Pe(W), M !== void 0 && U) {
|
|
780
|
+
const p = t.timeScale().timeToCoordinate(h), I = U.priceToCoordinate(M);
|
|
773
781
|
if (p !== null && I !== null) {
|
|
774
|
-
const
|
|
775
|
-
if (
|
|
776
|
-
const $ =
|
|
782
|
+
const R = B.current;
|
|
783
|
+
if (R) {
|
|
784
|
+
const $ = R.querySelector(
|
|
777
785
|
".LightweightChart"
|
|
778
786
|
);
|
|
779
787
|
if ($) {
|
|
780
|
-
const C = $.getBoundingClientRect(), H =
|
|
781
|
-
|
|
788
|
+
const C = $.getBoundingClientRect(), H = R.getBoundingClientRect(), r = p + (C.left - H.left), o = I + (C.top - H.top);
|
|
789
|
+
O({ x: r, y: o });
|
|
782
790
|
} else
|
|
783
|
-
|
|
791
|
+
O({ x: p, y: I });
|
|
784
792
|
} else
|
|
785
|
-
|
|
793
|
+
O({ x: p, y: I });
|
|
786
794
|
} else
|
|
787
|
-
|
|
795
|
+
O(null);
|
|
788
796
|
} else
|
|
789
|
-
|
|
797
|
+
O(null);
|
|
790
798
|
};
|
|
791
799
|
return t.subscribeCrosshairMove(a), P && t.subscribeClick(a), !l && !Z && !xe && requestAnimationFrame(() => {
|
|
792
|
-
const
|
|
793
|
-
if (h && n &&
|
|
794
|
-
const y = t.timeScale().timeToCoordinate(n), x =
|
|
795
|
-
y !== null && v !== null &&
|
|
800
|
+
const c = e[0], h = c ? L.current.get(ie(c)) : void 0;
|
|
801
|
+
if (h && n && c.data.length > 0) {
|
|
802
|
+
const y = t.timeScale().timeToCoordinate(n), x = c.data[c.data.length - 1].value, v = h.priceToCoordinate(x);
|
|
803
|
+
y !== null && v !== null && O({ x: y, y: v });
|
|
796
804
|
}
|
|
797
805
|
}), () => {
|
|
798
806
|
t.unsubscribeCrosshairMove(a), P && t.unsubscribeClick(a);
|
|
@@ -803,16 +811,16 @@ function oo({
|
|
|
803
811
|
const l = t.timeScale(), n = () => {
|
|
804
812
|
const a = ze.current;
|
|
805
813
|
if (a.length === 0) return;
|
|
806
|
-
const
|
|
807
|
-
if (!
|
|
808
|
-
const h = Number(
|
|
814
|
+
const c = l.getVisibleRange();
|
|
815
|
+
if (!c) return;
|
|
816
|
+
const h = Number(c.from), m = Number(c.to);
|
|
809
817
|
for (const y of a) {
|
|
810
818
|
const x = [];
|
|
811
819
|
for (const v of e)
|
|
812
820
|
if (y.labels.has(v.label))
|
|
813
821
|
for (const W of v.data) {
|
|
814
|
-
const
|
|
815
|
-
|
|
822
|
+
const M = Number(W.time);
|
|
823
|
+
M >= h && M <= m && x.push(W.value);
|
|
816
824
|
}
|
|
817
825
|
x.length > 0 && y.updateVisibleRange(x);
|
|
818
826
|
}
|
|
@@ -823,25 +831,25 @@ function oo({
|
|
|
823
831
|
);
|
|
824
832
|
};
|
|
825
833
|
}, [e]), A(() => {
|
|
826
|
-
const t = E.current, l = Array.from(
|
|
834
|
+
const t = E.current, l = Array.from(L.current.values()), n = [];
|
|
827
835
|
if (t && l.length > 0 && w) {
|
|
828
|
-
const a = Ct(),
|
|
836
|
+
const a = Ct(), c = l[0];
|
|
829
837
|
for (const h of w) {
|
|
830
838
|
const m = {
|
|
831
839
|
...a,
|
|
832
840
|
...h.options || {}
|
|
833
841
|
};
|
|
834
842
|
m.color && (m.color = ne(m.color, m.color));
|
|
835
|
-
const y = new
|
|
836
|
-
|
|
843
|
+
const y = new Tt(t, c, h.xCoordinate, m);
|
|
844
|
+
c.attachPrimitive(y), n.push(y);
|
|
837
845
|
}
|
|
838
846
|
}
|
|
839
847
|
return () => {
|
|
840
848
|
if (l.length > 0) {
|
|
841
849
|
const a = l[0];
|
|
842
|
-
for (const
|
|
850
|
+
for (const c of n)
|
|
843
851
|
try {
|
|
844
|
-
a.detachPrimitive(
|
|
852
|
+
a.detachPrimitive(c);
|
|
845
853
|
} catch {
|
|
846
854
|
}
|
|
847
855
|
}
|
|
@@ -855,13 +863,13 @@ function oo({
|
|
|
855
863
|
);
|
|
856
864
|
for (const a of k) {
|
|
857
865
|
if (!Number.isFinite(a.price)) continue;
|
|
858
|
-
const
|
|
859
|
-
|
|
866
|
+
const c = et(
|
|
867
|
+
L.current,
|
|
860
868
|
e,
|
|
861
869
|
a.seriesLabel
|
|
862
870
|
);
|
|
863
|
-
if (!
|
|
864
|
-
const h = a.color ? ne(a.color, a.color) : n, m = a.lineWidth ?? 1, y = a.lineStyle ?? ae.Dashed, x =
|
|
871
|
+
if (!c) continue;
|
|
872
|
+
const h = a.color ? ne(a.color, a.color) : n, m = a.lineWidth ?? 1, y = a.lineStyle ?? ae.Dashed, x = c.createPriceLine({
|
|
865
873
|
price: a.price,
|
|
866
874
|
color: h,
|
|
867
875
|
lineWidth: m,
|
|
@@ -869,15 +877,15 @@ function oo({
|
|
|
869
877
|
axisLabelVisible: a.axisLabelVisible ?? !0,
|
|
870
878
|
title: a.title ?? ""
|
|
871
879
|
});
|
|
872
|
-
t.push({ series:
|
|
880
|
+
t.push({ series: c, line: x });
|
|
873
881
|
const v = new Bt(
|
|
874
|
-
|
|
882
|
+
c,
|
|
875
883
|
a.price,
|
|
876
884
|
h,
|
|
877
885
|
m,
|
|
878
886
|
y
|
|
879
887
|
);
|
|
880
|
-
|
|
888
|
+
c.attachPrimitive(v), l.push({ series: c, primitive: v });
|
|
881
889
|
}
|
|
882
890
|
}
|
|
883
891
|
return () => {
|
|
@@ -898,16 +906,16 @@ function oo({
|
|
|
898
906
|
const l = "rgba(239, 68, 68, 0.12)";
|
|
899
907
|
for (const n of G) {
|
|
900
908
|
const a = et(
|
|
901
|
-
|
|
909
|
+
L.current,
|
|
902
910
|
e,
|
|
903
911
|
n.seriesLabel
|
|
904
912
|
);
|
|
905
913
|
if (!a) continue;
|
|
906
|
-
const
|
|
914
|
+
const c = n.color ? ne(n.color, l) : l, h = new kt(
|
|
907
915
|
a,
|
|
908
916
|
n.priceTop,
|
|
909
917
|
n.priceBottom,
|
|
910
|
-
|
|
918
|
+
c
|
|
911
919
|
);
|
|
912
920
|
a.attachPrimitive(h), t.push({ series: a, zone: h });
|
|
913
921
|
}
|
|
@@ -926,7 +934,7 @@ function oo({
|
|
|
926
934
|
return;
|
|
927
935
|
}
|
|
928
936
|
const l = () => {
|
|
929
|
-
const
|
|
937
|
+
const c = t.timeScale(), h = w.map((m) => c.timeToCoordinate(m.xCoordinate) ?? null);
|
|
930
938
|
$e(h), B.current && He(B.current.clientWidth);
|
|
931
939
|
};
|
|
932
940
|
l();
|
|
@@ -940,9 +948,9 @@ function oo({
|
|
|
940
948
|
lt((t) => {
|
|
941
949
|
const l = {};
|
|
942
950
|
let n = !1;
|
|
943
|
-
for (const [a,
|
|
944
|
-
if (!
|
|
945
|
-
const h =
|
|
951
|
+
for (const [a, c] of je.current) {
|
|
952
|
+
if (!c) continue;
|
|
953
|
+
const h = c.offsetWidth;
|
|
946
954
|
l[a] = h, t[a] !== h && (n = !0);
|
|
947
955
|
}
|
|
948
956
|
return Object.keys(t).length !== Object.keys(l).length && (n = !0), n ? l : t;
|
|
@@ -964,20 +972,20 @@ function oo({
|
|
|
964
972
|
i
|
|
965
973
|
),
|
|
966
974
|
children: [
|
|
967
|
-
ye != null && ye !== !1 && me ? /* @__PURE__ */
|
|
975
|
+
ye != null && ye !== !1 && me ? /* @__PURE__ */ V("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ V("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: ye }) }) : rt && me && Ke && /* @__PURE__ */ V(
|
|
968
976
|
Pt,
|
|
969
977
|
{
|
|
970
978
|
point: Ke,
|
|
971
|
-
xMeasureUnit:
|
|
979
|
+
xMeasureUnit: s,
|
|
972
980
|
yMeasureUnit: d,
|
|
973
981
|
decimals: Ce
|
|
974
982
|
}
|
|
975
983
|
),
|
|
976
|
-
Ge && We && /* @__PURE__ */
|
|
977
|
-
|
|
984
|
+
Ge && We && /* @__PURE__ */ V(
|
|
985
|
+
Rt,
|
|
978
986
|
{
|
|
979
987
|
points: Ge,
|
|
980
|
-
xMeasureUnit:
|
|
988
|
+
xMeasureUnit: s,
|
|
981
989
|
yMeasureUnit: d,
|
|
982
990
|
series: e,
|
|
983
991
|
position: We,
|
|
@@ -985,8 +993,8 @@ function oo({
|
|
|
985
993
|
decimals: Ce
|
|
986
994
|
}
|
|
987
995
|
),
|
|
988
|
-
u && /* @__PURE__ */
|
|
989
|
-
w && w.length > 0 && Xe.length === w.length && /* @__PURE__ */
|
|
996
|
+
u && /* @__PURE__ */ V(Wt, { series: e, onUnselect: f }),
|
|
997
|
+
w && w.length > 0 && Xe.length === w.length && /* @__PURE__ */ V(
|
|
990
998
|
"div",
|
|
991
999
|
{
|
|
992
1000
|
className: "absolute inset-0 z-[5] pointer-events-none",
|
|
@@ -994,13 +1002,13 @@ function oo({
|
|
|
994
1002
|
children: w.map((t, l) => {
|
|
995
1003
|
const n = Xe[l], a = t.options ?? {};
|
|
996
1004
|
if (n === null) return null;
|
|
997
|
-
const { labelText:
|
|
1005
|
+
const { labelText: c, valueStr: h } = Ft(
|
|
998
1006
|
a,
|
|
999
1007
|
d,
|
|
1000
1008
|
Ce
|
|
1001
1009
|
), m = a.tooltipText ?? "";
|
|
1002
|
-
if (!(
|
|
1003
|
-
const x = a.labelBackgroundColor ?? a.color ?? "hsl(var(--background))", v = a.labelTextColor ?? "hsl(var(--foreground))", W = `${String(t.xCoordinate)}-${
|
|
1010
|
+
if (!(c || h || m)) return null;
|
|
1011
|
+
const x = a.labelBackgroundColor ?? a.color ?? "hsl(var(--background))", v = a.labelTextColor ?? "hsl(var(--foreground))", W = `${String(t.xCoordinate)}-${c}-${m}`, M = zt(
|
|
1004
1012
|
n,
|
|
1005
1013
|
it,
|
|
1006
1014
|
at[l]
|
|
@@ -1016,14 +1024,14 @@ function oo({
|
|
|
1016
1024
|
m && "pointer-events-auto cursor-default"
|
|
1017
1025
|
),
|
|
1018
1026
|
style: {
|
|
1019
|
-
...
|
|
1027
|
+
...M,
|
|
1020
1028
|
backgroundColor: x,
|
|
1021
1029
|
color: v
|
|
1022
1030
|
},
|
|
1023
1031
|
children: [
|
|
1024
|
-
|
|
1025
|
-
h && /* @__PURE__ */
|
|
1026
|
-
m && /* @__PURE__ */
|
|
1032
|
+
c && /* @__PURE__ */ V("span", { className: "block", children: c }),
|
|
1033
|
+
h && /* @__PURE__ */ V("span", { className: ee("block", c && "mt-0.5"), children: h }),
|
|
1034
|
+
m && /* @__PURE__ */ V(
|
|
1027
1035
|
"span",
|
|
1028
1036
|
{
|
|
1029
1037
|
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",
|
|
@@ -1038,7 +1046,7 @@ function oo({
|
|
|
1038
1046
|
})
|
|
1039
1047
|
}
|
|
1040
1048
|
),
|
|
1041
|
-
/* @__PURE__ */
|
|
1049
|
+
/* @__PURE__ */ V(
|
|
1042
1050
|
"div",
|
|
1043
1051
|
{
|
|
1044
1052
|
ref: we,
|
|
@@ -1054,16 +1062,16 @@ function Wt({
|
|
|
1054
1062
|
onUnselect: i,
|
|
1055
1063
|
inline: u = !1
|
|
1056
1064
|
}) {
|
|
1057
|
-
const f = e.every((
|
|
1058
|
-
return /* @__PURE__ */
|
|
1065
|
+
const f = e.every((s) => s.data.length === 0);
|
|
1066
|
+
return /* @__PURE__ */ V(
|
|
1059
1067
|
"div",
|
|
1060
1068
|
{
|
|
1061
1069
|
className: ee(
|
|
1062
1070
|
"flex flex-wrap",
|
|
1063
1071
|
u ? "items-center justify-center gap-6" : "absolute top-0 left-2 z-[10] gap-2"
|
|
1064
1072
|
),
|
|
1065
|
-
children: e.map((
|
|
1066
|
-
const S = ot(d), w = (
|
|
1073
|
+
children: e.map((s, d) => {
|
|
1074
|
+
const S = ot(d), w = (s.lineColor ?? s.color) || S.line, k = !f && s.data.length === 0;
|
|
1067
1075
|
return /* @__PURE__ */ ge(
|
|
1068
1076
|
"div",
|
|
1069
1077
|
{
|
|
@@ -1073,7 +1081,7 @@ function Wt({
|
|
|
1073
1081
|
k && "opacity-50"
|
|
1074
1082
|
),
|
|
1075
1083
|
children: [
|
|
1076
|
-
/* @__PURE__ */
|
|
1084
|
+
/* @__PURE__ */ V(
|
|
1077
1085
|
"div",
|
|
1078
1086
|
{
|
|
1079
1087
|
className: ee(
|
|
@@ -1090,20 +1098,20 @@ function Wt({
|
|
|
1090
1098
|
u ? "text-sm" : "text-[10px] sm:text-xs"
|
|
1091
1099
|
),
|
|
1092
1100
|
children: [
|
|
1093
|
-
|
|
1101
|
+
s.label,
|
|
1094
1102
|
k && " (no data)"
|
|
1095
1103
|
]
|
|
1096
1104
|
}
|
|
1097
1105
|
),
|
|
1098
|
-
i && /* @__PURE__ */
|
|
1106
|
+
i && /* @__PURE__ */ V(
|
|
1099
1107
|
"button",
|
|
1100
1108
|
{
|
|
1101
1109
|
type: "button",
|
|
1102
1110
|
onClick: (G) => {
|
|
1103
|
-
G.stopPropagation(), i(
|
|
1111
|
+
G.stopPropagation(), i(s.label);
|
|
1104
1112
|
},
|
|
1105
1113
|
className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
|
|
1106
|
-
"aria-label": `Remove ${
|
|
1114
|
+
"aria-label": `Remove ${s.label}`,
|
|
1107
1115
|
children: /* @__PURE__ */ ge(
|
|
1108
1116
|
"svg",
|
|
1109
1117
|
{
|
|
@@ -1119,9 +1127,9 @@ function Wt({
|
|
|
1119
1127
|
className: "text-muted-foreground hover:text-foreground",
|
|
1120
1128
|
"aria-hidden": "true",
|
|
1121
1129
|
children: [
|
|
1122
|
-
/* @__PURE__ */
|
|
1123
|
-
/* @__PURE__ */
|
|
1124
|
-
/* @__PURE__ */
|
|
1130
|
+
/* @__PURE__ */ V("title", { children: "Close" }),
|
|
1131
|
+
/* @__PURE__ */ V("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
1132
|
+
/* @__PURE__ */ V("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
1125
1133
|
]
|
|
1126
1134
|
}
|
|
1127
1135
|
)
|
|
@@ -1129,7 +1137,7 @@ function Wt({
|
|
|
1129
1137
|
)
|
|
1130
1138
|
]
|
|
1131
1139
|
},
|
|
1132
|
-
|
|
1140
|
+
s.id ?? s.label
|
|
1133
1141
|
);
|
|
1134
1142
|
})
|
|
1135
1143
|
}
|