var project={"_id":"5bad4931ab233e8499be261d","id":"940446eb361650783af19cea4b7e80271a47559d","name":"Map builder","user":"566ac9850286a8f9080cdd79","description":"","created":"2018-09-26T11:52:02.564Z","shared":false,"server":"micro","datafiles":[{"file":{"link":"https://v4p4sz5ijk.execute-api.us-east-1.amazonaws.com/anbdata/services/groupselect","type":"URL/API","url":"https://v4p4sz5ijk.execute-api.us-east-1.amazonaws.com/anbdata/services/groupselect","message":{"error":false,"text":""}},"varname":"groups","title":"Groups","activated":true,"name":"datafile","linkedtofile":true,"optional":true,"content":""},{"file":{"link":"https://s3.amazonaws.com/istarsshare/worldcountry.txt","type":"URL/API","url":"https://s3.amazonaws.com/istarsshare/worldcountry.txt","message":{"error":false,"text":""}},"varname":"collection","title":"countries","activated":true,"name":"datafile","linkedtofile":true,"optional":true,"content":"","sendtojs":true},{"file":{"link":"http://api.anbdata.com/anb/services/swagger","type":"URL/API","url":"http://api.anbdata.com/anb/services/swagger","message":{"error":false,"text":""}},"varname":"anbdata","title":"APIs","activated":true,"name":"datafile","linkedtofile":true,"optional":true,"content":"","sendtojs":true},{"file":{"link":"https://v4p4sz5ijk.execute-api.us-east-1.amazonaws.com/anbdata/states/names/icao-member-states?api_key=7c3cb620-ed23-11e5-a5f9-adff4fb3e3e1&format=json","type":"URL/API","url":"https://v4p4sz5ijk.execute-api.us-east-1.amazonaws.com/anbdata/states/names/icao-member-states?api_key=7c3cb620-ed23-11e5-a5f9-adff4fb3e3e1&format=json","message":{"error":false,"text":""}},"varname":"icaostates","title":"icaostates","activated":true,"name":"datafile","linkedtofile":true,"optional":true,"content":"","sendtojs":true}],"packs":["bootstrap","jquery","D3","Datatables"],"container":"mainpart","js":{"file":{"type":"","url":"","link":"","message":{"error":true,"text":"File not defined"},"depurl":"https://quipslibistars.s3.amazonaws.com/prod/940446eb361650783af19cea4b7e80271a47559d/script.js"},"title":"Javascript","activated":true,"name":"js","linkedtofile":false,"optional":true,"content":"$(\"#customgroups optgroup:eq(0)\").remove()\n$(\"#customgroups\").val(\"530e1ca1afc6139425000409\")\nicaostates.sort(function(a,b){return (a.UN_state_name=0) elim=true\n })\n if (path.split(\"/\")[1]==\"states\"&&!elim) {\n var schema=anbdata.paths[path].get.responses[\"200\"].schema.$ref.split(\"/\")[2]\n var api=anbdata.definitions[schema]\n if (api.description&&api.description.split(\";\")[0].toUpperCase().indexOf(\"AGGREG\")<0) {\n var descr=api.description.split(\";\")\n var group=$(\"\")\n databox[descr[0]]={}\n var counts=0\n for (var prop in api.properties) {\n if (api.properties[prop].type==\"number\"&&api.properties[prop].description.toUpperCase().indexOf(\"LATITUDE\")<0&&api.properties[prop].description.toUpperCase().indexOf(\"LONGITUDE\")<0) {\n counts++\n var t=api.properties[prop].description.toUpperCase()\n var unit=\"\"\n if (t.indexOf(\"SCORE\")>=0||t.indexOf(\"PERCENT\")>=0||t.indexOf(\"%\")>=0) unit=\"%\"\n $(\"\").appendTo(group)\n apibundle[descr[0]]={url:path}\n }\n }\n //console.log(group.html())\n if (counts>0) $(\"#metric\").append(group)\n \n } \n } \n }\n $(\"#metric\").val(\"/states/usoap/ei-stats/overall\")\n\n}\nfunction applycols(){\n $(\"#cscale_h\").closest(\"tr\").find(\".colbox\").css(\"background-color\",$(\"#cscale_h\").val())\n $(\"#cscale_m\").closest(\"tr\").find(\".colbox\").css(\"background-color\",$(\"#cscale_m\").val())\n $(\"#cscale_l\").closest(\"tr\").find(\".colbox\").css(\"background-color\",$(\"#cscale_l\").val())\n}\n\nfunction builder()\n{\n$(\"#SomeSelectors\").append($(\"#theselect\"));\n\n\n$(\"select.cscales\").html($(\"#colorselect\").html())\n$(\"#cscale_h\").val(\"Green\")\n$(\"#cscale_m\").val(\"Yellow\")\n$(\"#cscale_l\").val(\"Red\")\n\napplycols()\n$(\".cscales\").change(function(){\n applycols()\n\n})\n//getApp();\t\n//getgroupdropdown( {container: \"customgroups\"}, function() {\n\tgetgroupdata(drawit)\n// })\n\n$(\"#customgroups\").change(function(){\n\tgetgroupdata(displayit)\n})\n $(\".redraw\").change(function(){\n\tdisplayit()\n})\n\n\n$(\"#metric\").change(function(){\nif ($(\"#metric\").val()==\"None\") {\n\t$(\"#middlecol\").hide()\n\t$(\"#lowcol\").hide()\n\t$(\"#colsel\").hide()\n\t$(\"#vscale\").val(\"dual\")\n}\nelse {\n\t$(\"#middlecol\").show()\n\t$(\"#lowcol\").show()\n\t$(\"#colsel\").show()\n}\n if ($(\"#metric option:selected\").attr(\"unit\")==\"yesno\") {\n\t$(\"#vscale\").val(\"dual\")\n\t$(\"#middlecol\").hide()\n\t$(\"#vscale option\").attr(\"disabled\",\"disabled\")\n\t$(\"#vscale option:selected\").removeAttr(\"disabled\")\n\t}\nelse { \n\t$(\"#vscale option\").removeAttr(\"disabled\")\n\tif ($(\"#vscale\").val()==\"dual\") {\n\t\t$(\"#vscale\").val(\"val\")\n\t\t\t$(\"#middlecol\").show()\n\n\t\t}\nif ($(\"#metric option:selected\").attr(\"unit\")!=\"%\") {\n\tif (($(\"#vscale\").val()==\"progress\")||($(\"#vscale\").val()==\"percent\")) {\n\t\t$(\"#vscale\").val(\"val\")\n\t}\n\t$(\"#vscale option.percent\").attr(\"disabled\",\"disabled\")\n\t}\nelse {\n\n\n\t$(\"#vscale option.percent\").removeAttr(\"disabled\")\n\t}\n\n}\n\ngetdata(function(){\n\t\tdisplayit() })\n\n})\n $(\"#vscale\").change(function(){\n\tif ($(this).val()==\"threshold\") {\n\t\t$(\"#thresholdp\").show()\n\t\tvar ext=extremes()\n\t\t$(\"#threshold\").val(Math.round((ext.min+ext.max)/2))\n\t\t}\n\telse {\n\t\t$(\"#thresholdp\").hide()}\nif (($(this).val()==\"threshold\")||($(this).val()==\"nonzero\")||($(this).val()==\"dual\")) {\n\t\t$(\"#middlecol\").hide()}\nelse {\n\t\t$(\"#middlecol\").show()}\n\n\n\t\n\tdisplayit()\n})\n\n//$(\"#SomeSelectors button\").button()\n//$(\"#accordion button\").button()\n\n$(\"#showlabs\").click(function(e){\ne.preventDefault()\nclearInterval(mytimer)\n$(\"#labels text\").hide()\nif (!labels) {\n\t$(\"#labels text\").each(function(){\n\t\tif ($(this).text()!=this.id.substring(2)) {\n\t\t\t$(this).show()\n\t\t\t}\n\t})\n\t\n\t}\nlabels=!labels\n})\n\n\n$(\"#togglestates\").click(function(e){\ne.preventDefault()\nnongrouptoggle=!nongrouptoggle\ndisplayit()\n})\n\n$(\"#invert\").click(function(e){\n\te.preventDefault()\n\tvar x=$(\"#cscale_h\").val()\n\t$(\"#cscale_h\").val($(\"#cscale_l\").val())\n\t$(\"#cscale_l\").val(x)\n\tdisplayit()\n})\n}\nvar labels=false\n\nfunction getdata(next){\nif ($(\"#metric\").val()==\"None\") {\n$.getJSON(\"https://api.anbdata.com/anb/services/groupcomp?callback=?\",\n {group:$(\"#customgroups\").val()},\n function(data){\n currentdata=data.Composition.map(function(d){return {State:d}})\n\n\t\t\tnext()\n\t\t\t\n\t\t});\n}\nelse {\nvar path=$(\"#metric option:selected\").attr(\"path\")\n$.getJSON(\"https://v4p4sz5ijk.execute-api.us-east-1.amazonaws.com/anbdata\"+path+\"?callback=?\",\n {api_key:\"6e3a1df0-492c-11e6-a6e7-479c8ae56bb0\",\n //states:$(\"#customgroups\").val(),\n Year:$(\"#yearsel\").val()},function(data){\n currentdata=[]\n $(data).each(function(i,v){\n if (!v.State) {\n if (v.iso_3_code) v.State=v.iso_3_code\n else if (v.state) v.State=v.state\n \n }\n if (currentgroup.Composition.indexOf(v.State)>=0) currentdata.push(v)\n })\n\n\t\t\tnext();\n\t\t\t\n\t\t});\n}\n}\n\nfunction getgroupdata(next){\n$.getJSON(\"https://api.anbdata.com/anb/services/groupcomp?callback=?\",\n {group:$(\"#customgroups\").val()},\n function(data){\n currentgroup=data\n\t\tgetdata(function(){\n\t\t\tnext();\n\t\t\t})\n\n \n })\n\n\n}\n\nvar legend;\n\nfunction drawit(){\n$(\"#mainmap\").html(\"\")\nsvg = d3.select(\"#mainmap\").append(\"svg\")\n .attr(\"width\", width)\n .attr(\"height\", height)\n\t.attr(\"overflow\", \"hidden\");\n\nsvg.append(\"rect\")\n .attr(\"class\", \"background\")\n .attr(\"width\", width)\n .attr(\"height\", height)\n .on(\"click\", clicked);\n\ng = svg.append(\"g\");\nsvg.append(\"defs:linearGradient\")\n\t.attr(\"id\",\"grad1\")\n\t.attr(\"x1\",\"0%\")\n\t.attr(\"x2\",\"100%\")\n\t.attr(\"y1\",\"0%\")\n\t.attr(\"y2\",\"0%\")\nsvg.select(\"#grad1\")\n\t.append(\"stop\")\n\t.attr(\"offset\",\"0%\")\n\t.style(\"stop-color\",\"green\")\n\t.style(\"stop-opacity\",1)\nsvg.select(\"#grad1\")\n\t.append(\"stop\")\n\t.attr(\"offset\",\"100%\")\n\t.style(\"stop-color\",\"yellow\")\n\t.style(\"stop-opacity\",1)\nsvg.append(\"defs:linearGradient\")\n\t.attr(\"id\",\"grad2\")\n\t.attr(\"x1\",\"0%\")\n\t.attr(\"x2\",\"100%\")\n\t.attr(\"y1\",\"0%\")\n\t.attr(\"y2\",\"0%\")\nsvg.select(\"#grad2\")\n\t.append(\"stop\")\n\t.attr(\"offset\",\"0%\")\n\t.style(\"stop-color\",\"yellow\")\n\t.style(\"stop-opacity\",1)\nsvg.select(\"#grad2\")\n\t.append(\"stop\")\n\t.attr(\"offset\",\"100%\")\n\t.style(\"stop-color\",\"red\")\n\t.style(\"stop-opacity\",1)\n\n\n\n\n //d3.json(\"/space/Tools%20and%20addons/jslibrary/worldcountry.txt\", function(error, collection) {\n var col2=collection.features\n\n\tg.append(\"g\")\n .attr(\"id\", \"states\")\n .selectAll(\"path\")\n .data(col2)\n .enter().append(\"path\")\n .attr(\"d\", path)\n\t .attr(\"id\",function(d){return d.id})\n\t .style(\"fill\",\"lightgray\")\n\t .style(\"stroke\",\"#fff\")\n\t .style(\"stroke-width\", 0.5)\n\t .on(\"click\", clicked);\n //.on(\"mouseover\", hover)\n //.on(\"mouseout\", hoverout);\n\n g.append(\"g\")\n .attr(\"id\", \"labels\")\n\t .selectAll(\".countryname\")\n .data(col2)\n\t .enter().append(\"text\")\n\t.attr(\"transform\", function(d) { return \"translate(\" + path.centroid(d) + \")\"; })\n .attr(\"dy\", \".35em\")\n .attr(\"font-size\", \"2px\")\n .attr(\"font-weight\", \"bold\")\n\t.attr(\"class\", \"countryname\")\n\t.style(\"display\",\"none\")\n\t.attr(\"id\",function(d){return \"C_\"+d.id})\n .text(\"\");\n\t \n\t svg.append(\"rect\")\n\t.attr(\"id\",\"legendbox1\")\n\t.attr(\"class\",\"mainlegend\")\n\t.attr(\"x\",20)\n\t.attr(\"y\",height-20)\n\t.attr(\"width\",50)\n\t.attr(\"height\",10)\n\t.style(\"fill\",\"url(#grad1)\")\nsvg.append(\"rect\")\n\t.attr(\"id\",\"legendbox2\")\n\t.attr(\"class\",\"mainlegend\")\n\t.attr(\"x\",70)\n\t.attr(\"y\",height-20)\n\t.attr(\"width\",50)\n\t.attr(\"height\",10)\n\t.style(\"fill\",\"url(#grad2)\")\n\n\tsvg.append(\"rect\")\n\t.attr(\"id\",\"legendbox3\")\n\t.attr(\"class\",\"secondlegend\")\n\t.attr(\"x\",20)\n\t.attr(\"y\",height-20)\n\t.attr(\"width\",10)\n\t.attr(\"height\",10)\n\t.style(\"display\",\"none\")\nsvg.append(\"rect\")\n\t.attr(\"id\",\"legendbox4\")\n\t.attr(\"class\",\"secondlegend\")\n\t.attr(\"x\",30)\n\t.attr(\"y\",height-20)\n\t.attr(\"width\",80)\n\t.attr(\"height\",10)\n\t.style(\"display\",\"none\")\nsvg.append(\"rect\")\n\t.attr(\"id\",\"legendbox5\")\n\t.attr(\"class\",\"secondlegend\")\n\t.attr(\"x\",110)\n\t.attr(\"y\",height-20)\n\t.attr(\"width\",10)\n\t.attr(\"height\",10)\n\t.style(\"display\",\"none\")\n\n\n\tsvg.append(\"text\")\n\t.attr(\"id\",\"mintext\")\n\t.attr(\"x\",15)\n\t.attr(\"y\",height-23)\n\t.style(\"font-size\",\"10px\")\n svg.append(\"text\")\n\t.attr(\"id\",\"midtext\")\n\t.attr(\"x\",65)\n\t.attr(\"y\",height-23)\n\t.style(\"font-size\",\"10px\") \nsvg.append(\"text\")\n\t.attr(\"id\",\"maxtext\")\n\t.attr(\"x\",115)\n\t.attr(\"y\",height-23)\n\t.style(\"font-size\",\"10px\")\t\n svg.append(\"text\")\n\t.attr(\"id\",\"metrictext\")\n\t.attr(\"x\",15)\n\t.attr(\"y\",height-33)\n\t.style(\"font-size\",\"10px\")\t\n displayit()\n//}); \n\n}\n\nvar nongrouptoggle=false\nvar color;\nvar n,mrank\nvar dom\n\n\n\nfunction setcolor() {\ndom=d3.scale.linear()\n .domain([0,50,100])\nvar mintext=\"0%\"\nvar midtext=\"50%\"\nvar maxtext=\"100%\"\nvar ext=extremes()\nvar mettext=$(\"#metric option:selected\").text()\nif ($(\"#metric\").val()==\"None\") {\n\tcolor=function(d) {\n\treturn $(\"#cscale_h\").val().toLowerCase() }\n\t$(\"#legendbox1\").show()\n\t$(\"#legendbox1\").css(\"fill\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#legendbox2\").hide()\n\t$(\"#legendbox3\").hide()\n\t$(\"#legendbox4\").hide()\n\t$(\"#legendbox5\").hide()\n\tmidtext=\"\"\n\tmintext=\"\"\n\t$(\"#midtext\").text(midtext)\n\tmaxtext=\"\"\n\tmettext=$(\"#customgroups option:selected\").text()\n}\nelse {\t\t\n\t$(\"#legendbox1\").show()\n\t$(\"#legendbox2\").show()\n\t$(\"#legendbox3\").hide()\n\t$(\"#legendbox4\").hide()\n\t$(\"#legendbox5\").hide()\n\nif ($(\"#vscale\").val()==\"val\") {\n\t\n\tdom = d3.scale.linear()\n .domain([ext.min,(ext.min+ext.max)/2,ext.max])\n\tmintext=ext.min\n\tmidtext=Math.round((ext.min+ext.max)/2)\n\tmaxtext=ext.max\n\t\n}\nif ($(\"#vscale\").val()==\"rank\") {\n\tmrank=maxrank()\n\tn=mrank.lastrank\n\tdom = d3.scale.linear()\n .domain([n,Math.round(n/2),1])\n\tmintext=n\n\tmidtext=Math.round(n/2)\n\tmaxtext=1\n\tmettext=\"Rank of \"+mettext\n}\nif ($(\"#vscale\").val()!=\"threshold\") {\nif ($(\"#vscale\").val()!=\"progress\") {\nif ($(\"#vscale\").val()!=\"nonzero\") {\nif ($(\"#vscale\").val()!=\"dual\") {\n\n\tcolor=dom.range([$(\"#cscale_l\").val().toLowerCase(),\n\t$(\"#cscale_m\").val().toLowerCase(),\n\t$(\"#cscale_h\").val().toLowerCase()\n\t])\n\t$(\"#legendbox1\").css(\"fill\",\"url(#grad1)\")\n\t$(\"#legendbox2\").css(\"fill\",\"url(#grad2)\")\n\t$(\"#grad2 stop:eq(1)\").css(\"stop-color\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#grad2 stop:eq(0)\").css(\"stop-color\",$(\"#cscale_m\").val().toLowerCase())\n\t$(\"#grad1 stop:eq(1)\").css(\"stop-color\",$(\"#cscale_m\").val().toLowerCase())\n\t$(\"#grad1 stop:eq(0)\").css(\"stop-color\",$(\"#cscale_l\").val().toLowerCase())\n\t$(\"#midtext\").text(midtext)\n\t$(\"rect.mainlegend\").show()\n\t$(\"rect.secondlegend\").hide()\n}\nelse {\n//Dual min,max\n\tcolor=function(d){\n\t\tif (d==ext.min) {\n\t\t\treturn $(\"#cscale_l\").val().toLowerCase() }\n\t\telse {\n\t\t\treturn $(\"#cscale_h\").val().toLowerCase() }\n\t\t}\n\t$(\"rect.mainlegend\").hide()\n\t$(\"rect.secondlegend\").show()\n\t\n\t$(\"#legendbox3\").css(\"fill\",$(\"#cscale_l\").val().toLowerCase())\n\t$(\"#legendbox5\").css(\"fill\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#legendbox4\").hide()\n\t$(\"#midtext\").text(\"\")\n\tmaxtext=ext.max\n\tmintext=ext.min\n\tif ($(\"#metric option:selected\").attr(\"unit\")==\"yesno\") {\n\t\tmaxtext=\"Yes\"\n\t\tmintext=\"No\"\n\t}\n\t\t\n}\n}\nelse {\n//Non zero\n\tcolor=function(d){\n\t\tif (d==0) {\n\t\t\treturn $(\"#cscale_l\").val().toLowerCase() }\n\t\telse {\n\t\t\treturn $(\"#cscale_h\").val().toLowerCase() }\n\t\t}\n\t$(\"rect.mainlegend\").hide()\n\t$(\"rect.secondlegend\").show()\n\t\n\t$(\"#legendbox3\").css(\"fill\",$(\"#cscale_l\").val().toLowerCase())\n\t$(\"#legendbox5\").css(\"fill\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#legendbox4\").css(\"fill\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#legendbox4\").show()\n\t$(\"#midtext\").text(\">0\")\n\tmaxtext=\"\"\n\tmintext=\"0\"\n}\n}\nelse {\n//Progress\n\tcolor=function(d){\n\t\tif (d==0) {\n\t\t\treturn $(\"#cscale_l\").val().toLowerCase() }\n\t\telse {\n\t\t\tif (d==100) {\n\t\t\t\t\treturn $(\"#cscale_h\").val().toLowerCase() }\n\t\t\telse {\n\t\t\t\t\treturn $(\"#cscale_m\").val().toLowerCase() }\n\t\t\t\n\t\t\t}\n\t\t}\n\t$(\"rect.mainlegend\").hide()\n\t$(\"rect.secondlegend\").show()\n\t\n\t$(\"#legendbox3\").css(\"fill\",$(\"#cscale_l\").val().toLowerCase())\n\t$(\"#legendbox5\").css(\"fill\",$(\"#cscale_h\").val().toLowerCase())\n\t$(\"#legendbox4\").css(\"fill\",$(\"#cscale_m\").val().toLowerCase())\n\t$(\"#legendbox4\").show()\n\t$(\"#midtext\").text(\"x\")\n}\n}\nelse {\n//Threshold\n\tcolor=function(d){\n\t\tif (dmax) {\n\t\tmax=x}\n})\nreturn {min:min,max:max}\n\n}\n\nfunction rank(z){\n//var metricdata=databox[$(\"#metric option:selected\").parent().attr(\"label\")]\nvar s=1\nvar field=$(\"#metric option:selected\").attr(\"field\")\n$(currentdata).each(function(i,data){\n\tvar x=data[field]\n\tif (x>z) s++\n\t})\nreturn s\n\n}\nfunction maxrank(z){\n//var metricdata=databox[$(\"#metric option:selected\").parent().attr(\"label\")]\nvar field=$(\"#metric option:selected\").attr(\"field\")\nvar smax=-1\nvar s=0\nvar n=0,n2=0\n$(currentdata).each(function(i,data){\n\tvar x=data[field]\n\tn++\n\tif ((smax<0)||(x\"+\n\t$(\"#customgroups option:selected\").text()+\"\")\nif ($(\"#metric\").val()!=\"None\") {\n$(\"#maptitle2\").show()\n$(\"#subtitle\").show()\n\nif ($(\"#vscale\").val()!=\"rank\") {\nif ($(\"#metric option:selected\").attr(\"unit\")==\"yesno\") {\n\n$(\"#maptitle2\").html(\"

\"+\n\t\"States having \"+$(\"#metric option:selected\").text().split(\" (yes\")[0]+\n\tyear+\"

\")\n\t}\n\nelse {\n$(\"#maptitle2\").html(\"

\"+\n\t$(\"#metric option:selected\").text()+\n\tyear+\"

\")\n\t}\n}\nelse {\n$(\"#maptitle2\").html(\"

States ranked by \"+\n\t$(\"#metric option:selected\").text()+\n\tyear+\"

\")\n}}\nelse {\n $(\"#maptitle2\").hide()\n $(\"#subtitle\").hide()\n\n}\n\n$(\"#states path\").each(function(){\nvar d=this\n\nif ($(\"#customgroups option:selected\").text().toUpperCase().indexOf(\"World\")<0) {\n\t$(\"#togglestates\").removeAttr(\"disabled\")\n\t\n\tif (nongrouptoggle) {\n\n\t\tif (currentgroup.Composition.indexOf(this.id)<0) {\n\t\t\t$(this).hide() }\n\t\telse {\n\t\t\t$(this).show() }\n\t}\n\telse {\n\t\t$(this).show()}\n\t}\nelse {\n\t$(\"#togglestates\").attr(\"disabled\",\"disabled\")\nnongrouptoggle=false\n\t$(this).show()\n\t}\nvar data=currentdata.filter(function(e){return e.State==d.id})[0]\nif (data) {\n\tvar metval=data[field]\n\t\t\n\n\tif ($(\"#vscale\").val()!=\"rank\") {\n\tif ($(\"#metric option:selected\").attr(\"unit\")==\"yesno\") {\n\t\t$(this).css(\"fill\",color(data[field])) \n\t\t$(\"#C_\"+this.id).text(d.id+\": \"+(metval?\"Yes\":\"No\"))\n\t\t}\n\telse {\n\t\t$(this).css(\"fill\",color(data[field])) \n\t\t$(\"#C_\"+this.id).text(d.id+\": \"+data[field]+\n\t\t$(\"#metric option:selected\").attr(\"unit\"))\n\t\t}\n\t}\n\telse {\n\t\t$(this).css(\"fill\",color(rank(data[field]))) \n\t\t$(\"#C_\"+this.id).text(d.id+\": \"+rank(data[field])+\n\t\t\"/\"+mrank.l)\n\t}\n\t$(\"#C_\"+this.id).addClass(\"inscope\")\n\t}\n\telse {\n\t$(this).css(\"fill\",\"lightgray\")\n\t$(\"#C_\"+this.id).text(this.id)\n\t$(\"#C_\"+this.id).removeClass(\"inscope\")\n\t\n\t}\n})\nbuildtable()\n}\n\n\nvar k,x,y,mytimer,isselected=false\nfunction clicked(d) {\nvar metricdata=databox[$(\"#metric option:selected\").parent().attr(\"label\")]\n//alert(d.id)\n if (!d) {\n x = width / 2;\n y = height / 2;\n k = 1\n centered = null;\n }\n else {\n \n\tif ((centered == d)&&(isselected)) {\n k = k-1;\n\tif (k==0) {\n\t\tk=Number($(\"#zoom\").val())}\n centered = d;\n\t}\n\telse {\n var centroid = path.centroid(d);\n x = centroid[0];\n y = centroid[1];\n\tif (!centered) {\n\t\tk=Number($(\"#zoom\").val())}\n\t centered = d;\n\t}\n }\n \n\n g.selectAll(\"path\")\n .classed(\"active\", centered && function(d) { return d === centered; });\n\n g.transition()\n .duration(750)\n .attr(\"transform\", \"translate(\" + width / 2 + \",\" + height / 2 + \")scale(\" + k + \")translate(\" + -x + \",\" + -y + \")\")\n .style(\"stroke-width\", 0.5 + \"px\")\n\t ;\nif (mytimer) {\n\tclearInterval(mytimer) }\n\tisselected=true\ng.selectAll(\"path\")\n\t\t.style(\"stroke\",\"#fff\")\nif (!labels) {\n\t\t$(\"#labels text\").hide()}\n\nif (d&&((!labels)||(!metricdata.values[this.id]))) {\n\t$(\"#C_\"+d.id).show()\n}\ng.select(\"#\"+d.id)\n\t.style(\"stroke\",\"black\")\n\t\nmytimer=setInterval(function(){\nisselected=false\n\tg.select(\"#\"+d.id)\n\t.style(\"stroke\",\"#fff\")\n\tif ((!labels)||(!metricdata.values[d.id])) {\n\t\t$(\"#C_\"+d.id).hide()}\n\n\t},2000);\n\t\n\t\n\t \n\t \n}\n\n\nfunction buildtable(){\n//var data=databox[$(\"#metric option:selected\").parent().attr(\"label\")]\n//var mindex=data.metrics.indexOf($(\"#metric option:selected\").val())\nvar total=0\nvar numb=0\nvar key\nvar isgroupdisplay=($(\"#metric\").val()==\"None\")\nvar currentfield=$(\"#metric option:selected\").attr(\"field\")\n$(icaostates).each(function(i,state){\n var tabletr=$(\"tr[state='\"+state.iso_3_code+\"']\")\n\n if (currentgroup.Composition.indexOf(state.iso_3_code)) {\n $(tabletr).show()\n if (isgroupdisplay) {\n $(tabletr).find(\"td.colortd\").css(\"background-color\",color())\n $(tabletr).find(\"td.valuetd\").text(\"\")\n \n }\n\t else {\n\t var data=currentdata.filter(function(d){return d.State==state.iso_3_code})[0]\n\t if (data&&data[currentfield]!=null) {\n\t total+=data[currentfield]\n\t numb++\n\t if ($(\"#vscale\").val()!=\"rank\") {\n\t $(tabletr).find(\"td.colortd\").css(\"background-color\",color(data[currentfield]))}\n\t else {\n\t $(tabletr).find(\"td.colortd\").css(\"background-color\",color(rank(data[currentfield])))}\n if ($(\"#metric option:selected\").attr(\"unit\")!=\"yesno\") {\n\t \t $(tabletr).find(\"td.valuetd\").text(data[currentfield])}\n\t else {\n\t\t $(tabletr).find(\"td.valuetd\").text((data[currentfield]?\"Yes\":\"No\"))}\n\n\n\t }\n\t else {\n\t $(tabletr).hide()\n\t }\n\t }\n }\n else {\n $(tabletr).hide()\n \n }\n})\n$(\"#metricth\").text($(\"#metric option:selected\").text())\nif (($(\"#metric option:selected\").attr(\"unit\")==\"%\")||($(\"#metric option:selected\").attr(\"unit\")==\"score\")) {\n\t$(\"#subtitle\").html(\"

Average: \"+(Math.round(10*total/numb)/10)\n\t+($(\"#metric option:selected\").attr(\"unit\")==\"%\"?\"%\":\"\")+\"

\") }\nelse {\n\t$(\"#subtitle\").html(\"

Total: \"+total+\"

\") }\n\nif (dtable) dtable.destroy()\ndtable=$(\"#datatab\").DataTable({\n\t\t\t\t\"aaSorting\":[[2,\"asc\"]],\n\t\t\t\t \"aoColumnDefs\": [ {\"bSortable\": false, \"aTargets\": [0 ] }],\n\n\t\t\t\t \"bPaginate\": false\n});\n\n\n\n\n}\n\n"},"css":{"file":{"type":"","url":"","link":"","message":{"error":true,"text":"File not defined"}},"title":"Cascading Style Sheet (CSS)","activated":true,"name":"css","linkedtofile":false,"optional":true,"content":".background {\n fill: none;\n pointer-events: all;\n}\n\n#states {\n fill: #aaa;\n}\n\n#states .active {\n fill: orange;\n}\n\n#state-borders {\n fill: none;\n stroke: #fff;\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n pointer-events: none;\n}\n"},"jade":{"file":{"type":"","url":"","link":"","message":{"error":true,"text":"File not defined"},"depurl":"https://quipslibistars.s3.amazonaws.com/prod/940446eb361650783af19cea4b7e80271a47559d/main.jade"},"title":"Jade","activated":true,"name":"jade","linkedtofile":false,"optional":false,"content":".container(style=\"width:980\")\n hr\n #SomeSelectors\n p Select a Group \n select#customgroups\n !{groups.html}\n p Select an indicator \n select#metric\n optgroup(label=\"None\")\n option(unit=\"yesno\",value=\"None\",field=\"\") State Group Display Only\n p#year(style=\"display:none\") Select a year\n select#yearsel\n - var y=new Date().getUTCFullYear()\n for i in [y-1,y-2,y-3,y-4,y-5]\n option(value=i)=i\n hr\n p Max zoom level \n select#zoom\n option(value=\"5\") 5\n option(value=\"6\") 6\n option(value=\"7\") 7\n p#colsel Value Scale \n select#vscale\n option.percent(value=\"percent\") Percent [0%,100%]\n option(value=\"rank\") Rank [first,last]\n option(value=\"val\") Value [min,max]\n option(value=\"threshold\") Threshold\n option.percent(value=\"progress\") Progress [0%,x,100%]\n option(value=\"nonzero\") Non Zero\n option(value=\"dual\") Dual {min/N,max/Y}\n p#thresholdp(style=\"display:none\") Cut-off Value \n input#threshold.redraw(type=\"text\")\n p Color Scale\n table\n tbody\n tr\n td(style=\"width:80px\") Highest \n td(style=\"width:15px\")\n .colbox(style=\"width:10px;height:10px\")\n td\n select#cscale_h.cscales.redraw\n tr#middlecol\n td(style=\"width:80px\") Middle\n td(style=\"width:15px\")\n .colbox(style=\"width:10px;height:10px\")\n td\n select#cscale_m.cscales.redraw\n tr#lowcol\n td(style=\"width:80px\") Lowest\n td(style=\"width:15px\")\n .colbox(style=\"width:10px;height:10px\")\n td\n select#cscale_l.cscales.redraw\n p\n button#invert.btn.btn-xs.btn-info Switch Highest/Lowest\n button#showlabs.btn.btn-xs.btn-info Toggle Labels\n button#togglestates.btn.btn-xs.btn-info Toggle Group States\n hr\n #mainpart2\n #maptitle1\n #maptitle2\n #subtitle\n #mainmap\n #maplegend\n #thetable\n table#datatab.table.table-condensed(style=\"width:100%\")\n thead\n tr\n th(style=\"width:30px\")\n th Code\n th State\n th#metricth\n tbody\n for state in icaostates.sort(function(a,b){return (a.UN_state_name") var libs=[] $(project.libs).each(function(i,v){ if (v.name!="jquery") { $(v.link.split(",")).each(function(j,u){ if (u.slice(-2)=="js") { libs.push(u+(v.haskey?"?key="+project[v.name+"key"]:"")) } else { $("head").append("") } }) } }) if (project.morejs) { $(project.morejs).each(function(i,v){ if ((v.url.substring(0,2)=="//")||(v.url.substring(0,8)=="https://")||(v.url.substring(0,7)=="http://")) { libs.push(v.url) } }) } if (project.morecss) { $(project.morecss).each(function(i,v){ $("head").append("") }) } loadlibs(libs.reverse()) }); })(); function loadlibs(libs){ if (libs.length>0) { var l=libs.pop() loadScript(l,function(){ //$.getScript(l,function(res){ loadlibs(libs) }) //.fail(function(e){ // loadlibs(libs) // //}) } else { start() } } function putscriptcontent(content){ var script = document.createElement("script") script.type = "text/javascript"; $(script).text(content) document.getElementsByTagName("head")[0].appendChild(script); } function start(){ //load jade $.getJSON(project.host+"/project/"+project.version+"/"+project.id+"/render?callback=?"+(project.datachange?"&data="+project.datachange:""),function(res){ $("#"+project.container).html(res.html) if (project.css.activated) { if (project.css.linkedtofile) { $("head").append("")} else { $("head").append("")} } if (project.js.activated) { if (project.js.linkedtofile) { $.getScript(project.js.file[(project.prod?"depurl":"url")])} else { putscriptcontent(project.js.content)} if (project.mainjs) { window[project.mainjs]() } } }) }