@veyforma/charts 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ /*! @veyforma/charts v1.0.0 · MIT License · Copyright (c) 2026 Veyforma · https://github.com/veyforma/veyforma-charts */
2
+ (function(B){"use strict";var St="1.0.0",Ft="http://www.w3.org/2000/svg",It=0,lt={down:"#4b5563",up:"#c2410c",hedge:"#2f6fed",contribution:"#a63d16",convexity:"#111827",limit:"#b91c1c",grid:"#ececec",axis:"#9ca3af",text:"#111827",mutedText:"#4b5563",axisText:"#4b5563",cardBackground:"#f9fafb",background:"transparent",tooltipBackground:"#111827",tooltipText:"#ffffff",focus:"#c2410c",accent:"#c2410c",fontFamily:"inherit",fontSize:12},vt={veyforma:{},mono:{down:"#8a8a8a",up:"#111111",hedge:"#8a8a8a",contribution:"#111111",convexity:"#111111",limit:"#111111",accent:"#111111",focus:"#111111"},"colour-safe":{down:"#2166ac",up:"#b2182b",hedge:"#1b7837",contribution:"#762a83",limit:"#b2182b",accent:"#2166ac"},ocean:{down:"#64748b",up:"#0c6e8f",hedge:"#c2410c",contribution:"#0c3b5e",cardBackground:"#eef5f8",accent:"#0c6e8f"},forest:{down:"#78716c",up:"#4d6b31",hedge:"#2f6fed",contribution:"#22311a",cardBackground:"#f2f4ee",accent:"#4d6b31"},corporate:{down:"#64748b",up:"#1d4ed8",hedge:"#c2410c",contribution:"#1e293b",cardBackground:"#f1f4f8",accent:"#1d4ed8"},midnight:{background:"#111418",down:"#a3abb8",up:"#f08a5d",hedge:"#93c5fd",contribution:"#f08a5d",convexity:"#f3f4f6",limit:"#fb7185",grid:"#252a31",axis:"#4b5563",text:"#f3f4f6",mutedText:"#a3abb8",axisText:"#a3abb8",cardBackground:"#1b2027",tooltipBackground:"#f3f4f6",tooltipText:"#111418",focus:"#93c5fd",accent:"#f08a5d"}},Mt={data:null,view:"factors",sort:"swing",top:15,shockScale:1,whatIf:null,theme:"veyforma",locale:void 0,animate:!0,summary:!0,legend:!0,labels:null,ariaLabel:void 0,caption:!0,annotations:null,onAnnotationsChange:null,onItemClick:null,exportRows:2e4,toolbar:!0},_t={factors:"Impact by risk factor",groups:"Impact by group",contribution:"Share of the combined move",down:"Down shock",up:"Up shock",swing:"Swing",worst:"Worst result",convexity:"Convexity",linear:"Linear part",limit:"Limit",largest:"Largest driver",worstShock:"Worst single shock",topShare:"Top {n} factors",combined:"Combined move",contributionAdds:"Adds to the combined move",hedge:"Hedges (lowers it)",standalone:"Stand-alone",other:"Other {n} factors",whatIf:"What-if",interaction:"Interaction",noData:"n/a"};function P(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];if(n)for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}var Et={};function nt(t){Et[t]||(Et[t]=1,B.console&&console.warn&&console.warn("VeyRiskTornado: "+t))}function I(t){throw new Error("VeyRiskTornado: "+t)}function wt(t,e,n){return Math.min(n,Math.max(e,t))}function ot(t,e){return String(t).replace(/\{(\w+)\}/g,function(n,o){return e[o]!=null?e[o]:n})}function Ht(t){return t=String(t),/^[A-Z0-9]{2}/.test(t)?t:t.charAt(0).toLowerCase()+t.slice(1)}function Dt(t){return typeof t=="number"?t:t==null||t===""?NaN:+t}function A(t,e,n){var o=document.createElementNS(Ft,t);if(e)for(var r in e)e[r]!=null&&o.setAttribute(r,e[r]);return n&&n.appendChild(o),o}function _(t,e,n){var o=document.createElement(t);return e&&(o.className=e),n&&n.appendChild(o),o}var rt=null;function U(t,e,n,o){if(!rt){var r=document.createElement("canvas");rt=r.getContext&&r.getContext("2d")}return rt?(rt.font=(n||400)+" "+e+"px "+o,rt.measureText(String(t)).width):String(t).length*e*.6}function it(t,e,n,o,r){if(t=String(t),U(t,n,o,r)<=e)return t;for(;t.length>2&&U(t+"\u2026",n,o,r)>e;)t=t.slice(0,-1);return t.replace(/\s+$/,"")+"\u2026"}function ut(t){var e=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(String(t||"").trim());if(!e)return null;var n=e[1].length===3?e[1].replace(/./g,"$&$&"):e[1],o=parseInt(n,16);return[o>>16&255,o>>8&255,o&255]}function bt(t){var e=t.map(function(n){return n/=255,n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4)});return .2126*e[0]+.7152*e[1]+.0722*e[2]}function Tt(t,e){var n=ut(t),o=ut(e);if(!n||!o)return 21;var r=bt(n),i=bt(o);return(Math.max(r,i)+.05)/(Math.min(r,i)+.05)}function X(t,e,n){var o=ut(t),r=ut(e);if(!o||!r||Tt(t,e)>=n)return t;for(var i=bt(r)>.4,s=0,u=t;s<=1&&Tt(u,e)<n;)s+=.05,u="#"+o.map(function(c){var a=i?c*(1-s):c+(255-c)*s;return("0"+Math.round(a).toString(16)).slice(-2)}).join("");return u}function ct(t,e){var n=t.decimals!=null?t.decimals:0,o=t.ratioDecimals!=null?t.ratioDecimals:1,r=t.prefix||"",i=t.suffix||"",s={},u=t.negatives==="brackets";function c(m){return s[m]||(s[m]=new Intl.NumberFormat(e||void 0,{minimumFractionDigits:m,maximumFractionDigits:m})),s[m]}function a(m,v){if(m==null||!isFinite(m))return"\u2013";v==null&&(v=n);var x=Number(m.toFixed(v)),y=r+c(v).format(Math.abs(x))+i;return x>=0?y:u?"("+y+")":"\u2212"+y}function f(m,v){var x=a(m,v);return m!=null&&Number(m.toFixed(v??n))>0?"+"+x:x}function d(m,v){return m==null||!isFinite(m)?"\u2013":(m<0?"\u2212":"")+c(v??o).format(Math.abs(m)*100)+"%"}function p(m,v){if(m==null||!isFinite(m))return"\u2013";var x=v??Math.max(o,1),y=Number((m*100).toFixed(x));return(y>0?"+":y<0?"\u2212":"")+c(x).format(Math.abs(y))+" pp"}function w(m,v){return m==null||!isFinite(m)?"\u2013":c(v??1).format(m*100)+"%"}return{value:a,signed:f,ratio:d,pp:p,percent:w,nf:c}}function F(t,e){var n=Dt(t);return isFinite(n)||I(e+" must be a number."),n}function gt(t,e){var n=F(t,e);return(n<-1||n>1)&&I(e+" must be between \u22121 and 1."),n}function Rt(t,e,n){var o=t.factors;(!Array.isArray(o)||!o.length)&&I("data.factors must be a non-empty array of risk factors.");var r={};return o.map(function(i,s){(!i||typeof i!="object")&&I("data.factors["+s+"] is not an object."),i.key==null&&i.label==null&&I("data.factors["+s+"] needs a key or a label.");var u=String(i.key!=null?i.key:i.label),c='factor "'+u+'"';r[u]&&I(c+" is used twice."),r[u]=1;var a=i.group!=null?String(i.group):"Other",f=i.shockDown!=null?F(i.shockDown,c+": shockDown"):i.shock!=null?-Math.abs(F(i.shock,c+": shock")):null,d=i.shockUp!=null?F(i.shockUp,c+": shockUp"):i.shock!=null?Math.abs(F(i.shock,c+": shock")):null,p,w,m;if(i.delta!=null){var v=F(i.delta,c+": delta"),x=i.gamma!=null?F(i.gamma,c+": gamma"):0;(f==null||d==null)&&I(c+": delta needs shockDown and shockUp (or shock).");var y=f*e,E=d*e;p=v*y+.5*x*y*y,w=v*E+.5*x*E*E,m="taylor"}else{(i.down==null||i.up==null)&&I(c+" needs down and up impacts, or delta (and gamma) with a shock.");var M=F(i.down,c+": down"),l=F(i.up,c+": up");if(e===1)p=M,w=l;else{var N=(l-M)/2,T=(l+M)/2;p=-N*e+T*e*e,w=N*e+T*e*e}m="revaluation"}var L=1;return n&&(n[u]!=null&&(L*=F(n[u],"whatIf."+u)),n[a]!=null&&a!==u&&(L*=F(n[a],"whatIf."+a))),{key:u,label:i.label!=null?String(i.label):u,group:a,unit:i.unit!=null?String(i.unit):"",shockDown:f==null?null:f*e,shockUp:d==null?null:d*e,down:p*L,up:w*L,source:m,index:s}})}function Ct(t,e,n){var o=t.length,r=new Array(o),i,s;if(e&&e.matrix){var u=e.matrix;for(i=0;i<o;i++){var c=0,a=u[i];for(s=0;s<o;s++)c+=(i===s?1:a[s])*n[s];r[i]=c}return r}var f=e?e.within:0,d=e?e.across:0,p={},w=0;for(i=0;i<o;i++)p[t[i].group]=(p[t[i].group]||0)+n[i],w+=n[i];for(i=0;i<o;i++){var m=p[t[i].group];r[i]=n[i]+f*(m-n[i])+d*(w-m)}return r}function Wt(t,e){var n=t.correlation;if(n==null)return null;if(typeof n!="object"&&I("data.correlation must be { within, across } or { matrix }."),n.matrix){var o=n.matrix;return(!Array.isArray(o)||o.length!==e||o.some(function(r){return!Array.isArray(r)||r.length!==e}))&&I("data.correlation.matrix must be square with one row per factor."),o.forEach(function(r,i){r.forEach(function(s,u){gt(s,"data.correlation.matrix["+i+"]["+u+"]")})}),{matrix:o}}return{within:n.within!=null?gt(n.within,"data.correlation.within"):0,across:n.across!=null?gt(n.across,"data.correlation.across"):0}}function K(t,e){e=e||{},(!t||typeof t!="object")&&I("data is required.");var n=e.shockScale!=null?F(e.shockScale,"shockScale"):1;n>0||I("shockScale must be more than 0.");var o=e.whatIf&&Object.keys(e.whatIf).length?e.whatIf:null,r=Rt(t,n,o),i=r.length;o&&Object.keys(o).forEach(function(h){r.some(function(k){return k.key===h||k.group===h})||nt('whatIf: there is no factor or group "'+h+'", so it changes nothing.')});var s=t.higherIsBetter!==!1,u=function(h){return s?-h:h},c=t.limit!=null?Math.abs(F(t.limit,"data.limit")):null,a=Wt(t,i),f=r.map(function(h){return(h.up-h.down)/2}),d=Ct(r,a,f),p=0,w;for(w=0;w<i;w++)p+=f[w]*d[w];var m=Math.sqrt(Math.max(0,p)),v=0,x=0,y=0,E=0;r.forEach(function(h,k){h.swing=Math.abs(h.up-h.down),h.linear=f[k],h.convexity=(h.up+h.down)/2,h.asymmetry=Math.abs(h.linear)+Math.abs(h.convexity)>0?Math.abs(h.convexity)/(Math.abs(h.linear)+Math.abs(h.convexity)):0,h.worst=u(h.down)>=u(h.up)?"down":"up",h.worstValue=h[h.worst],h.best=h.worst==="down"?"up":"down",h.breach=c!=null&&u(h.worstValue)>c+1e-12*Math.max(1,c),h.standalone=Math.abs(f[k]),h.contribution=m>0?f[k]*d[k]/m:0,v+=h.swing,x+=h.down,y+=h.up,E+=h.standalone});var M=r.slice().sort(e.sort==="worst"?function(h,k){return u(k.worstValue)-u(h.worstValue)||h.index-k.index}:function(h,k){return k.swing-h.swing||h.index-k.index}),l=0;M.forEach(function(h,k){h.rank=k+1,h.share=v>0?h.swing/v:0,l+=h.share,h.cumShare=l});var N={},T=[];r.forEach(function(h,k){var j=N[h.group];j||(j=N[h.group]={key:h.group,label:h.group,factors:[],idx:[],down:0,up:0,contribution:0,standaloneSum:0},T.push(j)),j.factors.push(h.key),j.idx.push(k),j.down+=h.down,j.up+=h.up,j.contribution+=h.contribution,j.standaloneSum+=h.standalone}),T.forEach(function(h){h.swing=Math.abs(h.up-h.down),h.linear=(h.up-h.down)/2,h.convexity=(h.up+h.down)/2,h.worst=u(h.down)>=u(h.up)?"down":"up",h.worstValue=h[h.worst],h.breach=c!=null&&u(h.worstValue)>c+1e-12*Math.max(1,c),h.share=v>0?h.swing/v:0;for(var k=h.idx.map(function(z){return r[z]}),j=h.idx.map(function(z){return f[z]}),at=a&&a.matrix?{matrix:h.idx.map(function(z){return h.idx.map(function(V){return a.matrix[z][V]})})}:a,H=Ct(k,at,j),b=0,W=0;W<j.length;W++)b+=j[W]*H[W];h.standalone=Math.sqrt(Math.max(0,b)),delete h.idx});var L=i>=10?5:Math.max(1,Math.ceil(i/2)),D=M.slice(0,L).reduce(function(h,k){return h+k.share},0),C={factors:r,order:M,groups:T,higherIsBetter:s,limit:c,base:t.base!=null?F(t.base,"data.base"):null,totalSwing:v,sumDown:x,sumUp:y,sigma:m,standalone:E,diversification:E-m,correlated:!!a,topN:L,topShare:D,breaches:r.filter(function(h){return h.breach}).length,shockScale:n,whatIf:o};if(C.worstFactor=r.slice().sort(function(h,k){return u(k.worstValue)-u(h.worstValue)||h.index-k.index})[0],t.joint&&(t.joint.down!=null||t.joint.up!=null)&&(n===1&&!o?(C.joint={down:t.joint.down!=null?F(t.joint.down,"data.joint.down"):null,up:t.joint.up!=null?F(t.joint.up,"data.joint.up"):null},C.interaction={down:C.joint.down!=null?C.joint.down-x:null,up:C.joint.up!=null?C.joint.up-y:null}):C.jointHidden=!0),o){var R=K(t,{shockScale:n,sort:e.sort});C.baseline={totalSwing:R.totalSwing,sigma:R.sigma,worstValue:R.worstFactor.worstValue,worstFactor:R.worstFactor.key}}return C}function Vt(){if(!document.getElementById("vtr-styles")){var t=".vtr{position:relative;color:var(--vtr-text);background:var(--vtr-bg);font-family:var(--vtr-font);line-height:1.4}.vtr.vtr-filled{padding:14px 14px 8px;border-radius:10px}.vtr-summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px;margin:0 0 10px}.vtr-stat{background:var(--vtr-card);border-radius:8px;padding:9px 12px;min-width:0}.vtr-stat .k{font-size:11px;letter-spacing:.04em;text-transform:uppercase;color:var(--vtr-card-muted);font-weight:600;overflow-wrap:anywhere;hyphens:auto}.vtr-stat .v{font-size:19px;font-weight:700;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.vtr-stat .n{font-size:12px;color:var(--vtr-card-muted)}.vtr-stat .v.vtr-wrap{white-space:normal;overflow-wrap:anywhere;line-height:1.2;font-size:17px}.vtr-scope{font-size:12px;color:var(--vtr-muted);margin:0 0 4px}.vtr-legend{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:12px;margin:0 0 6px;color:var(--vtr-text)}.vtr-legend span{display:inline-flex;align-items:center;gap:6px}.vtr-legend i{display:inline-block;width:12px;height:12px;border-radius:3px}.vtr-legend i.vtr-tick{width:3px;height:14px;border-radius:1px}.vtr-legend i.vtr-ring{background:transparent!important;border:2px solid;border-radius:2px;width:9px;height:9px;transform:rotate(45deg)}.vtr-plot{display:block;width:100%;height:auto;overflow:visible;outline:none}.vtr-plot:focus-visible{outline:2px solid var(--vtr-focus);outline-offset:4px;border-radius:4px}.vtr-animate .vtr-grow{animation:vtr-fade .45s ease both}@keyframes vtr-fade{from{opacity:0}to{opacity:1}}@media (prefers-reduced-motion:reduce){.vtr-animate .vtr-grow{animation:none}}.vtr-tip{position:absolute;left:0;top:0;pointer-events:none;background:var(--vtr-tip-bg);color:var(--vtr-tip-text);font-size:12px;line-height:1.45;padding:8px 10px;border-radius:8px;opacity:0;transform:translateY(4px);transition:opacity .12s,transform .12s;white-space:nowrap;z-index:5;font-variant-numeric:tabular-nums}.vtr-tip.vtr-on{opacity:1;transform:none}.vtr-tip b{font-weight:600}.vtr-table{border-collapse:collapse;font-size:12px;font-variant-numeric:tabular-nums;margin:0 0 14px;min-width:100%}.vtr-table caption{text-align:left;font-weight:700;padding:0 0 6px}.vtr-table th,.vtr-table td{padding:5px 8px;border-bottom:1px solid rgba(127,127,127,.25);text-align:right;white-space:nowrap}.vtr-table th:first-child,.vtr-table td:first-child{text-align:left}.vtr-table tr.vtr-breach td{color:var(--vtr-hedge);font-weight:600}@media (max-width:420px){.vtr-summary{grid-template-columns:repeat(auto-fit,minmax(118px,1fr))}.vtr-stat{padding:8px 10px}.vtr-stat .v{font-size:17px}}",e=_("style");e.id="vtr-styles",e.textContent=t,(document.head||document.documentElement).appendChild(e)}}function ht(t){var e;(t==null||t==="")&&(t="veyforma"),typeof t=="string"?(vt.hasOwnProperty(t)||(nt('Unknown theme "'+t+'". The "veyforma" theme is used instead.'),t="veyforma"),e=P({},lt,vt[t])):typeof t=="object"?(e=P(t.extends?ht(t.extends):P({},lt),t),delete e.extends):(nt("The theme option must be a theme name or an object."),e=P({},lt));var n=/^#/.test(e.background)?e.background:"#ffffff",o=/^#/.test(e.cardBackground)?e.cardBackground:n;return["axisText","mutedText"].forEach(function(r){e[r]=X(e[r],n,4.5)}),e.cardMuted=X(e.mutedText,o,4.5),e.hedgeText=X(X(e.hedge,n,4.5),o,4.5),e.limitText=X(X(e.limit,n,4.5),o,4.5),e.accentText=X(e.accent,n,4.5),e}function S(t,e){var n=typeof t=="string"?document.querySelector(t):t;(!n||n.nodeType!==1)&&I("container not found ("+t+")."),(!e||!e.data)&&I("options.data is required."),Vt(),this.id=++It,this.container=n,this.options=P({},Mt,e),this.element=_("div","vtr"),this.element.setAttribute("role","figure"),this.summaryEl=_("div","vtr-summary",this.element),this.scopeEl=_("p","vtr-scope",this.element),this.legendEl=_("div","vtr-legend",this.element),this.plotHost=_("div","vtr-plot-host",this.element),this.tipEl=_("div","vtr-tip",this.element),this.tipEl.setAttribute("role","tooltip"),n.appendChild(this.element),this._animateNext=!!this.options.animate,this._lastWidth=0,this._active=-1;var o=this;B.ResizeObserver?(this._observer=new B.ResizeObserver(function(){var r=Math.round(o.element.clientWidth);r&&Math.abs(r-o._lastWidth)>1&&o.redraw()}),this._observer.observe(this.element)):(this._onResize=function(){o.redraw()},B.addEventListener("resize",this._onResize)),this._onDocTap=function(r){o.element.contains(r.target)||o._hideTip()},document.addEventListener("pointerdown",this._onDocTap),this.redraw(),this.options.toolbar!==!1&&B.VeyformaToolkit&&(this.toolkit=B.VeyformaToolkit.attach(this,this.options.toolbar))}S.prototype.update=function(t){return t?(t.data&&t.data!==this.options.data&&this.options.animate&&(this._animateNext=!0),t.view&&t.view!==this.options.view&&this.options.animate&&(this._animateNext=!0),P(this.options,t),this.redraw()):this},S.prototype.setData=function(t){return this._res=null,this.update({data:t})},S.prototype.setView=function(t){return this.update({view:t})},S.prototype.setTheme=function(t){return this.update({theme:t})},S.prototype.getTheme=function(){return ht(this.options.theme)},S.prototype._opts=function(){return{shockScale:this.options.shockScale,whatIf:this.options.whatIf,sort:this.options.sort}},S.prototype.getResult=function(){return K(this.options.data,this._opts())},S.prototype.getFactor=function(t){return this.getResult().factors.filter(function(e){return e.key===String(t)})[0]||null},S.prototype.setWhatIf=function(t){return this.update({whatIf:t})},S.prototype.setShockScale=function(t){return this.update({shockScale:t})},S.prototype._labels=function(){return P({},_t,this.options.labels)},S.prototype.destroy=function(){this.toolkit&&this.toolkit.destroy&&this.toolkit.destroy(),this._observer&&this._observer.disconnect(),this._onResize&&B.removeEventListener("resize",this._onResize),document.removeEventListener("pointerdown",this._onDocTap),this.element.parentNode&&this.element.parentNode.removeChild(this.element)},S.prototype._hideTip=function(){this.tipEl.classList.remove("vtr-on"),this._hlEl&&this._hlEl.setAttribute("opacity",0)},S.prototype._placeTip=function(t,e,n){var o=this.tipEl;o.textContent="",t.forEach(function(f,d){d&&o.appendChild(document.createElement("br"));var p=d===0?document.createElement("b"):document.createElement("span");p.textContent=f,o.appendChild(p)});var r=this.element.getBoundingClientRect(),i=n&&n.clientX?n.clientX:e.left+e.width/2,s=n&&n.clientY?n.clientY:e.top+10;o.classList.add("vtr-on");var u=o.offsetWidth,c=o.offsetHeight;o.style.left=wt(i-r.left-u/2,4,Math.max(4,r.width-u-4))+"px";var a=s-r.top-c-14;a<0&&(a=s-r.top+18),o.style.top=a+"px"};function Lt(t,e,n){e>t||(e=t+1);var o=e-t,r=Math.pow(10,Math.floor(Math.log(o/n)/Math.LN10)),i=o/n/r;i>=7.5?r*=10:i>=3.5?r*=5:i>=1.5&&(r*=2);for(var s=Math.floor(t/r+1e-9)*r,u=Math.ceil(e/r-1e-9)*r,c=[],a=s;a<=u+r/2;a+=r)c.push(Math.round(a/r)*r);return{lo:s,hi:u,ticks:c,step:r}}function $(t,e,n,o,r){var i=A("text",P({x:e,y:n},r||{}),t);return i.textContent=o,i}S.prototype._bindInteraction=function(t,e,n,o,r,i){var s=this,u=this._items,c=this.options;function a(d){for(var p=t.getBoundingClientRect(),w=(d.clientX-p.left)*(e/p.width),m=(d.clientY-p.top)*(n/p.height),v=0;v<u.length;v++){var x=u[v];if(w>=x.x&&w<=x.x+x.w&&m>=x.y&&m<=x.y+x.h)return v}return-1}function f(d,p){if(d<0){s._hideTip();return}s._active=d;var w=u[d],m=s._hlEl;m.setAttribute("x",w.x-4),m.setAttribute("y",w.y),m.setAttribute("width",w.w+8),m.setAttribute("height",w.h),m.setAttribute("opacity",1);var v=t.getBoundingClientRect(),x=v.width/e,y={left:v.left+w.px*x,top:v.top+w.py*(v.height/n),width:0,height:0};s._placeTip(s._tipLines(w),y,p&&p.clientX?p:null)}t.addEventListener("pointermove",function(d){f(a(d),d)}),t.addEventListener("pointerleave",function(){s._hideTip()}),t.addEventListener("click",function(d){var p=a(d);p>=0&&typeof c.onItemClick=="function"&&c.onItemClick(s._detail(u[p]),d)}),t.addEventListener("keydown",function(d){var p=s._active;if(d.key==="ArrowRight"||d.key==="ArrowDown")p=Math.min(u.length-1,p+1);else if(d.key==="ArrowLeft"||d.key==="ArrowUp")p=Math.max(0,p<0?0:p-1);else if(d.key==="Home")p=0;else if(d.key==="End")p=u.length-1;else if(d.key==="Escape"){s._hideTip();return}else if((d.key==="Enter"||d.key===" ")&&p>=0){typeof c.onItemClick=="function"&&c.onItemClick(s._detail(u[p]),d),d.preventDefault();return}else return;d.preventDefault(),f(p,null)}),t.addEventListener("blur",function(){s._hideTip()})},S.prototype.createTable=function(){var t=this.getExportData(),e=_("div","vtr-tables");return t.sheets.forEach(function(n){if(n.name!=="Notes"){var o=_("table","vtr-table",e);_("caption",null,o).textContent=n.name;var r=_("tr",null,_("thead",null,o));n.columns.forEach(function(s){var u=_("th",null,r);u.scope="col",u.textContent=s.label});var i=_("tbody",null,o);n.text.forEach(function(s,u){var c=_("tr",n.flag&&n.flag[u]?"vtr-breach":null,i);s.forEach(function(a,f){var d=_(f?"td":"th",null,c);f||(d.scope="row"),d.textContent=a})})}}),e};function dt(t,e,n){if(t==null||!isFinite(t))return"";var o=Number(Math.abs(t).toFixed(4)).toLocaleString(n||void 0,{maximumFractionDigits:4});return(t>0?"+":t<0?"\u2212":"")+o+(e?e==="%"?"%":" "+e:"")}S.prototype.redraw=function(){var t=this.options,e=t.data,n=this._labels(),o=this._res=K(e,this._opts()),r=ht(t.theme),i=ct(e,t.locale),s=this.element,u=s.style,c=r.fontFamily==="inherit"?B.getComputedStyle?B.getComputedStyle(this.container).fontFamily:"sans-serif":r.fontFamily,a=r.background&&r.background!=="transparent",f=a?r.background:"#ffffff";u.setProperty("--vtr-text",r.text),u.setProperty("--vtr-muted",r.mutedText),u.setProperty("--vtr-bg",a?r.background:"transparent"),u.setProperty("--vtr-font",c),u.setProperty("--vtr-card",r.cardBackground),u.setProperty("--vtr-card-muted",r.cardMuted),u.setProperty("--vtr-tip-bg",r.tooltipBackground),u.setProperty("--vtr-tip-text",r.tooltipText),u.setProperty("--vtr-focus",r.focus),u.setProperty("--vtr-hedge",r.limitText),s.classList.toggle("vtr-filled",!!a),s.setAttribute("aria-label",t.ariaLabel||e.title||"Risk-factor tornado");var d=t.view;["factors","groups","contribution"].indexOf(d)<0&&(nt('Unknown view "'+d+'". The factor view is shown instead.'),d="factors"),t.sort!=="swing"&&t.sort!=="worst"&&nt('Unknown sort "'+t.sort+'". Factors are ranked by swing instead.'),this._view=d,this._renderSummary(o,i,n);var p=[n[d],t.shockScale!=null&&+t.shockScale!=1?"shocks \xD7"+ +t.shockScale:null,e.unit||null,o.whatIf?n.whatIf+" applied":null].filter(Boolean).join(" \xB7 ");this.scopeEl.textContent=p,this._renderLegend(d,r,n,o);var w=Math.max(280,Math.round(this.plotHost.clientWidth||s.clientWidth||720));this._lastWidth=Math.round(s.clientWidth);var m=r.fontSize||12;this.plotHost.textContent="";var v=A("svg",{class:"vtr-plot",role:"img",tabindex:0,"font-family":c},this.plotHost);v.style.fontSize=m+"px";var x=this._animateNext&&t.animate;this._animateNext=!1,x&&v.classList.add("vtr-animate");var y={svg:v,W:w,fs:m,theme:r,f:i,L:n,family:c,bg:f,res:o,items:[],points:{}},E=d==="contribution"?this._drawContribution(y):this._drawRows(y,d);return v.setAttribute("viewBox","0 0 "+w+" "+E),v.setAttribute("width",w),v.setAttribute("height",E),v.setAttribute("aria-label",(t.ariaLabel||e.title||"Risk-factor tornado")+". "+this.describe()),this._items=y.items,this._points=y.points,this._hlEl=A("rect",{x:0,y:0,width:0,height:0,rx:4,fill:r.text,"fill-opacity":.06,opacity:0,"pointer-events":"none"},v),v.insertBefore(this._hlEl,v.firstChild),this._bindInteraction(v,w,E,r,n,i),this},S.prototype._shockNames=function(){var t=this._labels(),e=this.options.data.shockLabels||{};return{down:e.down||t.down,up:e.up||t.up}},S.prototype._renderSummary=function(t,e,n){var o=this.summaryEl,r=this.options;if(o.textContent="",o.style.display=r.summary===!1?"none":"",r.summary===!1)return;function i(a,f,d,p){var w=_("div","vtr-stat",o);_("div","k",w).textContent=a,_("div",p?"v vtr-wrap":"v",w).textContent=f,d&&(_("div","n",w).textContent=d)}var s=this._shockNames(),u=t.order[0],c=t.worstFactor;i(n.largest,u.label,n.swing.toLowerCase()+" "+e.value(u.swing)+" \xB7 "+e.percent(u.share,0)+" of the total",!0),i(n.worstShock,e.signed(c.worstValue),c.label+", "+s[c.worst].toLowerCase()+(t.limit!=null?t.breaches?" \xB7 "+t.breaches+" beyond the limit":" \xB7 within the limit":"")+(t.baseline?" \xB7 was "+e.signed(t.baseline.worstValue):"")),i(ot(n.topShare,{n:t.topN}),e.percent(t.topShare,0),"of the total swing across "+t.factors.length+" factors"),i(n.combined,"\xB1"+e.value(t.sigma),t.baseline?n.whatIf+": was \xB1"+e.value(t.baseline.sigma):t.correlated?t.standalone>0?e.percent(t.diversification/t.standalone,0)+" below the sum of stand-alone moves":"":"factors treated as independent"),Array.prototype.forEach.call(o.querySelectorAll(".vtr-stat .v"),function(a){a.style.fontSize="";for(var f=parseFloat(B.getComputedStyle?B.getComputedStyle(a).fontSize:19)||19;a.scrollWidth>a.clientWidth&&f>12;)f-=1,a.style.fontSize=f+"px"})},S.prototype._renderLegend=function(t,e,n,o){var r=this.legendEl,i=this._shockNames();r.textContent="",r.style.display=this.options.legend===!1?"none":"";function s(u,c,a){var f=_("span",null,r),d=_("i",a||null,f);a==="vtr-ring"?d.style.borderColor=u:d.style.background=u,f.appendChild(document.createTextNode(c))}if(t==="contribution"){s(e.contribution,n.contributionAdds),s(e.hedge,n.hedge),s(e.convexity,n.standalone,"vtr-ring");return}s(e.down,i.down),s(e.up,i.up),o.factors.some(function(u){return u.asymmetry>=.1})&&s(e.convexity,n.convexity+" (midpoint)","vtr-ring"),o.limit!=null&&s(e.limit,n.limit,"vtr-tick")};function jt(t,e){var n=Math.min(Math.max.apply(null,e.map(function(r){return U(r,t.fs,600,t.family)}))+12,t.W*.34),o=t.W-n<260;return{nameW:o?0:n,narrow:o}}function Nt(t,e,n,o,r,i,s,u,c){var a=t.theme,f=t.fs,d=t.family,p=t.W,w=t.f,m=-1/0,v=Math.max.apply(null,n.ticks.map(function(y){return U(w.value(y),f-1,400,d)})),x=Math.max(1,Math.ceil((v+10)/((s-i)/Math.max(1,n.ticks.length-1))));n.ticks.forEach(function(y,E){if(A("line",{x1:o(y),x2:o(y),y1:u,y2:c,stroke:y===0?a.axis:a.grid,"stroke-width":y===0?1.2:1},e),!(E%x)){var M=w.value(y),l=U(M,f-1,400,d),N=l/2,T=o(y),L=T-N<0?"start":T+N>p?"end":"middle",D=L==="start"?T:L==="end"?T-l:T-N;D<m+8||(m=D+l,$(e,T,r+f,M,{"text-anchor":L,fill:a.axisText,"font-size":f-1,class:"vtr-tick"}))}})}S.prototype._rowsFor=function(t,e,n){if(e==="groups")return t.groups.slice().sort(function(a,f){return f.swing-a.swing}).map(function(a){return{kind:"group",obj:a,name:a.label,down:a.down,up:a.up,breach:a.breach,convexity:a.convexity,asym:Math.abs(a.linear)+Math.abs(a.convexity)>0?Math.abs(a.convexity)/(Math.abs(a.linear)+Math.abs(a.convexity)):0}});var o=+this.options.top>0?Math.floor(+this.options.top):t.order.length,r=t.order.slice(0,o).map(function(a){return{kind:"factor",obj:a,name:a.rank+". "+a.label,down:a.down,up:a.up,breach:a.breach,convexity:a.convexity,asym:a.asymmetry}}),i=t.order.slice(o);if(i.length){var s=0,u=0,c=0;i.forEach(function(a){s+=a.down,u+=a.up,c+=a.swing}),r.push({kind:"other",obj:{count:i.length,down:s,up:u,swing:c,share:t.totalSwing>0?c/t.totalSwing:0,factors:i},name:ot(n.other,{n:i.length}),down:s,up:u,breach:!1,convexity:(s+u)/2,asym:0})}return r},S.prototype._drawRows=function(t,e){var n=t.res,o=t.theme,r=t.f,i=t.L,s=t.fs,u=t.family,c=t.W,a=t.svg,f=n.higherIsBetter,d=this._rowsFor(n,e,i),p=jt(t,d.map(function(g){return g.name})),w=n.limit!=null?f?-n.limit:n.limit:null,m=[];d.forEach(function(g){m.push(g.down,g.up)});var v=Math.min.apply(null,m.concat([0,w??0])),x=Math.max.apply(null,m.concat([0,w??0])),y=function(g){return U(r.signed(g),s-1,600,u)+6},E=Math.max.apply(null,[4].concat(m.filter(function(g){return g<0}).map(y))),M=Math.max.apply(null,[4].concat(m.filter(function(g){return g>=0}).map(y))),l=p.nameW+E,N=c-M,T=Lt(v,x,Math.max(2,Math.min(6,Math.floor((N-l)/90)))),L=function(g){return l+(wt(g,T.lo,T.hi)-T.lo)/(T.hi-T.lo)*(N-l)},D=4,C=Math.max(36,s*3),R=p.narrow?s+4:0,h=D+s+6,k=h+d.length*(C+R),j=A("g",{class:"vtr-rows"},a);Nt(t,j,T,L,D,l,N,h,k);var at=A("g",null,j),H=A("g",{class:"vtr-cvx-layer"},j),b=A("g",null,j);w!=null&&A("line",{x1:L(w),x2:L(w),y1:h-2,y2:k,stroke:o.limit,"stroke-width":1.6,"stroke-dasharray":"5 3",class:"vtr-limit"},H);var W=this._shockNames(),z=this;d.forEach(function(g,Q){var st=h+Q*(C+R)+R,tt=Math.max(C*.32,s),et=st+(C-2*tt-3)/2,Bt=g.breach?o.limitText:g.kind==="other"?o.mutedText:o.text,zt=it(g.name,p.narrow?c:p.nameW-8,s,g.kind==="other"?400:600,u);if(p.narrow&&A("rect",{x:0,y:st-3-s*.95,width:U(zt,s,600,u)+4,height:s*1.25,fill:t.bg,class:"vtr-lbg"},b),$(b,0,p.narrow?st-3:st+C/2+s*.35,it(g.name,p.narrow?c:p.nameW-8,s,g.kind==="other"?400:600,u),{fill:Bt,"font-size":s,"font-weight":g.kind==="other"?400:600,class:"vtr-name"}),[["down",et],["up",et+tt+3]].forEach(function(q){var J=g[q[0]],mt=L(Math.min(0,J)),xt=L(Math.max(0,J)),Ut=g.kind!=="other"&&g.obj.worst===q[0];A("rect",{x:mt,y:q[1],width:Math.max(.8,xt-mt),height:tt,rx:2,fill:o[q[0]],class:"vtr-grow vtr-bar","data-shock":q[0]},at);var kt=g.breach&&Ut,Ot=r.signed(J),At=U(Ot,s-1,kt?700:400,u),Pt=J<0?mt-4-At:xt+4;A("rect",{x:Pt-2,y:q[1]+tt/2-(s-1)*.6,width:At+4,height:(s-1)*1.2,fill:t.bg,class:"vtr-lbg"},b),$(b,J<0?mt-4:xt+4,q[1]+tt/2+(s-1)*.35,r.signed(J),{"text-anchor":J<0?"end":"start",fill:kt?o.limitText:o.text,"font-size":s-1,"font-weight":kt?700:400,class:"vtr-val"})}),g.asym>=.1){var ft=L(g.convexity),pt=et+tt+1.5;A("path",{d:"M"+ft+","+(pt-4)+"L"+(ft+4)+","+pt+"L"+ft+","+(pt+4)+"L"+(ft-4)+","+pt+"Z",fill:t.bg,stroke:o.convexity,"stroke-width":1.5,class:"vtr-cvx"},H)}var yt=L(Math.max(0,g.down,g.up));g.kind==="factor"&&(t.points[g.obj.key]={x:yt,y:et}),g.kind==="group"&&(t.points["group:"+g.obj.key]={x:yt,y:et}),t.items.push({kind:g.kind,obj:g.obj,x:0,y:st-R,w:c,h:C+R,px:yt,py:et})}),e==="groups"&&n.factors.forEach(function(g){t.points[g.key]||(t.points[g.key]=t.points["group:"+g.group])});var V=[];if(w!=null&&V.push(i.limit+" "+r.signed(w)+(n.breaches?": "+n.breaches+" factor"+(n.breaches>1?"s":"")+" beyond it":": no factor beyond it")),e==="factors"){var O=d.filter(function(g){return g.kind==="factor"}).length;if(V.push("Each factor shocked alone"+(O<n.factors.length?"; top "+O+" of "+n.factors.length+", the rest summed":"")),n.interaction){var Y=n.interaction,G=[];Y.down!=null&&G.push(W.down.toLowerCase()+" together "+r.signed(n.joint.down)+" vs sum "+r.signed(n.sumDown)),Y.up!=null&&G.push(W.up.toLowerCase()+" together "+r.signed(n.joint.up)+" vs sum "+r.signed(n.sumUp)),V.push("All factors "+G.join(", "))}}else V.push("Every factor in the group shocked the same way at once (sum of single shocks)");var Z=k+s+8;return V.forEach(function(g){$(a,0,Z,it(g+".",c,s-1,400,u),{fill:o.mutedText,"font-size":s-1,class:"vtr-note"}),Z+=s+3}),Math.ceil(Z-s+6)},S.prototype._drawContribution=function(t){var e=t.res,n=t.theme,o=t.f,r=t.L,i=t.fs,s=t.family,u=t.W,c=t.svg,a=e.factors.slice().sort(function(b,W){return Math.abs(W.contribution)-Math.abs(b.contribution)||b.index-W.index}),f=+this.options.top>0?Math.floor(+this.options.top):a.length,d=a.slice(f),p=a.slice(0,f).sort(function(b,W){return W.contribution-b.contribution}).map(function(b){return{kind:"factor",obj:b,name:b.label,v:b.contribution,k:b.standalone}});if(d.length){var w=0,m=0;d.forEach(function(b){w+=b.contribution,m+=b.standalone}),p.push({kind:"other",obj:{count:d.length,contribution:w,standalone:m,factors:d},name:ot(r.other,{n:d.length}),v:w,k:null})}var v=jt(t,p.map(function(b){return b.name})),x=Math.max.apply(null,p.map(function(b){return U(o.signed(b.v),i,700,s)}))+10,y=v.nameW,E=u-x,M=Math.max(24,i*2),l=v.narrow?i+4:0,N=4,T=Math.min(0,Math.min.apply(null,p.map(function(b){return b.v}))),L=Math.max.apply(null,p.map(function(b){return Math.max(b.v,b.k||0)}))||1,D=Lt(T,L,Math.max(2,Math.min(6,Math.floor((E-y)/90)))),C=function(b){return y+(wt(b,D.lo,D.hi)-D.lo)/(D.hi-D.lo)*(E-y)},R=N+i+6,h=R+p.length*(M+l),k=A("g",{class:"vtr-contrib"},c);Nt(t,k,D,C,N,y,E,R,h),p.forEach(function(b,W){var z=R+W*(M+l)+l,V=M*.56,O=z+(M-V)/2,Y=b.v<0;$(k,0,v.narrow?z-3:O+V/2+i*.35,it(b.name,v.narrow?u-x:v.nameW-8,i,b.kind==="other"?400:600,s),{fill:b.kind==="other"?n.mutedText:n.text,"font-size":i,"font-weight":b.kind==="other"?400:600,class:"vtr-name"});var G=C(Math.min(0,b.v)),Z=C(Math.max(0,b.v));if(A("rect",{x:G,y:O,width:Math.max(.8,Z-G),height:V,rx:2,fill:Y?n.hedge:n.contribution,class:"vtr-grow vtr-cbar"+(Y?" vtr-hedge":"")},k),b.k!=null){var g=C(b.k),Q=O+V/2;A("path",{d:"M"+g+","+(Q-5)+"L"+(g+5)+","+Q+"L"+g+","+(Q+5)+"L"+(g-5)+","+Q+"Z",fill:t.bg,stroke:n.convexity,"stroke-width":1.6,class:"vtr-sa"},k)}$(k,u,O+V/2+i*.35,o.signed(b.v),{"text-anchor":"end",fill:Y?n.hedgeText:n.text,"font-size":i,"font-weight":700,class:"vtr-val"}),b.kind==="factor"&&(t.points[b.obj.key]={x:Y?G:Z,y:O}),t.items.push({kind:b.kind,obj:b.obj,contrib:!0,x:0,y:z-l,w:u,h:M+l,px:Y?G:Z,py:O})});var j=e.correlated?this.options.data.correlation.matrix?"with the correlation matrix given":"with correlations of "+o.percent(this.options.data.correlation.within||0,0)+" within groups and "+o.percent(this.options.data.correlation.across||0,0)+" across":"no correlations given, so factors are treated as independent and none can hedge another",at=["Shares add up to the combined move of \xB1"+o.value(e.sigma)+"; stand-alone moves add up to "+o.value(e.standalone),"Combined "+j],H=h+i+8;return at.forEach(function(b){$(c,0,H,it(b+".",u,i-1,400,s),{fill:n.mutedText,"font-size":i-1,class:"vtr-note"}),H+=i+3}),Math.ceil(H-i+6)},S.prototype._tipLines=function(t){var e=this.options,n=ct(e.data,e.locale),o=this._labels(),r=this._res,i=this._shockNames(),s=e.locale,u=function(p){return r.base!=null?" \u2192 "+n.value(r.base+p):""};if(t.kind==="other"){var c=t.obj;return t.contrib?[ot(o.other,{n:c.count}),"Shares together "+n.signed(c.contribution)]:[ot(o.other,{n:c.count}),i.down+" (sum) "+n.signed(c.down),i.up+" (sum) "+n.signed(c.up),o.swing+" together "+n.value(c.swing)+" ("+n.percent(c.share,0)+" of the total)"]}if(t.kind==="group"){var a=t.obj;return[a.label+" \xB7 "+a.factors.length+" factor"+(a.factors.length>1?"s":""),i.down+" "+n.signed(a.down)+u(a.down),i.up+" "+n.signed(a.up)+u(a.up),o.swing+" "+n.value(a.swing)+" ("+n.percent(a.share,0)+" of the total)","Combined move of the group \xB1"+n.value(a.standalone)+" \xB7 share of the total \xB1"+n.value(r.sigma)+": "+n.signed(a.contribution)].concat(a.breach?[o.worst+" beyond the limit"]:[])}var f=t.obj,d=[f.label,f.group+" \xB7 rank "+f.rank+" of "+r.factors.length,i.down+(f.shockDown!=null?" ("+dt(f.shockDown,f.unit,s)+")":"")+" "+n.signed(f.down)+u(f.down),i.up+(f.shockUp!=null?" ("+dt(f.shockUp,f.unit,s)+")":"")+" "+n.signed(f.up)+u(f.up),o.swing+" "+n.value(f.swing)+" \xB7 "+n.percent(f.share,0)+" of the total (top "+f.rank+": "+n.percent(f.cumShare,0)+")",o.linear+" \xB1"+n.value(Math.abs(f.linear))+" \xB7 "+o.convexity.toLowerCase()+" "+n.signed(f.convexity),"Share of the combined move "+n.signed(f.contribution)+" (stand-alone "+n.value(f.standalone)+")"];return f.breach&&d.push(i[f.worst]+" is beyond the limit of "+n.value(r.limit)),d},S.prototype._detail=function(t){if(!t)return null;var e=this._view;if(t.kind==="other")return{view:e,kind:"other",count:t.obj.count,down:t.obj.down,up:t.obj.up,swing:t.obj.swing,contribution:t.obj.contribution,factors:t.obj.factors.map(function(r){return r.key})};if(t.kind==="group"){var n=t.obj;return{view:e,kind:"group",key:n.key,label:n.label,factors:n.factors.slice(),down:n.down,up:n.up,swing:n.swing,share:n.share,linear:n.linear,convexity:n.convexity,worst:n.worst,worstValue:n.worstValue,breach:n.breach,contribution:n.contribution,standalone:n.standalone}}var o=t.obj;return{view:e,kind:"factor",key:o.key,label:o.label,group:o.group,unit:o.unit,shockDown:o.shockDown,shockUp:o.shockUp,down:o.down,up:o.up,swing:o.swing,share:o.share,cumShare:o.cumShare,rank:o.rank,linear:o.linear,convexity:o.convexity,asymmetry:o.asymmetry,worst:o.worst,worstValue:o.worstValue,breach:o.breach,contribution:o.contribution,standalone:o.standalone,source:o.source}},S.prototype.howToRead=function(){var t=this._view||this.options.view;return t==="contribution"?"Each bar is one factor's share of the combined move when all factors move together with their correlations. Shares add up exactly to the combined move; a bar to the left means the factor hedges the others. The diamond marks the factor's move on its own, so the gap between the diamond and the bar is diversification.":t==="groups"?"Each row is one group of factors, such as a risk class, with every factor in it shocked down (upper bar) and up (lower bar) at the same time. Rows are sorted by swing, the distance between the two results.":"Each row is one risk factor, shocked down (upper bar) and up (lower bar) on its own while everything else stays put. Rows are ranked by swing, the distance between the two results, so the factors that matter most are at the top. A diamond marks the midpoint of the two results when they are clearly unequal (convexity)"+(this._res&&this._res.limit!=null?"; the dashed line is the loss limit.":".")},S.prototype.describe=function(){var t=this.options,e=ct(t.data,t.locale),n=this._labels(),o=this._res||K(t.data,this._opts()),r=this._shockNames(),i=[],s=o.order[0];i.push("The largest driver is "+s.label+": "+r.down.toLowerCase()+" gives "+e.signed(s.down)+" and "+r.up.toLowerCase()+" "+e.signed(s.up)+", a swing of "+e.value(s.swing)+" ("+e.percent(s.share,0)+" of the total swing)."),o.factors.length>o.topN&&i.push("The top "+o.topN+" of "+o.factors.length+" factors explain "+e.percent(o.topShare,0)+".");var u=o.worstFactor;i.push("The worst single shock is "+u.label+" "+r[u.worst].toLowerCase()+" at "+e.signed(u.worstValue)+(o.limit!=null?o.breaches?", beyond the limit of "+e.value(o.limit)+" ("+o.breaches+" factor"+(o.breaches>1?"s":"")+" in all)":", within the limit of "+e.value(o.limit):"")+".");var c=o.factors.filter(function(d){return d.asymmetry>=.25&&d.swing>0}).sort(function(d,p){return Math.abs(p.convexity)-Math.abs(d.convexity)});if(c.length&&i.push(c.length+" factor"+(c.length>1?"s are":" is")+" strongly asymmetric, led by "+c[0].label+" (convexity "+e.signed(c[0].convexity)+"), so a bigger shock would cost more than in proportion."),o.correlated){var a=o.factors.slice().sort(function(d,p){return p.contribution-d.contribution}),f=o.factors.filter(function(d){return d.contribution<0}).sort(function(d,p){return d.contribution-p.contribution});i.push("Moving together with their correlations, the factors give a combined move of \xB1"+e.value(o.sigma)+", "+e.percent(o.standalone>0?o.diversification/o.standalone:0,0)+" less than the sum of their stand-alone moves; "+a[0].label+" contributes most ("+e.signed(a[0].contribution)+")"+(f.length?" and "+f[0].label+" hedges the most ("+e.signed(f[0].contribution)+")":"")+".")}return o.interaction&&o.interaction.down!=null&&i.push("Shocked all at once, the down case gives "+e.signed(o.joint.down)+" against "+e.signed(o.sumDown)+" for the sum of single shocks, an interaction of "+e.signed(o.interaction.down)+"."),o.baseline&&i.push("The what-if changes the worst single shock from "+e.signed(o.baseline.worstValue)+" to "+e.signed(u.worstValue)+"."),i.join(" ")},S.prototype.getExportData=function(){var t=this.options,e=t.data,n=this._labels(),o=ct(e,t.locale),r=this._res||K(e,this._opts()),i=this._shockNames(),s=t.locale,u={prefix:e.prefix||"",suffix:e.suffix||"",decimals:e.decimals!=null?e.decimals:0,negatives:e.negatives},c=function(l){return{label:l,type:"number",unit:u}},a=function(l){return{label:l,type:"number",unit:{decimals:4}}},f=function(l){return{label:l,type:"percent",decimals:1}},d=function(l){return{label:l,type:"text"}},p=[],w=t.exportRows!=null?t.exportRows:2e4,m=r.order,v=m.length>w;v&&(m=m.slice(0,w));var x=m.map(function(l){return[l.rank,l.label,l.group,l.unit,l.shockDown,l.shockUp,l.down,l.up,l.swing,l.share,l.cumShare,l.linear,l.convexity,i[l.worst],l.worstValue,l.breach?"Yes":"No",l.contribution,l.standalone]});p.push({name:"Factors",columns:[{label:"Rank",type:"number",unit:{decimals:0}},d("Risk factor"),d("Group"),d("Shock unit"),a("Shock down"),a("Shock up"),c(i.down),c(i.up),c(n.swing),f("Share of total swing"),f("Cumulative share"),c(n.linear),c(n.convexity),d("Worst shock"),c(n.worst),d("Beyond limit"),c("Share of combined move"),c("Stand-alone move")],rows:x,text:m.map(function(l){return[String(l.rank),l.label,l.group,l.unit,dt(l.shockDown,"",s)||"\u2013",dt(l.shockUp,"",s)||"\u2013",o.signed(l.down),o.signed(l.up),o.value(l.swing),o.percent(l.share),o.percent(l.cumShare),o.signed(l.linear),o.signed(l.convexity),i[l.worst],o.signed(l.worstValue),l.breach?"Yes":"No",o.signed(l.contribution),o.value(l.standalone)]}),flag:m.map(function(l){return l.breach})}),p.push({name:"Groups",columns:[d("Group"),{label:"Factors",type:"number",unit:{decimals:0}},c(i.down+" (sum)"),c(i.up+" (sum)"),c(n.swing),f("Share of total swing"),c(n.worst),d("Beyond limit"),c("Share of combined move"),c("Group combined move")],rows:r.groups.map(function(l){return[l.label,l.factors.length,l.down,l.up,l.swing,l.share,l.worstValue,l.breach?"Yes":"No",l.contribution,l.standalone]}),text:r.groups.map(function(l){return[l.label,String(l.factors.length),o.signed(l.down),o.signed(l.up),o.value(l.swing),o.percent(l.share),o.signed(l.worstValue),l.breach?"Yes":"No",o.signed(l.contribution),o.value(l.standalone)]}),flag:r.groups.map(function(l){return l.breach})});var y=[["Total swing",r.totalSwing],["Sum of "+i.down.toLowerCase()+" impacts",r.sumDown],["Sum of "+i.up.toLowerCase()+" impacts",r.sumUp]];r.joint&&(r.joint.down!=null&&y.push(["All factors "+i.down.toLowerCase()+" together",r.joint.down],[n.interaction+" ("+i.down.toLowerCase()+")",r.interaction.down]),r.joint.up!=null&&y.push(["All factors "+i.up.toLowerCase()+" together",r.joint.up],[n.interaction+" ("+i.up.toLowerCase()+")",r.interaction.up])),y.push([n.combined+" (\xB1)",r.sigma],["Sum of stand-alone moves",r.standalone],["Diversification",r.diversification]),r.limit!=null&&y.push([n.limit,r.limit]),p.push({name:"Summary",columns:[d("Item"),c("Amount")],rows:y,text:y.map(function(l){return[l[0],/Sum|Interaction|together/.test(l[0])?o.signed(l[1]):o.value(l[1])]})});var E=(t.annotations||[]).map(function(l,N){return[String(N+1),l.factor!=null?String(l.factor):"Group: "+String(l.group||""),l.text||""]});E.length&&p.push({name:"Notes",columns:[d("No."),d("Factor or group"),d("Note")],rows:E});var M=e.correlation;return{title:e.title||"Risk-factor tornado",subtitle:e.subtitle||"",summary:this.describe(),library:"Veyforma Risk-Factor Tornado "+St,sheets:p,meta:[["Unit",e.unit],["As of",e.asOf],["Desk",e.desk],["Measure",r.higherIsBetter?"Higher is better (for example P&L)":"Lower is better (for example capital)"],["Ranking",t.sort==="worst"?"By worst result":"By swing"],["Shocks",i.down+" / "+i.up+(r.shockScale!==1?", scaled \xD7"+r.shockScale:"")],["What-if",r.whatIf?Object.keys(r.whatIf).map(function(l){return l+" \xD7 "+r.whatIf[l]}).join(", "):null],["Correlation",M?M.matrix?"Matrix given":"Within groups "+(M.within||0)+", across "+(M.across||0):"None given (independent factors)"],["Limit",r.limit!=null?o.value(r.limit)+" ("+r.breaches+" beyond)":null],["Method","Impact = given down/up result, or \u0394\xB7s + \xBD\u0393\xB7s\xB2; swing = |up \u2212 down|; linear part L = (up \u2212 down) \xF7 2, convexity C = (up + down) \xF7 2; a shock k times larger \u2248 L\xB7k + C\xB7k\xB2; combined move \u03C3 = \u221A(L\u1D40 \u03C1 L); factor share = L_k (\u03C1L)_k \xF7 \u03C3 (Euler allocation, adds up to \u03C3)"+(v?"; factor sheet limited to the "+w+" largest swings":"")],["Data source",e.source]]}},S.prototype._annotationPoint=function(t){var e=this._points||{};return t.factor!=null?e[String(t.factor)]||null:t.group!=null&&e["group:"+String(t.group)]||null},S.prototype._annotationTarget=function(t){var e=this._items||[],n=null;if(!t)n=e[this._active];else for(var o=this.plotHost.querySelector("svg"),r=o.getBoundingClientRect(),i=o.viewBox.baseVal,s=(t.clientX-r.left)*(i.width/r.width),u=(t.clientY-r.top)*(i.height/r.height),c=0;c<e.length;c++){var a=e[c];if(s>=a.x&&s<=a.x+a.w&&u>=a.y&&u<=a.y+a.h){n=a;break}}return!n||n.kind==="other"?null:n.kind==="group"?{group:n.obj.key}:{factor:n.obj.key}},S.prototype._annotationLabel=function(t){if(t.group!=null)return String(t.group);var e=(this._res||this.getResult()).factors.filter(function(n){return n.key===String(t.factor)})[0];return e?e.label:String(t.factor||"")},B.VeyRiskTornado={version:St,create:function(t,e){return new S(t,e)},compute:function(t,e){return K(t,e)},listThemes:function(){return Object.keys(vt)},getTheme:function(t){return ht(t)},defaults:{options:Mt,labels:_t,theme:lt}}})(typeof window<"u"?window:void 0);
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@veyforma/charts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Zero-dependency JavaScript charts for finance and risk: exposure heatmap, risk-factor tornado and P&L attribution.",
5
+ "keywords": [
6
+ "charts",
7
+ "data-visualization",
8
+ "heatmap",
9
+ "tornado-chart",
10
+ "sensitivity-analysis",
11
+ "finance",
12
+ "risk-management",
13
+ "credit-risk",
14
+ "market-risk",
15
+ "frtb",
16
+ "svg",
17
+ "zero-dependency",
18
+ "accessible"
19
+ ],
20
+ "homepage": "https://github.com/veyforma/veyforma-charts#readme",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/veyforma/veyforma-charts.git"
24
+ },
25
+ "bugs": "https://github.com/veyforma/veyforma-charts/issues",
26
+ "license": "MIT",
27
+ "author": "Veyforma (https://www.veyforma.com)",
28
+ "type": "module",
29
+ "main": "./dist/veyforma-charts.cjs",
30
+ "module": "./dist/veyforma-charts.mjs",
31
+ "unpkg": "./dist/veyforma-charts.min.js",
32
+ "jsdelivr": "./dist/veyforma-charts.min.js",
33
+ "exports": {
34
+ ".": {
35
+ "import": "./dist/veyforma-charts.mjs",
36
+ "require": "./dist/veyforma-charts.cjs"
37
+ },
38
+ "./dist/*": "./dist/*"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "src",
43
+ "LICENSE",
44
+ "README.md"
45
+ ],
46
+ "scripts": {
47
+ "build": "node scripts/build.mjs",
48
+ "prepublishOnly": "npm run build"
49
+ },
50
+ "devDependencies": {
51
+ "esbuild": "^0.24.0"
52
+ }
53
+ }
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * Veyforma Charts
3
+ * One entry point for every chart in this package. Each chart is also available
4
+ * on its own global (VeyHeatmap, VeyRiskTornado, VeyPlaAttribution).
5
+ * Released under the MIT License. Copyright (c) 2026 Veyforma.
6
+ * https://github.com/veyforma/veyforma-charts
7
+ */
8
+ (function (root) {
9
+ "use strict";
10
+
11
+ function need(name) {
12
+ var lib = root[name];
13
+ if (!lib) throw new Error("VeyformaCharts: " + name + " is not loaded. Load its script before veyforma-charts.js, or use the bundled dist/veyforma-charts.js.");
14
+ return lib;
15
+ }
16
+
17
+ root.VeyformaCharts = {
18
+ version: "1.0.0",
19
+ /** Exposure heatmap: concentrations by any two fields, e.g. sector × country. */
20
+ heatmap: function (target, options) { return need("VeyHeatmap").create(target, options); },
21
+ /** Risk-factor tornado: down and up impact per factor, with convexity, limits and hedges. */
22
+ tornado: function (target, options) { return need("VeyRiskTornado").create(target, options); },
23
+ /** P&L attribution: HPL vs RTPL by factor, with the FRTB PLA test and the path to green. */
24
+ plaAttribution: function (target, options) { return need("VeyPlaAttribution").create(target, options); }
25
+ };
26
+ })(typeof window !== "undefined" ? window : this);