@veyforma/charts 0.0.0-stage → 1.0.2
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.
- package/LICENSE +21 -0
- package/README.md +186 -2
- package/dist/veyforma-charts.cjs +2952 -0
- package/dist/veyforma-charts.js +2945 -0
- package/dist/veyforma-charts.min.js +2 -0
- package/dist/veyforma-charts.mjs +2952 -0
- package/dist/veyforma-heatmap.js +1104 -0
- package/dist/veyforma-heatmap.min.js +2 -0
- package/dist/veyforma-pla.js +899 -0
- package/dist/veyforma-pla.min.js +2 -0
- package/dist/veyforma-tornado.js +912 -0
- package/dist/veyforma-tornado.min.js +2 -0
- package/package.json +51 -4
- package/src/veyforma-charts.js +26 -0
- package/src/veyforma-heatmap.js +1104 -0
- package/src/veyforma-pla.js +899 -0
- package/src/veyforma-tornado.js +912 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @veyforma/charts v1.0.2 · MIT License · Copyright (c) 2026 Veyforma · https://github.com/veyforma/veyforma-charts */
|
|
2
|
+
(function(Y){"use strict";var Ct="1.2.0",kt="http://www.w3.org/2000/svg",St=0,_t={low:"#fbf1ea",mid:"#ef8a54",high:"#9a3412",empty:"#ffffff",limit:"#111111",cellText:"#000000",cellTextOnDark:"#ffffff",totalBar:"#111111",totalBarOpacity:.12,headerText:"#555555",text:"#111111",mutedText:"#6b6b6b",summaryBackground:"#f6f6f6",background:"transparent",tooltipBackground:"#111111",tooltipText:"#ffffff",focus:"#2563eb",fontFamily:"inherit",fontSize:12,cellRadius:3,cellGap:2},Mt={veyforma:{},mono:{low:"#f4f4f4",mid:"#9a9a9a",high:"#111111",empty:"#ffffff",limit:"#111111"},"colour-safe":{low:"#eef3fb",mid:"#6d9be0",high:"#1d3f8f",limit:"#d9730d"},ocean:{low:"#ecf6f8",mid:"#5aaec0",high:"#0c3b5e",limit:"#be123c",summaryBackground:"#eef5f8"},forest:{low:"#f1f5ea",mid:"#8fb36b",high:"#22441a",limit:"#a8590b",summaryBackground:"#f2f4ee"},corporate:{low:"#eef1f6",mid:"#8195b8",high:"#1e3a6e",limit:"#b91c1c",summaryBackground:"#f1f4f8",cellRadius:0},midnight:{background:"#111418",low:"#1e242c",mid:"#2f6aa8",high:"#9cd0ff",empty:"#111418",limit:"#fbbf24",cellText:"#000000",cellTextOnDark:"#ffffff",totalBar:"#9cd0ff",totalBarOpacity:.18,headerText:"#c3c9d2",text:"#f3f4f6",mutedText:"#a3abb8",summaryBackground:"#1b2027",tooltipBackground:"#f3f4f6",tooltipText:"#111418",focus:"#93c5fd"}};function At(h){if((h==null||h==="")&&(h="veyforma"),typeof h=="string")return Mt.hasOwnProperty(h)||(bt('Unknown theme "'+h+'". The "veyforma" theme is used instead.'),h="veyforma"),ft({},_t,Mt[h]);if(typeof h!="object")return bt("The theme option must be a theme name or an object."),ft({},_t);var w=h.extends?At(h.extends):ft({},_t),g=ft(w,h);return delete g.extends,["low","mid","high","empty"].forEach(function(v){pt(g[v])||(bt('Theme colour "'+v+'" must be a hex value such as "#9a3412". The default is used instead.'),g[v]=_t[v])}),g}function ft(h){for(var w=1;w<arguments.length;w++){var g=arguments[w];if(g)for(var v in g)Object.prototype.hasOwnProperty.call(g,v)&&(h[v]=g[v])}return h}function wt(h,w,g){return Math.min(g,Math.max(w,h))}function bt(h){Y.console&&Y.console.warn("VeyHeatmap: "+h)}function ot(h,w,g){var v=document.createElementNS(kt,h);if(w)for(var e in w)w[e]!=null&&v.setAttribute(e,w[e]);return g&&g.appendChild(v),v}function V(h,w,g){var v=document.createElement(h);return w&&(v.className=w),g&&g.appendChild(v),v}function pt(h){if(typeof h!="string")return null;var w=h.trim().replace(/^#/,"");if(w.length===3&&(w=w.split("").map(function(v){return v+v}).join("")),!/^[0-9a-fA-F]{6}$/.test(w))return null;var g=parseInt(w,16);return[g>>16&255,g>>8&255,g&255]}function Rt(h){return"#"+h.map(function(w){var g=Math.round(wt(w,0,255)).toString(16);return g.length<2?"0"+g:g}).join("")}function $t(h,w,g){return[h[0]+(w[0]-h[0])*g,h[1]+(w[1]-h[1])*g,h[2]+(w[2]-h[2])*g]}function ae(h){var w=pt(h.low),g=pt(h.mid),v=pt(h.high);return function(e){return e=wt(e,0,1),Rt(e<.5?$t(w,g,e*2):$t(g,v,(e-.5)*2))}}function dt(h,w){var g=I(h),v=I(w);return(Math.max(g,v)+.05)/(Math.min(g,v)+.05)}function I(h){var w=pt(h);if(!w)return 1;var g=w.map(function(v){return v/=255,v<=.03928?v/12.92:Math.pow((v+.055)/1.055,2.4)});return .2126*g[0]+.7152*g[1]+.0722*g[2]}var J=null;function et(h,w,g,v){if(!J){var e=document.createElement("canvas");J=e.getContext&&e.getContext("2d")}return J?(J.font=(g||400)+" "+w+"px "+v,J.measureText(String(h)).width):String(h).length*w*.6}function ht(h,w,g,v,e){if(h=String(h),et(h,g,v,e)<=w)return h;for(var r=0,i=h.length;r<i;){var u=Math.ceil((r+i)/2);et(h.slice(0,u)+"\u2026",g,v,e)<=w?r=u:i=u-1}return r>0?h.slice(0,r).replace(/\s+$/,"")+"\u2026":""}function Ft(h,w,g,v,e){for(var r=String(h).split(/\s+/),i=[],u="",c=0;c<r.length;c++){var p=u?u+" "+r[c]:r[c];et(p,g,v,e)>w&&u?(i.push(u),u=r[c]):u=p}u&&i.push(u);var _=i.length<=2&&i.every(function(t){return et(t,g,v,e)<=w});return _?i:null}function yt(h){var w=Math.round(h*1e4)/100;return String(w)+"%"}function Dt(h,w){var g=h.decimals!=null?h.decimals:0,v=h.prefix||"",e=h.suffix||"",r={};function i(t,n){return r[t]||(r[t]=new Intl.NumberFormat(w||void 0,n)),r[t]}function u(t,n){n==null&&(n=g);var a=Math.pow(10,-n);if(t>0&&t<a/2)return"<"+v+i("f"+n,{minimumFractionDigits:n,maximumFractionDigits:n}).format(a)+e;var l=v+i("f"+n,{minimumFractionDigits:n,maximumFractionDigits:n}).format(Math.abs(t))+e;return t>=0?l:h.negatives==="brackets"?"("+l+")":"\u2212"+l}function c(t){return e?u(t,0):(t<0?"\u2212":"")+v+i("c",{notation:"compact",maximumFractionDigits:1}).format(Math.abs(t))}function p(t,n){return n==null&&(n=1),i("p"+n,{minimumFractionDigits:n,maximumFractionDigits:n}).format(t*100)+"%"}function _(t){return i("n",{maximumFractionDigits:0}).format(t)}return{value:u,compact:c,percent:p,count:_}}function it(h,w){return String(h).replace(/\{(\w+)\}/g,function(g,v){return w[v]!=null?w[v]:g})}var xt="\0other";function ut(h){if(Array.isArray(h.values)){var w=h.rowLabels,g=h.columnLabels,v=vt&&vt.get(h.values);if(v&&v.grid&&v.gridRows===w&&v.gridCols===g)return v.grid;if(!Array.isArray(w)||!Array.isArray(g))throw new Error("VeyHeatmap: a values grid needs rowLabels and columnLabels.");if(h.values.length!==w.length)throw new Error("VeyHeatmap: values has "+h.values.length+" rows but rowLabels has "+w.length+".");var e=[];h.values.forEach(function(p,_){if(!Array.isArray(p)||p.length!==g.length)throw new Error("VeyHeatmap: row "+(_+1)+" of values needs "+g.length+" numbers.");p.forEach(function(t,n){e.push({row:w[_],column:g[n],value:t})})});var r={records:e,rows:"row",columns:"column",dimensions:{row:{label:h.rowTitle||"Row",order:w.slice(),ordered:!0},column:{label:h.columnTitle||"Column",order:g.slice(),ordered:!0}}};if(vt){var i=vt.get(h.values)||{};i.grid=r,i.gridRows=w,i.gridCols=g,vt.set(h.values,i)}return r}if(!Array.isArray(h.records)||!h.records.length)throw new Error("VeyHeatmap: data needs records, or values with rowLabels and columnLabels.");var u=Object.keys(h.records[0]).filter(function(p){return p!=="value"}),c=ft({},h.dimensions||{});return u.forEach(function(p){c[p]||(c[p]={label:p.charAt(0).toUpperCase()+p.slice(1)})}),{records:h.records,rows:h.rows||u[0],columns:h.columns||u[1],dimensions:c}}var vt=typeof WeakMap=="function"?new WeakMap:null;function Zt(h,w,g,v){var e=w+""+g,r=vt&&v?vt.get(v):null;if(r&&r[e])return r[e];for(var i=new Map,u=new Map,c=new Map,p=0,_=h.records,t=_.length,n=0;n<t;n++){var a=_[n],l=a[w],o=a[g];if(l==null||l==="")throw new Error("VeyHeatmap: record "+(n+1)+' has no "'+w+'".');if(o==null||o==="")throw new Error("VeyHeatmap: record "+(n+1)+' has no "'+g+'".');var s=a.value,m=typeof s=="number"?s:Number(s);if(s==null||s===""||!isFinite(m))throw new Error("VeyHeatmap: record "+(n+1)+" has no numeric value.");if(m<0)throw new Error("VeyHeatmap: record "+(n+1)+" is negative. Exposure values must be zero or more.");typeof l!="string"&&(l=String(l)),typeof o!="string"&&(o=String(o));var f=i.get(l);f||(f=new Map,i.set(l,f),u.set(l,0)),f.set(o,(f.get(o)||0)+m),u.set(l,u.get(l)+m),c.set(o,(c.get(o)||0)+m),p+=m}var b=function(y){var x={};return y.forEach(function(M,d){x[d]=M}),x},k={cell:function(y,x){var M=i.get(y);return M&&M.get(x)||0},rowTot:b(u),colTot:b(c),rowSeen:Array.from(u.keys()),colSeen:Array.from(c.keys()),total:p};return vt&&v&&(r||(r={},vt.set(v,r)),r[e]=k),k}function Tt(h,w,g){var v=ut(h),e=w.rows||v.rows,r=w.columns||v.columns;if(!e||!r)throw new Error("VeyHeatmap: choose a field for the rows and a field for the columns.");if(e===r)throw new Error('VeyHeatmap: rows and columns cannot both use "'+e+'".');var i=ft({label:e},v.dimensions[e]),u=ft({label:r},v.dimensions[r]),c=Zt(v,e,r,Array.isArray(h.values)?h.values:h.records),p=c.rowTot,_=c.colTot,t=c.rowSeen,n=c.colSeen,a=c.total;function l(f,b,k,y,x){var M=f.slice();if(Array.isArray(k.order)){var d=k.order.map(String);M.sort(function(A,H){var lt=d.indexOf(A),tt=d.indexOf(H);return lt<0&&(lt=d.length+f.indexOf(A)),tt<0&&(tt=d.length+f.indexOf(H)),lt-tt})}var T=M.slice().sort(function(A,H){return b[H]-b[A]||M.indexOf(A)-M.indexOf(H)}),C=y==="total"||y!=="natural"&&!k.ordered,R=C?T:M,O=R.map(function(A){return{key:A,label:A,members:[A]}});if(x&&x>0&&R.length>x+1){var j=T.slice(0,x),E=R.filter(function(A){return j.indexOf(A)>=0}),S=R.filter(function(A){return j.indexOf(A)<0});O=E.map(function(A){return{key:A,label:A,members:[A]}}),O.push({key:xt,label:it(g.other,{count:S.length}),members:S,other:!0})}return O.forEach(function(A){A.total=A.members.reduce(function(H,lt){return H+b[lt]},0)}),O}var o=l(t,p,i,w.sortRows,w.topRows),s=l(n,_,u,w.sortColumns,w.topColumns),m=o.map(function(f){return s.map(function(b){var k=0;return f.members.forEach(function(y){b.members.forEach(function(x){k+=c.cell(y,x)})}),k})});return{rowKey:e,colKey:r,rowDim:i,colDim:u,rows:o,cols:s,values:m,total:a}}function Jt(h,w){var g=[],v=0;h.values.forEach(function(i,u){i.forEach(function(c,p){var _=h.total>0?c/h.total:0;v+=_*_*1e4,g.push({r:u,c:p,value:c,share:_})})}),g.sort(function(i,u){return u.value-i.value});var e=g.slice(0,5).reduce(function(i,u){return i+u.share},0),r=w>0?g.filter(function(i){return i.share>w+1e-12}):[];return{hhi:v,effective:v>0?1e4/v:0,largest:g[0],top5:e,above:r}}var Ht={data:null,theme:"veyforma",locale:void 0,rows:void 0,columns:void 0,valueMode:"amount",scale:"linear",sortRows:"auto",sortColumns:"auto",topRows:0,topColumns:0,fit:"auto",limit:void 0,totals:!0,cellLabels:"auto",cellHeight:void 0,summary:!0,legend:!0,tooltip:!0,animate:!0,labels:null,ariaLabel:void 0,tooltipFormatter:null,onClick:null,caption:!0,annotations:null,onAnnotationsChange:null,toolbar:!0},te={total:"Total",other:"Other ({count})",empty:"No exposure",totalExposure:"Total exposure",largest:"Largest concentration",hhi:"Concentration (HHI)",aboveLimit:"Above limit",top5:"Top 5 cells",hhiNote:"Like {n} equal-sized cells",aboveNote:"Cells above {limit} of total",gridNote:"{rows} {rowDim} \xD7 {cols} {colDim}",top5Note:"Share of total exposure",exposure:"Exposure",shareOfTotal:"Share of total",shareOfRow:"Share of {row}",shareOfColumn:"Share of {column}",limitLegend:"Above {limit} limit",limitTip:"Above the {limit} limit",rowTotalTip:"{label} total",scrollNote:"Scroll sideways to see all {columns}.",groupNote:"Smaller {columns} are grouped as Other to fit this screen. Tap an Other cell to see which.",includes:"Other includes {list}"};function Vt(){if(!document.getElementById("vhm-styles")){var h=".vhm{position:relative;color:var(--vhm-text);background:var(--vhm-bg);font-family:var(--vhm-font);line-height:1.4}.vhm.vhm-filled{padding:14px 14px 8px;border-radius:10px}.vhm-summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:8px;margin:0 0 12px}.vhm-stat{background:var(--vhm-summary-bg);border-radius:10px;padding:10px 12px;min-width:0}.vhm-stat-label{font-size:11px;letter-spacing:.04em;text-transform:uppercase;color:var(--vhm-muted)}.vhm-stat-value{font-size:20px;font-weight:650;letter-spacing:-.01em;margin-top:2px;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.vhm-stat-note{font-size:11.5px;color:var(--vhm-muted);margin-top:1px;overflow-wrap:anywhere}.vhm-legend{display:flex;flex-wrap:wrap;align-items:center;gap:6px 18px;font-size:12px;margin:0 0 10px}.vhm-legend>span{display:inline-flex;align-items:center;gap:6px}.vhm-legend .vhm-ramp{display:inline-flex;flex-direction:column;align-items:stretch;gap:2px}.vhm-ramp-bar{width:150px;height:10px;border-radius:3px}.vhm-ramp-ticks{display:flex;justify-content:space-between;gap:8px;font-size:11px;color:var(--vhm-muted);font-variant-numeric:tabular-nums}.vhm-plot-host{overflow-x:auto;-webkit-overflow-scrolling:touch}.vhm-plot{display:block;overflow:visible;outline:none}.vhm-plot:focus-visible{outline:2px solid var(--vhm-focus);outline-offset:4px;border-radius:4px}.vhm-animate .vhm-cell{animation:vhm-fade .45s ease both}@keyframes vhm-fade{from{opacity:0}to{opacity:1}}@media (prefers-reduced-motion:reduce){.vhm-animate .vhm-cell{animation:none}}.vhm-scroll-note{font-size:11.5px;color:var(--vhm-muted);margin-top:4px}.vhm-tip{position:absolute;left:0;top:0;pointer-events:none;background:var(--vhm-tip-bg);color:var(--vhm-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}.vhm-tip.vhm-on{opacity:1;transform:none}.vhm-tip b{font-weight:600}.vhm-table{width:100%;border-collapse:collapse;font-size:13px}.vhm-table th,.vhm-table td{text-align:right;padding:7px 6px;border-bottom:1px solid rgba(127,127,127,.25);font-variant-numeric:tabular-nums;white-space:nowrap}.vhm-table th:first-child,.vhm-table td:first-child{text-align:left}.vhm-table th{font-weight:600;font-size:12px}.vhm-table tr.vhm-total td{font-weight:600}",w=document.createElement("style");w.id="vhm-styles",w.appendChild(document.createTextNode(h)),(document.head||document.documentElement).appendChild(w)}}function W(h,w){var g=typeof h=="string"?document.querySelector(h):h;if(!g||g.nodeType!==1)throw new Error("VeyHeatmap: container not found ("+h+").");if(!w||!w.data)throw new Error("VeyHeatmap: options.data is required.");Vt(),this.id=++St,this.container=g,this.options=ft({},Ht,w),this.element=V("div","vhm"),this.summaryEl=V("div","vhm-summary",this.element),this.legendEl=V("div","vhm-legend",this.element),this.plotHost=V("div","vhm-plot-host",this.element),this.noteEl=V("div","vhm-scroll-note",this.element),this.tipEl=V("div","vhm-tip",this.element),this.tipEl.setAttribute("role","tooltip"),this.tipEl.id="vhm-tip-"+this.id,g.appendChild(this.element),this._animateNext=!!this.options.animate,this._lastWidth=0,this._active=null;var v=this;Y.ResizeObserver?(this._observer=new Y.ResizeObserver(function(){var e=Math.round(v.element.clientWidth);e&&e!==v._lastWidth&&v.redraw()}),this._observer.observe(this.element)):(this._onResize=function(){v.redraw()},Y.addEventListener("resize",this._onResize)),this._onDocTap=function(e){v.element.contains(e.target)||v._hideTip()},document.addEventListener("pointerdown",this._onDocTap),this.redraw(),this.options.toolbar!==!1&&Y.VeyformaToolkit&&(this.toolkit=Y.VeyformaToolkit.attach(this,this.options.toolbar))}W.prototype.update=function(h){return h?(h.data&&h.data!==this.options.data&&this.options.animate&&(this._animateNext=!0,this._active=null),(h.rows||h.columns||h.topRows!=null||h.topColumns!=null)&&(this._active=null),h.animate===!0&&(this._animateNext=!0),ft(this.options,h),this.redraw()):this},W.prototype.setData=function(h){return vt&&h&&(Array.isArray(h.records)&&vt.delete(h.records),Array.isArray(h.values)&&vt.delete(h.values)),this.update({data:h})},W.prototype.setTheme=function(h){return this.update({theme:h})},W.prototype.getTheme=function(){return At(this.options.theme)},W.prototype._labels=function(){return ft({},te,this.options.labels)},W.prototype._limit=function(){var h=this.options,w=h.limit!==void 0?h.limit:h.data.limit&&h.data.limit.share;return w=Number(w),isFinite(w)&&w>0&&w<1?w:0},W.prototype.getMatrix=function(){var h=Tt(this.options.data,this.options,this._labels()),w=function(g){return{key:g.key===xt?null:g.key,label:g.label,total:g.total,other:!!g.other,members:g.members.slice()}};return{rowField:h.rowKey,columnField:h.colKey,rows:h.rows.map(w),columns:h.cols.map(w),values:h.values.map(function(g){return g.slice()}),total:h.total}},W.prototype.getStats=function(){var h=Tt(this.options.data,ft({},this.options,{topRows:0,topColumns:0}),this._labels()),w=this._limit(),g=Jt(h,w),v=function(e){return{row:h.rows[e.r].label,column:h.cols[e.c].label,value:e.value,share:e.share}};return{total:h.total,rows:h.rows.length,columns:h.cols.length,hhi:g.hhi,effectiveCells:g.effective,top5Share:g.top5,largest:g.largest?v(g.largest):null,limit:w||null,aboveLimit:g.above.map(v)}},W.prototype.createTable=function(){var h=this.options,w=h.data,g=this._labels(),v=Tt(w,h,g),e=Dt(w,h.locale),r=document.createElement("table");if(r.className="vhm-table",w.title){var i=V("caption",null,r);i.textContent=w.title,i.style.cssText="text-align:left;font-weight:600;padding:0 6px 6px"}var u=V("tr",null,V("thead",null,r)),c=V("th",null,u);c.scope="col",c.textContent=v.rowDim.label,v.cols.forEach(function(n){var a=V("th",null,u);a.scope="col",a.textContent=n.label});var p=V("th",null,u);p.scope="col",p.textContent=g.total;var _=V("tbody",null,r);v.rows.forEach(function(n,a){var l=V("tr",null,_),o=V("th",null,l);o.scope="row",o.textContent=n.label,o.style.textAlign="left",o.style.fontWeight="400",v.values[a].forEach(function(s){V("td",null,l).textContent=s?e.value(s):"\u2014"}),V("td",null,l).textContent=e.value(n.total)});var t=V("tr","vhm-total",_);return V("td",null,t).textContent=g.total,v.cols.forEach(function(n){V("td",null,t).textContent=e.value(n.total)}),V("td",null,t).textContent=e.value(v.total),r},W.prototype.destroy=function(){this.toolkit&&this.toolkit.destroy(),this._observer&&this._observer.disconnect(),this._onResize&&Y.removeEventListener("resize",this._onResize),document.removeEventListener("pointerdown",this._onDocTap),this.element.parentNode&&this.element.parentNode.removeChild(this.element)},W.prototype._hideTip=function(){this.tipEl.classList.remove("vhm-on"),this._focusRect&&this._focusRect.setAttribute("opacity",0),this._boldReset&&this._boldReset()},W.prototype._placeTip=function(h,w,g){var v=this.tipEl;v.textContent="",h.forEach(function(t,n){n&&v.appendChild(document.createElement("br"));var a=n===0?document.createElement("b"):document.createTextNode("");a.textContent=t,v.appendChild(a)});var e=this.element.getBoundingClientRect(),r=g&&g.clientX?g.clientX:w.left+w.width/2,i=g&&g.clientY?g.clientY:w.top;v.classList.add("vhm-on");var u=v.offsetWidth,c=v.offsetHeight,p=wt(r-e.left-u/2,4,Math.max(4,e.width-u-4)),_=i-e.top-c-14;_<0&&(_=(w.bottom!=null?w.bottom:i)-e.top+10),v.style.left=p+"px",v.style.top=_+"px"},W.prototype.redraw=function(){var h=this.options,w=h.data,g=this,v=At(h.theme),e=this._labels(),r=Tt(w,h,e),i=Dt(w,h.locale),u=h.topRows>0||h.topColumns>0?Tt(w,ft({},h,{topRows:0,topColumns:0}),e):r,c=this._limit(),p=Jt(u,c),_=this.element,t=ae(v),n=v.background&&v.background!=="transparent"?v.background:"#ffffff",a=v.fontFamily==="inherit"?Y.getComputedStyle?Y.getComputedStyle(this.container).fontFamily:"sans-serif":v.fontFamily,l=_.style;l.setProperty("--vhm-text",v.text),l.setProperty("--vhm-muted",v.mutedText),l.setProperty("--vhm-bg",v.background),l.setProperty("--vhm-font",a),l.setProperty("--vhm-focus",v.focus),l.setProperty("--vhm-tip-bg",v.tooltipBackground),l.setProperty("--vhm-tip-text",v.tooltipText),l.setProperty("--vhm-summary-bg",v.summaryBackground),_.classList.toggle("vhm-filled",!!v.background&&v.background!=="transparent"),_.classList.toggle("vhm-animate",!!this._animateNext);var o=Math.max(this.plotHost.clientWidth||_.clientWidth||0,280);this._lastWidth=Math.round(_.clientWidth);var s=o<560,m=Number(v.fontSize)||12,f=s?m-1.5:m-.5,b=s?m-2:m-1,k=h.cellHeight||(s?28:34),y=Math.max(0,Number(v.cellGap)||0),x=s?26:34,M=Math.max.apply(null,r.rows.map(function(L){return et(L.label,f,400,a)})),d=Math.min(Math.ceil(M)+12,Math.round(o*(s?.3:.26))),T=h.totals?Math.max(s?50:70,Math.ceil(et(i.value(Math.max.apply(null,r.rows.map(function(L){return L.total}))),m-1,600,a))+12):0;h.totals&&s&&(T=Math.min(T,64));var C=h.totals?8:0,R=o-d-C-T-2,O=h.fit||"auto",j=!1,E=Math.floor(R/x),S=O==="group"||O==="auto"&&!r.colDim.ordered&&!(h.topColumns>0);S&&r.cols.length>E&&E>=3&&(r=Tt(w,ft({},h,{topColumns:E-1}),e),j=!0);var A=r.rows.length,H=r.cols.length,lt=(r.rowDim.plural||r.rowDim.label).toLowerCase(),tt=(r.colDim.plural||r.colDim.label).toLowerCase(),D=h.valueMode;["amount","shareOfTotal","shareOfRow","shareOfColumn"].indexOf(D)<0&&(D="amount");for(var K=function(L,z){var $=r.values[L][z];return D==="shareOfTotal"?r.total?$/r.total:0:D==="shareOfRow"?r.rows[L].total?$/r.rows[L].total:0:D==="shareOfColumn"?r.cols[z].total?$/r.cols[z].total:0:$},q=0,X=0;X<A;X++)for(var Q=0;Q<H;Q++)q=Math.max(q,K(X,Q));var Z=h.scale==="sqrt",P=function(L){if(q<=0)return 0;var z=L/q;return Z?Math.sqrt(z):z},N=function(L,z){return D==="amount"?z?i.compact(L):i.value(L):i.percent(L,z?0:1)},F=this.summaryEl;if(F.textContent="",F.style.display=h.summary?"":"none",h.summary){var B=function(L,z,$){var G=V("div","vhm-stat",F);V("div","vhm-stat-label",G).textContent=L,V("div","vhm-stat-value",G).textContent=z,$&&(V("div","vhm-stat-note",G).textContent=$)};B(e.totalExposure,i.value(r.total),it(e.gridNote,{rows:u.rows.length,rowDim:lt,cols:u.cols.length,colDim:tt})),p.largest&&B(e.largest,i.percent(p.largest.share),u.rows[p.largest.r].label+" \xD7 "+u.cols[p.largest.c].label+" \xB7 "+i.value(p.largest.value)),B(e.hhi,i.count(p.hhi),it(e.hhiNote,{n:i.count(Math.round(p.effective))})),c?B(e.aboveLimit,i.count(p.above.length),it(e.aboveNote,{limit:yt(c)})):B(e.top5,i.percent(p.top5),e.top5Note)}var U=this.legendEl;if(U.textContent="",U.style.display=h.legend?"":"none",h.legend){var nt=V("span","vhm-ramp",U),st=V("span","vhm-ramp-bar",nt);st.style.background="linear-gradient(to right,"+[0,.25,.5,.75,1].map(function(L){return t(L)}).join(",")+")";var at=V("span","vhm-ramp-ticks",nt),zt=Z?q*.25:q*.5;[0,zt,q].forEach(function(L){V("span",null,at).textContent=N(L,!0)});var mt=V("span",null,U),gt=ot("svg",{width:14,height:14,"aria-hidden":"true"},mt);if(ot("rect",{x:1,y:1,width:12,height:12,rx:2,fill:v.empty,stroke:v.mutedText,"stroke-opacity":.45,"stroke-dasharray":"2 2"},gt),mt.appendChild(document.createTextNode(e.empty)),c){var Et=V("span",null,U),jt=ot("svg",{width:14,height:14,"aria-hidden":"true"},Et);ot("rect",{x:1.5,y:1.5,width:11,height:11,rx:2,fill:t(.7),stroke:v.limit,"stroke-width":2},jt),ot("rect",{x:3.5,y:3.5,width:7,height:7,rx:1,fill:"none",stroke:n,"stroke-width":1},jt),Et.appendChild(document.createTextNode(it(e.limitLegend,{limit:yt(c)})))}}var rt=R/H,Wt=!1;rt<x&&(rt=x,Wt=!0),R=rt*H;var Kt=r.cols.map(function(L){return Ft(L.label,rt-4,f,400,a)}),ee=Kt.some(function(L){return L===null}),ne=Math.max.apply(null,r.cols.map(function(L){return et(L.label,f,400,a)})),oe=Math.min(ne,140),Xt=ee?Math.ceil(oe*.7071+f+10):Math.max.apply(null,Kt.map(function(L){return L.length}))*(f+3)+10,ce=ee?Math.max(0,oe*.7071-T-C):0,ie=d+R+C+T+2+ce;ie>o+.5&&(Wt=!0);var ye=Xt,Ee=h.totals?k:0,xe=ye+A*k+(h.totals?C+Ee:0)+4,fe=d,Bt=function(L){return fe+L*rt},Lt=function(L){return ye+L*k};this.plotHost.textContent="",this.noteEl.textContent=Wt?it(e.scrollNote,{columns:tt}):j?it(e.groupNote,{columns:tt}):"",this.noteEl.style.display=Wt||j?"":"none";var Nt=ot("svg",{class:"vhm-plot",viewBox:"0 0 "+ie+" "+xe,width:ie,height:xe,tabindex:0,role:"img","aria-label":h.ariaLabel||[w.title,r.rowDim.label+" by "+r.colDim.label,p.largest?e.largest+": "+u.rows[p.largest.r].label+" \xD7 "+u.cols[p.largest.c].label+", "+i.percent(p.largest.share):null].filter(Boolean).join(". ")},this.plotHost);Wt||(Nt.style.width="100%",Nt.style.height="auto");var Gt=function(L,z,$){var G=ot("text",ft({"font-family":a},L),$||Nt);return G.textContent=z,G},ke=[];r.cols.forEach(function(L,z){var $=Bt(z)+rt/2,G=ot("g",null,Nt);if(ee){var ct=Xt-6;Gt({x:$-2,y:ct,"text-anchor":"start",transform:"rotate(-45 "+($-2)+" "+ct+")","font-size":f,fill:L.other?v.mutedText:v.headerText},ht(L.label,140,f,400,a),G)}else{var qt=Kt[z];qt.forEach(function(Qt,Fe){Gt({x:$,y:Xt-6-(qt.length-1-Fe)*(f+3),"text-anchor":"middle","font-size":f,fill:L.other?v.mutedText:v.headerText},Qt,G)})}ke.push(G)}),h.totals&&Gt({x:fe+R+C+T-4,y:Xt-6,"text-anchor":"end","font-size":f,"font-weight":600,fill:v.text},e.total);var Le=r.rows.map(function(L,z){var $=ht(L.label,d-12,f,400,a),G=Gt({x:d-8,y:Lt(z)+k/2+f*.35,"text-anchor":"end","font-size":f,fill:L.other?v.mutedText:v.headerText},$);if($!==L.label){var ct=ot("title",null,G);ct.textContent=L.label}return G});h.totals&&Gt({x:d-8,y:Lt(A)+C+k/2+f*.35,"text-anchor":"end","font-size":f,"font-weight":600,fill:v.text},e.total);for(var Ut=ot("g",null,Nt),Ce=h.cellLabels===!0||h.cellLabels==="auto",Pt=0;Pt<A;Pt++)for(var Ot=0;Ot<H;Ot++){var le=r.values[Pt][Ot],pe=K(Pt,Ot),de=le>0?t(P(pe)):v.empty,re=ot("rect",{x:Bt(Ot)+y/2,y:Lt(Pt)+y/2,width:Math.max(rt-y,1),height:Math.max(k-y,1),rx:Math.min(v.cellRadius,rt/4),fill:de,class:"vhm-cell","data-r":Pt,"data-c":Ot},Ut);if(le>0||(re.setAttribute("stroke",v.mutedText),re.setAttribute("stroke-opacity",.45),re.setAttribute("stroke-dasharray","2 2"),re.setAttribute("stroke-width",1)),re.style.animationDelay=Math.min((Pt+Ot)*18,500)+"ms",c&&r.total>0&&le/r.total>c+1e-12&&!r.rows[Pt].other&&!r.cols[Ot].other&&(ot("rect",{x:Bt(Ot)+y/2+1,y:Lt(Pt)+y/2+1,width:Math.max(rt-y-2,1),height:Math.max(k-y-2,1),rx:Math.min(v.cellRadius,rt/4),fill:"none",stroke:v.limit,"stroke-width":2,"pointer-events":"none"},Ut),ot("rect",{x:Bt(Ot)+y/2+3,y:Lt(Pt)+y/2+3,width:Math.max(rt-y-6,1),height:Math.max(k-y-6,1),rx:Math.max(0,Math.min(v.cellRadius,rt/4)-1),fill:"none",stroke:n,"stroke-width":1,"pointer-events":"none"},Ut)),Ce&&le>0&&k-y>=16){var Se=rt-y-8,se=N(pe,!1);if(et(se,b,500,a)>Se&&(se=N(pe,!0)),et(se,b,500,a)<=Se){var Ae=dt(de,v.cellTextOnDark)>dt(de,v.cellText)?v.cellTextOnDark:v.cellText;Gt({x:Bt(Ot)+rt/2,y:Lt(Pt)+k/2+b*.35,"text-anchor":"middle","font-size":b,"font-weight":500,fill:Ae,"pointer-events":"none",class:"vhm-cell-label"},se,Ut)}}}var Yt=null;if(h.totals){Yt=ot("g",null,Nt);var Re=Math.max.apply(null,r.rows.map(function(L){return L.total}))||1,ze=Math.max.apply(null,r.cols.map(function(L){return L.total}))||1,me=fe+R+C;r.rows.forEach(function(L,z){var $=Math.max(2,(T-2)*L.total/Re);ot("rect",{x:me,y:Lt(z)+y/2+3,width:$,height:k-y-6,rx:2,fill:v.totalBar,"fill-opacity":v.totalBarOpacity,"data-tr":z},Yt);var G=i.value(L.total);et(G,m-1,600,a)>T-6&&(G=i.compact(L.total)),Gt({x:me+T-4,y:Lt(z)+k/2+(m-1)*.35,"text-anchor":"end","font-size":m-1,"font-weight":600,fill:v.text,"pointer-events":"none"},G,Yt)});var ve=Lt(A)+C;r.cols.forEach(function(L,z){var $=Math.max(2,(k-y-4)*L.total/ze);ot("rect",{x:Bt(z)+y/2+2,y:ve+k-y/2-2-$,width:Math.max(rt-y-4,1),height:$,rx:2,fill:v.totalBar,"fill-opacity":v.totalBarOpacity,"data-tc":z},Yt);var G=i.value(L.total);et(G,b,600,a)>rt-y-6&&(G=i.compact(L.total)),et(G,b,600,a)<=rt-y-6&&Gt({x:Bt(z)+rt/2,y:ve+k/2+b*.35,"text-anchor":"middle","font-size":b,"font-weight":600,fill:v.text,"pointer-events":"none"},G,Yt)});var be=i.value(r.total);et(be,m-1,700,a)>T-6&&(be=i.compact(r.total)),Gt({x:me+T-4,y:ve+k/2+(m-1)*.35,"text-anchor":"end","font-size":m-1,"font-weight":700,fill:v.text},be)}this._focusRect=ot("rect",{x:0,y:0,width:0,height:0,rx:Math.min(v.cellRadius+1,6),fill:"none",stroke:v.text,"stroke-width":2,opacity:0,"pointer-events":"none"},Nt);var ge=function(L,z){var $=r.values[L][z];return{row:r.rows[L].label,column:r.cols[z].label,rowIndex:L,columnIndex:z,value:$,shareOfTotal:r.total?$/r.total:0,shareOfRow:r.rows[L].total?$/r.rows[L].total:0,shareOfColumn:r.cols[z].total?$/r.cols[z].total:0,aboveLimit:!!(c&&r.total&&$/r.total>c+1e-12&&!r.rows[L].other&&!r.cols[z].other),rowMembers:r.rows[L].members.slice(),columnMembers:r.cols[z].members.slice()}},ue=[];this._boldReset=function(){ue.forEach(function(L){L.removeAttribute("font-weight")}),ue=[]};var Ne=function(L,z){g._boldReset();var $=Le[L];$.setAttribute("font-weight",600),ue.push($),Array.prototype.forEach.call(ke[z].childNodes,function(G){G.setAttribute("font-weight",600),ue.push(G)})},he=function(L,z,$){if(g._active=[L,z],g._focusRect.setAttribute("x",Bt(z)+y/2-1),g._focusRect.setAttribute("y",Lt(L)+y/2-1),g._focusRect.setAttribute("width",rt-y+2),g._focusRect.setAttribute("height",k-y+2),g._focusRect.setAttribute("opacity",1),Ne(L,z),!!h.tooltip){var G=ge(L,z),ct;typeof h.tooltipFormatter=="function"?(ct=h.tooltipFormatter(G,i),Array.isArray(ct)||(ct=[String(ct)])):(ct=[G.row+" \xD7 "+G.column],G.value?(ct.push(e.exposure+": "+i.value(G.value)),ct.push(e.shareOfTotal+": "+i.percent(G.shareOfTotal)),ct.push(it(e.shareOfRow,{row:G.row})+": "+i.percent(G.shareOfRow)),ct.push(it(e.shareOfColumn,{column:G.column})+": "+i.percent(G.shareOfColumn)),G.aboveLimit&&ct.push(it(e.limitTip,{limit:yt(c)}))):ct.push(e.empty),r.rows[L].other&&ct.push(it(e.includes,{list:r.rows[L].members.join(", ")})),r.cols[z].other&&ct.push(it(e.includes,{list:r.cols[z].members.join(", ")})));var qt=Nt.getBoundingClientRect(),Qt=qt.width/ie;g._placeTip(ct,{left:qt.left+Bt(z)*Qt,top:qt.top+Lt(L)*Qt,width:rt*Qt,bottom:qt.top+(Lt(L)+k)*Qt},$)}},_e=function(L,z,$){var G=L?r.rows[z]:r.cols[z],ct=[it(e.rowTotalTip,{label:G.label}),i.value(G.total)+" \xB7 "+i.percent(r.total?G.total/r.total:0)+" "+e.shareOfTotal.toLowerCase()];G.other&&ct.push(G.members.join(", ")),g._placeTip(ct,{left:$.clientX,top:$.clientY,width:0},$)};Ut.addEventListener("mousemove",function(L){var z=L.target;!z.hasAttribute||!z.hasAttribute("data-r")||he(+z.getAttribute("data-r"),+z.getAttribute("data-c"),L)}),Ut.addEventListener("pointerdown",function(L){var z=L.target;!z.hasAttribute||!z.hasAttribute("data-r")||he(+z.getAttribute("data-r"),+z.getAttribute("data-c"),L)}),Ut.addEventListener("mouseleave",function(){g._hideTip()}),typeof h.onClick=="function"&&(Ut.style.cursor="pointer",Ut.addEventListener("click",function(L){var z=L.target;!z.hasAttribute||!z.hasAttribute("data-r")||h.onClick(ge(+z.getAttribute("data-r"),+z.getAttribute("data-c")),L)})),Yt&&(Yt.addEventListener("mousemove",function(L){var z=L.target;z.hasAttribute&&z.hasAttribute("data-tr")?_e(!0,+z.getAttribute("data-tr"),L):z.hasAttribute&&z.hasAttribute("data-tc")&&_e(!1,+z.getAttribute("data-tc"),L)}),Yt.addEventListener("mouseleave",function(){g._hideTip()})),this._geom={rows:r.rows,cols:r.cols,cx:Bt,cy:Lt,cellW:rt,cellH:k,gap:y},Nt.setAttribute("aria-describedby",this.tipEl.id);var we=[0,0];if(p.largest){var Te=r.rows.map(function(L){return L.key}).indexOf(u.rows[p.largest.r].key),Me=r.cols.map(function(L){return L.key}).indexOf(u.cols[p.largest.c].key);Te>=0&&Me>=0&&(we=[Te,Me])}return Nt.addEventListener("focus",function(){var L=g._active&&g._active[0]<A&&g._active[1]<H?g._active:we;he(L[0],L[1])}),Nt.addEventListener("blur",function(){g._hideTip()}),Nt.addEventListener("keydown",function(L){var z=g._active&&g._active[0]<A&&g._active[1]<H?g._active.slice():we.slice();if(L.key==="ArrowLeft")z[1]=Math.max(0,z[1]-1);else if(L.key==="ArrowRight")z[1]=Math.min(H-1,z[1]+1);else if(L.key==="ArrowUp")z[0]=Math.max(0,z[0]-1);else if(L.key==="ArrowDown")z[0]=Math.min(A-1,z[0]+1);else if(L.key==="Home")z[1]=0;else if(L.key==="End")z[1]=H-1;else if((L.key==="Enter"||L.key===" ")&&typeof h.onClick=="function"){L.preventDefault(),h.onClick(ge(z[0],z[1]),L);return}else return;L.preventDefault(),he(z[0],z[1])}),this._hideTip(),this._animateNext=!1,this};function It(h,w){if(w==null)return-1;w=String(w);for(var g=0;g<h.length;g++)if(h[g].label===w||h[g].key===w||h[g].members.indexOf(w)>=0)return g;return-1}W.prototype.howToRead=function(){var h=Tt(this.options.data,this.options,this._labels()),w=(h.rowDim.label||"row").toLowerCase(),g=(h.colDim.label||"column").toLowerCase();return"Each cell is the exposure where a "+w+" meets a "+g+"; darker cells hold more. The bars on the right and along the bottom are the totals for each "+w+" and "+g+". HHI measures concentration: the higher it is, the more the book depends on a few cells."+(this._limit()?" Cells with a double outline are above the concentration limit.":"")},W.prototype.describe=function(){var h=this.getStats(),w=Dt(this.options.data,this.options.locale),g=Tt(this.options.data,this.options,this._labels()),v=["In this example total exposure is "+w.value(h.total)+" across "+h.rows+" "+(g.rowDim.plural||g.rowDim.label).toLowerCase()+" and "+h.columns+" "+(g.colDim.plural||g.colDim.label).toLowerCase()+"."];return h.largest&&v.push("The largest cell is "+h.largest.row+" \xD7 "+h.largest.column+" with "+w.value(h.largest.value)+" ("+w.percent(h.largest.share)+" of the total)."),v.push("HHI is "+w.count(h.hhi)+", like "+w.count(Math.round(h.effectiveCells))+" equal-sized cells."),h.limit&&v.push(h.aboveLimit.length+" "+(h.aboveLimit.length===1?"cell is":"cells are")+" above the "+yt(h.limit)+" limit."),v.join(" ")},W.prototype.getExportData=function(){var h=this.options,w=h.data,g=this._labels(),v=Tt(w,ft({},h,{topRows:0,topColumns:0}),g),e=Dt(w,h.locale),r=this.getStats(),i=this._limit(),u={prefix:w.prefix||"",suffix:w.suffix||"",decimals:w.decimals!=null?w.decimals:0,negatives:w.negatives},c=[{label:v.rowDim.label,type:"text"}].concat(v.cols.map(function(s){return{label:s.label,type:"number",unit:u}}),[{label:g.total,type:"number",unit:u}]),p=v.rows.map(function(s,m){return[s.label].concat(v.values[m],[s.total])});p.push([g.total].concat(v.cols.map(function(s){return s.total}),[v.total]));var _=v.rows.map(function(s,m){return[s.label].concat(v.values[m].map(function(f){return f?e.value(f):"\u2014"}),[e.value(s.total)])});_.push([g.total].concat(v.cols.map(function(s){return e.value(s.total)}),[e.value(v.total)]));var t=[];v.rows.forEach(function(s,m){v.cols.forEach(function(f,b){var k=v.values[m][b];k&&t.push([s.label,f.label,k,v.total?k/v.total:0])})}),t.sort(function(s,m){return m[2]-s[2]});var n=function(s){return i&&s>i+1e-12?"Yes":"No"},a=[[g.totalExposure,r.total,e.value(r.total)],[g.hhi,r.hhi,e.count(r.hhi)],["Effective number of cells",r.effectiveCells,e.count(Math.round(r.effectiveCells))],[g.top5,r.top5Share,e.percent(r.top5Share)]];r.largest&&a.push([g.largest,r.largest.share,r.largest.row+" \xD7 "+r.largest.column+" \xB7 "+e.percent(r.largest.share)]),i&&(a.push(["Limit (share of total)",i,yt(i)]),a.push([g.aboveLimit,r.aboveLimit.length,e.count(r.aboveLimit.length)]));var l=(h.annotations||[]).map(function(s,m){return[String(m+1),String(s.row||""),String(s.column||""),s.text||""]}),o=[{name:"Matrix",columns:c,rows:p,text:_,bold:p.map(function(s,m){return m===p.length-1})},{name:"Cells",columns:[{label:v.rowDim.label,type:"text"},{label:v.colDim.label,type:"text"},{label:g.exposure,type:"number",unit:u},{label:g.shareOfTotal,type:"percent",decimals:2},{label:g.aboveLimit,type:"text"}],rows:t.map(function(s){return[s[0],s[1],s[2],s[3],n(s[3])]}),text:t.map(function(s){return[s[0],s[1],e.value(s[2]),e.percent(s[3],2),n(s[3])]})},{name:"Concentration",columns:[{label:"Measure",type:"text"},{label:"Value",type:"general"},{label:"As shown",type:"text"}],rows:a,text:a.map(function(s){return[s[0],typeof s[1]=="number"?String(Number(s[1].toPrecision(10))):String(s[1]),s[2]]})}];return l.length&&o.push({name:"Notes",columns:[{label:"No.",type:"text"},{label:v.rowDim.label,type:"text"},{label:v.colDim.label,type:"text"},{label:"Note",type:"text"}],rows:l}),{title:w.title||"Exposure heatmap",subtitle:w.subtitle||"",summary:this.describe(),library:"Veyforma Exposure Heatmap "+Ct,sheets:o,meta:[["Method","HHI = 10,000 \xD7 sum of squared cell shares; effective number of cells = 10,000 \xF7 HHI; a cell is above the limit when its share is strictly greater"],["Grid",v.rowDim.label+" \xD7 "+v.colDim.label+", full grid without Other grouping"],["Unit",w.unit],["Limit",i?yt(i)+" of total":null],["As of",w.asOf],["Data source",w.source]]}},W.prototype._annotationPoint=function(h){var w=this._geom;if(!w||!h)return null;var g=It(w.rows,h.row),v=It(w.cols,h.column);if(g<0||v<0)return null;var e=w.rows[g]&&w.rows[g].other||w.cols[v]&&w.cols[v].other;return{x:w.cx(v)+w.gap/2+11,y:w.cy(g)+w.gap/2+11,inside:!0,where:e?"shown in Other":null}},W.prototype._annotationTarget=function(h){var w=this._geom,g,v;if(!w)return null;if(h){var e=h.target;if(!e||!e.getAttribute||e.getAttribute("data-r")==null)return null;g=+e.getAttribute("data-r"),v=+e.getAttribute("data-c")}else if(this._active)g=this._active[0],v=this._active[1];else return null;return!w.rows[g]||!w.cols[v]||w.rows[g].other||w.cols[v].other?null:{row:w.rows[g].label,column:w.cols[v].label}},W.prototype._annotationLabel=function(h){return[h.row,h.column].filter(Boolean).join(" \xD7 ")},Y.VeyHeatmap={version:Ct,create:function(h,w){return new W(h,w)},registerTheme:function(h,w){if(!h||typeof h!="string")throw new Error("VeyHeatmap: registerTheme needs a name.");return Mt[h]=At(w||{}),Mt[h]},getTheme:function(h){return At(h)},listThemes:function(){return Object.keys(Mt)}}})(typeof window<"u"?window:void 0);(function(Y){"use strict";var Ct="1.0.0",kt="http://www.w3.org/2000/svg",St=0,_t={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},Mt={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"}},At={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},ft={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 wt(e){for(var r=1;r<arguments.length;r++){var i=arguments[r];if(i)for(var u in i)Object.prototype.hasOwnProperty.call(i,u)&&(e[u]=i[u])}return e}var bt={};function ot(e){bt[e]||(bt[e]=1,Y.console&&console.warn&&console.warn("VeyRiskTornado: "+e))}function V(e){throw new Error("VeyRiskTornado: "+e)}function pt(e,r,i){return Math.min(i,Math.max(r,e))}function Rt(e,r){return String(e).replace(/\{(\w+)\}/g,function(i,u){return r[u]!=null?r[u]:i})}function $t(e){return e=String(e),/^[A-Z0-9]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1)}function ae(e){return typeof e=="number"?e:e==null||e===""?NaN:+e}function dt(e,r,i){var u=document.createElementNS(kt,e);if(r)for(var c in r)r[c]!=null&&u.setAttribute(c,r[c]);return i&&i.appendChild(u),u}function I(e,r,i){var u=document.createElement(e);return r&&(u.className=r),i&&i.appendChild(u),u}var J=null;function et(e,r,i,u){if(!J){var c=document.createElement("canvas");J=c.getContext&&c.getContext("2d")}return J?(J.font=(i||400)+" "+r+"px "+u,J.measureText(String(e)).width):String(e).length*r*.6}function ht(e,r,i,u,c){if(e=String(e),et(e,i,u,c)<=r)return e;for(;e.length>2&&et(e+"\u2026",i,u,c)>r;)e=e.slice(0,-1);return e.replace(/\s+$/,"")+"\u2026"}function Ft(e){var r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(String(e||"").trim());if(!r)return null;var i=r[1].length===3?r[1].replace(/./g,"$&$&"):r[1],u=parseInt(i,16);return[u>>16&255,u>>8&255,u&255]}function yt(e){var r=e.map(function(i){return i/=255,i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4)});return .2126*r[0]+.7152*r[1]+.0722*r[2]}function Dt(e,r){var i=Ft(e),u=Ft(r);if(!i||!u)return 21;var c=yt(i),p=yt(u);return(Math.max(c,p)+.05)/(Math.min(c,p)+.05)}function it(e,r,i){var u=Ft(e),c=Ft(r);if(!u||!c||Dt(e,r)>=i)return e;for(var p=yt(c)>.4,_=0,t=e;_<=1&&Dt(t,r)<i;)_+=.05,t="#"+u.map(function(n){var a=p?n*(1-_):n+(255-n)*_;return("0"+Math.round(a).toString(16)).slice(-2)}).join("");return t}function xt(e,r){var i=e.decimals!=null?e.decimals:0,u=e.ratioDecimals!=null?e.ratioDecimals:1,c=e.prefix||"",p=e.suffix||"",_={},t=e.negatives==="brackets";function n(f){return _[f]||(_[f]=new Intl.NumberFormat(r||void 0,{minimumFractionDigits:f,maximumFractionDigits:f})),_[f]}function a(f,b){if(f==null||!isFinite(f))return"\u2013";b==null&&(b=i);var k=Number(f.toFixed(b)),y=c+n(b).format(Math.abs(k))+p;return k>=0?y:t?"("+y+")":"\u2212"+y}function l(f,b){var k=a(f,b);return f!=null&&Number(f.toFixed(b??i))>0?"+"+k:k}function o(f,b){return f==null||!isFinite(f)?"\u2013":(f<0?"\u2212":"")+n(b??u).format(Math.abs(f)*100)+"%"}function s(f,b){if(f==null||!isFinite(f))return"\u2013";var k=b??Math.max(u,1),y=Number((f*100).toFixed(k));return(y>0?"+":y<0?"\u2212":"")+n(k).format(Math.abs(y))+" pp"}function m(f,b){return f==null||!isFinite(f)?"\u2013":n(b??1).format(f*100)+"%"}return{value:a,signed:l,ratio:o,pp:s,percent:m,nf:n}}function ut(e,r){var i=ae(e);return isFinite(i)||V(r+" must be a number."),i}function vt(e,r){var i=ut(e,r);return(i<-1||i>1)&&V(r+" must be between \u22121 and 1."),i}function Zt(e,r,i){var u=e.factors;(!Array.isArray(u)||!u.length)&&V("data.factors must be a non-empty array of risk factors.");var c={};return u.map(function(p,_){(!p||typeof p!="object")&&V("data.factors["+_+"] is not an object."),p.key==null&&p.label==null&&V("data.factors["+_+"] needs a key or a label.");var t=String(p.key!=null?p.key:p.label),n='factor "'+t+'"';c[t]&&V(n+" is used twice."),c[t]=1;var a=p.group!=null?String(p.group):"Other",l=p.shockDown!=null?ut(p.shockDown,n+": shockDown"):p.shock!=null?-Math.abs(ut(p.shock,n+": shock")):null,o=p.shockUp!=null?ut(p.shockUp,n+": shockUp"):p.shock!=null?Math.abs(ut(p.shock,n+": shock")):null,s,m,f;if(p.delta!=null){var b=ut(p.delta,n+": delta"),k=p.gamma!=null?ut(p.gamma,n+": gamma"):0;(l==null||o==null)&&V(n+": delta needs shockDown and shockUp (or shock).");var y=l*r,x=o*r;s=b*y+.5*k*y*y,m=b*x+.5*k*x*x,f="taylor"}else{(p.down==null||p.up==null)&&V(n+" needs down and up impacts, or delta (and gamma) with a shock.");var M=ut(p.down,n+": down"),d=ut(p.up,n+": up");if(r===1)s=M,m=d;else{var T=(d-M)/2,C=(d+M)/2;s=-T*r+C*r*r,m=T*r+C*r*r}f="revaluation"}var R=1;return i&&(i[t]!=null&&(R*=ut(i[t],"whatIf."+t)),i[a]!=null&&a!==t&&(R*=ut(i[a],"whatIf."+a))),{key:t,label:p.label!=null?String(p.label):t,group:a,unit:p.unit!=null?String(p.unit):"",shockDown:l==null?null:l*r,shockUp:o==null?null:o*r,down:s*R,up:m*R,source:f,index:_}})}function Tt(e,r,i){var u=e.length,c=new Array(u),p,_;if(r&&r.matrix){var t=r.matrix;for(p=0;p<u;p++){var n=0,a=t[p];for(_=0;_<u;_++)n+=(p===_?1:a[_])*i[_];c[p]=n}return c}var l=r?r.within:0,o=r?r.across:0,s={},m=0;for(p=0;p<u;p++)s[e[p].group]=(s[e[p].group]||0)+i[p],m+=i[p];for(p=0;p<u;p++){var f=s[e[p].group];c[p]=i[p]+l*(f-i[p])+o*(m-f)}return c}function Jt(e,r){var i=e.correlation;if(i==null)return null;if(typeof i!="object"&&V("data.correlation must be { within, across } or { matrix }."),i.matrix){var u=i.matrix;return(!Array.isArray(u)||u.length!==r||u.some(function(c){return!Array.isArray(c)||c.length!==r}))&&V("data.correlation.matrix must be square with one row per factor."),u.forEach(function(c,p){c.forEach(function(_,t){vt(_,"data.correlation.matrix["+p+"]["+t+"]")})}),{matrix:u}}return{within:i.within!=null?vt(i.within,"data.correlation.within"):0,across:i.across!=null?vt(i.across,"data.correlation.across"):0}}function Ht(e,r){r=r||{},(!e||typeof e!="object")&&V("data is required.");var i=r.shockScale!=null?ut(r.shockScale,"shockScale"):1;i>0||V("shockScale must be more than 0.");var u=r.whatIf&&Object.keys(r.whatIf).length?r.whatIf:null,c=Zt(e,i,u),p=c.length;u&&Object.keys(u).forEach(function(S){c.some(function(A){return A.key===S||A.group===S})||ot('whatIf: there is no factor or group "'+S+'", so it changes nothing.')});var _=e.higherIsBetter!==!1,t=function(S){return _?-S:S},n=e.limit!=null?Math.abs(ut(e.limit,"data.limit")):null,a=Jt(e,p),l=c.map(function(S){return(S.up-S.down)/2}),o=Tt(c,a,l),s=0,m;for(m=0;m<p;m++)s+=l[m]*o[m];var f=Math.sqrt(Math.max(0,s)),b=0,k=0,y=0,x=0;c.forEach(function(S,A){S.swing=Math.abs(S.up-S.down),S.linear=l[A],S.convexity=(S.up+S.down)/2,S.asymmetry=Math.abs(S.linear)+Math.abs(S.convexity)>0?Math.abs(S.convexity)/(Math.abs(S.linear)+Math.abs(S.convexity)):0,S.worst=t(S.down)>=t(S.up)?"down":"up",S.worstValue=S[S.worst],S.best=S.worst==="down"?"up":"down",S.breach=n!=null&&t(S.worstValue)>n+1e-12*Math.max(1,n),S.standalone=Math.abs(l[A]),S.contribution=f>0?l[A]*o[A]/f:0,b+=S.swing,k+=S.down,y+=S.up,x+=S.standalone});var M=c.slice().sort(r.sort==="worst"?function(S,A){return t(A.worstValue)-t(S.worstValue)||S.index-A.index}:function(S,A){return A.swing-S.swing||S.index-A.index}),d=0;M.forEach(function(S,A){S.rank=A+1,S.share=b>0?S.swing/b:0,d+=S.share,S.cumShare=d});var T={},C=[];c.forEach(function(S,A){var H=T[S.group];H||(H=T[S.group]={key:S.group,label:S.group,factors:[],idx:[],down:0,up:0,contribution:0,standaloneSum:0},C.push(H)),H.factors.push(S.key),H.idx.push(A),H.down+=S.down,H.up+=S.up,H.contribution+=S.contribution,H.standaloneSum+=S.standalone}),C.forEach(function(S){S.swing=Math.abs(S.up-S.down),S.linear=(S.up-S.down)/2,S.convexity=(S.up+S.down)/2,S.worst=t(S.down)>=t(S.up)?"down":"up",S.worstValue=S[S.worst],S.breach=n!=null&&t(S.worstValue)>n+1e-12*Math.max(1,n),S.share=b>0?S.swing/b:0;for(var A=S.idx.map(function(q){return c[q]}),H=S.idx.map(function(q){return l[q]}),lt=a&&a.matrix?{matrix:S.idx.map(function(q){return S.idx.map(function(X){return a.matrix[q][X]})})}:a,tt=Tt(A,lt,H),D=0,K=0;K<H.length;K++)D+=H[K]*tt[K];S.standalone=Math.sqrt(Math.max(0,D)),delete S.idx});var R=p>=10?5:Math.max(1,Math.ceil(p/2)),O=M.slice(0,R).reduce(function(S,A){return S+A.share},0),j={factors:c,order:M,groups:C,higherIsBetter:_,limit:n,base:e.base!=null?ut(e.base,"data.base"):null,totalSwing:b,sumDown:k,sumUp:y,sigma:f,standalone:x,diversification:x-f,correlated:!!a,topN:R,topShare:O,breaches:c.filter(function(S){return S.breach}).length,shockScale:i,whatIf:u};if(j.worstFactor=c.slice().sort(function(S,A){return t(A.worstValue)-t(S.worstValue)||S.index-A.index})[0],e.joint&&(e.joint.down!=null||e.joint.up!=null)&&(i===1&&!u?(j.joint={down:e.joint.down!=null?ut(e.joint.down,"data.joint.down"):null,up:e.joint.up!=null?ut(e.joint.up,"data.joint.up"):null},j.interaction={down:j.joint.down!=null?j.joint.down-k:null,up:j.joint.up!=null?j.joint.up-y:null}):j.jointHidden=!0),u){var E=Ht(e,{shockScale:i,sort:r.sort});j.baseline={totalSwing:E.totalSwing,sigma:E.sigma,worstValue:E.worstFactor.worstValue,worstFactor:E.worstFactor.key}}return j}function te(){if(!document.getElementById("vtr-styles")){var e=".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}}",r=I("style");r.id="vtr-styles",r.textContent=e,(document.head||document.documentElement).appendChild(r)}}function Vt(e){var r;(e==null||e==="")&&(e="veyforma"),typeof e=="string"?(Mt.hasOwnProperty(e)||(ot('Unknown theme "'+e+'". The "veyforma" theme is used instead.'),e="veyforma"),r=wt({},_t,Mt[e])):typeof e=="object"?(r=wt(e.extends?Vt(e.extends):wt({},_t),e),delete r.extends):(ot("The theme option must be a theme name or an object."),r=wt({},_t));var i=/^#/.test(r.background)?r.background:"#ffffff",u=/^#/.test(r.cardBackground)?r.cardBackground:i;return["axisText","mutedText"].forEach(function(c){r[c]=it(r[c],i,4.5)}),r.cardMuted=it(r.mutedText,u,4.5),r.hedgeText=it(it(r.hedge,i,4.5),u,4.5),r.limitText=it(it(r.limit,i,4.5),u,4.5),r.accentText=it(r.accent,i,4.5),r}function W(e,r){var i=typeof e=="string"?document.querySelector(e):e;(!i||i.nodeType!==1)&&V("container not found ("+e+")."),(!r||!r.data)&&V("options.data is required."),te(),this.id=++St,this.container=i,this.options=wt({},At,r),this.element=I("div","vtr"),this.element.setAttribute("role","figure"),this.summaryEl=I("div","vtr-summary",this.element),this.scopeEl=I("p","vtr-scope",this.element),this.legendEl=I("div","vtr-legend",this.element),this.plotHost=I("div","vtr-plot-host",this.element),this.tipEl=I("div","vtr-tip",this.element),this.tipEl.setAttribute("role","tooltip"),i.appendChild(this.element),this._animateNext=!!this.options.animate,this._lastWidth=0,this._active=-1;var u=this;Y.ResizeObserver?(this._observer=new Y.ResizeObserver(function(){var c=Math.round(u.element.clientWidth);c&&Math.abs(c-u._lastWidth)>1&&u.redraw()}),this._observer.observe(this.element)):(this._onResize=function(){u.redraw()},Y.addEventListener("resize",this._onResize)),this._onDocTap=function(c){u.element.contains(c.target)||u._hideTip()},document.addEventListener("pointerdown",this._onDocTap),this.redraw(),this.options.toolbar!==!1&&Y.VeyformaToolkit&&(this.toolkit=Y.VeyformaToolkit.attach(this,this.options.toolbar))}W.prototype.update=function(e){return e?(e.data&&e.data!==this.options.data&&this.options.animate&&(this._animateNext=!0),e.view&&e.view!==this.options.view&&this.options.animate&&(this._animateNext=!0),wt(this.options,e),this.redraw()):this},W.prototype.setData=function(e){return this._res=null,this.update({data:e})},W.prototype.setView=function(e){return this.update({view:e})},W.prototype.setTheme=function(e){return this.update({theme:e})},W.prototype.getTheme=function(){return Vt(this.options.theme)},W.prototype._opts=function(){return{shockScale:this.options.shockScale,whatIf:this.options.whatIf,sort:this.options.sort}},W.prototype.getResult=function(){return Ht(this.options.data,this._opts())},W.prototype.getFactor=function(e){return this.getResult().factors.filter(function(r){return r.key===String(e)})[0]||null},W.prototype.setWhatIf=function(e){return this.update({whatIf:e})},W.prototype.setShockScale=function(e){return this.update({shockScale:e})},W.prototype._labels=function(){return wt({},ft,this.options.labels)},W.prototype.destroy=function(){this.toolkit&&this.toolkit.destroy&&this.toolkit.destroy(),this._observer&&this._observer.disconnect(),this._onResize&&Y.removeEventListener("resize",this._onResize),document.removeEventListener("pointerdown",this._onDocTap),this.element.parentNode&&this.element.parentNode.removeChild(this.element)},W.prototype._hideTip=function(){this.tipEl.classList.remove("vtr-on"),this._hlEl&&this._hlEl.setAttribute("opacity",0)},W.prototype._placeTip=function(e,r,i){var u=this.tipEl;u.textContent="",e.forEach(function(l,o){o&&u.appendChild(document.createElement("br"));var s=o===0?document.createElement("b"):document.createElement("span");s.textContent=l,u.appendChild(s)});var c=this.element.getBoundingClientRect(),p=i&&i.clientX?i.clientX:r.left+r.width/2,_=i&&i.clientY?i.clientY:r.top+10;u.classList.add("vtr-on");var t=u.offsetWidth,n=u.offsetHeight;u.style.left=pt(p-c.left-t/2,4,Math.max(4,c.width-t-4))+"px";var a=_-c.top-n-14;a<0&&(a=_-c.top+18),u.style.top=a+"px"};function It(e,r,i){r>e||(r=e+1);var u=r-e,c=Math.pow(10,Math.floor(Math.log(u/i)/Math.LN10)),p=u/i/c;p>=7.5?c*=10:p>=3.5?c*=5:p>=1.5&&(c*=2);for(var _=Math.floor(e/c+1e-9)*c,t=Math.ceil(r/c-1e-9)*c,n=[],a=_;a<=t+c/2;a+=c)n.push(Math.round(a/c)*c);return{lo:_,hi:t,ticks:n,step:c}}function h(e,r,i,u,c){var p=dt("text",wt({x:r,y:i},c||{}),e);return p.textContent=u,p}W.prototype._bindInteraction=function(e,r,i,u,c,p){var _=this,t=this._items,n=this.options;function a(o){for(var s=e.getBoundingClientRect(),m=(o.clientX-s.left)*(r/s.width),f=(o.clientY-s.top)*(i/s.height),b=0;b<t.length;b++){var k=t[b];if(m>=k.x&&m<=k.x+k.w&&f>=k.y&&f<=k.y+k.h)return b}return-1}function l(o,s){if(o<0){_._hideTip();return}_._active=o;var m=t[o],f=_._hlEl;f.setAttribute("x",m.x-4),f.setAttribute("y",m.y),f.setAttribute("width",m.w+8),f.setAttribute("height",m.h),f.setAttribute("opacity",1);var b=e.getBoundingClientRect(),k=b.width/r,y={left:b.left+m.px*k,top:b.top+m.py*(b.height/i),width:0,height:0};_._placeTip(_._tipLines(m),y,s&&s.clientX?s:null)}e.addEventListener("pointermove",function(o){l(a(o),o)}),e.addEventListener("pointerleave",function(){_._hideTip()}),e.addEventListener("click",function(o){var s=a(o);s>=0&&typeof n.onItemClick=="function"&&n.onItemClick(_._detail(t[s]),o)}),e.addEventListener("keydown",function(o){var s=_._active;if(o.key==="ArrowRight"||o.key==="ArrowDown")s=Math.min(t.length-1,s+1);else if(o.key==="ArrowLeft"||o.key==="ArrowUp")s=Math.max(0,s<0?0:s-1);else if(o.key==="Home")s=0;else if(o.key==="End")s=t.length-1;else if(o.key==="Escape"){_._hideTip();return}else if((o.key==="Enter"||o.key===" ")&&s>=0){typeof n.onItemClick=="function"&&n.onItemClick(_._detail(t[s]),o),o.preventDefault();return}else return;o.preventDefault(),l(s,null)}),e.addEventListener("blur",function(){_._hideTip()})},W.prototype.createTable=function(){var e=this.getExportData(),r=I("div","vtr-tables");return e.sheets.forEach(function(i){if(i.name!=="Notes"){var u=I("table","vtr-table",r);I("caption",null,u).textContent=i.name;var c=I("tr",null,I("thead",null,u));i.columns.forEach(function(_){var t=I("th",null,c);t.scope="col",t.textContent=_.label});var p=I("tbody",null,u);i.text.forEach(function(_,t){var n=I("tr",i.flag&&i.flag[t]?"vtr-breach":null,p);_.forEach(function(a,l){var o=I(l?"td":"th",null,n);l||(o.scope="row"),o.textContent=a})})}}),r};function w(e,r,i){if(e==null||!isFinite(e))return"";var u=Number(Math.abs(e).toFixed(4)).toLocaleString(i||void 0,{maximumFractionDigits:4});return(e>0?"+":e<0?"\u2212":"")+u+(r?r==="%"?"%":" "+r:"")}W.prototype.redraw=function(){var e=this.options,r=e.data,i=this._labels(),u=this._res=Ht(r,this._opts()),c=Vt(e.theme),p=xt(r,e.locale),_=this.element,t=_.style,n=c.fontFamily==="inherit"?Y.getComputedStyle?Y.getComputedStyle(this.container).fontFamily:"sans-serif":c.fontFamily,a=c.background&&c.background!=="transparent",l=a?c.background:"#ffffff";t.setProperty("--vtr-text",c.text),t.setProperty("--vtr-muted",c.mutedText),t.setProperty("--vtr-bg",a?c.background:"transparent"),t.setProperty("--vtr-font",n),t.setProperty("--vtr-card",c.cardBackground),t.setProperty("--vtr-card-muted",c.cardMuted),t.setProperty("--vtr-tip-bg",c.tooltipBackground),t.setProperty("--vtr-tip-text",c.tooltipText),t.setProperty("--vtr-focus",c.focus),t.setProperty("--vtr-hedge",c.limitText),_.classList.toggle("vtr-filled",!!a),_.setAttribute("aria-label",e.ariaLabel||r.title||"Risk-factor tornado");var o=e.view;["factors","groups","contribution"].indexOf(o)<0&&(ot('Unknown view "'+o+'". The factor view is shown instead.'),o="factors"),e.sort!=="swing"&&e.sort!=="worst"&&ot('Unknown sort "'+e.sort+'". Factors are ranked by swing instead.'),this._view=o,this._renderSummary(u,p,i);var s=[i[o],e.shockScale!=null&&+e.shockScale!=1?"shocks \xD7"+ +e.shockScale:null,r.unit||null,u.whatIf?i.whatIf+" applied":null].filter(Boolean).join(" \xB7 ");this.scopeEl.textContent=s,this._renderLegend(o,c,i,u);var m=Math.max(280,Math.round(this.plotHost.clientWidth||_.clientWidth||720));this._lastWidth=Math.round(_.clientWidth);var f=c.fontSize||12;this.plotHost.textContent="";var b=dt("svg",{class:"vtr-plot",role:"img",tabindex:0,"font-family":n},this.plotHost);b.style.fontSize=f+"px";var k=this._animateNext&&e.animate;this._animateNext=!1,k&&b.classList.add("vtr-animate");var y={svg:b,W:m,fs:f,theme:c,f:p,L:i,family:n,bg:l,res:u,items:[],points:{}},x=o==="contribution"?this._drawContribution(y):this._drawRows(y,o);return b.setAttribute("viewBox","0 0 "+m+" "+x),b.setAttribute("width",m),b.setAttribute("height",x),b.setAttribute("aria-label",(e.ariaLabel||r.title||"Risk-factor tornado")+". "+this.describe()),this._items=y.items,this._points=y.points,this._hlEl=dt("rect",{x:0,y:0,width:0,height:0,rx:4,fill:c.text,"fill-opacity":.06,opacity:0,"pointer-events":"none"},b),b.insertBefore(this._hlEl,b.firstChild),this._bindInteraction(b,m,x,c,i,p),this},W.prototype._shockNames=function(){var e=this._labels(),r=this.options.data.shockLabels||{};return{down:r.down||e.down,up:r.up||e.up}},W.prototype._renderSummary=function(e,r,i){var u=this.summaryEl,c=this.options;if(u.textContent="",u.style.display=c.summary===!1?"none":"",c.summary===!1)return;function p(a,l,o,s){var m=I("div","vtr-stat",u);I("div","k",m).textContent=a,I("div",s?"v vtr-wrap":"v",m).textContent=l,o&&(I("div","n",m).textContent=o)}var _=this._shockNames(),t=e.order[0],n=e.worstFactor;p(i.largest,t.label,i.swing.toLowerCase()+" "+r.value(t.swing)+" \xB7 "+r.percent(t.share,0)+" of the total",!0),p(i.worstShock,r.signed(n.worstValue),n.label+", "+_[n.worst].toLowerCase()+(e.limit!=null?e.breaches?" \xB7 "+e.breaches+" beyond the limit":" \xB7 within the limit":"")+(e.baseline?" \xB7 was "+r.signed(e.baseline.worstValue):"")),p(Rt(i.topShare,{n:e.topN}),r.percent(e.topShare,0),"of the total swing across "+e.factors.length+" factors"),p(i.combined,"\xB1"+r.value(e.sigma),e.baseline?i.whatIf+": was \xB1"+r.value(e.baseline.sigma):e.correlated?e.standalone>0?r.percent(e.diversification/e.standalone,0)+" below the sum of stand-alone moves":"":"factors treated as independent"),Array.prototype.forEach.call(u.querySelectorAll(".vtr-stat .v"),function(a){a.style.fontSize="";for(var l=parseFloat(Y.getComputedStyle?Y.getComputedStyle(a).fontSize:19)||19;a.scrollWidth>a.clientWidth&&l>12;)l-=1,a.style.fontSize=l+"px"})},W.prototype._renderLegend=function(e,r,i,u){var c=this.legendEl,p=this._shockNames();c.textContent="",c.style.display=this.options.legend===!1?"none":"";function _(t,n,a){var l=I("span",null,c),o=I("i",a||null,l);a==="vtr-ring"?o.style.borderColor=t:o.style.background=t,l.appendChild(document.createTextNode(n))}if(e==="contribution"){_(r.contribution,i.contributionAdds),_(r.hedge,i.hedge),_(r.convexity,i.standalone,"vtr-ring");return}_(r.down,p.down),_(r.up,p.up),u.factors.some(function(t){return t.asymmetry>=.1})&&_(r.convexity,i.convexity+" (midpoint)","vtr-ring"),u.limit!=null&&_(r.limit,i.limit,"vtr-tick")};function g(e,r){var i=Math.min(Math.max.apply(null,r.map(function(c){return et(c,e.fs,600,e.family)}))+12,e.W*.34),u=e.W-i<260;return{nameW:u?0:i,narrow:u}}function v(e,r,i,u,c,p,_,t,n){var a=e.theme,l=e.fs,o=e.family,s=e.W,m=e.f,f=-1/0,b=Math.max.apply(null,i.ticks.map(function(y){return et(m.value(y),l-1,400,o)})),k=Math.max(1,Math.ceil((b+10)/((_-p)/Math.max(1,i.ticks.length-1))));i.ticks.forEach(function(y,x){if(dt("line",{x1:u(y),x2:u(y),y1:t,y2:n,stroke:y===0?a.axis:a.grid,"stroke-width":y===0?1.2:1},r),!(x%k)){var M=m.value(y),d=et(M,l-1,400,o),T=d/2,C=u(y),R=C-T<0?"start":C+T>s?"end":"middle",O=R==="start"?C:R==="end"?C-d:C-T;O<f+8||(f=O+d,h(r,C,c+l,M,{"text-anchor":R,fill:a.axisText,"font-size":l-1,class:"vtr-tick"}))}})}W.prototype._rowsFor=function(e,r,i){if(r==="groups")return e.groups.slice().sort(function(a,l){return l.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 u=+this.options.top>0?Math.floor(+this.options.top):e.order.length,c=e.order.slice(0,u).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}}),p=e.order.slice(u);if(p.length){var _=0,t=0,n=0;p.forEach(function(a){_+=a.down,t+=a.up,n+=a.swing}),c.push({kind:"other",obj:{count:p.length,down:_,up:t,swing:n,share:e.totalSwing>0?n/e.totalSwing:0,factors:p},name:Rt(i.other,{n:p.length}),down:_,up:t,breach:!1,convexity:(_+t)/2,asym:0})}return c},W.prototype._drawRows=function(e,r){var i=e.res,u=e.theme,c=e.f,p=e.L,_=e.fs,t=e.family,n=e.W,a=e.svg,l=i.higherIsBetter,o=this._rowsFor(i,r,p),s=g(e,o.map(function(F){return F.name})),m=i.limit!=null?l?-i.limit:i.limit:null,f=[];o.forEach(function(F){f.push(F.down,F.up)});var b=Math.min.apply(null,f.concat([0,m??0])),k=Math.max.apply(null,f.concat([0,m??0])),y=function(F){return et(c.signed(F),_-1,600,t)+6},x=Math.max.apply(null,[4].concat(f.filter(function(F){return F<0}).map(y))),M=Math.max.apply(null,[4].concat(f.filter(function(F){return F>=0}).map(y))),d=s.nameW+x,T=n-M,C=It(b,k,Math.max(2,Math.min(6,Math.floor((T-d)/90)))),R=function(F){return d+(pt(F,C.lo,C.hi)-C.lo)/(C.hi-C.lo)*(T-d)},O=4,j=Math.max(36,_*3),E=s.narrow?_+4:0,S=O+_+6,A=S+o.length*(j+E),H=dt("g",{class:"vtr-rows"},a);v(e,H,C,R,O,d,T,S,A);var lt=dt("g",null,H),tt=dt("g",{class:"vtr-cvx-layer"},H),D=dt("g",null,H);m!=null&&dt("line",{x1:R(m),x2:R(m),y1:S-2,y2:A,stroke:u.limit,"stroke-width":1.6,"stroke-dasharray":"5 3",class:"vtr-limit"},tt);var K=this._shockNames(),q=this;o.forEach(function(F,B){var U=S+B*(j+E)+E,nt=Math.max(j*.32,_),st=U+(j-2*nt-3)/2,at=F.breach?u.limitText:F.kind==="other"?u.mutedText:u.text,zt=ht(F.name,s.narrow?n:s.nameW-8,_,F.kind==="other"?400:600,t);if(s.narrow&&dt("rect",{x:0,y:U-3-_*.95,width:et(zt,_,600,t)+4,height:_*1.25,fill:e.bg,class:"vtr-lbg"},D),h(D,0,s.narrow?U-3:U+j/2+_*.35,ht(F.name,s.narrow?n:s.nameW-8,_,F.kind==="other"?400:600,t),{fill:at,"font-size":_,"font-weight":F.kind==="other"?400:600,class:"vtr-name"}),[["down",st],["up",st+nt+3]].forEach(function(jt){var rt=F[jt[0]],Wt=R(Math.min(0,rt)),Kt=R(Math.max(0,rt)),ee=F.kind!=="other"&&F.obj.worst===jt[0];dt("rect",{x:Wt,y:jt[1],width:Math.max(.8,Kt-Wt),height:nt,rx:2,fill:u[jt[0]],class:"vtr-grow vtr-bar","data-shock":jt[0]},lt);var ne=F.breach&&ee,oe=c.signed(rt),Xt=et(oe,_-1,ne?700:400,t),ce=rt<0?Wt-4-Xt:Kt+4;dt("rect",{x:ce-2,y:jt[1]+nt/2-(_-1)*.6,width:Xt+4,height:(_-1)*1.2,fill:e.bg,class:"vtr-lbg"},D),h(D,rt<0?Wt-4:Kt+4,jt[1]+nt/2+(_-1)*.35,c.signed(rt),{"text-anchor":rt<0?"end":"start",fill:ne?u.limitText:u.text,"font-size":_-1,"font-weight":ne?700:400,class:"vtr-val"})}),F.asym>=.1){var mt=R(F.convexity),gt=st+nt+1.5;dt("path",{d:"M"+mt+","+(gt-4)+"L"+(mt+4)+","+gt+"L"+mt+","+(gt+4)+"L"+(mt-4)+","+gt+"Z",fill:e.bg,stroke:u.convexity,"stroke-width":1.5,class:"vtr-cvx"},tt)}var Et=R(Math.max(0,F.down,F.up));F.kind==="factor"&&(e.points[F.obj.key]={x:Et,y:st}),F.kind==="group"&&(e.points["group:"+F.obj.key]={x:Et,y:st}),e.items.push({kind:F.kind,obj:F.obj,x:0,y:U-E,w:n,h:j+E,px:Et,py:st})}),r==="groups"&&i.factors.forEach(function(F){e.points[F.key]||(e.points[F.key]=e.points["group:"+F.group])});var X=[];if(m!=null&&X.push(p.limit+" "+c.signed(m)+(i.breaches?": "+i.breaches+" factor"+(i.breaches>1?"s":"")+" beyond it":": no factor beyond it")),r==="factors"){var Q=o.filter(function(F){return F.kind==="factor"}).length;if(X.push("Each factor shocked alone"+(Q<i.factors.length?"; top "+Q+" of "+i.factors.length+", the rest summed":"")),i.interaction){var Z=i.interaction,P=[];Z.down!=null&&P.push(K.down.toLowerCase()+" together "+c.signed(i.joint.down)+" vs sum "+c.signed(i.sumDown)),Z.up!=null&&P.push(K.up.toLowerCase()+" together "+c.signed(i.joint.up)+" vs sum "+c.signed(i.sumUp)),X.push("All factors "+P.join(", "))}}else X.push("Every factor in the group shocked the same way at once (sum of single shocks)");var N=A+_+8;return X.forEach(function(F){h(a,0,N,ht(F+".",n,_-1,400,t),{fill:u.mutedText,"font-size":_-1,class:"vtr-note"}),N+=_+3}),Math.ceil(N-_+6)},W.prototype._drawContribution=function(e){var r=e.res,i=e.theme,u=e.f,c=e.L,p=e.fs,_=e.family,t=e.W,n=e.svg,a=r.factors.slice().sort(function(D,K){return Math.abs(K.contribution)-Math.abs(D.contribution)||D.index-K.index}),l=+this.options.top>0?Math.floor(+this.options.top):a.length,o=a.slice(l),s=a.slice(0,l).sort(function(D,K){return K.contribution-D.contribution}).map(function(D){return{kind:"factor",obj:D,name:D.label,v:D.contribution,k:D.standalone}});if(o.length){var m=0,f=0;o.forEach(function(D){m+=D.contribution,f+=D.standalone}),s.push({kind:"other",obj:{count:o.length,contribution:m,standalone:f,factors:o},name:Rt(c.other,{n:o.length}),v:m,k:null})}var b=g(e,s.map(function(D){return D.name})),k=Math.max.apply(null,s.map(function(D){return et(u.signed(D.v),p,700,_)}))+10,y=b.nameW,x=t-k,M=Math.max(24,p*2),d=b.narrow?p+4:0,T=4,C=Math.min(0,Math.min.apply(null,s.map(function(D){return D.v}))),R=Math.max.apply(null,s.map(function(D){return Math.max(D.v,D.k||0)}))||1,O=It(C,R,Math.max(2,Math.min(6,Math.floor((x-y)/90)))),j=function(D){return y+(pt(D,O.lo,O.hi)-O.lo)/(O.hi-O.lo)*(x-y)},E=T+p+6,S=E+s.length*(M+d),A=dt("g",{class:"vtr-contrib"},n);v(e,A,O,j,T,y,x,E,S),s.forEach(function(D,K){var q=E+K*(M+d)+d,X=M*.56,Q=q+(M-X)/2,Z=D.v<0;h(A,0,b.narrow?q-3:Q+X/2+p*.35,ht(D.name,b.narrow?t-k:b.nameW-8,p,D.kind==="other"?400:600,_),{fill:D.kind==="other"?i.mutedText:i.text,"font-size":p,"font-weight":D.kind==="other"?400:600,class:"vtr-name"});var P=j(Math.min(0,D.v)),N=j(Math.max(0,D.v));if(dt("rect",{x:P,y:Q,width:Math.max(.8,N-P),height:X,rx:2,fill:Z?i.hedge:i.contribution,class:"vtr-grow vtr-cbar"+(Z?" vtr-hedge":"")},A),D.k!=null){var F=j(D.k),B=Q+X/2;dt("path",{d:"M"+F+","+(B-5)+"L"+(F+5)+","+B+"L"+F+","+(B+5)+"L"+(F-5)+","+B+"Z",fill:e.bg,stroke:i.convexity,"stroke-width":1.6,class:"vtr-sa"},A)}h(A,t,Q+X/2+p*.35,u.signed(D.v),{"text-anchor":"end",fill:Z?i.hedgeText:i.text,"font-size":p,"font-weight":700,class:"vtr-val"}),D.kind==="factor"&&(e.points[D.obj.key]={x:Z?P:N,y:Q}),e.items.push({kind:D.kind,obj:D.obj,contrib:!0,x:0,y:q-d,w:t,h:M+d,px:Z?P:N,py:Q})});var H=r.correlated?this.options.data.correlation.matrix?"with the correlation matrix given":"with correlations of "+u.percent(this.options.data.correlation.within||0,0)+" within groups and "+u.percent(this.options.data.correlation.across||0,0)+" across":"no correlations given, so factors are treated as independent and none can hedge another",lt=["Shares add up to the combined move of \xB1"+u.value(r.sigma)+"; stand-alone moves add up to "+u.value(r.standalone),"Combined "+H],tt=S+p+8;return lt.forEach(function(D){h(n,0,tt,ht(D+".",t,p-1,400,_),{fill:i.mutedText,"font-size":p-1,class:"vtr-note"}),tt+=p+3}),Math.ceil(tt-p+6)},W.prototype._tipLines=function(e){var r=this.options,i=xt(r.data,r.locale),u=this._labels(),c=this._res,p=this._shockNames(),_=r.locale,t=function(s){return c.base!=null?" \u2192 "+i.value(c.base+s):""};if(e.kind==="other"){var n=e.obj;return e.contrib?[Rt(u.other,{n:n.count}),"Shares together "+i.signed(n.contribution)]:[Rt(u.other,{n:n.count}),p.down+" (sum) "+i.signed(n.down),p.up+" (sum) "+i.signed(n.up),u.swing+" together "+i.value(n.swing)+" ("+i.percent(n.share,0)+" of the total)"]}if(e.kind==="group"){var a=e.obj;return[a.label+" \xB7 "+a.factors.length+" factor"+(a.factors.length>1?"s":""),p.down+" "+i.signed(a.down)+t(a.down),p.up+" "+i.signed(a.up)+t(a.up),u.swing+" "+i.value(a.swing)+" ("+i.percent(a.share,0)+" of the total)","Combined move of the group \xB1"+i.value(a.standalone)+" \xB7 share of the total \xB1"+i.value(c.sigma)+": "+i.signed(a.contribution)].concat(a.breach?[u.worst+" beyond the limit"]:[])}var l=e.obj,o=[l.label,l.group+" \xB7 rank "+l.rank+" of "+c.factors.length,p.down+(l.shockDown!=null?" ("+w(l.shockDown,l.unit,_)+")":"")+" "+i.signed(l.down)+t(l.down),p.up+(l.shockUp!=null?" ("+w(l.shockUp,l.unit,_)+")":"")+" "+i.signed(l.up)+t(l.up),u.swing+" "+i.value(l.swing)+" \xB7 "+i.percent(l.share,0)+" of the total (top "+l.rank+": "+i.percent(l.cumShare,0)+")",u.linear+" \xB1"+i.value(Math.abs(l.linear))+" \xB7 "+u.convexity.toLowerCase()+" "+i.signed(l.convexity),"Share of the combined move "+i.signed(l.contribution)+" (stand-alone "+i.value(l.standalone)+")"];return l.breach&&o.push(p[l.worst]+" is beyond the limit of "+i.value(c.limit)),o},W.prototype._detail=function(e){if(!e)return null;var r=this._view;if(e.kind==="other")return{view:r,kind:"other",count:e.obj.count,down:e.obj.down,up:e.obj.up,swing:e.obj.swing,contribution:e.obj.contribution,factors:e.obj.factors.map(function(c){return c.key})};if(e.kind==="group"){var i=e.obj;return{view:r,kind:"group",key:i.key,label:i.label,factors:i.factors.slice(),down:i.down,up:i.up,swing:i.swing,share:i.share,linear:i.linear,convexity:i.convexity,worst:i.worst,worstValue:i.worstValue,breach:i.breach,contribution:i.contribution,standalone:i.standalone}}var u=e.obj;return{view:r,kind:"factor",key:u.key,label:u.label,group:u.group,unit:u.unit,shockDown:u.shockDown,shockUp:u.shockUp,down:u.down,up:u.up,swing:u.swing,share:u.share,cumShare:u.cumShare,rank:u.rank,linear:u.linear,convexity:u.convexity,asymmetry:u.asymmetry,worst:u.worst,worstValue:u.worstValue,breach:u.breach,contribution:u.contribution,standalone:u.standalone,source:u.source}},W.prototype.howToRead=function(){var e=this._view||this.options.view;return e==="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.":e==="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.":".")},W.prototype.describe=function(){var e=this.options,r=xt(e.data,e.locale),i=this._labels(),u=this._res||Ht(e.data,this._opts()),c=this._shockNames(),p=[],_=u.order[0];p.push("The largest driver is "+_.label+": "+c.down.toLowerCase()+" gives "+r.signed(_.down)+" and "+c.up.toLowerCase()+" "+r.signed(_.up)+", a swing of "+r.value(_.swing)+" ("+r.percent(_.share,0)+" of the total swing)."),u.factors.length>u.topN&&p.push("The top "+u.topN+" of "+u.factors.length+" factors explain "+r.percent(u.topShare,0)+".");var t=u.worstFactor;p.push("The worst single shock is "+t.label+" "+c[t.worst].toLowerCase()+" at "+r.signed(t.worstValue)+(u.limit!=null?u.breaches?", beyond the limit of "+r.value(u.limit)+" ("+u.breaches+" factor"+(u.breaches>1?"s":"")+" in all)":", within the limit of "+r.value(u.limit):"")+".");var n=u.factors.filter(function(o){return o.asymmetry>=.25&&o.swing>0}).sort(function(o,s){return Math.abs(s.convexity)-Math.abs(o.convexity)});if(n.length&&p.push(n.length+" factor"+(n.length>1?"s are":" is")+" strongly asymmetric, led by "+n[0].label+" (convexity "+r.signed(n[0].convexity)+"), so a bigger shock would cost more than in proportion."),u.correlated){var a=u.factors.slice().sort(function(o,s){return s.contribution-o.contribution}),l=u.factors.filter(function(o){return o.contribution<0}).sort(function(o,s){return o.contribution-s.contribution});p.push("Moving together with their correlations, the factors give a combined move of \xB1"+r.value(u.sigma)+", "+r.percent(u.standalone>0?u.diversification/u.standalone:0,0)+" less than the sum of their stand-alone moves; "+a[0].label+" contributes most ("+r.signed(a[0].contribution)+")"+(l.length?" and "+l[0].label+" hedges the most ("+r.signed(l[0].contribution)+")":"")+".")}return u.interaction&&u.interaction.down!=null&&p.push("Shocked all at once, the down case gives "+r.signed(u.joint.down)+" against "+r.signed(u.sumDown)+" for the sum of single shocks, an interaction of "+r.signed(u.interaction.down)+"."),u.baseline&&p.push("The what-if changes the worst single shock from "+r.signed(u.baseline.worstValue)+" to "+r.signed(t.worstValue)+"."),p.join(" ")},W.prototype.getExportData=function(){var e=this.options,r=e.data,i=this._labels(),u=xt(r,e.locale),c=this._res||Ht(r,this._opts()),p=this._shockNames(),_=e.locale,t={prefix:r.prefix||"",suffix:r.suffix||"",decimals:r.decimals!=null?r.decimals:0,negatives:r.negatives},n=function(d){return{label:d,type:"number",unit:t}},a=function(d){return{label:d,type:"number",unit:{decimals:4}}},l=function(d){return{label:d,type:"percent",decimals:1}},o=function(d){return{label:d,type:"text"}},s=[],m=e.exportRows!=null?e.exportRows:2e4,f=c.order,b=f.length>m;b&&(f=f.slice(0,m));var k=f.map(function(d){return[d.rank,d.label,d.group,d.unit,d.shockDown,d.shockUp,d.down,d.up,d.swing,d.share,d.cumShare,d.linear,d.convexity,p[d.worst],d.worstValue,d.breach?"Yes":"No",d.contribution,d.standalone]});s.push({name:"Factors",columns:[{label:"Rank",type:"number",unit:{decimals:0}},o("Risk factor"),o("Group"),o("Shock unit"),a("Shock down"),a("Shock up"),n(p.down),n(p.up),n(i.swing),l("Share of total swing"),l("Cumulative share"),n(i.linear),n(i.convexity),o("Worst shock"),n(i.worst),o("Beyond limit"),n("Share of combined move"),n("Stand-alone move")],rows:k,text:f.map(function(d){return[String(d.rank),d.label,d.group,d.unit,w(d.shockDown,"",_)||"\u2013",w(d.shockUp,"",_)||"\u2013",u.signed(d.down),u.signed(d.up),u.value(d.swing),u.percent(d.share),u.percent(d.cumShare),u.signed(d.linear),u.signed(d.convexity),p[d.worst],u.signed(d.worstValue),d.breach?"Yes":"No",u.signed(d.contribution),u.value(d.standalone)]}),flag:f.map(function(d){return d.breach})}),s.push({name:"Groups",columns:[o("Group"),{label:"Factors",type:"number",unit:{decimals:0}},n(p.down+" (sum)"),n(p.up+" (sum)"),n(i.swing),l("Share of total swing"),n(i.worst),o("Beyond limit"),n("Share of combined move"),n("Group combined move")],rows:c.groups.map(function(d){return[d.label,d.factors.length,d.down,d.up,d.swing,d.share,d.worstValue,d.breach?"Yes":"No",d.contribution,d.standalone]}),text:c.groups.map(function(d){return[d.label,String(d.factors.length),u.signed(d.down),u.signed(d.up),u.value(d.swing),u.percent(d.share),u.signed(d.worstValue),d.breach?"Yes":"No",u.signed(d.contribution),u.value(d.standalone)]}),flag:c.groups.map(function(d){return d.breach})});var y=[["Total swing",c.totalSwing],["Sum of "+p.down.toLowerCase()+" impacts",c.sumDown],["Sum of "+p.up.toLowerCase()+" impacts",c.sumUp]];c.joint&&(c.joint.down!=null&&y.push(["All factors "+p.down.toLowerCase()+" together",c.joint.down],[i.interaction+" ("+p.down.toLowerCase()+")",c.interaction.down]),c.joint.up!=null&&y.push(["All factors "+p.up.toLowerCase()+" together",c.joint.up],[i.interaction+" ("+p.up.toLowerCase()+")",c.interaction.up])),y.push([i.combined+" (\xB1)",c.sigma],["Sum of stand-alone moves",c.standalone],["Diversification",c.diversification]),c.limit!=null&&y.push([i.limit,c.limit]),s.push({name:"Summary",columns:[o("Item"),n("Amount")],rows:y,text:y.map(function(d){return[d[0],/Sum|Interaction|together/.test(d[0])?u.signed(d[1]):u.value(d[1])]})});var x=(e.annotations||[]).map(function(d,T){return[String(T+1),d.factor!=null?String(d.factor):"Group: "+String(d.group||""),d.text||""]});x.length&&s.push({name:"Notes",columns:[o("No."),o("Factor or group"),o("Note")],rows:x});var M=r.correlation;return{title:r.title||"Risk-factor tornado",subtitle:r.subtitle||"",summary:this.describe(),library:"Veyforma Risk-Factor Tornado "+Ct,sheets:s,meta:[["Unit",r.unit],["As of",r.asOf],["Desk",r.desk],["Measure",c.higherIsBetter?"Higher is better (for example P&L)":"Lower is better (for example capital)"],["Ranking",e.sort==="worst"?"By worst result":"By swing"],["Shocks",p.down+" / "+p.up+(c.shockScale!==1?", scaled \xD7"+c.shockScale:"")],["What-if",c.whatIf?Object.keys(c.whatIf).map(function(d){return d+" \xD7 "+c.whatIf[d]}).join(", "):null],["Correlation",M?M.matrix?"Matrix given":"Within groups "+(M.within||0)+", across "+(M.across||0):"None given (independent factors)"],["Limit",c.limit!=null?u.value(c.limit)+" ("+c.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)"+(b?"; factor sheet limited to the "+m+" largest swings":"")],["Data source",r.source]]}},W.prototype._annotationPoint=function(e){var r=this._points||{};return e.factor!=null?r[String(e.factor)]||null:e.group!=null&&r["group:"+String(e.group)]||null},W.prototype._annotationTarget=function(e){var r=this._items||[],i=null;if(!e)i=r[this._active];else for(var u=this.plotHost.querySelector("svg"),c=u.getBoundingClientRect(),p=u.viewBox.baseVal,_=(e.clientX-c.left)*(p.width/c.width),t=(e.clientY-c.top)*(p.height/c.height),n=0;n<r.length;n++){var a=r[n];if(_>=a.x&&_<=a.x+a.w&&t>=a.y&&t<=a.y+a.h){i=a;break}}return!i||i.kind==="other"?null:i.kind==="group"?{group:i.obj.key}:{factor:i.obj.key}},W.prototype._annotationLabel=function(e){if(e.group!=null)return String(e.group);var r=(this._res||this.getResult()).factors.filter(function(i){return i.key===String(e.factor)})[0];return r?r.label:String(e.factor||"")},Y.VeyRiskTornado={version:Ct,create:function(e,r){return new W(e,r)},compute:function(e,r){return Ht(e,r)},listThemes:function(){return Object.keys(Mt)},getTheme:function(e){return Vt(e)},defaults:{options:At,labels:ft,theme:_t}}})(typeof window<"u"?window:void 0);(function(Y){"use strict";var Ct="1.0.0",kt="http://www.w3.org/2000/svg",St=0,_t={hpl:"#111827",rtpl:"#c2410c",unexplained:"#6b7280",contribution:"#a63d16",offset:"#2f6fed",standalone:"#111827",zones:{green:"#15803d",amber:"#b45309",red:"#b91c1c"},outside:"#d1d5db",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},Mt={veyforma:{},mono:{hpl:"#111111",rtpl:"#6b6b6b",unexplained:"#8a8a8a",contribution:"#111111",offset:"#8a8a8a",zones:{green:"#111111",amber:"#4b4b4b",red:"#111111"},accent:"#111111",focus:"#111111"},"colour-safe":{hpl:"#1f2937",rtpl:"#d55e00",unexplained:"#6b7280",contribution:"#cc3311",offset:"#0072b2",zones:{green:"#007a5e",amber:"#a35c00",red:"#b2182b"},accent:"#0072b2"},ocean:{hpl:"#0c3b5e",rtpl:"#0e7490",contribution:"#0c3b5e",offset:"#c2410c",cardBackground:"#eef5f8",accent:"#0e7490"},forest:{hpl:"#22311a",rtpl:"#4d6b31",contribution:"#22311a",offset:"#2f6fed",cardBackground:"#f2f4ee",accent:"#4d6b31"},corporate:{hpl:"#1e293b",rtpl:"#1d4ed8",contribution:"#1e293b",offset:"#c2410c",cardBackground:"#f1f4f8",accent:"#1d4ed8"},midnight:{background:"#111418",hpl:"#f3f4f6",rtpl:"#f08a5d",unexplained:"#8b93a1",contribution:"#f08a5d",offset:"#93c5fd",standalone:"#f3f4f6",zones:{green:"#4ade80",amber:"#fbbf24",red:"#fb7185"},outside:"#374151",grid:"#252a31",axis:"#4b5563",text:"#f3f4f6",mutedText:"#a3abb8",axisText:"#a3abb8",cardBackground:"#1b2027",tooltipBackground:"#f3f4f6",tooltipText:"#111418",focus:"#93c5fd",accent:"#f08a5d"}},At={spearmanGreen:.8,spearmanRed:.7,ksGreen:.09,ksRed:.12},ft={data:null,view:"factors",window:250,fix:null,thresholds:null,top:15,pathSteps:5,theme:"veyforma",locale:void 0,animate:!0,summary:!0,legend:!0,labels:null,ariaLabel:void 0,caption:!0,annotations:null,onAnnotationsChange:null,onItemClick:null,exportDays:2e4,toolbar:!0},wt={factors:"Unexplained P&L by risk factor",daily:"HPL and RTPL by day",distribution:"Distribution of HPL and RTPL",hpl:"HPL (front office)",rtpl:"RTPL (risk model)",unexplained:"Unexplained (HPL \u2212 RTPL)",adds:"Adds to unexplained volatility",offsets:"Offsets other gaps",standalone:"Gap on its own",test:"PLA test",unexplainedCard:"Unexplained P&L",largest:"Largest driver",path:"Path to green",green:"Green",amber:"Amber",red:"Red",na:"n/a",other:"Other {n} factors",unattributed:"Unattributed",notModelled:"not in the risk model",ifFixed:"If fixed",outside:"Outside the test window"};function bt(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(t[l]=a[l])}return t}var ot={};function V(t){ot[t]||(ot[t]=1,Y.console&&console.warn&&console.warn("VeyPlaAttribution: "+t))}function pt(t){throw new Error("VeyPlaAttribution: "+t)}function Rt(t,n,a){return Math.min(a,Math.max(n,t))}function $t(t,n){return String(t).replace(/\{(\w+)\}/g,function(a,l){return n[l]!=null?n[l]:a})}function ae(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 I(t,n,a){var l=document.createElementNS(kt,t);if(n)for(var o in n)n[o]!=null&&l.setAttribute(o,n[o]);return a&&a.appendChild(l),l}function J(t,n,a){var l=document.createElement(t);return n&&(l.className=n),a&&a.appendChild(l),l}var et=null;function ht(t,n,a,l){if(!et){var o=document.createElement("canvas");et=o.getContext&&o.getContext("2d")}return et?(et.font=(a||400)+" "+n+"px "+l,et.measureText(String(t)).width):String(t).length*n*.6}function Ft(t,n,a,l,o){if(t=String(t),ht(t,a,l,o)<=n)return t;for(;t.length>2&&ht(t+"\u2026",a,l,o)>n;)t=t.slice(0,-1);return t.replace(/\s+$/,"")+"\u2026"}function yt(t){var n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(String(t||"").trim());if(!n)return null;var a=n[1].length===3?n[1].replace(/./g,"$&$&"):n[1],l=parseInt(a,16);return[l>>16&255,l>>8&255,l&255]}function Dt(t){var n=t.map(function(a){return a/=255,a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4)});return .2126*n[0]+.7152*n[1]+.0722*n[2]}function it(t,n){var a=yt(t),l=yt(n);if(!a||!l)return 21;var o=Dt(a),s=Dt(l);return(Math.max(o,s)+.05)/(Math.min(o,s)+.05)}function xt(t,n,a){var l=yt(t),o=yt(n);if(!l||!o||it(t,n)>=a)return t;for(var s=Dt(o)>.4,m=0,f=t;m<=1&&it(f,n)<a;)m+=.05,f="#"+l.map(function(b){var k=s?b*(1-m):b+(255-b)*m;return("0"+Math.round(k).toString(16)).slice(-2)}).join("");return f}function ut(t,n){var a=t.decimals!=null?t.decimals:0,l=t.ratioDecimals!=null?t.ratioDecimals:1,o=t.prefix||"",s=t.suffix||"",m={},f=t.negatives==="brackets";function b(T){return m[T]||(m[T]=new Intl.NumberFormat(n||void 0,{minimumFractionDigits:T,maximumFractionDigits:T})),m[T]}function k(T,C){if(T==null||!isFinite(T))return"\u2013";C==null&&(C=a);var R=Number(T.toFixed(C)),O=o+b(C).format(Math.abs(R))+s;return R>=0?O:f?"("+O+")":"\u2212"+O}function y(T,C){var R=k(T,C);return T!=null&&Number(T.toFixed(C??a))>0?"+"+R:R}function x(T,C){return T==null||!isFinite(T)?"\u2013":(T<0?"\u2212":"")+b(C??l).format(Math.abs(T)*100)+"%"}function M(T,C){if(T==null||!isFinite(T))return"\u2013";var R=C??Math.max(l,1),O=Number((T*100).toFixed(R));return(O>0?"+":O<0?"\u2212":"")+b(R).format(Math.abs(O))+" pp"}function d(T,C){return T==null||!isFinite(T)?"\u2013":b(C??1).format(T*100)+"%"}return{value:k,signed:y,ratio:x,pp:M,percent:d,nf:b}}function vt(t,n){var a=dt(t);return isFinite(a)||pt(n+" must be a number."),a}function Zt(t){var n=t.length,a=new Array(n),l=new Array(n),o,s;for(o=0;o<n;o++)a[o]=o;for(a.sort(function(b,k){return t[b]-t[k]}),o=0;o<n;o=s){for(s=o;s<n&&t[a[s]]===t[a[o]];)s++;for(var m=(o+s+1)/2,f=o;f<s;f++)l[a[f]]=m}return l}function Tt(t,n){var a=t.length,l=0,o=0,s;for(s=0;s<a;s++)l+=t[s],o+=n[s];l/=a,o/=a;var m=0,f=0,b=0;for(s=0;s<a;s++){var k=t[s]-l,y=n[s]-o;m+=k*y,f+=k*k,b+=y*y}return f>0&&b>0?m/Math.sqrt(f*b):null}function Jt(t,n){return Tt(Zt(t),Zt(n))}function Ht(t,n){for(var a=t.slice().sort(function(M,d){return M-d}),l=n.slice().sort(function(M,d){return M-d}),o=a.length,s=l.length,m=0,f=0,b=0,k=a.length?a[0]:0;m<o&&f<s;){for(var y=Math.min(a[m],l[f]);m<o&&a[m]===y;)m++;for(;f<s&&l[f]===y;)f++;var x=Math.abs(m/o-f/s);x>b+1e-15&&(b=x,k=y)}return{d:b,at:k}}function te(t,n,a){return t==null?"red":(t=Math.round(t*1e12)/1e12,n=Math.round(n*1e12)/1e12,t>a.spearmanGreen&&n<a.ksGreen?"green":t<a.spearmanRed||n>a.ksRed?"red":"amber")}function Vt(t,n){return Math.max(0,n.spearmanGreen-(t.spearman==null?-1:t.spearman))/.1+Math.max(0,t.ks-n.ksGreen)/.03}function W(t,n,a){var l=Jt(t,n),o=Ht(t,n);return{spearman:l,ks:o.d,ksAt:o.at,zone:te(l,o.d,a)}}function It(t){var n=t.length,a=0,l=0,o;for(o=0;o<n;o++)a+=t[o];for(a/=n,o=0;o<n;o++)l+=(t[o]-a)*(t[o]-a);return Math.sqrt(l/n)}function h(t){for(var n=0,a=0;a<t.length;a++)n+=t[a];return t.length?n/t.length:0}function w(t){(!t||typeof t!="object")&&pt("data is required.");var n=t.dates;(!Array.isArray(n)||n.length<2)&&pt("data.dates must be an array of at least two days.");var a=n.length,l=function(x,M,d){return x==null&&d?null:((!Array.isArray(x)||x.length!==a)&&pt(M+" must be an array with one value per date ("+a+")."),x.map(function(T,C){return vt(T,M+"["+C+"]")}))};(!Array.isArray(t.factors)||!t.factors.length)&&pt("data.factors must be a non-empty array of risk factors.");var o={},s=t.factors.map(function(x,M){(!x||typeof x!="object")&&pt("data.factors["+M+"] is not an object."),x.key==null&&x.label==null&&pt("data.factors["+M+"] needs a key or a label.");var d=String(x.key!=null?x.key:x.label),T='factor "'+d+'"';o[d]&&pt(T+" is used twice."),o[d]=1;var C=l(x.hpl,T+": hpl"),R=l(x.rtpl,T+": rtpl",!0);return{key:d,label:x.label!=null?String(x.label):d,group:x.group!=null?String(x.group):"Other",modelled:R!=null,hpl:C,rtpl:R||C.map(function(){return 0}),index:M}}),m=l(t.hplTotal,"data.hplTotal",!0),f=l(t.rtplTotal,"data.rtplTotal",!0);if(m||f){var b=new Array(a),k=new Array(a),y;for(y=0;y<a;y++)b[y]=0,k[y]=0,s.forEach(function(x){b[y]+=x.hpl[y],k[y]+=x.rtpl[y]});s.push({key:"__unattributed",label:t.unattributedLabel||wt.unattributed,group:"Unattributed",modelled:!0,unattributed:!0,hpl:b.map(function(x,M){return m?m[M]-x:0}),rtpl:k.map(function(x,M){return f?f[M]-x:0}),index:s.length})}return{dates:n.map(String),factors:s,n:a}}function g(t,n){n=n||{};var a=w(t),l=a.n,o=a.factors,s=bt({},At,n.thresholds||{}),m=n.window!=null?Math.floor(vt(n.window,"window")):250;m>=2||pt("window must be at least 2 days.");var f=m>l;f&&(m=l);var b=l-m,k={};(n.fix||[]).forEach(function(P){o.some(function(N){return N.key===String(P)})||V('fix: there is no factor "'+P+'", so it changes nothing.'),k[String(P)]=1}),o.forEach(function(P){P.fixed=!!k[P.key],P.rt=P.fixed?P.hpl:P.rtpl,P.gap=P.hpl.map(function(N,F){return N-P.rt[F]})});var y=new Array(l),x=new Array(l),M=new Array(l),d,T;for(d=0;d<l;d++){var C=0,R=0;for(T=0;T<o.length;T++)C+=o[T].hpl[d],R+=o[T].rt[d];y[d]=C,x[d]=R,M[d]=C-R}var O=y.slice(b),j=x.slice(b),E=M.slice(b),S={dates:a.dates,hpl:y,rtpl:x,unexplained:M,start:b,window:m,shortWindow:f,thresholds:s,fixed:Object.keys(k)};S.test=W(O,j,s);var A=It(E),H=It(O),lt=h(E);S.sdUnexplained=A,S.sdHpl=H,S.meanUnexplained=lt,S.volRatio=H>0?A/H:null,S.meanRatio=H>0?lt/H:null,S.varRatio=H>0?A*A/(H*H):null,o.forEach(function(P){var N=P.gap.slice(b),F=h(N),B=0;for(d=0;d<m;d++)B+=(N[d]-F)*(E[d]-lt);for(B/=m,P.meanGap=F,P.sdGap=It(N),P.contribution=A>0?B/A:0,P.share=A>0?P.contribution/A:0,P.hplSum=0,P.rtplSum=0,d=b;d<l;d++)P.hplSum+=P.hpl[d],P.rtplSum+=P.rt[d];if(P.hasGap=P.sdGap>0||F!==0,P.hasGap){var U=j.map(function(nt,st){return nt+N[st]});P.ifFixed=W(O,U,s)}else P.ifFixed=S.test});var tt=o.slice().sort(function(P,N){return Math.abs(N.contribution)-Math.abs(P.contribution)||P.index-N.index});tt.forEach(function(P,N){P.rank=N+1}),S.factors=o,S.order=tt;for(var D=n.pathSteps!=null?Math.max(0,Math.floor(n.pathSteps)):5,K=[],q=j.slice(),X=S.test,Q={};X.zone!=="green"&&K.length<D;){var Z=null;if(o.forEach(function(P){if(!(Q[P.key]||P.fixed||!P.hasGap)){var N=P.gap.slice(b),F=q.map(function(nt,st){return nt+N[st]}),B=W(O,F,s),U=Vt(B,s);(!Z||U<Z.d-1e-12||Math.abs(U-Z.d)<=1e-12&&(B.spearman||-1)>(Z.t.spearman||-1))&&(Z={f:P,t:B,d:U,R:F})}}),!Z||Z.d>=Vt(X,s)-1e-12)break;Q[Z.f.key]=1,K.push({key:Z.f.key,label:Z.f.label,test:Z.t}),q=Z.R,X=Z.t}return S.path=K,S.pathReachesGreen=S.test.zone==="green"||K.length>0&&K[K.length-1].test.zone==="green",S.distribution={hpl:O.slice().sort(function(P,N){return P-N}),rtpl:j.slice().sort(function(P,N){return P-N})},S}function v(){if(!document.getElementById("vpa-styles")){var t=".vpa{position:relative;color:var(--vpa-text);background:var(--vpa-bg);font-family:var(--vpa-font);line-height:1.4}.vpa.vpa-filled{padding:14px 14px 8px;border-radius:10px}.vpa-summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px;margin:0 0 10px}.vpa-stat{background:var(--vpa-card);border-radius:8px;padding:9px 12px;min-width:0}.vpa-stat .k{font-size:11px;letter-spacing:.04em;text-transform:uppercase;color:var(--vpa-card-muted);font-weight:600;overflow-wrap:anywhere;hyphens:auto}.vpa-stat .v{font-size:19px;font-weight:700;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.vpa-stat .n{font-size:12px;color:var(--vpa-card-muted)}.vpa-stat .v.vpa-zone{font-weight:800}.vpa-stat .v.vpa-wrap{white-space:normal;overflow-wrap:anywhere;line-height:1.2;font-size:17px}.vpa-scope{font-size:12px;color:var(--vpa-muted);margin:0 0 4px}.vpa-legend{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:12px;margin:0 0 6px;color:var(--vpa-text)}.vpa-legend span{display:inline-flex;align-items:center;gap:6px}.vpa-legend i{display:inline-block;width:12px;height:12px;border-radius:3px}.vpa-legend i.vpa-tick{width:16px;height:3px;border-radius:1px}.vpa-legend i.vpa-ring{background:transparent!important;border:2px solid;border-radius:2px;width:9px;height:9px;transform:rotate(45deg)}.vpa-plot{display:block;width:100%;height:auto;overflow:visible;outline:none}.vpa-plot:focus-visible{outline:2px solid var(--vpa-focus);outline-offset:4px;border-radius:4px}.vpa-animate .vpa-grow{animation:vpa-fade .45s ease both}@keyframes vpa-fade{from{opacity:0}to{opacity:1}}@media (prefers-reduced-motion:reduce){.vpa-animate .vpa-grow{animation:none}}.vpa-tip{position:absolute;left:0;top:0;pointer-events:none;background:var(--vpa-tip-bg);color:var(--vpa-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}.vpa-tip.vpa-on{opacity:1;transform:none}.vpa-tip b{font-weight:600}.vpa-table{border-collapse:collapse;font-size:12px;font-variant-numeric:tabular-nums;margin:0 0 14px;min-width:100%}.vpa-table caption{text-align:left;font-weight:700;padding:0 0 6px}.vpa-table th,.vpa-table td{padding:5px 8px;border-bottom:1px solid rgba(127,127,127,.25);text-align:right;white-space:nowrap}.vpa-table th:first-child,.vpa-table td:first-child{text-align:left}.vpa-table tr.vpa-breach td{color:var(--vpa-hedge);font-weight:600}@media (max-width:420px){.vpa-summary{grid-template-columns:repeat(auto-fit,minmax(118px,1fr))}.vpa-stat{padding:8px 10px}.vpa-stat .v{font-size:17px}}",n=J("style");n.id="vpa-styles",n.textContent=t,(document.head||document.documentElement).appendChild(n)}}function e(t){var n;(t==null||t==="")&&(t="veyforma"),typeof t=="string"?(Mt.hasOwnProperty(t)||(V('Unknown theme "'+t+'". The "veyforma" theme is used instead.'),t="veyforma"),n=bt({},_t,Mt[t])):typeof t=="object"?(n=bt(t.extends?e(t.extends):bt({},_t),t),delete n.extends):(V("The theme option must be a theme name or an object."),n=bt({},_t));var a=/^#/.test(n.background)?n.background:"#ffffff",l=/^#/.test(n.cardBackground)?n.cardBackground:a;return["axisText","mutedText"].forEach(function(o){n[o]=xt(n[o],a,4.5)}),n.cardMuted=xt(n.mutedText,l,4.5),n.offsetText=xt(xt(n.offset,a,4.5),l,4.5),n.zoneText={},["green","amber","red"].forEach(function(o){n.zoneText[o]=xt(xt(n.zones[o],a,4.5),l,4.5)}),n.accentText=xt(n.accent,a,4.5),n}function r(t,n){var a=typeof t=="string"?document.querySelector(t):t;(!a||a.nodeType!==1)&&pt("container not found ("+t+")."),(!n||!n.data)&&pt("options.data is required."),v(),this.id=++St,this.container=a,this.options=bt({},ft,n),this.element=J("div","vpa"),this.element.setAttribute("role","figure"),this.summaryEl=J("div","vpa-summary",this.element),this.scopeEl=J("p","vpa-scope",this.element),this.legendEl=J("div","vpa-legend",this.element),this.plotHost=J("div","vpa-plot-host",this.element),this.tipEl=J("div","vpa-tip",this.element),this.tipEl.setAttribute("role","tooltip"),a.appendChild(this.element),this._animateNext=!!this.options.animate,this._lastWidth=0,this._active=-1;var l=this;Y.ResizeObserver?(this._observer=new Y.ResizeObserver(function(){var o=Math.round(l.element.clientWidth);o&&Math.abs(o-l._lastWidth)>1&&l.redraw()}),this._observer.observe(this.element)):(this._onResize=function(){l.redraw()},Y.addEventListener("resize",this._onResize)),this._onDocTap=function(o){l.element.contains(o.target)||l._hideTip()},document.addEventListener("pointerdown",this._onDocTap),this.redraw(),this.options.toolbar!==!1&&Y.VeyformaToolkit&&(this.toolkit=Y.VeyformaToolkit.attach(this,this.options.toolbar))}r.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),bt(this.options,t),this.redraw()):this},r.prototype.setData=function(t){return this._res=null,this.update({data:t})},r.prototype.setView=function(t){return this.update({view:t})},r.prototype.setTheme=function(t){return this.update({theme:t})},r.prototype.getTheme=function(){return e(this.options.theme)},r.prototype._opts=function(){return{window:this.options.window,fix:this.options.fix,thresholds:this.options.thresholds}},r.prototype.getResult=function(){return g(this.options.data,this._opts())},r.prototype.getFactor=function(t){return this.getResult().factors.filter(function(n){return n.key===String(t)})[0]||null},r.prototype.setFix=function(t){return this.update({fix:t})},r.prototype.setWindow=function(t){return this.update({window:t})},r.prototype._labels=function(){return bt({},wt,this.options.labels)},r.prototype.destroy=function(){this.toolkit&&this.toolkit.destroy&&this.toolkit.destroy(),this._observer&&this._observer.disconnect(),this._onResize&&Y.removeEventListener("resize",this._onResize),document.removeEventListener("pointerdown",this._onDocTap),this.element.parentNode&&this.element.parentNode.removeChild(this.element)},r.prototype._hideTip=function(){this.tipEl.classList.remove("vpa-on"),this._hlEl&&this._hlEl.setAttribute("opacity",0)},r.prototype._placeTip=function(t,n,a){var l=this.tipEl;l.textContent="",t.forEach(function(y,x){x&&l.appendChild(document.createElement("br"));var M=x===0?document.createElement("b"):document.createElement("span");M.textContent=y,l.appendChild(M)});var o=this.element.getBoundingClientRect(),s=a&&a.clientX?a.clientX:n.left+n.width/2,m=a&&a.clientY?a.clientY:n.top+10;l.classList.add("vpa-on");var f=l.offsetWidth,b=l.offsetHeight;l.style.left=Rt(s-o.left-f/2,4,Math.max(4,o.width-f-4))+"px";var k=m-o.top-b-14;k<0&&(k=m-o.top+18),l.style.top=k+"px"};function i(t,n,a){n>t||(n=t+1);var l=n-t,o=Math.pow(10,Math.floor(Math.log(l/a)/Math.LN10)),s=l/a/o;s>=7.5?o*=10:s>=3.5?o*=5:s>=1.5&&(o*=2);for(var m=Math.floor(t/o+1e-9)*o,f=Math.ceil(n/o-1e-9)*o,b=[],k=m;k<=f+o/2;k+=o)b.push(Math.round(k/o)*o);return{lo:m,hi:f,ticks:b,step:o}}function u(t,n,a,l,o){var s=I("text",bt({x:n,y:a},o||{}),t);return s.textContent=l,s}r.prototype._bindInteraction=function(t,n,a,l,o,s){var m=this,f=this._items,b=this.options;function k(x){for(var M=t.getBoundingClientRect(),d=(x.clientX-M.left)*(n/M.width),T=(x.clientY-M.top)*(a/M.height),C=0;C<f.length;C++){var R=f[C];if(d>=R.x&&d<=R.x+R.w&&T>=R.y&&T<=R.y+R.h)return C}return-1}function y(x,M){if(x<0){m._hideTip();return}m._active=x;var d=f[x],T=m._hlEl;T.setAttribute("x",d.x-4),T.setAttribute("y",d.y),T.setAttribute("width",d.w+8),T.setAttribute("height",d.h),T.setAttribute("opacity",1);var C=t.getBoundingClientRect(),R=C.width/n,O={left:C.left+d.px*R,top:C.top+d.py*(C.height/a),width:0,height:0};m._placeTip(m._tipLines(d),O,M&&M.clientX?M:null)}t.addEventListener("pointermove",function(x){y(k(x),x)}),t.addEventListener("pointerleave",function(){m._hideTip()}),t.addEventListener("click",function(x){var M=k(x);M>=0&&typeof b.onItemClick=="function"&&b.onItemClick(m._detail(f[M]),x)}),t.addEventListener("keydown",function(x){var M=m._active;if(x.key==="ArrowRight"||x.key==="ArrowDown")M=Math.min(f.length-1,M+1);else if(x.key==="ArrowLeft"||x.key==="ArrowUp")M=Math.max(0,M<0?0:M-1);else if(x.key==="Home")M=0;else if(x.key==="End")M=f.length-1;else if(x.key==="Escape"){m._hideTip();return}else if((x.key==="Enter"||x.key===" ")&&M>=0){typeof b.onItemClick=="function"&&b.onItemClick(m._detail(f[M]),x),x.preventDefault();return}else return;x.preventDefault(),y(M,null)}),t.addEventListener("blur",function(){m._hideTip()})},r.prototype.createTable=function(){var t=this.getExportData(),n=J("div","vpa-tables");return t.sheets.forEach(function(a){if(a.name!=="Notes"){var l=J("table","vpa-table",n);J("caption",null,l).textContent=a.name;var o=J("tr",null,J("thead",null,l));a.columns.forEach(function(m){var f=J("th",null,o);f.scope="col",f.textContent=m.label});var s=J("tbody",null,l);a.text.forEach(function(m,f){var b=J("tr",a.flag&&a.flag[f]?"vpa-breach":null,s);m.forEach(function(k,y){var x=J(y?"td":"th",null,b);y||(x.scope="row"),x.textContent=k})})}}),n},r.prototype.redraw=function(){var t=this.options,n=t.data,a=this._labels(),l=this._res=g(n,bt(this._opts(),{pathSteps:t.pathSteps})),o=e(t.theme),s=ut(n,t.locale),m=this.element,f=m.style,b=o.fontFamily==="inherit"?Y.getComputedStyle?Y.getComputedStyle(this.container).fontFamily:"sans-serif":o.fontFamily,k=o.background&&o.background!=="transparent",y=k?o.background:"#ffffff";f.setProperty("--vpa-text",o.text),f.setProperty("--vpa-muted",o.mutedText),f.setProperty("--vpa-bg",k?o.background:"transparent"),f.setProperty("--vpa-font",b),f.setProperty("--vpa-card",o.cardBackground),f.setProperty("--vpa-card-muted",o.cardMuted),f.setProperty("--vpa-tip-bg",o.tooltipBackground),f.setProperty("--vpa-tip-text",o.tooltipText),f.setProperty("--vpa-focus",o.focus),f.setProperty("--vpa-hedge",o.zoneText.red),m.classList.toggle("vpa-filled",!!k),m.setAttribute("aria-label",t.ariaLabel||n.title||"P&L attribution");var x=t.view;["factors","daily","distribution"].indexOf(x)<0&&(V('Unknown view "'+x+'". The factor view is shown instead.'),x="factors"),l.shortWindow&&!this._warnedShort&&(V("There are fewer days than the "+(t.window||250)+"-day window; all "+l.window+" are used."),this._warnedShort=!0),this._view=x,this._renderSummary(l,s,a,o),this.scopeEl.textContent=[a[x],l.window+"-day window",n.unit||null,l.fixed.length?l.fixed.length+" fix"+(l.fixed.length>1?"es":"")+" applied":null].filter(Boolean).join(" \xB7 "),this._renderLegend(x,o,a,l);var M=Math.max(280,Math.round(this.plotHost.clientWidth||m.clientWidth||720));this._lastWidth=Math.round(m.clientWidth);var d=o.fontSize||12;this.plotHost.textContent="";var T=I("svg",{class:"vpa-plot",role:"img",tabindex:0,"font-family":b},this.plotHost);T.style.fontSize=d+"px";var C=this._animateNext&&t.animate;this._animateNext=!1,C&&T.classList.add("vpa-animate");var R={svg:T,W:M,fs:d,theme:o,f:s,L:a,family:b,bg:y,res:l,items:[],points:{}},O=x==="daily"?this._drawDaily(R):x==="distribution"?this._drawDistribution(R):this._drawFactors(R);return T.setAttribute("viewBox","0 0 "+M+" "+O),T.setAttribute("width",M),T.setAttribute("height",O),T.setAttribute("aria-label",(t.ariaLabel||n.title||"P&L attribution")+". "+this.describe()),this._items=R.items,this._points=R.points,this._hlEl=I("rect",{x:0,y:0,width:0,height:0,rx:4,fill:o.text,"fill-opacity":.06,opacity:0,"pointer-events":"none"},T),T.insertBefore(this._hlEl,T.firstChild),this._bindInteraction(T,M,O,o,a,s),this};function c(t){return t==null?"n/a":t.toFixed(2)}r.prototype._zoneName=function(t){var n=this._labels();return n[t]||t},r.prototype._renderSummary=function(t,n,a,l){var o=this.summaryEl,s=this.options,m=this;if(o.textContent="",o.style.display=s.summary===!1?"none":"",s.summary===!1)return;function f(y,x,M,d,T){var C=J("div","vpa-stat",o);J("div","k",C).textContent=y;var R=J("div",d?"v "+d:"v",C);R.textContent=x,T&&(R.style.color=T),M&&(J("div","n",C).textContent=M)}var b=t.test,k=t.order[0];f(a.test,this._zoneName(b.zone),"Spearman "+c(b.spearman)+" \xB7 KS "+c(b.ks)+" ("+t.window+" days)","vpa-zone",l.zoneText[b.zone]),f(a.unexplainedCard,"\xB1"+n.value(t.sdUnexplained),(t.volRatio!=null?n.percent(t.volRatio,0)+" of HPL volatility \xB7 ":"")+"mean "+n.signed(t.meanUnexplained)+" a day"),f(a.largest,k.label,n.percent(k.share,0)+" of the unexplained volatility","vpa-wrap"),b.zone==="green"?f(a.path,"Already green","margin: Spearman +"+(b.spearman-t.thresholds.spearmanGreen).toFixed(2)+", KS \u2212"+(t.thresholds.ksGreen-b.ks).toFixed(2)):t.pathReachesGreen?f(a.path,"Fix "+t.path.length+" factor"+(t.path.length>1?"s":""),t.path.map(function(y){return y.label}).join(", ")+" \u2192 Spearman "+c(t.path[t.path.length-1].test.spearman)+", KS "+c(t.path[t.path.length-1].test.ks),"vpa-wrap"):f(a.path,t.path.length?"Not within "+t.path.length+" fix"+(t.path.length>1?"es":""):"No single fix helps",t.path.length?"best reached: "+this._zoneName(t.path[t.path.length-1].test.zone).toLowerCase():"the gap is spread across factors"),Array.prototype.forEach.call(o.querySelectorAll(".vpa-stat .v"),function(y){y.style.fontSize="";for(var x=parseFloat(Y.getComputedStyle?Y.getComputedStyle(y).fontSize:19)||19;y.scrollWidth>y.clientWidth&&x>12;)x-=1,y.style.fontSize=x+"px"})},r.prototype._renderLegend=function(t,n,a,l){var o=this.legendEl;o.textContent="",o.style.display=this.options.legend===!1?"none":"";function s(m,f,b){var k=J("span",null,o),y=J("i",b||null,k);b==="vpa-ring"?y.style.borderColor=m:y.style.background=m,k.appendChild(document.createTextNode(f))}if(t==="factors"){s(n.contribution,a.adds),s(n.offset,a.offsets),s(n.standalone,a.standalone,"vpa-ring");return}s(n.hpl,a.hpl,"vpa-tick"),s(n.rtpl,a.rtpl,"vpa-tick"),t==="daily"&&(s(n.unexplained,a.unexplained),l.start>0&&s(n.outside,a.outside))};function p(t,n){var a=Math.min(Math.max.apply(null,n.map(function(o){return ht(o,t.fs,600,t.family)}))+12,t.W*.34),l=t.W-a<300;return{nameW:l?0:a,narrow:l}}function _(t,n,a,l,o,s,m,f,b,k){var y=t.theme,x=t.fs,M=t.family,d=t.W,T=-1/0;a.ticks.forEach(function(C){I("line",{x1:l(C),x2:l(C),y1:f,y2:b,stroke:C===0?y.axis:y.grid,"stroke-width":C===0?1.2:1},n);var R=k(C),O=ht(R,x-1,400,M),j=l(C),E=j-O/2<0?"start":j+O/2>d?"end":"middle",S=E==="start"?j:E==="end"?j-O:j-O/2;S<T+8||(T=S+O,u(n,j,o+x,R,{"text-anchor":E,fill:y.axisText,"font-size":x-1,class:"vpa-tick"}))})}r.prototype._drawFactors=function(t){var n=t.res,a=t.theme,l=t.f,o=t.L,s=t.fs,m=t.family,f=t.W,b=t.svg,k=this,y=+this.options.top>0?Math.floor(+this.options.top):n.order.length,x=n.order.slice(y),M=n.order.slice(0,y).sort(function(N,F){return F.contribution-N.contribution}).map(function(N){return{kind:"factor",obj:N,name:N.label+(N.modelled?"":" *"),v:N.contribution,k:N.sdGap}});if(x.length){var d=0,T=0;x.forEach(function(N){d+=N.contribution,T+=N.sdGap}),M.push({kind:"other",obj:{count:x.length,contribution:d,factors:x},name:$t(o.other,{n:x.length}),v:d,k:null})}var C=p(t,M.map(function(N){return N.name})),R=Math.max(ht("\u2192 "+o.amber,s-1,600,m),ht("\u2192 "+o.green,s-1,600,m),ht("\u2192 "+o.red,s-1,600,m))+14,O=Math.max.apply(null,M.map(function(N){return ht(l.signed(N.v),s,700,m)}))+10,j=C.nameW,E=f-O-R,S=Math.max(26,s*2.1),A=C.narrow?s+4:0,H=4,lt=Math.min(0,Math.min.apply(null,M.map(function(N){return N.v}))),tt=Math.max.apply(null,M.map(function(N){return Math.max(N.v,N.k||0)}))||1,D=i(lt,tt,Math.max(2,Math.min(6,Math.floor((E-j)/90)))),K=function(N){return j+(Rt(N,D.lo,D.hi)-D.lo)/(D.hi-D.lo)*(E-j)},q=H+s+6,X=q+M.length*(S+A),Q=I("g",{class:"vpa-factors"},b);_(t,Q,D,K,H,j,E,q,X,function(N){return l.value(N)}),u(Q,f,H+s,o.ifFixed,{"text-anchor":"end",fill:a.axisText,"font-size":s-1,class:"vpa-tick"}),M.forEach(function(N,F){var B=q+F*(S+A)+A,U=S*.56,nt=B+(S-U)/2,st=N.v<0&&l.value(-N.v)!==l.value(0);u(Q,0,C.narrow?B-3:nt+U/2+s*.35,Ft(N.name,C.narrow?f-R:C.nameW-8,s,N.kind==="other"?400:600,m),{fill:N.kind==="other"?a.mutedText:a.text,"font-size":s,"font-weight":N.kind==="other"?400:600,class:"vpa-name"});var at=K(Math.min(0,N.v)),zt=K(Math.max(0,N.v));if(I("rect",{x:at,y:nt,width:Math.max(.8,zt-at),height:U,rx:2,fill:st?a.offset:a.contribution,class:"vpa-grow vpa-cbar"+(st?" vpa-offset":"")},Q),N.k!=null){var mt=K(N.k),gt=nt+U/2;I("path",{d:"M"+mt+","+(gt-5)+"L"+(mt+5)+","+gt+"L"+mt+","+(gt+5)+"L"+(mt-5)+","+gt+"Z",fill:t.bg,stroke:a.standalone,"stroke-width":1.6,class:"vpa-sa"},Q)}if(u(Q,f-R,nt+U/2+s*.35,l.signed(N.v),{"text-anchor":"end",fill:st?a.offsetText:a.text,"font-size":s,"font-weight":700,class:"vpa-val"}),N.kind==="factor"){var Et=N.obj.ifFixed.zone;u(Q,f,nt+U/2+s*.35,"\u2192 "+k._zoneName(Et),{"text-anchor":"end",fill:a.zoneText[Et],"font-size":s-1,"font-weight":600,class:"vpa-zonefix"}),t.points[N.obj.key]={x:st?at:zt,y:nt}}t.items.push({kind:N.kind,obj:N.obj,x:0,y:B-A,w:f,h:S+A,px:st?at:zt,py:nt})});var Z=["Shares add up to the unexplained volatility of \xB1"+l.value(n.sdUnexplained)+" a day over "+n.window+" days"];n.factors.some(function(N){return!N.modelled})&&Z.push("* "+o.notModelled+" (RTPL taken as zero)"),Z.push("\u201C"+o.ifFixed+"\u201D: test zone with that factor's RTPL set equal to its HPL");var P=X+s+8;return Z.forEach(function(N){u(b,0,P,Ft(N+".",f,s-1,400,m),{fill:a.mutedText,"font-size":s-1,class:"vpa-note"}),P+=s+3}),Math.ceil(P-s+6)},r.prototype._drawDaily=function(t){var n=t.res,a=t.theme,l=t.f,o=t.L,s=t.fs,m=t.family,f=t.W,b=t.svg,k=n.dates.length,y=n.hpl.concat(n.rtpl,n.unexplained),x=i(Math.min(0,Math.min.apply(null,y)),Math.max(0,Math.max.apply(null,y)),f<480?4:6),M=Math.max.apply(null,x.ticks.map(function(B){return ht(l.value(B),s-1,400,m)})),d=M+10,T=f-4,C=6,R=f<480?220:300,O=C+R,j=function(B){return d+(B+.5)/k*(T-d)},E=function(B){return C+(x.hi-Rt(B,x.lo,x.hi))/(x.hi-x.lo)*R},S=I("g",{class:"vpa-daily"},b);n.start>0&&I("rect",{x:d,y:C,width:j(n.start)-(T-d)/k/2-d,height:R,fill:a.outside,"fill-opacity":.35,class:"vpa-outside"},S),x.ticks.forEach(function(B){I("line",{x1:d,x2:T,y1:E(B),y2:E(B),stroke:B===0?a.axis:a.grid,"stroke-width":B===0?1.2:1},S),u(S,d-6,E(B)+(s-1)*.35,l.value(B),{"text-anchor":"end",fill:a.axisText,"font-size":s-1,class:"vpa-tick"})});var A=Math.max(.6,(T-d)/k*.7);n.unexplained.forEach(function(B,U){var nt=E(Math.max(0,B)),st=E(Math.min(0,B));I("rect",{x:j(U)-A/2,y:nt,width:A,height:Math.max(.6,st-nt),fill:a.unexplained,"fill-opacity":U<n.start?.4:.85,class:"vpa-grow vpa-ubar"},S)});var H=function(B){return B.map(function(U,nt){return(nt?"L":"M")+j(nt).toFixed(2)+","+E(U).toFixed(2)}).join("")};I("path",{d:H(n.hpl),fill:"none",stroke:a.hpl,"stroke-width":1.6,"stroke-linejoin":"round",class:"vpa-line vpa-hpl"},S),I("path",{d:H(n.rtpl),fill:"none",stroke:a.rtpl,"stroke-width":1.6,"stroke-dasharray":"4 2","stroke-linejoin":"round",class:"vpa-line vpa-rtpl"},S);for(var lt=ht(n.dates[0],s-1,400,m)+16,tt=Math.max(1,Math.ceil(lt/((T-d)/k))),D=-1/0,K=0;K<k;K+=tt){var q=j(K),X=ht(n.dates[K],s-1,400,m),Q=q-X/2<0?"start":q+X/2>f?"end":"middle",Z=Q==="start"?q:Q==="end"?q-X:q-X/2;Z<D+8||(D=Z+X,u(S,q,O+s+9,n.dates[K],{"text-anchor":Q,fill:a.axisText,"font-size":s-1,class:"vpa-tick"}))}var P=(T-d)/k;n.dates.forEach(function(B,U){t.items.push({kind:"day",index:U,x:j(U)-P/2,y:C,w:P,h:R,px:j(U),py:E(Math.max(n.hpl[U],n.rtpl[U]))}),t.points["date:"+B]={x:j(U),y:E(Math.max(n.hpl[U],n.rtpl[U]))}});var N=["Unexplained P&L \xB1"+l.value(n.sdUnexplained)+" a day ("+(n.volRatio!=null?l.percent(n.volRatio,0)+" of HPL volatility":"")+") over the last "+n.window+" days"],F=O+s*2+17;return N.forEach(function(B){u(b,0,F,Ft(B+".",f,s-1,400,m),{fill:a.mutedText,"font-size":s-1,class:"vpa-note"}),F+=s+3}),Math.ceil(F-s+6)},r.prototype._drawDistribution=function(t){var n=t.res,a=t.theme,l=t.f,o=t.L,s=t.fs,m=t.family,f=t.W,b=t.svg,k=n.distribution,y=k.hpl.length,x=n.thresholds,M=Math.min(k.hpl[0],k.rtpl[0]),d=Math.max(k.hpl[y-1],k.rtpl[y-1]),T=i(M,d,f<480?4:6),C=ht("100%",s-1,400,m)+10,R=f-6,O=8,j=f<480?200:270,E=O+j,S=function(at){return C+(Rt(at,T.lo,T.hi)-T.lo)/(T.hi-T.lo)*(R-C)},A=function(at){return O+(1-at)*j},H=I("g",{class:"vpa-dist"},b);[0,.25,.5,.75,1].forEach(function(at){I("line",{x1:C,x2:R,y1:A(at),y2:A(at),stroke:at===0?a.axis:a.grid},H),u(H,C-6,A(at)+(s-1)*.35,Math.round(at*100)+"%",{"text-anchor":"end",fill:a.axisText,"font-size":s-1,class:"vpa-tick"})}),_(t,H,T,S,E+8,C,R,O,E,function(at){return l.value(at)});var lt=function(at){var zt="M"+S(T.lo)+","+A(0);return at.forEach(function(mt,gt){zt+="L"+S(mt).toFixed(2)+","+A(gt/y).toFixed(2)+"L"+S(mt).toFixed(2)+","+A((gt+1)/y).toFixed(2)}),zt+"L"+S(T.hi)+","+A(1)};I("path",{d:lt(k.hpl),fill:"none",stroke:a.hpl,"stroke-width":1.8,class:"vpa-line vpa-hpl"},H),I("path",{d:lt(k.rtpl),fill:"none",stroke:a.rtpl,"stroke-width":1.8,"stroke-dasharray":"4 2",class:"vpa-line vpa-rtpl"},H);var tt=function(at,zt){for(var mt=0,gt=at.length;mt<gt;){var Et=mt+gt>>1;at[Et]<=zt?mt=Et+1:gt=Et}return mt/at.length},D=n.test.ksAt,K=tt(k.hpl,D),q=tt(k.rtpl,D),X=S(D),Q=n.test.zone;I("line",{x1:X,x2:X,y1:A(K),y2:A(q),stroke:a.zoneText[Q],"stroke-width":3,class:"vpa-ksline"},H);var Z="KS "+c(n.test.ks),P=ht(Z,s,700,m),N=X+8+P>f?X-8:X+8;I("rect",{x:(X+8+P>f?N-P:N)-3,y:(A(K)+A(q))/2-s*.7,width:P+6,height:s*1.4,rx:3,fill:t.bg,class:"vpa-lbg"},H),u(H,N,(A(K)+A(q))/2+s*.35,Z,{"text-anchor":X+8+P>f?"end":"start",fill:a.zoneText[Q],"font-size":s,"font-weight":700,class:"vpa-kslabel"});for(var F=0;F<=20;F++){var B=T.lo+(T.hi-T.lo)*F/20,U=(R-C)/20;t.items.push({kind:"point",value:B,ph:tt(k.hpl,B),pr:tt(k.rtpl,B),x:S(B)-U/2,y:O,w:U,h:j,px:S(B),py:A(Math.max(tt(k.hpl,B),tt(k.rtpl,B)))})}var nt=["Spearman "+c(n.test.spearman)+" (green above "+x.spearmanGreen.toFixed(2)+", red below "+x.spearmanRed.toFixed(2)+") \xB7 KS "+c(n.test.ks)+" (green below "+x.ksGreen.toFixed(2)+", red above "+x.ksRed.toFixed(2)+")","Share of the "+n.window+" days with P&L at or below each value"],st=E+s*2+12;return nt.forEach(function(at){u(b,0,st,Ft(at+".",f,s-1,400,m),{fill:a.mutedText,"font-size":s-1,class:"vpa-note"}),st+=s+3}),Math.ceil(st-s+6)},r.prototype._tipLines=function(t){var n=this.options,a=ut(n.data,n.locale),l=this._labels(),o=this._res,s=this;if(t.kind==="other")return[$t(l.other,{n:t.obj.count}),"Together "+a.signed(t.obj.contribution)+" of the unexplained volatility"];if(t.kind==="day"){var m=t.index,f=o.factors.map(function(y){return{l:y.label,g:y.gap[m]}}).filter(function(y){return y.g!==0}).sort(function(y,x){return Math.abs(x.g)-Math.abs(y.g)}).slice(0,3);return[o.dates[m]+(m<o.start?" \xB7 "+l.outside.toLowerCase():""),l.hpl+" "+a.signed(o.hpl[m]),l.rtpl+" "+a.signed(o.rtpl[m]),l.unexplained+" "+a.signed(o.unexplained[m])].concat(f.length?["Largest gaps: "+f.map(function(y){return y.l+" "+a.signed(y.g)}).join(", ")]:[])}if(t.kind==="point")return["P&L at or below "+a.signed(t.value),"HPL "+a.percent(t.ph,0)+" of days \xB7 RTPL "+a.percent(t.pr,0),"Gap "+a.percent(Math.abs(t.ph-t.pr),0)+" (KS is the largest gap: "+c(o.test.ks)+")"];var b=t.obj,k=b.ifFixed;return[b.label+(b.modelled?"":" ("+l.notModelled+")"),b.group+" \xB7 rank "+b.rank+" of "+o.factors.length,"Share of unexplained volatility "+a.signed(b.contribution)+" ("+a.percent(b.share,0)+")","Gap on its own \xB1"+a.value(b.sdGap)+" a day \xB7 mean "+a.signed(b.meanGap),"HPL "+a.signed(b.hplSum)+" \xB7 RTPL "+a.signed(b.rtplSum)+" over "+o.window+" days",l.ifFixed+": "+s._zoneName(k.zone).toLowerCase()+" (Spearman "+c(k.spearman)+", KS "+c(k.ks)+")"]},r.prototype._detail=function(t){if(!t)return null;var n=this._res,a=this._view;if(t.kind==="other")return{view:a,kind:"other",count:t.obj.count,contribution:t.obj.contribution,factors:t.obj.factors.map(function(s){return s.key})};if(t.kind==="day"){var l=t.index;return{view:a,kind:"day",date:n.dates[l],hpl:n.hpl[l],rtpl:n.rtpl[l],unexplained:n.unexplained[l],inWindow:l>=n.start,gaps:n.factors.map(function(s){return{key:s.key,gap:s.gap[l]}})}}if(t.kind==="point")return{view:a,kind:"point",value:t.value,hplShare:t.ph,rtplShare:t.pr};var o=t.obj;return{view:a,kind:"factor",key:o.key,label:o.label,group:o.group,modelled:o.modelled,fixed:o.fixed,rank:o.rank,contribution:o.contribution,share:o.share,sdGap:o.sdGap,meanGap:o.meanGap,hplSum:o.hplSum,rtplSum:o.rtplSum,ifFixed:{spearman:o.ifFixed.spearman,ks:o.ifFixed.ks,zone:o.ifFixed.zone}}},r.prototype.howToRead=function(){var t=this._view||this.options.view;return t==="daily"?"The dark line is front-office hypothetical P&L (HPL) and the dashed line the risk model's P&L (RTPL), day by day. Grey bars are the difference, the unexplained P&L. Only the most recent days, inside the test window, count for the test.":t==="distribution"?"Each line shows the share of days with P&L at or below a value, for HPL and for RTPL. If the risk model matched the front office, the two lines would sit on top of each other. The coloured bar marks the largest gap between them, the Kolmogorov-Smirnov (KS) statistic.":"Each bar is one risk factor's share of the unexplained P&L volatility (HPL \u2212 RTPL). Shares add up exactly to the total; a bar to the left means the factor's gap offsets other gaps. The diamond is the factor's gap on its own, and the right column shows the test zone the desk would reach if that factor's gap were closed."},r.prototype.describe=function(){var t=this.options,n=ut(t.data,t.locale),a=this._labels(),l=this._res||g(t.data,this._opts()),o=l.test,s=l.thresholds,m=[],f=this,b=[];(o.spearman==null||o.spearman<=s.spearmanGreen)&&b.push("Spearman "+c(o.spearman)+(o.spearman!=null&&o.spearman>=s.spearmanRed?" is below "+s.spearmanGreen.toFixed(2):" is below "+s.spearmanRed.toFixed(2))),o.ks>=s.ksGreen&&b.push("KS "+c(o.ks)+(o.ks<=s.ksRed?" is above "+s.ksGreen.toFixed(2):" is above "+s.ksRed.toFixed(2))),m.push("Over the last "+l.window+" days the desk is in the "+this._zoneName(o.zone).toLowerCase()+" zone of the P&L attribution test"+(b.length?": "+b.join(" and ")+".":" (Spearman "+c(o.spearman)+", KS "+c(o.ks)+").")),m.push("Unexplained P&L is \xB1"+n.value(l.sdUnexplained)+" a day"+(l.volRatio!=null?", "+n.percent(l.volRatio,0)+" of the front office's P&L volatility":"")+".");var k=l.order[0],y=l.order[1];m.push(k.label+(k.modelled?"":", which is not in the risk model,")+" explains "+n.percent(k.share,0)+" of it"+(y?", followed by "+y.label+" ("+n.percent(y.share,0)+")":"")+".");var x=l.factors.filter(function(d){return d.share<-.02}).sort(function(d,T){return d.contribution-T.contribution});if(x.length&&m.push("The gap on "+x[0].label+" partly offsets the others."),o.zone!=="green")if(l.pathReachesGreen){var M=l.path[l.path.length-1].test;m.push("Closing the gap on "+l.path.map(function(d){return d.label}).join(" and ")+" would bring the desk to green (Spearman "+c(M.spearman)+", KS "+c(M.ks)+").")}else l.path.length&&m.push("Even closing the gaps on "+l.path.map(function(d){return d.label}).join(", ")+" only reaches "+this._zoneName(l.path[l.path.length-1].test.zone).toLowerCase()+".");return l.fixed.length&&m.push("Fixes applied: "+l.fixed.join(", ")+"."),m.join(" ")},r.prototype.getExportData=function(){var t=this.options,n=t.data,a=this._labels(),l=ut(n,t.locale),o=this._res||g(n,this._opts()),s=this,m=o.thresholds,f={prefix:n.prefix||"",suffix:n.suffix||"",decimals:n.decimals!=null?n.decimals:0,negatives:n.negatives},b=function(E){return{label:E,type:"number",unit:f}},k=function(E){return{label:E,type:"number",unit:{decimals:3}}},y=function(E){return{label:E,type:"percent",decimals:1}},x=function(E){return{label:E,type:"text"}},M=[];M.push({name:"Factors",columns:[{label:"Rank",type:"number",unit:{decimals:0}},x("Risk factor"),x("Group"),x("In risk model"),x("Fixed"),b("HPL over window"),b("RTPL over window"),b("Mean daily gap"),b("Gap volatility"),b("Share of unexplained volatility"),y("Share (%)"),k("Spearman if fixed"),k("KS if fixed"),x("Zone if fixed")],rows:o.order.map(function(E){return[E.rank,E.label,E.group,E.modelled?"Yes":"No",E.fixed?"Yes":"No",E.hplSum,E.rtplSum,E.meanGap,E.sdGap,E.contribution,E.share,E.ifFixed.spearman,E.ifFixed.ks,s._zoneName(E.ifFixed.zone)]}),text:o.order.map(function(E){return[String(E.rank),E.label,E.group,E.modelled?"Yes":"No",E.fixed?"Yes":"No",l.signed(E.hplSum),l.signed(E.rtplSum),l.signed(E.meanGap),l.value(E.sdGap),l.signed(E.contribution),l.percent(E.share),c(E.ifFixed.spearman),c(E.ifFixed.ks),s._zoneName(E.ifFixed.zone)]}),flag:o.order.map(function(E){return!E.modelled})});for(var d=t.exportDays!=null?t.exportDays:2e4,T=Math.max(0,o.dates.length-d),C=[],R=T;R<o.dates.length;R++)C.push(R);M.push({name:"Daily",columns:[x("Date"),b("HPL"),b("RTPL"),b("Unexplained"),x("In test window")],rows:C.map(function(E){return[o.dates[E],o.hpl[E],o.rtpl[E],o.unexplained[E],E>=o.start?"Yes":"No"]}),text:C.map(function(E){return[o.dates[E],l.signed(o.hpl[E]),l.signed(o.rtpl[E]),l.signed(o.unexplained[E]),E>=o.start?"Yes":"No"]})});var O=[["Spearman correlation",o.test.spearman,"green above "+m.spearmanGreen+", red below "+m.spearmanRed],["Kolmogorov-Smirnov statistic",o.test.ks,"green below "+m.ksGreen+", red above "+m.ksRed],["Unexplained volatility \xF7 HPL volatility",o.volRatio,""],["Mean unexplained \xF7 HPL volatility",o.meanRatio,""],["Variance of unexplained \xF7 variance of HPL",o.varRatio,""]];o.path.forEach(function(E,S){O.push(["Path step "+(S+1)+": fix "+E.label+" \u2192 Spearman",E.test.spearman,s._zoneName(E.test.zone)],["Path step "+(S+1)+": fix "+E.label+" \u2192 KS",E.test.ks,s._zoneName(E.test.zone)])}),M.push({name:"Test",columns:[x("Measure"),k("Value"),x("Note")],rows:O,text:O.map(function(E){return[E[0],E[1]==null?"n/a":E[1].toFixed(3),E[2]]})});var j=(t.annotations||[]).map(function(E,S){return[String(S+1),E.factor!=null?String(E.factor):"Date: "+String(E.date||""),E.text||""]});return j.length&&M.push({name:"Notes",columns:[x("No."),x("Factor or date"),x("Note")],rows:j}),{title:n.title||"P&L attribution",subtitle:n.subtitle||"",summary:this.describe(),library:"Veyforma P&L Attribution "+Ct,sheets:M,meta:[["Unit",n.unit],["As of",n.asOf],["Desk",n.desk],["Test window",o.window+" days ("+o.dates[o.start]+" to "+o.dates[o.dates.length-1]+")"],["PLA test zone",s._zoneName(o.test.zone)+" (Spearman "+c(o.test.spearman)+", KS "+c(o.test.ks)+")"],["Fixes applied",o.fixed.length?o.fixed.join(", "):null],["Method","Spearman = correlation of the ranks of daily HPL and RTPL (ties averaged); KS = largest gap between their empirical distribution functions; green if Spearman > "+m.spearmanGreen+" and KS < "+m.ksGreen+", red if Spearman < "+m.spearmanRed+" or KS > "+m.ksRed+`, otherwise amber; factor share = cov(gap, unexplained) \xF7 sd(unexplained), adds up to sd(unexplained); "if fixed" sets that factor's RTPL equal to its HPL`+(T>0?"; daily sheet limited to the last "+d+" days":"")],["Data source",n.source]]}},r.prototype._annotationPoint=function(t){var n=this._points||{};return t.factor!=null?n[String(t.factor)]||null:t.date!=null&&n["date:"+String(t.date)]||null},r.prototype._annotationTarget=function(t){var n=this._items||[],a=null;if(!t)a=n[this._active];else for(var l=this.plotHost.querySelector("svg"),o=l.getBoundingClientRect(),s=l.viewBox.baseVal,m=(t.clientX-o.left)*(s.width/o.width),f=(t.clientY-o.top)*(s.height/o.height),b=0;b<n.length;b++){var k=n[b];if(m>=k.x&&m<=k.x+k.w&&f>=k.y&&f<=k.y+k.h){a=k;break}}return a?a.kind==="factor"?{factor:a.obj.key}:a.kind==="day"?{date:this._res.dates[a.index]}:null:null},r.prototype._annotationLabel=function(t){if(t.date!=null)return String(t.date);var n=(this._res||this.getResult()).factors.filter(function(a){return a.key===String(t.factor)})[0];return n?n.label:String(t.factor||"")},Y.VeyPlaAttribution={version:Ct,create:function(t,n){return new r(t,n)},compute:function(t,n){return g(t,n)},test:function(t,n,a){return W(t,n,bt({},At,a||{}))},thresholds:At,listThemes:function(){return Object.keys(Mt)},getTheme:function(t){return e(t)},defaults:{options:ft,labels:wt,theme:_t}}})(typeof window<"u"?window:void 0);(function(Y){"use strict";function Ct(kt){var St=Y[kt];if(!St)throw new Error("VeyformaCharts: "+kt+" is not loaded. Load its script before veyforma-charts.js, or use the bundled dist/veyforma-charts.js.");return St}Y.VeyformaCharts={version:"1.0.2",heatmap:function(kt,St){return Ct("VeyHeatmap").create(kt,St)},tornado:function(kt,St){return Ct("VeyRiskTornado").create(kt,St)},plaAttribution:function(kt,St){return Ct("VeyPlaAttribution").create(kt,St)}}})(typeof window<"u"?window:void 0);
|