-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiife.js
2 lines (2 loc) · 18.8 KB
/
iife.js
1
2
// jsonstat-suite v3.5.0 Copyright 2023 Xavier Badosa https://jsonstat.com
var JSONstatUtils=function(e,t){"use strict";function n(e,n){return null==e?null:("string"!=typeof e&&void 0!==e.length||(e=t(e)),0===e.length||"dataset"!==e.class&&"collection"!==e.class&&"bundle"!==e.class?null:"dataset"===e.class?e:e.Dataset(n))}function r(e){if(null===e||0===e.length||"dataset"!==e.class)return!1;for(var t=e.length,n=1;t--;)n*=e.Dimension(t).length;return n===e.n}function a(e,t,n){var r,a,l,i,o;return(t.label||n).capitalize()+(a=t,o="",(r=e)&&"metric"===r.role&&a.unit&&(l=a.unit.hasOwnProperty("label")?a.unit.label:"")+(i=a.unit.hasOwnProperty("symbol")?a.unit.symbol:"")!==""&&(o=" ("+(o=""===i?l:""===l?i:"start"===a.unit.position?i+l:l+" "+i)+")"),o)}function l(e,t,n){var r,l='<select name="'+t+'">',i=[];if(null!==n[1]){if(r=e.id,i=e.Dimension(),2===r.length)return(e.Dimension(n[0]).label||n[0]).capitalize()}else{var o=e.Dimension(t);if(r=o.id,i=o.Category(),1===r.length)return}return r.forEach((function(e,t){var r=e!==n[0]?"":'selected="selected" ';null!==n[1]&&e===n[1]||(l+="<option "+r+'value="'+e+'">'+a(o,i[t],e)+"</option>")})),l+="</select>"}function i(e,t){var n={};return Array.isArray(e[t])?(e[t].forEach((function(e,t){null!==e&&(n[String(t)]=e)})),n):e[t]}function o(e,n){if(void 0===e)return null;void 0===n&&(n={}),"boolean"!=typeof n.ovalue&&(n.ovalue=!1),"boolean"!=typeof n.ostatus&&(n.ostatus=!1),"boolean"!=typeof n.instance&&(n.instance=!1);var r=n.vlabel||"Value",a=n.slabel||"Status",l=n.type||"array",o=n.label||"",s=n.header||null,u=[],c=[],d=[],f=[],h={},v={},p=function(e,t){for(var n=1,r=0,a=0;a<E;a++)r+=(n*=a>0?t[E-a]:1)*e[E-a-1];return r},b=function(){var t=e[S][r];d[p(A,c)]=isNaN(t)?null:t};switch(l){case"array":e=function(e){for(var t=e[0],n=e.slice(1),r=[],a=0,l=n.length;a<l;a++){for(var i=0,o=t.length,s={};i<o;i++)s[t[i]]=n[a][i];r.push(s)}return r}(e);break;case"object":e=function(e){for(var t=e.cols.map((function(e){return e.id})),n=e.rows,r=[],a=0,l=n.length;a<l;a++){for(var i=0,o=t.length,s={};i<o;i++)s[t[i]]=n[a].c[i].v;r.push(s)}return r}(e)}var y,m=e.length;for(var g in n.hasOwnProperty("drop")&&Array.isArray(n.drop)&&n.drop.length&&e.forEach((function(e){n.drop.forEach((function(t){delete e[t]}))})),e[0])if(g!==r)if(g!==a){if(u.push(g),s)y=s.dimension[g],h[g]=y.category.index;else{h[g]=[];for(var w=0;w<m;w++){var O=e[w][g];-1===h[g].indexOf(O)&&h[g].push(O)}}c.push(h[g].length),v[g]={label:s?y.label:g,category:{index:h[g]}},s&&(v[g].category.label=y.category.label,y.category.unit&&(v[g].category.unit=y.category.unit))}else b=function(){var t=e[S][r],n=e[S][a];d[p(A,c)]=isNaN(t)?null:t,f[p(A,c)]=""===n?null:n};for(var E=u.length,S=0;S<m;S++){for(var A=[],x=0;x<E;x++){var j=u[x];A.push(h[j].indexOf(e[S][j]))}b()}var D={version:"2.0",class:"dataset",value:d,dimension:v,id:u,size:c};return o&&(D.label=o),f.length&&(D.status=f),s&&(s.label&&(D.label=s.label),s.source&&(D.source=s.source),s.updated&&(D.updated=s.updated),s.href&&(D.href=s.href),s.role&&(D.role=s.role)),n.ovalue&&(D.value=i(D,"value")),n.ostatus&&D.hasOwnProperty("status")&&(D.status=i(D,"status")),n.instance?t(D):D}function s(e,t){return null==e?"":-1!==e.indexOf(t)?'"'+e+'"':e}String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1)};return e.datalist=function(e,t){if(void 0===e)return null;void 0===t&&(t={});var a="",l="",i="",o=0,s=t.na||"n/a",u=t.dsid||0,c=t.vlabel||null,d=t.slabel||null,f=t.counter||!1,h=t.tblclass||"",v=t.numclass||"",p=t.valclass||"",b=t.status||!1,y=t.locale||"en-US",m=t.source||"Source",g=n(e,u),w=g.role&&g.role.metric?g.id.indexOf(g.role.metric[0]):null,O=g.Dimension({role:"metric"}),E={},S=Number.toLocaleString&&"none"!==y?function(e,t){return null===t?e.toLocaleString(y):e.toLocaleString(y,{minimumFractionDigits:t,maximumFractionDigits:t})}:function(e,t){return null===t?e:e.toFixed(t)},A=function(e,t){var n=null;e.forEach((function(e,r){var i=D===r?' class="'+v+" "+p+'"':"",o=s;t?(w===r&&(n=E[e]),null!==e&&(o=D===r?S(e,n):e),l+="<td"+i+">"+o+"</td>"):a+="<th"+i+">"+e+"</th>"}))},x=f?function(e,t){t?l+='<tr><td class="'+v+'">'+t+"</td>":a+='<th class="'+v+'">#</th>',A(e,t),l+="</tr>"}:function(e,t){l+="<tr>",A(e,t),l+="</tr>"};if(!r(g))return null;O&&O[0].Category().forEach((function(e){var t=e.unit&&e.unit.hasOwnProperty("decimals")?e.unit.decimals:null;E[e.label]=t}));var j=g.toTable({status:b,vlabel:c,slabel:d}),D=j[0].length-1;return j.forEach((function(e,t){x(e,t)})),g.source&&(o=g.length+1,f&&o++,b&&o++,"."!==(m+=": "+g.source).slice(-1)&&(m+="."),i='<tfoot><td colspan="'+o+'">'+m+"</td></tfoot>"),'<table class="'+h+'"><caption>'+(t.caption||g.label||"")+"</caption><thead><tr>"+a+"</tr></thead><tbody>"+l+"</tbody>"+i+"</table>"},e.fromCSV=function(e,t){if(void 0===e)return null;void 0===t&&(t={});var n,r,a,l=[],i=null,s=null,u=!1,c={time:[],geo:[],metric:[]},d="jsonstat"===e.substring(0,8),f=d?"value":t.vlabel,h=d?"status":t.slabel,v=d?e.substring(8,9):t.delimiter||",",p=";"===v?t.decimal||",":t.decimal||".",b=function(e,t){t=t||",";for(var n,r,a=new RegExp("(\\"+t+'|\\r?\\n|\\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^"\\'+t+"\\r\\n]*))","gi"),l=[[]],i=null;i=a.exec(e);)(r=i[1]).length&&r!=t&&l.push([]),n=i[2]?i[2].replace(new RegExp('""',"g"),'"'):i[3],l[l.length-1].push(n);return l}(e.trim(),v);if(d){for(p=b[0][1],a=b[0][2],b.shift();"data"!==b[0][0];)l.push(b.shift());b.shift(),s={dimension:{}},l.forEach((function(e){var t,n,r,l,i,o,d,f;switch(e[0]){case"dimension":if(s.dimension[e[1]]={},(l=s.dimension[e[1]]).label=e[2],l.category={},(i=l.category).index=[],n={},r=2*e[3]+3,e.length>=r){for(t=4;t<r;t++)d=e[t],f=e[++t],Object.defineProperty(n,d,{value:f,writable:!0,configurable:!0,enumerable:!0}),i.label=n,i.index.push(d);"string"==typeof e[t]&&-1!==["time","geo","metric"].indexOf(e[t])&&(c[e[t]].push(e[1]),u=!0,"metric"===e[t]&&"string"==typeof e[++t]&&(i.unit={},i.index.forEach((function(n,r){var l=e[t+r].split(a);i.unit[n]={},o=i.unit[n],void 0!==l[0]&&""!==l[0]&&(o.decimals=1*l[0]),void 0!==l[1]&&""!==l[1]&&(o.label=l[1]),void 0!==l[2]&&""!==l[2]&&(o.symbol=l[2]),void 0!==l[1]&&-1!==["start","end"].indexOf(l[3])&&(o.position=l[3])}))))}break;case"label":case"source":case"updated":case"href":s[e[0]]=e[1]||null}})),u&&(c.time.length||delete c.time,c.geo.length||delete c.geo,c.metric.length||delete c.metric,s.role=c)}if(n=b.length,r=b[0].length,void 0!==f){for(;r--;)if(b[0][r]===f){i=r;break}if(null===i)return null}else i=r-1,f=b[0][i];if(","===p)for(r=1;r<n;r++)b[r][i]=Number(b[r][i].replace(",","."));else for(r=1;r<n;r++)b[r][i]=Number(b[r][i]);return o(b,{header:s,vlabel:f,slabel:h,type:"array",label:t.label||"",ovalue:t.ovalue||!1,ostatus:t.ostatus||!1,instance:t.instance||!1})},e.fromSDMX=function(e,n){if("object"!=typeof e)return null;if(e.hasOwnProperty("data")&&e.hasOwnProperty("meta")&&e.data.hasOwnProperty("dataSets")&&e.data.hasOwnProperty("structures")&&Array.isArray(e.data.structures)&&(e.dataSets=e.data.dataSets,e.structure=e.data.structures[0],e.header=e.meta),!e.hasOwnProperty("dataSets")||!Array.isArray(e.dataSets))return null;if(1!==e.dataSets.length)return null;e.dataSets[0].hasOwnProperty("observations")||function(e){var t=e.dataSets[0],n=t.series,r=e.structure,a=r.dimensions,l={};Object.keys(n).forEach((function(e){var t=n[e].observations;Object.keys(t).forEach((function(r){l[e+":"+r]=t[r].concat(n[e].attributes)}))})),t.observations=l,delete t.series,a.observation=a.series.concat(a.observation),delete a.series,r.attributes.observation=r.attributes.observation.concat(r.attributes.series),delete r.attributes.series}(e),void 0===n?n={ovalue:!1,ostatus:!1,instance:!1}:("boolean"!=typeof n.ovalue&&(n.ovalue=!1),"boolean"!=typeof n.ostatus&&(n.ostatus=!1),"boolean"!=typeof n.instance&&(n.instance=!1));var r=e.structure,a=e.dataSets[0].observations,l=r.attributes.observation,i=r.dimensions;if(!i.hasOwnProperty("observation"))return null;if(i.hasOwnProperty("series")&&Object.keys(i.series).length)return null;Array.prototype.reduce||Object.defineProperty(Array.prototype,"reduce",{value:function(e){if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof e)throw new TypeError(e+" is not a function");var t,n=Object(this),r=n.length>>>0,a=0;if(arguments.length>=2)t=arguments[1];else{for(;a<r&&!(a in n);)a++;if(a>=r)throw new TypeError("Reduce of empty array with no initial value");t=n[a++]}for(;a<r;)a in n&&(t=e(t,n[a],a,n)),a++;return t}}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw TypeError("predicate must be a function");for(var r=arguments[1],a=0;a<n;){var l=t[a];if(e.call(r,l,a,t))return l;a++}},configurable:!0,writable:!0}),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var r=arguments[1],a=0;a<n;){var l=t[a];if(e.call(r,l,a,t))return a;a++}return-1},configurable:!0,writable:!0});var o=1,s=[],u=[],c={},d=[],f={time:[],geo:[]},h=function(){},v=function(e,t){for(var n=e.size,r=n.length-t.length;r--;)t.push(0);for(var a=0,l=n.length,i=0,o=1;a<l;a++)i+=(o*=a>0?n[l-a]:1)*t[l-a-1];return i},p=function(e){if(c[e.id]={label:e.name},e.hasOwnProperty("role"))switch(e.role){case"REF_AREA":f.geo.push(e.id);break;case"TIME_PERIOD":f.time.push(e.id)}Object.defineProperty(c[e.id],"category",{value:{index:[],label:{}},writable:!0,enumerable:!0}),s.push(e.id),u.push(e.values.length),o*=e.values.length;var t=c[e.id].category;e.values.forEach((function(e){t.index.push(e.id),Object.defineProperty(t.label,e.id,{value:e.name,writable:!0,enumerable:!0})}))},b=e.header.links?e.header.links.find((function(e){return"request"===e.rel})):null,y=l.findIndex((function(e){return"OBS_STATUS"===e.id}));-1!==y&&(l[y].values.length?d=l[y].values:y=-1),i.observation.forEach(p),i.hasOwnProperty("dataSet")&&i.dataSet.forEach(p);var m={version:"2.0",class:"dataset",updated:e.header.prepared||null,source:e.header.sender.name||null,label:r.name||null,id:s,size:u,dimension:c,value:n.ovalue?{}:new Array(o).fill(null)};for(var g in b&&(m.link={alternate:[{type:"application/vnd.sdmx.data+json",href:b.href}]}),f.geo.length+f.time.length>0&&(f.time.length||delete f.time,f.geo.length||delete f.geo,m.role=f),-1!==y&&(m.status=n.ostatus?{}:new Array(o).fill(null),m.extension={status:{label:{}}},d.forEach((function(e){m.extension.status.label[e.id]=e.name})),h=n.ostatus?function(){var e=a[g][y];null!==e&&(m.status[v(m,w)]=d[e].id)}:function(){var e=a[g][y];m.status[v(m,w)]=null===e?null:d[e].id}),y++,a){var w=g.split(":");n.ovalue&&null===a[g][0]||(m.value[v(m,w)]=a[g][0]),h()}return n.instance?t(m):m},e.fromTable=o,e.join=function(e,n){if(void 0===e||!Array.isArray(e))return null;var r=JSON.parse(JSON.stringify(e)),a=r[0];if(!a.hasOwnProperty("version")||!a.hasOwnProperty("class")||"dataset"!==a.class)return null;void 0===n&&(n={});var l=void 0===n.label?null:n.label,i=void 0===n.by?null:n.by,s=[];if(null===i){for(var u=1,c=r.length;u<c;u++)s=s.concat(r[u].value);return a.value=s,null!==l&&(a.label=l),a}var d,f,h,v=function(e,t,n){if(Array.isArray(e))e=e.concat(t);else for(var r in t)e[r]=0===t[r]?n:t[r];return e};r.forEach((function(e,n){var r=t(e).toTable({status:!0}),a=e.dimension[i].category;0===n?(s=[r[0]],d=a.index,f=a.label,h=a.unit):(d=function(e,t,n){if(Array.isArray(e))e=e.concat(t);else for(var r in t)e[r]=t[r]+n;return e}(d,a.index,Object.keys(d).length),f=v(f,a.label,n),h=v(h,a.unit,n)),s=s.concat(r.slice(1))}));var p=o(s);return a.value=p.value,a.size=p.size,a.status=p.status||null,a.label=l||"",a.href=null,a.dimension[i].category.index=d||null,a.dimension[i].category.label=f||null,a.dimension[i].category.unit=h||null,a},e.tbrowser=function(e,t,i){function o(e){void 0!==t?t.innerHTML=s[e]:window.alert(s[e])}if(void 0!==e)if(void 0!==t){void 0===i&&(i={});var s=void 0===i.i18n||void 0===i.i18n.msgs?{urierror:"tbrowser: A valid JSON-stat input must be specified.",selerror:"tbrowser: A valid selector must be specified.",jsonerror:"The request did not return a valid JSON-stat dataset.",dimerror:"Only one dimension was found in the dataset. At least two are required.",dataerror:"Selection returned no data!",source:"Source",filters:"Filters",constants:"Constants",rc:"Rows & Columns",na:"n/a"}:i.i18n.msgs,u=void 0===i.i18n||void 0===i.i18n.locale?"en-US":i.i18n.locale,c=i.dsid||0,d=i.status||!1,f=i.tblclass||"",h=i.nonconst||!1,v=n(e,c);if(r(v)){if(h)var p=function(e){var t=0,n=e.size.slice(0),r=[];return n.forEach((function(n,a){var l=a-t,i=e.Dimension(l);1===n&&(delete e.__tree__.dimension[e.id[l]],e.size.splice(l,1),e.id.splice(l,1),e.length--,t++,r.push(i.label.capitalize()+": "+i.Category(0).label.capitalize()))})),r}(v);1!==v.length?function e(t,n,r,o){"function"==typeof i.callback&&i.callback(r);var c="",f="",v="",b="",y=r.rows,m=n.Dimension(y),g=m.id,w=r.cols,O=n.Dimension(w),E=O.id,S=n.role&&n.role.metric?n.role.metric[0]:null,A=null!==S?n.Dimension(S):null,x=function(e){return e.hasOwnProperty("unit")&&e.unit&&e.unit.hasOwnProperty("decimals")?e.unit.decimals:null},j=r.filters,D=JSON.parse(JSON.stringify(j)),P=[],T="",C="",N=n.source?s.source+": "+n.source:"",k=null!==n.label?'<span class="label">'+n.label.capitalize()+"</span>":"";for(var z in h&&p.length&&(k='<span class="label">'+p.join(". ")+"</span>"),""!==N&&"."!==N.slice(-1)&&(N+="."),v+="<caption>"+k+"<form>",j){var R=n.Dimension(z),_=R.label?R.label.capitalize():z.capitalize();R.length>1?T+="<p>"+l(n,z,[j[z],null])+" <strong>"+_+"</strong></p>":P.push({label:_,value:a(R,R.Category(0)),name:z,id:R.id[0]})}""!==T&&(T='<fieldset id="filters"><legend>'+s.filters+"</legend>"+T+"</fieldset>"),P.forEach((function(e){C+="<p>"+e.value+" <strong>"+e.label+'</strong></p><input type="hidden" name="'+e.name+'" value="'+e.id+'" />'})),""!==C&&(C='<fieldset id="constants"><legend>'+s.constants+"</legend>"+C+"</fieldset>"),v+=C+T+'<fieldset id="rowscols"><legend>'+s.rc+"</legend>"+l(n,"rows",[y,w])+" <a>↔</a> "+l(n,"cols",[w,y])+"</fieldset></form></caption>",b+="<tbody>";var L=Number.toLocaleString&&"none"!==u?function(e,t){return null===t?e.toLocaleString(u):e.toLocaleString(u,{minimumFractionDigits:t,maximumFractionDigits:t})}:function(e,t){return null===t?e:e.toFixed(t)};if(g.forEach((function(e){D[y]=e;var t=n.Data(D),r=function(e,t){var n,r=w!==S?null===A?null:x(A.Category(D[S])):x(O.Category(t));null!==e.value?(n=L(e.value,r),d&&null!==e.status&&(n+=" ("+e.status+")")):n=e.status||s.na,b+="<td>"+n+"</td>"};null!==t?(b+='<tr><th scope="row">'+a(m,m.Category(e))+"</th>",Array.isArray(t)?t.forEach((function(e,t){r(e,t)})):r(t,0),b+="</tr>"):b="ERROR"})),"ERROR"===b)return s.dataerror;b+="</tbody>",c+="<thead><tr><th></th>",E.forEach((function(e){c+='<th scope="col">'+a(O,O.Category(e))+"</th>"})),c+="</tr></thead>",""!==N&&(f='<tfoot><tr><td colspan="'+(E.length+1)+'">'+N+"</td></tr></tfoot>"),t.innerHTML='<table class="'+o+'">'+v+c+b+f+"</table>",[].slice.call(t.querySelectorAll("select")).forEach((function(r){r.addEventListener("change",(function(r){var a,l;e(t,n,function(e,t,n){var r={filters:{}};return n.forEach((function(e){"rows"===e.name||"cols"===e.name?r[e.name]=e.value:r.filters[e.name]=e.value})),"rowscols"===t&&e.id.forEach((function(t,n){t!==r.rows&&t!==r.cols?void 0===r.filters[t]&&(r.filters[t]=e.Dimension(n).id[0]):delete r.filters[t]})),r}(n,r.target.parentElement.getAttribute("id"),(a=t,l=[],[].slice.call(a.querySelectorAll("select, input")).forEach((function(e){l.push({name:e.name,value:e.value})})),l)),o)}),!1)})),t.querySelector("a").addEventListener("click",(function(){r.cols=y,r.rows=w,e(t,n,r,o)}),!1)}(t,v,function(e,t){if("object"==typeof t)return{rows:t.rows,cols:t.cols,filters:t.filters};var n,r,a={},l=[],i=e.id;if(t){var o="bigger"===t?function(e,t){return e.len<t.len?1:-1}:function(e,t){return e.len>t.len?1:-1};e.Dimension().forEach((function(e,t){l.push({id:i[t],len:e.length})})),l.sort(o),n=l[0].id,r=l[1].id}else n=i[0],r=i[1];return e.Dimension(n).length<e.Dimension(r).length&&(n=r+(r=n,"")),i.forEach((function(t){t!==n&&t!==r&&(a[t]=e.Dimension(t).id[0])})),{rows:n,cols:r,filters:a}}(v,i.preset),f):o("dimerror")}else o("jsonerror")}else o("selerror");else o("urierror")},e.toCSV=function(e,t){if(void 0===e)return null;void 0===t&&(t={});var a={content:!1,field:!1},l=!0===t.rich,i=t.content||"label",o=t.field||"label",u=l?"value":t.vlabel||"Value",c=l?"status":t.slabel||"Status",d=!0===t.status,f=t.na||"n/a",h=t.delimiter||",",v=t.separator||"|",p=";"===h?t.decimal||",":t.decimal||".",b=!0===t.array,y=n(e,t.dsid||0),m=b?[]:"",g=b?[]:"",w=b?function(e){m.push(e)}:function(e){m+=e+"\n"},O=b?function(e){g.push(e)}:function(e){g+=e+"\n"};if(!r(y))return null;l?d=null!==y.status:("[id] label"===i&&(a.content=!0,i="id"),"[id] label"===o&&(a.field=!0,o="id"));var E=!l&&t.by&&-1!==y.id.indexOf(t.by)?t.by:null,S=E&&void 0!==t.drop&&Array.isArray(t.drop)?t.drop:null;if(E)return function(e,t){const n=[],r=t.by,a=t.idlabel,l=t.drop,i=t.na,o=t.delimiter,u=t.decimal,c=a.content?"id":t.content,d=a.field?"label":t.field,f=e.toTable({drop:l,content:c,by:r,type:"arrobj"}),h=Object.keys(f[0]),v=function(e,t,n,r,l){return e.map((e=>"label"===n?-1!==r.id.indexOf(e)?s((a.field?"["+e+"] ":"")+r.Dimension(e).label,t):s((a.field?"["+e+"] ":"")+r.Dimension(l).Category(e).label,t):s(e,t))).join(t)+"\n"}(h,o,d,e,r),p="."!==u?function(e){return null===e?s(i,o):String(e).replace(".",u)}:function(e){return null===e?s(i,o):e};return f.forEach((t=>{let r=[];h.forEach((n=>{const l=t[n],i="string"==typeof l?s(a.content?"["+l+"] "+e.Dimension(n).Category(l).label:l,o):p(l);r.push(i)})),n.push(r.join(o))})),v+n.join("\n")}(y,{drop:S,na:f,delimiter:h,decimal:p,content:i,field:o,by:E,idlabel:a});var A=y.toTable({vlabel:u,slabel:c,status:d,field:l||a.field?"id":o,content:l||a.content?"id":i,type:"array"}),x=A[0].indexOf("id"===o?"value":u),j=d?A[0].indexOf("id"===o?"status":c):-1;return A.forEach((function(e,t){e.forEach((function(n,r){var l=y.Dimension(r);t&&r===x?null===n?e[r]=s(f,h):"."!==p&&(e[r]=String(e[r]).replace(".",p)):t&&r===j&&null===n?e[r]="":(a.content&&t&&l?e[r]="["+e[r]+"] "+l.Category(e[r]).label:a.field&&0===t&&(e[r]=l?"["+e[r]+"] "+l.label:"value"===e[r]?u:c),e[r]=s(e[r],h))})),w(e.join(h))})),l&&(O("jsonstat"+h+p+h+v),["label","source","updated","href"].forEach((function(e){y[e]&&O(e+h+s(y[e],h))})),y.id.forEach((function(e,t){var n=[],r=y.Dimension(t),a=r.role,l=!1,i="";i+="dimension"+h+s(e,h)+h+s(r.label,h)+h+r.length,"metric"===a&&r.__tree__.category.unit&&(l=!0),r.id.forEach((function(e,t){var a=[],o=r.Category(t);i+=h+s(e,h)+h+s(o.label,h),l&&(a.push(o.unit.hasOwnProperty("decimals")?o.unit.decimals:""),a.push(o.unit.label||""),o.unit.symbol&&(a.push(o.unit.symbol),a.push(o.unit.position)),n.push(s(a.join(v),h)))})),null!==a&&"classification"!==a&&(i+=h+r.role,l&&(i+=h+n.join(h))),O(i)})),m=b?g.concat(["data"],m):g+"data\n"+m),m},e.version="3.5.0",e}({},JSONstat);