text: /*! minnpost-swlrt-demographics - LATEST VERSION - 2018-03-28
  * https://github.com/minnpost/minnpost-swlrt-demographics
  * Copyright (c) 2018 MinnPost; Licensed MIT */
  
  define("helpers",["jquery","underscore"],function(a,b){var c={};return c.overrideBackboneAJAX=function(){Backbone.ajax=function(){var a=arguments;return!0!==a[0].dataTypeForce&&(a[0].dataType="jsonp",a[0].jsonpCallback="mpServerSideCachingHelper"+b.hash(a[0].url)),Backbone.$.ajax.apply(Backbone.$,a)}},c.isMSIE=function(){var a=/(msie) ([\w.]+)/i.exec(navigator.userAgent);return!!a&&parseInt(a[2],10)},c.jsonpRequest=function(b,c){var d=b||{};return d.dataType="jsonp",a.ajax.apply(a,[d])},c.getLocalData=function(d,e){var f=!1,g=[];return d=b.isArray(d)?d:[d],e&&e.paths&&0===e.paths.data.indexOf("http")&&(f=!0),b.each(d,function(b){var d;d=f?c.jsonpRequest({url:e.remoteProxy+encodeURI(e.paths.data+b)},e):a.getJSON(e.paths.data+b),g.push(d)}),a.when.apply(a,g)},c.parseQueryString=function(){var a={},c=function(a){return decodeURIComponent(a.replace(/\+/g," "))},d=location.search.substring(1),e=d.split("&");return b.each(e,function(b,d){var e=b.split("=");e.length>1&&(a[c(e[0])]=c(e[1]))}),a},c}),define("text!templates/application.underscore",[],function(){return'<div class="application-container">\n  <div class="message-container"></div>\n\n  <div class="content-container">\n\n    <div class="loading-container">\n      <i class="loading"></i> Loading...\n    </div>\n\n    <div class="visual-container cf">\n      <div class="demographics-chooser cf">\n        <div class="demographic pop <%= (currentSet == \'pop\') ? \'active\' : \'\' %>" data-set="pop">\n          <div class="inside">\n            <div class="strong">Population density</div>\n            <div class="caption">Population per square square kilometer.  &#177;<span class="margin"></span> margin of error &#8224;.</div>\n            <div class="legend"></div>\n          </div>\n        </div>\n\n        <div class="demographic income <%= (currentSet == \'income\') ? \'active\' : \'\' %>" data-set="income">\n          <div class="inside">\n            <div class="strong">Household income</div>\n            <div class="caption">Median household income for each tract.  &#177;<span class="margin"></span> margin of error &#8224;.</div>\n            <div class="legend"></div>\n          </div>\n        </div>\n\n        <div class="demographic white <%= (currentSet == \'white\') ? \'active\' : \'\' %>" data-set="white">\n          <div class="inside">\n            <div class="strong">People of color</div>\n            <div class="caption">Percentage of population that are people of color (not white).  &#177;<span class="margin"></span> margin of error &#8224;.</div>\n            <div class="legend"></div>\n          </div>\n        </div>\n\n        <div class="demographic transit <%= (currentSet == \'transit\') ? \'active\' : \'\' %>" data-set="transit">\n          <div class="inside">\n            <div class="strong">Public transit</div>\n            <div class="caption">Percentage of worker population that uses public transportation for work.  &#177;<span class="margin"></span> margin of error &#8224;.</div>\n            <div class="legend"></div>\n          </div>\n        </div>\n      </div>\n\n      <div class="map-container">\n        <div class="tooltip-container">\n          <div class="tooltip">\n            <div class="stop-info"></div>\n            <div class="tract-info"></div>\n          </div>\n        </div>\n\n        <div id="line-map"></div>\n      </div>\n    </div>\n\n  </div>\n\n  <div class="footnote-container">\n    <div class="footnote">\n      <p>&#8224; Margin of error for each demographic is the average margin of error for all census tracts being presented.</p>\n\n      <p>\n        Proposed line route and stop data is provided by MetroTransit via the <a href="http://www.datafinder.org/" target="_blank">MetroGIS DataFinder</a>.\n\n        Demographic data from the Census Bureau\'s 2012 American Community Survey 5 year estimates via <a href="http://censusreporter.org/" target="_blank">Census Reporter</a>.\n\n        Some code, techniques, and data on <a href="https://github.com/minnpost/minnpost-swlrt-demographics" target="_blank">Github</a>.</p>\n    </div>\n  </div>\n</div>\n'}),define("text!templates/fallback.underscore",[],function(){return'<div class="application-container">\n  <div class="message-container"></div>\n\n  <div class="content-container fallback">\n\n    <img src="<%= paths.images %>fallback-pop-density.png" />\n    <div class="separator"></div>\n    <img src="<%= paths.images %>fallback-income.png" />\n    <div class="separator"></div>\n    <img src="<%= paths.images %>fallback-color.png" />\n    <div class="separator"></div>\n    <img src="<%= paths.images %>fallback-transit.png" />\n\n  </div>\n\n  <div class="footnote-container">\n    <div class="footnote">\n      <p>&#8224; Margin of error for each demographic is the average margin of error for all census tracts being presented.</p>\n\n      <p>\n        Line route and stop data provided by MetroTransit via the <a href="http://www.datafinder.org/" target="_blank">MetroGIS DataFinder</a>.\n\n        Demographic data from the Census Bureau\'s 2012 American Community Survey 5 year estimates via <a href="http://censusreporter.org/" target="_blank">Census Reporter</a>.\n\n        Some code, techniques, and data on <a href="https://github.com/minnpost/minnpost-green-line-demographics" target="_blank">Github</a>.</p>\n    </div>\n  </div>\n</div>\n'}),define("minnpost-swlrt-demographics",["jquery","underscore","mpConfig","helpers","text!templates/application.underscore","text!templates/fallback.underscore"],function(a,b,c,d,e,f){function g(){return!!("createElementNS"in document&&document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect)}var h,i,j=function(c){this.options=b.extend(this.defaultOptions,c),this.el=this.options.el,this.$el=a(this.el),this.$=function(a){return this.$el.find(a)},this.loadApp()};return b.extend(j.prototype,{start:function(){var a=this;g()?require(["d3","topojson"],function(b,c){h=b,i=c,a.full()}):this.fallback()},fallback:function(){this.templateFallback=b.template(f),this.$el.html(this.templateFallback({paths:this.options.paths}))},full:function(){var a=this;this.sets={pop:{table:"B01003",column:"B01003001",prop:"by_area",error_prop:"by_area_error",colors:["#c8e0dc","#8bc1c7","#4da0bb","#087db2","#0d57a0"],format:h.format(",.0f")},white:{table:"B02008",column:"B02008001",prop:"by_population",error_prop:"by_population_error",colors:["#e6fde6","#daf8c4","#dbef9a","#e7e36f","#fbd341"],format:h.format("%,.2f")},income:{table:"B19013",column:"B19013001",prop:"estimate",error_prop:"error",colors:["#e5f5ef","#c7ebe4","#a6e1dd","#81d6db","#55cbdd"],format:h.format("$,.0f")},transit:{table:"B08301",column:"B08301010",prop:"by_population",error_prop:"by_population_error",colors:["#dcefd4","#d2d99c","#dabe66","#ec983c","#ff6633"],format:h.format("%,.2f")}},this.dataset="pop",this.templateApplication=b.template(e),this.$el.html(this.templateApplication({currentSet:this.dataset})),b.delay(function(){a.getData().done(function(){a.buildMap(),a.handleEvents()})},200)},buildMap:function(){var a=this,b=this.$el.find("#line-map"),c=b.width(),d=b.height(),e=.0035,f=h.select(b[0]).append("svg").attr("width",c).attr("height",d),g=this.data.route,j=(h.geo.centroid(g),h.geo.mercator().scale(150).translate([c/2,d/2])),k=h.geo.path().projection(j).pointRadius(e),l=h.geo.path().projection(j).pointRadius(2*e),m=this.featureGroup=f.append("g").attr("class","feature-group"),n=k.bounds(g);m.attr("transform","translate("+j.translate()+") scale("+.95/Math.max((n[1][0]-n[0][0])/c,(n[1][1]-n[0][1])/d)+") translate("+-(n[1][0]+n[0][0])/2+","+-(n[1][1]+n[0][1])/2+")"),this.data.tracts=i.feature(this.data.tractsTopo,this.data.tractsTopo.objects["census-tracts.geo"]),this.tracts=m.selectAll(".census-tract").data(this.data.tracts.features).enter().append("path").attr("class","census-tract").attr("d",k),this.data.boundaries=i.feature(this.data.boundariesTopo,this.data.boundariesTopo.objects["boundaries.geo"]),m.selectAll(".boundary").data(this.data.boundaries.features).enter().append("path").attr("class","boundary").attr("d",k),this.data.landmarks=i.feature(this.data.landmarksTopo,this.data.landmarksTopo.objects["area-features.geo"]),m.selectAll(".landmark-feature").data(this.data.landmarks.features).enter().append("path").filter(function(a){return"city-label"!==a.properties.type}).attr("class",function(a){return"landmark-feature "+a.properties.type}).attr("d",k),m.selectAll(".city-label").data(this.data.landmarks.features).enter().append("text").filter(function(a){return"city-label"===a.properties.type}).attr("class","city-label").attr("dx",function(a){return j(a.geometry.coordinates)[0]}).attr("dy",function(a){return j(a.geometry.coordinates)[1]}).text(function(a){return a.properties.name}),m.selectAll(".route").data(this.data.route.features).enter().append("path").attr("class","route").attr("d",k),m.selectAll(".stop").data(this.data.stops.features).enter().append("path").attr("class","stop").attr("d",k).attr("filter",function(a){a.stop=this}),this.voronoiStops=h.geom.voronoi().x(function(a){return j(a.geometry.coordinates)[0]}).y(function(a){return j(a.geometry.coordinates)[1]}).clipExtent([[0,0],[c,d]]),m.selectAll(".voronoi-stops").data(this.voronoiStops(this.data.stops.features)).enter().append("path").filter(function(a){return a.length}).attr("class","voronoi-stops").attr("d",function(a){return"M"+a.join("L")+"Z"}).on("mouseover",function(b,c){h.select(b.point.stop).attr("d",l(b.point)).classed("active",!0),a.updateTooltip({stop:b.point.properties.Station,bottom:j(b.point.geometry.coordinates)[1]>220.09579})}).on("mouseout",function(b){h.select(b.point.stop).attr("d",k(b.point)).classed("active",!1),a.updateTooltip(!1)}),this.makeLegendsScales(),this.updateTracts()},handleEvents:function(){var b=this;this.$(".demographic").on("click",function(c){c.preventDefault();var d=a(this);b.$(".demographic").removeClass("active"),d.addClass("active"),b.dataset=d.data("set"),b.updateTracts()})},makeLegendsScales:function(){b.each(this.sets,function(a,b){a.access=function(b){return b.properties.data[a.table][a.prop][a.column]},a.estimate=function(b){return b.properties.data[a.table].estimate[a.column]},a.error=function(b){return b.properties.data[a.table][a.error_prop][a.column]};var c=this.data.tracts.features.map(a.access).sort(function(a,b){return a-b});a.scale=h.scale.quantize().domain(c).range(a.colors),h.select(".demographic."+b+" .legend").append("div").attr("class","legend-block-end").text(a.format(c[0])),a.legend=h.select(".demographic."+b+" .legend").selectAll(".legend-block").data(a.scale.range()).enter().append("div").classed("legend-block",!0).attr("title",function(b,c){var d=a.scale.invertExtent(b);return">= "+a.format(d[0])+" and < "+a.format(d[1])}).style("background-color",function(a){return a}),h.select(".demographic."+b+" .legend").append("div").attr("class","legend-block-end").text(a.format(c[c.length-1])),a.avg_error=this.data.tracts.features.map(a.error).reduce(function(a,b,c,d){return a+b},0)/this.data.tracts.features.length,a.legend=h.select(".demographic."+b+" .margin").text(a.format(a.avg_error)),this.sets[b]=a},this)},updateTracts:function(){var a=this.sets[this.dataset];this.tracts.transition().duration(300).style("fill",function(b){return a.scale(a.access(b))})},updateTooltip:function(a){var c=this.$(".tooltip-container"),d=this.$(".tooltip"),e=this.$(".tooltip .stop-info"),f=this.$(".tooltip .tract-info");!1===a?d.hide():d.show(),c.removeClass("bottom"),a.bottom&&c.addClass("bottom"),b.isObject(a)&&a.stop&&e.html(a.stop),b.isObject(a)&&a.tract&&f.html(a.tract)},getData:function(){var a=this;return d.getLocalData(["swlrt-route.geo.json","swlrt-stops.geo.json","features.topo.json","boundaries.topo.json","census-tracts.topo.json"],this.options).done(function(b,c,d,e,f){a.data=a.data||{},a.data.route=b[0],a.data.stops=c[0],a.data.landmarksTopo=d[0],a.data.boundariesTopo=e[0],a.data.tractsTopo=f[0],a.$el.find(".loading-container").slideUp("fast")})},defaultOptions:{projectName:"minnpost-swlrt-demographics",remoteProxy:"https://mp-jsonproxy.herokuapp.com/proxy?callback=?&url=",el:".minnpost-swlrt-demographics-container",availablePaths:{local:{css:[".tmp/css/main.css"],images:"images/",data:"data/"},build:{css:["//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css","dist/minnpost-swlrt-demographics.libs.min.css","dist/minnpost-swlrt-demographics.latest.min.css"],ie:["dist/minnpost-swlrt-demographics.libs.min.ie.css","dist/minnpost-swlrt-demographics.latest.min.ie.css"],images:"dist/images/",data:"dist/data/"},deploy:{css:["//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css","https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/minnpost-swlrt-demographics.libs.min.css","https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/minnpost-swlrt-demographics.latest.min.css"],ie:["https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/minnpost-swlrt-demographics.libs.min.ie.css","https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/minnpost-swlrt-demographics.latest.min.ie.css"],images:"https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/images/",data:"https://s3.amazonaws.com/data.minnpost/projects/minnpost-swlrt-demographics/data/"}}},loadApp:function(){this.determinePaths(),this.getLocalAssests(function(a){this.renderAssests(a),this.start()})},determinePaths:function(){var a;this.options.deployment="deploy",-1!==window.location.host.indexOf("localhost")&&(this.options.deployment="local",a=d.parseQueryString(),b.isObject(a)&&b.isString(a.mpDeployment)&&(this.options.deployment=a.mpDeployment)),this.options.paths=this.options.availablePaths[this.options.deployment]},getLocalAssests:function(b){var c=this;"local"===this.options.deployment?a.getJSON("bower.json",function(a){b.apply(c,[a.dependencyMap])}):b.apply(this,[])},renderAssests:function(c){var e=d.isMSIE()&&d.isMSIE()<=8;b.isObject(c)&&b.each(c,function(c,d){c.css&&b.each(c.css,function(b,c){b=b.match(/^(http|\/\/)/)?b:"bower_components/"+b+".css",a("head").append('<link rel="stylesheet" href="'+b+'" type="text/css" />')}),c.ie&&e&&b.each(c.ie,function(b,c){b=b.match(/^(http|\/\/)/)?b:"bower_components/"+b+".css",a("head").append('<link rel="stylesheet" href="'+b+'" type="text/css" />')})}),b.each(this.options.paths.css,function(b,c){a("head").append('<link rel="stylesheet" href="'+b+'" type="text/css" />')}),e&&b.each(this.options.paths.ie,function(b,c){a("head").append('<link rel="stylesheet" href="'+b+'" type="text/css" />')}),this.$el.addClass("processed")}}),j}),require(["jquery","minnpost-swlrt-demographics"],function(a,b){a(document).ready(function(){new b})});