1/* JavaScript for SimSim.Run. Copyright 2026. All rights reserved. */ 2!function(t){"use strict";function e(t){return t}const i=Intl.DateTimeFormat("en-US",{year:"numeric",month:"long",day:"numeric"}).format,s=Intl.DateTimeFormat("en-US",{year:"numeric",month:"numeric"}).format;class a extends Set{hasAny(t){for(const e of t)if(this.has(e))return e;return!1}}const o={contextMenuTarget:null,contextMenuID:null,input_original:{},beforeUnloadFormId:"",inputLastSaved:"",modalMenuData:{},modalID:null,observers:{},canvasContext:document.createElement("canvas").getContext("2d"),plots:{},plots_extra:{},plot_selection:{},plot_selection_init:{},sim_id:null,user_logged_in:!1};window.turnstileCallback=function(){let t=document.getElementById("turnstile-submit");t?t.disabled=!1:console.warn("Turnstile form submit button does not exist.")};const l=["title","keywords","remove_outliers","comment"],n=["access_level","access_handles","access_emails","access_email_domains"],r=["constant","uniform_lo","uniform_hi","normal_mean","normal_std","general"],_=[...r,"note","weight","enabled","selected","interpolate"],d="Current Price",c="Current Share-Price",u="Mixture Distribution",p="Earnings Yield (Annualized)",m="Future Year",h="Internal Rate of Return (IRR)",f="Price Change (Annualized)",b="Present Value",g="Net Present Value Ratio",v="Return on Buyback (ROB)",y="Return on Intrinsic Value (ROIV)",w="Return on Intrinsic Value (ROIV) for Company A",x="Return on Intrinsic Value (ROIV) for Company B",k="Return on Issuance (ROIS)",S="Return on Issuance (ROIS) for Company A",I="Return on Issuance (ROIS) for Company B",A="Return on Issuance (ROIS) for Buyer",E="P/S Ratio",P="Swap Ratio (A/B)",D="Total Return (Annualized)",z="Weighted Sum",N="Share Price",B="Share Price FX",M="Market Cap",T="Market Cap FX",R="P/S",C="P/B Tangible",F="P/E",Y="P/FCF",O="Earnings Yield",L="FCF Yield",V="Dividend Yield",q="Dividend / Assets",j="Net Share Buyback Yield",W="Net Share Buyback / Assets",K="Net Share Buyback / Assets (Qrt)",G="Share Buyback ROIV (Mean)",U="Share Buyback ROIV (Std)",X="Share Buyback ROB (Mean)",J="Share Buyback ROB (Std)",H="Cumulative Dividend",Q="Cumulative Share Buyback",Z="Return on Intrinsic Value (ROIV Cumulative)",tt="Return on Buyback (ROB Cumulative)",et="EV / EBIT",it="EV / EBITDA",st="EV / Sales",at="EBIT / EV",ot="EBITDA / EV",lt="Sales",nt="Sales Normalized",rt="Cost of Sales",_t="SG&A",dt="R&D",ct="Interest",ut="Income Tax",pt="Depr & Amor",mt="Other Expenses",ht="Net Income",ft="FCF",bt="EBITDA",gt="Sales Growth",vt="Sales YOY",yt="Sales CAGR",wt="EBITDA YOY",xt="EBITDA CAGR",kt="Net CapEx / Sales",St="Net CapEx / Sales (Cum)",It="R&D / Sales",At="R&D / Sales (Cum)",Et="Acq & Divest / Assets",Pt="Acq & Divest / Assets (Cum)",Dt="Spin-Off",zt="Spin-Off Yield",Nt="Spin-Off Yield (Cum)",Bt="CapEx",$t="Chg Debt",Mt="Chg Invest",Tt="Acq & Divest",Rt="Dividend",Ct="Net Share Buyback",Ft="Other Cash Flows",Yt="Cash & Equiv",Ot="Receivables",Lt="Inventory",Vt="Other Current Assets",qt="PP&E",jt="Investments",Wt="Intangibles",Kt="Other Assets",Gt="Total Assets",Ut="Total Equity",Xt="Minority Interest",Jt="Payables",Ht="Current Debt",Qt="Other Current Liabilities",Zt="LT Debt",te="Other Liabilities",ee="Shares Basic",ie="Shares Diluted",se="Shares Change",ae="Shares Change Implied",oe="Gross Margin",le="Operating Margin",ne="Net Margin",re="FCF Margin",_e="ROTA",de="Current Ratio",ce="Quick Ratio",ue="Cash Ratio",pe="Interest / EBITDA",me="Interest / Op.Income",he="Debt / Assets",fe="Debt / EBITDA",be="Debt / FCF",ge="Net Debt / Assets",ve="Net Debt / EBITDA",ye="Net Debt / FCF",we="Asset Turnover",xe="Inventory Turnover",ke="DS Outstanding",Se="DS Inventory",Ie="Nominal",Ae="Real",Ee="Index",Pe="Rate",De="PV (Mean)",ze="PV (Std)",Ne="PV Per Share (Mean)",Be="PV Per Share (Std)",$e="NPV Ratio (Mean)",Me="NPV Ratio (Std)",Te="Max Drawdown",Re="Max Pullup",Ce="1-3Y Nom.",Fe="3-5Y Nom.",Ye="5-7Y Nom.",Oe="7-10Y Nom.",Le="1-3Y Real",Ve="3-5Y Real",qe="5-7Y Real",je="7-10Y Real",We="Guests",Ke="Users",Ge="New Users",Ue="Sim Created",Xe="Sim Runs",Je="Sim Views",He="Data Views",Qe={close:N,close_fx:B,mcap:M,mcap_fx:T,ps:R,pb:"P/B",pb_tangible:C,pe:F,pe_adj:"P/E Adj.",pfcf:Y,earnings_yield:O,fcf_yield:L,div_yield:V,div_to_assets:q,net_share_buyback_yield:j,net_share_buyback_to_assets:W,net_share_buyback_to_assets_qrt:K,net_share_buyback_roiv_mean:G,net_share_buyback_roiv_std:U,net_share_buyback_rob_mean:X,net_share_buyback_rob_std:J,dividend_cum:H,share_buyback_cum:Q,share_buyback_cum_roiv:Z,share_buyback_cum_rob:tt,ev_ebit:et,ev_ebitda:it,ev_sales:st,ev_ebit_yield:at,ev_ebitda_yield:ot,sales:lt,sales_norm:nt,cost_sales:rt,sga:_t,research_dev:dt,interest_net
2:ct,income_tax:ut,depr_amor:pt,other_expenses:mt,net_income:ht,net_income_adj:"Net Income Adj.",fcf:ft,ebitda:bt,sales_yoy:vt,sales_cagr:yt,ebitda_yoy:wt,ebitda_cagr:xt,net_capex_to_sales:kt,net_capex_to_sales_cum:St,rd_to_sales:It,rd_to_sales_cum:At,acq_divest_to_assets:Et,acq_divest_to_assets_cum:Pt,spin_off_yield:zt,spin_off_yield_cum:Nt,depr_amor_cf:"Depr & Amor CF",capex:Bt,non_cash_items:"Non-Cash Items",chg_working_capital:"Chg Working Capital",chg_debt:$t,chg_invest:Mt,acq_divest:Tt,dividend:Rt,net_share_buyback:Ct,ncf_other:Ft,cash_equiv:Yt,receivables:Ot,inventory:Lt,other_cur_assets:Vt,ppe_net:qt,investments:jt,intangibles:Wt,other_assets:Kt,total_assets:Gt,total_equity:Ut,minority_interest:Xt,payables:Jt,cur_debt:Ht,other_cur_liab:Qt,lt_debt:Zt,other_liab:te,shares_basic:ee,shares_diluted:ie,shares_chg:se,shares_chg_implied:ae,gross_margin:oe,op_margin:le,net_margin:ne,net_margin_adj:"Net Margin Adj.",fcf_margin:re,roa:"ROA",rota:_e,roe:"ROE",current_ratio:de,quick_ratio:ce,cash_ratio:ue,interest_to_ebitda:pe,interest_to_op_income:me,debt_to_assets:he,debt_to_ebitda:fe,debt_to_fcf:be,net_debt_to_assets:ge,net_debt_to_ebitda:ve,net_debt_to_fcf:ye,asset_turnover:we,inventory_turnover:xe,dso:ke,dsi:Se,yield:Ie,yield_real:Ae,index:Ee,rate:Pe,max_drawdown:Te,max_pullup:Re,pv_mean:De,pv_std:ze,pv_per_share_mean:Ne,pv_per_share_std:Be,npv_ratio_mean:$e,npv_ratio_std:Me,mean_ann_ret_1_3y:Ce,mean_ann_ret_3_5y:Fe,mean_ann_ret_5_7y:Ye,mean_ann_ret_7_10y:Oe,mean_ann_ret_1_3y_real:Le,mean_ann_ret_3_5y_real:Ve,mean_ann_ret_5_7y_real:qe,mean_ann_ret_7_10y_real:je,num_guests_unique:We,num_users_unique:Ke,num_users_created:Ge,num_sim_created:Ue,num_sim_runs:Xe,num_sim_views:Je,num_data_views:He};function Ze({x:t,x1:e,x2:i,y1:s,y2:a}){return s+(a-s)*(t-e)/(i-e)}function ti({id:t,func:e,data:i=null,once:s=!0}){const a=document.getElementById(t);if(a){var l=o.observers[t];l||(l=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting&&(e(i),s&&l.disconnect())})}),o.observers[t]=l),l.observe(a)}else console.warn(`HTML element with ID '${t}' does not exist.`)}function ei({id:t,color:e,timeout:i=300}){if(t){var s=$("#"+t);if(s){var a=s.css("backgroundColor");s.css("backgroundColor",e),setTimeout(function(){s.css("backgroundColor",a)},i)}}}function ii(t){ei({id:t,color:"lightgreen"})}function si(t){ei({id:t,color:"lightpink"})}function ai(t){const e=o.plots[t].cloneNode(!0);return e.querySelectorAll("svg").forEach(t=>{const e=t.getAttribute("x")||0,i=t.getAttribute("y")||0,s=htl.svg`<g transform="translate(${e}, ${i})"></g>`;wi({src_elm:t,dest_elm:s,names:["text-anchor","font-family","font-size","fill","stroke","color","style"]}),s.append(...t.childNodes),t.parentNode.replaceChild(s,t)}),(new XMLSerializer).serializeToString(e)}jQuery.fn.reverse=[].reverse;const oi={hide:["bi-eye-slash-fill","bi-eye-fill"],star:["bi-star-fill","bi-star"],"up-down":["bi-arrow-up-square-fill","bi-arrow-down-square-fill"]};function li(t){for(let i of t){var e=document.getElementById(i);e&&(e.checked=!e.checked)}}function ni(t){$("#"+t)?.removeClass("is-invalid"),$("#"+t+"-err")?.html("")}function ri({id:t,errors:e}){$("#"+t)?.addClass("is-invalid");var i=$("#"+t+"-err");if(i){var s='<ul class="small ps-4 mb-0">';for(let t of e)s+=`<li>${t}</li>`;s+="</ul>",i.html(s)}}function _i(){$(":input.is-invalid").reverse().each(function(){!function(t){var e=t.closest("div.modal");for(e&&Si({modal_id_full:e.id});t;){var i=t.closest("div.tab-pane");if(t=null,i&&i.id){let e=`button.nav-link[data-bs-target='#${i.id}']`,s=document.querySelector(e);s&&!s.classList.contains("is-invalid")&&(s.classList.add("is-invalid"),s.click(),t=s)}}}(this)})}function di({search:t="",modal:e=!1}={}){$.fn.dataTable.ext.search.push(function(t,e,i){if("table_sim_models"!==t.nTable.id)return!0;if(document.getElementById("show_favorite_models")?.checked){let e=t.api.row(i).node();return e.querySelector('input[type="checkbox"]')?.checked??!0}return!0});const i=new DataTable("#table_sim_models",{order:[[0,"asc"]],columnDefs:[{orderable:!1,targets:[0,1]}],pageLength:5,pagingType:"numbers",search:{search:t},language:{search:"",searchPlaceholder:"Ex: Present Value"},layout:{top:"search",topStart:null,topEnd:null,bottomStart:"info",bottomEnd:"paging"},initComplete:function(){$("#table_sim_models_wrapper div.dt-search input").removeClass("form-control-sm").focus(),$("#table_sim_models").removeClass("d-none")}});$("#show_favorite_models").on("change",i.draw),e&&(ki({modal_id:"sim-models",enter_submit:!1}
2),$("#modal-menu-sim-models").on("shown.bs.modal",function(){$(this).find("#table_sim_models_wrapper div.dt-search input").focus()}))}function ci(t){$("#"+t).removeClass("show"),o.contextMenuID=null,o.contextMenuTarget=null,$("body").off("click.contextMenuClose"),$("body").off("contextmenu.prevent")}function ui({selector:t,menu_id:e}){$(t).on("contextmenu",function(t){t.preventDefault(),null!=o.contextMenuID&&ci(o.contextMenuID),o.contextMenuID=e,o.contextMenuTarget=this;var i=$("#"+e);i.css({top:t.pageY,left:t.pageX,position:"absolute"}),i.addClass("show"),$("body").on("click.contextMenuClose",function(t){ci(e)}),$("body").on("contextmenu.prevent",function(t){t.preventDefault()})})}function pi({root:t=null,form_id:e=null,context_menu:i=!1}){i&&(t=o.contextMenuTarget.getAttribute("data-bs-target")),t||(t=document);var s=e?`[form="${e}"]`:"";return s+=':input:not(button):not([type="hidden"])',(t=$(t)).find(s)}const mi="SIMSIM_DIST=",hi="SIMSIM_INPUTS=";function fi({text:t,prefix:e=""}){localStorage.setItem("clipboard",e+t)}function bi({process:t,prefix:e=""}){const i=localStorage.getItem("clipboard");i&&i.startsWith(e)?t(i.substring(e.length)):alert("No proper data in your clipboard.")}function gi({dist_id:t=null,root:e=null,context_menu:i=!1}){return t||(i&&(e=o.contextMenuTarget.getAttribute("data-bs-target")),t=$(e).find("div.dist-form").first().attr("id")),t}function vi({dist_id:t,data:e}){e.enabled=!0,function({data:t,field_names:e,prefix_id:i=null}){for(let s of e)if(s in t){let e=t[s],a=i?i+"-"+s:s,o=document.getElementById(a);o&&("checkbox"==o.type?o.checked=e:o.value=e)}}({field_names:_,data:e,prefix_id:t});var i=new Ti(t);""==i.selected&&(i.selected="constant",alert("The copied dist-type is not supported here.\nPlease check the dist is correct.")),i.setInputFields(),i.plot(),Ei({checkbox_id:t+"-enabled",div_id:t+"-main"})}function yi({plot_id:t,button_id:e,dist_id:i=null,dest:s=null,name:a="All",bins:l=100,smooth:n=!1}){try{const f=o.plots_extra[t],b=f.kind,g=f.wide_data;var r,_,d,c,u,p,m,h=f.note;switch(b){case cs:case us:r=gs({plot_id:t,name:a,wide_data:g}),c=(_=new Ni({points:r,sort:!0,normalize:!0})).min(),u=_.max(),[p,m]=_.mean_std(),d=b==us,n&&(d&&(_=_.interpolate()),_=_.kde(),d=!0);break;case hs:{r=gs({plot_id:t}),_=new Ni({points:r,sort:!0});const e=new Set(r.map(t=>t.number));(n||e.size>1)&&(_=_.kde(Ni.ARGS_KDE_VIOLINS)),c=_.min(),u=_.max(),[p,m]=_.mean_std(),d=!0;break}case ms:[r,h]=vs({plot_id:t}),c=(_=new ns(r).pmf({max_std:3,len:l})).min(),u=_.max(),[p,m]=_.mean_std(),d=!0;break;case ps:console.warn("Copy must be done directly from the sub-plot.");break;default:[r,h]=vs({plot_id:t,name:a,wide_data:g}),c=ss.min(r),u=ss.max(r),p=ss.mean(r),m=ss.standardDeviation(r),_=new Bi({values:r,bins:l}),(d=n||_.use_histogram)&&(_=_.kde())}const v={note:h,selected:_.length>1?"general":"constant",constant:p,uniform_lo:c,uniform_hi:u,normal_mean:p,normal_std:m,general:_.toString(),interpolate:d};if(i)vi({dist_id:i,data:v});else if("dist-form"==s){const t=o.modalMenuData[o.modalID];t?(vi({dist_id:t.data.dist_id,data:v}),t.modal.hide()):si(e)}else fi({text:JSON.stringify(v),prefix:mi}),ii(e)}catch(t){si(e),console.warn(t)}}function wi({src_elm:t,dest_elm:e,names:i,remove:s=!0}
2){Array.isArray(i)||(i=[i]),i.forEach(i=>{t.hasAttribute(i)?e.setAttribute(i,t.getAttribute(i)):s&&e.removeAttribute(i)})}function xi({src_id:t,dest_id:e}){_.forEach(i=>function({src_id:t,dest_id:e}){const i=document.getElementById(t),s=document.getElementById(e);i&&s&&("checkbox"===i.type?s.checked=i.checked:s.value=i.value,wi({src_elm:i,dest_elm:s,names:["readonly"]}))}({src_id:t+"-"+i,dest_id:e+"-"+i})),wi({src_elm:document.getElementById(t),dest_elm:document.getElementById(e),names:["data-update"]});var i=document.getElementById(t+"-plot");document.getElementById(e+"-plot").innerHTML=i.innerHTML,Ei({checkbox_id:e+"-enabled",div_id:e+"-main"}),Di(e)}function ki({modal_id:t,focus_submit:e=!1,enter_submit:i=!1}){const s="modal-menu-"+t,a=document.getElementById(s);if(a){var l=new bootstrap.Modal("#"+s,{});o.modalMenuData[t]={modal:l,data:null};var n=document.getElementById(s+"-submit");e&&a.addEventListener("shown.bs.modal",()=>n.focus()),i&&a.addEventListener("keypress",function(t){if("Enter"===t.key){t.preventDefault();const e=new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window,ctrlKey:t.ctrlKey,metaKey:t.metaKey});n.dispatchEvent(e)}})}else console.warn(`Modal-menu ID ${s} was not found.`)}function Si({modal_id:t,modal_id_full:e=null,data:i=null}){var s,a;e&&(a="modal-menu-",t=(s=e).startsWith(a)?s.substring(11):s);var l=o.modalMenuData[t];return l?(l.data=i,o.modalID=t,l.modal.show()):console.warn(`modalMenuData not found '${t}'`),l}function Ii(t){document.getElementById("_tooltip").style.visibility="hidden",document.body.removeEventListener("click",Ii,!0)}function Ai(t){var e={};return $(`:input[form='${t}']`).each(function(t,i){i.id&&(e[i.id]="checkbox"==i.type?i.checked:i.value)}),e}function Ei({checkbox_id:t,div_id:e}){const i=document.getElementById(t);if(i){const t=document.getElementById(e);i.checked?t.classList.remove("opacity-25"):t.classList.add("opacity-25")}}function Pi(t,e={}){new Ti(t).plot(e)}function Di(t){r.forEach(e=>document.getElementById(t+"_div_"+e)?.classList.add("d-none"));const e=e=>{document.getElementById(t+"_div_"+e)?.classList.remove("d-none")};switch(document.getElementById(t+"-selected").value){case"constant":e("constant");break;case"uniform":e("uniform_lo"),e("uniform_hi");break;case"normal":e("normal_mean"),e("normal_std");break;case"general":e("general")}}function zi(t){(t=$(t||document.body)).find("div.dist-form").addBack("div.dist-form").each((t,e)=>{!function(t){return!!(t.offsetWidth||t.offsetHeight||t.getClientRects().length)}(e)?e.setAttribute("data-update","plot"):Pi(e.id)})}class Ni{constructor({points:t=null,values:e=null,prob:i=null,reduce:s=!1,sort:a=!1,normalize:o=!1}){if(t)this.points=t;else{if(!e)throw Error("Must be called with either 'points' or 'values' and 'prob'.");var l=e.length;if(i&&l!=i.length)throw Error("Array lengths must be equal.");if(i||(i=new Float64Array(l).fill(1/l)),s){var n={};for(var r of e)n[r]=0;e.map((t,e)=>n[t]=n[t]+i[e]),e=Object.keys(n).map(t=>+t),i=Object.values(n),l=e.length}this.points=Array(l);for(let t=0;t<l;t++)this.points[t]={value:e[t],prob:i[t]}}o&&this.normalize(),a&&this.sort()}get length(){return this.points.length}toString(){var t="";return this.points.forEach(e=>t+=`${e.value} ; ${e.prob}\n`),t}toArrays(){const t=this.length;var e=new Float64Array(t),i=new Float64Array(t);for(let s=0;s<t;s++){const t=this.points[s];e[s]=t.value,i[s]=t.prob}return[e,i]}area(){const t=this.points,e=this.length;var i=0;for(let s=1;s<e;s++)i+=(t[s].value-t[s-1].value)*(t[s].prob+t[s-1].prob);return.5*i}normalize(){const t=this.length;var i=function(t,i=e){return i!==e&&(t=t.map(t=>i(t))),ss.sum(t)}(this.points,t=>t.prob);if(0!=i)for(let e=0;e<t;e++)this.points[e].prob/=i;else{const e=1/t;for(let i=0;i<t;i++)this.points[i].prob=e}}scale({mult:t=1,add:e=0}){this.points.forEach(i=>i.value=t*i.value+e)}sort(){this.points.sort((t,e)=>t.value-e.value)}remove_prob_zero(){this.points=this.points.filter(t=>0!=t.prob)}remove_outside({lo:t=-1/0,hi:e=1/0}){this.points=this.points.filter(i=>i.value>=t&&i.value<=e)}min(){return Oi(this.points,t=>t.value)}max(){return Li(this.points,t=>t.value)}max_prob(){return Li(this.points,t=>t.prob)}prob_loss(t=0){var e=0,i=0;for(let s=0;s<this.length;s++){let a=this.points[s],o=a.value,l=a.prob;e+=l,o<t&&(i+=l)}return i/e}mean_std(){const t=this.length;if(1==t)return[this.points[0].value,0];if(0==t)throw Error("PMF is empty.");var e=0,i=0,s=0;for(let a=0;a<t;a++){const t=this.points[a],o=t.value,l=t.prob;i+=l,s+=o*l,0!=l&&++e}const a=s/i;var o=0;for(let e=0;e<t;e++){const t=this.points[e],i=t.value;o+=t.prob*(i-a)**2}const l=(e-1)/e;return[a,Math.sqrt(o/(l*i))]}interpolate(t=200){if(1==this.length)return this;if(0==this.length)throw Error("PMF is empty.");this.sort();var[e,i]=this.toArrays();const s=d3.scaleLinear().domain(e).range(i);var a=Vi({start:e.at(0),stop:e.at(-1),len:t}),o=new Float64Array(t);for(let e=0;e<t;e++)o[e]=s(a[e]);return new Ni({values:a,prob:o})}insert_bounds({lo:t=-1/0,hi:e=1/0}){var i=this.points[0],s=[i];for(let a=1;a<this.points.length;a++){let o=this.points[a];function l(t){if(i.value<t&&o.value>t){let e=Ze({x:t,x1:i.value,y1:i.prob,x2:o.value,y2:o.prob});s.push({value:t,prob:e})}}t!=-1/0&&l(t),e!=1/0&&l(e),s.push(o),i=o}return new Ni({points:s,normalize:!0})}static ARGS_KDE_SIM={len:200,len_taper:5,h_factor:.3};static ARGS_KDE_VIOLINS={len:100,len_taper:0,h_factor:.2};kde({len:t=100,len_taper:e=2,h_factor:i=.2}={}){if(this.length<2)return this;var[s,a]=this.toArrays();const[o,l]=this.mean_std(),n=1.06*i*l*this.length**-.2,r=1/n,_=this.length*n*Math.sqrt(2*Math.PI),d=ss.min(s),c=ss.max(s),u=(c-d)/(t-2*e-1);var p=Vi({start:d-u*e,stop:c+u*e,len:t}),m=new Float64Array(t);for(let e=0;e<t;e++){let t=p[e];var h=0;for(let e=0;e<this.length;e++){var f=(t-s[e])*r;h+=a[e]*Math.exp(.5*-(f**2))}m[e]=h/_}if(e>0){const i=Vi({start:.1,stop:.9,len:e});for(let s=0;s<e;s++)m[s]*=i[s],m[t-s-1]*=i[s]}return new Ni({values:p,prob:m,normalize:!0})}}class Bi extends Ni{constructor({values:t,bins:e=100}
2){var i=new Ni({values:t,reduce:!0});i.remove_prob_zero();const s=i.length>e;if(s){let s=d3.histogram().thresholds(e)(t);t=s.map(t=>.5*(t.x0+t.x1));var a=function(t,e={inplace:!1}){const i=1/ss.sum(t);if(e.inplace)for(let e=0;e<t.length;e++)t[e]*=i;else t=t.map(t=>t*i);return t}(s.map(t=>t.length));(i=new Ni({values:t,prob:a})).remove_prob_zero()}super({points:i.points,sort:!0}),this.use_histogram=s}}class $i extends Ni{constructor({x_min:t,x_max:e,mean:i=0,stddev:s=1,len:a=60}){const o=s*s,l=1/(2*o),n=Math.sqrt(2*Math.PI*o),r=Vi({start:t,stop:e,len:a}),_=r.map(t=>Math.exp(-((t-i)**2)*l)/n);super({values:r,prob:_})}}class Mi{constructor({id:t,format:e=null,label:i=null,note:s="",weight:a=1,enabled:o=!0,min_incl:l=-1/0,min_excl:n=-1/0,max_incl:r=1/0,max_excl:_=1/0,x_value:d=null}){this.id=t,this.format=e,this.label=i,this.note=s.trim(),this.enabled=o,this.weight=a,this.x_value=d,this.bounds={clip_lo:Math.max(l,n),clip_hi:Math.min(r,_),min_incl:l,min_excl:n,max_incl:r,max_excl:_},this.error=!1}get use_area(){return["uniform","normal"].includes(this.selected)||"general"==this.selected&&this.interpolate}}class Ti extends Mi{constructor(t,e={x_value:null,digits:4}){const i=document.getElementById(t);var s=i.getAttribute("data-extra"),a=JSON.parse(s);const o=i.getAttribute("data-label"),l=document.getElementById(t+"-note")?.value??"",n=+(document.getElementById(t+"-weight")?.value??1),r=document.getElementById(t+"-enabled")?.checked??!0;super({id:t,format:a.format,x_value:e.x_value,label:o,note:l,weight:n,enabled:r,min_incl:+a.min_incl,min_excl:+a.min_excl,max_incl:+a.max_incl,max_excl:+a.max_excl}),this.dist_div=i,this.funcStringToNumber=function(t){switch(t){case"big":return Ui;case"percent":return Xi;default:return Ji}}(this.format),this.funcNumberToString=Hi(this.format,e.digits),this.funcNumberToStringPercent=Hi("percent",e.digits),this.getInputFields()}plot({show_button_status:t=!1}={}){if(da({plot_id:this.id+"-plot",dist:this,text_size:Ls,show_disabled:!0}),t){let t=this.id+"_btn_plot";this.error?si(t):ii(t)}this.dist_div.setAttribute("data-update",null)}getInputFields(){this.selected=document.getElementById(this.id+"-selected").value,this.interpolate=document.getElementById(this.id+"-interpolate").checked,this.constant=this._getInput({id_suffix:"constant",bounds:this.bounds}),this.uniform_lo=this._getInput({id_suffix:"uniform_lo",bounds:this.bounds}),this.uniform_hi=this._getInput({id_suffix:"uniform_hi",bounds:this.bounds}),this.normal_mean=this._getInput({id_suffix:"normal_mean"}),this.normal_std=this._getInput({id_suffix:"normal_std",bounds:{min_incl:0}}),this.general=this._getInputGeneral(),Di(this.id)}setInputFields(){this.error||(document.getElementById(this.id+"-selected").value=this.selected,document.getElementById(this.id+"-interpolate").checked=this.interpolate,this._setInput({id_suffix:"constant",value:this.constant}),this._setInput({id_suffix:"uniform_lo",value:this.uniform_lo}),this._setInput({id_suffix:"uniform_hi",value:this.uniform_hi}),this._setInput({id_suffix:"normal_mean",value:this.normal_mean}),this._setInput({id_suffix:"normal_std",value:this.normal_std}),this._setInputGeneral(),Di(this.id))}tweak({mult:t=1,add:e=0,min_incl:i=-1/0,max_incl:s=1/0}){function a(a){var o=t*a+e;return o=Math.min(o,s),Math.max(o,i)}var o;this.constant=a(this.constant),this.uniform_lo=a(this.uniform_lo),this.uniform_hi=a(this.uniform_hi),this.normal_mean=a(this.normal_mean),this.normal_std=(o=this.normal_std,Math.abs(o*t)),this.general.scale({mult:t,add:e}),this.general.remove_outside({lo:i,hi:s})}smooth(){this.general.length<2||(this.interpolate?this.general=this.general.interpolate().kde():this.general=this.general.kde(),this.selected="general",this.interpolate=!0)}_checkBounds({value:t,min_incl:e=-1/0,min_excl:i=-1/0,max_incl:s=1/0,max_excl:a=1/0}){var o=null;if(Number.isFinite(t)?t<e?o=`Must be greater than or equal to ${e}.`:t<=i?o=`Must be greater than ${i}.`:t>s?o=`Must be less than or equal to ${s}.`:t>=a&&(o=`Must be less than ${a}.`):o="Not a valid number.",o)throw new Error(o)}_mapArray({x:t,func:e,bounds:i}){for(var s=new Float64Array(t.length),a=0;a<t.length;a++){var o,l=t[a];try{s[a]=o=e(l),this._checkBounds({value:o,...i})}catch(t){var n=l.toString().trim();throw new Error(""==n?"Error, string was empty.":`Error in "${n}".`)}}return s}
2_getInput({id_suffix:t,bounds:e}){var i=this.id+"-"+t;try{var s=document.getElementById(i);if(ni(i),!s.checkValidity())throw new Error("Not a valid number.");var a=this.funcStringToNumber(s.value);if(!Number.isFinite(a))throw new Error("Not a valid number.")}catch(t){this.error=!0,ri({id:i,errors:[t.message]})}return a}_setInput({id_suffix:t,value:e}){var i=this.id+"-"+t,s=document.getElementById(i);s&&(s.value=this.funcNumberToString(e))}_setInputGeneral(){var t="";for(const e of this.general.points)t+=this.funcNumberToString(e.value)+" ; "+this.funcNumberToStringPercent(e.prob)+"\n";var e=document.getElementById(this.id+"-general");e&&(e.value=t)}_getInputGeneral(t=200){const e=this.id+"-general";var i=document.getElementById(e).value;ni(e);try{var s=[],a=[],o=i.split(/\r?\n/);for(var l of o)if((l=l.trim()).length>0){var n=l.split(";");if(1==n.length)s.push(n[0].trim()),a.push("");else{if(2!=n.length)throw new Error(`Error in '${l}'`);s.push(n[0].trim()),a.push(n[1].trim())}}if(0==s.length)throw new Error("Error, no data.");if(s.length>t)throw new Error(`Error, max ${t} lines of data.`);const r=1/(s=this._mapArray({func:this.funcStringToNumber,x:s})).length;function _(t){return""!=t?Xi(t):r}return a=this._mapArray({func:_,x:a,bounds:{min_incl:0}}),new Ni({values:s,prob:a,reduce:!0,sort:!0})}catch(d){this.error=!0,ri({id:e,errors:[d.message]})}}}async function Ri({url:t,fetch_options:e={},form_id:i,button_id:s,set_tabs_valid:a=!1,silent:o=!1}){try{const o=await fetch(t,e);if(!o.ok)throw new Error(o.status+" "+o.statusText);const l=await o.json(),n=l?.error;if(n)throw new Error(n);i&&function(t=""){var e=":input.is-invalid";t&&(e+=`[form="${t}"]`),$(e).each((t,e)=>{e.id&&ni(e.id)})}(i),a&&$("button.nav-link.is-invalid").removeClass("is-invalid");const r=l?.input_errors;return r?(s&&si(s),Object.entries(r)?.forEach(([t,e])=>ri({id:t,errors:e})),a&&_i(),null):(s&&ii(s),l?.data??{})}catch(t){return o?console.warn(t):alert(t),null}}async function Ci({url:t,data:e,...i}){const s={method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}};return await Ri({url:t,fetch_options:s,...i})}function Fi(t){alert("The simulation was deleted.\nYou will now be redirected."),window.removeEventListener("beforeunload",Ta),window.location.replace("/")}function Yi(t,i=e){return t.filter(t=>!isNaN(i(t)))}function Oi(t,i=e){return i!==e&&(t=t.map(t=>i(t))),ss.min(t)}function Li(t,i=e){return i!==e&&(t=t.map(t=>i(t))),ss.max(t)}function Vi({start:t,stop:e,len:i}){var s=new Float64Array(i);const a=(e-t)/(i-1);for(let e=0;e<i;e++)s[e]=e*a+t;return s}function qi(t,e){const i=t.length,s=e.length;var a=new Float64Array(i*s),o=0;for(let l=0;l<i;l++)for(let i=0;i<s;i++,o++)a[o]=t[l]*e[i];return a}const ji={k:1e3,m:1e6,b:1e9,t:1e12},Wi={"%":.01},Ki={...Wi,...ji};function Gi(t,e={scales:Ki,case_sensitive:!1}){var i=NaN;if((t=(t=t.trim()).replaceAll(",","")).length>0){const o=t.length-1;var s=t[o];e.case_sensitive||(s=s.toLowerCase());var a=e.scales[s];void 0===a?i=+t:(i=+t.substring(0,o),i*=a),Number.isNaN(i)&&("inf"==(t=t.toLowerCase())||"inft"==t||"infinity"==t?i=1/0:"-inf"!=t&&"-inft"!=t&&"-infinity"!=t||(i=-1/0))}return i}function Ui(t,e={case_sensitive:!1}){return Gi(t,{scales:ji,...e})}function Xi(t,e={case_sensitive:!1}){return Gi(t,{scales:Wi,...e})}function Ji(t){return+t.replaceAll(",","")}function Hi(t,e=3){var i,s;switch(t){case"big":{i={notation:"compact",maximumSignificantDigits:e};const t=Intl.NumberFormat("en",i);s=e=>t.format(e).toLowerCase();break}case"percent":i={style:"percent",maximumSignificantDigits:e},s=t=>t.toLocaleString("en-US",i);break;case"round":i={maximumSignificantDigits:e},s=t=>t.toLocaleString("en-US",i);break;case"none":s=t=>t.toLocaleString("en-US");break;default:s=void 0}return s}function Qi(t){try{if(t<0||t>1)throw new Error("Arg 'value' must be between 0.0 and 1.0 (incl).");return 0==t?"0.0%":1==t?"100%":t<.001?"<0.1%":t>.999?">99.9%":t<.1||t>.99?`${(100*t).toFixed(1)}%`:`${(100*t).toFixed(0)}%`}catch(t){return"-"}}const Zi="Date",ts="Name",es="Value",is="Mean",as="Std";class os{constructor(t){if(this.data={},t){this.data[Zi]=t.date_str.map(t=>new Date(t));for(const e in t)if(Object.hasOwn(t,e)&&"date_str"!=e){const i=Qe[e];i?this.data[i]=t[e]:console.warn(`Time-series not found. key: ${e}, name: ${i}`)}}}rangeRecentYears(t){if(Zi in this.data){const e=this.data[Zi].at(-1),i=new Date(e);if(i.setFullYear(e.getFullYear()-t),i>this.data[Zi].at(0))return[i,e]}return null}toWide(t,e={map_names:null,remove_nan:!1}){var i=[];const s=this.data[Zi];for(let a=0;a<s.length;a++){let o={};o[Zi]=s[a];let l=!1;for(const i of t){let t=e.map_names?.get(i)??i,s=this.data[i][a];if(o[t]=s,e.remove_nan&&Number.isNaN(s)){l=!0;break}}l||i.push(o)}return new ls(i)}toMeanStd({name_mean:t,name_std:e,remove_nan:i=!1}
2){let s=[t,e],a=new Map([[t,is],[e,as]]),o=this.toWide(s,{map_names:a,remove_nan:i});return new ns(o.data)}toNarrow(t,e={map_names:null,split:!1,remove_nan:!1}){var i=[];if(e.split)for(let e=0;e<t.length;e++)i.push([]);const s=this.data[Zi];for(let a=0;a<t.length;a++){let o=t[a],l=e.map_names?.get(o)??o,n=this.data[o];if(n)for(let t=0;t<s.length;t++){let o=s[t],r=n[t];if(!e.remove_nan||!isNaN(r)){let t={};t[Zi]=o,t[es]=r,t[ts]=l,e.split?i[a].push(t):i.push(t)}}else console.warn(`Time-series not found: ${o}`)}return e.split?i.map(t=>new rs(t)):new rs(i)}}class ls{constructor(t){this.data=t}toNarrow(t,e={split:!1,remove_nan:!1}){var i=[];if(e.split)for(let e=0;e<t.length;e++)i.push([]);for(const s of this.data){let a=s[Zi];for(let o=0;o<t.length;o++){let l=t[o],n=s[l];if(e.remove_nan&&isNaN(n))break;let r={};r[Zi]=a,r[es]=n,r[ts]=l,e.split?i[o].push(r):i.push(r)}}return new rs(i)}toNarrowProcess(t,e={name:void 0,remove_nan:!1}){var i=[];for(const s of this.data){let a=t(s);if(e.remove_nan&&isNaN(a))break;let o={};o[Zi]=s[Zi],o[es]=a,o[ts]=e.name,i.push(o)}return new rs(i)}select({names:t,options:e={map_names:null}}){var i=[];for(const s of this.data){let a=s[Zi],o={};o[Zi]=a;for(let i=0;i<t.length;i++){let a=t[i],l=s[a];o[e.map_names?.get(a)??a]=l}i.push(o)}return new ls(i)}toArray(t,e={remove_nan:!0}){var i=[];if(t.constructor===Array){const e=t.map(t=>this.data.map(e=>e[t]));i=i.concat(...e)}else if(t.constructor===String){const e=t;i=this.data.map(t=>t[e])}return e.remove_nan&&(i=Yi(i)),i}normalize({name_scale:t,names:e}){for(const i of this.data){const s=i[t];for(const t of e)i[t]=i[t]/s}}extent({names:t,pad:e=0,zero:i=!1}){return _s({x:this.toArray(t),pad:e,zero:i})}addRange({name:t="range",start:e=0,end:i=1}){const s=this.data.length;if(s>0){const a=(i-e)/s;this.data.forEach((i,s)=>i[t]=s*a+e)}}}class ns extends ls{constructor(t,e={remove_nan:!1}){e.remove_nan&&(t=Yi(t,t=>t[is]),t=Yi(t,t=>t[as])),super(t)}extent({max_std:t=2,pad:e=0,zero:i=!1}){var s=Array(2*this.data.length);for(let e=0;e<this.data.length;e++){const i=this.data[e][is],a=this.data[e][as];s[2*e]=i-a*t,s[2*e+1]=i+a*t}return _s({x:s,pad:e,zero:i})}pmf({max_std:t=3,len:e=100}){for(let t of this.data){const e=t[as],i=e*e;t._variance_factor=1/(2*i),t._denom_factor=1/Math.sqrt(2*Math.PI*i)}let[i,s]=this.extent({max_std:t}),a=Vi({start:i,stop:s,len:e}),o=new Float64Array(e);for(let t=0;t<e;t++)for(let e of this.data)0!=e[as]&&(o[t]+=Math.exp(-((a[t]-e[is])**2)*e._variance_factor)*e._denom_factor);return new Ni({values:a,prob:o,normalize:!0})}}class rs{constructor(t){this.data=t}toArray(t,e={remove_nan:!0}){var i=this.data;t&&(i=i.filter(e=>t.includes(e[ts])));var s=i.map(t=>t[es]);return e.remove_nan&&(s=Yi(s)),s}negate(t=null){for(const e of this.data)(null===t||t.includes(e[ts]))&&(e[es]=-e[es])}rename(t){for(const e of this.data){let i=e[ts],s=t.get(i);s&&(e[ts]=s)}}extent({names:t=null,pad:e=0,zero:i=!1}){return _s({x:this.toArray(t),pad:e,zero:i})}copyDist({name:t="All",num_recent_years:e=null,dist_id:i=null,smooth:a=!1}){var o=this.data;if(t&&"All"!=t&&(o=o.filter(e=>e[ts]==t)),0==(o=Yi(o,t=>t[es])).length)throw new Error("No data.");var l=new Date(Li(o,t=>t[Zi]));if(e){var n=new Date;n.setFullYear(l.getFullYear()-e),o=o.filter(t=>t[Zi]>=n)}var r=new Date(Oi(o,t=>t[Zi]));const _=(r=s(r))==(l=s(l))?r:`${r} - ${l}`,d=o.map(t=>t[es]);var c=ss.min(d),u=ss.max(d),p=ss.mean(d),m=ss.standardDeviation(d),h=new Bi({values:d});const f=a||h.use_histogram;f&&(h=h.kde()),vi({dist_id:i,data:{note:_,selected:"general",constant:p,uniform_lo:c,uniform_hi:u,normal_mean:p,normal_std:m,general:h.toString(),interpolate:f}})}}function _s({x:t,pad:e=0,zero:i=!1,accessor:s}){var[a,o]=d3.extent(t,s);const l=(o-a)*e;return a-=l,o+=l,i&&(a>0&&(a=0),o<0&&(o=0)),[a,o]}const ds="dist",cs="pmf",us="pmf-interpolate",ps="stacked",ms="time-series-mean-std",hs="violins";function fs({plot_id:t,selection:e}){t in o.plot_selection_init||o.sim_id||(o.plot_selection_init[t]=e)}function bs({plot:t,plot_id:e,title:i=null,symbol:s=null,note:a="",kind:l,wide_data:n}){if(e&&t&&(t.setAttribute("xmlns","http://www.w3.org/2000/svg"),(a=a.trim()).length>30&&(a=a.substring(0,30).trim()),o.plots[e]=t,o.plots_extra[e]={kind:l,title:i,note:a,symbol:s,wide_data:n},!e.startsWith("sub_plot"))){var r=document.getElementById(e);r?(r.innerHTML="","string"==typeof t?r.innerHTML=`<img class="plot-dist" src="/static/images/${t}"></img>`:r.append(t)):console.warn(`HTML element with ID '${e}' does not exist.`)}}function gs({plot_id:t}){var e=o.plots[t].value;if(0==(e=structuredClone(e)).length)throw new Error("No data.");return e}function vs({plot_id:t,name:e="All"}){const i=o.plots[t],a=o.plots_extra[t];var l,n=i.value;if(a.kind==ms?(n=Yi(n,t=>t[is]),l=n=Yi(n,t=>t[as])):(a.wide_data?n=new ls(n).toNarrow([e],{remove_nan:!0}).data:(null!=e&&"All"!=e&&(n=n.filter(t=>
2t[ts]==e)),n=Yi(n,t=>t[es])),l=n.map(t=>t[es])),0==n.length)throw new Error("No data.");var r=new Date(Oi(n,t=>t[Zi])),_=new Date(Li(n,t=>t[Zi]));return[l,(r=s(r))==(_=s(_))?r:`${r} - ${_}`]}const ys={scheme:"Tableau10"},ws={range:d3.schemeTableau10.map(t=>d3.interpolateRgb("#ffffff",t)(.6))},xs={scheme:"Blues",range:[.1,1]},ks=Plot.scale({color:{domain:[1,2,3,4,5],...ys}});Plot.scale({color:{domain:[1,2,3,4,5],...ws}});const Ss=ks.apply(1);ks.apply(2),ks.apply(3),ks.apply(4),ks.apply(5);const Is="#e15759",As="#59a14f",Es="#4e79a7",Ps="#f28e2c",Ds="#3a5a7d",zs="#f0abac",Ns="#a6bcd3",Bs="#CCFFCC",$s="#FFCCCC",Ms="#dc3545",Ts=.15,Rs="system-ui, sans-serif",Cs=13,Fs=16,Ys=14,Os=16,Ls=25,Vs=40,qs=20,js=768,Ws=216,Ks=380,Gs=120;function Us({title:t=null,sub_title:e=null,x_label:i=null,y_label:s=null,x_ticks:a=!0,y_ticks:o=!0,height:l=432}){var n={className:"plot-data",width:js,height:l,inset:5,marginBottom:0,marginTop:10,marginLeft:20,marginRight:20,style:{fontFamily:Rs,fontSize:Cs,backgroundColor:"white"}};return t&&(n.marginTop+=20),e&&(n.marginTop+=20),i&&(n.marginBottom+=20),s&&(n.marginLeft+=20),a&&(n.marginBottom+=20),o&&(n.marginLeft+=30),n}function Xs(t,e={use_date:!0}){if(!t.startsWith("sub_plot")){var s="SimSim.Run";return e.use_date&&(s=`${s} - ${i(new Date)}`),Plot.text([s],{frameAnchor:"right",rotate:90,textAnchor:"middle",dx:8,fontSize:12})}}function Js({title:t=null,sub_title:e=null}){var i,s=[];return e?(t&&(i={frameAnchor:"top",textAnchor:"middle",dy:-40,fontSize:Fs,fontWeight:"bold"},s.push(Plot.text([t],i))),i={frameAnchor:"top",textAnchor:"middle",dy:-20,fontSize:Ys},s.push(Plot.text([e],i))):t&&(i={frameAnchor:"top",textAnchor:"middle",dy:-20,fontSize:Fs,fontWeight:"bold"},s.push(Plot.text([t],i))),s}function Hs({x_label:t=null,y_label:e=null,label_center:i=!0,fontWeight:s="bold",x_offset:a=35,y_offset:o=-55}){if(i){var l=[];return t&&l.push(Plot.text([t],{frameAnchor:"bottom",textAnchor:"middle",dy:a,fontSize:Cs,fontWeight:s})),e&&l.push(Plot.text([e],{frameAnchor:"left",textAnchor:"middle",dx:o,fontSize:Cs,fontWeight:s,rotate:270})),l}}function Qs({args:t,domain:e,enabled:i,position:s="below"}){const a=t.width-t.marginLeft-t.marginRight,l=Plot.scale({color:{domain:e,...ys}});i&&(e=e.filter((t,e)=>i[e]));let n=0,r=0,_={};"inside-top"===s?(r=t.marginTop+12.5,_={stroke:"white",strokeOpacity:.5,strokeWidth:2,paintOrder:"stroke"}):r=t.height+10+12.5;let d=0,c=[0];const u=e.map(t=>{const e=function(t,e={size:Cs,family:Rs}){const i=`${e.size}px ${e.family}`,s=o.canvasContext;return s.font!==i&&(s.font=i),s.measureText(t)}(t).width+20+30;n+e>a&&(d+=1,c.push(0),n=0,r+=25);const i={label:t,x:n,y:r,line:d,color:l.apply(t)};return c[d]+=e,n+=e,i}),p=d+1,m=c.map(t=>(a-t+30)/2);if(u.forEach(e=>e.x+=t.marginLeft+m[e.line]),"below"==s){const e=25*p+10;t.height+=e,t.marginBottom+=e}return[Plot.dot(u,{x:{value:"x",scale:null},dx:5,y:{value:"y",scale:null},r:8,fill:"color",symbol:"circle",..._}),Plot.text(u,{x:{value:"x",scale:null},dx:20,y:{value:"y",scale:null},text:"label",textAnchor:"start",fill:"black",fillOpacity:1,fontSize:Cs,..._})]}function Zs(t,e={x:0}){if(Number.isFinite(t)&&t>0)return(i,s,a,o)=>{const[l,n]=s.scales.x.domain,[r,_]=s.scales.y.domain,d=n-l,c=function({value:t,min:e,max:i}){return Math.max(e,Math.min(t,i))}({value:e.x,min:l+.1*d,max:n-.1*d}),u="Prob Loss: "+Qi(t);return Plot.tip([u],{x:c,y:r,dy:-20,textPadding:3,fill:zs,anchor:"middle",frameAnchor:"bottom"}).plot({x:s.scales.x,y:s.scales.y,...o}).querySelector("[aria-label=tip]")}}function ta({prob_loss:t,x_ticks:e,y_min:i}){if(ss.max(t)>0){if(t.length!=e.length)throw new Error("prob_loss.length != x_ticks.length");var s=[];for(let a=0;a<t.length;a++){const o=Qi(t[a]);s.push(Plot.tip([o],{x:e[a],y:i,dy:-20,textPadding:3,fill:zs,anchor:"middle",frameAnchor:"bottom"}))}return s}}function ea(t,{y1:e=null,y2:i=null,color:s=Ds}={}){if(Number.isFinite(t))return Plot.ruleX([t],{y1:e,y2:i,stroke:s,strokeDasharray:5,strokeWidth:1.5})}function ia(t,{x1:e=null,x2:i=null,color:s=Ds}={}){if(Number.isFinite(t))return Plot.ruleY([t],{x1:e,x2:i,stroke:s,strokeDasharray:5,strokeWidth:1.5})}function sa(t,e={axis:"y"}){if(t)return(t,i,s,a)=>
2{if("x"==e.axis){const[t,e]=i.scales.x.domain;if(t<0&&e>=0)return Plot.ruleX([0],{strokeDasharray:10,opacity:.5}).plot({x:i.scales.x,...a}).querySelector("[aria-label=rule]")}else if("y"==e.axis){const[t,e]=i.scales.y.domain;if(t<0&&e>=0)return Plot.ruleY([0],{strokeDasharray:10,opacity:.5}).plot({y:i.scales.y,...a}).querySelector("[aria-label=rule]")}}}function aa({show_grid:t,location:e}){if(t&&t==e)return[Plot.gridX({strokeOpacity:Ts}),Plot.gridY({strokeOpacity:Ts})]}function oa({show_gain_loss:t,data_min:e,data_max:i,zero:s=!1,axis:a="y"}){if(t){var o=[];return s&&(e=Math.min(e,0),i=Math.max(i,0)),"x"==a?(e<0&&o.push(Plot.rectX({length:1},{x1:Math.min(0,i),x2:e,fill:$s})),i>0&&o.push(Plot.rectX({length:1},{x1:Math.max(0,e),x2:i,fill:Bs}))):"y"==a&&(e<0&&o.push(Plot.rectY({length:1},{y1:Math.min(0,i),y2:e,fill:$s})),i>0&&o.push(Plot.rectY({length:1},{y1:Math.max(0,e),y2:i,fill:Bs}))),o}}function la({selector:t,plot_id:e,data:i,x:s,y:a}){if(t){if(!e)throw Error("Arg 'plot_id' missing.");return(t,a,l,n,r,_)=>{const d=function(t,e){let i;return function(...t){clearTimeout(i),i=setTimeout(()=>e.apply(this,t),1e3)}}(0,async t=>await Ci({url:"/user/ajax_set_plot_selection",data:t,silent:!0})),{width:c,height:u,marginTop:p,marginRight:m,marginBottom:h,marginLeft:f}=n,b=[[f,p],[c-m,u-h]],g=d3.brushX().extent(b).on("end",async function(t){var l,{selection:n}=t;if(n){n=n.map(a.x.invert);const[t,e]=n;l=i.filter(i=>i[s]>=t&&i[s]<=e)}else l=i;if(r.dispatchValue(l),o.plot_selection[e]=n,t.sourceEvent&&o.user_logged_in){const t=o.plots_extra[e].symbol??null;t&&await d({symbol:t,plot_id:e,selection:n})}}),v=d3.create("svg:g");v.call(g);var y=o.plot_selection_init?.[e];if(y){"utc"!=a.x.type&&"time"!=a.x.type||(y=y.map(t=>new Date(t))),a.x.clamp(!0);var w=y.map(a.x);v.call(g.move,w),a.x.clamp(!1)}else r.dispatchValue(i);return v.node()}}}function na({hover:t,data:e,x:i,y:s,y1:a,y2:o,color:l,y_format:n,stacked:r=!1}){var _,d,c,u=t=>r?Plot.stackY(t):t;switch(t){case"tip":return a&&o?(d={y:!1,[a]:n,[o]:n},c={[a]:a,[o]:o}):d={y:n},_={x:i,y:s,y1:a,y2:o,stroke:l,fill:"white",channels:c,format:d},Plot.tip(e,Plot.pointerX(u(_)));case"crosshair":return _={x:i,y:s,color:l,opacity:1},Plot.crosshair(e,u(_));case null:case!1:return;default:throw new Error(`Unknown arg for hover: '${t}'`)}}function ra({plot_id:t,sub_plots:e,title:i}){var s=0,a=0,o=[];e.forEach(t=>{var e=parseInt(t.getAttribute("height")),i=parseInt(t.getAttribute("width"));t.setAttribute("x",0),t.setAttribute("y",s),t.removeAttribute("xmlns"),t.setAttribute("overflow","visible"),o.push(t),s+=e,a=Math.max(a,i)});var l=Plot.plot({width:a,height:s,marginRight:20,style:{fontSize:Cs,backgroundColor:"white"},marks:[Xs(t)]});o.push(l);const n=htl.svg`<svg class="plot" width="${a}" height="${s}" viewBox="0 0 ${a} ${s}">${o}</svg>`;return bs({plot:n,plot_id:t,wide_data:!1,kind:ps,title:i}),n}function _a(t,{y_min:e=0,y_scale:i=1,normalize:s="max",stroke:a=Es,fill:o=Ns,opacity:l=1,fillOpacity:n=1}={}){var r,_,d=[],c=5,u=!0;const p=t.bounds.clip_lo,m=t.bounds.clip_hi;switch(t.selected){case"constant":{u=!1;const e=t.constant;_=[{value:e,prob:1}],c=[e];break}case"uniform":{const e=t.uniform_lo,i=t.uniform_hi;_=[{value:e,prob:1},{value:i,prob:1}],c=[e,.5*(e+i),i];break}case"normal":{const e=t.normal_mean,i=t.normal_std;0==i?(u=!1,_=[{value:e,prob:1}],c=[e]):(r=new $i({x_min:e-3.5*i,x_max:e+3.5*i,mean:e,stddev:i}),c=[e-2*i,e,e+2*i]);break}case"general":r=t.general,u=t.interpolate&&r.length>1;break;default:throw new Error(`Invalid selection: '${t.selected}'`)}r||(r=new Ni({points:_})),!u||p==-1/0&&m==1/0||(r=r.insert_bounds({lo:p,hi:m})),_=r.points;const h=r.max_prob();i/=u&&"area"==s?r.area():h;const f=e+i*h;function b(t){return t.value>=p&&t.value<=m?1:.3}if(u)d.push(Plot.areaY(_,{x:"value",y1:e,y2:t=>e+i*t.prob,stroke:a,fill:o,opacity:t=>l*b(t),fillOpacity:t=>n*b(t)}));else{var g=5-4*_.length/150;g=Math.max(g,1),d.push(Plot.ruleX(_,{x:"value",y1:e,y2:t=>e+i*t.prob,stroke:a,strokeWidth:g,opacity:t=>l*b(t)}))}return(r.min()<p||r.max()>m)&&d.push(Plot.text(["Clipped!"],{textAnchor:"middle",fill:Is,y:e+.5,fontSize:Ls})),[d,{pmf:r,x_ticks:c,y_max:f,use_area:u}]}function da({plot_id:t,dist:e,show_title:i=!1,show_label:s=!0,show_disabled:a=!1,text:o=null,text_size:l=Os}){var n,r,_=!0,d=null,c="black",u=null;if(i&&(u=s?e.note?`${e.label} (${e.note})`:e.label:e.note?e.note:e.label),e.error?(o="Error!",c=Ms,l=Vs):e.enabled||a?"same"==e.selected&&(o="(Same as previous)"):o="(Disabled)",o)r=Plot.text([o],{textAnchor:"middle",frameAnchor:"middle",fontSize:l,fill:c}),_=!1;else{let t;[r,t]=_a(e),d=t.x_ticks}return bs({plot:n=Plot.plot({className:"plot-dist",width:Ks,height:Gs,marginBottom:20,marginTop:u?25:5,marginLeft:5,marginRight:5,inset:0,grid:_,style:{fontSize:Cs,backgroundColor:"white"}
2,x:{label:null,ticks:d,inset:qs,tickFormat:Hi(e.format)},y:{label:null,ticks:[.5],domain:[0,1],insetTop:5},marks:[r,ea(e.x_value),Js({title:u}),Plot.axisY({ticks:[]}),Plot.frame({strokeWidth:1})]}),plot_id:t,kind:ds,note:e.note}),n}function ca({plot_id:t,list_dist:e=null,list_dist_id:i=null,title:s=null,format:a=null,label:l=null,cutoff_same:n=!1,max_dists:r=10}){i&&(e=i.map(t=>{const e=o.sim_results?.dists_extra?.[t]?.x_value??null;return new Ti(t,{x_value:e})}));var _=e.length;if(n)for(;_>0&&"same"==e[_-1].selected;)_-=1;var d=[],c=e[0];for(let t=0;t<_;t++){"same"!=e[t].selected&&(c=e[t]),d.push(ua({note:e[t].note,y:t+2})),d.push(ea(e[t].x_value,{y1:t+1,y2:t+2}));const[i]=_a(c,{y_min:t+1,y_scale:1.3,normalize:"max",fill:t});d.push(i)}d.reverse();const u=Array.from({length:_},(t,e)=>e+1),p=Hi(a),m=Hi("round");var h=[Plot.gridX({strokeOpacity:Ts}),Plot.ruleY(u,{opacity:Ts}),Plot.frame(),Js({title:s}),Hs({x_label:null,y_label:l,y_offset:-30}),d];const f=1+(_-1)/3;var b=Plot.plot({className:"plot-dist",width:Ks,height:Gs*f,inset:0,marginBottom:20,marginTop:25,marginLeft:40,marginRight:5,style:{fontSize:Cs,backgroundColor:"white"},color:{scheme:"Blues",range:[.1,1],domain:[0,r-1]},x:{tickFormat:p,label:null,margin:20,inset:qs},y:{tickFormat:m,ticks:u,label:null,margin:20,insetTop:5,domain:[1,_+1.3]},marks:h});return bs({plot:b,plot_id:t,title:s,kind:"dist-multi"}),b}function ua({note:t,y:e}){if(t)return Plot.text([t],{frameAnchor:"left",y:e,dy:12,dx:7,fontSize:Cs,fontWeight:"bold",fill:"black",fillOpacity:1,paintOrder:"stroke",stroke:"white",strokeWidth:2,strokeOpacity:.5})}function pa({plot_id:t,list_dist:e=null,list_dist_id:i=null,title:s=null,format:a=null,label:o=null,show_weights:l=!1}){i&&(e=i.map(t=>new Ti(t)));var n=0,r=[];for(let t=0;t<e.length;t++){let i=e[t];if(i.enabled){const e=ks.apply(t+1),[s]=_a(i,{y_min:n,y_scale:.9,normalize:"max",stroke:e,fill:e,fillOpacity:.6});r.push(s);let a=i.note;""==a&&(a=i.label),l&&(a=`(${i.weight}) ${a}`),r.push(ua({note:a,y:n+1})),++n}}const _=Array.from({length:n-1},(t,e)=>e+1),d=Hi(a);var c=[Plot.gridX({strokeOpacity:Ts}),Plot.ruleY(_,{opacity:Ts}),Plot.frame(),Js({title:s}),Hs({x_label:o}),r];const u=1+(n-1)/2;var p=Plot.plot({className:"plot-dist",width:Ks,height:Gs*u,inset:0,marginBottom:20,marginTop:25,marginLeft:5,marginRight:5,style:{fontSize:Cs,backgroundColor:"white"},x:{tickFormat:d,label:null,margin:20,inset:qs},y:{ticks:[],label:null,margin:20,domain:[0,n]},marks:c});return bs({plot:p,plot_id:t,title:s,kind:"dist-cmp-ver"}),p}function ma({plot_id:t,list_dist:e=null,list_dist_id:i=null,title:s=null,sub_title:a=null,format:o=null,label:l=null,show_weights:n=!1,show_zero_line:r=!1,show_gain_loss:_=!1,show_grid:d="above",legend_position:c="below"}){var u=Us({title:s,sub_title:a,y_ticks:!1,x_label:l});i&&(e=i.map(t=>new Ti(t)));let p=e.map(t=>t.enabled);var m=e.length,h=[],f=1/0,b=-1/0,g=-1/0;for(let t=0;t<m;t++){let i=e[t];if(i.enabled&&i.use_area){const e=ks.apply(t+1),[s,a]=_a(i,{normalize:"area",opacity:1,fillOpacity:.6,stroke:e,fill:e});h.push(s),f=Math.min(f,a.pmf.min()),b=Math.max(b,a.pmf.max()),g=Math.max(g,a.y_max)}}h.reverse(),g==-1/0&&(g=1);for(let t=0;t<m;t++){let i=e[t];if(i.enabled&&!i.use_area){const e=ks.apply(t+1),[s,a]=_a(i,{y_scale:g,normalize:"max",opacity:1,stroke:e,fill:e});h.push(s),f=Math.min(f,a.pmf.min()),b=Math.max(b,a.pmf.max())}}var v=[];for(let t=0;t<m;t++){let i=e[t],s=n?`(${i.weight}) `:"";s+=i.note?` ${i.note} [${t+1}]`:i.label,v.push(s)}var y,w={label:l,tickFormat:Hi(o),inset:5};if(_){w.inset=0;let[t,e]=_s({x:[f,b],pad:qs/js});y=oa({show_gain_loss:_,axis:"x",data_min:t,data_max:e})}else y=[];var x=[...y,aa({show_grid:d,location:"below"}),Plot.frame(),Plot.axisY({ticks:[]}),Js({title:s,sub_title:a}),Hs({x_label:l}),Xs(t),h,aa({show_grid:d,location:"above"}),sa(r,{axis:"x"}),Qs({args:u,domain:v,enabled:p,position:c})],k=Plot.plot({...u,color:{domain:v,...ys}
2,x:w,y:{label:null,inset:0,insetTop:5},marks:x});return bs({plot:k,plot_id:t,title:s,kind:"dist-cmp-hor"}),k}function ha({plot_id:t,pmf:e=null,data_pack:i=null,interpolate:s=!0,prob_loss:a=null,title:o=null,sub_title:l=null,symbol:n=null,note:r="",color:_=Es,color_fill:d=Ns,format:c=null,label:u=null,label_center:p=!0,selector:m=!1,show_zero_line:h=!1,show_gain_loss:f=!1,show_grid:b="above"}){if(i)e=new Ni({values:i.values,prob:i.prob}),a=i.prob_loss,s=i.interpolate;else if(!e)throw new Error("Either arg 'data_pack' or 'pmf' must be provided.");const g=e.points,v="value",y="prob";var w,x,k,S={tickFormat:Hi(c),inset:5};if(S.label=p?null:u,f){S.inset=0;let[t,e]=_s({x:g,pad:qs/js,accessor:t=>t[v]});w=oa({show_gain_loss:f,axis:"x",data_min:t,data_max:e})}else w=[];if(s&&g.length>1)k=Plot.areaY(g,{x:v,y:y,stroke:_,fill:d}),x=us;else{var I=8-6*g.length/150;I=Math.max(I,1),k=Plot.ruleX(g,{x:v,y1:0,y2:y,stroke:_,strokeWidth:I}),x=cs}var A=[...w,aa({show_grid:b,location:"below"}),Plot.frame(),Plot.axisY({ticks:[]}),Js({title:o,sub_title:l}),Hs({x_label:u,label_center:p}),Xs(t),k,aa({show_grid:b,location:"above"}),sa(h,{axis:"x"}),Zs(a),la({selector:m,plot_id:t,data:g,x:v})],E=Plot.plot({...Us({title:o,sub_title:l,y_ticks:!1,x_label:u}),x:S,y:{label:null,inset:0,insetTop:5},marks:A});return r||(r=u??""),bs({plot:E,plot_id:t,symbol:n,kind:x,title:o,note:r}),E}function fa({plot_id:t,data_pack:e=null,title:i=null,sub_title:s=null,symbol:a=null,format:o=null,x_label:l=null,y_label:n=null,selector:r=!1,show_zero_line:_=!1,show_gain_loss:d=!1,show_grid:c="below"}){var u=[],p=[];const m=e.list_kde.length;for(let t=0;t<m;t++){var h=[];const i=e.list_kde[t];if(i.values.length>0){const e=ss.max(i.prob);for(let s=0;s<i.values.length;s++){var f={value:i.values[s],prob:.4*i.prob[s]/e,number:t+1};u.push(f),h.push(f)}p.push(Plot.areaX(h,{x1:t=>t.prob+t.number,x2:t=>-t.prob+t.number,y:"value",stroke:Es,fill:t}))}}const b=Array.from({length:m},(t,e)=>e+1);var g,v={ticks:b,label:null,margin:20,domain:[.5,m+.5]},y={tickFormat:Hi(o),label:null,margin:20};let[w,x]=_s({x:u,pad:qs/js,accessor:t=>t.value});d?(y.inset=0,g=oa({show_gain_loss:d,axis:"y",data_min:w,data_max:x})):g=[];var k=[...g,aa({show_grid:c,location:"below"}),Plot.frame(),Js({title:i,sub_title:s}),Hs({x_label:l,y_label:n}),Xs(t),p,aa({show_grid:c,location:"above"}),sa(_,{axis:"y"}),ta({prob_loss:e.prob_loss,x_ticks:b,y_min:w}),la({selector:r,plot_id:t,data:u,x:"number"})],S=Plot.plot({...Us({title:i,sub_title:s,x_label:l,y_label:n}),color:xs,x:v,y:y,marks:k});return bs({plot:S,plot_id:t,title:i,symbol:a,note:n,kind:hs}),S}function ba({plot_id:t,ts_narrow:e,y_value:i=null,mavg:s=0,title:a=null,sub_title:o=null,symbol:l=null,color:n=Es,color_fill:r=Ns,color_mavg:_=Ps,format:d=null,label:c=null,hover:u=null,selector:p=!1,show_zero_line:m=!1,show_gain_loss:h=!1,show_grid:f="above",x_ticks:b=!0,height:g=432}){var v,y=e.data;const w=Hi(d);var x,k={label:c,tickFormat:w};if(h){k.inset=0;let[t,i]=e.extent({pad:5/g});x=oa({show_gain_loss:h,zero:!0,data_min:t,data_max:i})}else x=[];var S=[...x,aa({show_grid:f,location:"below"}),Plot.frame(),b?null:Plot.axisX({ticks:[]}),Js({title:a,sub_title:o}),Xs(t),Plot.areaY(y,{x:Zi,y:es,stroke:n,fill:r}),s?Plot.lineY(y,Plot.windowY(s,{x:Zi,y:es,stroke:_})):null,aa({show_grid:f,location:"above"}),ia(i),sa(m)];p?(v={selector:p,plot_id:t,data:y,x:Zi},S.push(la(v))):(v={hover:u,data:y,x:Zi,y:es,color:n,y_format:w},S.push(na(v)));var I=Plot.plot({...Us({title:a,sub_title:o,height:g,x_ticks:b}),y:k,marks:S});return bs({plot:I,plot_id:t,symbol:l,wide_data:!1,kind:"time-series",title:a}),I}function ga({plot_id:t,ts_narrow:e,title:i=null,sub_title:s=null,symbol:a=null,format:o=null,label:l=null,hover:n=null,selector:r=!1,show_grid:_="above",show_zero_line:d=!1,show_gain_loss:c=!1,y_lines:u=[],stacked:p=!1,domain:m=null,fix_zigzag:h=!1,legend_position:f="below",height:b=432}){if(!m)throw Error("Arg 'domain' missing.");var g,v=Us({title:i,sub_title:s,height:b}),y=e.data;const w=Hi(o);var x,k={label:l,tickFormat:w};if(c){k.inset=0;let[t,i]=e.extent({pad:10/b,names:m});x=oa({show_gain_loss:c,data_min:t,data_max:i})}else x=[];var S=[x,aa({show_grid:_,location:"below"}),Plot.frame(),Js({title:i,sub_title:s}),Xs(t)];p?h?(g={x:Zi,y:t=>Math.max(0,t[es]),stroke:ts,fill:ts,fillOpacity:.6},S.push(Plot.areaY(y,g)),g={x:Zi,y:t=>Math.min(-1e-35,t[es]),stroke:ts,fill:ts,fillOpacity:.6},S.push(Plot.areaY(y,g))):(g={x:Zi,y:es,stroke:ts,fill:ts,fillOpacity:.6},S.push(Plot.areaY(y,g))):(g={x:Zi,y2:es,stroke:ts,fill:ts,fillOpacity:c?.4:.3},S.push(Plot.areaY(y,g))),S.push(aa({show_grid:_,location:"above"})),S.push(sa(d)),S.push(function({data:t,axis:e}){if(t.length>0)return(e,i,s,a)=>{{const[e,s]=i.scales.y.domain;if((t=t.filter(t=>e<t&&s>=t)).length>0)return Plot.ruleY(t,{strokeDasharray:10,opacity:.5}).plot({y:i.scales.y,...a}).querySelector("[aria-label=rule]")}}}({data:u,axis:"y"})),S.push(Qs({args:v,domain:m,position:f})),r?(g={selector:r,plot_id:t,data:y,x:Zi},S.push(la(g))):(g={hover:n,data:y,stacked:p,x:Zi,y:es,color:ts,y_format:w},S.push(na(g)));var I=Plot.plot({...v,color:{domain:m,...ys}
2,y:k,marks:S});return bs({plot:I,plot_id:t,symbol:a,wide_data:!1,kind:"time-series-multi",title:i}),I}function va({plot_id:t,ts_mean_std:e,max_std:i=2,title:s=null,sub_title:a=null,symbol:o=null,format:l=null,label:n=null,hover:r=null,selector:_=!1,show_gain_loss:d=!1,show_zero_line:c=!1,show_grid:u="above",zero:p=!1,height:m=432}){var h;if(!Number.isInteger(i)||i<1)throw Error("Arg 'max_std' must be an int >= 1");var f=e.data;const b=Hi(l);var g={label:n,tickFormat:b,zero:p};let[v,y]=e.extent({max_std:i,zero:p,pad:5/432});var w;d?(g.inset=0,w=oa({show_gain_loss:d,data_min:v,data_max:y})):w=[];var x=[];for(let t=i;t>0;t--)x.push(Plot.areaY(f,{x:Zi,fill:Ns,opacity:1==t?1:.4,y1:e=>e[is]-t*e[as],y2:e=>e[is]+t*e[as]}));var k=[...w,aa({show_grid:u,location:"below"}),Plot.frame(),Js({title:s,sub_title:a}),Xs(t),...x,Plot.lineY(f,{x:Zi,y:is,stroke:Ds}),aa({show_grid:u,location:"above"}),sa(c)];_?(h={selector:_,plot_id:t,data:f,x:Zi},k.push(la(h))):(h={hover:r,data:f,x:Zi,y:is,color:Ds,y_format:b},k.push(na(h)));var S=Plot.plot({...Us({title:s,sub_title:a,height:m}),y:g,marks:k});return bs({plot:S,plot_id:t,symbol:o,wide_data:!0,kind:ms,title:s}),S}function ya({plot_id:t,ts_narrow:e,y_pos:i=null,y_neg:s=null,title:a=null,sub_title:o=null,symbol:l=null,format:n=null,label:r=null,color:_=Ss,hover:d=null,selector:c=!1,show_grid:u="above",show_zero_line:p=!1,smooth_window:m=7}){var h,f=e.data;const b=Hi(n);f=f.filter(t=>t[ts]==i||t[ts]==s);var g=[aa({show_grid:u,location:"below"}),Plot.frame(),Js({title:a,sub_title:o}),Xs(t),i?Plot.areaY(f,{x:Zi,y:es,filter:t=>t[ts]==i,stroke:As,fill:As,fillOpacity:.6}):null,s?Plot.areaY(f,{x:Zi,y:es,filter:t=>t[ts]==s,stroke:Is,fill:Is,fillOpacity:.6}):null,aa({show_grid:u,location:"above"}),sa(p)];c?(h={selector:c,plot_id:t,data:f,x:Zi},g.push(la(h))):(h={hover:d,data:f,x:Zi,y:es,color:_,y_format:b},g.push(na(h)));var v=Plot.plot({...Us({title:a,sub_title:o}),y:{label:r,tickFormat:b,zero:!0},marks:g});return bs({plot:v,plot_id:t,symbol:l,wide_data:!0,kind:"time-series-pos-neg",title:a}),v}function wa({plot_id:t,ts_wide:e,y1:i,y2:s,title:a=null,sub_title:o=null,symbol:l=null,color_y1:n=Ps,color_y2:r=Es,positiveFill:_=Ns,negativeFill:d="#f7bb80",format:c=null,label:u=null,hover:p=null,selector:m=!1,show_gain_loss:h=!1,show_zero_line:f=!1,show_grid:b="above",zero:g=!1,smooth_window:v=7,x_ticks:y=!0,legend_position:w="below",height:x=432}){var k,S=Us({title:a,sub_title:o,height:x,x_ticks:y}),I=e.data;const A=[s,i],E=Hi(c);var P,D={label:u,tickFormat:E,zero:g};if(h){D.inset=0;let[t,a]=e.extent({names:[i,s],zero:g,pad:5/x});P=oa({show_gain_loss:h,data_min:t,data_max:a})}else P=[];var z=[...P,aa({show_grid:b,location:"below"}),Plot.frame(),y?null:Plot.axisX({ticks:[]}),Js({title:a,sub_title:o}),Xs(t),Plot.differenceY(I,Plot.windowY(v,{x:Zi,y1:i,y2:s,stroke:r,positiveFill:_,negativeFill:d})),Plot.lineY(I,Plot.windowY(v,{x:Zi,y:i,stroke:n})),aa({show_grid:b,location:"above"}),sa(f),Qs({args:S,domain:A,position:w})];m?(k={selector:m,plot_id:t,data:I,x:Zi},z.push(la(k))):(k={hover:p,data:I,x:Zi,y1:i,y2:s,color:r,y_format:E},z.push(na(k)));var N=Plot.plot({...S,color:{domain:A,...ys},y:D,marks:z});return bs({plot:N,plot_id:t,symbol:l,wide_data:!0,kind:"time-series-dif",title:a}),N}function xa({plot_id:t,data_pack:e,title:i=null,sub_title:s=null,symbol:a=null,x_format:o=null,y_format:l=null,x_label:n=null,y_label:r=null,show_zero_line:_=!0,show_gain_loss:d=!0,show_grid:c="above",kind:u="contour",thresholds:p=30}){var m,h,f,b,g={label:null,tickFormat:Hi(o),inset:0},v={label:null,tickFormat:Hi(l)};if("date"==o&&(e.x=e.x.map(t=>new Date(t))),d){v.inset=0;let[t,i]=_s({x:e.y,pad:5/432});m=oa({show_gain_loss:d,data_min:t,data_max:i})}else m=[];if("contour"==u)h=Plot.contour,f=-1/0,b="barycentric";else{if("raster"!=u)throw new Error(`Unknown arg for kind: '${u}'`);h=Plot.raster,f=NaN,b=null}for(let t=0;t<e.bins_x;t++)e.hist2d[0][t]=0,e.hist2d[e.bins_y-1][t]=0;for(let t=0;t<e.bins_y;t++)e.hist2d[t][0]=0,e.hist2d[t][e.bins_x-1]=0;const y=e.hist2d.flat().map(t=>0==t?f:t);var w=[...m,aa({show_grid:c,location:"below"}),Js({title:i,sub_title:s}),Hs({x_label:n,y_label:r,label_center:!0}),Xs(t),h({length:e.bins_x*e.bins_y},{x:(t,i)=>e.x[i%e.bins_x],y:(t,i)=>e.y[Math.floor(i/e.bins_x)],fill:y,width:e.bins_x,height:e.bins_y,interpolate:b,thresholds:p}),aa({show_grid:c,location:"above"}),sa(_),ea(e.x_value),Plot.frame(),Zs(e.x_value_prob_loss,{x:e.x_value})],x=Plot.plot({...Us({title:i,sub_title:s,x_label:n,y_label:r}),color:{scheme:"Blues",range:[.3,1]},x:g,y:v,marks:w});return bs({plot:x,plot_id:t,symbol:a,title:i}),x}class ka{constructor({name:t,symbol:e}){this.name=t,this.symbol=e}_create_title(t=null){var e=`${this.name} (${this.symbol})`;return t&&(e=`${t} for ${e}`),e}}class Sa{constructor({data:t,name:e}){this.name=e,this.symbol=t?.symbol,t?.plot_selection&&!o.sim_id&&(o.plot_selection_init={...t.plot_selection,...o.plot_selection_init})}_create_title(t=null){var e=`${this.name} (${this.symbol})`;return t&&(e=`${t} for ${e}`),e}_updateInput({id:t,value:e,time:i,prefix:s=""}){const a=document.getElementById(t),o=document.getElementById(t+"_update"),l=document.getElementById(t+"_info");if(a&&o){if(a.dataset.value=e,o.checked&&(a.value=e),l){""!=s&&(s+=" ");const t=function(t,e=null){null==e&&(e=new Date);const i=t.getTime()-e.getTime(),s=Math.abs(i)/1e3/60,a=s/60,o=a/24,l=o/365.25,n=12*l;let r;return r=l>=2?Math.floor(l)+" years":l>=1?"1 year":n>=2?Math.floor(n)+" months":o>=2?Math.floor(o)+" days":o>=1?"1 day":a>=2?Math.floor(a)+" hours":a>=1?"1 hour":s>=1?Math.floor(s)+" min":"<1 min",r}(new Date(i));l.title+=`\n${t} ago the value was ${s}${e}`}}else console.warn(`Elements with ID '${t}' or '${t}_update' are missing.`)}}class Ia extends Sa{constructor({data:t,plot_ids:e=[],update_input_ids:i=[],init_input_ids:s=[],init_dist_ids:l=[],modal:n=!0}){if(super({data:t,name:t?.info?.name}),!t)return;var r;this.modal=n,this.currency_financials=t.financials?.extra.currency,this.currency_prices=t.prices?.extra.currency,this.latest_mcap_fx=t.info.extra.mcap_fx,this.latest_ps=t.info.extra.ps,this.is_currency_same=this.currency_prices==this.currency_financials,this.is_currency_same?(this.title_postfix="",this.title_postfix_fx=""):(this.title_postfix=" in "+this.currency_prices,this.title_postfix_fx=" in "+this.currency_financials),e=new a(e),s=new Set(s),i=new a(i),this.init_dist_ids=new a(l),o.sim_id&&(this.init_dist_ids=new a),o.sim_id||(s.has("title")&&(document.getElementById("title").value=this.name),s.has("currency")&&(
2document.getElementById("currency").value=this.currency_financials));const _=t.info?.extra;if(_&&i.size>0){const t=_?.time_price,e=_?.time_financials,s=Hi("big");if(r=i.hasAny(["cur_share_price","cur_share_price_A","cur_share_price_B"])){const e=_.share_price_fx;this._updateInput({id:r,value:e,time:t,prefix:this.currency_financials})}(r=i.hasAny(["cur_shares","cur_shares_A","cur_shares_B"]))&&this._updateInput({id:r,value:s(_.shares),time:e})}this.ts_prices=new os(t.prices?.series),this.ts_financials=new os(t.financials?.series),this.selection_prices_5y=this.ts_prices.rangeRecentYears(5),this.selection_financials_1y=this.ts_financials.rangeRecentYears(1),this.selection_financials_3y=this.ts_financials.rangeRecentYears(3),this.selection_financials_5y=this.ts_financials.rangeRecentYears(5),e.forEach(t=>this["plot_"+t]())}plot_share_price(){var t=[N],e=this.ts_prices.toNarrow(t);ba({plot_id:"plot_share_price",ts_narrow:e,title:this._create_title("Share-Price"+this.title_postfix),label:this.currency_prices,format:"big",hover:"tip"}),this.modal&&ki({modal_id:"share_price"}),this.is_currency_same||(t=[B],ba({plot_id:"plot_share_price_fx",ts_narrow:e=this.ts_prices.toNarrow(t),title:this._create_title("Share-Price"+this.title_postfix_fx),label:this.currency_financials,format:"big",hover:"tip"}),this.modal&&ki({modal_id:"share_price_fx"}))}plot_mcap(){var t=[M],e=this.ts_prices.toNarrow(t);ba({plot_id:"plot_mcap",ts_narrow:e,title:this._create_title("Market-Cap"+this.title_postfix),label:this.currency_prices,format:"big",hover:"tip"}),this.modal&&ki({modal_id:"mcap"}),this.is_currency_same||(t=[T],ba({plot_id:"plot_mcap_fx",ts_narrow:e=this.ts_prices.toNarrow(t),title:this._create_title("Market-Cap"+this.title_postfix_fx),label:this.currency_financials,format:"big",hover:"tip"}),this.modal&&ki({modal_id:"mcap_fx"}))}plot_max_drawdown(){var t=[Te,Re];const e={ts_narrow:this.ts_prices.toNarrow(t),format:"percent",hover:"crosshair",selector:!1};var i=this._create_title("3-Year Max Drawdown & Pullup");ya({plot_id:"plot_max_drawdown_pullup",title:i,y_pos:Re,y_neg:Te,...e}),ya({plot_id:"plot_max_drawdown",title:i=this._create_title("3-Year Max Drawdown"),y_neg:Te,...e}),ya({plot_id:"plot_max_pullup",title:i=this._create_title("3-Year Max Pullup"),y_pos:Re,...e}),this.modal&&ki({modal_id:"max_drawdown"})}plot_present_value(){var t=this.ts_financials.toMeanStd({name_mean:De,name_std:ze});va({plot_id:"plot_present_value",ts_mean_std:t,max_std:2,title:this._create_title(b),label:this.currency_financials,format:"big",selector:!0,zero:!0}),va({plot_id:"plot_present_value_per_share",ts_mean_std:t=this.ts_financials.toMeanStd({name_mean:Ne,name_std:Be}),max_std:2,title:this._create_title("Present Value Per Share"),label:this.currency_financials,format:"big",selector:!0,zero:!0}),t=this.ts_financials.toMeanStd({name_mean:$e,name_std:Me}),va({plot_id:"plot_npv_ratio",title:this._create_title(g),ts_mean_std:t,max_std:2,hover:"tip",format:"percent",show_gain_loss:!0,show_zero_line:!0});var e=[R,$e],i=new Map([[R,E],[$e,g]]),s=this.ts_financials.toWide(e,{map_names:i,remove_nan:!0});s.addRange({name:"opacity",start:1,end:.1}),function({plot_id:t,data_wide:e,x:i,y:s,x_value:a=null,title:o=null,sub_title:l=null,symbol:n=null,opacity:r,radius:_=5,color:d=Es,color_fill:c=Ns,x_format:u=null,y_format:p=null,hover:m=null,selector:h=!1,show_zero_line:f=!1,show_gain_loss:b=!1,show_grid:g="above",height:v=432}){var y,w,x={tickFormat:Hi(u),inset:10,label:null},k={tickFormat:Hi(p),inset:10,label:null},S=e.data;if(b){k.inset=0;let[t,i]=e.extent({pad:10/432,names:[s]});w=oa({show_gain_loss:b,data_min:t,data_max:i})}else w=[];var I=[...w,aa({show_grid:g,location:"below"}),Plot.frame(),Js({title:o,sub_title:l}),Hs({x_label:i,y_label:s}),Xs(t),Plot.dot(S,{x:i,y:s,stroke:d,fill:c,opacity:r,r:_}),ea(a),aa({show_grid:g,location:"above"}),sa(f)];h?(y={selector:h,plot_id:t,data:S,x:Zi},I.push(la(y))):(y={hover:m,data:S,x:i,y:s,color:d,y_format:k.tickFormat},I.push(na(y))),bs({plot:Plot.plot({...Us({title:o,sub_title:l,height:v,x_label:i,y_label:s}),x:x,y:k,color:xs,opacity:{type:"identity"},marks:I}),plot_id:t,symbol:n,wide_data:!0,kind:"scatter",title:o})}({plot_id:"plot_npv_ratio_scatter",data_wide:s,x_value:this.latest_ps,opacity:"opacity",x:E,y:g,title:this._create_title("NPV vs. P/S Ratio"),show_gain_loss:!0,show_zero_line:!0,y_format:"percent"}),this.modal&&ki({modal_id:"present_value"})}plot_ps_ratio(){var t="plot_ps_ratio";fs({plot_id:t,selection:this.selection_prices_5y});var e=[R];ba({plot_id:t,ts_narrow:this.ts_prices.toNarrow(e),symbol:this.symbol,title:this._create_title("P/S Ratio"),y_value:this.latest_ps,hover:"crosshair",selector:!0}),this.modal&&ki({modal_id:"ps_ratio"});const i=this.init_dist_ids.hasAny(["dist_ps_ratio","dist_ps_ratio_y1"]);i&&yi({plot_id:t,dist_id:i,smooth:!0})}plot_pe_ratio(){var t="plot_pe_ratio";fs({plot_id:t,selection:this.selection_prices_5y});var e=[F,Y];ga({plot_id:t,ts_narrow:this.ts_prices.toNarrow(e),title:this._create_title("P/E Ratios"),symbol:this.symbol,domain:e,hover:"crosshair",selector:!0}),this.modal&&ki({modal_id:"pe_ratio"});const i=this.init_dist_ids.hasAny(["dist_pe_ratio","dist_pe_ratio_y1"]);i&&yi({plot_id:t,dist_id:i,smooth:!0,name:F})}plot_pb_ratio(){var t=["P/B",C];ga({plot_id:"plot_pb_ratio",ts_narrow:this.ts_prices.toNarrow(t),title:this._create_title("P/B Ratio"),hover:"tip",selector:!1,domain:t}),this.modal&&ki({modal_id:"pb_ratio"})}plot_earnings_yield(){var t=[O,L];ga({plot_id:"plot_earnings_yield",ts_narrow:this.ts_prices.toNarrow(t),title:this._create_title("Earnings Yield"),format:"percent",domain:t,hover:"crosshair",selector:!0,symbol:this.symbol}),this.modal&&ki({modal_id:"earnings_yield"})}plot_ev_ebitda(){var t=[et,it,st],e=this.ts_prices.toNarrow(t);ga({plot_id:"plot_ev_multiples",ts_narrow:e,title:this._create_title("EV / EBIT & EBITDA & Sales"),domain:t,hover:"crosshair",selector:!0}),t=[at,ot],ga({plot_id:"plot_ev_yields",ts_narrow:e=this.ts_prices.toNarrow(t),format:"percent",title:this._create_title("EBIT & EBITDA / EV"),domain:t,hover:"crosshair",selector:!0}),this.modal&&ki({modal_id:"ev_ebitda"})}plot_sales(){var t="plot_sales";fs({plot_id:t,selection:this.selection_financials_1y});var e=[lt];ba({plot_id:t,ts_narrow:this.ts_financials.toNarrow(e),title:this._create_title("Sales"),label:this.currency_financials,symbol:this.symbol,hover:"tip",format:"big",selector:!0}),this.modal&&ki({modal_id:"sales"});const i=this.init_dist_ids.hasAny(["dist_sales","dist_sales_y1"]);i&&yi({plot_id:t,dist_id:i,smooth:!1})}plot_earnings(){var t="plot_earnings";fs({plot_id:t,selection:this.selection_financials_3y});var e=[ht,ft,bt],i=[bt,ft,ht];ga({plot_id:"plot_earnings",ts_narrow:this.ts_financials.toNarrow(e),title:this._create_title("Earnings"),label:this.currency_financials,hover:"tip",format:"big",selector:!0,domain:i}),this.modal&&ki({modal_id:"earnings"});const s=this.init_dist_ids.hasAny(["dist_earnings","dist_earnings_y1"]);s&&yi({plot_id:t,dist_id:s,smooth:!0,name:ht})}plot_shares(){this._plot_shares("shares")}
2plot_shares_A(){this._plot_shares("shares_A")}plot_shares_B(){this._plot_shares("shares_B")}_plot_shares(t){var e=[ee,ie];ga({plot_id:"plot_"+t,ts_narrow:this.ts_financials.toNarrow(e),title:this._create_title("Shares Basic & Diluted"),format:"big",hover:"tip",domain:e}),this.modal&&ki({modal_id:t})}plot_shares_dilution(){let t=[ee,ie];ba({plot_id:"plot_shares_dilution",ts_narrow:this.ts_financials.toWide(t).toNarrowProcess(t=>t[ie]/t[ee]-1),title:this._create_title("Shares Dilution"),format:"percent",hover:"tip"}),this.modal&&ki({modal_id:"shares_dilution"})}plot_shares_changes(){let t="Actual Change",e="Implied From Net Buyback",i=[se,ae],s=new Map([[se,t],[ae,e]]),a=this.ts_financials.toWide(i,{map_names:s}),o=a.toNarrowProcess(i=>i[e]-i[t]);ra({plot_id:"plot_shares_changes",sub_plots:[wa({plot_id:"sub_plot_shares_changes",ts_wide:a,y1:t,y2:e,title:this._create_title("Changes in Shares"),format:"percent",selector:!1,hover:"tip",show_gain_loss:!0,show_zero_line:!0,smooth_window:1,height:Ws}),ba({plot_id:"sub_plot_shares_changes_dif",ts_narrow:o,title:`Difference = ${e} - ${t}`,format:"percent",hover:"tip",selector:!1,show_gain_loss:!0,show_zero_line:!0,height:Ws,color:"#af7aa1",color_fill:"#d4becd"})],title:this._create_title("Changes in Shares")}),this.modal&&ki({modal_id:"shares_changes"})}plot_balance(){var t=[Yt,Ot,Lt,Vt,qt,jt,Wt,Kt],e=this.ts_financials.toNarrow(t);ga({plot_id:"plot_assets",ts_narrow:e,title:this._create_title("Assets"),label:this.currency_financials,format:"big",hover:"tip",stacked:!0,domain:t}),t=[Ut,Xt,Jt,Ht,Qt,Zt,te],ga({plot_id:"plot_liabilities",ts_narrow:e=this.ts_financials.toNarrow(t),title:this._create_title("Liabilities and Equity"),label:this.currency_financials,format:"big",hover:"tip",stacked:!0,domain:t}),this.modal&&ki({modal_id:"balance"})}plot_balance_ratios(){var t=[Yt,Ot,Lt,Vt,qt,jt,Wt,Kt],e=this.ts_financials.toWide([...t,Gt]);e.normalize({name_scale:Gt,names:t});var i=e.toNarrow(t);ga({plot_id:"plot_assets_ratios",ts_narrow:i,title:this._create_title("Assets"),format:"percent",hover:"tip",stacked:!0,domain:t}),t=[Ut,Xt,Jt,Ht,Qt,Zt,te],(e=this.ts_financials.toWide([...t,Gt])).normalize({name_scale:Gt,names:t}),ga({plot_id:"plot_liabilities_ratios",ts_narrow:i=e.toNarrow(t),title:this._create_title("Liabilities"),format:"percent",hover:"tip",stacked:!0,domain:t}),this.modal&&ki({modal_id:"balance"})}plot_profit_margin(){var t="plot_profit_margin";fs({plot_id:t,selection:this.selection_financials_5y});var e=[oe,le,ne,re];ga({plot_id:t,ts_narrow:this.ts_financials.toNarrow(e),title:this._create_title("Profit Margins"),format:"percent",hover:"tip",selector:!0,domain:e,symbol:this.symbol}),this.modal&&ki({modal_id:"profit_margin"});const i="dist_net_profit_margin";this.init_dist_ids.has(i)&&yi({plot_id:t,dist_id:i,name:ne,smooth:!0})}plot_expenses(){var t=[ht,mt,ut,ct,dt,_t,rt],e=t.slice().reverse(),i=this.ts_financials.toNarrow(t);ga({plot_id:"plot_expenses",ts_narrow:i,title:this._create_title("Expenses"),label:this.currency_financials,format:"big",hover:"tip",stacked:!0,fix_zigzag:!0,domain:e});var s=this.ts_financials.toWide([...t,lt]);s.normalize({name_scale:lt,names:t}),ga({plot_id:"plot_expenses_ratios",ts_narrow:i=s.toNarrow(t),title:this._create_title("Expenses (% of Sales)"),stacked:!0,fix_zigzag:!0,format:"percent",hover:"tip",y_lines:[1],selector:!1,domain:e}),this.modal&&ki({modal_id:"expenses"})}plot_payout(){var t=[Rt,Ct],e=this.ts_financials.toNarrow(t);e.negate(),ga({plot_id:"plot_payout",ts_narrow:e,title:this._create_title("Dividend and Net Share Buyback"),label:this.currency_financials,format:"big",hover:"tip",stacked:!0,fix_zigzag:!0,domain:t}),this.modal&&ki({modal_id:"payout"})}plot_payout_yield(){var t=[V,j];ga({plot_id:"plot_payout_yield",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Dividend and Net Share Buyback Yield"),format:"percent",selector:!1,hover:"tip",stacked:!0,fix_zigzag:!0,domain:t}),this.modal&&ki({modal_id:"payout_yield"})}plot_payout_spinoff(){var t=[zt],e=this.ts_financials.toNarrow(t);e.negate(t),ga({plot_id:"plot_payout_spinoff",ts_narrow:e,title:this._create_title("Spin-Off Yield"),format:"percent",selector:!1,hover:"tip",stacked:!0,fix_zigzag:!0,domain:t}),this.modal&&ki({modal_id:"payout_spinoff"})}plot_payout_to_assets(){var t=[q,W];ga({plot_id:"plot_payout_to_assets",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Dividend and Net Share Buyback (% of Assets)"),format:"percent",selector:!1,hover:"tip",stacked:!0,fix_zigzag:!0,domain:t}),this.modal&&ki({modal_id:"payout_to_assets"})}plot_buyback_returns(){const t=({plot_id:t,name_data:e,title:i,format:s})=>ba({plot_id:t,ts_narrow:this.ts_financials.toNarrow([e]),title:i,format:s,hover:"tip",selector:!1,show_zero_line:!1,height:Ws}),e=({plot_id:t,name_mean:e,name_std:i,title:s})=>va({plot_id:t,ts_mean_std:this.ts_financials.toMeanStd({name_mean:e,name_std:i}),max_std:2,title:s,show_zero_line:!0,hover:"tip",show_gain_loss:!0,format:"percent",height:Ws});ra({plot_id:"plot_buyback_returns",sub_plots:[t({plot_id:"sub_plot_buyback_ps_ratio",format:"big",name_data:R,title:this._create_title("P/S Ratio")}),t({plot_id:"sub_plot_buyback_to_assets",format:"percent",name_data:K,title:"Net Share Buyback (% of Assets)"}
2),e({plot_id:"sub_plot_buyback_roiv",name_mean:G,name_std:U,title:"Return on Intrinsic Value (ROIV Forward)"}),e({plot_id:"sub_plot_buyback_rob",name_mean:X,name_std:J,title:"Return on Buyback (ROB Forward)"})],title:this._create_title("Share Buyback Returns (FORWARD)")}),this.modal&&ki({modal_id:"buyback_returns"})}plot_buyback_returns_cum(){const t=({plot_id:t,name_data:e,title:i,label:s,format:a="percent",show_gain_loss:o=!0})=>(i||(i=e),ba({plot_id:t,ts_narrow:this.ts_financials.toNarrow([e]),title:i,format:a,label:s,show_gain_loss:o,show_zero_line:!1,hover:"tip",selector:!1,height:Ws}));var e="Share Buyback",i="Dividend",s=[e,i],a=[Q,H],o=new Map([[Q,e],[H,i]]);ra({plot_id:"plot_buyback_returns_cum",sub_plots:[ga({plot_id:"sub_plot_payout_cum",ts_narrow:this.ts_financials.toNarrow(a,{map_names:o}),title:this._create_title("Cumulative Payout"),domain:s,format:"big",label:this.currency_financials,stacked:!0,show_gain_loss:!1,show_zero_line:!1,hover:"tip",selector:!1,legend_position:"inside-top",height:Ws}),t({plot_id:"sub_plot_buyback_cum_roiv",name_data:Z}),t({plot_id:"sub_plot_buyback_cum_rob",name_data:tt})],title:this._create_title("Share Buyback Returns (CUMULATIVE)")}),this.modal&&ki({modal_id:"buyback_returns_cum"})}plot_cash_flow(){var t=[ht,Rt,Ct,Bt,pt,$t,Mt,Tt,Ft],e=[ht,pt,Rt,Ct,Bt,$t,Mt,Tt,Ft],i=this.ts_financials.toWide(t),s=i.toNarrow(t);const a=this._create_title("Cash Flow");ga({plot_id:"plot_cash_flow",ts_narrow:s,title:a,label:this.currency_financials,format:"big",hover:"tip",stacked:!0,show_zero_line:!0,fix_zigzag:!0,domain:e});for(const e of i.data){var o=0,l=0;for(const i of t){const t=e[i];t>0?o+=t:l+=t}e.scale=o>0?o:-l}i.normalize({name_scale:"scale",names:t}),ga({plot_id:"plot_cash_flow_ratios",ts_narrow:s=i.toNarrow(t),title:a,y_lines:[-1],format:"percent",hover:"tip",stacked:!0,show_zero_line:!0,fix_zigzag:!0,domain:e}),this.modal&&ki({modal_id:"cash_flow"})}plot_sales_growth(){var t=[vt],e=this.ts_financials.toNarrow(t);ba({plot_id:"plot_sales_yoy",ts_narrow:e,title:this._create_title("Sales Growth YOY"),format:"percent",hover:"tip",selector:!0,show_zero_line:!1,show_gain_loss:!1}),t=[yt],ba({plot_id:"plot_sales_cagr",ts_narrow:e=this.ts_financials.toNarrow(t),title:this._create_title("Sales Growth CAGR"),format:"percent",hover:"tip",selector:!0,show_zero_line:!1,show_gain_loss:!1}),this.modal&&ki({modal_id:"sales_growth"})}plot_ebitda_growth(){var t=[wt],e=this.ts_financials.toNarrow(t);ba({plot_id:"plot_ebitda_yoy",ts_narrow:e,title:this._create_title("EBITDA Growth YOY"),format:"percent",hover:"tip",selector:!0,show_zero_line:!1,show_gain_loss:!1}),t=[xt],ba({plot_id:"plot_ebitda_cagr",ts_narrow:e=this.ts_financials.toNarrow(t),title:this._create_title("EBITDA Growth CAGR"),format:"percent",hover:"tip",selector:!0,show_zero_line:!1,show_gain_loss:!1}),this.modal&&ki({modal_id:"ebitda_growth"})}plot_growth_factors(){const t=({plot_id:t,name_data:e,name_display:i=null,title:s,format:a,hover:o="tip",selector:l=!1})=>{let n=i?new Map([[e,i]]):null;return ba({plot_id:t,ts_narrow:this.ts_financials.toNarrow([e],{map_names:n}),title:s,format:a,hover:o,selector:l,show_zero_line:!1,show_gain_loss:!1,height:Ws})};var e=[t({plot_id:"sub_plot_sales_growth_cum",format:"big",name_data:nt,name_display:gt,title:this._create_title("Sales Growth Cumulative")}),t({plot_id:"sub_plot_capex_to_sales_cum",format:"big",name_data:St,name_display:Bt,title:"(CapEx - Depr & Amor) / Sales (Cumulative)"}),t({plot_id:"sub_plot_rd_to_sales_cum",format:"big",name_data:At,name_display:dt,title:"R&D / Sales (Cumulative)"}),t({plot_id:"sub_plot_acq_divest_to_assets_cum",format:"big",name_data:Pt,name_display:Tt,title:"Acq & Divest / Total Assets (Cumulative)"}),t({plot_id:"sub_plot_spin_off_cum",format:"big",name_data:Nt,name_display:Dt,title:"Spin-Off (Cumulative)"})];ra({plot_id:"plot_growth_factors_cum",sub_plots:e,title:this._create_title("Growth Factors Cumulative")}),ra({plot_id:"plot_growth_factors_yearly",sub_plots:e=[t({plot_id:"sub_plot_sales_growth",format:"percent",name_data:vt,name_display:gt,title:this._create_title("Sales Growth YOY")}
2),t({plot_id:"sub_plot_capex_to_sales",format:"percent",name_data:kt,name_display:Bt,title:"(CapEx - Depr & Amor) / Sales"}),t({plot_id:"sub_plot_rd_to_sales",format:"percent",name_data:It,name_display:dt,title:"R&D / Sales"}),t({plot_id:"sub_plot_acq_divest_to_assets",format:"percent",name_data:Et,name_display:Tt,title:"(Acq - Divest) / Total Assets"}),t({plot_id:"sub_plot_spin_off",format:"percent",name_data:zt,name_display:Dt,title:"Spin-Off",selector:!1})],title:this._create_title("Growth Factors Yearly")}),this.modal&&ki({modal_id:"growth_factors"})}plot_interest_to_ebitda(){var t=[pe,me];ga({plot_id:"plot_interest_to_ebitda",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Interest Expense / EBITDA"),hover:"tip",format:"percent",domain:t}),this.modal&&ki({modal_id:"interest_to_ebitda"})}plot_debt_to_assets(){var t=[he,ge];ga({plot_id:"plot_debt_to_assets",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Total & Net Debt / Assets"),hover:"tip",format:"percent",domain:t}),this.modal&&ki({modal_id:"debt_to_assets"})}plot_debt_to_ebitda(){var t=[fe,ve];ga({plot_id:"plot_debt_to_ebitda",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Total & Net Debt / EBITDA"),hover:"tip",domain:t}),this.modal&&ki({modal_id:"debt_to_ebitda"})}plot_debt_to_fcf(){var t=[be,ye];ga({plot_id:"plot_debt_to_fcf",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Total & Net Debt / FCF"),hover:"tip",domain:t}),this.modal&&ki({modal_id:"debt_to_fcf"})}plot_liquidity(){var t=[de,ce,ue];ga({plot_id:"plot_liquidity",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Liquidity Ratios"),hover:"tip",domain:t}),this.modal&&ki({modal_id:"liquidity"})}plot_return_ratios(){var t=["ROE",_e,"ROA"];ga({plot_id:"plot_return_ratios",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Return on Assets & Equity"),hover:"tip",format:"percent",domain:t}),this.modal&&ki({modal_id:"return_ratios"})}plot_asset_turnover(){var t=[we];ba({plot_id:"plot_asset_turnover",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Asset Turnover"),hover:"tip"}),this.modal&&ki({modal_id:"asset_turnover"})}plot_inventory_turnover(){var t=[xe];ba({plot_id:"plot_inventory_turnover",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Inventory Turnover"),hover:"tip"}),this.modal&&ki({modal_id:"inventory_turnover"})}plot_days_sales(){var t=[ke,Se];ga({plot_id:"plot_days_sales",ts_narrow:this.ts_financials.toNarrow(t),title:this._create_title("Days Sales"),hover:"tip",domain:t}),this.modal&&ki({modal_id:"days_sales"})}}class Aa{constructor({data:t=null,once:e=!0}){this.data=t,ti({id:"plot_sim_earnings",once:e,func:this.plot_sim_earnings.bind(this)}),ti({id:"plot_sim_earnings_yield",once:e,func:this.plot_sim_earnings_yield.bind(this)}),ti({id:"plot_sim_price_change",once:e,func:this.plot_sim_price_change.bind(this)})}set_data(t){this.data=t}_create_title(t){return`${t} for ${this.data.name} (${this.data.symbol})`}_sim_price(){var t,e,i;try{[e,i]=vs({plot_id:"plot_sales"}),[t,i]=vs({plot_id:"plot_ps_ratio",name:R})}catch(t){return void alert("Select some P/S and Sales data.")}return qi(t,e)}_sim_earnings(){var t,e,i;try{[e,i]=vs({plot_id:"plot_sales"}),[t,i]=vs({plot_id:"plot_profit_margin",name:ne})}catch(t){return void alert("Select some Profit Margin and Sales data.")}return qi(t,e)}plot_sim_earnings(){const t=this._sim_earnings();var e=new Bi({values:t}),i=e.kde(Ni.ARGS_KDE_SIM);const s=e.prob_loss(),a=`Sim Earnings (${this.data.currency_financials})`;ha({plot_id:"plot_sim_earnings",pmf:i,prob_loss:s,title:this._create_title(a),note:a,format:"big",selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim_earnings_yield(){const t=this._sim_earnings().map(t=>t/this.data.latest_mcap_fx);var e=new Bi({values:t});const i="Sim Earnings Yield";ha({plot_id:"plot_sim_earnings_yield",pmf:e.kde(Ni.ARGS_KDE_SIM),prob_loss:e.prob_loss(),format:"percent",title:this._create_title(i),note:i,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim_price_change(){const t=this._sim_price().map(t=>t/this.data.latest_mcap_fx-1);var e=new Bi({values:t});const i="Sim Price Change";ha({plot_id:"plot_sim_price_change",pmf:e.kde(Ni.ARGS_KDE_SIM),prob_loss:e.prob_loss(),format:"percent",title:this._create_title(i),note:i,selector:!0,show_gain_loss:!0,show_zero_line:!0})}}function Ea(t,{start:e=1,end:i=10}={}){return Array.from({length:i-e+1},(e,i)=>`${t}${i+1}`)}function Pa(t={}){pa({plot_id:"plot_dist_cmp",list_dist_id:Ea("dist_big_",{start:1,end:5}),format:"big",...t})}function Da(t={}){pa({plot_id:"plot_dist_cmp",list_dist_id:Ea("dist_percent_",{start:1,end:5}),format:"percent",...t})}function za(t={}){ca({plot_id:"plot_dist_multi_earnings",title:"Earnings",list_dist_id:Ea("dist_earnings_y"),format:"big",label:m,...t})}function Na(t={}){ca({plot_id:"plot_dist_multi_future_value",title:"Future Value",list_dist_id:Ea("dist_future_value_y"),format:"big",label:m,...t})}function Ba(t={}){ca({plot_id:"plot_dist_multi_sales",title:"Sales",list_dist_id:Ea("dist_sales_y"),format:"big",label:m,...t})}function $a(t={}){ca({plot_id:"plot_dist_multi_pe_ratio",title:"P/E Ratio",list_dist_id:Ea("dist_pe_ratio_y"),format:"big",label:m,...t})}function Ma(t={}){ca({plot_id:"plot_dist_multi_ps_ratio",title:"P/S Ratio",list_dist_id:Ea("dist_ps_ratio_y"),format:"big",label:m,...t})}function Ta(t){var e=Ai(o.beforeUnloadFormId);JSON.stringify(e)!=o.inputLastSaved&&t.preventDefault()}class Ra{constructor({desc_short:t=null,data:e=null}={}){this.sub_title=t,this._title=document.getElementById("title").value;var i=document.getElementById("sim_id").value;"None"===i&&(i=null),o.sim_id=i,this._plot_dist_label=!0,this._args_json="",this._args_json_last_run="",e&&(e.plot_selection&&(o.plot_selection_init={...e.plot_selection,...o.plot_selection_init}),this._processData(e)),function(){var t={};$(":input").each(function(e,i){i.id&&(t[i.id]="checkbox"==i.type?i.checked:i.value)}),o.input_original=t}(),function(t){var e=Ai(t);o.inputLastSaved=JSON.stringify(e),o.beforeUnloadFormId=t,window.addEventListener("beforeunload",Ta)}("form_sim_edit"),_i(),function(){const t=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){const e=t.target.id;e&&function(t){var e=document.getElementById(t);e&&"plot"==e.getAttribute("data-update")&&Pi(t)}(e)}})});
2document.querySelectorAll("div.dist-form").forEach(e=>{t.observe(e)})}(),ui({selector:"button.nav-link.form-empty",menu_id:"tab-context-menu-form-empty"}),ui({selector:"button.nav-link.form",menu_id:"tab-context-menu-form"}),ui({selector:"button.nav-link.form-dist",menu_id:"tab-context-menu-form-dist"}),ui({selector:"button.nav-link.form-dist-year",menu_id:"tab-context-menu-form-dist-year"}),ki({modal_id:"dist-tweak",enter_submit:!0}),ki({modal_id:"sim-report"}),ki({modal_id:"help"}),ki({modal_id:"comment",enter_submit:!1}),ki({modal_id:"settings",enter_submit:!1}),function({func:t,button_id:e}){document.addEventListener("keydown",function(i){const s=i.target.tagName;if("Enter"===i.key&&("INPUT"===s||"BODY"==s))if(i.preventDefault(),t)t(i);else{const t=document.getElementById(e),s=new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window,ctrlKey:i.ctrlKey,metaKey:i.metaKey});t.dispatchEvent(s)}})}({button_id:"btn_sim"}),document.getElementById("title").addEventListener("input",t=>this.title=t.target.value)}get title(){return this._title}set title(t){"string"==typeof t&&(document.getElementById("title").value=t,t=t.trim(),this._title=t,document.title=t,document.getElementById("title-header").textContent=t)}get _plot_ids(){return[]}get _dist_ids(){return[]}_processData(t){}_plotDists(){this._dist_ids.forEach(t=>{const e="plot_"+t;ti({id:e,once:!0,data:this,func:i=>{const s=o.sim_results?.dists_extra?.[t]?.x_value??null,a=new Ti(t,{title:"label",x_value:s});da({plot_id:e,dist:a,show_title:!0,show_label:this._plot_dist_label,show_disabled:!1})}})})}_plotSims(){this._plot_ids.forEach(t=>ti({id:t,once:!0,data:this,func:e=>e[t]()}))}async save({copy:t=!1,event:e=null}={}){var i=Ai("form_sim_edit");this._args_json=JSON.stringify(i),i._copy=t;var s={args:i,plot_selection:o.plot_selection};const a=await Ci({url:"/sim/ajax_save",data:s,button_id:"btn_save",set_tabs_valid:!0});if(a){const t=a?.sim_id_new;if(t){const i="/sim/edit?sim_id="+t;e&&(e.ctrlKey||e.metaKey)?window.open(i,"_blank"):(o.inputLastSaved=this._args_json,window.location.assign(i))}else o.inputLastSaved=this._args_json}}async simulate(){var t,e=Ai("form_sim_edit");if(this._args_json=JSON.stringify(e),this._args_json==this._args_json_last_run)Si({modal_id:"sim-report"});else{$("#dialog-wait").modal("show"),this._args_json_last_run="";const i=await Ci({url:"/sim/ajax_run",data:e,form_id:"form_sim_edit",button_id:"btn_sim",set_tabs_valid:!0});$("#dialog-wait").modal("hide"),i&&(this._args_json_last_run=this._args_json,o.sim_results=i,o.data_plots=i.data_plots,t=i?.strings,t&&Object.entries(t)?.forEach(([t,e])=>$(`span.${t}`).text(e)),this._plotSims(),this._plotDists(),Si({modal_id:"sim-report"}))}}}class Ca extends Ra{_plot_dist_label=!1;get _dist_ids(){return["dist_percent_1","dist_percent_2","dist_big_3","dist_big_4"]}get _plot_ids(){return["plot_sim"]}}class Fa extends Ra{get _plot_ids(){return["plot_sim1_irr","plot_sim2_irr"]}plot_sim1_irr(){ha({plot_id:"plot_sim1_irr",data_pack:o.data_plots.sim1_irr,title:this.title,sub_title:this.sub_title,format:"percent",label:h,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_irr(){xa({plot_id:"plot_sim2_irr",data_pack:o.data_plots.sim2_irr,title:this.title,sub_title:this.sub_title,x_label:d,y_label:h,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Ya extends Fa{plot_sim2_irr(){xa({plot_id:"plot_sim2_irr",data_pack:o.data_plots.sim2_irr,title:this.title,sub_title:this.sub_title,x_label:c,y_label:h,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Oa extends Ya{get _dist_ids(){return["dist_tax_rate_dividends","dist_tax_rate_cap_gains"]}plot_sim1_irr(){fa({plot_id:"plot_sim1_irr",data_pack:o.data_plots.sim1_irr,title:this.title,sub_title:this.sub_title,format:"percent",x_label:m,y_label:h,selector:!0,show_gain_loss:!0,show_zero_line:!0})}}class La extends Ra{get _plot_ids(){return["plot_sim1_pv","plot_sim1_npv","plot_sim1_npv_ratio","plot_sim2_npv","plot_sim2_npv_ratio"]}_plotSims(){const t=o.data_plots.currency,e=o.data_plots?.per_share,i=e?`- Per Share (${t})`:`(${t})`;this._label_pv=`${b} ${i}`,this._label_npv=`Net Present Value ${i}`,super._plotSims()}plot_sim1_pv(){ha({plot_id:"plot_sim1_pv",data_pack:o.data_plots.sim1_pv,title:this.title,sub_title:this.sub_title,format:"big",label:this._label_pv,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_npv(){ha({plot_id:"plot_sim1_npv",data_pack:o.data_plots.sim1_npv,title:this.title,sub_title:this.sub_title,format:"big",label:this._label_npv,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_npv_ratio(){ha({plot_id:"plot_sim1_npv_ratio",data_pack:o.data_plots.sim1_npv_ratio,title:this.title,sub_title:this.sub_title,format:"percent",label:g,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_npv(){xa({plot_id:"plot_sim2_npv",data_pack:o.data_plots.sim2_npv,title:this.title,sub_title:this.sub_title,x_label:d,y_label:this._label_npv,x_format:"big",y_format:"big",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_npv_ratio(){xa({plot_id:"plot_sim2_npv_ratio",data_pack:o.data_plots.sim2_npv_ratio,title:this.title,sub_title:this.sub_title,x_label:d,y_label:g,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Va extends La{plot_sim2_npv(){xa({plot_id:"plot_sim2_npv",data_pack:o.data_plots.sim2_npv,title:this.title,sub_title:this.sub_title,x_label:c,y_label:this._label_npv,x_format:"big",y_format:"big",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_npv_ratio(){xa({plot_id:"plot_sim2_npv_ratio",data_pack:o.data_plots.sim2_npv_ratio,title:this.title,sub_title:this.sub_title,x_label:c,y_label:g,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class qa extends Va{get _dist_ids(){return["dist_discount_rate","dist_tax_rate_dividends","dist_tax_rate_cap_gains"]}plot_sim1_pv(){fa({plot_id:"plot_sim1_pv",data_pack:o.data_plots.sim1_pv,title:this.title,sub_title:this.sub_title,format:"big",x_label:m,y_label:this._label_pv,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_npv(){fa({plot_id:"plot_sim1_npv",data_pack:o.data_plots.sim1_npv,title:this.title,sub_title:this.sub_title,format:"big",x_label:m,y_label:this._label_npv,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_npv_ratio(){fa({plot_id:"plot_sim1_npv_ratio",data_pack:o.data_plots.sim1_npv_ratio,title:this.title,sub_title:this.sub_title,format:"percent",x_label:m,y_label:g,selector:!0,show_gain_loss:!0,show_zero_line:!0})}}class ja extends Ra{get _plot_ids(){return["plot_sim1_roiv","plot_sim1_rob","plot_sim2_roiv","plot_sim2_rob"]}plot_sim1_roiv(){ha({plot_id:"plot_sim1_roiv",data_pack:o.data_plots.sim1_roiv,title:this.title,sub_title:this.sub_title,format:"percent",label:y,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rob(){ha({plot_id:"plot_sim1_rob",data_pack:o.data_plots.sim1_rob,title:this.title,sub_title:this.sub_title,format:"percent",label:v,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_roiv(){xa({plot_id:"plot_sim2_roiv",data_pack:o.data_plots.sim2_roiv,title:this.title,sub_title:this.sub_title,x_label:c,y_label:y,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rob(){xa({plot_id:"plot_sim2_rob",data_pack:o.data_plots.sim2_rob,title:this.title,sub_title:this.sub_title,x_label:c,y_label:v,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Wa extends ja{plot_sim1_roiv(){fa({plot_id:"plot_sim1_roiv",data_pack:o.data_plots.sim1_roiv,title:this.title,sub_title:this.sub_title,format:"percent",x_label:m,y_label:y,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rob(){fa({plot_id:"plot_sim1_rob",data_pack:o.data_plots.sim1_rob,title:this.title,sub_title:this.sub_title,format:"percent",x_label:m,y_label:v,selector:!0,show_gain_loss:!0,show_zero_line:!0})}}class Ka extends Ra{get _plot_ids(){return["plot_sim1_roiv","plot_sim1_rois","plot_sim1_rois_buyer","plot_sim2_roiv","plot_sim2_rois","plot_sim2_rois_buyer"]}plot_sim1_roiv(){ha({plot_id:"plot_sim1_roiv",data_pack:o.data_plots.sim1_roiv,title:this.title,sub_title:this.sub_title,format:"percent",label:y,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rois(){ha({plot_id:"plot_sim1_rois",data_pack:o.data_plots.sim1_rois,title:this.title,sub_title:this.sub_title,format:"percent",label:k,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rois_buyer(){ha({plot_id:"plot_sim1_rois_buyer",data_pack:o.data_plots.sim1_rois_buyer,title:this.title,sub_title:this.sub_title,format:"percent",label:A,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_roiv(){xa({plot_id:"plot_sim2_roiv",data_pack:o.data_plots.sim2_roiv,title:this.title,sub_title:this.sub_title,x_label:c,y_label:y,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rois(){xa({plot_id:"plot_sim2_rois",data_pack:o.data_plots.sim2_rois,title:this.title,sub_title:this.sub_title,x_label:c,y_label:k,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rois_buyer(){xa({plot_id:"plot_sim2_rois_buyer",data_pack:o.data_plots.sim2_rois_buyer,title:this.title,sub_title:this.sub_title,x_label:c,y_label:A,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Ga extends Ra{get _plot_ids(){return["plot_sim1_roiv_A","plot_sim1_rois_A","plot_sim1_roiv_B","plot_sim1_rois_B","plot_sim2_roiv_A","plot_sim2_rois_A","plot_sim2_roiv_B","plot_sim2_rois_B"]}plot_sim1_roiv_A(){ha({plot_id:"plot_sim1_roiv_A",data_pack:o.data_plots.sim1_roiv_A,title:this.title,sub_title:this.sub_title,format:"percent",label:w,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_roiv_B(){ha({plot_id:"plot_sim1_roiv_B",data_pack:o.data_plots.sim1_roiv_B,title:this.title,sub_title:this.sub_title,format:"percent",label:x,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rois_A(){ha({plot_id:"plot_sim1_rois_A",data_pack:o.data_plots.sim1_rois_A,title:this.title,sub_title:this.sub_title,format:"percent",label:S,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rois_B(){ha({plot_id:"plot_sim1_rois_B",data_pack:o.data_plots.sim1_rois_B,title:this.title,sub_title:this.sub_title,format:"percent",label:I,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_rois_buyer(){ha({plot_id:"plot_sim1_rois_buyer",data_pack:o.data_plots.sim1_rois_buyer,title:this.title,sub_title:this.sub_title,format:"percent",label:A,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_roiv_A(){xa({plot_id:"plot_sim2_roiv_A",data_pack:o.data_plots.sim2_roiv_A,title:this.title,sub_title:this.sub_title,x_label:P,y_label:w,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_roiv_B(){xa({plot_id:"plot_sim2_roiv_B",data_pack:o.data_plots.sim2_roiv_B,title:this.title,sub_title:this.sub_title,x_label:P,y_label:x,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rois_A(){xa({plot_id:"plot_sim2_rois_A",data_pack:o.data_plots.sim2_rois_A,title:this.title,sub_title:this.sub_title,x_label:P,y_label:S,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rois_B(){xa({plot_id:"plot_sim2_rois_B",data_pack:o.data_plots.sim2_rois_B,title:this.title,sub_title:this.sub_title,x_label:P,y_label:I,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_rois_buyer(){xa({plot_id:"plot_sim2_rois_buyer",data_pack:o.data_plots.sim2_rois_buyer,title:this.title,sub_title:this.sub_title,x_label:"Current Share-Price for Company A",y_label:A,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}_processData(t){const e=new Ia({data:t?.stock_A,plot_ids:["shares_A"],init_input_ids:["currency"],update_input_ids:["cur_share_price_A","cur_shares_A"]}),i=new Ia({data:t?.stock_B,plot_ids:["shares_B"],init_input_ids:["currency"],update_input_ids:["cur_share_price_B","cur_shares_B"]});if(!o.sim_id){const t=e.name??"N/A",s=i.name??"N/A";this.title=`(A) ${t} + ${s} (B)`;const a=+document.getElementById("cur_share_price_A").value,o=+document.getElementById("cur_share_price_B").value/a;o&&(document.getElementById("swap_ratio").value=o.toPrecision(3))}}}class Ua extends Ra{get _dist_ids(){return["dist_tax_rate_dividends","dist_tax_rate_cap_gains"]}get _plot_ids(){return["plot_sim1_tr","plot_sim2_tr"]}plot_sim1_tr(){fa({plot_id:"plot_sim1_tr",data_pack:o.data_plots.sim1_tr,title:this.title,sub_title:this.sub_title,format:"percent",x_label:m,y_label:D,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_tr(){xa({plot_id:"plot_sim2_tr",data_pack:o.data_plots.sim2_tr,title:this.title,sub_title:this.sub_title,x_label:c,y_label:D,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}class Xa extends Ra{get _plot_ids(){return["plot_sim1_earnings_yield","plot_sim1_price_change","plot_sim2_earnings_yield","plot_sim2_price_change"]}plot_sim1_earnings_yield(){ha({plot_id:"plot_sim1_earnings_yield",data_pack:o.data_plots.sim1_earnings_yield,title:this.title,sub_title:this.sub_title,format:"percent",label:p,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim1_price_change(){ha({plot_id:"plot_sim1_price_change",data_pack:o.data_plots.sim1_price_change,title:this.title,sub_title:this.sub_title,format:"percent",label:f,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_sim2_earnings_yield(){xa({plot_id:"plot_sim2_earnings_yield",data_pack:o.data_plots.sim2_earnings_yield,title:this.title,sub_title:this.sub_title,x_label:c,y_label:p,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}plot_sim2_price_change(){xa({plot_id:"plot_sim2_price_change",data_pack:o.data_plots.sim2_price_change,title:this.title,sub_title:this.sub_title,x_label:c,y_label:f,x_format:"big",y_format:"percent",show_zero_line:!0,show_gain_loss:!0,show_grid:"above",kind:"contour"})}}const Ja=[class extends Ra{static id="DIST-CMP";get _plot_ids(){return["plot_dist_cmp"]}plot_dist_cmp(){var t=Ea("dist_big_",{start:1,end:5});ma({plot_id:"plot_dist_cmp",format:"big",title:this.title,sub_title:this.sub_title,list_dist_id:t,show_weights:!1,show_gain_loss:!0,show_zero_line:!0})}},class extends Ra{static id="DIST-CMP-PCT";get _plot_ids(){return["plot_dist_cmp"]}plot_dist_cmp(){var t=Ea("dist_percent_",{start:1,end:5});ma({plot_id:"plot_dist_cmp",format:"percent",title:this.title,sub_title:this.sub_title,list_dist_id:t,show_weights:!1,show_gain_loss:!0,show_zero_line:!0})}},class extends Ra{static id="DIST-MIX";get _plot_ids(){return["plot_sim","plot_dist_cmp"]}plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:"big",label:u,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_dist_cmp(){Pa({title:this.title,sub_title:this.sub_title,show_weights:!0})}},class extends Ra{static id="DIST-MIX-PCT";get _plot_ids(){return["plot_sim","plot_dist_cmp"]}plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:"percent",label:u,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_dist_cmp(){Da({title:this.title,sub_title:this.sub_title,show_weights:!0})}},class extends Ra{static id="DIST-SUM";get _plot_ids(){return["plot_sim","plot_dist_cmp"]}plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:"big",label:z,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_dist_cmp(){Pa({title:this.title,sub_title:this.sub_title,show_weights:!0})}},class extends Ra{static id="DIST-SUM-PCT";get _plot_ids(){return["plot_sim","plot_dist_cmp"]}plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:"percent",label:z,selector:!0,show_gain_loss:!0,show_zero_line:!0})}plot_dist_cmp(){Da({title
2:this.title,sub_title:this.sub_title,show_weights:!0})}},class extends Ca{static id="DIST-MUL";plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:o.data_plots.sim.format,label:"Multiplied Distribution",selector:!0,show_gain_loss:!0,show_zero_line:!0})}},class extends Ca{static id="DIST-DIV";plot_sim(){ha({plot_id:"plot_sim",data_pack:o.data_plots.sim,title:this.title,sub_title:this.sub_title,format:o.data_plots.sim.format,label:"Divided Distribution",selector:!0,show_gain_loss:!0,show_zero_line:!0})}},class extends La{static id="PV-ONE";get _dist_ids(){return["dist_future_value","dist_year","dist_discount_rate"]}},class extends La{static id="PV-TG";get _dist_ids(){return["dist_discount_rate","dist_terminal_growth"]}get _plot_ids(){return["plot_dist_multi_future_value",...super._plot_ids]}plot_dist_multi_future_value(){Na({cutoff_same:!0})}},class extends qa{static id="STK-PV-PE";get _plot_ids(){return["plot_dist_multi_pe_ratio","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_pe_ratio(){$a()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","pe_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_pe_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends qa{static id="STK-PV-PS";get _plot_ids(){return["plot_dist_multi_ps_ratio","plot_dist_multi_sales","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_ps_ratio(){Ma()}plot_dist_multi_sales(){Ba()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","sales","ps_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_sales_y1","dist_ps_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends Va{static id="STK-PV-TG";get _dist_ids(){return["dist_discount_rate","dist_terminal_growth","dist_tax_rate_dividends"]}get _plot_ids(){return["plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_earnings(){za({cutoff_same:!0})}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1"]});o.sim_id||(this.title=e.name)}},class extends Ua{static id="STK-TR-PE";get _plot_ids(){return["plot_dist_multi_pe_ratio","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_pe_ratio(){$a()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","pe_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_pe_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends Ua{static id="STK-TR-PS";get _plot_ids(){return["plot_dist_multi_ps_ratio","plot_dist_multi_sales","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_ps_ratio(){Ma()}plot_dist_multi_sales(){Ba()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","sales","ps_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_sales_y1","dist_ps_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends Fa{static id="IRR-TG";get _dist_ids(){return["dist_terminal_growth"]}get _plot_ids(){return["plot_dist_multi_future_value",...super._plot_ids]}plot_dist_multi_future_value(){Na({cutoff_same:!0})}},class extends Ya{static id="STK-IRR-TG";get _dist_ids(){return["dist_terminal_growth","dist_tax_rate_dividends"]}get _plot_ids(){return["plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_earnings(){za({cutoff_same:!0})}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1"]});o.sim_id||(this.title=e.name)}
2},class extends Oa{static id="STK-IRR-PE";get _plot_ids(){return["plot_dist_multi_pe_ratio","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_pe_ratio(){$a()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","pe_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_pe_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends Oa{static id="STK-IRR-PS";get _plot_ids(){return["plot_dist_multi_ps_ratio","plot_dist_multi_sales","plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_ps_ratio(){Ma()}plot_dist_multi_sales(){Ba()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","sales","ps_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_sales_y1","dist_ps_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends ja{static id="STK-BUY-IV";get _dist_ids(){return["dist_intrinsic_value"]}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["shares","payout"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"]});o.sim_id||(this.title=e.name)}},class extends ja{static id="STK-BUY-TG";get _dist_ids(){return["dist_discount_rate","dist_terminal_growth"]}get _plot_ids(){return["plot_dist_multi_earnings",...super._plot_ids]}plot_dist_multi_earnings(){za({cutoff_same:!0})}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","balance","shares","payout"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1"]});o.sim_id||(this.title=e.name)}},class extends Wa{static id="STK-BUY-PE";get _plot_ids(){return["plot_dist_multi_pe_ratio","plot_dist_multi_earnings",...super._plot_ids]}get _dist_ids(){return["dist_discount_rate","dist_tax_rate_cap_gains","dist_tax_rate_dividends","dist_pe_scale_buyback"]}plot_dist_multi_pe_ratio(){$a()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","pe_ratio","balance","shares","payout"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_pe_ratio_y1"]});o.sim_id||(this.title=e.name)}},class extends Wa{static id="STK-BUY-PS";get _plot_ids(){return["plot_dist_multi_ps_ratio","plot_dist_multi_sales","plot_dist_multi_earnings",...super._plot_ids]}get _dist_ids(){return["dist_discount_rate","dist_tax_rate_cap_gains","dist_tax_rate_dividends","dist_ps_scale_buyback"]}plot_dist_multi_ps_ratio(){Ma()}plot_dist_multi_sales(){Ba()}plot_dist_multi_earnings(){za()}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["earnings","sales","ps_ratio","balance","shares","payout"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_earnings_y1","dist_sales_y1","dist_ps_ratio_y1"]});o.sim_id||(this.title=e.name)}}
2,class extends Ka{static id="STK-IS-CASH";get _dist_ids(){return["dist_intrinsic_value"]}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:[]});o.sim_id||(this.title=e.name)}},class extends Ka{static id="STK-IS-INV";get _dist_ids(){return["dist_intrinsic_value","dist_return_value"]}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:[]});o.sim_id||(this.title=e.name)}},class extends Ga{static id="STK-SWAP-FUL";get _dist_ids(){return["dist_intrinsic_value_A","dist_intrinsic_value_B","dist_synergy"]}},class extends Ga{static id="STK-SWAP-PRT";get _dist_ids(){return["dist_intrinsic_value_A","dist_intrinsic_value_B"]}},class extends Xa{static id="STK-YLD-PE";get _dist_ids(){return["dist_sales","dist_net_profit_margin","dist_pe_ratio","dist_year","dist_tax_rate_dividends","dist_tax_rate_cap_gains"]}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["sales","profit_margin","pe_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_sales","dist_net_profit_margin","dist_pe_ratio"]});o.sim_id||(this.title=e.name)}},class extends Xa{static id="STK-YLD-PS";get _dist_ids(){return["dist_sales","dist_net_profit_margin","dist_ps_ratio","dist_year","dist_tax_rate_dividends","dist_tax_rate_cap_gains"]}_processData(t){const e=new Ia({data:t?.stock,plot_ids:["sales","profit_margin","ps_ratio","balance","shares"],update_input_ids:["cur_share_price","cur_shares"],init_input_ids:["title","currency"],init_dist_ids:["dist_sales","dist_net_profit_margin","dist_ps_ratio"]});o.sim_id||(this.title=e.name)}}].reduce((t,e)=>(t[e.id]=e,t),{});t.AdminPlots=class{constructor(t){xa(t.plot_hist_2d_A),xa(t.plot_hist_2d_B)}},t.AdminStats=class{constructor({data_daily_packed:t,total:e}){var i,s,a=new os(t),o={format:"big",hover:"tip",stacked:!0};s=`Data Views: ${e.num_data_views}`,i=[He],ba({plot_id:"plot_data_views",ts_narrow:a.toNarrow(i),title:s,mavg:14,...o});const l=({plot_id:t,name:e,total:i,mavg:s=0})=>{let l=e;return i&&(l+=` (Total: ${i})`),ba({plot_id:t,ts_narrow:a.toNarrow([e]),title:l,height:Ws,mavg:s,...o})};ra({plot_id:"plot_users",sub_plots:[l({plot_id:"sub_plot_num_guests",name:We,mavg:14}),l({plot_id:"sub_plot_num_users",name:Ke}),l({plot_id:"sub_plot_num_new_users",name:Ge,total:e.num_users_created})],title:"Users"}),ra({plot_id:"plot_sims",sub_plots:[l({plot_id:"sub_plot_num_sim_views",name:Je,total:e.num_sim_views}),l({plot_id:"sub_plot_num_sim_runs",name:Xe,total:e.num_sim_runs}),l({plot_id:"sub_plot_num_sim_created",name:Ue,total:e.num_sim_created})],title:"Sims"})}},t.ShowBond=class extends ka{constructor({name:t,symbol:e,desc_short:i,data_packed:s}){super({name:t,symbol:e});const a=new os(s);var o=[Ie,Ae];wa({plot_id:"plot_yield",ts_wide:a.toWide(o),title:this._create_title(),sub_title:i,y1:Ae,y2:Ie,show_zero_line:!1,show_gain_loss:!0,zero:!0,format:"percent",hover:null,selector:!0})}},t.ShowInflation=class extends ka{constructor({name:t,symbol:e,desc_short:i,data_packed:s}){super({name:t,symbol:e});const a=new os(s);var o=[Ee,Pe],[l,n]=a.toNarrow(o,{split:!0});ba({plot_id:"plot_index",ts_narrow:l,hover:"tip",title:this._create_title(),sub_title:i}),ba({plot_id:"plot_rate",ts_narrow:n,format:"percent",title:this._create_title("Inflation Rate"),sub_title:i,show_gain_loss:!0,hover:"crosshair",selector:!0})}},t.ShowStock=class extends ka{constructor({data:t}){var e;super({name:t.name,symbol:t.symbol}),this.data_stock=new Ia({data:t,plot_ids:["share_price","mcap","present_value","buyback_returns","buyback_returns_cum","max_drawdown","earnings_yield","ps_ratio","pe_ratio","pb_ratio","ev_ebitda","sales","expenses","earnings","payout","payout_to_assets","payout_yield","payout_spinoff","cash_flow","balance","balance_ratios","sales_growth","ebitda_growth","growth_factors","profit_margin","interest_to_ebitda","debt_to_assets","debt_to_ebitda","debt_to_fcf","liquidity","return_ratios","asset_turnover","inventory_turnover","days_sales","shares","shares_changes","shares_dilution"],modal:!1}),this.sim_stock=new Aa({data:this.data_stock,once:!1}),ki({modal_id:"help",enter_submit:!1}),ki({modal_id:"sim",enter_submit:!1}),ki({modal_id:"search-data",enter_submit:!0}),ki({modal_id:"stock-hide",enter_submit:!0}),e=()=>document.getElementById("btn_search_data")?.click(),document.addEventListener("keydown",t=>{"/"!==t.key&&("k"!==t.key||!t.ctrlKey&&!t.metaKey)||document.activeElement.isContentEditable||["INPUT","TEXTAREA"].includes(document.activeElement.tagName)||(t.preventDefault(),e())}),di({modal:!0})}},t.ShowStockIndex=class extends ka{constructor({name:t,symbol:e,desc_short:i,data_packed:s}){super({name:t,symbol:e}),ki({modal_id:"help"});const a={y1:"Real",y2:"Nominal",sub_title:i,show_zero_line:!1,show_gain_loss:!0,format:"percent",hover:null,selector:!0,zero:!0};var o,l,n;const r="Nominal",_="Real",d=new os(s);n=this._create_title("1-3 Year Mean Annualized Return"),o=[Ce,Le],l=new Map([[Ce,r],[Le,_]]),wa({plot_id:"plot_1-3Y",ts_wide:d.toWide(o,{map_n
2ames:l}),title:n,...a}),n=this._create_title("3-5 Year Mean Annualized Return"),o=[Fe,Ve],l=new Map([[Fe,r],[Ve,_]]),wa({plot_id:"plot_3-5Y",ts_wide:d.toWide(o,{map_names:l}),title:n,...a}),n=this._create_title("5-7 Year Mean Annualized Return"),o=[Ye,qe],l=new Map([[Ye,r],[qe,_]]),wa({plot_id:"plot_5-7Y",ts_wide:d.toWide(o,{map_names:l}),title:n,...a}),n=this._create_title("7-10 Year Mean Annualized Return"),o=[Oe,je],l=new Map([[Oe,r],[je,_]]),wa({plot_id:"plot_7-10Y",ts_wide:d.toWide(o,{map_names:l}),title:n,...a}),n=this._create_title("3-Year Max Drawdown & Pullup"),o=[Te,Re],ya({plot_id:"plot_max_drawdown",ts_narrow:d.toNarrow(o),y_pos:Re,y_neg:Te,title:n,sub_title:i,format:"percent",hover:"crosshair",selector:!1})}},t.StockScreener=class{constructor(){ki({modal_id:"help"}),ki({modal_id:"sim"}),ki({modal_id:"sim-models"}),ki({modal_id:"stock-hide",enter_submit:!0}),di({modal:!0}),this.symbol=null,this.sim_stock=new Aa({once:!1})}toggleArrows(){$("i.bi.bi-chevron-double-right, i.bi.bi-chevron-double-left").each(function(){$(this).toggleClass("bi-chevron-double-right bi-chevron-double-left")})}createNewSim(t){$("#table_sim_models").DataTable().rows().every(function(){const e=this.node().querySelector("a"),i=new URL(e.getAttribute("href"),window.location.origin);i.searchParams.set("symbol_stock",t),e.href=i.href}),Si({modal_id:"sim-models"})}async simulate(t){if(t==this.symbol)return void Si({modal_id:"sim"});o.plot_selection_init={};const e=await async function(t,e={}){const i=await Ri({url:`/data/ajax_stock_data?symbol=${t}`});return i?new Ia({data:i,...e}):null}(t,{modal:!1,plot_ids:["ps_ratio","sales","profit_margin"]});e&&(this.symbol=e.symbol,this.sim_stock.set_data(e),$("#nav_data").click(),$("#nav_sales").click(),$("#nav_sim_earnings_yield").click(),Si({modal_id:"sim"}))}},t.ajaxMoreSearchResults=async function({table_id:t,url_ajax:e,page_rows:i=5,max_rows:s=30}){function a(t){var e=$("#button_more");e.html(t),e.attr("disabled",!0)}i=Number(i),s=Number(s);var o=$("#"+t+" tr").length-1;if(o>=s)return void a("Max "+s+" reached. Please refine your search.");var l=new URL(document.URL).searchParams;l.set("search_start",o),e+="?"+l.toString();const n=await async function(t,e={}){try{const i=await fetch(t,e);if(!i.ok)throw new Error(i.status+" "+i.statusText);return await i.text()}catch(t){return alert(t),null}}(e);n&&($("#"+t+" tr:last").after(n),$(n).filter("tr").length<i&&a("No more matches"))},t.ajaxSetFavorite=async function({kind:t,key:e,checked:i}){const s={kind:t,key:e,checked:i};await Ci({url:"/user/ajax_set_favorite",data:s})},t.ajaxSimDelete=async function({sim_id:t,success:e=Fi}){confirm("Delete the simulation?\nThis cannot be undone!")&&await Ri({url:"/sim/ajax_delete?sim_id="+t})&&e(t)},t.ajaxStockHide=async function(){if(await async function({url:t,data:e,form_id:i,...s}){var a;if(e){a=new FormData;for(const[t,i]of Object.entries(e))a.append(t,String(i))}else a=new FormData(document.getElementById(i));return await Ri({url:t,form_id:i,...s,fetch_options:{method:"POST",body:a}})}({url:"/stock/ajax_hide",form_id:"form_stock_hide",button_id:"modal-menu-stock-hide-submit"})){if("never"!=$("#stock_hide_duration").val()){const t=$("#stock_hide_symbol").val();t&&$("tr#"+t).remove()}o.modalMenuData["stock-hide"].modal.hide()}},t.buttonShowFailure=si,t.buttonShowSuccess=ii,t.changeAccessLevel=function(){var t="users"!=$("#access_level").val();$("#access_handles").prop("readonly",t),$("#access_emails").prop("readonly",t),$("#access_email_domains").prop("readonly",t)},t.checkboxClear_All=function(t){$("#"+t+" :input[type=checkbox]").each(function(t,e){e.checked=!1})},t.checkboxInvert_Access=function(){li(n)},t.checkboxInvert_All=function(t){$("#"+t+" :input[type=checkbox]").each(function(t,e){e.checked=!e.checked})},t.checkboxInvert_Basic=function(){li(l)},t.checkboxInvert_Icon=function(t){const e=document.getElementById(t),i=document.getElementById(t+"-icon");if(e&&i){const t=i.dataset.kind,[s,a]=oi[t];e.checked?(i.classList.remove(a),i.classList.add(s)):(i.classList.remove(s),i.classList.add(a))}else console.warn(`Either checkbox or icon is missing for id: '${t}'`)},t.checkboxInvert_Sim=function(t){$("#"+t+" :input[type=checkbox]").each(function(t,e){l.includes(e.id)||n.includes(e.id)||(e.checked=!e.checked)})},t.clipboardCopyDist=function({dist_id:t=null,context_menu:e=!1}){var i=function({dist_id:t,use_full_id:e}){return function({field_names:t,prefix_id:e=null,use_full_id:i=!0}){var s={};for(let a of t){let t=e?e+"-"+a:a,o=document.getElementById(t);if(o){const e="checkbox"==o.type?o.checked:o.value;i?s[t]=e:s[a]=e}}return s}({field_names:_,prefix_id:t,use_full_id:e})}({dist_id:t=gi({dist_id:t,context_menu:e}),use_full_id:!1});fi({text:JSON.stringify(i),prefix:mi})},t.clipboardCopyInputs=function({root:t=null,form_id:e=null,context_menu:i=!1}){var s={};pi({root:t,form_id:e,context_menu:i}).each(function(t,e){e.id&&("checkbox"==e.type?s[e.id]=e.checked:s[e.id]=e.value)}),fi({text:JSON.stringify(s),prefix:hi})},t.clipboardPasteDist=function({dist_id:t=null,context_menu:e=!1}){t=gi({dist_id:t,context_menu:e}),bi({process:function(e){var i=JSON.parse(e);vi({dist_id:t,data:i})},prefix:mi})},t.clipboardPasteInputs=function({root:t=null,form_id:e=null,context_menu:i=!1}){i&&(t=o.contextMenuTarget.getAttribute("data-bs-target")),t||(t=document),t=$(t),bi({process:function(i){var s=JSON.parse(i),a=0;for(let i of Object.keys(s)){var o=t.find("#"+i);o.length>0&&(!e||o.attr("form")==e)&&(++a,"checkbox"==o.attr("type")?o.prop("checked",s[i]):o.val(s[i]))}0==a?alert("No matching input-fields in your clipboard."):zi(t)},prefix:hi})},t.copyDistFromPlot=yi,t.createModel=function(t,e={}){return new Ja[t]({...e})},t.distFormPlot=Pi,t.distFormSmooth=function({dist_id:t=null,context_menu:e=!1}){t=gi({dist_id:t,context_menu:e});var i=new Ti(t);i.error||(i.smooth(),i.setInputFields(),i.plot())},t.distFormTweak=function(){const t=Gi($("#tweak_multiply").val()),e=Gi($("#tweak_add").val()),i=Gi($("#tweak_min").val()),s=Gi($("#tweak_max").val()),a=Ji($("#tweak_digits").val()),l=$("#tweak_smooth").prop("checked");var n=o.modalMenuData["dist-tweak"],r=n.data.dist_id,_=new Ti(r,{digits:a});_.error||(_.tweak({mult:t,add:e,min_incl:i,max_incl:s}),l&&_.smooth(),_.setInputFields(),(_=new Ti(r,{digits:a})).plot()),n.modal.hide()},t.distYearsPushLeft=function(){var t=gi({context_menu:!0}
2),e=$("#"+t).closest("div.dist-form-parent").find("div.dist-form"),i=e[1].id,s=$("#"+i+"-selected").val();for(let i=0;i<e.length-1;i++){var a=e[i+1].id,o=e[i].id;if(o==t)break;(i>0||"same"!=s)&&xi({src_id:a,dest_id:o})}},t.distYearsPushRight=function(){var t=gi({context_menu:!0}),e=$("#"+t).closest("div.dist-form-parent").find("div.dist-form");for(let a=e.length-2;a>=0;a--){var i=e[a].id,s=e[a+1].id;if(s==t)break;xi({src_id:i,dest_id:s})}},t.init=function({user_logged_in:t}){o.user_logged_in=t},t.inputRestore=function({root:t=null,form_id:e=null,context_menu:i=!1}){const s=o.input_original;pi({root:t,form_id:e,context_menu:i}).each(function(t,e){const i=e.id;if(i&&i in s){const t=s[i];"checkbox"==e.type?e.checked=t:e.value=t}}),zi(t)},t.inputRestoreValue=function(t){const e=document.getElementById(t+"_update");if(e?.checked){const e=document.getElementById(t),i=e.dataset.value;void 0!==i&&(e.value=i)}},t.modalReset_DistTweak=function(){$("#tweak_multiply").val("1"),$("#tweak_add").val("0"),$("#tweak_min").val("-inf"),$("#tweak_max").val("inf"),$("#tweak_digits").val("4"),$("#tweak_smooth").prop("checked",!1)},t.modalShow=Si,t.modalShow_Data=function({modal_id:t,dist_id:e=null}){o.modalMenuData[t]?Si({modal_id:t,data:{dist_id:e}}):alert("No data has been loaded.\n1) Enter symbol in More / Settings.\n2) Click the Save button.\n3) Press F5 key to reload.")},t.modalShow_DistTweak=function({dist_id:t=null,context_menu:e=!1}){Si({modal_id:"dist-tweak",data:{dist_id:t=gi({dist_id:t,context_menu:e})}})},t.modalShow_StockHide=async function(t){const e=await Ri({url:`/stock/ajax_hide?symbol=${t}`,form_id:"form_stock_hide"});if(e){const a=Hi("big",3);var i=e?.mcap_lo?a(e?.mcap_lo):"",s=e?.mcap_hi?a(e?.mcap_hi):"";$("#stock_hide_symbol_title").text(t),$("#stock_hide_symbol").val(t),$("#stock_hide_duration").val(e?.duration??"never"),$("#stock_hide_ps_lo").val(e?.ps_lo),$("#stock_hide_ps_hi").val(e?.ps_hi),$("#stock_hide_mcap_lo").val(i),$("#stock_hide_mcap_hi").val(s)}Si({modal_id:"stock-hide",data:{symbol:t}}),$("#duration").focus()},t.savePlot=function(t,{postfix:e=null,type:i="svg"}={}){const s=o.plots_extra[t]?.title;if(s){var a=s;e&&(a+=" - "+e),a+="."+i,saveAs(new Blob([ai(t)],{type:"image/svg+xml;charset=utf-8"}),a)}else console.warn(`Title / filename missing for plot ID: '${t}'`)},t.setupTable_SimModels=di,t.showTooltip=function({elm:t,event:e}){if(!window.matchMedia("(hover: hover)").matches){e.stopPropagation();const i=t?.getAttribute("title");if(i){const t=document.getElementById("_tooltip");t.textContent=i;let s={top:e.pageY+12+"px",visibility:"visible"};e.pageX<window.innerWidth/2?s.left=e.pageX+12+"px":s.left=e.pageX-t.offsetWidth-12+"px",Object.assign(t.style,s),document.body.addEventListener("click",Ii,!0)}}},t.toggleView=function(t){var e=$("#"+t);e.closest("div.toggle-pane").find("div.toggle-contents").each(function(){$(this).addClass("d-none")}),e.closest("div.toggle-contents").removeClass("d-none")}}(this.simsim=this.simsim||{}); 3//# sourceMappingURL=scripts.min.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.