From e464b4ebbb73aa82b9554cd1b71d9659426f5366 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Thu, 15 Jun 2023 09:12:06 -0400 Subject: [PATCH] fix theme fails if `trace.marker.color` isn't an array (#5144) --- .../plotly/src/components/Chart.tsx | 6 ++-- .../plotly/src/components/ResizeHandler.tsx | 36 +++++++++---------- openbb_terminal/core/plots/plotly.html | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/frontend-components/plotly/src/components/Chart.tsx b/frontend-components/plotly/src/components/Chart.tsx index 2773302b8073..511e5845c19b 100644 --- a/frontend-components/plotly/src/components/Chart.tsx +++ b/frontend-components/plotly/src/components/Chart.tsx @@ -339,8 +339,8 @@ export default function Chart({ if (changeTheme) { try { console.log("changeTheme", changeTheme); - const TRACES = plotData?.data.filter((trace) => - trace?.name?.startsWith("Volume"), + const TRACES = plotData?.data.filter( + (trace) => trace?.name?.trim() === "Volume", ); const darkmode = !darkMode; @@ -375,7 +375,7 @@ export default function Chart({ const volumeColors = darkmode ? volumeColorsDark : volumeColorsLight; TRACES.forEach((trace) => { - if (trace.type === "bar") + if (trace.type === "bar" && Array.isArray(trace.marker.color)) trace.marker.color = trace.marker.color.map((color) => { return volumeColors[color] || color; }); diff --git a/frontend-components/plotly/src/components/ResizeHandler.tsx b/frontend-components/plotly/src/components/ResizeHandler.tsx index ced5fff3e738..c916d1bbacdc 100644 --- a/frontend-components/plotly/src/components/ResizeHandler.tsx +++ b/frontend-components/plotly/src/components/ResizeHandler.tsx @@ -17,31 +17,31 @@ export default async function ResizeHandler({ .filter( (x) => plotData.layout[x].showticklabels || - plotData.layout[x].matches == undefined + plotData.layout[x].matches === undefined, ); - const TRACES = plotData.data.filter((trace) => - trace?.name?.startsWith("Volume") + const TRACES = plotData.data.filter( + (trace) => trace?.name?.trim() === "Volume", ); - let layout_update: any = {}; - let volume: any = volumeBars || { old_nticks: {} }; + const layout_update: any = {}; + const volume: any = volumeBars || { old_nticks: {} }; const width = window.innerWidth; const height = window.innerHeight; - let tick_size = + const tick_size = height > 420 && width < 920 ? 8 : height > 420 && width < 500 ? 9 : 7; if (width < 750) { // We hide the modebar and set the number of ticks to 6 TRACES.forEach((trace) => { - if (trace.type == "bar") { + if (trace.type === "bar") { trace.opacity = 1; trace.marker.line.width = 0.09; - if (volumeBars.yaxis == undefined) { - volume.yaxis = "yaxis" + trace.yaxis.replace("y", ""); - layout_update[volume.yaxis + ".tickfont.size"] = tick_size; + if (volumeBars.yaxis === undefined) { + volume.yaxis = `yaxis${trace.yaxis.replace("y", "")}`; + layout_update[`${volume.yaxis}.tickfont.size`] = tick_size; volume.tickfont = plotData.layout[volume.yaxis].tickfont || {}; plotData.layout.margin.l -= 40; @@ -50,8 +50,8 @@ export default async function ResizeHandler({ }); XAXIS.forEach((x) => { - if (volumeBars.old_nticks?.[x] == undefined) { - layout_update[x + ".nticks"] = 6; + if (volumeBars.old_nticks?.[x] === undefined) { + layout_update[`${x}.nticks`] = 6; volume.old_nticks[x] = plotData.layout[x].nticks || 10; } }); @@ -63,21 +63,21 @@ export default async function ResizeHandler({ await hideModebar(false); setMaximizePlot(false); - if (volumeBars.old_nticks != undefined) { + if (volumeBars.old_nticks !== undefined) { XAXIS.forEach((x) => { - if (volumeBars.old_nticks[x] != undefined) { - layout_update[x + ".nticks"] = volume.old_nticks[x]; + if (volumeBars.old_nticks[x] !== undefined) { + layout_update[`${x}.nticks`] = volume.old_nticks[x]; volume.old_nticks[x] = undefined; } }); } - if (volumeBars.yaxis != undefined) { + if (volumeBars.yaxis !== undefined) { TRACES.forEach((trace) => { - if (trace.type == "bar") { + if (trace.type === "bar") { trace.opacity = 0.5; trace.marker.line.width = 0.2; - layout_update[volume.yaxis + ".tickfont.size"] = + layout_update[`${volume.yaxis}.tickfont.size`] = volume.tickfont.size + 3; plotData.layout.margin.l += 40; volume.yaxis = undefined; diff --git a/openbb_terminal/core/plots/plotly.html b/openbb_terminal/core/plots/plotly.html index 24032598e6f0..ac7c06bc3040 100644 --- a/openbb_terminal/core/plots/plotly.html +++ b/openbb_terminal/core/plots/plotly.html @@ -3706,7 +3706,7 @@ .block-interactivity-`.concat(L,` {pointer-events: none;} .allow-interactivity-`).concat(L,` {pointer-events: all;} `)},r9=0,ih=[];function i9(L){var I=In.useRef([]),$=In.useRef([0,0]),se=In.useRef(),Pe=In.useState(r9++)[0],R=In.useState(function(){return P5()})[0],E=In.useRef(L);In.useEffect(function(){E.current=L},[L]),In.useEffect(function(){if(L.inert){document.body.classList.add("block-interactivity-".concat(Pe));var t=MA([L.lockRef.current],(L.shards||[]).map(b_),!0).filter(Boolean);return t.forEach(function(o){return o.classList.add("allow-interactivity-".concat(Pe))}),function(){document.body.classList.remove("block-interactivity-".concat(Pe)),t.forEach(function(o){return o.classList.remove("allow-interactivity-".concat(Pe))})}}},[L.inert,L.lockRef.current,L.shards]);var e=In.useCallback(function(t,o){if("touches"in t&&t.touches.length===2)return!E.current.allowPinchZoom;var r=k0(t),n=$.current,a="deltaX"in t?t.deltaX:n[0]-r[0],s="deltaY"in t?t.deltaY:n[1]-r[1],u,p=t.target,c=Math.abs(a)>Math.abs(s)?"h":"v";if("touches"in t&&c==="h"&&p.type==="range")return!1;var b=y_(c,p);if(!b)return!0;if(b?u=c:(u=c==="v"?"h":"v",b=y_(c,p)),!b)return!1;if(!se.current&&"changedTouches"in t&&(a||s)&&(se.current=u),!u)return!0;var g=se.current||u;return e9(g,o,t,g==="h"?a:s,!0)},[]),w=In.useCallback(function(t){var o=t;if(!(!ih.length||ih[ih.length-1]!==R)){var r="deltaY"in o?x_(o):k0(o),n=I.current.filter(function(u){return u.name===o.type&&u.target===o.target&&t9(u.delta,r)})[0];if(n&&n.should){o.cancelable&&o.preventDefault();return}if(!n){var a=(E.current.shards||[]).map(b_).filter(Boolean).filter(function(u){return u.contains(o.target)}),s=a.length>0?e(o,a[0]):!E.current.noIsolation;s&&o.cancelable&&o.preventDefault()}}},[]),k=In.useCallback(function(t,o,r,n){var a={name:t,delta:o,target:r,should:n};I.current.push(a),setTimeout(function(){I.current=I.current.filter(function(s){return s!==a})},1)},[]),i=In.useCallback(function(t){$.current=k0(t),se.current=void 0},[]),_=In.useCallback(function(t){k(t.type,x_(t),t.target,e(t,L.lockRef.current))},[]),y=In.useCallback(function(t){k(t.type,k0(t),t.target,e(t,L.lockRef.current))},[]);In.useEffect(function(){return ih.push(R),L.setCallbacks({onScrollCapture:_,onWheelCapture:_,onTouchMoveCapture:y}),document.addEventListener("wheel",w,rh),document.addEventListener("touchmove",w,rh),document.addEventListener("touchstart",i,rh),function(){ih=ih.filter(function(t){return t!==R}),document.removeEventListener("wheel",w,rh),document.removeEventListener("touchmove",w,rh),document.removeEventListener("touchstart",i,rh)}},[]);var h=L.removeScrollBar,l=L.inert;return In.createElement(In.Fragment,null,l?In.createElement(R,{styles:n9(Pe)}):null,h?In.createElement(ZA,{gapMode:"margin"}):null)}const a9=zA(L5,i9);var z5=In.forwardRef(function(L,I){return In.createElement(B1,ku({},L,{ref:I,sideCar:a9}))});z5.classNames=B1.classNames;const o9=z5;var s9=function(L){if(typeof document>"u")return null;var I=Array.isArray(L)?L[0]:L;return I.ownerDocument.body},ah=new WeakMap,T0=new WeakMap,A0={},pv=0,D5=function(L){return L&&(L.host||D5(L.parentNode))},l9=function(L,I){return I.map(function($){if(L.contains($))return $;var se=D5($);return se&&L.contains(se)?se:(console.error("aria-hidden",$,"in not contained inside",L,". Doing nothing"),null)}).filter(function($){return!!$})},u9=function(L,I,$,se){var Pe=l9(I,Array.isArray(L)?L:[L]);A0[$]||(A0[$]=new WeakMap);var R=A0[$],E=[],e=new Set,w=new Set(Pe),k=function(_){!_||e.has(_)||(e.add(_),k(_.parentNode))};Pe.forEach(k);var i=function(_){!_||w.has(_)||Array.prototype.forEach.call(_.children,function(y){if(e.has(y))i(y);else{var h=y.getAttribute(se),l=h!==null&&h!=="false",t=(ah.get(y)||0)+1,o=(R.get(y)||0)+1;ah.set(y,t),R.set(y,o),E.push(y),t===1&&l&&T0.set(y,!0),o===1&&y.setAttribute($,"true"),l||y.setAttribute(se,"true")}})};return i(I),e.clear(),pv++,function(){E.forEach(function(_){var y=ah.get(_)-1,h=R.get(_)-1;ah.set(_,y),R.set(_,h),y||(T0.has(_)||_.removeAttribute(se),T0.delete(_)),h||_.removeAttribute($)}),pv--,pv||(ah=new WeakMap,ah=new WeakMap,T0=new WeakMap,A0={})}},c9=function(L,I,$){$===void 0&&($="data-aria-hidden");var se=Array.from(Array.isArray(L)?L:[L]),Pe=I||s9(L);return Pe?(se.push.apply(se,Array.from(Pe.querySelectorAll("[aria-live]"))),u9(se,Pe,$,"aria-hidden")):function(){return null}};const F5="Dialog",[B5,nM]=J7(F5),[f9,ic]=B5(F5),h9=L=>{const{__scopeDialog:I,children:$,open:se,defaultOpen:Pe,onOpenChange:R,modal:E=!0}=L,e=In.useRef(null),w=In.useRef(null),[k=!1,i]=nA({prop:se,defaultProp:Pe,onChange:R});return In.createElement(f9,{scope:I,triggerRef:e,contentRef:w,contentId:sv(),titleId:sv(),descriptionId:sv(),open:k,onOpenChange:i,onOpenToggle:In.useCallback(()=>i(_=>!_),[i]),modal:E},$)},p9="DialogPortal",[rM,N5]=B5(p9,{forceMount:void 0}),Em="DialogOverlay",d9=In.forwardRef((L,I)=>{const $=N5(Em,L.__scopeDialog),{forceMount:se=$.forceMount,...Pe}=L,R=ic(Em,L.__scopeDialog);return R.modal?In.createElement(By,{present:se||R.open},In.createElement(g9,zo({},Pe,{ref:I}))):null}),g9=In.forwardRef((L,I)=>{const{__scopeDialog:$,...se}=L,Pe=ic(Em,$);return In.createElement(o9,{as:Fy,allowPinchZoom:!0,shards:[Pe.contentRef]},In.createElement(Nh.div,zo({"data-state":U5(Pe.open)},se,{ref:I,style:{pointerEvents:"auto",...se.style}})))}),sd="DialogContent",v9=In.forwardRef((L,I)=>{const $=N5(sd,L.__scopeDialog),{forceMount:se=$.forceMount,...Pe}=L,R=ic(sd,L.__scopeDialog);return In.createElement(By,{present:se||R.open},R.modal?In.createElement(m9,zo({},Pe,{ref:I})):In.createElement(y9,zo({},Pe,{ref:I})))}),m9=In.forwardRef((L,I)=>{const $=ic(sd,L.__scopeDialog),se=In.useRef(null),Pe=dd(I,$.contentRef,se);return In.useEffect(()=>{const R=se.current;if(R)return c9(R)},[]),In.createElement(j5,zo({},L,{ref:Pe,trapFocus:$.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:wf(L.onCloseAutoFocus,R=>{var E;R.preventDefault(),(E=$.triggerRef.current)===null||E===void 0||E.focus()}),onPointerDownOutside:wf(L.onPointerDownOutside,R=>{const E=R.detail.originalEvent,e=E.button===0&&E.ctrlKey===!0;(E.button===2||e)&&R.preventDefault()}),onFocusOutside:wf(L.onFocusOutside,R=>R.preventDefault())}))}),y9=In.forwardRef((L,I)=>{const $=ic(sd,L.__scopeDialog),se=In.useRef(!1),Pe=In.useRef(!1);return In.createElement(j5,zo({},L,{ref:I,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:R=>{var E;if((E=L.onCloseAutoFocus)===null||E===void 0||E.call(L,R),!R.defaultPrevented){var e;se.current||(e=$.triggerRef.current)===null||e===void 0||e.focus(),R.preventDefault()}se.current=!1,Pe.current=!1},onInteractOutside:R=>{var E,e;(E=L.onInteractOutside)===null||E===void 0||E.call(L,R),R.defaultPrevented||(se.current=!0,R.detail.originalEvent.type==="pointerdown"&&(Pe.current=!0));const w=R.target;((e=$.triggerRef.current)===null||e===void 0?void 0:e.contains(w))&&R.preventDefault(),R.detail.originalEvent.type==="focusin"&&Pe.current&&R.preventDefault()}}))}),j5=In.forwardRef((L,I)=>{const{__scopeDialog:$,trapFocus:se,onOpenAutoFocus:Pe,onCloseAutoFocus:R,...E}=L,e=ic(sd,$),w=In.useRef(null),k=dd(I,w);return AA(),In.createElement(In.Fragment,null,In.createElement(vA,{asChild:!0,loop:!0,trapped:se,onMountAutoFocus:Pe,onUnmountAutoFocus:R},In.createElement(pA,zo({role:"dialog",id:e.contentId,"aria-describedby":e.descriptionId,"aria-labelledby":e.titleId,"data-state":U5(e.open)},E,{ref:k,onDismiss:()=>e.onOpenChange(!1)}))),!1)}),x9="DialogTitle",b9=In.forwardRef((L,I)=>{const{__scopeDialog:$,...se}=L,Pe=ic(x9,$);return In.createElement(Nh.h2,zo({id:Pe.titleId},se,{ref:I}))}),_9="DialogDescription",w9=In.forwardRef((L,I)=>{const{__scopeDialog:$,...se}=L,Pe=ic(_9,$);return In.createElement(Nh.p,zo({id:Pe.descriptionId},se,{ref:I}))}),k9="DialogClose",T9=In.forwardRef((L,I)=>{const{__scopeDialog:$,...se}=L,Pe=ic(k9,$);return In.createElement(Nh.button,zo({type:"button"},se,{ref:I,onClick:wf(L.onClick,()=>Pe.onOpenChange(!1))}))});function U5(L){return L?"open":"closed"}const A9=h9,M9=d9,S9=v9,E9=b9,C9=w9,__=T9,w_=({title:L,titleId:I,...$})=>hr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,...$,children:hr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),V5={margin:"2px 0px 2px 10px",padding:"5px 2px 2px 5px"};function gd({open:L,close:I,title:$,description:se,children:Pe}){return Xr(A9,{open:L,onOpenChange:I,children:[hr(M9,{onClick:I,className:"_modal-overlay"}),Xr(S9,{className:"_modal",children:[hr(E9,{className:"_modal-title",children:$}),hr(C9,{className:"_modal_description",children:se}),hr(__,{children:hr(w_,{})}),Pe,hr(__,{className:"_modal-close",onClick:I,children:hr(w_,{className:"w-6 h-6"})})]})]})}function L9({title:L,content:I,open:$,close:se}){return hr(gd,{title:L,description:"",open:$,close:se,children:Xr("div",{id:"popup_title",className:"popup_content",style:{padding:"0px 2px 2px 5px",marginTop:5},children:[hr("div",{style:{display:"flex",flexDirection:"column",gap:0},children:hr("div",{children:hr("label",{htmlFor:"title_text",children:I})})}),hr("div",{style:{float:"right",marginTop:20},children:hr("button",{type:"button",className:"_btn",style:{padding:"8px 16px",width:"100%"},onClick:se,children:"Close"})})]})})}function P9({open:L,close:I}){const $=window.download_path||"~/OpenBBUserData/exports";return hr(gd,{title:"Success",description:"",open:L,close:I,children:Xr("div",{id:"popup_title",className:"popup_content",style:{padding:"0px 2px 2px 5px",marginTop:5},children:[hr("div",{style:{display:"flex",flexDirection:"column",gap:0},children:hr("div",{children:Xr("label",{htmlFor:"title_text",children:[hr("b",{children:window.title})," has been downloaded to",hr("br",{}),hr("br",{}),hr("a",{style:{color:"#FFDD00",marginTop:15},href:`${$}`,onClick:se=>{se.preventDefault(),window.pywry.open_file($)},children:$})]})})}),hr("div",{style:{float:"right",marginTop:20},children:hr("button",{className:"_btn",style:{padding:"8px 16px",width:"100%"},onClick:I,children:"Close"})})]})})}const k_=new FileReader,O9={overlaying:"y",side:"left",tickfont:{size:12},tickpadding:5,showgrid:!1,showline:!1,showticklabels:!0,showlegend:!0,zeroline:!1,anchor:"x",type:"linear",autorange:!0};function I9({open:L,close:I,setLoading:$,addOverlay:se,plotlyData:Pe}){const[R,E]=In.useState("scatter"),[e,w]=In.useState("#FFDD00"),[k,i]=In.useState("#00ACFF"),[_,y]=In.useState("#FF0000"),[h,l]=In.useState(""),[t,o]=In.useState([]),[r,n]=In.useState([]),[a,s]=In.useState({}),u=["x","open","high","low","close"],p={scatter:"Scatter (Line)",candlestick:"Candlestick",bar:"Bar"},[c,b]=In.useState({});function g(){I(),E("scatter"),l(""),o([]),n([]),b({})}function f(){var m,x;if(t.length==0){(m=document.getElementById("csv_file"))==null||m.focus(),(x=document.getElementById("csv_file"))==null||x.style.setProperty("border","1px solid red"),document.getElementById("csv_file_warning").style.display="block";return}const v=R9({csvData:t,plotlyData:Pe,yaxisOptions:a,traceType:R,traceColor:e,traceName:h,options:c,increasingColor:k,decreasingColor:_});se(v),g()}return hr(gd,{title:"Overlay Chart",description:"Upload a CSV file to overlay a chart on the main chart.",open:L,close:I,children:Xr("div",{id:"popup_csv",className:"popup_content",children:[Xr("div",{children:[Xr("label",{htmlFor:"csv_file",children:[hr("b",{children:"CSV file:"}),hr("div",{id:"csv_file_warning",className:"popup_warning",style:{marginLeft:"80px",marginBottom:"10px"},children:"CSV file is required."})]}),hr("input",{onChange:v=>{var m,x;if(v.target.files){if(v.target.files[0].type!=="text/csv"){(m=document.getElementById("csv_file"))==null||m.focus(),(x=document.getElementById("csv_file"))==null||x.style.setProperty("border","1px solid red"),document.getElementById("csv_file_warning").style.display="block";return}}else return;r.length>0&&(n([]),b({}),E("scatter")),k_.onload=T=>{var Y;if(!((Y=T.target)!=null&&Y.result)||typeof T.target.result!="string")return;const d=T.target.result.split(` -`).map(D=>D.replace(/\r/g,"")),M=d[0].split(","),A=M.map(D=>D.trim().toLowerCase()),C={};M.length>1&&(C.x=M[0],C.y=M[1]);for(let D=0;DA.includes(D))?E("candlestick"):A.length>=5&&P.forEach(D=>{C[D]=M[P.indexOf(D)+1]}),A.includes("close")&&(b({...c,y:M[A.indexOf("close")]}),C.y=M[A.indexOf("close")]);const z=[];for(let D=1;D2&&(G.test(D[0])?D.splice(0,2):G.test(D[D.length-2])&&D.splice(D.length-2,2),B=D.join("_").replace(/openbb_/g,""))}}catch(D){console.log(D)}l(B),b(C),n(M),o(z)},k_.readAsText(v.target.files[0])},type:"file",id:"csv_file",accept:".csv",style:{marginLeft:10}})]}),Xr("div",{style:{marginTop:15},children:[hr("label",{htmlFor:"csv_trace_type",children:hr("b",{children:"Display data type:"})}),Xr("select",{onChange:v=>{E(v.target.value)},id:"csv_trace_type",style:V5,defaultValue:p[R],children:[R&&hr("option",{value:R,children:p[R]},R),Object.keys(p).map(v=>R!==v&&hr("option",{value:v,children:p[v]},v))]})]}),Xr("div",{style:{marginTop:12},children:[hr("label",{htmlFor:"csv_name",children:hr("b",{children:"Trace Name:"})}),hr("textarea",{id:"csv_name",value:h,onChange:v=>{l(v.target.value)},style:{padding:"5px 2px 2px 5px",width:"100%",maxWidth:"100%",maxHeight:200,marginTop:2},rows:2,cols:20,placeholder:"Enter a name to give this trace"})]}),r.length>0&&Xr(Mg,{children:[["scatter","bar"].includes(R)&&hr("div",{style:{marginTop:15,marginBottom:10},id:"csv_columns",className:"csv_column_container",children:["x","y"].map(v=>Xr("div",{style:{marginTop:10,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[Xr("label",{htmlFor:`csv_${v}`,style:{width:"100px"},children:[v.toUpperCase()," Axis"]}),hr("select",{onChange:m=>{b({...c,[v]:m.target.value})},id:`csv_${v}`,style:{width:"100%"},defaultValue:c[v],children:r.map(m=>hr("option",{value:m,children:m},m))})]},v))}),R==="candlestick"&&hr("div",{id:"csv_columns",className:"csv_column_container",style:{marginTop:15},children:["x","open","high","low","close"].map(v=>Xr("div",{style:{marginTop:10,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[hr("label",{htmlFor:`csv_${v}`,style:{width:"100px"},children:v.charAt(0).toUpperCase()+v.slice(1)}),hr("select",{onChange:m=>{b({...c,[v]:m.target.value})},id:`csv_${v}`,style:{width:"100%"},defaultValue:c[v],children:r.map(m=>hr("option",{value:m,children:m},m))})]},v))}),Xr("div",{style:{marginTop:20},id:"csv_colors",children:[["scatter","bar"].includes(R)&&Xr("div",{children:[hr("label",{htmlFor:"csv_color",children:`${R.charAt(0).toUpperCase()}${R.slice(1)} color`}),hr("input",{type:"color",id:"csv_color",defaultValue:"#FFDD00",style:{margin:"2px 2px 2px 10px"},onChange:v=>{console.log(v.target.value),w(v.target.value)}})]}),R==="candlestick"&&Xr(Mg,{children:[hr("label",{htmlFor:"csv_increasing",children:"Increasing color"}),hr("input",{type:"color",id:"csv_increasing",defaultValue:"#00ACFF",style:{margin:"2px 0px 2px 10px"},onChange:v=>{i(v.target.value)}}),hr("label",{htmlFor:"csv_decreasing",style:{marginLeft:15},children:"Decreasing color"}),hr("input",{style:{margin:"2px 0px 2px 10px"},type:"color",id:"csv_decreasing",defaultValue:"#FF0000",onChange:v=>{y(v.target.value)}})]})]}),Xr("div",{style:{marginTop:20},id:"csv_plot_yaxis_options",children:[R!=="candlestick"&&Xr(Mg,{children:[hr("input",{type:"checkbox",id:"csv_percent_change",name:"csv_plot_yaxis_check",style:{marginBottom:2},onChange:v=>{s({...a,percentChange:v.target.checked,sameYaxis:!1})},checked:!a.sameYaxis&&a.percentChange}),hr("label",{htmlFor:"csv_percent_change",style:{marginLeft:5},children:"Plot as percent change from first value"}),hr("br",{})]}),hr("input",{style:{marginTop:2},type:"checkbox",id:"csv_same_yaxis",name:"csv_plot_yaxis_check",onChange:v=>{s({...a,sameYaxis:v.target.checked,percentChange:!1})},checked:!a.percentChange&&a.sameYaxis}),hr("label",{htmlFor:"csv_same_yaxis",style:{marginLeft:5},children:"Share Y-axis"}),R==="bar"&&Xr("div",{style:{marginTop:2},id:"csv_bar_orientation",children:[hr("input",{type:"checkbox",id:"csv_bar_horizontal",onChange:v=>{b({...c,orientation:v.target.checked?"h":"v"})}}),hr("label",{htmlFor:"csv_bar_horizontal",style:{marginLeft:5},children:"Plot horizontally"})]})]})]}),hr("br",{}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary",id:"csv_cancel",onClick:g,children:"Cancel"}),hr("button",{className:"_btn",id:"csv_submit",onClick:f,children:"Submit"})]})]})})}function R9({csvData:L,plotlyData:I,yaxisOptions:$,traceType:se,traceColor:Pe,traceName:R,options:E,increasingColor:e,decreasingColor:w}){console.log("options",E);const k=I.data[0]||{};k.xaxis===void 0&&(k.xaxis="x"),k.yaxis===void 0&&(k.yaxis="y");let i=k.yaxis,_;const h=Object.keys(I.layout).filter(o=>o.startsWith("yaxis")).map(o=>I.layout[o]).filter(o=>o.side==="left"&&(o.overlaying==="y"||o.fixedrange!==void 0&&o.fixedrange===!0)).length>0?" ":"";if($.sameYaxis!==!0){const o=Object.keys(I.layout).filter(r=>r.startsWith("yaxis")).map(r=>I.layout[r]);_=`y${o.length+1}`,i=`yaxis${o.length+1}`,I.layout[i]={...O9,title:{text:R,font:{size:14},standoff:0},ticksuffix:h,layer:"below traces"}}else _=k.yaxis.replace("yaxis","y");const l={type:se,name:R,showlegend:!0,yaxis:_};let t={};if(["scatter","bar"].includes(se)){if(!L||L.length===0)return I;const o=L.findIndex(n=>n[E.y]!==null&&n[E.y]!==0);if(o===-1)return I;const r={x:[],y:[],customdata:[]};L.forEach(n=>{let a=n[E.y];r.customdata.push(a),$.percentChange&&(se==="scatter"||se==="line")&&(a=(n[E.y]-L[o][E.y])/L[o][E.y]),r.x.push(n[E.x]),r.y.push(a)}),t={...l,x:r.x,y:r.y,customdata:r.customdata,hovertemplate:"%{customdata:.2f}",connectgaps:!0,marker:{color:Pe}},se==="bar"&&(t.orientation=E.orientation,t.marker.opacity=.7,t.connectgaps=void 0,t.hovertemplate=void 0,t.customdata=void 0)}else if(se==="candlestick"){const o={x:[],open:[],high:[],low:[],close:[]};L.forEach(r=>{o.x.push(r[E.x]),o.open.push(r[E.open]),o.high.push(r[E.high]),o.low.push(r[E.low]),o.close.push(r[E.close])}),t={...l,x:o.x,open:o.open,high:o.high,low:o.low,close:o.close,increasing:{line:{color:e,width:.8},fillcolor:e},decreasing:{line:{color:w,width:.8},fillcolor:w}}}return{...I,data:[...I.data,t]}}const T_={padding:"5px 2px 2px 5px",margin:"2px 0"};function z9({open:L,close:I,addAnnotation:$,deleteAnnotation:se,popupData:Pe}){var l,t,o,r,n;const R={text:"",color:"#0088CC",size:18,bordercolor:"#822661",yanchor:"above"},[E,e]=In.useState(R),[w,k]=In.useState(R);Pe&&Pe!==E&&Pe.annotation&&(Pe.annotation=(Pe==null?void 0:Pe.annotation)||{},e(Pe),k(Pe));function i(){console.log("closing"),e(R),k(R),I()}function _(a){console.log(a.target.id.replace("addtext_",""),a.target.value);const s=a.target.id.replace("addtext_",""),u=a.target.value;k({...w,[s]:u})}function y(){console.log("submitting",w),w.text!==""?(E!=null&&E.annotation&&k({...w,annotation:E.annotation}),$(w),I()):(document.getElementById("popup_textarea_warning").style.display="block",document.getElementById("addtext_text").style.border="1px solid red")}function h(){se(E),i()}return hr(gd,{title:"Add Text to Chart",description:"Change the titles on the chart.",open:L,close:i,children:Xr("div",{id:"popup_title",className:"popup_content",children:[Xr("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Xr("div",{style:{marginBottom:20},children:[Xr("label",{htmlFor:"popup_text",children:[hr("b",{children:"Text:"}),hr("div",{id:"popup_textarea_warning",className:"popup_warning",children:"Text is required"})]}),hr("textarea",{id:"addtext_text",style:{...T_,width:"100%",maxWidth:"100%",maxHeight:"200px",marginTop:"8px"},rows:4,cols:50,placeholder:"Enter text here",onChange:_,defaultValue:((l=E==null?void 0:E.annotation)==null?void 0:l.text)||(w==null?void 0:w.text)})]}),Xr("div",{style:{display:"flex",gap:15,alignItems:"center",flexWrap:"wrap",columnCount:2,justifyContent:"space-between",marginBottom:20},children:[hr("label",{htmlFor:"addtext_color",children:hr("b",{children:"Font color"})}),hr("input",{type:"color",id:"addtext_color",style:{margin:"2px 2px 2px 15px"},defaultValue:((t=E==null?void 0:E.annotation)==null?void 0:t.color)||(w==null?void 0:w.color),onChange:_}),hr("label",{htmlFor:"addtext_bordercolor",style:{marginLeft:20},children:hr("b",{children:"Border color"})}),hr("input",{type:"color",id:"addtext_bordercolor",style:{margin:"2px 2px 10px 15px"},defaultValue:((o=E==null?void 0:E.annotation)==null?void 0:o.bordercolor)||(w==null?void 0:w.bordercolor),onChange:_}),hr("label",{htmlFor:"addtext_size",children:hr("b",{children:"Font size"})}),hr("input",{style:{...T_,width:"52px",margin:"0px 0px 0px 2px"},type:"number",id:"addtext_size",onChange:_,defaultValue:((r=E==null?void 0:E.annotation)==null?void 0:r.size)||(w==null?void 0:w.size)}),Xr("div",{children:[hr("label",{htmlFor:"addtext_yanchor",style:{marginRight:31},children:hr("b",{children:"Position"})}),Xr("select",{id:"addtext_yanchor",name:"yanchor",style:{width:"100px"},defaultValue:((n=E==null?void 0:E.annotation)==null?void 0:n.yanchor)||(w==null?void 0:w.yanchor),onChange:_,children:[hr("option",{value:"above",children:"Above"}),hr("option",{value:"below",children:"Below"})]})]})]})]}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary ph-capture",id:"title_cancel",onClick:i,children:"Cancel"}),hr("button",{className:"_btn ph-capture",id:"title_delete",onClick:h,children:"Delete"}),hr("button",{className:"_btn ph-capture",id:"title_submit",onClick:y,children:"Submit"})]})]})})}function D9({plotlyData:L,open:I,close:$,defaultTitle:se,updateTitle:Pe,updateAxesTitles:R}){const[E,e]=In.useState(se),w=Object.keys(L.layout||{}).filter(y=>y.startsWith("yaxis")&&L.layout[y].range!=null),k=Object.keys(L.layout||{}).filter(y=>{var h;return y.startsWith("xaxis")&&L.layout[y].showticklabels!=null&&((h=L.layout[y])==null?void 0:h.anchor)}),[i,_]=In.useState({});return hr(gd,{title:"Chart Titles",description:"Change the titles on the chart.",open:I,close:$,children:Xr("div",{id:"popup_title",className:"popup_content",children:[Xr("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[Xr("div",{children:[hr("label",{htmlFor:"title_text",children:hr("b",{children:"Title:"})}),hr("textarea",{id:"title_text",style:{...V5,width:"100%",maxWidth:"100%",maxHeight:"200px",marginTop:"8px",marginLeft:"0px"},rows:2,cols:20,value:E,onChange:y=>e(y.target.value)})]}),hr("div",{id:"xaxis_div",className:"csv_column_container",style:{marginTop:5,marginBottom:-5},children:k.map((y,h)=>{var l,t;return Xr("div",{style:{marginTop:5,marginBottom:5},children:[hr("label",{htmlFor:`title_${y}`,children:h===0?hr("b",{children:"X axis:"}):Xr("b",{children:["X axis ",h+1,":"]})}),hr("input",{id:`title_${y}`,style:{marginLeft:"0px",padding:"5px 2px 2px 5px"},type:"text",defaultValue:((t=(l=L==null?void 0:L.layout[y])==null?void 0:l.title)==null?void 0:t.text)||"",onChange:o=>{_({...i,[y]:o.target.value})}})]},y)})}),hr("div",{id:"yaxis_div",className:"csv_column_container",style:{marginTop:5,marginBottom:5},children:w.map((y,h)=>{var l,t;return Xr("div",{style:{marginTop:10},children:[hr("label",{htmlFor:`title_${y}`,children:h===0?hr("b",{children:"Y axis:"}):Xr("b",{children:["Y axis ",h+1,":"]})}),hr("input",{id:`title_${y}`,style:{marginLeft:"0px",padding:"5px 2px 2px 5px"},type:"text",defaultValue:((t=(l=L==null?void 0:L.layout[y])==null?void 0:l.title)==null?void 0:t.text)||"",onChange:o=>{_({...i,[y]:o.target.value})}})]},y)})})]}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary ph-capture",id:"title_cancel",onClick:$,children:"Cancel"}),hr("button",{className:"_btn ph-capture",id:"title_submit",onClick:()=>{Pe(E),R(i),$()},children:"Submit"})]})]})})}function Cm(){return Cm=Object.assign?Object.assign.bind():function(L){for(var I=1;I'),!0):I?L.some(function($){return I.includes($)})||L.includes("*"):!0}var q9=function(I,$,se){se===void 0&&(se=!1);var Pe=$.alt,R=$.meta,E=$.mod,e=$.shift,w=$.ctrl,k=$.keys,i=I.key,_=I.code,y=I.ctrlKey,h=I.metaKey,l=I.shiftKey,t=I.altKey,o=Ic(_),r=i.toLowerCase();if(!se){if(Pe===!t&&r!=="alt"||e===!l&&r!=="shift")return!1;if(E){if(!h&&!y)return!1}else if(R===!h&&r!=="meta"&&r!=="os"||w===!y&&r!=="ctrl"&&r!=="control")return!1}return k&&k.length===1&&(k.includes(r)||k.includes(o))?!0:k?N9(k):!k},G9=In.createContext(void 0),W9=function(){return In.useContext(G9)};function Z5(L,I){return L&&I&&typeof L=="object"&&typeof I=="object"?Object.keys(L).length===Object.keys(I).length&&Object.keys(L).reduce(function($,se){return $&&Z5(L[se],I[se])},!0):L===I}var Z9=In.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),Y9=function(){return In.useContext(Z9)};function X9(L){var I=In.useRef(void 0);return Z5(I.current,L)||(I.current=L),I.current}var A_=function(I){I.stopPropagation(),I.preventDefault(),I.stopImmediatePropagation()},$9=typeof window<"u"?In.useLayoutEffect:In.useEffect;function _c(L,I,$,se){var Pe=In.useRef(null),R=In.useRef(!1),E=$ instanceof Array?se instanceof Array?void 0:se:$,e=L instanceof Array?L.join(E==null?void 0:E.splitKey):L,w=$ instanceof Array?$:se instanceof Array?se:void 0,k=In.useCallback(I,w??[]),i=In.useRef(k);w?i.current=k:i.current=I;var _=X9(E),y=Y9(),h=y.enabledScopes,l=W9();return $9(function(){if(!((_==null?void 0:_.enabled)===!1||!H9(h,_==null?void 0:_.scopes))){var t=function(s,u){var p;if(u===void 0&&(u=!1),!(V9(s)&&!W5(s,_==null?void 0:_.enableOnFormTags))&&!(_!=null&&_.ignoreEventWhen!=null&&_.ignoreEventWhen(s))){if(Pe.current!==null&&document.activeElement!==Pe.current&&!Pe.current.contains(document.activeElement)){A_(s);return}(p=s.target)!=null&&p.isContentEditable&&!(_!=null&&_.enableOnContentEditable)||dv(e,_==null?void 0:_.splitKey).forEach(function(c){var b,g=gv(c,_==null?void 0:_.combinationKey);if(q9(s,g,_==null?void 0:_.ignoreModifiers)||(b=g.keys)!=null&&b.includes("*")){if(u&&R.current)return;if(j9(s,g,_==null?void 0:_.preventDefault),!U9(s,g,_==null?void 0:_.enabled)){A_(s);return}i.current(s,g),u||(R.current=!0)}})}},o=function(s){s.key!==void 0&&(q5(Ic(s.code)),((_==null?void 0:_.keydown)===void 0&&(_==null?void 0:_.keyup)!==!0||_!=null&&_.keydown)&&t(s))},r=function(s){s.key!==void 0&&(G5(Ic(s.code)),R.current=!1,_!=null&&_.keyup&&t(s,!0))},n=Pe.current||(E==null?void 0:E.document)||document;return n.addEventListener("keyup",r),n.addEventListener("keydown",o),l&&dv(e,_==null?void 0:_.splitKey).forEach(function(a){return l.addHotkey(gv(a,_==null?void 0:_.combinationKey,_==null?void 0:_.description))}),function(){n.removeEventListener("keyup",r),n.removeEventListener("keydown",o),l&&dv(e,_==null?void 0:_.splitKey).forEach(function(a){return l.removeHotkey(gv(a,_==null?void 0:_.combinationKey,_==null?void 0:_.description))})}}},[e,_,h]),Pe}function Lc(L=!0){return new Promise(I=>{window.MODEBAR||(window.MODEBAR=window.document.getElementsByClassName("modebar-container")[0],window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`),window.MODEBAR&&(window.MODEBAR.style.cssText.includes("display: none")||!L?window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`:window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:none;`,I(!0))})}function K9({setModal:L,changeTheme:I,autoScaling:$,Loading:se,changeColor:Pe,downloadFinished:R}){return _c("ctrl+shift+t",()=>{L({name:"titleDialog"})},{preventDefault:!0}),_c("ctrl+t",()=>{L({name:"textDialog"})},{preventDefault:!0}),_c("ctrl+o",()=>{L({name:"overlayChart"})},{preventDefault:!0}),_c(["ctrl+shift+h","ctrl+h"],()=>{Lc()},{preventDefault:!0}),_c("ctrl+e",()=>{Pe(!0)},{preventDefault:!0}),_c("ctrl+shift+s",async()=>{L({name:"downloadCsv"}),await o_(document.getElementById("plotlyChart"),R)},{preventDefault:!0}),_c("ctrl+s",async()=>{Lc(),l_("MainChart",Lc,se,R)},{preventDefault:!0}),_c("ctrl+w",()=>{window.close()},{preventDefault:!0}),{plotGlPixelRatio:1,scrollZoom:!0,responsive:!0,displaylogo:!1,displayModeBar:!0,modeBarButtonsToRemove:["lasso2d","select2d","downloadImage"],modeBarButtons:[[{name:"Download CSV (Ctrl+Shift+S)",icon:qu.downloadCsv,click:async function(e){await o_(e,R)}},{name:"Download Chart as Image (Ctrl+S)",icon:qu.downloadImage,click:async function(){Lc(),await l_("MainChart",Lc,se,R)}}],[{name:"Edit Color (Ctrl+E)",icon:qu.changeColor,click:function(){Pe(!0)}},"drawline","drawopenpath","drawcircle","drawrect","eraseshape"],[{name:"Overlay chart from CSV (Ctrl+O)",icon:qu.plotCsv,click:function(){L({name:"overlayChart"})}},{name:"Add Text (Ctrl+T)",icon:qu.addText,click:function(){L({name:"textDialog",data:{text:""}})}},{name:"Change Titles (Ctrl+Shift+T)",icon:qu.changeTitle,click:function(){L({name:"titleDialog"})}},{name:"Change Theme",icon:qu.sunIcon,click:function(){I(!0)}}],["hoverClosestCartesian","hoverCompareCartesian","toggleSpikelines"],[{name:"Auto Scale (Ctrl+Shift+A)",icon:ds.Icons.autoscale,click:function(){$(!0)}},"zoomIn2d","zoomOut2d","autoScale2d","zoom2d","pan2d"]]}}async function J9({plotData:L,volumeBars:I,setMaximizePlot:$}){const se=Object.keys(L.layout).filter(i=>i.startsWith("xaxis")).filter(i=>L.layout[i].showticklabels||L.layout[i].matches==null),Pe=L.data.filter(i=>{var _;return(_=i==null?void 0:i.name)==null?void 0:_.startsWith("Volume")});let R={},E=I||{old_nticks:{}};const e=window.innerWidth,w=window.innerHeight;let k=w>420&&e<920?8:w>420&&e<500?9:7;return e<750?(Pe.forEach(i=>{i.type=="bar"&&(i.opacity=1,i.marker.line.width=.09,I.yaxis==null&&(E.yaxis="yaxis"+i.yaxis.replace("y",""),R[E.yaxis+".tickfont.size"]=k,E.tickfont=L.layout[E.yaxis].tickfont||{},L.layout.margin.l-=40))}),se.forEach(i=>{var _;((_=I.old_nticks)==null?void 0:_[i])==null&&(R[i+".nticks"]=6,E.old_nticks[i]=L.layout[i].nticks||10)}),$(!0),await Lc()):window.MODEBAR.style.cssText.includes("display: none")&&(await Lc(!1),$(!1),I.old_nticks!=null&&se.forEach(i=>{I.old_nticks[i]!=null&&(R[i+".nticks"]=E.old_nticks[i],E.old_nticks[i]=void 0)}),I.yaxis!=null&&Pe.forEach(i=>{i.type=="bar"&&(i.opacity=.5,i.marker.line.width=.2,R[E.yaxis+".tickfont.size"]=E.tickfont.size+3,L.layout.margin.l+=40,E.yaxis=void 0)})),{volume_update:E,layout_update:R,plotData:L}}const Q9=N7(I7);function Y5(L,I){var se,Pe;I||(I=[(se=L[0])==null?void 0:se.x[L[0].x.length-1e3],(Pe=L[0])==null?void 0:Pe.x[L[0].x.length-1]]);const $=[];return L.forEach(R=>{const E={...R},e=["x","y","low","high","open","close","text","customdata"],w=R.x?R.x:[],k=[];for(let _=0;_=I[0]&&w[_]<=I[1]&&k.push(_);e.forEach(_=>{R[_]&&Array.isArray(R[_])&&(E[_]=R[_].filter((y,h)=>k.includes(h)))}),["marker","line"].forEach(_=>{var y;(y=R[_])!=null&&y.color&&Array.isArray(R[_].color)&&(E[_]={...R[_]},E[_].color=R[_].color.filter((h,l)=>k.includes(l)))}),$.push(E)}),$.length===0?L:$}async function M_({event:L,figure:I}){var $,se;try{const Pe=I.data.filter(e=>e.x!==void 0&&e.x.length>0&&e.x[0]!==void 0);if(Pe.length===0)return I;const R=L?[L["xaxis.range[0]"],L["xaxis.range[1]"]]:[($=Pe[0])==null?void 0:$.x[Pe[0].x.length-1e3],(se=Pe[0])==null?void 0:se.x[Pe[0].x.length-1]],E=Y5(I.data,R);return I.data=E,I.layout.xaxis.range=R,I}catch(Pe){console.log("error",Pe)}}function eM({json:L,date:I,cmd:$,title:se,globals:Pe,theme:R,info:E}){var De,Ee,Me,he;const e=L7();In.useEffect(()=>{e&&e.capture("chart",E)},[]),L.layout.width=void 0,L.layout.height=void 0,(Ee=(De=L.layout)==null?void 0:De.title)!=null&&Ee.text&&(L.layout.title.text="");const[w,k]=In.useState(L),[i,_]=In.useState({}),[y,h]=In.useState(!1),[l,t]=In.useState(se),[o,r]=In.useState({}),[n,a]=In.useState(!1),[s,u]=In.useState({name:""}),[p,c]=In.useState(!1),[b,g]=In.useState(null),[f,v]=In.useState({old_nticks:{}}),[m,x]=In.useState(!1),[T,d]=In.useState(!1),[M,A]=In.useState(!1),[C,P]=In.useState(w),[O,z]=In.useState([]),[B,Y]=In.useState(!1),[D,G]=In.useState(!0),[V,j]=In.useState(!1),[W,Z]=In.useState(!1),[ie,te]=In.useState(!1),[J,X]=In.useState({}),[ee,re]=In.useState([]),[oe,ue]=In.useState([]),ce=()=>u({name:""});function de(fe){var be,Ie,Te,Ne,qe;console.log("onDeleteAnnotation",fe);const ae=(Ie=(be=C==null?void 0:C.layout)==null?void 0:be.annotations)==null?void 0:Ie.findIndex(ve=>ve.text===fe.text);console.log("index",ae),ae>-1&&((Ne=(Te=C==null?void 0:C.layout)==null?void 0:Te.annotations)==null||Ne.splice(ae,1),P({...C}),z((qe=C==null?void 0:C.layout)==null?void 0:qe.annotations))}function me(fe){U7({plotData:C,popupData:fe,setPlotData:P,setModal:u,setOnAnnotationClick:X,setAnnotations:z,onAnnotationClick:J,ohlcAnnotation:ee,setOhlcAnnotation:re,annotations:O,plotDiv:b})}In.useEffect(()=>{T&&(u({name:"downloadFinished"}),d(!1))},[T]),In.useEffect(()=>{o&&Object.keys(o).length>0&&(Object.keys(o).forEach(fe=>{C.layout[fe].title={...C.layout[fe].title||{},text:o[fe]},C.layout[fe].showticklabels=!0}),r({}))},[o]);function _e(fe){const ae=b.layout.shapes;if(!ae||ae.length===0)return;const be=ae[ae.length-1];be.line.color=fe,ds.update(b,{},{shapes:ae})}function Se(fe,ae=!1){const be=i[fe]||document.querySelector(`[data-title="${fe}"]`);ae?(be.style.border="transparent",be.style.boxShadow="none"):(be.style.border="1px solid rgba(0, 151, 222, 1.0)",be.style.borderRadius="5px",be.style.borderpadding="5px",be.style.boxShadow="0 0 5px rgba(0, 151, 222, 1.0)"),_({...i,[fe]:be})}function we(){const fe="Auto Scale (Ctrl+Shift+A)",ae=i[fe]||document.querySelector(`[data-title="${fe}"]`);let be=!0;ae.style.border==="transparent"?(b.removeAllListeners("plotly_relayout"),be=!1,b.on("plotly_relayout",Sh(async function(Ie){if(Ie["xaxis.range[0]"]!==void 0)if(M){const Te={...w};await M_({event:Ie,figure:Te}).then(async Ne=>{P(Ne),ds.react(b,Ne.data,Ne.layout);const qe=await u_(Ie,b);ue(qe.yaxis_fixedrange),ds.update(b,{},qe.to_update)})}else{const Te=await u_(Ie,b);ue(Te.yaxis_fixedrange),ds.update(b,{},Te.to_update)}},100))):(b.removeAllListeners("plotly_relayout"),oe.forEach(Ie=>{b.layout[Ie].fixedrange=!1}),ue([]),M&&b.on("plotly_relayout",Sh(async function(Ie){if(Ie["xaxis.range[0]"]===void 0)return;const Te={...w};await M_({event:Ie,figure:Te}).then(async Ne=>{P(Ne),ds.react(b,Ne.data,Ne.layout)})},100))),Se(fe,be)}function xe(){const fe="Edit Color (Ctrl+E)",ae=i[fe]||document.querySelector(`[data-title="${fe}"]`);let be=!0;ae.style.border==="transparent"&&(be=!1),te(!be),Se(fe,be)}return In.useEffect(()=>{V&&(console.log("activateAutoScale",!V),we(),j(!1))},[V]),In.useEffect(()=>{W&&(xe(),Z(!1))},[W]),In.useEffect(()=>{if(B)try{console.log("changeTheme",B);const fe=C==null?void 0:C.data.filter(qe=>{var ve;return(ve=qe==null?void 0:qe.name)==null?void 0:ve.startsWith("Volume")}),ae=!D;window.document.body.style.backgroundColor=ae?"#000":"#fff",C.layout.font={...C.layout.font||{},color:ae?"#fff":"#000"};const be=ae?qu.sunIcon:qu.moonIcon;document.querySelector('[data-title="Change Theme"]').getElementsByTagName("path")[0].setAttribute("d",be.path),document.querySelector('[data-title="Change Theme"]').getElementsByTagName("svg")[0].setAttribute("viewBox",be.viewBox);const Ne=ae?{"#009600":"#00ACFF","#c80000":"#e4003a"}:{"#e4003a":"#c80000","#00ACFF":"#009600"};fe.forEach(qe=>{qe.type==="bar"&&(qe.marker.color=qe.marker.color.map(ve=>Ne[ve]||ve))}),C.layout.template=ae?X7:$7,P({...C}),ds.react(b,C.data,C.layout),G(ae),Y(!1)}catch(fe){console.log("error",fe)}},[B]),In.useEffect(()=>{var fe,ae,be,Ie;if(n){G(!0),j(!1);const Te=["Download CSV","Download Chart as Image","Overlay chart from CSV","Add Text","Change Titles","Auto Scale (Ctrl+Shift+A)","Reset Axes"],Ne=document.querySelector('[data-title="Autoscale"]');Ne&&(Ne.getElementsByTagName("path")[0].setAttribute("d",ds.Icons.home.path),Ne.setAttribute("data-title","Reset Axes")),window.MODEBAR=document.getElementsByClassName("modebar-container")[0];const qe=window.MODEBAR.getElementsByClassName("modebar-btn");if(window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`,qe){const Ae={};for(let ze=0;ze0&&(P(Ue),v(Ve),ds.relayout(b,ze))}),R!=="dark"&&Y(!0);const ve=w.data.map(Ae=>Ae.type==="candlestick");if(((be=w.data[0])==null?void 0:be.x)!==void 0&&((Ie=w.data[0])==null?void 0:Ie.x.length)<=1e3||!ve.includes(!0))return;u({name:"alertDialog",data:{title:"Warning",content:`Data has been truncated to 1000 points for performance reasons. +`).map(D=>D.replace(/\r/g,"")),M=d[0].split(","),A=M.map(D=>D.trim().toLowerCase()),C={};M.length>1&&(C.x=M[0],C.y=M[1]);for(let D=0;DA.includes(D))?E("candlestick"):A.length>=5&&P.forEach(D=>{C[D]=M[P.indexOf(D)+1]}),A.includes("close")&&(b({...c,y:M[A.indexOf("close")]}),C.y=M[A.indexOf("close")]);const z=[];for(let D=1;D2&&(G.test(D[0])?D.splice(0,2):G.test(D[D.length-2])&&D.splice(D.length-2,2),B=D.join("_").replace(/openbb_/g,""))}}catch(D){console.log(D)}l(B),b(C),n(M),o(z)},k_.readAsText(v.target.files[0])},type:"file",id:"csv_file",accept:".csv",style:{marginLeft:10}})]}),Xr("div",{style:{marginTop:15},children:[hr("label",{htmlFor:"csv_trace_type",children:hr("b",{children:"Display data type:"})}),Xr("select",{onChange:v=>{E(v.target.value)},id:"csv_trace_type",style:V5,defaultValue:p[R],children:[R&&hr("option",{value:R,children:p[R]},R),Object.keys(p).map(v=>R!==v&&hr("option",{value:v,children:p[v]},v))]})]}),Xr("div",{style:{marginTop:12},children:[hr("label",{htmlFor:"csv_name",children:hr("b",{children:"Trace Name:"})}),hr("textarea",{id:"csv_name",value:h,onChange:v=>{l(v.target.value)},style:{padding:"5px 2px 2px 5px",width:"100%",maxWidth:"100%",maxHeight:200,marginTop:2},rows:2,cols:20,placeholder:"Enter a name to give this trace"})]}),r.length>0&&Xr(Mg,{children:[["scatter","bar"].includes(R)&&hr("div",{style:{marginTop:15,marginBottom:10},id:"csv_columns",className:"csv_column_container",children:["x","y"].map(v=>Xr("div",{style:{marginTop:10,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[Xr("label",{htmlFor:`csv_${v}`,style:{width:"100px"},children:[v.toUpperCase()," Axis"]}),hr("select",{onChange:m=>{b({...c,[v]:m.target.value})},id:`csv_${v}`,style:{width:"100%"},defaultValue:c[v],children:r.map(m=>hr("option",{value:m,children:m},m))})]},v))}),R==="candlestick"&&hr("div",{id:"csv_columns",className:"csv_column_container",style:{marginTop:15},children:["x","open","high","low","close"].map(v=>Xr("div",{style:{marginTop:10,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[hr("label",{htmlFor:`csv_${v}`,style:{width:"100px"},children:v.charAt(0).toUpperCase()+v.slice(1)}),hr("select",{onChange:m=>{b({...c,[v]:m.target.value})},id:`csv_${v}`,style:{width:"100%"},defaultValue:c[v],children:r.map(m=>hr("option",{value:m,children:m},m))})]},v))}),Xr("div",{style:{marginTop:20},id:"csv_colors",children:[["scatter","bar"].includes(R)&&Xr("div",{children:[hr("label",{htmlFor:"csv_color",children:`${R.charAt(0).toUpperCase()}${R.slice(1)} color`}),hr("input",{type:"color",id:"csv_color",defaultValue:"#FFDD00",style:{margin:"2px 2px 2px 10px"},onChange:v=>{console.log(v.target.value),w(v.target.value)}})]}),R==="candlestick"&&Xr(Mg,{children:[hr("label",{htmlFor:"csv_increasing",children:"Increasing color"}),hr("input",{type:"color",id:"csv_increasing",defaultValue:"#00ACFF",style:{margin:"2px 0px 2px 10px"},onChange:v=>{i(v.target.value)}}),hr("label",{htmlFor:"csv_decreasing",style:{marginLeft:15},children:"Decreasing color"}),hr("input",{style:{margin:"2px 0px 2px 10px"},type:"color",id:"csv_decreasing",defaultValue:"#FF0000",onChange:v=>{y(v.target.value)}})]})]}),Xr("div",{style:{marginTop:20},id:"csv_plot_yaxis_options",children:[R!=="candlestick"&&Xr(Mg,{children:[hr("input",{type:"checkbox",id:"csv_percent_change",name:"csv_plot_yaxis_check",style:{marginBottom:2},onChange:v=>{s({...a,percentChange:v.target.checked,sameYaxis:!1})},checked:!a.sameYaxis&&a.percentChange}),hr("label",{htmlFor:"csv_percent_change",style:{marginLeft:5},children:"Plot as percent change from first value"}),hr("br",{})]}),hr("input",{style:{marginTop:2},type:"checkbox",id:"csv_same_yaxis",name:"csv_plot_yaxis_check",onChange:v=>{s({...a,sameYaxis:v.target.checked,percentChange:!1})},checked:!a.percentChange&&a.sameYaxis}),hr("label",{htmlFor:"csv_same_yaxis",style:{marginLeft:5},children:"Share Y-axis"}),R==="bar"&&Xr("div",{style:{marginTop:2},id:"csv_bar_orientation",children:[hr("input",{type:"checkbox",id:"csv_bar_horizontal",onChange:v=>{b({...c,orientation:v.target.checked?"h":"v"})}}),hr("label",{htmlFor:"csv_bar_horizontal",style:{marginLeft:5},children:"Plot horizontally"})]})]})]}),hr("br",{}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary",id:"csv_cancel",onClick:g,children:"Cancel"}),hr("button",{className:"_btn",id:"csv_submit",onClick:f,children:"Submit"})]})]})})}function R9({csvData:L,plotlyData:I,yaxisOptions:$,traceType:se,traceColor:Pe,traceName:R,options:E,increasingColor:e,decreasingColor:w}){console.log("options",E);const k=I.data[0]||{};k.xaxis===void 0&&(k.xaxis="x"),k.yaxis===void 0&&(k.yaxis="y");let i=k.yaxis,_;const h=Object.keys(I.layout).filter(o=>o.startsWith("yaxis")).map(o=>I.layout[o]).filter(o=>o.side==="left"&&(o.overlaying==="y"||o.fixedrange!==void 0&&o.fixedrange===!0)).length>0?" ":"";if($.sameYaxis!==!0){const o=Object.keys(I.layout).filter(r=>r.startsWith("yaxis")).map(r=>I.layout[r]);_=`y${o.length+1}`,i=`yaxis${o.length+1}`,I.layout[i]={...O9,title:{text:R,font:{size:14},standoff:0},ticksuffix:h,layer:"below traces"}}else _=k.yaxis.replace("yaxis","y");const l={type:se,name:R,showlegend:!0,yaxis:_};let t={};if(["scatter","bar"].includes(se)){if(!L||L.length===0)return I;const o=L.findIndex(n=>n[E.y]!==null&&n[E.y]!==0);if(o===-1)return I;const r={x:[],y:[],customdata:[]};L.forEach(n=>{let a=n[E.y];r.customdata.push(a),$.percentChange&&(se==="scatter"||se==="line")&&(a=(n[E.y]-L[o][E.y])/L[o][E.y]),r.x.push(n[E.x]),r.y.push(a)}),t={...l,x:r.x,y:r.y,customdata:r.customdata,hovertemplate:"%{customdata:.2f}",connectgaps:!0,marker:{color:Pe}},se==="bar"&&(t.orientation=E.orientation,t.marker.opacity=.7,t.connectgaps=void 0,t.hovertemplate=void 0,t.customdata=void 0)}else if(se==="candlestick"){const o={x:[],open:[],high:[],low:[],close:[]};L.forEach(r=>{o.x.push(r[E.x]),o.open.push(r[E.open]),o.high.push(r[E.high]),o.low.push(r[E.low]),o.close.push(r[E.close])}),t={...l,x:o.x,open:o.open,high:o.high,low:o.low,close:o.close,increasing:{line:{color:e,width:.8},fillcolor:e},decreasing:{line:{color:w,width:.8},fillcolor:w}}}return{...I,data:[...I.data,t]}}const T_={padding:"5px 2px 2px 5px",margin:"2px 0"};function z9({open:L,close:I,addAnnotation:$,deleteAnnotation:se,popupData:Pe}){var l,t,o,r,n;const R={text:"",color:"#0088CC",size:18,bordercolor:"#822661",yanchor:"above"},[E,e]=In.useState(R),[w,k]=In.useState(R);Pe&&Pe!==E&&Pe.annotation&&(Pe.annotation=(Pe==null?void 0:Pe.annotation)||{},e(Pe),k(Pe));function i(){console.log("closing"),e(R),k(R),I()}function _(a){console.log(a.target.id.replace("addtext_",""),a.target.value);const s=a.target.id.replace("addtext_",""),u=a.target.value;k({...w,[s]:u})}function y(){console.log("submitting",w),w.text!==""?(E!=null&&E.annotation&&k({...w,annotation:E.annotation}),$(w),I()):(document.getElementById("popup_textarea_warning").style.display="block",document.getElementById("addtext_text").style.border="1px solid red")}function h(){se(E),i()}return hr(gd,{title:"Add Text to Chart",description:"Change the titles on the chart.",open:L,close:i,children:Xr("div",{id:"popup_title",className:"popup_content",children:[Xr("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Xr("div",{style:{marginBottom:20},children:[Xr("label",{htmlFor:"popup_text",children:[hr("b",{children:"Text:"}),hr("div",{id:"popup_textarea_warning",className:"popup_warning",children:"Text is required"})]}),hr("textarea",{id:"addtext_text",style:{...T_,width:"100%",maxWidth:"100%",maxHeight:"200px",marginTop:"8px"},rows:4,cols:50,placeholder:"Enter text here",onChange:_,defaultValue:((l=E==null?void 0:E.annotation)==null?void 0:l.text)||(w==null?void 0:w.text)})]}),Xr("div",{style:{display:"flex",gap:15,alignItems:"center",flexWrap:"wrap",columnCount:2,justifyContent:"space-between",marginBottom:20},children:[hr("label",{htmlFor:"addtext_color",children:hr("b",{children:"Font color"})}),hr("input",{type:"color",id:"addtext_color",style:{margin:"2px 2px 2px 15px"},defaultValue:((t=E==null?void 0:E.annotation)==null?void 0:t.color)||(w==null?void 0:w.color),onChange:_}),hr("label",{htmlFor:"addtext_bordercolor",style:{marginLeft:20},children:hr("b",{children:"Border color"})}),hr("input",{type:"color",id:"addtext_bordercolor",style:{margin:"2px 2px 10px 15px"},defaultValue:((o=E==null?void 0:E.annotation)==null?void 0:o.bordercolor)||(w==null?void 0:w.bordercolor),onChange:_}),hr("label",{htmlFor:"addtext_size",children:hr("b",{children:"Font size"})}),hr("input",{style:{...T_,width:"52px",margin:"0px 0px 0px 2px"},type:"number",id:"addtext_size",onChange:_,defaultValue:((r=E==null?void 0:E.annotation)==null?void 0:r.size)||(w==null?void 0:w.size)}),Xr("div",{children:[hr("label",{htmlFor:"addtext_yanchor",style:{marginRight:31},children:hr("b",{children:"Position"})}),Xr("select",{id:"addtext_yanchor",name:"yanchor",style:{width:"100px"},defaultValue:((n=E==null?void 0:E.annotation)==null?void 0:n.yanchor)||(w==null?void 0:w.yanchor),onChange:_,children:[hr("option",{value:"above",children:"Above"}),hr("option",{value:"below",children:"Below"})]})]})]})]}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary ph-capture",id:"title_cancel",onClick:i,children:"Cancel"}),hr("button",{className:"_btn ph-capture",id:"title_delete",onClick:h,children:"Delete"}),hr("button",{className:"_btn ph-capture",id:"title_submit",onClick:y,children:"Submit"})]})]})})}function D9({plotlyData:L,open:I,close:$,defaultTitle:se,updateTitle:Pe,updateAxesTitles:R}){const[E,e]=In.useState(se),w=Object.keys(L.layout||{}).filter(y=>y.startsWith("yaxis")&&L.layout[y].range!=null),k=Object.keys(L.layout||{}).filter(y=>{var h;return y.startsWith("xaxis")&&L.layout[y].showticklabels!=null&&((h=L.layout[y])==null?void 0:h.anchor)}),[i,_]=In.useState({});return hr(gd,{title:"Chart Titles",description:"Change the titles on the chart.",open:I,close:$,children:Xr("div",{id:"popup_title",className:"popup_content",children:[Xr("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[Xr("div",{children:[hr("label",{htmlFor:"title_text",children:hr("b",{children:"Title:"})}),hr("textarea",{id:"title_text",style:{...V5,width:"100%",maxWidth:"100%",maxHeight:"200px",marginTop:"8px",marginLeft:"0px"},rows:2,cols:20,value:E,onChange:y=>e(y.target.value)})]}),hr("div",{id:"xaxis_div",className:"csv_column_container",style:{marginTop:5,marginBottom:-5},children:k.map((y,h)=>{var l,t;return Xr("div",{style:{marginTop:5,marginBottom:5},children:[hr("label",{htmlFor:`title_${y}`,children:h===0?hr("b",{children:"X axis:"}):Xr("b",{children:["X axis ",h+1,":"]})}),hr("input",{id:`title_${y}`,style:{marginLeft:"0px",padding:"5px 2px 2px 5px"},type:"text",defaultValue:((t=(l=L==null?void 0:L.layout[y])==null?void 0:l.title)==null?void 0:t.text)||"",onChange:o=>{_({...i,[y]:o.target.value})}})]},y)})}),hr("div",{id:"yaxis_div",className:"csv_column_container",style:{marginTop:5,marginBottom:5},children:w.map((y,h)=>{var l,t;return Xr("div",{style:{marginTop:10},children:[hr("label",{htmlFor:`title_${y}`,children:h===0?hr("b",{children:"Y axis:"}):Xr("b",{children:["Y axis ",h+1,":"]})}),hr("input",{id:`title_${y}`,style:{marginLeft:"0px",padding:"5px 2px 2px 5px"},type:"text",defaultValue:((t=(l=L==null?void 0:L.layout[y])==null?void 0:l.title)==null?void 0:t.text)||"",onChange:o=>{_({...i,[y]:o.target.value})}})]},y)})})]}),Xr("div",{style:{float:"right",marginTop:20},children:[hr("button",{className:"_btn-tertiary ph-capture",id:"title_cancel",onClick:$,children:"Cancel"}),hr("button",{className:"_btn ph-capture",id:"title_submit",onClick:()=>{Pe(E),R(i),$()},children:"Submit"})]})]})})}function Cm(){return Cm=Object.assign?Object.assign.bind():function(L){for(var I=1;I'),!0):I?L.some(function($){return I.includes($)})||L.includes("*"):!0}var q9=function(I,$,se){se===void 0&&(se=!1);var Pe=$.alt,R=$.meta,E=$.mod,e=$.shift,w=$.ctrl,k=$.keys,i=I.key,_=I.code,y=I.ctrlKey,h=I.metaKey,l=I.shiftKey,t=I.altKey,o=Ic(_),r=i.toLowerCase();if(!se){if(Pe===!t&&r!=="alt"||e===!l&&r!=="shift")return!1;if(E){if(!h&&!y)return!1}else if(R===!h&&r!=="meta"&&r!=="os"||w===!y&&r!=="ctrl"&&r!=="control")return!1}return k&&k.length===1&&(k.includes(r)||k.includes(o))?!0:k?N9(k):!k},G9=In.createContext(void 0),W9=function(){return In.useContext(G9)};function Z5(L,I){return L&&I&&typeof L=="object"&&typeof I=="object"?Object.keys(L).length===Object.keys(I).length&&Object.keys(L).reduce(function($,se){return $&&Z5(L[se],I[se])},!0):L===I}var Z9=In.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),Y9=function(){return In.useContext(Z9)};function X9(L){var I=In.useRef(void 0);return Z5(I.current,L)||(I.current=L),I.current}var A_=function(I){I.stopPropagation(),I.preventDefault(),I.stopImmediatePropagation()},$9=typeof window<"u"?In.useLayoutEffect:In.useEffect;function _c(L,I,$,se){var Pe=In.useRef(null),R=In.useRef(!1),E=$ instanceof Array?se instanceof Array?void 0:se:$,e=L instanceof Array?L.join(E==null?void 0:E.splitKey):L,w=$ instanceof Array?$:se instanceof Array?se:void 0,k=In.useCallback(I,w??[]),i=In.useRef(k);w?i.current=k:i.current=I;var _=X9(E),y=Y9(),h=y.enabledScopes,l=W9();return $9(function(){if(!((_==null?void 0:_.enabled)===!1||!H9(h,_==null?void 0:_.scopes))){var t=function(s,u){var p;if(u===void 0&&(u=!1),!(V9(s)&&!W5(s,_==null?void 0:_.enableOnFormTags))&&!(_!=null&&_.ignoreEventWhen!=null&&_.ignoreEventWhen(s))){if(Pe.current!==null&&document.activeElement!==Pe.current&&!Pe.current.contains(document.activeElement)){A_(s);return}(p=s.target)!=null&&p.isContentEditable&&!(_!=null&&_.enableOnContentEditable)||dv(e,_==null?void 0:_.splitKey).forEach(function(c){var b,g=gv(c,_==null?void 0:_.combinationKey);if(q9(s,g,_==null?void 0:_.ignoreModifiers)||(b=g.keys)!=null&&b.includes("*")){if(u&&R.current)return;if(j9(s,g,_==null?void 0:_.preventDefault),!U9(s,g,_==null?void 0:_.enabled)){A_(s);return}i.current(s,g),u||(R.current=!0)}})}},o=function(s){s.key!==void 0&&(q5(Ic(s.code)),((_==null?void 0:_.keydown)===void 0&&(_==null?void 0:_.keyup)!==!0||_!=null&&_.keydown)&&t(s))},r=function(s){s.key!==void 0&&(G5(Ic(s.code)),R.current=!1,_!=null&&_.keyup&&t(s,!0))},n=Pe.current||(E==null?void 0:E.document)||document;return n.addEventListener("keyup",r),n.addEventListener("keydown",o),l&&dv(e,_==null?void 0:_.splitKey).forEach(function(a){return l.addHotkey(gv(a,_==null?void 0:_.combinationKey,_==null?void 0:_.description))}),function(){n.removeEventListener("keyup",r),n.removeEventListener("keydown",o),l&&dv(e,_==null?void 0:_.splitKey).forEach(function(a){return l.removeHotkey(gv(a,_==null?void 0:_.combinationKey,_==null?void 0:_.description))})}}},[e,_,h]),Pe}function Lc(L=!0){return new Promise(I=>{window.MODEBAR||(window.MODEBAR=window.document.getElementsByClassName("modebar-container")[0],window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`),window.MODEBAR&&(window.MODEBAR.style.cssText.includes("display: none")||!L?window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`:window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:none;`,I(!0))})}function K9({setModal:L,changeTheme:I,autoScaling:$,Loading:se,changeColor:Pe,downloadFinished:R}){return _c("ctrl+shift+t",()=>{L({name:"titleDialog"})},{preventDefault:!0}),_c("ctrl+t",()=>{L({name:"textDialog"})},{preventDefault:!0}),_c("ctrl+o",()=>{L({name:"overlayChart"})},{preventDefault:!0}),_c(["ctrl+shift+h","ctrl+h"],()=>{Lc()},{preventDefault:!0}),_c("ctrl+e",()=>{Pe(!0)},{preventDefault:!0}),_c("ctrl+shift+s",async()=>{L({name:"downloadCsv"}),await o_(document.getElementById("plotlyChart"),R)},{preventDefault:!0}),_c("ctrl+s",async()=>{Lc(),l_("MainChart",Lc,se,R)},{preventDefault:!0}),_c("ctrl+w",()=>{window.close()},{preventDefault:!0}),{plotGlPixelRatio:1,scrollZoom:!0,responsive:!0,displaylogo:!1,displayModeBar:!0,modeBarButtonsToRemove:["lasso2d","select2d","downloadImage"],modeBarButtons:[[{name:"Download CSV (Ctrl+Shift+S)",icon:qu.downloadCsv,click:async function(e){await o_(e,R)}},{name:"Download Chart as Image (Ctrl+S)",icon:qu.downloadImage,click:async function(){Lc(),await l_("MainChart",Lc,se,R)}}],[{name:"Edit Color (Ctrl+E)",icon:qu.changeColor,click:function(){Pe(!0)}},"drawline","drawopenpath","drawcircle","drawrect","eraseshape"],[{name:"Overlay chart from CSV (Ctrl+O)",icon:qu.plotCsv,click:function(){L({name:"overlayChart"})}},{name:"Add Text (Ctrl+T)",icon:qu.addText,click:function(){L({name:"textDialog",data:{text:""}})}},{name:"Change Titles (Ctrl+Shift+T)",icon:qu.changeTitle,click:function(){L({name:"titleDialog"})}},{name:"Change Theme",icon:qu.sunIcon,click:function(){I(!0)}}],["hoverClosestCartesian","hoverCompareCartesian","toggleSpikelines"],[{name:"Auto Scale (Ctrl+Shift+A)",icon:ds.Icons.autoscale,click:function(){$(!0)}},"zoomIn2d","zoomOut2d","autoScale2d","zoom2d","pan2d"]]}}async function J9({plotData:L,volumeBars:I,setMaximizePlot:$}){const se=Object.keys(L.layout).filter(i=>i.startsWith("xaxis")).filter(i=>L.layout[i].showticklabels||L.layout[i].matches===void 0),Pe=L.data.filter(i=>{var _;return((_=i==null?void 0:i.name)==null?void 0:_.trim())==="Volume"}),R={},E=I||{old_nticks:{}},e=window.innerWidth,w=window.innerHeight,k=w>420&&e<920?8:w>420&&e<500?9:7;return e<750?(Pe.forEach(i=>{i.type==="bar"&&(i.opacity=1,i.marker.line.width=.09,I.yaxis===void 0&&(E.yaxis=`yaxis${i.yaxis.replace("y","")}`,R[`${E.yaxis}.tickfont.size`]=k,E.tickfont=L.layout[E.yaxis].tickfont||{},L.layout.margin.l-=40))}),se.forEach(i=>{var _;((_=I.old_nticks)==null?void 0:_[i])===void 0&&(R[`${i}.nticks`]=6,E.old_nticks[i]=L.layout[i].nticks||10)}),$(!0),await Lc()):window.MODEBAR.style.cssText.includes("display: none")&&(await Lc(!1),$(!1),I.old_nticks!==void 0&&se.forEach(i=>{I.old_nticks[i]!==void 0&&(R[`${i}.nticks`]=E.old_nticks[i],E.old_nticks[i]=void 0)}),I.yaxis!==void 0&&Pe.forEach(i=>{i.type==="bar"&&(i.opacity=.5,i.marker.line.width=.2,R[`${E.yaxis}.tickfont.size`]=E.tickfont.size+3,L.layout.margin.l+=40,E.yaxis=void 0)})),{volume_update:E,layout_update:R,plotData:L}}const Q9=N7(I7);function Y5(L,I){var se,Pe;I||(I=[(se=L[0])==null?void 0:se.x[L[0].x.length-1e3],(Pe=L[0])==null?void 0:Pe.x[L[0].x.length-1]]);const $=[];return L.forEach(R=>{const E={...R},e=["x","y","low","high","open","close","text","customdata"],w=R.x?R.x:[],k=[];for(let _=0;_=I[0]&&w[_]<=I[1]&&k.push(_);e.forEach(_=>{R[_]&&Array.isArray(R[_])&&(E[_]=R[_].filter((y,h)=>k.includes(h)))}),["marker","line"].forEach(_=>{var y;(y=R[_])!=null&&y.color&&Array.isArray(R[_].color)&&(E[_]={...R[_]},E[_].color=R[_].color.filter((h,l)=>k.includes(l)))}),$.push(E)}),$.length===0?L:$}async function M_({event:L,figure:I}){var $,se;try{const Pe=I.data.filter(e=>e.x!==void 0&&e.x.length>0&&e.x[0]!==void 0);if(Pe.length===0)return I;const R=L?[L["xaxis.range[0]"],L["xaxis.range[1]"]]:[($=Pe[0])==null?void 0:$.x[Pe[0].x.length-1e3],(se=Pe[0])==null?void 0:se.x[Pe[0].x.length-1]],E=Y5(I.data,R);return I.data=E,I.layout.xaxis.range=R,I}catch(Pe){console.log("error",Pe)}}function eM({json:L,date:I,cmd:$,title:se,globals:Pe,theme:R,info:E}){var De,Ee,Me,he;const e=L7();In.useEffect(()=>{e&&e.capture("chart",E)},[]),L.layout.width=void 0,L.layout.height=void 0,(Ee=(De=L.layout)==null?void 0:De.title)!=null&&Ee.text&&(L.layout.title.text="");const[w,k]=In.useState(L),[i,_]=In.useState({}),[y,h]=In.useState(!1),[l,t]=In.useState(se),[o,r]=In.useState({}),[n,a]=In.useState(!1),[s,u]=In.useState({name:""}),[p,c]=In.useState(!1),[b,g]=In.useState(null),[f,v]=In.useState({old_nticks:{}}),[m,x]=In.useState(!1),[T,d]=In.useState(!1),[M,A]=In.useState(!1),[C,P]=In.useState(w),[O,z]=In.useState([]),[B,Y]=In.useState(!1),[D,G]=In.useState(!0),[V,j]=In.useState(!1),[W,Z]=In.useState(!1),[ie,te]=In.useState(!1),[J,X]=In.useState({}),[ee,re]=In.useState([]),[oe,ue]=In.useState([]),ce=()=>u({name:""});function de(fe){var be,Ie,Te,Ne,qe;console.log("onDeleteAnnotation",fe);const ae=(Ie=(be=C==null?void 0:C.layout)==null?void 0:be.annotations)==null?void 0:Ie.findIndex(ve=>ve.text===fe.text);console.log("index",ae),ae>-1&&((Ne=(Te=C==null?void 0:C.layout)==null?void 0:Te.annotations)==null||Ne.splice(ae,1),P({...C}),z((qe=C==null?void 0:C.layout)==null?void 0:qe.annotations))}function me(fe){U7({plotData:C,popupData:fe,setPlotData:P,setModal:u,setOnAnnotationClick:X,setAnnotations:z,onAnnotationClick:J,ohlcAnnotation:ee,setOhlcAnnotation:re,annotations:O,plotDiv:b})}In.useEffect(()=>{T&&(u({name:"downloadFinished"}),d(!1))},[T]),In.useEffect(()=>{o&&Object.keys(o).length>0&&(Object.keys(o).forEach(fe=>{C.layout[fe].title={...C.layout[fe].title||{},text:o[fe]},C.layout[fe].showticklabels=!0}),r({}))},[o]);function _e(fe){const ae=b.layout.shapes;if(!ae||ae.length===0)return;const be=ae[ae.length-1];be.line.color=fe,ds.update(b,{},{shapes:ae})}function Se(fe,ae=!1){const be=i[fe]||document.querySelector(`[data-title="${fe}"]`);ae?(be.style.border="transparent",be.style.boxShadow="none"):(be.style.border="1px solid rgba(0, 151, 222, 1.0)",be.style.borderRadius="5px",be.style.borderpadding="5px",be.style.boxShadow="0 0 5px rgba(0, 151, 222, 1.0)"),_({...i,[fe]:be})}function we(){const fe="Auto Scale (Ctrl+Shift+A)",ae=i[fe]||document.querySelector(`[data-title="${fe}"]`);let be=!0;ae.style.border==="transparent"?(b.removeAllListeners("plotly_relayout"),be=!1,b.on("plotly_relayout",Sh(async function(Ie){if(Ie["xaxis.range[0]"]!==void 0)if(M){const Te={...w};await M_({event:Ie,figure:Te}).then(async Ne=>{P(Ne),ds.react(b,Ne.data,Ne.layout);const qe=await u_(Ie,b);ue(qe.yaxis_fixedrange),ds.update(b,{},qe.to_update)})}else{const Te=await u_(Ie,b);ue(Te.yaxis_fixedrange),ds.update(b,{},Te.to_update)}},100))):(b.removeAllListeners("plotly_relayout"),oe.forEach(Ie=>{b.layout[Ie].fixedrange=!1}),ue([]),M&&b.on("plotly_relayout",Sh(async function(Ie){if(Ie["xaxis.range[0]"]===void 0)return;const Te={...w};await M_({event:Ie,figure:Te}).then(async Ne=>{P(Ne),ds.react(b,Ne.data,Ne.layout)})},100))),Se(fe,be)}function xe(){const fe="Edit Color (Ctrl+E)",ae=i[fe]||document.querySelector(`[data-title="${fe}"]`);let be=!0;ae.style.border==="transparent"&&(be=!1),te(!be),Se(fe,be)}return In.useEffect(()=>{V&&(console.log("activateAutoScale",!V),we(),j(!1))},[V]),In.useEffect(()=>{W&&(xe(),Z(!1))},[W]),In.useEffect(()=>{if(B)try{console.log("changeTheme",B);const fe=C==null?void 0:C.data.filter(qe=>{var ve;return((ve=qe==null?void 0:qe.name)==null?void 0:ve.trim())==="Volume"}),ae=!D;window.document.body.style.backgroundColor=ae?"#000":"#fff",C.layout.font={...C.layout.font||{},color:ae?"#fff":"#000"};const be=ae?qu.sunIcon:qu.moonIcon;document.querySelector('[data-title="Change Theme"]').getElementsByTagName("path")[0].setAttribute("d",be.path),document.querySelector('[data-title="Change Theme"]').getElementsByTagName("svg")[0].setAttribute("viewBox",be.viewBox);const Ne=ae?{"#009600":"#00ACFF","#c80000":"#e4003a"}:{"#e4003a":"#c80000","#00ACFF":"#009600"};fe.forEach(qe=>{qe.type==="bar"&&Array.isArray(qe.marker.color)&&(qe.marker.color=qe.marker.color.map(ve=>Ne[ve]||ve))}),C.layout.template=ae?X7:$7,P({...C}),ds.react(b,C.data,C.layout),G(ae),Y(!1)}catch(fe){console.log("error",fe)}},[B]),In.useEffect(()=>{var fe,ae,be,Ie;if(n){G(!0),j(!1);const Te=["Download CSV","Download Chart as Image","Overlay chart from CSV","Add Text","Change Titles","Auto Scale (Ctrl+Shift+A)","Reset Axes"],Ne=document.querySelector('[data-title="Autoscale"]');Ne&&(Ne.getElementsByTagName("path")[0].setAttribute("d",ds.Icons.home.path),Ne.setAttribute("data-title","Reset Axes")),window.MODEBAR=document.getElementsByClassName("modebar-container")[0];const qe=window.MODEBAR.getElementsByClassName("modebar-btn");if(window.MODEBAR.style.cssText=`${window.MODEBAR.style.cssText}; display:flex;`,qe){const Ae={};for(let ze=0;ze0&&(P(Ue),v(Ve),ds.relayout(b,ze))}),R!=="dark"&&Y(!0);const ve=w.data.map(Ae=>Ae.type==="candlestick");if(((be=w.data[0])==null?void 0:be.x)!==void 0&&((Ie=w.data[0])==null?void 0:Ie.x.length)<=1e3||!ve.includes(!0))return;u({name:"alertDialog",data:{title:"Warning",content:`Data has been truncated to 1000 points for performance reasons. Please use the zoom tool to see more data.`}});const Ce=Y5(w.data);P({...w,data:Ce}),A(!0),j(!0)}},[n]),Xr("div",{className:"relative h-full",children:[p&&hr("div",{className:"absolute inset-0 flex items-center justify-center z-[100]",children:Xr("svg",{className:"animate-spin h-20 w-20 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[hr("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),hr("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8z"})]})}),Xr("div",{id:"loading",className:"saving",children:[hr("div",{id:"loading_text",className:"loading_text"}),hr("div",{id:"loader",className:"loader"})]}),hr(L9,{title:(Me=s==null?void 0:s.data)==null?void 0:Me.title,content:(he=s==null?void 0:s.data)==null?void 0:he.content,open:s.name==="alertDialog",close:ce}),hr(I9,{addOverlay:fe=>{console.log(fe),C.layout.showlegend=!0,P(fe),a(!1)},plotlyData:C,setLoading:c,open:s.name==="overlayChart",close:ce}),hr(D9,{updateTitle:fe=>t(fe),updateAxesTitles:fe=>r(fe),defaultTitle:l,plotlyData:C,open:s.name==="titleDialog",close:ce}),hr(z9,{popupData:s.name==="textDialog"?s==null?void 0:s.data:null,open:s.name==="textDialog",close:ce,addAnnotation:fe=>me(fe),deleteAnnotation:fe=>de(fe)}),hr(Y7,{open:ie,onColorChange:_e}),hr(P9,{open:s.name==="downloadFinished",close:ce}),Xr("div",{className:"relative h-full",id:"MainChart",children:[Xr("div",{className:"_header relative gap-4 py-2 text-center text-xs flex items-center justify-between px-4 text-white",children:[hr("div",{className:"w-1/3",children:hr("svg",{xmlns:"http://www.w3.org/2000/svg",width:"64",height:"40",fill:"none",viewBox:"0 0 64 40",children:hr("path",{fill:"#fff",d:"M61.283 3.965H33.608v27.757h25.699V19.826H37.561v-3.965H63.26V3.965h-1.977zM39.538 23.792h15.815v3.965H37.561v-3.965h1.977zM59.306 9.913v1.983H37.561V7.931h21.745v1.982zM33.606 0h-3.954v3.965H33.606V0zM25.7 3.966H0V15.86h25.7v3.965H3.953v11.896h25.7V3.966h-3.955zm0 21.808v1.983H7.907v-3.965h17.791v1.982zm0-15.86v1.982H3.953V7.931h21.745v1.982zM37.039 35.693v2.952l-.246-.246-.245-.245-.245-.247-.245-.246-.246-.246-.245-.245-.245-.247-.247-.246-.245-.246-.245-.246-.245-.246-.246-.246h-.49v3.936h.49v-3.198l.246.246.245.246.245.246.245.246.246.246.246.246.245.247.246.245.245.246.245.247.245.246.246.245.245.246h.245v-3.936h-.49zM44.938 37.17h-.491v-1.477h-2.944v3.937h3.93v-2.46h-.495zm-2.944-.246v-.739h1.962v.984h-1.962v-.245zm2.944.984v1.23h-2.944V37.66h2.944v.247zM52.835 37.17h-.49v-1.477h-2.946v3.937h3.925v-2.46h-.489zm-2.944-.246v-.739h1.963v.984h-1.965l.002-.245zm2.944.984v1.23H49.89V37.66h2.946v.247zM29.174 35.693H25.739v3.936H29.663v-.491H26.229v-.984h2.943v-.493H26.229v-1.476h3.434v-.492h-.489zM13.37 35.693H9.934v3.937h3.925v-3.937h-.49zm0 .738v2.709h-2.945v-2.955h2.943l.001.246zM21.276 35.693h-3.435v3.937h.491v-1.476h3.434v-2.461h-.49zm0 .738v1.23h-2.944v-1.476h2.944v.246z"})})}),hr("p",{className:"font-bold w-1/3 flex flex-col gap-0.5 items-center",children:l}),Xr("p",{className:"w-1/3 text-right text-xs",children:[new Intl.DateTimeFormat("en-GB",{dateStyle:"full",timeStyle:"long"}).format(I).replace(/:\d\d /," "),hr("br",{}),hr("span",{className:"text-grey-400",children:$})]})]}),hr("div",{className:P7("w-full sm:pb-12",{"h-[calc(100%-10px)]":m,"h-[calc(100%-50px)]":!m}),children:hr(Q9,{onInitialized:()=>{if(!b){const fe=document.getElementById("plotlyChart");console.log("plot",fe),fe&&g(fe),fe.globals=Pe}n||a(!0)},className:"w-full h-full",divId:"plotlyChart",data:C.data,layout:C.layout,config:K9({setModal:u,changeTheme:Y,autoScaling:j,Loading:c,changeColor:Z,downloadFinished:d})})})]})]})}function tM(){const[L,I]=In.useState(null),[$,se]=In.useState({});In.useEffect(()=>{{const E=setInterval(()=>{if(window.json_data){const e=window.json_data;console.log(e),I(e),clearInterval(E)}},100);return()=>clearInterval(E)}},[]);const R=(E=>{var y,h,l,t;if(!E)return null;const e={added_traces:[],csv_yaxis_id:null,cmd_src_idx:null,cmd_idx:null,cmd_src:"",old_margin:null,title:""},w=(h=(y=E.layout)==null?void 0:y.title)==null?void 0:h.text.replace(/ -/g,"").replace(/-/g,"").replace(/|<\/b>/g,"").replace(/ /g,"_"),k=new Date().toISOString().slice(0,10).replace(/-/g,""),i=new Date().toISOString().slice(11,19).replace(/:/g,"");window.title=`openbb_${w}_${k}_${i}`.replace(/_{2,}/g,"_"),E.layout.annotations!==void 0&&E.layout.annotations.forEach(function(o){if(o.text!==void 0&&o.text[0]==="/"){e.cmd_src=o.text,e.cmd_idx=E.layout.annotations.indexOf(o),o.text="";const r=E.layout.margin;e.old_margin={...r},r.t!==void 0&&r.t>40&&(r.t=40),E.cmd==="/stocks/candle"&&(r.r-=50)}}),E.data.forEach(function(o){if(o.name!==void 0){const r=o.name.length;o.name=`${o.name} `,o.hoverlabel={namelength:r}}});const _=((t=(l=E.layout)==null?void 0:l.title)==null?void 0:t.text)||"Interactive Chart";return e.title=_,{data:E,date:new Date,globals:e,cmd:E.command_location,posthog:E.posthog,python_version:E.python_version,pywry_version:E.pywry_version,terminal_version:E.terminal_version,theme:E.theme,title:_}})(L);if(R){R.posthog.collect_logs&&!$&&se({api_host:"https://app.posthog.com",autocapture:{css_selector_allowlist:[".ph-capture"]},capture_pageview:!1,loaded:function(k){const i=(R==null?void 0:R.log_id)||"";i!==""&&i!=="REPLACE_ME"&&k.identify(i),k.onFeatureFlags(function(){k.isFeatureEnabled("record-pywry",{send_event:!1})||k.stopSessionRecording(),k.isFeatureEnabled("collect-logs-pywry",{send_event:!1})?k.has_opted_out_capturing()&&k.opt_in_capturing():k.opt_out_capturing()})}});const E={INFO:{command:R.cmd,title:R.title,date:R.date,python_version:R.python_version,pywry_version:R.pywry_version,terminal_version:R.terminal_version}},e=hr(eM,{json:R.data,date:R.date,cmd:R.cmd,title:R.title,globals:R.globals,theme:R.theme,info:E});return R.posthog.collect_logs&&$?hr(C7,{apiKey:"phc_vhssDAMod5qIplznQ75Kdgz4aB1qPFmeVmfEOZ4hkRw",options:$,children:e}):e}else return hr("div",{className:"absolute inset-0 flex items-center justify-center z-[100]",children:Xr("svg",{className:"animate-spin h-20 w-20 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[hr("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),hr("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8z"})]})})}tT.render(hr(F_.StrictMode,{children:hr(tM,{})}),document.getElementById("root"));