@gearbox-protocol/ui-kit 3.1.0-next.2 → 3.2.0-next.1
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 g=require("react/jsx-runtime"),se=require("lightweight-charts"),f=require("react"),Te=require("../../hooks/use-media-query.cjs"),ce=require("../../utils/cn.cjs"),O=require("../../utils/colors.cjs"),X=require("./default-config.cjs"),$=require("./formatters.cjs"),Fe=require("./graph-current-value.cjs"),Me=require("./graph-tooltip.cjs"),Ee=require("./plugins/vertical-line.cjs");function _e(e){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const c in e)if(c!=="default"){const R=Object.getOwnPropertyDescriptor(e,c);Object.defineProperty(m,c,R.get?R:{enumerable:!0,get:()=>e[c]})}}return m.default=e,Object.freeze(m)}const ie=_e(f);function Re(e,m,c){const R=e.labelText??"",b=e.value,w=b===void 0?"":typeof b=="number"?m==="$"?`$${$.formatExactValue(b,void 0,c)}`:m==="%"?`${$.formatExactValue(b,void 0,c)}%`:$.formatExactValue(b,m!=="none"&&m!=="%"&&m!=="$"?m:void 0,c):String(b);return{labelText:R,valueStr:w}}const Z=[{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)"}],Ae=137.5;function ue(e){if(e<Z.length)return Z[e];const c=(e-Z.length)*Ae%360,R=O.hslToHex(c,70,50),{topColor:b,bottomColor:w}=O.generateColorsFromBase(R);return{line:R,top:b,bottom:w}}function Oe({series:e,className:m,showLegend:c=!1,onUnselectSeries:R,xMeasureUnit:b="time",yMeasureUnit:w="token",optionsOverrides:B,verticalLineOptions:x,currentValueDecimals:K,useSharedPriceScale:j=!1,showCurrentValue:we=!0,graphTitle:Q,yScaleMin:fe,yScaleMinMultiple:ge}){const N=f.useRef(null),y=f.useRef(new Map),J=f.useRef(!1),de=f.useRef(!0),U=f.useRef(null),ye=f.useRef(null),A=f.useRef(null),ee=f.useRef(null),Y=f.useRef(null),k=Te.useIsMobile(),E=ie.useMemo(()=>e.flatMap(t=>t.data),[e]),Ve=ie.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[be,te]=f.useState(()=>{if(!Ve)return;const t=new Map;for(const a of e)a.data.length>0&&t.set(a.label,a.data[a.data.length-1]);return t}),[me,_]=f.useState(null),[he,pe]=f.useState([]);f.useEffect(()=>{const t=()=>{try{if(N.current&&A.current){const l=A.current.clientWidth,i=A.current.clientHeight;N.current.resize(l,i)}}catch{}},a=A.current,r=a?new ResizeObserver(t):null;return Y.current=r,a&&r?.observe(a),()=>{a&&r?.unobserve(a),r?.disconnect(),Y.current=null}},[]),f.useEffect(()=>{if(!ee.current||J.current)return;const t=X.getDefaultOptions(),a=O.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),r=se.createChart(ee.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!k,textColor:a},...k&&{crosshair:{...t.crosshair,mode:se.CrosshairMode.Magnet}},...B});return N.current=r,J.current=!0,()=>{Y.current?.disconnect(),Y.current=null,r.remove(),N.current=null,J.current=!1,y.current.clear()}},[k,B]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const r=e.filter(o=>o.data.length>0).length<=1?fe:ge,l=b==="time"?$.getXFormatters(b,E):$.getXFormatters(b),i=E.map(o=>o.value),{formatter:u,tickmarksFormatter:d,updateVisibleRange:P,updateLastValues:h}=$.createAdaptiveYAxisFormatter(i,w,{yScaleMin:r});U.current=P,ye.current=h;const L=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);h(L);const T=X.getDefaultOptions();t.applyOptions({localization:{...T.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...T.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const p=(E.length>0?Math.min(...E.map(o=>o.value)):0)<0,S=E.some(o=>o.value===0),C=!p&&S,v=e.length>1&&!j,F=e.length>1&&!j||k,M=O.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...T.rightPriceScale||{},visible:!F,textColor:M,...C&&{scaleMargins:{top:.3,bottom:0}}}});const oe=new Set(y.current.keys()),re=new Set(e.map(o=>o.label));for(const o of oe)if(!re.has(o)){const n=y.current.get(o);n&&(t.removeSeries(n),y.current.delete(o))}const ke=X.getDefaultSeries(),ne=[];let W=0;for(let o=0;o<e.length;o++){const n=e[o],G=ue(o),I=n.lineColor??n.color??G.line;let D,q;if(n.lineColor??n.color)if(n.topColor&&n.bottomColor)D=n.topColor,q=n.bottomColor;else if(n.topColor){const s=O.generateColorsFromBase(I);D=n.topColor,q=s.bottomColor}else if(n.bottomColor)D=O.generateColorsFromBase(I).topColor,q=n.bottomColor;else{const s=O.generateColorsFromBase(I);D=s.topColor,q=s.bottomColor}else D=n.topColor||G.top,q=n.bottomColor||G.bottom;if(n.data.length===0){const s=y.current.get(n.label);s&&(t.removeSeries(s),y.current.delete(n.label));continue}const je=(n.data.length>0?Math.min(...n.data.map(s=>s.value)):0)<0,Ne=n.data.some(s=>s.value===0),Pe=!je&&Ne,ve=j||!v||W===0?"right":`scale-${W}`;v&&ne.push({priceScaleId:ve||"right",shouldPreventNegativeAxis:Pe,seriesIndex:W});const xe=(j||!v)&&r!==void 0&&typeof r=="number",Se={lineColor:I,topColor:D,bottomColor:q,priceScaleId:ve,priceFormat:{type:"custom",minMove:.01,formatter:xe&&typeof r=="number"?s=>u(s<r?r:s):u,tickmarksFormatter:d},autoscaleInfoProvider:s=>{if(!xe)return s();const le=s();if(le?.priceRange){const Le=r;le.priceRange.minValue=Le}return le}};let z=y.current.get(n.label);z?(z.applyOptions(Se),z.setData(n.data.map(s=>({...s,time:s.time})))):(z=t.addSeries(se.AreaSeries,{...ke,...Se}),z.setData(n.data.map(s=>({...s,time:s.time}))),y.current.set(n.label,z)),W++}if(v&&ne.length>0)for(const o of ne)try{const n=t.priceScale(o.priceScaleId);n&&n.applyOptions({visible:!1,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:M})}catch(n){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,n)}else if(!v)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!k,autoScale:!0,scaleMargins:{top:.1,bottom:r!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:M})}catch{}if(r!==void 0&&!k&&(j||!v)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),E.length>0){const o=E.map(I=>Number(I.time)),n=Math.min(...o),G=Math.max(...o);t.timeScale().setVisibleRange({from:n,to:G})}de.current&&(de.current=!1);const ae=new Map;for(const o of e)o.data.length>0&&ae.set(o.label,o.data[o.data.length-1]);te(ae.size>0?ae:void 0)},[e,E,b,w,k,j,fe,ge]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const a=e.length===1;let r;for(const i of e)if(i.data.length>0){r=i.data[i.data.length-1].time;break}if(!r)return;const l=i=>{const{time:u=r,seriesData:d,point:P}=i||{},h=Array.from(y.current.values());if(!P||!u){const V=new Map;for(const p of e)p.data.length>0&&V.set(p.label,p.data[p.data.length-1]);if(te(V.size>0?V:void 0),a||j)_(null);else if(h[0]&&r){const S=t.timeScale().timeToCoordinate(r),C=e[0];if(C.data.length>0){const v=C.data[C.data.length-1].value,F=h[0].priceToCoordinate(v);S!==null&&F!==null&&_({x:S,y:F})}}return}const L=new Map;let T;for(let V=0;V<e.length;V++){const p=e[V],S=h[V];if(!S)continue;const C=d?.get(S),v=C&&"value"in C?C.value:void 0,F=p.data[p.data.length-1],M=v!==void 0?v:F?.value??0;V===0&&(T=M),L.set(p.label,{value:M,time:u})}if(te(L),T!==void 0&&h[0]){const p=t.timeScale().timeToCoordinate(u),S=h[0].priceToCoordinate(T);if(p!==null&&S!==null){const C=A.current;if(C){const v=C.querySelector(".LightweightChart");if(v){const F=v.getBoundingClientRect(),M=C.getBoundingClientRect(),oe=p+(F.left-M.left),re=S+(F.top-M.top);_({x:oe,y:re})}else _({x:p,y:S})}else _({x:p,y:S})}else _(null)}else _(null)};return t.subscribeCrosshairMove(l),k&&t.subscribeClick(l),!a&&!j&&requestAnimationFrame(()=>{const i=Array.from(y.current.values());if(i[0]&&r&&e[0]?.data.length>0){const d=t.timeScale().timeToCoordinate(r),P=e[0].data[e[0].data.length-1].value,h=i[0].priceToCoordinate(P);d!==null&&h!==null&&_({x:d,y:h})}}),()=>{t.unsubscribeCrosshairMove(l),k&&t.unsubscribeClick(l)}},[e,j,k]),f.useEffect(()=>{const t=N.current;if(!t||e.length===0)return;const a=t.timeScale(),r=()=>{if(!U.current)return;const l=a.getVisibleRange();if(!l)return;const i=Number(l.from),u=Number(l.to),d=[];for(const P of e)for(const h of P.data){const L=Number(h.time);L>=i&&L<=u&&d.push(h.value)}d.length>0&&U.current(d)};return a.subscribeVisibleLogicalRangeChange(r),()=>{a.unsubscribeVisibleLogicalRangeChange(r)}},[e]),f.useEffect(()=>{const t=N.current,a=Array.from(y.current.values()),r=[];if(t&&a.length>0&&x){const l=X.getDefaultVerticalLine(),i=a[0];for(const u of x){const d=new Ee.VertLine(t,i,u.xCoordinate,{...l,...u.options||{}});i.attachPrimitive(d),r.push(d)}}return()=>{if(a.length>0){const l=a[0];for(const i of r)l.detachPrimitive(i)}}},[x]),f.useEffect(()=>{const t=N.current;if(!t||!x?.length){pe([]);return}const a=()=>{const i=t.timeScale(),u=x.map(d=>i.timeToCoordinate(d.xCoordinate)??null);pe(u)};a();const r=t.timeScale(),l=()=>{a()};return r.subscribeVisibleLogicalRangeChange(l),()=>{r.unsubscribeVisibleLogicalRangeChange(l)}},[x]);const H=e.length===1,Ce=ie.useMemo(()=>{if(H&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[H,e]);return g.jsxs("div",{ref:A,className:ce.cn("relative z-[1] w-full h-full overflow-hidden p-0",m),children:[Q!=null&&Q!==!1&&H?g.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:g.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:Q})}):we&&H&&Ce&&g.jsx(Fe.GraphCurrentValue,{point:Ce,xMeasureUnit:b,yMeasureUnit:w,decimals:K}),be&&me&&g.jsx(Me.GraphTooltip,{points:be,xMeasureUnit:b,yMeasureUnit:w,series:e,position:me,containerRef:A,decimals:K}),c&&g.jsx(Ie,{series:e,onUnselect:R}),x&&x.length>0&&he.length===x.length&&g.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:x.map((t,a)=>{const r=he[a],l=t.options??{},i=l.showLabel!==!1;if(r===null||!i)return null;const{labelText:u,valueStr:d}=Re(l,w,K);if(!(u||d))return null;const h=l.labelBackgroundColor??l.color??"hsl(var(--background))",L=l.labelTextColor??"hsl(var(--foreground))",T=`${String(t.xCoordinate)}-${u}`;return g.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:r,transform:"translateX(-50%)",backgroundColor:h,color:L},children:[u&&g.jsx("span",{className:"block",children:u}),d&&g.jsx("span",{className:ce.cn("block",u&&"mt-0.5"),children:d})]},T)})}),g.jsx("div",{ref:ee,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ie({series:e,onUnselect:m}){return g.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((c,R)=>{const b=ue(R),w=(c.lineColor??c.color)||b.line,B=c.data.length===0;return g.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",B&&"opacity-50"),children:[g.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:w}}),g.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[c.label,B&&" (no data)"]}),m&&g.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),m(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:g.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:[g.jsx("title",{children:"Close"}),g.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),g.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},c.label)})})}exports.DEFAULT_SERIES_COLORS=Z;exports.Graph=Oe;exports.getSeriesColorPalette=ue;exports.getVerticalLineTooltipContent=Re;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),fe=require("lightweight-charts"),f=require("react"),Ae=require("../../hooks/use-media-query.cjs"),de=require("../../utils/cn.cjs"),D=require("../../utils/colors.cjs"),U=require("./default-config.cjs"),H=require("./formatters.cjs"),Oe=require("./graph-current-value.cjs"),De=require("./graph-tooltip.cjs"),qe=require("./plugins/vertical-line.cjs");function ze(e){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const N=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(m,s,N.get?N:{enumerable:!0,get:()=>e[s]})}}return m.default=e,Object.freeze(m)}const ge=ze(f);function ke(e,m,s){const N=e.labelText??"",h=e.value,w=h===void 0?"":typeof h=="number"?m==="$"?`$${H.formatExactValue(h,void 0,s)}`:m==="%"?`${H.formatExactValue(h,void 0,s)}%`:H.formatExactValue(h,m!=="none"&&m!=="%"&&m!=="$"?m:void 0,s):String(h);return{labelText:N,valueStr:w}}function je(e,m){for(let s=e.length-1;s>=0;s--)if(Number(e[s].time)<=m)return e[s].value;return 0}const ee=[{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)"}],$e=137.5;function be(e){if(e<ee.length)return ee[e];const s=(e-ee.length)*$e%360,N=D.hslToHex(s,70,50),{topColor:h,bottomColor:w}=D.generateColorsFromBase(N);return{line:N,top:h,bottom:w}}function Be({series:e,className:m,showLegend:s=!1,onUnselectSeries:N,xMeasureUnit:h="time",yMeasureUnit:w="token",optionsOverrides:W,verticalLineOptions:S,currentValueDecimals:te,useSharedPriceScale:P=!1,showCurrentValue:Pe=!0,graphTitle:oe,yScaleMin:me,yScaleMinMultiple:he,visibleTimeFrom:A}){const L=f.useRef(null),V=f.useRef(new Map),re=f.useRef(!1),pe=f.useRef(!0),ne=f.useRef(null),Le=f.useRef(null),O=f.useRef(null),ae=f.useRef(null),K=f.useRef(null),y=Ae.useIsMobile(),M=ge.useMemo(()=>e.flatMap(t=>t.data),[e]),Te=ge.useMemo(()=>{if(e.length>0){const t=e[e.length-1];if(t.data.length>0)return t.data[t.data.length-1]}},[e]),[Ce,le]=f.useState(()=>{if(!Te)return;const t=new Map;for(const a of e)a.data.length>0&&t.set(a.label,a.data[a.data.length-1]);return t}),[ve,E]=f.useState(null),[xe,Se]=f.useState([]);f.useEffect(()=>{const t=()=>{try{if(L.current&&O.current){const l=O.current.clientWidth,c=O.current.clientHeight;L.current.resize(l,c)}}catch{}},a=O.current,r=a?new ResizeObserver(t):null;return K.current=r,a&&r?.observe(a),()=>{a&&r?.unobserve(a),r?.disconnect(),K.current=null}},[]),f.useEffect(()=>{if(!ae.current||re.current)return;const t=U.getDefaultOptions(),a=D.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)"),r=fe.createChart(ae.current,{...t,rightPriceScale:{...t.rightPriceScale||{},visible:!y,textColor:a},...y&&{crosshair:{...t.crosshair,mode:fe.CrosshairMode.Magnet}},...W});return L.current=r,re.current=!0,()=>{K.current?.disconnect(),K.current=null,r.remove(),L.current=null,re.current=!1,V.current.clear()}},[y,W]),f.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const r=e.filter(o=>o.data.length>0).length<=1?me:he,l=h==="time"?H.getXFormatters(h,M):H.getXFormatters(h),c=M.map(o=>o.value),{formatter:u,tickmarksFormatter:d,updateVisibleRange:T,updateLastValues:p}=H.createAdaptiveYAxisFormatter(c,w,{yScaleMin:r});ne.current=T,Le.current=p;const F=e.filter(o=>o.data.length>0).map(o=>o.data[o.data.length-1].value);p(F);const k=U.getDefaultOptions();t.applyOptions({localization:{...k.localization||{},timeFormatter:o=>l.timeFormatter(parseFloat(o),void 0)},timeScale:{...k.timeScale||{},tickMarkFormatter:l.tickMarkFormatter,minBarSpacing:0}});const b=(M.length>0?Math.min(...M.map(o=>o.value)):0)<0,R=M.some(o=>o.value===0),C=!b&&R,x=e.length>1&&!P,v=e.length>1&&!P||y,_=D.resolveCSSColor("hsl(var(--foreground))","rgb(0, 0, 0)");t.applyOptions({rightPriceScale:{...k.rightPriceScale||{},visible:!v,textColor:_,...C&&{scaleMargins:{top:.3,bottom:0}}}});const X=new Set(V.current.keys()),se=new Set(e.map(o=>o.label));for(const o of X)if(!se.has(o)){const n=V.current.get(o);n&&(t.removeSeries(n),V.current.delete(o))}const Fe=U.getDefaultSeries(),ie=[];let J=0;for(let o=0;o<e.length;o++){const n=e[o],Z=be(o),q=n.lineColor??n.color??Z.line;let I,z;if(n.lineColor??n.color)if(n.topColor&&n.bottomColor)I=n.topColor,z=n.bottomColor;else if(n.topColor){const i=D.generateColorsFromBase(q);I=n.topColor,z=i.bottomColor}else if(n.bottomColor)I=D.generateColorsFromBase(q).topColor,z=n.bottomColor;else{const i=D.generateColorsFromBase(q);I=i.topColor,z=i.bottomColor}else I=n.topColor||Z.top,z=n.bottomColor||Z.bottom;if(n.data.length===0){const i=V.current.get(n.label);i&&(t.removeSeries(i),V.current.delete(n.label));continue}const Me=(n.data.length>0?Math.min(...n.data.map(i=>i.value)):0)<0,Ee=n.data.some(i=>i.value===0),_e=!Me&&Ee,Ne=P||!x||J===0?"right":`scale-${J}`;x&&ie.push({priceScaleId:Ne||"right",shouldPreventNegativeAxis:_e,seriesIndex:J});const we=(P||!x)&&r!==void 0&&typeof r=="number",Ve={lineColor:q,topColor:I,bottomColor:z,priceScaleId:Ne,priceFormat:{type:"custom",minMove:.01,formatter:we&&typeof r=="number"?i=>u(i<r?r:i):u,tickmarksFormatter:d},autoscaleInfoProvider:i=>{if(!we)return i();const G=i();if(G?.priceRange){const Y=r;G.priceRange.minValue=Y}return G}};let $=V.current.get(n.label);const B=n.data.map(i=>({...i,time:i.time}));if(A!==void 0&&B.length>0&&Number(B[0].time)>A){const i=Number(B[0].time),G=i-A,Y=86400,Ie=G>180*Y?7*Y:G>30*Y?Y:6*3600,ye=[];for(let ue=A;ue<i;ue+=Ie)ye.push({time:ue});B.unshift(...ye)}$?($.applyOptions(Ve),$.setData(B)):($=t.addSeries(fe.AreaSeries,{...Fe,...Ve}),$.setData(B),V.current.set(n.label,$)),J++}if(x&&ie.length>0)for(const o of ie)try{const n=t.priceScale(o.priceScaleId);n&&n.applyOptions({visible:!1,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:_})}catch(n){console.warn(`Failed to configure price scale ${o.priceScaleId} for series ${o.seriesIndex}:`,n)}else if(!x)try{const o=t.priceScale("right");o&&o.applyOptions({visible:!y,autoScale:!0,scaleMargins:{top:.1,bottom:r!==void 0||C?0:.1,...C&&{top:.3}},alignLabels:!0,borderVisible:!0,borderColor:"rgba(224, 227, 235, 0.1)",entireTextOnly:!1,textColor:_})}catch{}if(r!==void 0&&!y&&(P||!x)&&t.applyOptions({handleScroll:{vertTouchDrag:!1}}),M.length>0){const o=M.map(I=>Number(I.time)),n=Math.min(...o),Z=A!==void 0?Math.min(A,n):n,q=Math.max(...o);t.timeScale().setVisibleRange({from:Z,to:q})}pe.current&&(pe.current=!1);const ce=new Map;for(const o of e)o.data.length>0&&ce.set(o.label,o.data[o.data.length-1]);le(ce.size>0?ce:void 0)},[e,M,h,w,y,P,me,he,A]),f.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const a=e.length===1;let r;for(const c of e)if(c.data.length>0){r=c.data[c.data.length-1].time;break}if(!r)return;const l=c=>{const{time:u=r,seriesData:d,point:T}=c||{},p=Array.from(V.current.values());if(!T||!u){const j=new Map;for(const b of e)b.data.length>0&&j.set(b.label,b.data[b.data.length-1]);if(le(j.size>0?j:void 0),a||P)E(null);else if(p[0]&&r){const R=t.timeScale().timeToCoordinate(r),C=e[0];if(C.data.length>0){const x=C.data[C.data.length-1].value,v=p[0].priceToCoordinate(x);R!==null&&v!==null&&E({x:R,y:v})}}return}const F=new Map;let k;for(let j=0;j<e.length;j++){const b=e[j],R=p[j];if(!R)continue;const C=d?.get(R),x=C&&"value"in C?C.value:void 0;let v;if(x!==void 0)v=x;else if(a){const _=Number(u),X=b.data.length>0?Number(b.data[0].time):Number.POSITIVE_INFINITY;_<X?v=Number.NaN:v=b.data[b.data.length-1]?.value??0}else v=je(b.data,Number(u));Number.isNaN(v)||(k===void 0&&(k=v),F.set(b.label,{value:v,time:u}))}if(le(F),k!==void 0&&p[0]){const b=t.timeScale().timeToCoordinate(u),R=p[0].priceToCoordinate(k);if(b!==null&&R!==null){const C=O.current;if(C){const x=C.querySelector(".LightweightChart");if(x){const v=x.getBoundingClientRect(),_=C.getBoundingClientRect(),X=b+(v.left-_.left),se=R+(v.top-_.top);E({x:X,y:se})}else E({x:b,y:R})}else E({x:b,y:R})}else E(null)}else E(null)};return t.subscribeCrosshairMove(l),y&&t.subscribeClick(l),!a&&!P&&requestAnimationFrame(()=>{const c=Array.from(V.current.values());if(c[0]&&r&&e[0]?.data.length>0){const d=t.timeScale().timeToCoordinate(r),T=e[0].data[e[0].data.length-1].value,p=c[0].priceToCoordinate(T);d!==null&&p!==null&&E({x:d,y:p})}}),()=>{t.unsubscribeCrosshairMove(l),y&&t.unsubscribeClick(l)}},[e,P,y]),f.useEffect(()=>{const t=L.current;if(!t||e.length===0)return;const a=t.timeScale(),r=()=>{if(!ne.current)return;const l=a.getVisibleRange();if(!l)return;const c=Number(l.from),u=Number(l.to),d=[];for(const T of e)for(const p of T.data){const F=Number(p.time);F>=c&&F<=u&&d.push(p.value)}d.length>0&&ne.current(d)};return a.subscribeVisibleLogicalRangeChange(r),()=>{a.unsubscribeVisibleLogicalRangeChange(r)}},[e]),f.useEffect(()=>{const t=L.current,a=Array.from(V.current.values()),r=[];if(t&&a.length>0&&S){const l=U.getDefaultVerticalLine(),c=a[0];for(const u of S){const d=new qe.VertLine(t,c,u.xCoordinate,{...l,...u.options||{}});c.attachPrimitive(d),r.push(d)}}return()=>{if(a.length>0){const l=a[0];for(const c of r)l.detachPrimitive(c)}}},[S]),f.useEffect(()=>{const t=L.current;if(!t||!S?.length){Se([]);return}const a=()=>{const c=t.timeScale(),u=S.map(d=>c.timeToCoordinate(d.xCoordinate)??null);Se(u)};a();const r=t.timeScale(),l=()=>{a()};return r.subscribeVisibleLogicalRangeChange(l),()=>{r.unsubscribeVisibleLogicalRangeChange(l)}},[S]);const Q=e.length===1,Re=ge.useMemo(()=>{if(Q&&e.length>0){const t=e[0];if(t.data.length>0)return t.data[t.data.length-1]}},[Q,e]);return g.jsxs("div",{ref:O,className:de.cn("relative z-[1] w-full h-full overflow-hidden p-0",m),children:[oe!=null&&oe!==!1&&Q?g.jsx("div",{className:"absolute top-2 left-2 right-2 z-[100] pointer-events-none",children:g.jsx("div",{className:"text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis",children:oe})}):Pe&&Q&&Re&&g.jsx(Oe.GraphCurrentValue,{point:Re,xMeasureUnit:h,yMeasureUnit:w,decimals:te}),Ce&&ve&&g.jsx(De.GraphTooltip,{points:Ce,xMeasureUnit:h,yMeasureUnit:w,series:e,position:ve,containerRef:O,decimals:te}),s&&g.jsx(Ge,{series:e,onUnselect:N}),S&&S.length>0&&xe.length===S.length&&g.jsx("div",{className:"absolute inset-0 z-[5] pointer-events-none","aria-hidden":!0,children:S.map((t,a)=>{const r=xe[a],l=t.options??{},c=l.showLabel!==!1;if(r===null||!c)return null;const{labelText:u,valueStr:d}=ke(l,w,te);if(!(u||d))return null;const p=l.labelBackgroundColor??l.color??"hsl(var(--background))",F=l.labelTextColor??"hsl(var(--foreground))",k=`${String(t.xCoordinate)}-${u}`;return g.jsxs("div",{className:"absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",style:{left:r,transform:"translateX(-50%)",backgroundColor:p,color:F},children:[u&&g.jsx("span",{className:"block",children:u}),d&&g.jsx("span",{className:de.cn("block",u&&"mt-0.5"),children:d})]},k)})}),g.jsx("div",{ref:ae,className:"LightweightChart w-full h-full overflow-hidden"})]})}function Ge({series:e,onUnselect:m}){return g.jsx("div",{className:"absolute top-0 left-2 z-[10] flex flex-wrap gap-2",children:e.map((s,N)=>{const h=be(N),w=(s.lineColor??s.color)||h.line,W=s.data.length===0;return g.jsxs("div",{className:de.cn("flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",W&&"opacity-50"),children:[g.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:w}}),g.jsxs("span",{className:"text-[10px] sm:text-xs font-medium text-foreground",children:[s.label,W&&" (no data)"]}),m&&g.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),m(s.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 ${s.label}`,children:g.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:[g.jsx("title",{children:"Close"}),g.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),g.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},s.label)})})}exports.DEFAULT_SERIES_COLORS=ee;exports.Graph=Be;exports.getSeriesColorPalette=be;exports.getStepForwardValue=je;exports.getVerticalLineTooltipContent=ke;
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { createChart as
|
|
3
|
-
import * as
|
|
4
|
-
import { useRef as M, useState as
|
|
5
|
-
import { useIsMobile as
|
|
6
|
-
import { cn as
|
|
7
|
-
import { resolveCSSColor as
|
|
8
|
-
import { getDefaultOptions as
|
|
9
|
-
import { getXFormatters as
|
|
10
|
-
import { GraphCurrentValue as
|
|
11
|
-
import { GraphTooltip as
|
|
12
|
-
import { VertLine as
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
) : String(
|
|
19
|
-
return { labelText:
|
|
1
|
+
import { jsxs as Z, jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import { createChart as Ot, CrosshairMode as Yt, AreaSeries as Gt } from "lightweight-charts";
|
|
3
|
+
import * as ut from "react";
|
|
4
|
+
import { useRef as M, useState as ft, useEffect as O } from "react";
|
|
5
|
+
import { useIsMobile as Bt } from "../../hooks/use-media-query.js";
|
|
6
|
+
import { cn as mt } from "../../utils/cn.js";
|
|
7
|
+
import { resolveCSSColor as kt, generateColorsFromBase as U, hslToHex as jt } from "../../utils/colors.js";
|
|
8
|
+
import { getDefaultOptions as Pt, getDefaultSeries as Ht, getDefaultVerticalLine as _t } from "./default-config.js";
|
|
9
|
+
import { getXFormatters as Lt, createAdaptiveYAxisFormatter as Wt, formatExactValue as dt } from "./formatters.js";
|
|
10
|
+
import { GraphCurrentValue as Xt } from "./graph-current-value.js";
|
|
11
|
+
import { GraphTooltip as qt } from "./graph-tooltip.js";
|
|
12
|
+
import { VertLine as Zt } from "./plugins/vertical-line.js";
|
|
13
|
+
function Kt(e, C, u) {
|
|
14
|
+
const T = e.labelText ?? "", g = e.value, N = g === void 0 ? "" : typeof g == "number" ? C === "$" ? `$${dt(g, void 0, u)}` : C === "%" ? `${dt(g, void 0, u)}%` : dt(
|
|
15
|
+
g,
|
|
16
|
+
C !== "none" && C !== "%" && C !== "$" ? C : void 0,
|
|
17
|
+
u
|
|
18
|
+
) : String(g);
|
|
19
|
+
return { labelText: T, valueStr: N };
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
function Jt(e, C) {
|
|
22
|
+
for (let u = e.length - 1; u >= 0; u--)
|
|
23
|
+
if (Number(e[u].time) <= C)
|
|
24
|
+
return e[u].value;
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
const gt = [
|
|
22
28
|
// 0 green (emerald)
|
|
23
29
|
{
|
|
24
30
|
line: "#02c39a",
|
|
@@ -133,98 +139,99 @@ const ct = [
|
|
|
133
139
|
top: "rgba(71, 85, 105, 0.56)",
|
|
134
140
|
bottom: "rgba(71, 85, 105, 0.04)"
|
|
135
141
|
}
|
|
136
|
-
],
|
|
137
|
-
function
|
|
138
|
-
if (e <
|
|
139
|
-
return
|
|
140
|
-
const
|
|
141
|
-
return { line:
|
|
142
|
+
], Qt = 137.5;
|
|
143
|
+
function It(e) {
|
|
144
|
+
if (e < gt.length)
|
|
145
|
+
return gt[e];
|
|
146
|
+
const u = (e - gt.length) * Qt % 360, T = jt(u, 70, 50), { topColor: g, bottomColor: N } = U(T);
|
|
147
|
+
return { line: T, top: g, bottom: N };
|
|
142
148
|
}
|
|
143
|
-
function
|
|
149
|
+
function me({
|
|
144
150
|
series: e,
|
|
145
|
-
className:
|
|
146
|
-
showLegend:
|
|
147
|
-
onUnselectSeries:
|
|
148
|
-
xMeasureUnit:
|
|
149
|
-
yMeasureUnit:
|
|
150
|
-
optionsOverrides:
|
|
151
|
-
verticalLineOptions:
|
|
152
|
-
currentValueDecimals:
|
|
153
|
-
useSharedPriceScale:
|
|
154
|
-
showCurrentValue:
|
|
155
|
-
graphTitle:
|
|
156
|
-
yScaleMin:
|
|
157
|
-
yScaleMinMultiple:
|
|
151
|
+
className: C,
|
|
152
|
+
showLegend: u = !1,
|
|
153
|
+
onUnselectSeries: T,
|
|
154
|
+
xMeasureUnit: g = "time",
|
|
155
|
+
yMeasureUnit: N = "token",
|
|
156
|
+
optionsOverrides: W,
|
|
157
|
+
verticalLineOptions: x,
|
|
158
|
+
currentValueDecimals: tt,
|
|
159
|
+
useSharedPriceScale: k = !1,
|
|
160
|
+
showCurrentValue: Mt = !0,
|
|
161
|
+
graphTitle: et,
|
|
162
|
+
yScaleMin: bt,
|
|
163
|
+
yScaleMinMultiple: ht,
|
|
164
|
+
visibleTimeFrom: $
|
|
158
165
|
}) {
|
|
159
|
-
const
|
|
166
|
+
const P = M(null), w = M(/* @__PURE__ */ new Map()), ot = M(!1), pt = M(!0), rt = M(
|
|
160
167
|
null
|
|
161
|
-
),
|
|
168
|
+
), Tt = M(null), E = M(null), nt = M(null), K = M(null), R = Bt(), A = ut.useMemo(() => e.flatMap((t) => t.data), [e]), At = ut.useMemo(() => {
|
|
162
169
|
if (e.length > 0) {
|
|
163
170
|
const t = e[e.length - 1];
|
|
164
171
|
if (t.data.length > 0)
|
|
165
172
|
return t.data[t.data.length - 1];
|
|
166
173
|
}
|
|
167
|
-
}, [e]), [
|
|
168
|
-
if (!
|
|
174
|
+
}, [e]), [Ct, at] = ft(() => {
|
|
175
|
+
if (!At) return;
|
|
169
176
|
const t = /* @__PURE__ */ new Map();
|
|
170
177
|
for (const a of e)
|
|
171
178
|
a.data.length > 0 && t.set(a.label, a.data[a.data.length - 1]);
|
|
172
179
|
return t;
|
|
173
|
-
}), [
|
|
174
|
-
|
|
180
|
+
}), [vt, F] = ft(null), [xt, St] = ft([]);
|
|
181
|
+
O(() => {
|
|
175
182
|
const t = () => {
|
|
176
183
|
try {
|
|
177
|
-
if (
|
|
178
|
-
const l =
|
|
179
|
-
|
|
184
|
+
if (P.current && E.current) {
|
|
185
|
+
const l = E.current.clientWidth, s = E.current.clientHeight;
|
|
186
|
+
P.current.resize(l, s);
|
|
180
187
|
}
|
|
181
188
|
} catch {
|
|
182
189
|
}
|
|
183
|
-
}, a =
|
|
184
|
-
return
|
|
185
|
-
a && r?.unobserve(a), r?.disconnect(),
|
|
190
|
+
}, a = E.current, r = a ? new ResizeObserver(t) : null;
|
|
191
|
+
return K.current = r, a && r?.observe(a), () => {
|
|
192
|
+
a && r?.unobserve(a), r?.disconnect(), K.current = null;
|
|
186
193
|
};
|
|
187
|
-
}, []),
|
|
188
|
-
if (!
|
|
189
|
-
const t =
|
|
194
|
+
}, []), O(() => {
|
|
195
|
+
if (!nt.current || ot.current) return;
|
|
196
|
+
const t = Pt(), a = kt(
|
|
190
197
|
"hsl(var(--foreground))",
|
|
191
198
|
"rgb(0, 0, 0)"
|
|
192
|
-
), r =
|
|
199
|
+
), r = Ot(nt.current, {
|
|
193
200
|
...t,
|
|
194
201
|
rightPriceScale: {
|
|
195
202
|
...t.rightPriceScale || {},
|
|
196
|
-
visible: !
|
|
203
|
+
visible: !R,
|
|
197
204
|
textColor: a
|
|
198
205
|
},
|
|
199
|
-
...
|
|
206
|
+
...R && {
|
|
200
207
|
crosshair: {
|
|
201
208
|
...t.crosshair,
|
|
202
|
-
mode:
|
|
209
|
+
mode: Yt.Magnet
|
|
203
210
|
}
|
|
204
211
|
},
|
|
205
|
-
...
|
|
212
|
+
...W
|
|
206
213
|
});
|
|
207
|
-
return
|
|
208
|
-
|
|
214
|
+
return P.current = r, ot.current = !0, () => {
|
|
215
|
+
K.current?.disconnect(), K.current = null, r.remove(), P.current = null, ot.current = !1, w.current.clear();
|
|
209
216
|
};
|
|
210
|
-
}, [
|
|
211
|
-
const t =
|
|
217
|
+
}, [R, W]), O(() => {
|
|
218
|
+
const t = P.current;
|
|
212
219
|
if (!t || e.length === 0) return;
|
|
213
|
-
const r = e.filter((o) => o.data.length > 0).length <= 1 ?
|
|
220
|
+
const r = e.filter((o) => o.data.length > 0).length <= 1 ? bt : ht, l = g === "time" ? Lt(g, A) : Lt(g), s = A.map((o) => o.value), {
|
|
214
221
|
formatter: c,
|
|
215
|
-
tickmarksFormatter:
|
|
216
|
-
updateVisibleRange:
|
|
217
|
-
updateLastValues:
|
|
218
|
-
} =
|
|
222
|
+
tickmarksFormatter: f,
|
|
223
|
+
updateVisibleRange: L,
|
|
224
|
+
updateLastValues: m
|
|
225
|
+
} = Wt(s, N, {
|
|
219
226
|
yScaleMin: r
|
|
220
227
|
});
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
const
|
|
228
|
+
rt.current = L, Tt.current = m;
|
|
229
|
+
const I = e.filter((o) => o.data.length > 0).map((o) => o.data[o.data.length - 1].value);
|
|
230
|
+
m(I);
|
|
231
|
+
const V = Pt();
|
|
225
232
|
t.applyOptions({
|
|
226
233
|
localization: {
|
|
227
|
-
...
|
|
234
|
+
...V.localization || {},
|
|
228
235
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
229
236
|
timeFormatter: (o) => (
|
|
230
237
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
@@ -232,21 +239,21 @@ function se({
|
|
|
232
239
|
)
|
|
233
240
|
},
|
|
234
241
|
timeScale: {
|
|
235
|
-
...
|
|
242
|
+
...V.timeScale || {},
|
|
236
243
|
// biome-ignore lint/suspicious/noExplicitAny: External library type compatibility
|
|
237
244
|
tickMarkFormatter: l.tickMarkFormatter,
|
|
238
245
|
minBarSpacing: 0
|
|
239
246
|
}
|
|
240
247
|
});
|
|
241
|
-
const
|
|
248
|
+
const d = (A.length > 0 ? Math.min(...A.map((o) => o.value)) : 0) < 0, S = A.some((o) => o.value === 0), b = !d && S, v = e.length > 1 && !k, h = e.length > 1 && !k || R, z = kt(
|
|
242
249
|
"hsl(var(--foreground))",
|
|
243
250
|
"rgb(0, 0, 0)"
|
|
244
251
|
);
|
|
245
252
|
t.applyOptions({
|
|
246
253
|
rightPriceScale: {
|
|
247
|
-
...
|
|
248
|
-
visible: !
|
|
249
|
-
textColor:
|
|
254
|
+
...V.rightPriceScale || {},
|
|
255
|
+
visible: !h,
|
|
256
|
+
textColor: z,
|
|
250
257
|
...b && {
|
|
251
258
|
scaleMargins: {
|
|
252
259
|
top: 0.3,
|
|
@@ -255,83 +262,83 @@ function se({
|
|
|
255
262
|
}
|
|
256
263
|
}
|
|
257
264
|
});
|
|
258
|
-
const
|
|
259
|
-
for (const o of
|
|
260
|
-
if (!
|
|
265
|
+
const X = new Set(w.current.keys()), lt = new Set(e.map((o) => o.label));
|
|
266
|
+
for (const o of X)
|
|
267
|
+
if (!lt.has(o)) {
|
|
261
268
|
const n = w.current.get(o);
|
|
262
269
|
n && (t.removeSeries(n), w.current.delete(o));
|
|
263
270
|
}
|
|
264
|
-
const
|
|
265
|
-
let
|
|
271
|
+
const Ft = Ht(), it = [];
|
|
272
|
+
let Q = 0;
|
|
266
273
|
for (let o = 0; o < e.length; o++) {
|
|
267
|
-
const n = e[o],
|
|
268
|
-
let
|
|
274
|
+
const n = e[o], q = It(o), Y = n.lineColor ?? n.color ?? q.line;
|
|
275
|
+
let D, G;
|
|
269
276
|
if (n.lineColor ?? n.color)
|
|
270
277
|
if (n.topColor && n.bottomColor)
|
|
271
|
-
|
|
278
|
+
D = n.topColor, G = n.bottomColor;
|
|
272
279
|
else if (n.topColor) {
|
|
273
|
-
const i =
|
|
274
|
-
|
|
280
|
+
const i = U(Y);
|
|
281
|
+
D = n.topColor, G = i.bottomColor;
|
|
275
282
|
} else if (n.bottomColor)
|
|
276
|
-
|
|
283
|
+
D = U(Y).topColor, G = n.bottomColor;
|
|
277
284
|
else {
|
|
278
|
-
const i =
|
|
279
|
-
|
|
285
|
+
const i = U(Y);
|
|
286
|
+
D = i.topColor, G = i.bottomColor;
|
|
280
287
|
}
|
|
281
288
|
else
|
|
282
|
-
|
|
289
|
+
D = n.topColor || q.top, G = n.bottomColor || q.bottom;
|
|
283
290
|
if (n.data.length === 0) {
|
|
284
291
|
const i = w.current.get(n.label);
|
|
285
292
|
i && (t.removeSeries(i), w.current.delete(n.label));
|
|
286
293
|
continue;
|
|
287
294
|
}
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
priceScaleId:
|
|
291
|
-
shouldPreventNegativeAxis:
|
|
292
|
-
seriesIndex:
|
|
295
|
+
const zt = (n.data.length > 0 ? Math.min(...n.data.map((i) => i.value)) : 0) < 0, Dt = n.data.some((i) => i.value === 0), $t = !zt && Dt, wt = k || !v || Q === 0 ? "right" : `scale-${Q}`;
|
|
296
|
+
v && it.push({
|
|
297
|
+
priceScaleId: wt || "right",
|
|
298
|
+
shouldPreventNegativeAxis: $t,
|
|
299
|
+
seriesIndex: Q
|
|
293
300
|
});
|
|
294
|
-
const
|
|
295
|
-
lineColor:
|
|
296
|
-
topColor:
|
|
297
|
-
bottomColor:
|
|
298
|
-
priceScaleId:
|
|
301
|
+
const Rt = (k || !v) && r !== void 0 && typeof r == "number", Vt = {
|
|
302
|
+
lineColor: Y,
|
|
303
|
+
topColor: D,
|
|
304
|
+
bottomColor: G,
|
|
305
|
+
priceScaleId: wt,
|
|
299
306
|
priceFormat: {
|
|
300
307
|
type: "custom",
|
|
301
308
|
minMove: 0.01,
|
|
302
|
-
formatter:
|
|
309
|
+
formatter: Rt && typeof r == "number" ? (i) => c(
|
|
303
310
|
i < r ? r : i
|
|
304
311
|
) : c,
|
|
305
|
-
tickmarksFormatter:
|
|
312
|
+
tickmarksFormatter: f
|
|
306
313
|
},
|
|
307
314
|
autoscaleInfoProvider: (i) => {
|
|
308
|
-
if (!
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
|
|
315
|
+
if (!Rt) return i();
|
|
316
|
+
const H = i();
|
|
317
|
+
if (H?.priceRange) {
|
|
318
|
+
const _ = r;
|
|
319
|
+
H.priceRange.minValue = _;
|
|
313
320
|
}
|
|
314
|
-
return
|
|
321
|
+
return H;
|
|
315
322
|
}
|
|
316
323
|
};
|
|
317
324
|
let B = w.current.get(n.label);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
), w.current.set(n.label, B)),
|
|
325
|
+
const j = n.data.map((i) => ({
|
|
326
|
+
...i,
|
|
327
|
+
time: i.time
|
|
328
|
+
}));
|
|
329
|
+
if ($ !== void 0 && j.length > 0 && Number(j[0].time) > $) {
|
|
330
|
+
const i = Number(j[0].time), H = i - $, _ = 86400, Et = H > 180 * _ ? 7 * _ : H > 30 * _ ? _ : 6 * 3600, yt = [];
|
|
331
|
+
for (let ct = $; ct < i; ct += Et)
|
|
332
|
+
yt.push({ time: ct });
|
|
333
|
+
j.unshift(...yt);
|
|
334
|
+
}
|
|
335
|
+
B ? (B.applyOptions(Vt), B.setData(j)) : (B = t.addSeries(Gt, {
|
|
336
|
+
...Ft,
|
|
337
|
+
...Vt
|
|
338
|
+
}), B.setData(j), w.current.set(n.label, B)), Q++;
|
|
332
339
|
}
|
|
333
|
-
if (
|
|
334
|
-
for (const o of
|
|
340
|
+
if (v && it.length > 0)
|
|
341
|
+
for (const o of it)
|
|
335
342
|
try {
|
|
336
343
|
const n = t.priceScale(o.priceScaleId);
|
|
337
344
|
n && n.applyOptions({
|
|
@@ -349,7 +356,7 @@ function se({
|
|
|
349
356
|
borderVisible: !0,
|
|
350
357
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
351
358
|
entireTextOnly: !1,
|
|
352
|
-
textColor:
|
|
359
|
+
textColor: z
|
|
353
360
|
});
|
|
354
361
|
} catch (n) {
|
|
355
362
|
console.warn(
|
|
@@ -357,11 +364,11 @@ function se({
|
|
|
357
364
|
n
|
|
358
365
|
);
|
|
359
366
|
}
|
|
360
|
-
else if (!
|
|
367
|
+
else if (!v)
|
|
361
368
|
try {
|
|
362
369
|
const o = t.priceScale("right");
|
|
363
370
|
o && o.applyOptions({
|
|
364
|
-
visible: !
|
|
371
|
+
visible: !R,
|
|
365
372
|
autoScale: !0,
|
|
366
373
|
scaleMargins: {
|
|
367
374
|
top: 0.1,
|
|
@@ -375,34 +382,35 @@ function se({
|
|
|
375
382
|
borderVisible: !0,
|
|
376
383
|
borderColor: "rgba(224, 227, 235, 0.1)",
|
|
377
384
|
entireTextOnly: !1,
|
|
378
|
-
textColor:
|
|
385
|
+
textColor: z
|
|
379
386
|
});
|
|
380
387
|
} catch {
|
|
381
388
|
}
|
|
382
|
-
if (r !== void 0 && !
|
|
389
|
+
if (r !== void 0 && !R && (k || !v) && t.applyOptions({
|
|
383
390
|
handleScroll: {
|
|
384
391
|
vertTouchDrag: !1
|
|
385
392
|
}
|
|
386
|
-
}),
|
|
387
|
-
const o =
|
|
388
|
-
t.timeScale().setVisibleRange({ from:
|
|
393
|
+
}), A.length > 0) {
|
|
394
|
+
const o = A.map((D) => Number(D.time)), n = Math.min(...o), q = $ !== void 0 ? Math.min($, n) : n, Y = Math.max(...o);
|
|
395
|
+
t.timeScale().setVisibleRange({ from: q, to: Y });
|
|
389
396
|
}
|
|
390
|
-
|
|
391
|
-
const
|
|
397
|
+
pt.current && (pt.current = !1);
|
|
398
|
+
const st = /* @__PURE__ */ new Map();
|
|
392
399
|
for (const o of e)
|
|
393
|
-
o.data.length > 0 &&
|
|
394
|
-
|
|
400
|
+
o.data.length > 0 && st.set(o.label, o.data[o.data.length - 1]);
|
|
401
|
+
at(st.size > 0 ? st : void 0);
|
|
395
402
|
}, [
|
|
396
403
|
e,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
A,
|
|
405
|
+
g,
|
|
406
|
+
N,
|
|
407
|
+
R,
|
|
408
|
+
k,
|
|
409
|
+
bt,
|
|
410
|
+
ht,
|
|
411
|
+
$
|
|
412
|
+
]), O(() => {
|
|
413
|
+
const t = P.current;
|
|
406
414
|
if (!t || e.length === 0) return;
|
|
407
415
|
const a = e.length === 1;
|
|
408
416
|
let r;
|
|
@@ -413,89 +421,97 @@ function se({
|
|
|
413
421
|
}
|
|
414
422
|
if (!r) return;
|
|
415
423
|
const l = (s) => {
|
|
416
|
-
const { time: c = r, seriesData:
|
|
417
|
-
if (!
|
|
418
|
-
const
|
|
419
|
-
for (const
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
else if (
|
|
424
|
-
const
|
|
424
|
+
const { time: c = r, seriesData: f, point: L } = s || {}, m = Array.from(w.current.values());
|
|
425
|
+
if (!L || !c) {
|
|
426
|
+
const y = /* @__PURE__ */ new Map();
|
|
427
|
+
for (const d of e)
|
|
428
|
+
d.data.length > 0 && y.set(d.label, d.data[d.data.length - 1]);
|
|
429
|
+
if (at(y.size > 0 ? y : void 0), a || k)
|
|
430
|
+
F(null);
|
|
431
|
+
else if (m[0] && r) {
|
|
432
|
+
const S = t.timeScale().timeToCoordinate(r), b = e[0];
|
|
425
433
|
if (b.data.length > 0) {
|
|
426
|
-
const
|
|
427
|
-
|
|
434
|
+
const v = b.data[b.data.length - 1].value, h = m[0].priceToCoordinate(v);
|
|
435
|
+
S !== null && h !== null && F({ x: S, y: h });
|
|
428
436
|
}
|
|
429
437
|
}
|
|
430
438
|
return;
|
|
431
439
|
}
|
|
432
|
-
const
|
|
433
|
-
let
|
|
434
|
-
for (let
|
|
435
|
-
const
|
|
436
|
-
if (!
|
|
437
|
-
const b =
|
|
438
|
-
|
|
440
|
+
const I = /* @__PURE__ */ new Map();
|
|
441
|
+
let V;
|
|
442
|
+
for (let y = 0; y < e.length; y++) {
|
|
443
|
+
const d = e[y], S = m[y];
|
|
444
|
+
if (!S) continue;
|
|
445
|
+
const b = f?.get(S), v = b && "value" in b ? b.value : void 0;
|
|
446
|
+
let h;
|
|
447
|
+
if (v !== void 0)
|
|
448
|
+
h = v;
|
|
449
|
+
else if (a) {
|
|
450
|
+
const z = Number(c), X = d.data.length > 0 ? Number(d.data[0].time) : Number.POSITIVE_INFINITY;
|
|
451
|
+
z < X ? h = Number.NaN : h = d.data[d.data.length - 1]?.value ?? 0;
|
|
452
|
+
} else
|
|
453
|
+
h = Jt(d.data, Number(c));
|
|
454
|
+
Number.isNaN(h) || (V === void 0 && (V = h), I.set(d.label, { value: h, time: c }));
|
|
439
455
|
}
|
|
440
|
-
if (
|
|
441
|
-
const
|
|
442
|
-
if (
|
|
443
|
-
const b =
|
|
456
|
+
if (at(I), V !== void 0 && m[0]) {
|
|
457
|
+
const d = t.timeScale().timeToCoordinate(c), S = m[0].priceToCoordinate(V);
|
|
458
|
+
if (d !== null && S !== null) {
|
|
459
|
+
const b = E.current;
|
|
444
460
|
if (b) {
|
|
445
|
-
const
|
|
461
|
+
const v = b.querySelector(
|
|
446
462
|
".LightweightChart"
|
|
447
463
|
);
|
|
448
|
-
if (
|
|
449
|
-
const
|
|
450
|
-
|
|
464
|
+
if (v) {
|
|
465
|
+
const h = v.getBoundingClientRect(), z = b.getBoundingClientRect(), X = d + (h.left - z.left), lt = S + (h.top - z.top);
|
|
466
|
+
F({ x: X, y: lt });
|
|
451
467
|
} else
|
|
452
|
-
|
|
468
|
+
F({ x: d, y: S });
|
|
453
469
|
} else
|
|
454
|
-
|
|
470
|
+
F({ x: d, y: S });
|
|
455
471
|
} else
|
|
456
|
-
|
|
472
|
+
F(null);
|
|
457
473
|
} else
|
|
458
|
-
|
|
474
|
+
F(null);
|
|
459
475
|
};
|
|
460
|
-
return t.subscribeCrosshairMove(l),
|
|
476
|
+
return t.subscribeCrosshairMove(l), R && t.subscribeClick(l), !a && !k && requestAnimationFrame(() => {
|
|
461
477
|
const s = Array.from(w.current.values());
|
|
462
478
|
if (s[0] && r && e[0]?.data.length > 0) {
|
|
463
|
-
const
|
|
464
|
-
|
|
479
|
+
const f = t.timeScale().timeToCoordinate(r), L = e[0].data[e[0].data.length - 1].value, m = s[0].priceToCoordinate(L);
|
|
480
|
+
f !== null && m !== null && F({ x: f, y: m });
|
|
465
481
|
}
|
|
466
482
|
}), () => {
|
|
467
|
-
t.unsubscribeCrosshairMove(l),
|
|
483
|
+
t.unsubscribeCrosshairMove(l), R && t.unsubscribeClick(l);
|
|
468
484
|
};
|
|
469
|
-
}, [e,
|
|
470
|
-
const t =
|
|
485
|
+
}, [e, k, R]), O(() => {
|
|
486
|
+
const t = P.current;
|
|
471
487
|
if (!t || e.length === 0) return;
|
|
472
488
|
const a = t.timeScale(), r = () => {
|
|
473
|
-
if (!
|
|
489
|
+
if (!rt.current) return;
|
|
474
490
|
const l = a.getVisibleRange();
|
|
475
491
|
if (!l) return;
|
|
476
|
-
const s = Number(l.from), c = Number(l.to),
|
|
477
|
-
for (const
|
|
478
|
-
for (const
|
|
479
|
-
const
|
|
480
|
-
|
|
492
|
+
const s = Number(l.from), c = Number(l.to), f = [];
|
|
493
|
+
for (const L of e)
|
|
494
|
+
for (const m of L.data) {
|
|
495
|
+
const I = Number(m.time);
|
|
496
|
+
I >= s && I <= c && f.push(m.value);
|
|
481
497
|
}
|
|
482
|
-
|
|
498
|
+
f.length > 0 && rt.current(f);
|
|
483
499
|
};
|
|
484
500
|
return a.subscribeVisibleLogicalRangeChange(r), () => {
|
|
485
501
|
a.unsubscribeVisibleLogicalRangeChange(
|
|
486
502
|
r
|
|
487
503
|
);
|
|
488
504
|
};
|
|
489
|
-
}, [e]),
|
|
490
|
-
const t =
|
|
491
|
-
if (t && a.length > 0 &&
|
|
492
|
-
const l =
|
|
493
|
-
for (const c of
|
|
494
|
-
const
|
|
505
|
+
}, [e]), O(() => {
|
|
506
|
+
const t = P.current, a = Array.from(w.current.values()), r = [];
|
|
507
|
+
if (t && a.length > 0 && x) {
|
|
508
|
+
const l = _t(), s = a[0];
|
|
509
|
+
for (const c of x) {
|
|
510
|
+
const f = new Zt(t, s, c.xCoordinate, {
|
|
495
511
|
...l,
|
|
496
512
|
...c.options || {}
|
|
497
513
|
});
|
|
498
|
-
s.attachPrimitive(
|
|
514
|
+
s.attachPrimitive(f), r.push(f);
|
|
499
515
|
}
|
|
500
516
|
}
|
|
501
517
|
return () => {
|
|
@@ -505,15 +521,15 @@ function se({
|
|
|
505
521
|
l.detachPrimitive(s);
|
|
506
522
|
}
|
|
507
523
|
};
|
|
508
|
-
}, [
|
|
509
|
-
const t =
|
|
510
|
-
if (!t || !
|
|
511
|
-
|
|
524
|
+
}, [x]), O(() => {
|
|
525
|
+
const t = P.current;
|
|
526
|
+
if (!t || !x?.length) {
|
|
527
|
+
St([]);
|
|
512
528
|
return;
|
|
513
529
|
}
|
|
514
530
|
const a = () => {
|
|
515
|
-
const s = t.timeScale(), c =
|
|
516
|
-
|
|
531
|
+
const s = t.timeScale(), c = x.map((f) => s.timeToCoordinate(f.xCoordinate) ?? null);
|
|
532
|
+
St(c);
|
|
517
533
|
};
|
|
518
534
|
a();
|
|
519
535
|
const r = t.timeScale(), l = () => {
|
|
@@ -522,84 +538,84 @@ function se({
|
|
|
522
538
|
return r.subscribeVisibleLogicalRangeChange(l), () => {
|
|
523
539
|
r.unsubscribeVisibleLogicalRangeChange(l);
|
|
524
540
|
};
|
|
525
|
-
}, [
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
541
|
+
}, [x]);
|
|
542
|
+
const J = e.length === 1, Nt = ut.useMemo(() => {
|
|
543
|
+
if (J && e.length > 0) {
|
|
528
544
|
const t = e[0];
|
|
529
545
|
if (t.data.length > 0)
|
|
530
546
|
return t.data[t.data.length - 1];
|
|
531
547
|
}
|
|
532
|
-
}, [
|
|
533
|
-
return /* @__PURE__ */
|
|
548
|
+
}, [J, e]);
|
|
549
|
+
return /* @__PURE__ */ Z(
|
|
534
550
|
"div",
|
|
535
551
|
{
|
|
536
|
-
ref:
|
|
537
|
-
className:
|
|
552
|
+
ref: E,
|
|
553
|
+
className: mt(
|
|
538
554
|
"relative z-[1] w-full h-full overflow-hidden p-0",
|
|
539
|
-
|
|
555
|
+
C
|
|
540
556
|
),
|
|
541
557
|
children: [
|
|
542
|
-
|
|
543
|
-
|
|
558
|
+
et != null && et !== !1 && J ? /* @__PURE__ */ p("div", { className: "absolute top-2 left-2 right-2 z-[100] pointer-events-none", children: /* @__PURE__ */ p("div", { className: "text-xl sm:text-2xl font-semibold text-foreground whitespace-nowrap overflow-hidden text-ellipsis", children: et }) }) : Mt && J && Nt && /* @__PURE__ */ p(
|
|
559
|
+
Xt,
|
|
544
560
|
{
|
|
545
|
-
point:
|
|
546
|
-
xMeasureUnit:
|
|
547
|
-
yMeasureUnit:
|
|
548
|
-
decimals:
|
|
561
|
+
point: Nt,
|
|
562
|
+
xMeasureUnit: g,
|
|
563
|
+
yMeasureUnit: N,
|
|
564
|
+
decimals: tt
|
|
549
565
|
}
|
|
550
566
|
),
|
|
551
|
-
|
|
552
|
-
|
|
567
|
+
Ct && vt && /* @__PURE__ */ p(
|
|
568
|
+
qt,
|
|
553
569
|
{
|
|
554
|
-
points:
|
|
555
|
-
xMeasureUnit:
|
|
556
|
-
yMeasureUnit:
|
|
570
|
+
points: Ct,
|
|
571
|
+
xMeasureUnit: g,
|
|
572
|
+
yMeasureUnit: N,
|
|
557
573
|
series: e,
|
|
558
|
-
position:
|
|
559
|
-
containerRef:
|
|
560
|
-
decimals:
|
|
574
|
+
position: vt,
|
|
575
|
+
containerRef: E,
|
|
576
|
+
decimals: tt
|
|
561
577
|
}
|
|
562
578
|
),
|
|
563
|
-
|
|
564
|
-
|
|
579
|
+
u && /* @__PURE__ */ p(Ut, { series: e, onUnselect: T }),
|
|
580
|
+
x && x.length > 0 && xt.length === x.length && /* @__PURE__ */ p(
|
|
565
581
|
"div",
|
|
566
582
|
{
|
|
567
583
|
className: "absolute inset-0 z-[5] pointer-events-none",
|
|
568
584
|
"aria-hidden": !0,
|
|
569
|
-
children:
|
|
570
|
-
const r =
|
|
585
|
+
children: x.map((t, a) => {
|
|
586
|
+
const r = xt[a], l = t.options ?? {}, s = l.showLabel !== !1;
|
|
571
587
|
if (r === null || !s) return null;
|
|
572
|
-
const { labelText: c, valueStr:
|
|
588
|
+
const { labelText: c, valueStr: f } = Kt(
|
|
573
589
|
l,
|
|
574
|
-
|
|
575
|
-
|
|
590
|
+
N,
|
|
591
|
+
tt
|
|
576
592
|
);
|
|
577
|
-
if (!(c ||
|
|
578
|
-
const
|
|
579
|
-
return /* @__PURE__ */
|
|
593
|
+
if (!(c || f)) return null;
|
|
594
|
+
const m = l.labelBackgroundColor ?? l.color ?? "hsl(var(--background))", I = l.labelTextColor ?? "hsl(var(--foreground))", V = `${String(t.xCoordinate)}-${c}`;
|
|
595
|
+
return /* @__PURE__ */ Z(
|
|
580
596
|
"div",
|
|
581
597
|
{
|
|
582
598
|
className: "absolute top-2 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shadow-sm border border-border",
|
|
583
599
|
style: {
|
|
584
600
|
left: r,
|
|
585
601
|
transform: "translateX(-50%)",
|
|
586
|
-
backgroundColor:
|
|
587
|
-
color:
|
|
602
|
+
backgroundColor: m,
|
|
603
|
+
color: I
|
|
588
604
|
},
|
|
589
605
|
children: [
|
|
590
|
-
c && /* @__PURE__ */
|
|
591
|
-
|
|
606
|
+
c && /* @__PURE__ */ p("span", { className: "block", children: c }),
|
|
607
|
+
f && /* @__PURE__ */ p("span", { className: mt("block", c && "mt-0.5"), children: f })
|
|
592
608
|
]
|
|
593
609
|
},
|
|
594
|
-
|
|
610
|
+
V
|
|
595
611
|
);
|
|
596
612
|
})
|
|
597
613
|
}
|
|
598
614
|
),
|
|
599
|
-
/* @__PURE__ */
|
|
615
|
+
/* @__PURE__ */ p(
|
|
600
616
|
"div",
|
|
601
617
|
{
|
|
602
|
-
ref:
|
|
618
|
+
ref: nt,
|
|
603
619
|
className: "LightweightChart w-full h-full overflow-hidden"
|
|
604
620
|
}
|
|
605
621
|
)
|
|
@@ -607,41 +623,41 @@ function se({
|
|
|
607
623
|
}
|
|
608
624
|
);
|
|
609
625
|
}
|
|
610
|
-
function
|
|
626
|
+
function Ut({
|
|
611
627
|
series: e,
|
|
612
|
-
onUnselect:
|
|
628
|
+
onUnselect: C
|
|
613
629
|
}) {
|
|
614
|
-
return /* @__PURE__ */
|
|
615
|
-
const
|
|
616
|
-
return /* @__PURE__ */
|
|
630
|
+
return /* @__PURE__ */ p("div", { className: "absolute top-0 left-2 z-[10] flex flex-wrap gap-2", children: e.map((u, T) => {
|
|
631
|
+
const g = It(T), N = (u.lineColor ?? u.color) || g.line, W = u.data.length === 0;
|
|
632
|
+
return /* @__PURE__ */ Z(
|
|
617
633
|
"div",
|
|
618
634
|
{
|
|
619
|
-
className:
|
|
635
|
+
className: mt(
|
|
620
636
|
"flex items-center gap-1.5 px-2 py-1 bg-background/80 backdrop-blur-sm rounded border border-border",
|
|
621
|
-
|
|
637
|
+
W && "opacity-50"
|
|
622
638
|
),
|
|
623
639
|
children: [
|
|
624
|
-
/* @__PURE__ */
|
|
640
|
+
/* @__PURE__ */ p(
|
|
625
641
|
"div",
|
|
626
642
|
{
|
|
627
643
|
className: "w-3 h-3 rounded-sm",
|
|
628
|
-
style: { backgroundColor:
|
|
644
|
+
style: { backgroundColor: N }
|
|
629
645
|
}
|
|
630
646
|
),
|
|
631
|
-
/* @__PURE__ */
|
|
632
|
-
|
|
633
|
-
|
|
647
|
+
/* @__PURE__ */ Z("span", { className: "text-[10px] sm:text-xs font-medium text-foreground", children: [
|
|
648
|
+
u.label,
|
|
649
|
+
W && " (no data)"
|
|
634
650
|
] }),
|
|
635
|
-
|
|
651
|
+
C && /* @__PURE__ */ p(
|
|
636
652
|
"button",
|
|
637
653
|
{
|
|
638
654
|
type: "button",
|
|
639
|
-
onClick: (
|
|
640
|
-
|
|
655
|
+
onClick: (x) => {
|
|
656
|
+
x.stopPropagation(), C(u.label);
|
|
641
657
|
},
|
|
642
658
|
className: "ml-1 flex items-center justify-center w-4 h-4 rounded-sm hover:bg-muted transition-colors cursor-pointer",
|
|
643
|
-
"aria-label": `Remove ${
|
|
644
|
-
children: /* @__PURE__ */
|
|
659
|
+
"aria-label": `Remove ${u.label}`,
|
|
660
|
+
children: /* @__PURE__ */ Z(
|
|
645
661
|
"svg",
|
|
646
662
|
{
|
|
647
663
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -656,9 +672,9 @@ function Xt({
|
|
|
656
672
|
className: "text-muted-foreground hover:text-foreground",
|
|
657
673
|
"aria-hidden": "true",
|
|
658
674
|
children: [
|
|
659
|
-
/* @__PURE__ */
|
|
660
|
-
/* @__PURE__ */
|
|
661
|
-
/* @__PURE__ */
|
|
675
|
+
/* @__PURE__ */ p("title", { children: "Close" }),
|
|
676
|
+
/* @__PURE__ */ p("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
677
|
+
/* @__PURE__ */ p("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
662
678
|
]
|
|
663
679
|
}
|
|
664
680
|
)
|
|
@@ -666,13 +682,14 @@ function Xt({
|
|
|
666
682
|
)
|
|
667
683
|
]
|
|
668
684
|
},
|
|
669
|
-
|
|
685
|
+
u.label
|
|
670
686
|
);
|
|
671
687
|
}) });
|
|
672
688
|
}
|
|
673
689
|
export {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
690
|
+
gt as DEFAULT_SERIES_COLORS,
|
|
691
|
+
me as Graph,
|
|
692
|
+
It as getSeriesColorPalette,
|
|
693
|
+
Jt as getStepForwardValue,
|
|
694
|
+
Kt as getVerticalLineTooltipContent
|
|
678
695
|
};
|
|
@@ -32,6 +32,12 @@ export declare function getVerticalLineTooltipContent(opts: VerticalLineOptions,
|
|
|
32
32
|
labelText: string;
|
|
33
33
|
valueStr: string;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Step-forward interpolation: find the last data point with
|
|
37
|
+
* `time <= crosshairTime` and return its value.
|
|
38
|
+
* Returns 0 when the crosshair is before the first data point (no history).
|
|
39
|
+
*/
|
|
40
|
+
export declare function getStepForwardValue(data: ReadonlyArray<Point>, crosshairTime: number): number;
|
|
35
41
|
/**
|
|
36
42
|
* Palette ordered for maximum contrast; first color is the original teal.
|
|
37
43
|
* Greens/teals are spread out so that when only a subset of series is visible,
|
|
@@ -95,10 +101,17 @@ export interface GraphProps {
|
|
|
95
101
|
* Which prop applies is chosen by how many series actually have points (empty series are ignored).
|
|
96
102
|
*/
|
|
97
103
|
yScaleMinMultiple?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Minimum visible time (unix seconds). When set, the X axis never zooms
|
|
106
|
+
* in further than this value — even if the current series data starts later.
|
|
107
|
+
* Useful for keeping the full selected time range (e.g. 1Y) when switching
|
|
108
|
+
* between series with different data coverage.
|
|
109
|
+
*/
|
|
110
|
+
visibleTimeFrom?: number;
|
|
98
111
|
}
|
|
99
112
|
/**
|
|
100
113
|
* Graph component that renders a chart using lightweight-charts library
|
|
101
114
|
* with support for area series, custom tooltips, and vertical line annotations
|
|
102
115
|
* Supports single or multiple series with different colors and legends
|
|
103
116
|
*/
|
|
104
|
-
export declare function Graph({ series, className, showLegend, onUnselectSeries, xMeasureUnit, yMeasureUnit, optionsOverrides, verticalLineOptions, currentValueDecimals, useSharedPriceScale, showCurrentValue, graphTitle, yScaleMin, yScaleMinMultiple, }: GraphProps): React.ReactElement;
|
|
117
|
+
export declare function Graph({ series, className, showLegend, onUnselectSeries, xMeasureUnit, yMeasureUnit, optionsOverrides, verticalLineOptions, currentValueDecimals, useSharedPriceScale, showCurrentValue, graphTitle, yScaleMin, yScaleMinMultiple, visibleTimeFrom, }: GraphProps): React.ReactElement;
|