@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.
@@ -0,0 +1,2 @@
1
+ /*! @veyforma/charts v1.0.2 · MIT License · Copyright (c) 2026 Veyforma · https://github.com/veyforma/veyforma-charts */
2
+ (function(I){"use strict";var Pt="1.2.0",fe="http://www.w3.org/2000/svg",ce=0,bt={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},st={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 ut(t){if((t==null||t==="")&&(t="veyforma"),typeof t=="string")return st.hasOwnProperty(t)||(Mt('Unknown theme "'+t+'". The "veyforma" theme is used instead.'),t="veyforma"),S({},bt,st[t]);if(typeof t!="object")return Mt("The theme option must be a theme name or an object."),S({},bt);var r=t.extends?ut(t.extends):S({},bt),o=S(r,t);return delete o.extends,["low","mid","high","empty"].forEach(function(e){ft(o[e])||(Mt('Theme colour "'+e+'" must be a hex value such as "#9a3412". The default is used instead.'),o[e]=bt[e])}),o}function S(t){for(var r=1;r<arguments.length;r++){var o=arguments[r];if(o)for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=o[e])}return t}function At(t,r,o){return Math.min(o,Math.max(r,t))}function Mt(t){I.console&&I.console.warn("VeyHeatmap: "+t)}function R(t,r,o){var e=document.createElementNS(fe,t);if(r)for(var n in r)r[n]!=null&&e.setAttribute(n,r[n]);return o&&o.appendChild(e),e}function E(t,r,o){var e=document.createElement(t);return r&&(e.className=r),o&&o.appendChild(e),e}function ft(t){if(typeof t!="string")return null;var r=t.trim().replace(/^#/,"");if(r.length===3&&(r=r.split("").map(function(e){return e+e}).join("")),!/^[0-9a-fA-F]{6}$/.test(r))return null;var o=parseInt(r,16);return[o>>16&255,o>>8&255,o&255]}function he(t){return"#"+t.map(function(r){var o=Math.round(At(r,0,255)).toString(16);return o.length<2?"0"+o:o}).join("")}function It(t,r,o){return[t[0]+(r[0]-t[0])*o,t[1]+(r[1]-t[1])*o,t[2]+(r[2]-t[2])*o]}function me(t){var r=ft(t.low),o=ft(t.mid),e=ft(t.high);return function(n){return n=At(n,0,1),he(n<.5?It(r,o,n*2):It(o,e,(n-.5)*2))}}function Gt(t,r){var o=qt(t),e=qt(r);return(Math.max(o,e)+.05)/(Math.min(o,e)+.05)}function qt(t){var r=ft(t);if(!r)return 1;var o=r.map(function(e){return e/=255,e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)});return .2126*o[0]+.7152*o[1]+.0722*o[2]}var ct=null;function z(t,r,o,e){if(!ct){var n=document.createElement("canvas");ct=n.getContext&&n.getContext("2d")}return ct?(ct.font=(o||400)+" "+r+"px "+e,ct.measureText(String(t)).width):String(t).length*r*.6}function Ut(t,r,o,e,n){if(t=String(t),z(t,o,e,n)<=r)return t;for(var a=0,s=t.length;a<s;){var f=Math.ceil((a+s)/2);z(t.slice(0,f)+"\u2026",o,e,n)<=r?a=f:s=f-1}return a>0?t.slice(0,a).replace(/\s+$/,"")+"\u2026":""}function pe(t,r,o,e,n){for(var a=String(t).split(/\s+/),s=[],f="",m=0;m<a.length;m++){var c=f?f+" "+a[m]:a[m];z(c,o,e,n)>r&&f?(s.push(f),f=a[m]):f=c}f&&s.push(f);var C=s.length<=2&&s.every(function(v){return z(v,o,e,n)<=r});return C?s:null}function at(t){var r=Math.round(t*1e4)/100;return String(r)+"%"}function gt(t,r){var o=t.decimals!=null?t.decimals:0,e=t.prefix||"",n=t.suffix||"",a={};function s(v,h){return a[v]||(a[v]=new Intl.NumberFormat(r||void 0,h)),a[v]}function f(v,h){h==null&&(h=o);var d=Math.pow(10,-h);if(v>0&&v<d/2)return"<"+e+s("f"+h,{minimumFractionDigits:h,maximumFractionDigits:h}).format(d)+n;var w=e+s("f"+h,{minimumFractionDigits:h,maximumFractionDigits:h}).format(Math.abs(v))+n;return v>=0?w:t.negatives==="brackets"?"("+w+")":"\u2212"+w}function m(v){return n?f(v,0):(v<0?"\u2212":"")+e+s("c",{notation:"compact",maximumFractionDigits:1}).format(Math.abs(v))}function c(v,h){return h==null&&(h=1),s("p"+h,{minimumFractionDigits:h,maximumFractionDigits:h}).format(v*100)+"%"}function C(v){return s("n",{maximumFractionDigits:0}).format(v)}return{value:f,compact:m,percent:c,count:C}}function F(t,r){return String(t).replace(/\{(\w+)\}/g,function(o,e){return r[e]!=null?r[e]:o})}var Yt="\0other";function ve(t){if(Array.isArray(t.values)){var r=t.rowLabels,o=t.columnLabels,e=W&&W.get(t.values);if(e&&e.grid&&e.gridRows===r&&e.gridCols===o)return e.grid;if(!Array.isArray(r)||!Array.isArray(o))throw new Error("VeyHeatmap: a values grid needs rowLabels and columnLabels.");if(t.values.length!==r.length)throw new Error("VeyHeatmap: values has "+t.values.length+" rows but rowLabels has "+r.length+".");var n=[];t.values.forEach(function(c,C){if(!Array.isArray(c)||c.length!==o.length)throw new Error("VeyHeatmap: row "+(C+1)+" of values needs "+o.length+" numbers.");c.forEach(function(v,h){n.push({row:r[C],column:o[h],value:v})})});var a={records:n,rows:"row",columns:"column",dimensions:{row:{label:t.rowTitle||"Row",order:r.slice(),ordered:!0},column:{label:t.columnTitle||"Column",order:o.slice(),ordered:!0}}};if(W){var s=W.get(t.values)||{};s.grid=a,s.gridRows=r,s.gridCols=o,W.set(t.values,s)}return a}if(!Array.isArray(t.records)||!t.records.length)throw new Error("VeyHeatmap: data needs records, or values with rowLabels and columnLabels.");var f=Object.keys(t.records[0]).filter(function(c){return c!=="value"}),m=S({},t.dimensions||{});return f.forEach(function(c){m[c]||(m[c]={label:c.charAt(0).toUpperCase()+c.slice(1)})}),{records:t.records,rows:t.rows||f[0],columns:t.columns||f[1],dimensions:m}}var W=typeof WeakMap=="function"?new WeakMap:null;function de(t,r,o,e){var n=r+""+o,a=W&&e?W.get(e):null;if(a&&a[n])return a[n];for(var s=new Map,f=new Map,m=new Map,c=0,C=t.records,v=C.length,h=0;h<v;h++){var d=C[h],w=d[r],A=d[o];if(w==null||w==="")throw new Error("VeyHeatmap: record "+(h+1)+' has no "'+r+'".');if(A==null||A==="")throw new Error("VeyHeatmap: record "+(h+1)+' has no "'+o+'".');var u=d.value,y=typeof u=="number"?u:Number(u);if(u==null||u===""||!isFinite(y))throw new Error("VeyHeatmap: record "+(h+1)+" has no numeric value.");if(y<0)throw new Error("VeyHeatmap: record "+(h+1)+" is negative. Exposure values must be zero or more.");typeof w!="string"&&(w=String(w)),typeof A!="string"&&(A=String(A));var T=s.get(w);T||(T=new Map,s.set(w,T),f.set(w,0)),T.set(A,(T.get(A)||0)+y),f.set(w,f.get(w)+y),m.set(A,(m.get(A)||0)+y),c+=y}var O=function(b){var H={};return b.forEach(function(j,B){H[B]=j}),H},x={cell:function(b,H){var j=s.get(b);return j&&j.get(H)||0},rowTot:O(f),colTot:O(m),rowSeen:Array.from(f.keys()),colSeen:Array.from(m.keys()),total:c};return W&&e&&(a||(a={},W.set(e,a)),a[n]=x),x}function X(t,r,o){var e=ve(t),n=r.rows||e.rows,a=r.columns||e.columns;if(!n||!a)throw new Error("VeyHeatmap: choose a field for the rows and a field for the columns.");if(n===a)throw new Error('VeyHeatmap: rows and columns cannot both use "'+n+'".');var s=S({label:n},e.dimensions[n]),f=S({label:a},e.dimensions[a]),m=de(e,n,a,Array.isArray(t.values)?t.values:t.records),c=m.rowTot,C=m.colTot,v=m.rowSeen,h=m.colSeen,d=m.total;function w(T,O,x,b,H){var j=T.slice();if(Array.isArray(x.order)){var B=x.order.map(String);j.sort(function(_,D){var tt=B.indexOf(_),et=B.indexOf(D);return tt<0&&(tt=B.length+T.indexOf(_)),et<0&&(et=B.length+T.indexOf(D)),tt-et})}var N=j.slice().sort(function(_,D){return O[D]-O[_]||j.indexOf(_)-j.indexOf(D)}),Y=b==="total"||b!=="natural"&&!x.ordered,G=Y?N:j,Z=G.map(function(_){return{key:_,label:_,members:[_]}});if(H&&H>0&&G.length>H+1){var nt=N.slice(0,H),ht=G.filter(function(_){return nt.indexOf(_)>=0}),wt=G.filter(function(_){return nt.indexOf(_)<0});Z=ht.map(function(_){return{key:_,label:_,members:[_]}}),Z.push({key:Yt,label:F(o.other,{count:wt.length}),members:wt,other:!0})}return Z.forEach(function(_){_.total=_.members.reduce(function(D,tt){return D+O[tt]},0)}),Z}var A=w(v,c,s,r.sortRows,r.topRows),u=w(h,C,f,r.sortColumns,r.topColumns),y=A.map(function(T){return u.map(function(O){var x=0;return T.members.forEach(function(b){O.members.forEach(function(H){x+=m.cell(b,H)})}),x})});return{rowKey:n,colKey:a,rowDim:s,colDim:f,rows:A,cols:u,values:y,total:d}}function Kt(t,r){var o=[],e=0;t.values.forEach(function(s,f){s.forEach(function(m,c){var C=t.total>0?m/t.total:0;e+=C*C*1e4,o.push({r:f,c,value:m,share:C})})}),o.sort(function(s,f){return f.value-s.value});var n=o.slice(0,5).reduce(function(s,f){return s+f.share},0),a=r>0?o.filter(function(s){return s.share>r+1e-12}):[];return{hhi:e,effective:e>0?1e4/e:0,largest:o[0],top5:n,above:a}}var be={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},ge={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 we(){if(!document.getElementById("vhm-styles")){var t=".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}",r=document.createElement("style");r.id="vhm-styles",r.appendChild(document.createTextNode(t)),(document.head||document.documentElement).appendChild(r)}}function L(t,r){var o=typeof t=="string"?document.querySelector(t):t;if(!o||o.nodeType!==1)throw new Error("VeyHeatmap: container not found ("+t+").");if(!r||!r.data)throw new Error("VeyHeatmap: options.data is required.");we(),this.id=++ce,this.container=o,this.options=S({},be,r),this.element=E("div","vhm"),this.summaryEl=E("div","vhm-summary",this.element),this.legendEl=E("div","vhm-legend",this.element),this.plotHost=E("div","vhm-plot-host",this.element),this.noteEl=E("div","vhm-scroll-note",this.element),this.tipEl=E("div","vhm-tip",this.element),this.tipEl.setAttribute("role","tooltip"),this.tipEl.id="vhm-tip-"+this.id,o.appendChild(this.element),this._animateNext=!!this.options.animate,this._lastWidth=0,this._active=null;var e=this;I.ResizeObserver?(this._observer=new I.ResizeObserver(function(){var n=Math.round(e.element.clientWidth);n&&n!==e._lastWidth&&e.redraw()}),this._observer.observe(this.element)):(this._onResize=function(){e.redraw()},I.addEventListener("resize",this._onResize)),this._onDocTap=function(n){e.element.contains(n.target)||e._hideTip()},document.addEventListener("pointerdown",this._onDocTap),this.redraw(),this.options.toolbar!==!1&&I.VeyformaToolkit&&(this.toolkit=I.VeyformaToolkit.attach(this,this.options.toolbar))}L.prototype.update=function(t){return t?(t.data&&t.data!==this.options.data&&this.options.animate&&(this._animateNext=!0,this._active=null),(t.rows||t.columns||t.topRows!=null||t.topColumns!=null)&&(this._active=null),t.animate===!0&&(this._animateNext=!0),S(this.options,t),this.redraw()):this},L.prototype.setData=function(t){return W&&t&&(Array.isArray(t.records)&&W.delete(t.records),Array.isArray(t.values)&&W.delete(t.values)),this.update({data:t})},L.prototype.setTheme=function(t){return this.update({theme:t})},L.prototype.getTheme=function(){return ut(this.options.theme)},L.prototype._labels=function(){return S({},ge,this.options.labels)},L.prototype._limit=function(){var t=this.options,r=t.limit!==void 0?t.limit:t.data.limit&&t.data.limit.share;return r=Number(r),isFinite(r)&&r>0&&r<1?r:0},L.prototype.getMatrix=function(){var t=X(this.options.data,this.options,this._labels()),r=function(o){return{key:o.key===Yt?null:o.key,label:o.label,total:o.total,other:!!o.other,members:o.members.slice()}};return{rowField:t.rowKey,columnField:t.colKey,rows:t.rows.map(r),columns:t.cols.map(r),values:t.values.map(function(o){return o.slice()}),total:t.total}},L.prototype.getStats=function(){var t=X(this.options.data,S({},this.options,{topRows:0,topColumns:0}),this._labels()),r=this._limit(),o=Kt(t,r),e=function(n){return{row:t.rows[n.r].label,column:t.cols[n.c].label,value:n.value,share:n.share}};return{total:t.total,rows:t.rows.length,columns:t.cols.length,hhi:o.hhi,effectiveCells:o.effective,top5Share:o.top5,largest:o.largest?e(o.largest):null,limit:r||null,aboveLimit:o.above.map(e)}},L.prototype.createTable=function(){var t=this.options,r=t.data,o=this._labels(),e=X(r,t,o),n=gt(r,t.locale),a=document.createElement("table");if(a.className="vhm-table",r.title){var s=E("caption",null,a);s.textContent=r.title,s.style.cssText="text-align:left;font-weight:600;padding:0 6px 6px"}var f=E("tr",null,E("thead",null,a)),m=E("th",null,f);m.scope="col",m.textContent=e.rowDim.label,e.cols.forEach(function(h){var d=E("th",null,f);d.scope="col",d.textContent=h.label});var c=E("th",null,f);c.scope="col",c.textContent=o.total;var C=E("tbody",null,a);e.rows.forEach(function(h,d){var w=E("tr",null,C),A=E("th",null,w);A.scope="row",A.textContent=h.label,A.style.textAlign="left",A.style.fontWeight="400",e.values[d].forEach(function(u){E("td",null,w).textContent=u?n.value(u):"\u2014"}),E("td",null,w).textContent=n.value(h.total)});var v=E("tr","vhm-total",C);return E("td",null,v).textContent=o.total,e.cols.forEach(function(h){E("td",null,v).textContent=n.value(h.total)}),E("td",null,v).textContent=n.value(e.total),a},L.prototype.destroy=function(){this.toolkit&&this.toolkit.destroy(),this._observer&&this._observer.disconnect(),this._onResize&&I.removeEventListener("resize",this._onResize),document.removeEventListener("pointerdown",this._onDocTap),this.element.parentNode&&this.element.parentNode.removeChild(this.element)},L.prototype._hideTip=function(){this.tipEl.classList.remove("vhm-on"),this._focusRect&&this._focusRect.setAttribute("opacity",0),this._boldReset&&this._boldReset()},L.prototype._placeTip=function(t,r,o){var e=this.tipEl;e.textContent="",t.forEach(function(v,h){h&&e.appendChild(document.createElement("br"));var d=h===0?document.createElement("b"):document.createTextNode("");d.textContent=v,e.appendChild(d)});var n=this.element.getBoundingClientRect(),a=o&&o.clientX?o.clientX:r.left+r.width/2,s=o&&o.clientY?o.clientY:r.top;e.classList.add("vhm-on");var f=e.offsetWidth,m=e.offsetHeight,c=At(a-n.left-f/2,4,Math.max(4,n.width-f-4)),C=s-n.top-m-14;C<0&&(C=(r.bottom!=null?r.bottom:s)-n.top+10),e.style.left=c+"px",e.style.top=C+"px"},L.prototype.redraw=function(){var t=this.options,r=t.data,o=this,e=ut(t.theme),n=this._labels(),a=X(r,t,n),s=gt(r,t.locale),f=t.topRows>0||t.topColumns>0?X(r,S({},t,{topRows:0,topColumns:0}),n):a,m=this._limit(),c=Kt(f,m),C=this.element,v=me(e),h=e.background&&e.background!=="transparent"?e.background:"#ffffff",d=e.fontFamily==="inherit"?I.getComputedStyle?I.getComputedStyle(this.container).fontFamily:"sans-serif":e.fontFamily,w=C.style;w.setProperty("--vhm-text",e.text),w.setProperty("--vhm-muted",e.mutedText),w.setProperty("--vhm-bg",e.background),w.setProperty("--vhm-font",d),w.setProperty("--vhm-focus",e.focus),w.setProperty("--vhm-tip-bg",e.tooltipBackground),w.setProperty("--vhm-tip-text",e.tooltipText),w.setProperty("--vhm-summary-bg",e.summaryBackground),C.classList.toggle("vhm-filled",!!e.background&&e.background!=="transparent"),C.classList.toggle("vhm-animate",!!this._animateNext);var A=Math.max(this.plotHost.clientWidth||C.clientWidth||0,280);this._lastWidth=Math.round(C.clientWidth);var u=A<560,y=Number(e.fontSize)||12,T=u?y-1.5:y-.5,O=u?y-2:y-1,x=t.cellHeight||(u?28:34),b=Math.max(0,Number(e.cellGap)||0),H=u?26:34,j=Math.max.apply(null,a.rows.map(function(i){return z(i.label,T,400,d)})),B=Math.min(Math.ceil(j)+12,Math.round(A*(u?.3:.26))),N=t.totals?Math.max(u?50:70,Math.ceil(z(s.value(Math.max.apply(null,a.rows.map(function(i){return i.total}))),y-1,600,d))+12):0;t.totals&&u&&(N=Math.min(N,64));var Y=t.totals?8:0,G=A-B-Y-N-2,Z=t.fit||"auto",nt=!1,ht=Math.floor(G/H),wt=Z==="group"||Z==="auto"&&!a.colDim.ordered&&!(t.topColumns>0);wt&&a.cols.length>ht&&ht>=3&&(a=X(r,S({},t,{topColumns:ht-1}),n),nt=!0);var _=a.rows.length,D=a.cols.length,tt=(a.rowDim.plural||a.rowDim.label).toLowerCase(),et=(a.colDim.plural||a.colDim.label).toLowerCase(),it=t.valueMode;["amount","shareOfTotal","shareOfRow","shareOfColumn"].indexOf(it)<0&&(it="amount");for(var $t=function(i,l){var g=a.values[i][l];return it==="shareOfTotal"?a.total?g/a.total:0:it==="shareOfRow"?a.rows[i].total?g/a.rows[i].total:0:it==="shareOfColumn"?a.cols[l].total?g/a.cols[l].total:0:g},rt=0,kt=0;kt<_;kt++)for(var Lt=0;Lt<D;Lt++)rt=Math.max(rt,$t(kt,Lt));var Jt=t.scale==="sqrt",xe=function(i){if(rt<=0)return 0;var l=i/rt;return Jt?Math.sqrt(l):l},Ot=function(i,l){return it==="amount"?l?s.compact(i):s.value(i):s.percent(i,l?0:1)},Rt=this.summaryEl;if(Rt.textContent="",Rt.style.display=t.summary?"":"none",t.summary){var mt=function(i,l,g){var p=E("div","vhm-stat",Rt);E("div","vhm-stat-label",p).textContent=i,E("div","vhm-stat-value",p).textContent=l,g&&(E("div","vhm-stat-note",p).textContent=g)};mt(n.totalExposure,s.value(a.total),F(n.gridNote,{rows:f.rows.length,rowDim:tt,cols:f.cols.length,colDim:et})),c.largest&&mt(n.largest,s.percent(c.largest.share),f.rows[c.largest.r].label+" \xD7 "+f.cols[c.largest.c].label+" \xB7 "+s.value(c.largest.value)),mt(n.hhi,s.count(c.hhi),F(n.hhiNote,{n:s.count(Math.round(c.effective))})),m?mt(n.aboveLimit,s.count(c.above.length),F(n.aboveNote,{limit:at(m)})):mt(n.top5,s.percent(c.top5),n.top5Note)}var pt=this.legendEl;if(pt.textContent="",pt.style.display=t.legend?"":"none",t.legend){var Qt=E("span","vhm-ramp",pt),ye=E("span","vhm-ramp-bar",Qt);ye.style.background="linear-gradient(to right,"+[0,.25,.5,.75,1].map(function(i){return v(i)}).join(",")+")";var Te=E("span","vhm-ramp-ticks",Qt),Ee=Jt?rt*.25:rt*.5;[0,Ee,rt].forEach(function(i){E("span",null,Te).textContent=Ot(i,!0)});var Zt=E("span",null,pt),Ce=R("svg",{width:14,height:14,"aria-hidden":"true"},Zt);if(R("rect",{x:1,y:1,width:12,height:12,rx:2,fill:e.empty,stroke:e.mutedText,"stroke-opacity":.45,"stroke-dasharray":"2 2"},Ce),Zt.appendChild(document.createTextNode(n.empty)),m){var te=E("span",null,pt),ee=R("svg",{width:14,height:14,"aria-hidden":"true"},te);R("rect",{x:1.5,y:1.5,width:11,height:11,rx:2,fill:v(.7),stroke:e.limit,"stroke-width":2},ee),R("rect",{x:3.5,y:3.5,width:7,height:7,rx:1,fill:"none",stroke:h,"stroke-width":1},ee),te.appendChild(document.createTextNode(F(n.limitLegend,{limit:at(m)})))}}var k=G/D,vt=!1;k<H&&(k=H,vt=!0),G=k*D;var Dt=a.cols.map(function(i){return pe(i.label,k-4,T,400,d)}),St=Dt.some(function(i){return i===null}),_e=Math.max.apply(null,a.cols.map(function(i){return z(i.label,T,400,d)})),re=Math.min(_e,140),xt=St?Math.ceil(re*.7071+T+10):Math.max.apply(null,Dt.map(function(i){return i.length}))*(T+3)+10,Ae=St?Math.max(0,re*.7071-N-Y):0,yt=B+G+Y+N+2+Ae;yt>A+.5&&(vt=!0);var oe=xt,Me=t.totals?x:0,ae=oe+_*x+(t.totals?Y+Me:0)+4,Ht=B,K=function(i){return Ht+i*k},V=function(i){return oe+i*x};this.plotHost.textContent="",this.noteEl.textContent=vt?F(n.scrollNote,{columns:et}):nt?F(n.groupNote,{columns:et}):"",this.noteEl.style.display=vt||nt?"":"none";var P=R("svg",{class:"vhm-plot",viewBox:"0 0 "+yt+" "+ae,width:yt,height:ae,tabindex:0,role:"img","aria-label":t.ariaLabel||[r.title,a.rowDim.label+" by "+a.colDim.label,c.largest?n.largest+": "+f.rows[c.largest.r].label+" \xD7 "+f.cols[c.largest.c].label+", "+s.percent(c.largest.share):null].filter(Boolean).join(". ")},this.plotHost);vt||(P.style.width="100%",P.style.height="auto");var $=function(i,l,g){var p=R("text",S({"font-family":d},i),g||P);return p.textContent=l,p},ne=[];a.cols.forEach(function(i,l){var g=K(l)+k/2,p=R("g",null,P);if(St){var M=xt-6;$({x:g-2,y:M,"text-anchor":"start",transform:"rotate(-45 "+(g-2)+" "+M+")","font-size":T,fill:i.other?e.mutedText:e.headerText},Ut(i.label,140,T,400,d),p)}else{var ot=Dt[l];ot.forEach(function(lt,He){$({x:g,y:xt-6-(ot.length-1-He)*(T+3),"text-anchor":"middle","font-size":T,fill:i.other?e.mutedText:e.headerText},lt,p)})}ne.push(p)}),t.totals&&$({x:Ht+G+Y+N-4,y:xt-6,"text-anchor":"end","font-size":T,"font-weight":600,fill:e.text},n.total);var ke=a.rows.map(function(i,l){var g=Ut(i.label,B-12,T,400,d),p=$({x:B-8,y:V(l)+x/2+T*.35,"text-anchor":"end","font-size":T,fill:i.other?e.mutedText:e.headerText},g);if(g!==i.label){var M=R("title",null,p);M.textContent=i.label}return p});t.totals&&$({x:B-8,y:V(_)+Y+x/2+T*.35,"text-anchor":"end","font-size":T,"font-weight":600,fill:e.text},n.total);for(var J=R("g",null,P),Le=t.cellLabels===!0||t.cellLabels==="auto",q=0;q<_;q++)for(var U=0;U<D;U++){var Tt=a.values[q][U],Nt=$t(q,U),zt=Tt>0?v(xe(Nt)):e.empty,dt=R("rect",{x:K(U)+b/2,y:V(q)+b/2,width:Math.max(k-b,1),height:Math.max(x-b,1),rx:Math.min(e.cellRadius,k/4),fill:zt,class:"vhm-cell","data-r":q,"data-c":U},J);if(Tt>0||(dt.setAttribute("stroke",e.mutedText),dt.setAttribute("stroke-opacity",.45),dt.setAttribute("stroke-dasharray","2 2"),dt.setAttribute("stroke-width",1)),dt.style.animationDelay=Math.min((q+U)*18,500)+"ms",m&&a.total>0&&Tt/a.total>m+1e-12&&!a.rows[q].other&&!a.cols[U].other&&(R("rect",{x:K(U)+b/2+1,y:V(q)+b/2+1,width:Math.max(k-b-2,1),height:Math.max(x-b-2,1),rx:Math.min(e.cellRadius,k/4),fill:"none",stroke:e.limit,"stroke-width":2,"pointer-events":"none"},J),R("rect",{x:K(U)+b/2+3,y:V(q)+b/2+3,width:Math.max(k-b-6,1),height:Math.max(x-b-6,1),rx:Math.max(0,Math.min(e.cellRadius,k/4)-1),fill:"none",stroke:h,"stroke-width":1,"pointer-events":"none"},J)),Le&&Tt>0&&x-b>=16){var ie=k-b-8,Et=Ot(Nt,!1);if(z(Et,O,500,d)>ie&&(Et=Ot(Nt,!0)),z(Et,O,500,d)<=ie){var Oe=Gt(zt,e.cellTextOnDark)>Gt(zt,e.cellText)?e.cellTextOnDark:e.cellText;$({x:K(U)+k/2,y:V(q)+x/2+O*.35,"text-anchor":"middle","font-size":O,"font-weight":500,fill:Oe,"pointer-events":"none",class:"vhm-cell-label"},Et,J)}}}var Q=null;if(t.totals){Q=R("g",null,P);var Re=Math.max.apply(null,a.rows.map(function(i){return i.total}))||1,De=Math.max.apply(null,a.cols.map(function(i){return i.total}))||1,Ft=Ht+G+Y;a.rows.forEach(function(i,l){var g=Math.max(2,(N-2)*i.total/Re);R("rect",{x:Ft,y:V(l)+b/2+3,width:g,height:x-b-6,rx:2,fill:e.totalBar,"fill-opacity":e.totalBarOpacity,"data-tr":l},Q);var p=s.value(i.total);z(p,y-1,600,d)>N-6&&(p=s.compact(i.total)),$({x:Ft+N-4,y:V(l)+x/2+(y-1)*.35,"text-anchor":"end","font-size":y-1,"font-weight":600,fill:e.text,"pointer-events":"none"},p,Q)});var Bt=V(_)+Y;a.cols.forEach(function(i,l){var g=Math.max(2,(x-b-4)*i.total/De);R("rect",{x:K(l)+b/2+2,y:Bt+x-b/2-2-g,width:Math.max(k-b-4,1),height:g,rx:2,fill:e.totalBar,"fill-opacity":e.totalBarOpacity,"data-tc":l},Q);var p=s.value(i.total);z(p,O,600,d)>k-b-6&&(p=s.compact(i.total)),z(p,O,600,d)<=k-b-6&&$({x:K(l)+k/2,y:Bt+x/2+O*.35,"text-anchor":"middle","font-size":O,"font-weight":600,fill:e.text,"pointer-events":"none"},p,Q)});var Vt=s.value(a.total);z(Vt,y-1,700,d)>N-6&&(Vt=s.compact(a.total)),$({x:Ft+N-4,y:Bt+x/2+(y-1)*.35,"text-anchor":"end","font-size":y-1,"font-weight":700,fill:e.text},Vt)}this._focusRect=R("rect",{x:0,y:0,width:0,height:0,rx:Math.min(e.cellRadius+1,6),fill:"none",stroke:e.text,"stroke-width":2,opacity:0,"pointer-events":"none"},P);var Wt=function(i,l){var g=a.values[i][l];return{row:a.rows[i].label,column:a.cols[l].label,rowIndex:i,columnIndex:l,value:g,shareOfTotal:a.total?g/a.total:0,shareOfRow:a.rows[i].total?g/a.rows[i].total:0,shareOfColumn:a.cols[l].total?g/a.cols[l].total:0,aboveLimit:!!(m&&a.total&&g/a.total>m+1e-12&&!a.rows[i].other&&!a.cols[l].other),rowMembers:a.rows[i].members.slice(),columnMembers:a.cols[l].members.slice()}},Ct=[];this._boldReset=function(){Ct.forEach(function(i){i.removeAttribute("font-weight")}),Ct=[]};var Se=function(i,l){o._boldReset();var g=ke[i];g.setAttribute("font-weight",600),Ct.push(g),Array.prototype.forEach.call(ne[l].childNodes,function(p){p.setAttribute("font-weight",600),Ct.push(p)})},_t=function(i,l,g){if(o._active=[i,l],o._focusRect.setAttribute("x",K(l)+b/2-1),o._focusRect.setAttribute("y",V(i)+b/2-1),o._focusRect.setAttribute("width",k-b+2),o._focusRect.setAttribute("height",x-b+2),o._focusRect.setAttribute("opacity",1),Se(i,l),!!t.tooltip){var p=Wt(i,l),M;typeof t.tooltipFormatter=="function"?(M=t.tooltipFormatter(p,s),Array.isArray(M)||(M=[String(M)])):(M=[p.row+" \xD7 "+p.column],p.value?(M.push(n.exposure+": "+s.value(p.value)),M.push(n.shareOfTotal+": "+s.percent(p.shareOfTotal)),M.push(F(n.shareOfRow,{row:p.row})+": "+s.percent(p.shareOfRow)),M.push(F(n.shareOfColumn,{column:p.column})+": "+s.percent(p.shareOfColumn)),p.aboveLimit&&M.push(F(n.limitTip,{limit:at(m)}))):M.push(n.empty),a.rows[i].other&&M.push(F(n.includes,{list:a.rows[i].members.join(", ")})),a.cols[l].other&&M.push(F(n.includes,{list:a.cols[l].members.join(", ")})));var ot=P.getBoundingClientRect(),lt=ot.width/yt;o._placeTip(M,{left:ot.left+K(l)*lt,top:ot.top+V(i)*lt,width:k*lt,bottom:ot.top+(V(i)+x)*lt},g)}},le=function(i,l,g){var p=i?a.rows[l]:a.cols[l],M=[F(n.rowTotalTip,{label:p.label}),s.value(p.total)+" \xB7 "+s.percent(a.total?p.total/a.total:0)+" "+n.shareOfTotal.toLowerCase()];p.other&&M.push(p.members.join(", ")),o._placeTip(M,{left:g.clientX,top:g.clientY,width:0},g)};J.addEventListener("mousemove",function(i){var l=i.target;!l.hasAttribute||!l.hasAttribute("data-r")||_t(+l.getAttribute("data-r"),+l.getAttribute("data-c"),i)}),J.addEventListener("pointerdown",function(i){var l=i.target;!l.hasAttribute||!l.hasAttribute("data-r")||_t(+l.getAttribute("data-r"),+l.getAttribute("data-c"),i)}),J.addEventListener("mouseleave",function(){o._hideTip()}),typeof t.onClick=="function"&&(J.style.cursor="pointer",J.addEventListener("click",function(i){var l=i.target;!l.hasAttribute||!l.hasAttribute("data-r")||t.onClick(Wt(+l.getAttribute("data-r"),+l.getAttribute("data-c")),i)})),Q&&(Q.addEventListener("mousemove",function(i){var l=i.target;l.hasAttribute&&l.hasAttribute("data-tr")?le(!0,+l.getAttribute("data-tr"),i):l.hasAttribute&&l.hasAttribute("data-tc")&&le(!1,+l.getAttribute("data-tc"),i)}),Q.addEventListener("mouseleave",function(){o._hideTip()})),this._geom={rows:a.rows,cols:a.cols,cx:K,cy:V,cellW:k,cellH:x,gap:b},P.setAttribute("aria-describedby",this.tipEl.id);var jt=[0,0];if(c.largest){var se=a.rows.map(function(i){return i.key}).indexOf(f.rows[c.largest.r].key),ue=a.cols.map(function(i){return i.key}).indexOf(f.cols[c.largest.c].key);se>=0&&ue>=0&&(jt=[se,ue])}return P.addEventListener("focus",function(){var i=o._active&&o._active[0]<_&&o._active[1]<D?o._active:jt;_t(i[0],i[1])}),P.addEventListener("blur",function(){o._hideTip()}),P.addEventListener("keydown",function(i){var l=o._active&&o._active[0]<_&&o._active[1]<D?o._active.slice():jt.slice();if(i.key==="ArrowLeft")l[1]=Math.max(0,l[1]-1);else if(i.key==="ArrowRight")l[1]=Math.min(D-1,l[1]+1);else if(i.key==="ArrowUp")l[0]=Math.max(0,l[0]-1);else if(i.key==="ArrowDown")l[0]=Math.min(_-1,l[0]+1);else if(i.key==="Home")l[1]=0;else if(i.key==="End")l[1]=D-1;else if((i.key==="Enter"||i.key===" ")&&typeof t.onClick=="function"){i.preventDefault(),t.onClick(Wt(l[0],l[1]),i);return}else return;i.preventDefault(),_t(l[0],l[1])}),this._hideTip(),this._animateNext=!1,this};function Xt(t,r){if(r==null)return-1;r=String(r);for(var o=0;o<t.length;o++)if(t[o].label===r||t[o].key===r||t[o].members.indexOf(r)>=0)return o;return-1}L.prototype.howToRead=function(){var t=X(this.options.data,this.options,this._labels()),r=(t.rowDim.label||"row").toLowerCase(),o=(t.colDim.label||"column").toLowerCase();return"Each cell is the exposure where a "+r+" meets a "+o+"; darker cells hold more. The bars on the right and along the bottom are the totals for each "+r+" and "+o+". 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.":"")},L.prototype.describe=function(){var t=this.getStats(),r=gt(this.options.data,this.options.locale),o=X(this.options.data,this.options,this._labels()),e=["In this example total exposure is "+r.value(t.total)+" across "+t.rows+" "+(o.rowDim.plural||o.rowDim.label).toLowerCase()+" and "+t.columns+" "+(o.colDim.plural||o.colDim.label).toLowerCase()+"."];return t.largest&&e.push("The largest cell is "+t.largest.row+" \xD7 "+t.largest.column+" with "+r.value(t.largest.value)+" ("+r.percent(t.largest.share)+" of the total)."),e.push("HHI is "+r.count(t.hhi)+", like "+r.count(Math.round(t.effectiveCells))+" equal-sized cells."),t.limit&&e.push(t.aboveLimit.length+" "+(t.aboveLimit.length===1?"cell is":"cells are")+" above the "+at(t.limit)+" limit."),e.join(" ")},L.prototype.getExportData=function(){var t=this.options,r=t.data,o=this._labels(),e=X(r,S({},t,{topRows:0,topColumns:0}),o),n=gt(r,t.locale),a=this.getStats(),s=this._limit(),f={prefix:r.prefix||"",suffix:r.suffix||"",decimals:r.decimals!=null?r.decimals:0,negatives:r.negatives},m=[{label:e.rowDim.label,type:"text"}].concat(e.cols.map(function(u){return{label:u.label,type:"number",unit:f}}),[{label:o.total,type:"number",unit:f}]),c=e.rows.map(function(u,y){return[u.label].concat(e.values[y],[u.total])});c.push([o.total].concat(e.cols.map(function(u){return u.total}),[e.total]));var C=e.rows.map(function(u,y){return[u.label].concat(e.values[y].map(function(T){return T?n.value(T):"\u2014"}),[n.value(u.total)])});C.push([o.total].concat(e.cols.map(function(u){return n.value(u.total)}),[n.value(e.total)]));var v=[];e.rows.forEach(function(u,y){e.cols.forEach(function(T,O){var x=e.values[y][O];x&&v.push([u.label,T.label,x,e.total?x/e.total:0])})}),v.sort(function(u,y){return y[2]-u[2]});var h=function(u){return s&&u>s+1e-12?"Yes":"No"},d=[[o.totalExposure,a.total,n.value(a.total)],[o.hhi,a.hhi,n.count(a.hhi)],["Effective number of cells",a.effectiveCells,n.count(Math.round(a.effectiveCells))],[o.top5,a.top5Share,n.percent(a.top5Share)]];a.largest&&d.push([o.largest,a.largest.share,a.largest.row+" \xD7 "+a.largest.column+" \xB7 "+n.percent(a.largest.share)]),s&&(d.push(["Limit (share of total)",s,at(s)]),d.push([o.aboveLimit,a.aboveLimit.length,n.count(a.aboveLimit.length)]));var w=(t.annotations||[]).map(function(u,y){return[String(y+1),String(u.row||""),String(u.column||""),u.text||""]}),A=[{name:"Matrix",columns:m,rows:c,text:C,bold:c.map(function(u,y){return y===c.length-1})},{name:"Cells",columns:[{label:e.rowDim.label,type:"text"},{label:e.colDim.label,type:"text"},{label:o.exposure,type:"number",unit:f},{label:o.shareOfTotal,type:"percent",decimals:2},{label:o.aboveLimit,type:"text"}],rows:v.map(function(u){return[u[0],u[1],u[2],u[3],h(u[3])]}),text:v.map(function(u){return[u[0],u[1],n.value(u[2]),n.percent(u[3],2),h(u[3])]})},{name:"Concentration",columns:[{label:"Measure",type:"text"},{label:"Value",type:"general"},{label:"As shown",type:"text"}],rows:d,text:d.map(function(u){return[u[0],typeof u[1]=="number"?String(Number(u[1].toPrecision(10))):String(u[1]),u[2]]})}];return w.length&&A.push({name:"Notes",columns:[{label:"No.",type:"text"},{label:e.rowDim.label,type:"text"},{label:e.colDim.label,type:"text"},{label:"Note",type:"text"}],rows:w}),{title:r.title||"Exposure heatmap",subtitle:r.subtitle||"",summary:this.describe(),library:"Veyforma Exposure Heatmap "+Pt,sheets:A,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",e.rowDim.label+" \xD7 "+e.colDim.label+", full grid without Other grouping"],["Unit",r.unit],["Limit",s?at(s)+" of total":null],["As of",r.asOf],["Data source",r.source]]}},L.prototype._annotationPoint=function(t){var r=this._geom;if(!r||!t)return null;var o=Xt(r.rows,t.row),e=Xt(r.cols,t.column);if(o<0||e<0)return null;var n=r.rows[o]&&r.rows[o].other||r.cols[e]&&r.cols[e].other;return{x:r.cx(e)+r.gap/2+11,y:r.cy(o)+r.gap/2+11,inside:!0,where:n?"shown in Other":null}},L.prototype._annotationTarget=function(t){var r=this._geom,o,e;if(!r)return null;if(t){var n=t.target;if(!n||!n.getAttribute||n.getAttribute("data-r")==null)return null;o=+n.getAttribute("data-r"),e=+n.getAttribute("data-c")}else if(this._active)o=this._active[0],e=this._active[1];else return null;return!r.rows[o]||!r.cols[e]||r.rows[o].other||r.cols[e].other?null:{row:r.rows[o].label,column:r.cols[e].label}},L.prototype._annotationLabel=function(t){return[t.row,t.column].filter(Boolean).join(" \xD7 ")},I.VeyHeatmap={version:Pt,create:function(t,r){return new L(t,r)},registerTheme:function(t,r){if(!t||typeof t!="string")throw new Error("VeyHeatmap: registerTheme needs a name.");return st[t]=ut(r||{}),st[t]},getTheme:function(t){return ut(t)},listThemes:function(){return Object.keys(st)}}})(typeof window<"u"?window:void 0);