@gearbox-protocol/permissionless-ui 1.17.7 → 1.17.8
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 r=require("../../utils/colors.cjs"),o={topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:"#02c39a",lineWidth:2},l={showLabel:!0,color:"#02c39a",labelBackgroundColor:"#02c39a",width:2};function t(){const e=r.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");return{timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0},rightPriceScale:{autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:e},layout:{background:{color:"transparent"},textColor:e,fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}}}function i(){return{topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:o.lineColor,lineWidth:2}}function a(){const e=r.resolveCSSColor("hsl(var(--primary))","rgb(76, 175, 80)");return{showLabel:!0,color:e,labelBackgroundColor:e,width:2}}const s={timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0},rightPriceScale:{autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1},layout:{background:{color:"transparent"},textColor:"rgb(0, 0, 0)",fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}};exports.DEFAULT_AREA_SERIES=o;exports.DEFAULT_OPTIONS=s;exports.DEFAULT_VERTICAL_LINE=l;exports.getDefaultOptions=t;exports.getDefaultSeries=i;exports.getDefaultVerticalLine=a;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../utils/colors.cjs"),o={topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:"#02c39a",lineWidth:2},l={showLabel:!0,color:"#02c39a",labelBackgroundColor:"#02c39a",width:2};function t(){const e=r.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");return{timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0},rightPriceScale:{visible:!0,autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:e},layout:{background:{color:"transparent"},textColor:e,fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}}}function i(){return{topColor:"rgba(76, 175, 80, 0.56)",bottomColor:"rgba(76, 175, 80, 0.04)",lineColor:o.lineColor,lineWidth:2}}function a(){const e=r.resolveCSSColor("hsl(var(--primary))","rgb(76, 175, 80)");return{showLabel:!0,color:e,labelBackgroundColor:e,width:2}}const s={timeScale:{borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",visible:!0},rightPriceScale:{visible:!0,autoScale:!0,alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1},layout:{background:{color:"transparent"},textColor:"rgb(0, 0, 0)",fontSize:14},crosshair:{horzLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1},vertLine:{width:2,color:"rgba(224, 227, 235, 0.1)",style:0,labelVisible:!1}},grid:{vertLines:{visible:!1},horzLines:{visible:!1}}};exports.DEFAULT_AREA_SERIES=o;exports.DEFAULT_OPTIONS=s;exports.DEFAULT_VERTICAL_LINE=l;exports.getDefaultOptions=t;exports.getDefaultSeries=i;exports.getDefaultVerticalLine=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),be=require("lightweight-charts"),i=require("react"),ve=require("../../hooks/use-media-query.cjs"),ce=require("../../utils/cn.cjs"),G=require("../../utils/colors.cjs"),$=require("./default-config.cjs"),oe=require("./formatters.cjs"),Ce=require("./graph-current-value.cjs"),Se=require("./graph-tooltip.cjs"),xe=require("./plugins/vertical-line.cjs");function Re(e){const V=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const p in e)if(p!=="default"){const T=Object.getOwnPropertyDescriptor(e,p);Object.defineProperty(V,p,T.get?T:{enumerable:!0,get:()=>e[p]})}}return V.default=e,Object.freeze(V)}const ne=Re(i),H=[{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:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 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:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"}];function ye({series:e,className:V,showLegend:p=!1,onUnselectSeries:T,xMeasureUnit:L="time",yMeasureUnit:q="token",optionsOverrides:D,verticalLineOptions:I}){const R=i.useRef(null),S=i.useRef(new Map),X=i.useRef(!1),Y=i.useRef(new Set),re=i.useRef(0),ae=i.useRef(!0),W=i.useRef(null),ue=i.useRef(null),F=i.useRef(null),Z=i.useRef(null),A=ve.useIsMobile(),P=ne.useMemo(()=>e.flatMap(t=>t.data),[e]),fe=ne.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[le,Q]=i.useState(()=>{if(!fe)return;const t=new Map;for(const n of e)n.data.length>0&&t.set(n.label,n.data[n.data.length-1]);return t}),[se,M]=i.useState(null);i.useEffect(()=>{const t=()=>{if(R.current&&F.current){const d=F.current.clientWidth,a=F.current.clientHeight;R.current.resize(d,a),R.current.timeScale().fitContent()}},n=F.current,l=n?new ResizeObserver(t):null;return n&&l?.observe(n),()=>{n&&l?.unobserve(n)}},[]),i.useEffect(()=>{if(!Z.current||X.current)return;const t=$.getDefaultOptions(),n=G.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=be.createChart(Z.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!A,textColor:n},...D});return R.current=l,X.current=!0,()=>{l.remove(),R.current=null,X.current=!1,S.current.clear()}},[A,D]),i.useEffect(()=>{const t=R.current;if(!t||e.length===0)return;const n=L==="time"?oe.getXFormatter(L,P):oe.getXFormatter(L),l=P.map(o=>o.value),{formatter:d,updateVisibleRange:a,updateLastValues:f}=oe.createAdaptiveYAxisFormatter(l);W.current=a,ue.current=f;const b=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);f(b);const x=$.getDefaultOptions();t.applyOptions({localization:{...x.localization||{},timeFormatter:n?(o=>n(parseFloat(o),void 0)):void 0},timeScale:{...x.timeScale||{},tickMarkFormatter:n?(o=>n(parseFloat(o),void 0)):void 0,minBarSpacing:0}});const j=(P.length>0?Math.min(...P.map(o=>o.value)):0)<0,y=P.some(o=>o.value===0),g=!j&&y,s=e.length>1,u=s||A,c=G.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...x.rightPriceScale||{},visible:!A,textColor:c,...g&&{scaleMargins:{top:.3,bottom:0}}}});const h=new Set(S.current.keys()),w=new Set(e.map(o=>o.label));for(const o of h)if(!w.has(o)){const r=S.current.get(o);r&&(t.removeSeries(r),S.current.delete(o))}const O=$.getDefaultSeries(),z=[];let k=0;for(let o=0;o<e.length;o++){const r=e[o],ee=H[o%H.length],B=r.color||ee.line;let _,N;if(r.color)if(r.topColor&&r.bottomColor)_=r.topColor,N=r.bottomColor;else if(r.topColor){const C=G.generateColorsFromBase(B);_=r.topColor,N=C.bottomColor}else if(r.bottomColor)_=G.generateColorsFromBase(B).topColor,N=r.bottomColor;else{const C=G.generateColorsFromBase(B);_=C.topColor,N=C.bottomColor}else _=r.topColor||ee.top,N=r.bottomColor||ee.bottom;if(r.data.length===0){const C=S.current.get(r.label);C&&(t.removeSeries(C),S.current.delete(r.label));continue}const he=(r.data.length>0?Math.min(...r.data.map(C=>C.value)):0)<0,me=r.data.some(C=>C.value===0),pe=!he&&me,te=s?k===0?void 0:`scale-${k}`:void 0;s&&z.push({priceScaleId:te||"right",shouldPreventNegativeAxis:pe,seriesIndex:k});let E=S.current.get(r.label);E?(E.applyOptions({lineColor:B,topColor:_,bottomColor:N,priceScaleId:te,priceFormat:{type:"custom",formatter:d}}),E.setData(r.data)):(E=t.addAreaSeries({...O,lineColor:B,topColor:_,bottomColor:N,priceScaleId:te,priceFormat:{type:"custom",formatter:d}}),E.setData(r.data),S.current.set(r.label,E)),k++}if(s&&z.length>0)for(const o of z)try{const r=t.priceScale(o.priceScaleId);r&&r.applyOptions({visible:!u,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...o.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:c})}catch(r){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,r)}const K=new Set(e.map(o=>o.label)),de=K.size!==Y.current.size||[...K].some(o=>!Y.current.has(o)),ge=P.length!==re.current;(ae.current||de||ge||A)&&(t.timeScale().fitContent(),ae.current=!1),Y.current=K,re.current=P.length;const U=new Map;for(const o of e)o.data.length>0&&U.set(o.label,o.data[o.data.length-1]);Q(U.size>0?U:void 0)},[e,P,L,q,A]),i.useEffect(()=>{const t=R.current;if(!t||e.length===0)return;const n=e.length===1;let l;for(const a of e)if(a.data.length>0){l=a.data[a.data.length-1].time;break}if(!l)return;const d=a=>{const{time:f=l,seriesData:b,point:x}=a||{},v=Array.from(S.current.values());if(!x||!f){const g=new Map;for(const s of e)s.data.length>0&&g.set(s.label,s.data[s.data.length-1]);if(Q(g.size>0?g:void 0),n)M(null);else if(v[0]&&l){const u=t.timeScale().timeToCoordinate(l),c=e[0];if(c.data.length>0){const h=c.data[c.data.length-1].value,w=v[0].priceToCoordinate(h);u!==null&&w!==null&&M({x:u,y:w})}}return}const j=new Map;let y;for(let g=0;g<e.length;g++){const s=e[g],u=v[g];if(!u)continue;const c=b?.get(u),h=c&&"value"in c?c.value:void 0,w=s.data[s.data.length-1],O=h!==void 0?h:w?.value??0;g===0&&(y=O),j.set(s.label,{value:O,time:f})}if(Q(j),y!==void 0&&v[0]){const s=t.timeScale().timeToCoordinate(f),u=v[0].priceToCoordinate(y);if(s!==null&&u!==null){const c=F.current;if(c){const h=c.querySelector(".LightweightChart");if(h){const w=h.getBoundingClientRect(),O=c.getBoundingClientRect(),z=s+(w.left-O.left),k=u+(w.top-O.top);M({x:z,y:k})}else M({x:s,y:u})}else M({x:s,y:u})}else M(null)}else M(null)};return t.subscribeCrosshairMove(d),n||requestAnimationFrame(()=>{const a=Array.from(S.current.values());if(a[0]&&l&&e[0]?.data.length>0){const b=t.timeScale().timeToCoordinate(l),x=e[0].data[e[0].data.length-1].value,v=a[0].priceToCoordinate(x);b!==null&&v!==null&&M({x:b,y:v})}}),()=>{t.unsubscribeCrosshairMove(d)}},[e]),i.useEffect(()=>{const t=R.current;if(!t||e.length===0)return;const n=t.timeScale(),l=Math.max(...e.map(a=>a.data.length)),d=()=>{if(l===0)return;const a=n.getVisibleLogicalRange();if(!a)return;const f={from:0,to:l-1},b=typeof a.from=="number"?a.from:0,x=typeof a.to=="number"?a.to:l-1;if(W.current){const g=Math.max(0,Math.floor(b)),s=Math.min(l-1,Math.ceil(x)),u=[];for(const c of e)for(let h=g;h<=s&&h<c.data.length;h++)u.push(c.data[h].value);u.length>0&&W.current(u)}const v=.01;let j=!1;const y={...a};b<f.from-v&&(y.from=f.from,j=!0),x>f.to+v&&(y.to=f.to,j=!0),j&&n.setVisibleLogicalRange(y)};return n.subscribeVisibleLogicalRangeChange(d),()=>{n.unsubscribeVisibleLogicalRangeChange(d)}},[e]),i.useEffect(()=>{const t=R.current,n=Array.from(S.current.values()),l=[];if(t&&n.length>0&&I){const d=$.getDefaultVerticalLine(),a=n[0];for(const f of I){const b=new xe.VertLine(t,a,f.xCoordinate,{...d,...f.options||{}});a.attachPrimitive(b),l.push(b)}}return()=>{if(n.length>0){const d=n[0];for(const a of l)d.detachPrimitive(a)}}},[I]);const J=e.length===1,ie=ne.useMemo(()=>{if(J&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[J,e]);return m.jsxs("div",{ref:F,className:ce.cn("relative z-[1] w-full h-full overflow-hidden p-0",V),children:[J&&ie&&m.jsx(Ce.GraphCurrentValue,{point:ie,xMeasureUnit:L,yMeasureUnit:q}),le&&se&&m.jsx(Se.GraphTooltip,{points:le,xMeasureUnit:L,yMeasureUnit:q,series:e,position:se,containerRef:F}),p&&m.jsx(we,{series:e,onUnselect:T}),m.jsx("div",{ref:Z,className:"LightweightChart w-full h-full overflow-hidden"})]})}function we({series:e,onUnselect:V}){return m.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((p,T)=>{const L=H[T%H.length],q=p.color||L.line,D=p.data.length===0;return m.jsxs("div",{className:ce.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",D&&"opacity-50"),children:[m.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:q}}),m.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[p.label,D&&" (no data)"]}),V&&m.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),V(p.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 ${p.label}`,children:m.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:[m.jsx("title",{children:"Close"}),m.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),m.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},p.label)})})}exports.DEFAULT_SERIES_COLORS=H;exports.Graph=ye;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),be=require("lightweight-charts"),i=require("react"),ve=require("../../hooks/use-media-query.cjs"),ce=require("../../utils/cn.cjs"),G=require("../../utils/colors.cjs"),Y=require("./default-config.cjs"),oe=require("./formatters.cjs"),Ce=require("./graph-current-value.cjs"),Se=require("./graph-tooltip.cjs"),xe=require("./plugins/vertical-line.cjs");function Re(e){const V=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const p in e)if(p!=="default"){const A=Object.getOwnPropertyDescriptor(e,p);Object.defineProperty(V,p,A.get?A:{enumerable:!0,get:()=>e[p]})}}return V.default=e,Object.freeze(V)}const re=Re(i),H=[{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:"#f59e0b",top:"rgba(245, 158, 11, 0.56)",bottom:"rgba(245, 158, 11, 0.04)"},{line:"#ef4444",top:"rgba(239, 68, 68, 0.56)",bottom:"rgba(239, 68, 68, 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:"#10b981",top:"rgba(16, 185, 129, 0.56)",bottom:"rgba(16, 185, 129, 0.04)"},{line:"#06b6d4",top:"rgba(6, 182, 212, 0.56)",bottom:"rgba(6, 182, 212, 0.04)"}];function ye({series:e,className:V,showLegend:p=!1,onUnselectSeries:A,xMeasureUnit:L="time",yMeasureUnit:q="token",optionsOverrides:D,verticalLineOptions:I}){const R=i.useRef(null),S=i.useRef(new Map),$=i.useRef(!1),X=i.useRef(new Set),ne=i.useRef(0),ae=i.useRef(!0),W=i.useRef(null),ue=i.useRef(null),F=i.useRef(null),Z=i.useRef(null),N=ve.useIsMobile(),P=re.useMemo(()=>e.flatMap(o=>o.data),[e]),fe=re.useMemo(()=>{if(e.length>0){const o=e[e.length-1];if(o.data.length>0)return o.data[o.data.length-1]}},[e]),[le,Q]=i.useState(()=>{if(!fe)return;const o=new Map;for(const r of e)r.data.length>0&&o.set(r.label,r.data[r.data.length-1]);return o}),[se,M]=i.useState(null);i.useEffect(()=>{const o=()=>{if(R.current&&F.current){const d=F.current.clientWidth,a=F.current.clientHeight;R.current.resize(d,a),R.current.timeScale().fitContent()}},r=F.current,l=r?new ResizeObserver(o):null;return r&&l?.observe(r),()=>{r&&l?.unobserve(r)}},[]),i.useEffect(()=>{if(!Z.current||$.current)return;const o=Y.getDefaultOptions(),r=G.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),l=be.createChart(Z.current,{...o,rightPriceScale:{...o.rightPriceScale||{},visible:!N,textColor:r},...D});return R.current=l,$.current=!0,()=>{l.remove(),R.current=null,$.current=!1,S.current.clear()}},[N,D]),i.useEffect(()=>{const o=R.current;if(!o||e.length===0)return;const r=L==="time"?oe.getXFormatter(L,P):oe.getXFormatter(L),l=P.map(t=>t.value),{formatter:d,updateVisibleRange:a,updateLastValues:f}=oe.createAdaptiveYAxisFormatter(l);W.current=a,ue.current=f;const b=e.filter(t=>t.data.length>0).map(t=>t.data[t.data.length-1].value);f(b);const x=Y.getDefaultOptions();o.applyOptions({localization:{...x.localization||{},timeFormatter:r?(t=>r(parseFloat(t),void 0)):void 0},timeScale:{...x.timeScale||{},tickMarkFormatter:r?(t=>r(parseFloat(t),void 0)):void 0,minBarSpacing:0}});const j=(P.length>0?Math.min(...P.map(t=>t.value)):0)<0,y=P.some(t=>t.value===0),g=!j&&y,s=e.length>1,u=s||N,c=G.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");o.applyOptions({rightPriceScale:{...x.rightPriceScale||{},visible:!u,textColor:c,...g&&{scaleMargins:{top:.3,bottom:0}}}});const h=new Set(S.current.keys()),w=new Set(e.map(t=>t.label));for(const t of h)if(!w.has(t)){const n=S.current.get(t);n&&(o.removeSeries(n),S.current.delete(t))}const O=Y.getDefaultSeries(),z=[];let k=0;for(let t=0;t<e.length;t++){const n=e[t],ee=H[t%H.length],B=n.color||ee.line;let T,_;if(n.color)if(n.topColor&&n.bottomColor)T=n.topColor,_=n.bottomColor;else if(n.topColor){const C=G.generateColorsFromBase(B);T=n.topColor,_=C.bottomColor}else if(n.bottomColor)T=G.generateColorsFromBase(B).topColor,_=n.bottomColor;else{const C=G.generateColorsFromBase(B);T=C.topColor,_=C.bottomColor}else T=n.topColor||ee.top,_=n.bottomColor||ee.bottom;if(n.data.length===0){const C=S.current.get(n.label);C&&(o.removeSeries(C),S.current.delete(n.label));continue}const he=(n.data.length>0?Math.min(...n.data.map(C=>C.value)):0)<0,me=n.data.some(C=>C.value===0),pe=!he&&me,te=s?k===0?"right":`scale-${k}`:"right";s&&z.push({priceScaleId:te||"right",shouldPreventNegativeAxis:pe,seriesIndex:k});let E=S.current.get(n.label);E?(E.applyOptions({lineColor:B,topColor:T,bottomColor:_,priceScaleId:te,priceFormat:{type:"custom",formatter:d}}),E.setData(n.data)):(E=o.addAreaSeries({...O,lineColor:B,topColor:T,bottomColor:_,priceScaleId:te,priceFormat:{type:"custom",formatter:d}}),E.setData(n.data),S.current.set(n.label,E)),k++}if(s&&z.length>0)for(const t of z)try{const n=o.priceScale(t.priceScaleId);n&&n.applyOptions({visible:!1,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...t.shouldPreventNegativeAxis&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:c})}catch(n){console.warn(`Failed to configure price scale ${t.priceScaleId} for series ${t.seriesIndex}:`,n)}else if(!s)try{const t=o.priceScale("right");t&&t.applyOptions({visible:!N,autoScale:!0,scaleMargins:{top:.1,bottom:.1,...g&&{top:.3,bottom:0}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:c})}catch{}const K=new Set(e.map(t=>t.label)),ge=K.size!==X.current.size||[...K].some(t=>!X.current.has(t)),de=P.length!==ne.current;(ae.current||ge||de||N)&&(o.timeScale().fitContent(),ae.current=!1),X.current=K,ne.current=P.length;const U=new Map;for(const t of e)t.data.length>0&&U.set(t.label,t.data[t.data.length-1]);Q(U.size>0?U:void 0)},[e,P,L,q,N]),i.useEffect(()=>{const o=R.current;if(!o||e.length===0)return;const r=e.length===1;let l;for(const a of e)if(a.data.length>0){l=a.data[a.data.length-1].time;break}if(!l)return;const d=a=>{const{time:f=l,seriesData:b,point:x}=a||{},v=Array.from(S.current.values());if(!x||!f){const g=new Map;for(const s of e)s.data.length>0&&g.set(s.label,s.data[s.data.length-1]);if(Q(g.size>0?g:void 0),r)M(null);else if(v[0]&&l){const u=o.timeScale().timeToCoordinate(l),c=e[0];if(c.data.length>0){const h=c.data[c.data.length-1].value,w=v[0].priceToCoordinate(h);u!==null&&w!==null&&M({x:u,y:w})}}return}const j=new Map;let y;for(let g=0;g<e.length;g++){const s=e[g],u=v[g];if(!u)continue;const c=b?.get(u),h=c&&"value"in c?c.value:void 0,w=s.data[s.data.length-1],O=h!==void 0?h:w?.value??0;g===0&&(y=O),j.set(s.label,{value:O,time:f})}if(Q(j),y!==void 0&&v[0]){const s=o.timeScale().timeToCoordinate(f),u=v[0].priceToCoordinate(y);if(s!==null&&u!==null){const c=F.current;if(c){const h=c.querySelector(".LightweightChart");if(h){const w=h.getBoundingClientRect(),O=c.getBoundingClientRect(),z=s+(w.left-O.left),k=u+(w.top-O.top);M({x:z,y:k})}else M({x:s,y:u})}else M({x:s,y:u})}else M(null)}else M(null)};return o.subscribeCrosshairMove(d),r||requestAnimationFrame(()=>{const a=Array.from(S.current.values());if(a[0]&&l&&e[0]?.data.length>0){const b=o.timeScale().timeToCoordinate(l),x=e[0].data[e[0].data.length-1].value,v=a[0].priceToCoordinate(x);b!==null&&v!==null&&M({x:b,y:v})}}),()=>{o.unsubscribeCrosshairMove(d)}},[e]),i.useEffect(()=>{const o=R.current;if(!o||e.length===0)return;const r=o.timeScale(),l=Math.max(...e.map(a=>a.data.length)),d=()=>{if(l===0)return;const a=r.getVisibleLogicalRange();if(!a)return;const f={from:0,to:l-1},b=typeof a.from=="number"?a.from:0,x=typeof a.to=="number"?a.to:l-1;if(W.current){const g=Math.max(0,Math.floor(b)),s=Math.min(l-1,Math.ceil(x)),u=[];for(const c of e)for(let h=g;h<=s&&h<c.data.length;h++)u.push(c.data[h].value);u.length>0&&W.current(u)}const v=.01;let j=!1;const y={...a};b<f.from-v&&(y.from=f.from,j=!0),x>f.to+v&&(y.to=f.to,j=!0),j&&r.setVisibleLogicalRange(y)};return r.subscribeVisibleLogicalRangeChange(d),()=>{r.unsubscribeVisibleLogicalRangeChange(d)}},[e]),i.useEffect(()=>{const o=R.current,r=Array.from(S.current.values()),l=[];if(o&&r.length>0&&I){const d=Y.getDefaultVerticalLine(),a=r[0];for(const f of I){const b=new xe.VertLine(o,a,f.xCoordinate,{...d,...f.options||{}});a.attachPrimitive(b),l.push(b)}}return()=>{if(r.length>0){const d=r[0];for(const a of l)d.detachPrimitive(a)}}},[I]);const J=e.length===1,ie=re.useMemo(()=>{if(J&&e.length>0){const o=e[0];if(o.data.length>0)return o.data[o.data.length-1]}},[J,e]);return m.jsxs("div",{ref:F,className:ce.cn("relative z-[1] w-full h-full overflow-hidden p-0",V),children:[J&&ie&&m.jsx(Ce.GraphCurrentValue,{point:ie,xMeasureUnit:L,yMeasureUnit:q}),le&&se&&m.jsx(Se.GraphTooltip,{points:le,xMeasureUnit:L,yMeasureUnit:q,series:e,position:se,containerRef:F}),p&&m.jsx(we,{series:e,onUnselect:A}),m.jsx("div",{ref:Z,className:"LightweightChart w-full h-full overflow-hidden"})]})}function we({series:e,onUnselect:V}){return m.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((p,A)=>{const L=H[A%H.length],q=p.color||L.line,D=p.data.length===0;return m.jsxs("div",{className:ce.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",D&&"opacity-50"),children:[m.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:q}}),m.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[p.label,D&&" (no data)"]}),V&&m.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),V(p.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 ${p.label}`,children:m.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:[m.jsx("title",{children:"Close"}),m.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),m.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},p.label)})})}exports.DEFAULT_SERIES_COLORS=H;exports.Graph=ye;
|
|
@@ -22,6 +22,7 @@ function i() {
|
|
|
22
22
|
visible: !0
|
|
23
23
|
},
|
|
24
24
|
rightPriceScale: {
|
|
25
|
+
visible: !0,
|
|
25
26
|
autoScale: !0,
|
|
26
27
|
alignLabels: !0,
|
|
27
28
|
borderVisible: !0,
|
|
@@ -87,6 +88,7 @@ const b = {
|
|
|
87
88
|
visible: !0
|
|
88
89
|
},
|
|
89
90
|
rightPriceScale: {
|
|
91
|
+
visible: !0,
|
|
90
92
|
autoScale: !0,
|
|
91
93
|
alignLabels: !0,
|
|
92
94
|
borderVisible: !0,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as Y, jsx as S } from "react/jsx-runtime";
|
|
2
2
|
import { createChart as xt } from "lightweight-charts";
|
|
3
3
|
import * as ot from "react";
|
|
4
|
-
import { useRef as C, useState as ct, useEffect as
|
|
5
|
-
import { useIsMobile as
|
|
4
|
+
import { useRef as C, useState as ct, useEffect as O } from "react";
|
|
5
|
+
import { useIsMobile as yt } from "../../hooks/use-media-query.js";
|
|
6
6
|
import { cn as gt } from "../../utils/cn.js";
|
|
7
7
|
import { resolveCSSColor as ut, generateColorsFromBase as rt } from "../../utils/colors.js";
|
|
8
|
-
import { getDefaultOptions as ft, getDefaultSeries as
|
|
8
|
+
import { getDefaultOptions as ft, getDefaultSeries as Rt, getDefaultVerticalLine as wt } from "./default-config.js";
|
|
9
9
|
import { getXFormatter as dt, createAdaptiveYAxisFormatter as Vt } from "./formatters.js";
|
|
10
10
|
import { GraphCurrentValue as Lt } from "./graph-current-value.js";
|
|
11
11
|
import { GraphTooltip as Pt } from "./graph-tooltip.js";
|
|
12
12
|
import { VertLine as Mt } from "./plugins/vertical-line.js";
|
|
13
|
-
const
|
|
13
|
+
const $ = [
|
|
14
14
|
{
|
|
15
15
|
line: "#02c39a",
|
|
16
16
|
top: "rgba(2, 195, 154, 0.56)",
|
|
@@ -53,41 +53,41 @@ const Y = [
|
|
|
53
53
|
}
|
|
54
54
|
];
|
|
55
55
|
function Ht({
|
|
56
|
-
series:
|
|
56
|
+
series: o,
|
|
57
57
|
className: H,
|
|
58
|
-
showLegend:
|
|
58
|
+
showLegend: w = !1,
|
|
59
59
|
onUnselectSeries: q,
|
|
60
60
|
xMeasureUnit: V = "time",
|
|
61
|
-
yMeasureUnit:
|
|
61
|
+
yMeasureUnit: D = "token",
|
|
62
62
|
optionsOverrides: E,
|
|
63
63
|
verticalLineOptions: j
|
|
64
64
|
}) {
|
|
65
65
|
const x = C(null), b = C(/* @__PURE__ */ new Map()), W = C(!1), X = C(/* @__PURE__ */ new Set()), nt = C(0), at = C(!0), Z = C(
|
|
66
66
|
null
|
|
67
|
-
), mt = C(null),
|
|
68
|
-
if (
|
|
69
|
-
const e =
|
|
67
|
+
), mt = C(null), A = C(null), _ = C(null), k = yt(), L = ot.useMemo(() => o.flatMap((e) => e.data), [o]), ht = ot.useMemo(() => {
|
|
68
|
+
if (o.length > 0) {
|
|
69
|
+
const e = o[o.length - 1];
|
|
70
70
|
if (e.data.length > 0)
|
|
71
71
|
return e.data[e.data.length - 1];
|
|
72
72
|
}
|
|
73
|
-
}, [
|
|
73
|
+
}, [o]), [lt, J] = ct(() => {
|
|
74
74
|
if (!ht) return;
|
|
75
75
|
const e = /* @__PURE__ */ new Map();
|
|
76
|
-
for (const r of
|
|
76
|
+
for (const r of o)
|
|
77
77
|
r.data.length > 0 && e.set(r.label, r.data[r.data.length - 1]);
|
|
78
78
|
return e;
|
|
79
79
|
}), [it, P] = ct(null);
|
|
80
|
-
|
|
80
|
+
O(() => {
|
|
81
81
|
const e = () => {
|
|
82
|
-
if (x.current &&
|
|
83
|
-
const
|
|
84
|
-
x.current.resize(
|
|
82
|
+
if (x.current && A.current) {
|
|
83
|
+
const d = A.current.clientWidth, a = A.current.clientHeight;
|
|
84
|
+
x.current.resize(d, a), x.current.timeScale().fitContent();
|
|
85
85
|
}
|
|
86
|
-
}, r =
|
|
86
|
+
}, r = A.current, l = r ? new ResizeObserver(e) : null;
|
|
87
87
|
return r && l?.observe(r), () => {
|
|
88
88
|
r && l?.unobserve(r);
|
|
89
89
|
};
|
|
90
|
-
}, []),
|
|
90
|
+
}, []), O(() => {
|
|
91
91
|
if (!_.current || W.current) return;
|
|
92
92
|
const e = ft(), r = ut(
|
|
93
93
|
"hsl(var(--foreground))",
|
|
@@ -96,7 +96,7 @@ function Ht({
|
|
|
96
96
|
...e,
|
|
97
97
|
rightPriceScale: {
|
|
98
98
|
...e.rightPriceScale || {},
|
|
99
|
-
visible: !
|
|
99
|
+
visible: !k,
|
|
100
100
|
textColor: r
|
|
101
101
|
},
|
|
102
102
|
...E
|
|
@@ -104,16 +104,16 @@ function Ht({
|
|
|
104
104
|
return x.current = l, W.current = !0, () => {
|
|
105
105
|
l.remove(), x.current = null, W.current = !1, b.current.clear();
|
|
106
106
|
};
|
|
107
|
-
}, [
|
|
107
|
+
}, [k, E]), O(() => {
|
|
108
108
|
const e = x.current;
|
|
109
|
-
if (!e ||
|
|
110
|
-
const r = V === "time" ? dt(V, L) : dt(V), l = L.map((
|
|
111
|
-
formatter:
|
|
109
|
+
if (!e || o.length === 0) return;
|
|
110
|
+
const r = V === "time" ? dt(V, L) : dt(V), l = L.map((t) => t.value), {
|
|
111
|
+
formatter: d,
|
|
112
112
|
updateVisibleRange: a,
|
|
113
113
|
updateLastValues: u
|
|
114
114
|
} = Vt(l);
|
|
115
115
|
Z.current = a, mt.current = u;
|
|
116
|
-
const m =
|
|
116
|
+
const m = o.filter((t) => t.data.length > 0).map((t) => t.data[t.data.length - 1].value);
|
|
117
117
|
u(m);
|
|
118
118
|
const v = ft();
|
|
119
119
|
e.applyOptions({
|
|
@@ -121,28 +121,28 @@ function Ht({
|
|
|
121
121
|
...v.localization || {},
|
|
122
122
|
timeFormatter: r ? (
|
|
123
123
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
124
|
-
((
|
|
124
|
+
((t) => r(parseFloat(t), void 0))
|
|
125
125
|
) : void 0
|
|
126
126
|
},
|
|
127
127
|
timeScale: {
|
|
128
128
|
...v.timeScale || {},
|
|
129
129
|
tickMarkFormatter: r ? (
|
|
130
130
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
131
|
-
((
|
|
131
|
+
((t) => r(parseFloat(t), void 0))
|
|
132
132
|
) : void 0,
|
|
133
133
|
minBarSpacing: 0
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
|
-
const M = (L.length > 0 ? Math.min(...L.map((
|
|
136
|
+
const M = (L.length > 0 ? Math.min(...L.map((t) => t.value)) : 0) < 0, y = L.some((t) => t.value === 0), f = !M && y, i = o.length > 1, c = i || k, s = ut(
|
|
137
137
|
"hsl(var(--foreground))",
|
|
138
138
|
"rgb(0, 0, 0)"
|
|
139
139
|
);
|
|
140
140
|
e.applyOptions({
|
|
141
141
|
rightPriceScale: {
|
|
142
142
|
...v.rightPriceScale || {},
|
|
143
|
-
visible: !
|
|
143
|
+
visible: !c,
|
|
144
144
|
textColor: s,
|
|
145
|
-
...
|
|
145
|
+
...f && {
|
|
146
146
|
scaleMargins: {
|
|
147
147
|
top: 0.3,
|
|
148
148
|
bottom: 0
|
|
@@ -150,37 +150,37 @@ function Ht({
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
-
const g = new Set(b.current.keys()),
|
|
154
|
-
for (const
|
|
155
|
-
if (!
|
|
156
|
-
const n = b.current.get(
|
|
157
|
-
n && (e.removeSeries(n), b.current.delete(
|
|
153
|
+
const g = new Set(b.current.keys()), R = new Set(o.map((t) => t.label));
|
|
154
|
+
for (const t of g)
|
|
155
|
+
if (!R.has(t)) {
|
|
156
|
+
const n = b.current.get(t);
|
|
157
|
+
n && (e.removeSeries(n), b.current.delete(t));
|
|
158
158
|
}
|
|
159
|
-
const
|
|
159
|
+
const F = Rt(), B = [];
|
|
160
160
|
let I = 0;
|
|
161
|
-
for (let
|
|
162
|
-
const n = t
|
|
163
|
-
let
|
|
161
|
+
for (let t = 0; t < o.length; t++) {
|
|
162
|
+
const n = o[t], tt = $[t % $.length], G = n.color || tt.line;
|
|
163
|
+
let N, T;
|
|
164
164
|
if (n.color)
|
|
165
165
|
if (n.topColor && n.bottomColor)
|
|
166
|
-
|
|
166
|
+
N = n.topColor, T = n.bottomColor;
|
|
167
167
|
else if (n.topColor) {
|
|
168
168
|
const p = rt(G);
|
|
169
|
-
|
|
169
|
+
N = n.topColor, T = p.bottomColor;
|
|
170
170
|
} else if (n.bottomColor)
|
|
171
|
-
|
|
171
|
+
N = rt(G).topColor, T = n.bottomColor;
|
|
172
172
|
else {
|
|
173
173
|
const p = rt(G);
|
|
174
|
-
|
|
174
|
+
N = p.topColor, T = p.bottomColor;
|
|
175
175
|
}
|
|
176
176
|
else
|
|
177
|
-
|
|
177
|
+
N = n.topColor || tt.top, T = n.bottomColor || tt.bottom;
|
|
178
178
|
if (n.data.length === 0) {
|
|
179
179
|
const p = b.current.get(n.label);
|
|
180
180
|
p && (e.removeSeries(p), b.current.delete(n.label));
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
183
|
-
const vt = (n.data.length > 0 ? Math.min(...n.data.map((p) => p.value)) : 0) < 0, Ct = n.data.some((p) => p.value === 0), St = !vt && Ct, et = i ? I === 0 ?
|
|
183
|
+
const vt = (n.data.length > 0 ? Math.min(...n.data.map((p) => p.value)) : 0) < 0, Ct = n.data.some((p) => p.value === 0), St = !vt && Ct, et = i ? I === 0 ? "right" : `scale-${I}` : "right";
|
|
184
184
|
i && B.push({
|
|
185
185
|
priceScaleId: et || "right",
|
|
186
186
|
shouldPreventNegativeAxis: St,
|
|
@@ -189,36 +189,36 @@ function Ht({
|
|
|
189
189
|
let z = b.current.get(n.label);
|
|
190
190
|
z ? (z.applyOptions({
|
|
191
191
|
lineColor: G,
|
|
192
|
-
topColor:
|
|
193
|
-
bottomColor:
|
|
192
|
+
topColor: N,
|
|
193
|
+
bottomColor: T,
|
|
194
194
|
priceScaleId: et,
|
|
195
195
|
priceFormat: {
|
|
196
196
|
type: "custom",
|
|
197
|
-
formatter:
|
|
197
|
+
formatter: d
|
|
198
198
|
}
|
|
199
199
|
}), z.setData(n.data)) : (z = e.addAreaSeries({
|
|
200
|
-
...
|
|
200
|
+
...F,
|
|
201
201
|
lineColor: G,
|
|
202
|
-
topColor:
|
|
203
|
-
bottomColor:
|
|
202
|
+
topColor: N,
|
|
203
|
+
bottomColor: T,
|
|
204
204
|
priceScaleId: et,
|
|
205
205
|
priceFormat: {
|
|
206
206
|
type: "custom",
|
|
207
|
-
formatter:
|
|
207
|
+
formatter: d
|
|
208
208
|
}
|
|
209
209
|
}), z.setData(n.data), b.current.set(n.label, z)), I++;
|
|
210
210
|
}
|
|
211
211
|
if (i && B.length > 0)
|
|
212
|
-
for (const
|
|
212
|
+
for (const t of B)
|
|
213
213
|
try {
|
|
214
|
-
const n = e.priceScale(
|
|
214
|
+
const n = e.priceScale(t.priceScaleId);
|
|
215
215
|
n && n.applyOptions({
|
|
216
|
-
visible: !
|
|
216
|
+
visible: !1,
|
|
217
217
|
autoScale: !0,
|
|
218
218
|
scaleMargins: {
|
|
219
219
|
top: 0.1,
|
|
220
220
|
bottom: 0.1,
|
|
221
|
-
...
|
|
221
|
+
...t.shouldPreventNegativeAxis && {
|
|
222
222
|
top: 0.3,
|
|
223
223
|
bottom: 0
|
|
224
224
|
}
|
|
@@ -231,62 +231,84 @@ function Ht({
|
|
|
231
231
|
});
|
|
232
232
|
} catch (n) {
|
|
233
233
|
console.warn(
|
|
234
|
-
`Failed to configure price scale ${
|
|
234
|
+
`Failed to configure price scale ${t.priceScaleId} for series ${t.seriesIndex}:`,
|
|
235
235
|
n
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
else if (!i)
|
|
239
|
+
try {
|
|
240
|
+
const t = e.priceScale("right");
|
|
241
|
+
t && t.applyOptions({
|
|
242
|
+
visible: !k,
|
|
243
|
+
autoScale: !0,
|
|
244
|
+
scaleMargins: {
|
|
245
|
+
top: 0.1,
|
|
246
|
+
bottom: 0.1,
|
|
247
|
+
...f && {
|
|
248
|
+
top: 0.3,
|
|
249
|
+
bottom: 0
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
alignLabels: !0,
|
|
253
|
+
borderVisible: !0,
|
|
254
|
+
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
255
|
+
entireTextOnly: !1,
|
|
256
|
+
textColor: s
|
|
257
|
+
});
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
const Q = new Set(o.map((t) => t.label)), pt = Q.size !== X.current.size || [...Q].some((t) => !X.current.has(t)), bt = L.length !== nt.current;
|
|
261
|
+
(at.current || pt || bt || k) && (e.timeScale().fitContent(), at.current = !1), X.current = Q, nt.current = L.length;
|
|
240
262
|
const U = /* @__PURE__ */ new Map();
|
|
241
|
-
for (const
|
|
242
|
-
|
|
263
|
+
for (const t of o)
|
|
264
|
+
t.data.length > 0 && U.set(t.label, t.data[t.data.length - 1]);
|
|
243
265
|
J(U.size > 0 ? U : void 0);
|
|
244
|
-
}, [
|
|
266
|
+
}, [o, L, V, D, k]), O(() => {
|
|
245
267
|
const e = x.current;
|
|
246
|
-
if (!e ||
|
|
247
|
-
const r =
|
|
268
|
+
if (!e || o.length === 0) return;
|
|
269
|
+
const r = o.length === 1;
|
|
248
270
|
let l;
|
|
249
|
-
for (const a of
|
|
271
|
+
for (const a of o)
|
|
250
272
|
if (a.data.length > 0) {
|
|
251
273
|
l = a.data[a.data.length - 1].time;
|
|
252
274
|
break;
|
|
253
275
|
}
|
|
254
276
|
if (!l) return;
|
|
255
|
-
const
|
|
277
|
+
const d = (a) => {
|
|
256
278
|
const { time: u = l, seriesData: m, point: v } = a || {}, h = Array.from(b.current.values());
|
|
257
279
|
if (!v || !u) {
|
|
258
|
-
const
|
|
259
|
-
for (const i of
|
|
260
|
-
i.data.length > 0 &&
|
|
261
|
-
if (J(
|
|
280
|
+
const f = /* @__PURE__ */ new Map();
|
|
281
|
+
for (const i of o)
|
|
282
|
+
i.data.length > 0 && f.set(i.label, i.data[i.data.length - 1]);
|
|
283
|
+
if (J(f.size > 0 ? f : void 0), r)
|
|
262
284
|
P(null);
|
|
263
285
|
else if (h[0] && l) {
|
|
264
|
-
const c = e.timeScale().timeToCoordinate(l), s =
|
|
286
|
+
const c = e.timeScale().timeToCoordinate(l), s = o[0];
|
|
265
287
|
if (s.data.length > 0) {
|
|
266
|
-
const g = s.data[s.data.length - 1].value,
|
|
267
|
-
c !== null &&
|
|
288
|
+
const g = s.data[s.data.length - 1].value, R = h[0].priceToCoordinate(g);
|
|
289
|
+
c !== null && R !== null && P({ x: c, y: R });
|
|
268
290
|
}
|
|
269
291
|
}
|
|
270
292
|
return;
|
|
271
293
|
}
|
|
272
294
|
const M = /* @__PURE__ */ new Map();
|
|
273
|
-
let
|
|
274
|
-
for (let
|
|
275
|
-
const i =
|
|
295
|
+
let y;
|
|
296
|
+
for (let f = 0; f < o.length; f++) {
|
|
297
|
+
const i = o[f], c = h[f];
|
|
276
298
|
if (!c) continue;
|
|
277
|
-
const s = m?.get(c), g = s && "value" in s ? s.value : void 0,
|
|
278
|
-
|
|
299
|
+
const s = m?.get(c), g = s && "value" in s ? s.value : void 0, R = i.data[i.data.length - 1], F = g !== void 0 ? g : R?.value ?? 0;
|
|
300
|
+
f === 0 && (y = F), M.set(i.label, { value: F, time: u });
|
|
279
301
|
}
|
|
280
|
-
if (J(M),
|
|
281
|
-
const i = e.timeScale().timeToCoordinate(u), c = h[0].priceToCoordinate(
|
|
302
|
+
if (J(M), y !== void 0 && h[0]) {
|
|
303
|
+
const i = e.timeScale().timeToCoordinate(u), c = h[0].priceToCoordinate(y);
|
|
282
304
|
if (i !== null && c !== null) {
|
|
283
|
-
const s =
|
|
305
|
+
const s = A.current;
|
|
284
306
|
if (s) {
|
|
285
307
|
const g = s.querySelector(
|
|
286
308
|
".LightweightChart"
|
|
287
309
|
);
|
|
288
310
|
if (g) {
|
|
289
|
-
const
|
|
311
|
+
const R = g.getBoundingClientRect(), F = s.getBoundingClientRect(), B = i + (R.left - F.left), I = c + (R.top - F.top);
|
|
290
312
|
P({ x: B, y: I });
|
|
291
313
|
} else
|
|
292
314
|
P({ x: i, y: c });
|
|
@@ -297,19 +319,19 @@ function Ht({
|
|
|
297
319
|
} else
|
|
298
320
|
P(null);
|
|
299
321
|
};
|
|
300
|
-
return e.subscribeCrosshairMove(
|
|
322
|
+
return e.subscribeCrosshairMove(d), r || requestAnimationFrame(() => {
|
|
301
323
|
const a = Array.from(b.current.values());
|
|
302
|
-
if (a[0] && l &&
|
|
303
|
-
const m = e.timeScale().timeToCoordinate(l), v =
|
|
324
|
+
if (a[0] && l && o[0]?.data.length > 0) {
|
|
325
|
+
const m = e.timeScale().timeToCoordinate(l), v = o[0].data[o[0].data.length - 1].value, h = a[0].priceToCoordinate(v);
|
|
304
326
|
m !== null && h !== null && P({ x: m, y: h });
|
|
305
327
|
}
|
|
306
328
|
}), () => {
|
|
307
|
-
e.unsubscribeCrosshairMove(
|
|
329
|
+
e.unsubscribeCrosshairMove(d);
|
|
308
330
|
};
|
|
309
|
-
}, [
|
|
331
|
+
}, [o]), O(() => {
|
|
310
332
|
const e = x.current;
|
|
311
|
-
if (!e ||
|
|
312
|
-
const r = e.timeScale(), l = Math.max(...
|
|
333
|
+
if (!e || o.length === 0) return;
|
|
334
|
+
const r = e.timeScale(), l = Math.max(...o.map((a) => a.data.length)), d = () => {
|
|
313
335
|
if (l === 0) return;
|
|
314
336
|
const a = r.getVisibleLogicalRange();
|
|
315
337
|
if (!a) return;
|
|
@@ -318,29 +340,29 @@ function Ht({
|
|
|
318
340
|
to: l - 1
|
|
319
341
|
}, m = typeof a.from == "number" ? a.from : 0, v = typeof a.to == "number" ? a.to : l - 1;
|
|
320
342
|
if (Z.current) {
|
|
321
|
-
const
|
|
322
|
-
for (const s of
|
|
323
|
-
for (let g =
|
|
343
|
+
const f = Math.max(0, Math.floor(m)), i = Math.min(l - 1, Math.ceil(v)), c = [];
|
|
344
|
+
for (const s of o)
|
|
345
|
+
for (let g = f; g <= i && g < s.data.length; g++)
|
|
324
346
|
c.push(s.data[g].value);
|
|
325
347
|
c.length > 0 && Z.current(c);
|
|
326
348
|
}
|
|
327
349
|
const h = 0.01;
|
|
328
350
|
let M = !1;
|
|
329
|
-
const
|
|
330
|
-
m < u.from - h && (
|
|
351
|
+
const y = { ...a };
|
|
352
|
+
m < u.from - h && (y.from = u.from, M = !0), v > u.to + h && (y.to = u.to, M = !0), M && r.setVisibleLogicalRange(y);
|
|
331
353
|
};
|
|
332
|
-
return r.subscribeVisibleLogicalRangeChange(
|
|
354
|
+
return r.subscribeVisibleLogicalRangeChange(d), () => {
|
|
333
355
|
r.unsubscribeVisibleLogicalRangeChange(
|
|
334
|
-
|
|
356
|
+
d
|
|
335
357
|
);
|
|
336
358
|
};
|
|
337
|
-
}, [
|
|
359
|
+
}, [o]), O(() => {
|
|
338
360
|
const e = x.current, r = Array.from(b.current.values()), l = [];
|
|
339
361
|
if (e && r.length > 0 && j) {
|
|
340
|
-
const
|
|
362
|
+
const d = wt(), a = r[0];
|
|
341
363
|
for (const u of j) {
|
|
342
364
|
const m = new Mt(e, a, u.xCoordinate, {
|
|
343
|
-
...
|
|
365
|
+
...d,
|
|
344
366
|
...u.options || {}
|
|
345
367
|
});
|
|
346
368
|
a.attachPrimitive(m), l.push(m);
|
|
@@ -348,23 +370,23 @@ function Ht({
|
|
|
348
370
|
}
|
|
349
371
|
return () => {
|
|
350
372
|
if (r.length > 0) {
|
|
351
|
-
const
|
|
373
|
+
const d = r[0];
|
|
352
374
|
for (const a of l)
|
|
353
|
-
|
|
375
|
+
d.detachPrimitive(a);
|
|
354
376
|
}
|
|
355
377
|
};
|
|
356
378
|
}, [j]);
|
|
357
|
-
const K =
|
|
358
|
-
if (K &&
|
|
359
|
-
const e =
|
|
379
|
+
const K = o.length === 1, st = ot.useMemo(() => {
|
|
380
|
+
if (K && o.length > 0) {
|
|
381
|
+
const e = o[0];
|
|
360
382
|
if (e.data.length > 0)
|
|
361
383
|
return e.data[e.data.length - 1];
|
|
362
384
|
}
|
|
363
|
-
}, [K,
|
|
364
|
-
return /* @__PURE__ */
|
|
385
|
+
}, [K, o]);
|
|
386
|
+
return /* @__PURE__ */ Y(
|
|
365
387
|
"div",
|
|
366
388
|
{
|
|
367
|
-
ref:
|
|
389
|
+
ref: A,
|
|
368
390
|
className: gt(
|
|
369
391
|
"relative z-[1] w-full h-full overflow-hidden p-0",
|
|
370
392
|
H
|
|
@@ -375,7 +397,7 @@ function Ht({
|
|
|
375
397
|
{
|
|
376
398
|
point: st,
|
|
377
399
|
xMeasureUnit: V,
|
|
378
|
-
yMeasureUnit:
|
|
400
|
+
yMeasureUnit: D
|
|
379
401
|
}
|
|
380
402
|
),
|
|
381
403
|
lt && it && /* @__PURE__ */ S(
|
|
@@ -383,13 +405,13 @@ function Ht({
|
|
|
383
405
|
{
|
|
384
406
|
points: lt,
|
|
385
407
|
xMeasureUnit: V,
|
|
386
|
-
yMeasureUnit:
|
|
387
|
-
series:
|
|
408
|
+
yMeasureUnit: D,
|
|
409
|
+
series: o,
|
|
388
410
|
position: it,
|
|
389
|
-
containerRef:
|
|
411
|
+
containerRef: A
|
|
390
412
|
}
|
|
391
413
|
),
|
|
392
|
-
|
|
414
|
+
w && /* @__PURE__ */ S(At, { series: o, onUnselect: q }),
|
|
393
415
|
/* @__PURE__ */ S(
|
|
394
416
|
"div",
|
|
395
417
|
{
|
|
@@ -401,13 +423,13 @@ function Ht({
|
|
|
401
423
|
}
|
|
402
424
|
);
|
|
403
425
|
}
|
|
404
|
-
function
|
|
405
|
-
series:
|
|
426
|
+
function At({
|
|
427
|
+
series: o,
|
|
406
428
|
onUnselect: H
|
|
407
429
|
}) {
|
|
408
|
-
return /* @__PURE__ */ S("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children:
|
|
409
|
-
const V =
|
|
410
|
-
return /* @__PURE__ */
|
|
430
|
+
return /* @__PURE__ */ S("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: o.map((w, q) => {
|
|
431
|
+
const V = $[q % $.length], D = w.color || V.line, E = w.data.length === 0;
|
|
432
|
+
return /* @__PURE__ */ Y(
|
|
411
433
|
"div",
|
|
412
434
|
{
|
|
413
435
|
className: gt(
|
|
@@ -419,11 +441,11 @@ function Ft({
|
|
|
419
441
|
"div",
|
|
420
442
|
{
|
|
421
443
|
className: "w-3 h-3 rounded-sm",
|
|
422
|
-
style: { backgroundColor:
|
|
444
|
+
style: { backgroundColor: D }
|
|
423
445
|
}
|
|
424
446
|
),
|
|
425
|
-
/* @__PURE__ */
|
|
426
|
-
|
|
447
|
+
/* @__PURE__ */ Y("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
|
|
448
|
+
w.label,
|
|
427
449
|
E && " (no data)"
|
|
428
450
|
] }),
|
|
429
451
|
H && /* @__PURE__ */ S(
|
|
@@ -431,11 +453,11 @@ function Ft({
|
|
|
431
453
|
{
|
|
432
454
|
type: "button",
|
|
433
455
|
onClick: (j) => {
|
|
434
|
-
j.stopPropagation(), H(
|
|
456
|
+
j.stopPropagation(), H(w.label);
|
|
435
457
|
},
|
|
436
458
|
className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
|
|
437
|
-
"aria-label": `Remove ${
|
|
438
|
-
children: /* @__PURE__ */
|
|
459
|
+
"aria-label": `Remove ${w.label}`,
|
|
460
|
+
children: /* @__PURE__ */ Y(
|
|
439
461
|
"svg",
|
|
440
462
|
{
|
|
441
463
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -460,11 +482,11 @@ function Ft({
|
|
|
460
482
|
)
|
|
461
483
|
]
|
|
462
484
|
},
|
|
463
|
-
|
|
485
|
+
w.label
|
|
464
486
|
);
|
|
465
487
|
}) });
|
|
466
488
|
}
|
|
467
489
|
export {
|
|
468
|
-
|
|
490
|
+
$ as DEFAULT_SERIES_COLORS,
|
|
469
491
|
Ht as Graph
|
|
470
492
|
};
|