forked from idescat/visual
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual.js
More file actions
25 lines (22 loc) · 30 KB
/
visual.js
File metadata and controls
25 lines (22 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
Visual
Copyright (c) 2025 Institut d'Estadistica de Catalunya (Idescat)
http://www.idescat.cat (https://github.com/idescat/visual)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
let VisualJS={version:"1.3.0",show:!0,old:!1,fixed:null,width:500,bwidth:500,height:500,normal:500,scripts:[],map:{},container:{},pub:{},func:{},callback:null,getSize:function(e){function t(e,t){return("function"==typeof getComputedStyle?getComputedStyle(e):e.currentStyle)[t]}function a(e){return(e=o(e))[0]instanceof Element?e[0]:e[0]&&e[0][0]?e[0][0]:void 0}function i(e){return e?e.offsetHeight+Math.round(parseFloat(t(e,"marginTop"))+parseFloat(t(e,"marginBottom"))):0}let l=VisualJS.setup,n=l.html,r=n.heading,s="."+VisualJS.setup.footerclass,o="undefined"!=typeof jQuery?jQuery:"undefined"!=typeof d3?d3.select:document.querySelectorAll.bind(document),u=window,d=document,p=d.documentElement,c=d.getElementsByTagName("body")[0],y=d.getElementById(e),f=i(a(r)),g=i(a(s)),x=u.innerHeight||p.clientHeight||c.clientHeight,b=Math.round(parseFloat(t(y,"marginTop"))+parseFloat(t(y,"marginBottom")));return void 0!==x&&void 0!==f&&void 0!==g&&(null===VisualJS.fixed?(VisualJS.bwidth=u.innerWidth||p.clientWidth||c.clientWidth,VisualJS.width=VisualJS.bwidth-l.padding.w,VisualJS.height=Math.floor(x-f-g-b-10)):(VisualJS.bwidth=p.clientWidth||c.clientWidth,VisualJS.width=VisualJS.fixed[0]-l.padding.w,VisualJS.height=Math.floor(VisualJS.fixed[1]-f-g-b-10))),VisualJS.visualsize=VisualJS.width<VisualJS.normal?l.mini:l.normal,10<VisualJS.width&&10<VisualJS.height},arr2html:function(e){let t="";return void 0!==e&&(Array.isArray(e)?e.forEach(function(e){"string"==typeof e&&""!==e&&(t+=`<p>${e}</p>`)}):"string"==typeof e&&""!==e&&(t+=`<p>${e}</p>`)),t},iframe:function(t,a){let e=VisualJS.setup,i=("string"==typeof t.clas?t:e).clas,l='<!DOCTYPE html>\n\x3c!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--\x3e\n\x3c!--[if IE 7]><html class="lt-ie9 lt-ie8"> <![endif]--\x3e\n\x3c!--[if IE 8]><html class="lt-ie9"> <![endif]--\x3e\n\x3c!--[if gt IE 8]>\x3c!--\x3e <html> \x3c!--<![endif]--\x3e\n<head>';"string"==typeof a&&(-1===a.indexOf("{")?l+=`<link href="${a}" rel="stylesheet" type="text/css"/>`:l+=`<style type="text/css">'${a}'</style>`),l=(l=(l=(l+=`<script type="text/javascript" src="${VisualJS.setup.main.visual}"></script>`)+`<script type="text/javascript" src="${VisualJS.setup.main.setup}"></script>`)+`<script type="text/javascript" src="${VisualJS.setup.main.lazy}"></script>`)+`</head><body><div id="${t.id}" class="${i}"></div><script>window.setTimeout(function(){visual(${JSON.stringify(t)});},1);</script></body></html>`,a=document,n=a.createElement("iframe"),a=a.getElementById(t.id),n.setAttribute("title",t.title?VisualJS.setup.i18n.text.iframetitle[t.lang]+": "+t.title:VisualJS.setup.i18n.text.iframetitle[t.lang]),n.setAttribute("aria-hidden","true"),n.setAttribute("role","widget"),n.border="none",n.overflow="hidden",a.parentNode.insertBefore(n,a.nextSibling);var n,t=n,a=l;if(void 0!==t){let e;t.contentDocument?e=t.contentDocument:t.contentWindow?e=t.contentWindow.document:window.frames[t.name]&&(e=window.frames[t.name].document),e&&(e.open(),e.write(a),e.close())}},compare:function(a){function e(){var e,t;VisualJS.getSize(n)&&(e=VisualJS.height+("string"==typeof a.footer&&""!==a.footer?14:0),t=VisualJS.width+i.margin,t=`iframe{ float: left; width: ${Math.floor((t-l)/2-i.margin)}px; height:${e}px; }`,y.innerHTML=t,c.style.height=e+"px")}let i=VisualJS.setup,l=VisualJS.setup.separator,n=("string"==typeof a.id?a:i).id,t=Array.isArray(a.css)?0===a.css.length?["",""]:1===a.css.length?[a.css[0],a.css[0]]:a.css:[a.css,a.css],r=document,s=r.createElement(i.html.heading),o="string"==typeof a.title?a.title:"",u=r.createElement("p"),d="string"==typeof a.footer?VisualJS.arr2html(a.footer):"",p=r.getElementById(n),c=r.createElement("div"),y=r.createElement("style"),f;s.innerHTML=o,s.style.overflow="auto",u.innerHTML=d,u.style.overflow="auto",u.style.clear="both",p.appendChild(s),p.appendChild(u),r.getElementsByTagName("head")[0].appendChild(y),c.style.width=l+"px",c.style.cssFloat="left";for(let e=0;e<2;e++)f=r.createElement("span"),"string"!=typeof a.load[e].id&&(a.load[e].id=i.compareids[e]),f.id=a.load[e].id,p.insertBefore(f,u),VisualJS.iframe(a.load[e],t[e]);p.insertBefore(c,f),e(),VisualJS.fixed||(window.addEventListener?window.addEventListener("resize",e,!1):window.onresize=e)},load:function(a){function e(t){let e;function a(e){t.source.postMessage(JSON.stringify(e),"*")}if("string"==typeof t.data?e=JSON.parse(t.data):"object"==typeof t.data&&(e=t.data),e)if(void 0===e.action)a({type:"error",data:[{id:"400",label:'"action" is required.'}]});else if("send"===e.action){var i=e.id||VisualJS.id,i=VisualJS.container[i];if(i){if("cmap"===i.type&&!i.data[0].hasOwnProperty("label")){var l=[];for(let e=VisualJS.map[i.by],t=e.features.length;t--;)l[e.features[t].properties[e.id]]=e.features[t].properties[e.label];for(let e=i.data,t=e.length;t--;)e[t].label=l[e[t].id]}a(i)}else a({type:"error",data:[{id:"404",label:'A visualisation with the specified "id" was not found'}]})}else a({type:"error",data:[{id:"400",label:'"action" value is not correct.'}]})}if(void 0===VisualJS.setup&&window.alert("Visual: Setup not found (visual.setup.js)!"),"[object Array]"!==Object.prototype.toString.call(a))VisualJS.get(a);else for(let e=0,t=a.length;e<t;e++)VisualJS.get(a[e]);VisualJS.container[VisualJS.id].listen&&window.addEventListener&&window.addEventListener("message",e,{once:!0})},get:function(R){function t(e,a,i){if("string"==typeof e)a.match(typeof R[e])||(R[e]=i[e]);else if(!a.match(typeof r(R,e))){a=R;var l=e;i=r(i,e);let t=a;for(let e=0;e<=l.length-2;e++)void 0===t[l[e]]&&(t[l[e]]={}),t=t[l[e]];t[l[l.length-1]]=i}}function r(e,t){let a=e;for(let e=0;e<t.length;e++){if(void 0===a[t[e]]){a=void 0;break}a=a[t[e]]}return a}let X=VisualJS.setup,e=X.html,Y=X.canvas,s=e.heading,D="."+VisualJS.setup.footerclass,o=function(e){return"object"==typeof e&&null!==e},a=[["show","boolean",VisualJS],["callback","function",VisualJS],["id","string",X],["listen","boolean",X],["dec","number|object",Y],["autoheading","boolean",Y],["legend","boolean",Y],["grid","object",Y],[["grid","border"],"number",Y],[["grid","shadow"],"number",Y],[["grid","line"],"number",Y],[["grid","point"],"number",Y],[["grid","markings"],"object",Y],["axis","object",Y],[["axis","x"],"boolean",Y],[["axis","y"],"boolean",Y],[["axis","labels","x"],"boolean",Y],[["axis","labels","y"],"boolean",Y],[["axis","ticks","x"],"boolean",Y],[["axis","ticks","y"],"boolean",Y]];void 0===Y.axis.labels&&(Y.axis.labels={x:!0,y:!0}),void 0===Y.axis.ticks&&(Y.axis.ticks={x:!0,y:!0});for(let e=0;e<a.length;e++)t(a[e][0],a[e][1],a[e][2]);var i;VisualJS.scripts=[],VisualJS.id=R.id,VisualJS.pub[VisualJS.id]={heading:null,legend:null},"object"==typeof R.fixed&&(VisualJS.fixed=R.fixed),"object"==typeof R.unit&&null!==R.unit?(t(["unit","label"],"string|object",Y),t(["unit","symbol"],"string|object",Y),t(["unit","position"],"string|object",Y)):R.unit=Y.unit,R.range=(e=>{var a=(()=>{let e="invalid";return Array.isArray(R.data)&&(Array.isArray(R.data[0])?e="array":o(R.data[0])&&(e=o(R.data[0].z)?"xyz":o(R.data[0].y)?"xy":void 0!==R.data[0].x||void 0!==R.data[0].y||!Array.isArray(R.data[0].val)||null===R.data[0].val[0]||2!=R.data[0].val[0].length&&3!=R.data[0].val[0].length?"object":"points")),e})();if("object"!=typeof e||null===e||Array.isArray(e)||"array"!==a&&"object"!==a||("rank"===R.type||"pyram"===R.type?e=e.x:"xy"!==R.type&&(e=e.y)),Array.isArray(e)&&2===e.length&&null===e[0]&&null===e[1])R.data&&"object"===a&&(0<=(i=(()=>{if(!R.data||0===R.data.length)return[void 0,void 0];let t=R.data[0].val[0],a=R.data[0].val[0];return R.data.forEach(e=>{e.val.forEach(e=>{t=e<t?e:t,a=e>a?e:a})}),[t,a]})())[0]&&0<=i[1]?e=[0,null]:i[0]<=0&&i[1]<=0&&(e=[null,0]));else if("object"==typeof e&&!Array.isArray(e)&&null!==e&&(Array.isArray(e.x)&&null===e.x[0]&&null===e.x[1]||Array.isArray(e.y)&&null===e.y[0]&&null===e.y[1])){let t={x:[],y:[]};"points"===a?R.data.forEach(function(e){e.val.forEach(function(e){t.x.push(e[0]),t.y.push(e[1])})}):"xy"!==a&&"xyz"!==a||R.data.forEach(function(e){t.x=t.x.concat(e.x.val),t.y=t.y.concat(e.y.val)});var i=function(e,t,a,i){Array.isArray(e[t])&&null===e[t][0]&&null===e[t][1]&&(0<=a[t]&&0<=i[t]?e[t]=[0,null]:a[t]<=0&&i[t]<=0?e[t]=[null,0]:e[t]=[null,null])},l={x:Math.min(...t.x),y:Math.min(...t.y)},n={x:Math.max(...t.x),y:Math.max(...t.y)};i(e,"x",l,n),i(e,"y",l,n)}else"xy"!==a&&"xyz"!==a&&"points"!==a||("number"==typeof e||Array.isArray(e)?e={x:[null,null],y:Array.isArray(e)?e:[null,e]}:"object"==typeof e&&null!==e||(e={x:[null,null],y:[null,null]}));return e})(R.range),R.lang=R.lang||X.i18n.lang,"number"==typeof R.range||void 0!==(i=R.range)&&Array.isArray(i)&&2===i.length&&"number"==typeof i[0]&&"number"==typeof i[1]&&i[0]<i[1]||"object"==typeof R.range&&null!==R.range&&!Array.isArray(R.range)||(R.range="number"==typeof R.range||Array.isArray(R.range)&&2===R.range.length?R.range:Y.range.hasOwnProperty(R.type)&&"number"==typeof Y.range[R.type]?Y.range[R.type]:null),R.unit=(e=>{var t,a;if("xy"!==R.type)for(var i in e)e.hasOwnProperty(i)&&(i=i,t="rank"===R.type||"pyram"===R.type?"x":"y",a=void 0,(a=e[i])&&void 0!==a[t]?e[i]=a[t]:e[i]="string"==typeof a?a:"");return e})(R.unit),R.tooltipseparator=X.tooltipseparator&&"string"==typeof X.tooltipseparator?X.tooltipseparator:" / ",VisualJS.container[VisualJS.id]=R;function y(){return!1!==K.tooltip}function f(){if(!1===K.autoheading)return K.title||"";let a=[],e;function t(e,t){"string"==typeof e&&""!==e&&(!0===t&&(e='<span class="'+VisualJS.setup.nowrapclass+'">'+e+"</span>"),a.push(e))}return e=null!==K.time&&"object"==typeof K.time?V(K.time[0],VisualJS.id)+"–"+V(K.time[K.time.length-1],VisualJS.id):V(K.time,VisualJS.id),t(K.title,!1),t(K.geo,!0),t(e,!0),g(a.join(". "))}function l(){let e=!1;var t,a;"function"==typeof VisualJS.chart&&(y()&&!(a=document).getElementById(VisualJS.setup.tooltipid)&&((t=a.createElement("div")).setAttribute("role","tooltip"),t.id=VisualJS.setup.tooltipid,t.style.display="none",a.body.appendChild(t)),K.show&&VisualJS.chart(),VisualJS.fixed||(window.addEventListener?window.addEventListener("resize",A,!1):window.onresize=A),e=!0),null!==K.callback&&K.callback.call({id:VisualJS.id,chart:e,heading:VisualJS.pub[VisualJS.id].heading,legend:VisualJS.pub[VisualJS.id].legend})}function g(e){return String(e).replace(/&/g,"&")}function x(e,t){return!(t&&e.exists.call()||(VisualJS.scripts.push(e.js),0))}function U(e,t,a){var i="number"==typeof a&&""!==VisualJS.container[e].unit.label?" "+VisualJS.container[e].unit.label:"",l="number"==typeof a?VisualJS.container[e].unit.symbol:"",e=(a=Z(a,e))!==VisualJS.setup.i18n.text.na[VisualJS.container[e].lang]?"end"===VisualJS.container[e].unit.position?a+i+(""!==l?" "+l:l):l+a+i:a;return t?`<strong>${e}</strong> `+t:e}function Q(e,t,a){var i="number"==typeof a?VisualJS.container[e].unit.symbol:"",e=(a=Z(a,e))!==VisualJS.setup.i18n.text.na[VisualJS.container[e].lang]?"end"===VisualJS.container[e].unit.position?a+""+(""!==i?" "+i:i):i+a+"":a;return t?`<strong>${e}</strong> `+t:e}function b(e,t,a,i){return R.axis.labels[a]?("function"==typeof i?i:Z)(e,t,a):""}function h(e){return e.map(e=>Array.isArray(e)?[e[0],""]:[e,""])}function V(e,t){let a,i;if(!n){if(!e)return null;if(isNaN(e))return e;switch(e.length){case 5:a=VisualJS.setup.i18n.text.quarter,i=u("aaaaq",R.lang);break;case 6:a=VisualJS.setup.i18n.text.month,i=u("aaaamm",R.lang);break;default:return e}n={label:a,text:a[VisualJS.container[t].lang],template:i}}var l;return void 0===n.label||void 0===n.text||void 0===(t=n.text[e.slice(4)-1])?e:(l=e.slice(0,4),n.template.replace("{{period}}",t).replace("{{year}}",l))}function G(e,t,a){var i=document.getElementById(VisualJS.setup.tooltipid),l=VisualJS.bwidth-VisualJS.setup.margin,n={},r=i.clientWidth/2;i.innerHTML=e,i.style.display="block",n.x=t-r,n.y=a-i.clientHeight-5,l<t+r?n.x-=t+r-l:n.x<VisualJS.setup.margin&&(n.x+=VisualJS.setup.margin-n.x),n.y<VisualJS.setup.margin&&(n.y+=1.75*i.clientHeight),i.style.left=n.x+"px",i.style.top=n.y+"px"}let k,w,A,n=null,j="#"+VisualJS.id,E=j+" ."+X.canvasclass,K=VisualJS.container[VisualJS.id],Z=function(t,a,i){if(null==t)return VisualJS.setup.i18n.text.na[VisualJS.container[a].lang];if("number"!=typeof t)return"";{var l=/(\d+)(\d{3})/,i=("object"==typeof VisualJS.container[a].dec&&null!==VisualJS.container[a].dec&&"string"==typeof i&&"number"==typeof VisualJS.container[a].dec[i]?t.toFixed(VisualJS.container[a].dec[i]):"number"==typeof VisualJS.container[a].dec?t.toFixed(VisualJS.container[a].dec):String(t)).split(".");let e=i[0];for(t=1<i.length?VisualJS.setup.i18n.text.dec[VisualJS.container[a].lang]+i[1]:"";l.test(e);)e=e.replace(l,"$1"+VisualJS.setup.i18n.text.k[VisualJS.container[a].lang]+"$2");return e+t}},u=function(e,t){var a=X.i18n.template;if(a){if("string"==typeof a)return a;if("object"==typeof a&&a[e]&&"string"==typeof a[e][t])return a[e][t]}return"{{period}} {{year}}"};if("cmap"===R.type){if("string"!=typeof R.by)return;x(X.lib.maps,!0),x(X.lib.d3,!0),x(X.map[R.by],!0),VisualJS.chart=function(){let I=f(),M=VisualJS.map[R.by],F=M.area[0],B=M.area[1],T=null!==R.grouped&&"object"==typeof R.grouped&&Array.isArray(R.grouped.label)&&0<R.grouped.label.length&&R.data[0].hasOwnProperty("group"),q=R.data[0].hasOwnProperty("val"),W=T?R.grouped.label.length:q?X.colors.map.max:1,C=X.colorclassprefix,O=d3.select(j),e=d3.geo[M.projection](),t="object"==typeof M.center&&"function"==typeof e.center?e.center(M.center):e,a=t.scale(M.scale).translate([F/2,B/2]),P=d3.geo.path().projection(a),H=d3.select("#"+X.tooltipid),N=VisualJS.func.colors(X.colors.map.base,W,"fill",C,T&&!q&&"object"==typeof R.grouped.color&&R.grouped.color.length===R.grouped.label.length?R.grouped.color:[],VisualJS.id);(A=function(){var L,$,z=g(VisualJS.arr2html(R.footer)||"");if(O.html("<header><"+s+' id="ARIAtitle" style="overflow:auto;" ></'+s+'></header><footer class="'+VisualJS.setup.footerclass+'" style="overflow:auto;"></footer>'),d3.select(j+" "+s).html(I),d3.select(j+" "+D).html(z),VisualJS.getSize(VisualJS.id)){let i=VisualJS.id,l=d3.map(),n=d3.map(),r=R.data[0].hasOwnProperty("label"),t=[],e=VisualJS.height/B,a=VisualJS.width/F,s=Math.min(Math.round(F*e),VisualJS.width),o=Math.min(Math.round(B*a),VisualJS.height),u=Math.floor((VisualJS.width-s)/2),d=Math.floor((VisualJS.height-o)/2),p=e<a?e:a,c=O.insert("svg:svg",D).attr("viewBox","0 0 "+s+" "+o).attr("width",s).attr("height",o).attr("role","img").attr("aria-labelledby","ARIAtitle"),y=function(){},f=function(){},g=!0,x,b,h,m,v,S,J=(T&&q?(S=[],[1,R.grouped.label.length].forEach(function(t){for(let e=0;e<R.data.length;e++)if(R.data[e].group===t){S.push(R.data[e].val);break}}),S[0]>S[1]&&(g=!1)):T&&R.grouped.color&&(N=R.grouped.color),T?(x=d3.map(),f=function(e,t){e.set(t.id,t.group)},VisualJS.groupedLabelSize=null,h=function(e,t,a){var i;return q&&!g?(VisualJS.groupedLabelSize||(i=d3.values(e).reduce((e,t)=>(e[t]=1+(e[t]||0),e),{}),VisualJS.groupedLabelSize=Object.keys(i).length),C+(VisualJS.groupedLabelSize-e.get(a[M.id]))):C+(e.get(a[M.id])-1)},b=function(e,t){e=R.grouped.label[e.get(t[M.id])-1];let a=r?n.get(t[M.id]):t[M.label];return void 0!==e&&(a+=` <em>${e}</em>`),a},y=VisualJS.func.legend):q?(h=function(e,t,a,i,l){t=t.get(a[M.id]);return void 0===t?"":i===l?C+(W/2).toFixed(0):d3.scale.quantize().domain([i,l]).range(d3.range(W).map(function(e){return C+e}))(t)},y=VisualJS.func.legend):h=function(e,t,a){return""!==t.get(a[M.id])?"":C+(W-1)},b=function(e,t){return r?n.get(t[M.id]):t[M.label]},R.data.forEach(e=>{e.hasOwnProperty("val")?null!==e.val&&(l.set(e.id,e.val),t.push(e.val)):l.set(e.id,""),r&&n.set(e.id,e.label),f(x,e)}),t.sort(function(e,t){return e-t}),t[0]),V=t[t.length-1],k=function(e,t,a){""!==e.properties[M.id]&&""!==e.properties[M.label]&&(q||T||void 0!==l.get(e.properties[M.id]))&&G(U(i,b(x,e.properties),l.get(e.properties[M.id])),t,a)},w=!1,A=null,j=null,E;v="number"==typeof K.range?(m=d3.quantile(t,K.range),d3.quantile(t,1-K.range)):(m=K.range[0],K.range[1]),"function"!=typeof K.click&&(K.click=function(){}),c.style("margin-left",u+"px"),c.style("margin-top",d+"px"),c.style("margin-bottom",d+"px"),c.append("g").attr("class",X.areaclass).attr("transform","scale("+p+")").selectAll("path").data(M.features).enter().append("svg:path").attr("class",function(e){return""===e.properties[M.id]||""===e.properties[M.label]||!q&&void 0===l.get(e.properties[M.id])?C+"nohover":h(x,l,e.properties,m,v)}).attr("tabindex",function(){return d3.select(this).classed(C+"nohover")?"-1":"0"}).attr("role","presentation").attr("d",P).on("mousemove",function(e,t){k(e,d3.event.pageX,d3.event.pageY)}).on("mouseout",function(){return H.style("display","none")}).on("mousedown",function(){w=!0}).on("mouseup",function(){w=!1}).on("focusout",function(){return H.style("display","none")}).on("focusin",function(t){if(w){let e=!0;var a=(new Date).getTime();K.priv&&K.priv.click?500<a-K.priv.click?K.priv.click=a:e=!1:K.priv={click:a},e&&K.click.apply(null,[{id:t.properties[M.id],label:r?void 0!==n.get(t.properties[M.id])?n.get(t.properties[M.id]):null:t.properties[M.label],position:{x:d3.event.pageX,y:d3.event.pageY},group:T&&void 0!==x.get(t.properties[M.id])?{num:x.get(t.properties[M.id]),label:K.grouped.label[x.get(t.properties[M.id])-1]}:null,value:q&&void 0!==l.get(t.properties[M.id])?l.get(t.properties[M.id]):null}]),A=d3.event.pageX,j=d3.event.pageY}else E=d3.select(this).node().getBoundingClientRect(),A=(E.left+E.right)/2,j=(E.top+E.bottom)/2;k(t,A,j)}).on("keyup",function(e){var t;"Enter"===d3.event.key&&(t=d3.select(this).node().getBoundingClientRect(),K.click.apply(null,[{id:e.properties[M.id],label:r?void 0!==n.get(e.properties[M.id])?n.get(e.properties[M.id]):null:e.properties[M.label],position:{x:t.left,y:t.top},group:T&&void 0!==x.get(e.properties[M.id])?{num:x.get(e.properties[M.id]),label:K.grouped.label[x.get(e.properties[M.id])-1]}:null,value:q&&void 0!==l.get(e.properties[M.id])?l.get(e.properties[M.id]):null}]))}),(q||T)&&(z=[U(i,null,m),U(i,null,v)],L=[N[N.length-1],N[0]],$=[m<J||Z(m,i)===Z(J,i),v>V||Z(v,i)===Z(V,i)],T?(!q&&void 0!==R.grouped.color||(R.grouped.color=N),VisualJS.pub[VisualJS.id].legend={color:R.grouped.color,text:R.grouped.label},K.legend&&VisualJS.func.groupLegend(z,c,H,o,$,R,Y,g)):q&&(z=[Q(i,null,m),Q(i,null,v)],VisualJS.pub[VisualJS.id].legend={color:L,text:z,symbol:[$[0]?"==":"<=",$[1]?"==":">="]},K.legend)&&VisualJS.func.legend(z,N,c,H,o,$,R.unit.label)),VisualJS.pub[VisualJS.id].heading=I}})(),document.querySelectorAll(".visual .VisualJSarea path").forEach(function(e){e.addEventListener("mouseenter",function(){this.parentNode.appendChild(this)})})}}else{let e=!0,d=(x(X.lib.jquery,!0)?(e=!1,x(X.lib.jquery.flot,!1)):x(X.lib.jquery.flot,!0)&&(e=!1),[]),t=function(){if(K.autoheading){let e=R.time.length,t,a;if(null===R.data[0].val[0]){for(t=0,a=[];t<e;t++){if(!R.data.every(e=>null===e.val[t]))break;a.push(!0)}0<a.length&&(R.time.splice(0,a.length),R.data.forEach(e=>e.val.splice(0,a.length))),e=R.time.length}if(null===R.data[0].val[e-1]){for(t=e,a=[];t--;){if(!R.data.every(e=>null===e.val[t]))break;a.push(!0)}0<a.length&&(R.time.splice(-a.length),R.data.forEach(e=>e.val.splice(-a.length)))}}let u=function(){};return J?x(X.lib.jquery.flot.stack,e):"tsbar"===R.type&&(x(X.lib.jquery.flot.orderbars,e),u=function(e){return e.bars}),c=function(i,e){VisualJS.ticks=[];let l,t=e.length,a=i.length,n=K.grid&&K.grid.bar&&"number"==typeof K.grid.bar?K.grid.bar:2<=t&&4<a?.18:.2;for(l=0;l<t;l++){var r;"tsbar"===R.type?(r=l-(1<a?n/2:0),S.push([r,e[l]]),VisualJS.ticks.push([r,e[l]])):(S.push([l,e[l]]),VisualJS.ticks.push([l,e[l]]))}for(l=0;l<a;l++){var s=[];for(let e=i[l].val,t=e.length,a=0;a<t;a++)s.push([a,e[a]]);"tsbar"!==R.type||J||1===a?v.push({label:i[l].label,data:s}):v.push({label:i[l].label,data:s,bars:{show:!0,barWidth:n,order:l+1,lineWidth:2,align:"center"}})}var o=v.length;for(l=0;l<o;l++)d.push({data:v[l].data,label:v[l].label,bars:u(v[l]),shadowSize:K.grid.shadow});p=1<o},f()},p,a,i,l,n,o,u,v=[],S=[],c=function(){},J=R.stacked||!1;switch(Array.max=function(e){return Math.max.apply(Math,e)},R.type){case"xy":x(X.lib.jquery.flot.axisLabels,e),l=!0,n=!1,i=!1,u=f(),c=function(e,t,a){Array.isArray(e)&&Array.isArray(e[0])?v=[e]:Array.isArray(e)&&"object"==typeof e[0]&&!Array.isArray(e[0])&&(v=e.map(e=>{return e={label:(a=e).label,data:[],by:Array.isArray(a.by)&&"string"==typeof a.by[0]?a.by:null},"object"==typeof a.x&&"object"==typeof a.y?(X.canvas.axis.labelsText={x:a.x.label,y:a.y.label},e.data=a.x.val.map((e,t)=>[e,a.y.val[t]])):a.val&&1<=a.val.length&&2==a.val[0].length&&(X.canvas.axis.labelsText={x:a.x,y:a.y},e.data=a.val),e;var a}))},p=!0;break;case"pyram":x(X.lib.jquery.flot.pyramid,e),l=!1,n=!1,u=f(),c=function(a,e,t){k=Math.max(Array.max(a[0].val),Array.max(a[1].val)),v[0]={label:a[0].label,data:[],pyramid:{direction:"L"}},v[1]={label:a[1].label,data:[]},t.forEach((e,t)=>{v[0].data[t]=[e,a[0].val[t]],v[1].data[t]=[e,a[1].val[t]]})},p=!0,a=!1,J=!1,i=!1;break;case"rank":let r=[];i=!1,l=!1,n=!0,u=f(),c=function(a,e,i){var l=[];for(let e=0,t=a.length;e<t;e++){var n=t-e-1,n=(S[e]=[e,void 0!==a[n][0]?a[n][0]:i[n]],void 0!==a[n][1]?a[n][1]:a[n]);l.push(n),r[e]=[n,e]}v={data:r},k=Array.max(l)},p=!1,a=!1;break;case"pie":x(X.lib.jquery.flot.pie,e),o=!0,i=!1,l=!1,n=!1,u=f(),c=function(a,e,t){"object"!=typeof t||null===t?v=a.filter(e=>null!==e[1]).map(e=>({label:e[0],data:e[1]})):"number"==typeof a[0]&&(v=t.filter((e,t)=>null!==a[t]).map((e,t)=>({label:e,data:a[t]})))},p=!0;break;case"bar":let s=function(){};J?(x(X.lib.jquery.flot.stack,e),s=function(e){return e.bars}):x(X.lib.jquery.flot.categories,e),l=!1,n=!0,u=f(),i=!1,c=function(a,e,i){if("object"!=typeof i||null===i)v=[v=a.filter(e=>null!==e[1]).map(e=>[`<span>${e[0]}</span>`,e[1]])];else if(J){VisualJS.ticks=[];let t,e;for(t=0,e=a.length;t<e;t++)S.push([t,a[t].label]),VisualJS.ticks.push([t,a[t].label]);for(t=0,e=i.length;t<e;t++){var l=[];for(let e=0;e<a.length;e++){var n=a[e].val;l.push([e,n[t]])}v.push({label:i[t],data:l})}var r=v.length;for(t=0;t<r;t++)d.push({data:v[t].data,label:v[t].label,bars:s(v[t]),shadowSize:K.grid.shadow})}else if(R.by&&R.by.length&&"object"==typeof R.data[0]){v=R.by.map(e=>({label:e,data:[]}));let a=0;R.data.forEach(e=>{var t=e.val;S.push([t.length%2==0?a+(t.length-1)/2:Math.floor(a+t.length/2),e.label]),t.forEach((e,t)=>{v[t].data.push([a,e]),a++}),a++})}else v=[v="number"==typeof a[0]?i.filter((e,t)=>null!==a[t]).map((e,t)=>[`<span>${e}</span>`,a[t]]):v]},p=!0,a=!0;break;case"tsline":u=t(),a=null,l=!0,n=!1,i=!0;break;case"tsbar":u=t(),a=!0,l=!1,n=!0,i=!1}VisualJS.chart=function(){c(R.data,R.time,R.by),$.fn.UseTooltip=function(b){let h=[];$(this).bind("plothover",function(e,t,a){let i;if(a){if(h!=[a.seriesIndex,a.dataIndex])if(h=[a.seriesIndex,a.dataIndex],"xy"===R.type){var l,n={},r={},s=VisualJS.container[b].unit,o={x:"start"===s.position.x,y:"start"===s.position.y,z:"start"===s.position.z};for(l in o){var u=o[l],d=s.symbol&&"string"==typeof s.symbol[l]?s.symbol[l]:"",p=s.label&&"string"==typeof s.label[l]?s.label[l]:"";u?(n[l]=d,r[l]=p,r[l]=""!==r[l]?" "+r[l]:""):(n[l]="",r[l]=" "+p+" "+d)}i="<div><strong>"+n.x+Z(a.datapoint[0],b,"x")+r.x+"</strong> "+(void 0!==m.xaxis.axisLabel?m.xaxis.axisLabel:"x")+"</div><div><strong>"+n.y+Z(a.datapoint[1],b,"y")+r.y+"</strong> "+(void 0!==m.yaxis.axisLabel?m.yaxis.axisLabel:"y")+"</div>",i+=Array.isArray(v[a.seriesIndex].by)&&"string"==typeof v[a.seriesIndex].by[a.dataIndex]&&""!==v[a.seriesIndex].by[a.dataIndex]?v[a.seriesIndex].by[a.dataIndex]+("string"==typeof v[a.seriesIndex].label&&""!==v[a.seriesIndex].label?" ("+v[a.seriesIndex].label+")":""):"",G(i,t.pageX,t.pageY)}else{var c=a.datapoint[0],y=a.datapoint[1],f="bar"!==R.type||Boolean(R.data[0].val)?a.series.label:(1<v.length?v:v[0])[c][0],f="rank"!==R.type?f:S[y][1],g=!!("rank"!==R.type&&"pie"!==R.type&&"bar"!==R.type||"bar"===R.type&&Boolean(R.data[0].val))&&(J||1===v.length?!!(Array.isArray(S)&&0<S.length)&&S[c][1]:"pyram"===R.type?v[t.x<0?0:1].data[a.dataIndex][0]:S[a.dataIndex][1]),x=(g=g,f=f,x=VisualJS.container[b].tooltipseparator,"bar"===R.type&&R.by?g?""+g+(f?x+f:""):f||"":g?""+(f?f+x+g:g):f||"");i="pyram"===R.type?Math.abs(c):"rank"===R.type?c:"tsbar"===R.type||"bar"===R.type&&J?J||1===v.length?v[a.seriesIndex].data[c][1]:y:"pie"===R.type?y[0][1]:y,G(U(b,x,i),t.pageX,t.pageY)}}else $("#"+X.tooltipid).hide(),h=[];var x})};let m={colors:X.colors.series,series:{stack:a,bars:{show:n,barWidth:.7,align:"center",fill:.9},pie:{show:o,label:{show:!1}},lines:{show:i,lineWidth:K.grid.line},points:{show:l,radius:K.grid.point,fill:.85,fillColor:null}},legend:{show:K.legend&&p,position:Y.position||"ne"},grid:{borderWidth:K.grid.border,hoverable:!0,clickable:!1,mouseActiveRadius:10},xaxis:{show:K.axis.x,axisLabel:void 0!==r(X.canvas.axis,["labelsText","x"])?X.canvas.axis.labelsText.x:void 0,axisLabelUseCanvas:!0,axisLabelFontSizePixels:w=Number($("."+VisualJS.setup.clas).css("font-size").replace("px","")),axisLabelFontFamily:$("."+VisualJS.setup.clas).css("font-family"),axisLabelPadding:w,axisLabelColour:"#545454",labelWidth:28},yaxis:{show:K.axis.y,axisLabel:void 0!==r(X.canvas.axis,["labelsText","y"])?X.canvas.axis.labelsText.y:void 0,axisLabelUseCanvas:!0,axisLabelFontSizePixels:w,axisLabelFontFamily:$("."+VisualJS.setup.clas).css("font-family"),axisLabelPadding:w,axisLabelColour:"#545454"}};(A=function(){let a=VisualJS.id,i=S.length,e=g(VisualJS.arr2html(R.footer)||"");if($(j).html(`<header><${s} id="ARIAtitle" style="overflow:auto;">${u}</${s}></header><footer class=${VisualJS.setup.footerclass} style="overflow:auto;">${e}</footer>`),VisualJS.getSize(a)){var t=X.typeclassprefix+R.type;switch($(j+" header").after('<main class="'+X.canvasclass+" "+t+" "+VisualJS.visualsize+'" style="width: '+VisualJS.width+"px; height: "+VisualJS.height+'px; display: block;"></main>'),m.xaxis.tickFormatter=function(e){return b(e,a,"x")},m.yaxis.tickFormatter=function(e){return b(e,a,"y")},m.xaxis.tickLength=R.axis.ticks.x?null:0,m.yaxis.tickLength=R.axis.ticks.y?null:0,m.grid.markings=R.grid.markings||null,R.type){case"xy":R.range?(R.range.x?Array.isArray(R.range.x)?(m.xaxis.min=R.range.x[0],m.xaxis.max=R.range.x[1]):(m.xaxis.min=0,m.xaxis.max=R.range.x):(m.xaxis.min=null,m.xaxis.max=null),R.range.y?Array.isArray(R.range.x)?(m.yaxis.min=R.range.y[0],m.yaxis.max=R.range.y[1]):(m.yaxis.min=0,m.yaxis.max=R.range.y):(m.yaxis.min=null,m.yaxis.max=null)):(m.xaxis.min=null,m.yaxis.min=null,m.xaxis.max=null,m.yaxis.max=null),m.hooks={drawBackground:function(e,t){e=e.getXAxes()[0];void 0!==e.ticks&&0<e.ticks.length&&(e.datamin=e.ticks[0].v,e.datamax=e.ticks[e.ticks.length-1].v)}},$.plot(E,v,m);break;case"pyram":m.series.pyramid={show:!0,barWidth:1},m.yaxis.show=!!(11<VisualJS.height/v[0].data.length&&R.axis.labels.y)&&K.axis.y,m.xaxis.max="number"==typeof K.range?k*K.range:Array.isArray(K.range)?K.range[1]:null,m.xaxis.tickFormatter=function(e){return b(e,a,"x",Z)},$.plot(E,v,m);break;case"rank":m.series.bars.horizontal=!0,m.yaxis.ticks=11<VisualJS.height/i?S.slice(0):0,!1===R.axis.labels.y&&(m.yaxis.ticks=h(m.yaxis.ticks)),"number"==typeof K.range?m.xaxis.max=k*K.range:Array.isArray(K.range)&&(m.xaxis.min=K.range[0],m.xaxis.max=K.range[1]),m.xaxis.tickFormatter=function(e){return b(e,a,"x",Z)},m.yaxis.autoscaleMargin=0,m.series.bars.barWidth=.5,$.plot(E,[v],m);break;case"pie":$.plot(E,v,m);break;case"bar":m.xaxis.tickLength=0,!1===R.axis.labels.x&&(m.xaxis.ticks=h(S),m.xaxis.show=!1),R.by&&R.by.length&&"object"==typeof R.data[0]?(m.xaxis.ticks=S,m.bars={show:!0}):(m.xaxis.mode="categories",m.yaxis.tickFormatter=function(e){return b(e,a,"y",Z)}),"number"!=typeof K.range&&null!==K.range?(m.yaxis.min=K.range[0],m.yaxis.max=K.range[1]):"number"==typeof K.range&&(m.yaxis.min=null,m.yaxis.max=K.range),$.plot(E,v,m);break;case"tsline":case"tsbar":"tsbar"===R.type?m.xaxis.tickLength=0:null===m.grid.markings&&(m.grid.markings=[{color:"#333333",lineWidth:1,yaxis:{from:0,to:0}}]),m.yaxis.tickFormatter=function(e){return b(e,a,"y",Z)};var l=VisualJS.width/i,n=[],r="string"==typeof R.first&&R.first?R.first:6===VisualJS.ticks[0][1].length?"01":"1";let e;"number"!=typeof K.range&&null!==K.range?(m.yaxis.min=K.range[0],m.yaxis.max=K.range[1]):"number"==typeof K.range&&(m.yaxis.min=null,m.yaxis.max=K.range);let t;switch(VisualJS.ticks[0][1].length){case 4:if(l<33){for(e=16.5<l?2:10.5<l?3:9<l?4:10,t=0;t<i;t++)n[t]=t%e?[S[t][0],""]:[S[t][0],S[t][1]];m.xaxis.ticks=n}else m.xaxis.ticks=S;!1===R.axis.labels.x&&(m.xaxis.ticks=h(m.xaxis.ticks));break;case 5:case 6:if(l<56){for(l<8.5&&56<i&&$("main").addClass(X.mini),t=0;t<i;t++)n[t]=VisualJS.ticks[t][1].slice(4)!==r?[VisualJS.ticks[t][0],""]:[VisualJS.ticks[t][0],VisualJS.ticks[t][1].slice(0,4)],S[t][1]=V(VisualJS.ticks[t][1],VisualJS.id);m.xaxis.ticks=n}else{for(t=0;t<i;t++)S[t][1]=V(VisualJS.ticks[t][1],VisualJS.id);m.xaxis.ticks=S}!1===R.axis.labels.x&&(m.xaxis.ticks=h(m.xaxis.ticks));break;case 7:if(l<55){for(e=20<l?2:10<l?3:4,t=0;t<i;t++)n[t]=t%e?[S[t][0],""]:[S[t][0],S[t][1]];m.xaxis.ticks=n}else m.xaxis.ticks=S;!1===R.axis.labels.x&&(m.xaxis.ticks=h(m.xaxis.ticks));break;default:m.xaxis.ticks=S,!1===R.axis.labels.x&&(m.xaxis.ticks=h(m.xaxis.ticks))}$.plot(E,d,m)}y()&&$(E).UseTooltip(VisualJS.id),VisualJS.pub[VisualJS.id].heading=u,$(E).find("canvas").attr("role","img").attr("aria-labelledBy","ARIAtitle")}})()}}VisualJS.scripts.length&&"object"==typeof LazyLoad?LazyLoad.js(VisualJS.scripts,l):l()}};var visual;Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),"function"!=typeof visual&&(visual=VisualJS.load);