$(window).on("load",(function(){var t=d3.select("#stacked-to-multiples"),e={top:20,right:20,bottom:30,left:60},a=t.node().getBoundingClientRect().width-e.left-e.right,n=500-e.top-e.bottom,r=d3.time.format("%Y-%m").parse,l=d3.format("02d"),u=d3.scale.ordinal().rangeRoundBands([n,0],.2),o=d3.scale.linear(),i=d3.scale.ordinal().rangeRoundBands([0,a],.1,0),d=d3.svg.axis().scale(i).orient("bottom").tickFormat((function(t){return"Q"+(1+(t.getMonth()/3|0))+l(t.getFullYear()%100)})),s=d3.nest().key((function(t){return t.group})),c=d3.layout.stack().values((function(t){return t.values})).x((function(t){return t.date})).y((function(t){return t.value})).out((function(t,e){t.valueOffset=e})),f=d3.scale.ordinal().range(["#99B898","#FECEA8","#FF847C","#E84A5F"]),g=t.append("svg"),p=g.attr("width",a+e.left+e.right).attr("height",n+e.top+e.bottom).append("g").attr("transform","translate("+e.left+","+e.top+")");function v(){a=t.node().getBoundingClientRect().width-e.left-e.right,g.attr("width",a+e.left+e.right),p.attr("width",a+e.left+e.right),i.rangeRoundBands([0,a],.1,0),p.selectAll(".d3-xaxis").call(d),p.selectAll(".d3-bar").attr("x",(function(t){return i(t.date)})).attr("width",i.rangeBand())}d3.tsv("../../../app-assets/data/d3/bar/stacked-to-multiples.tsv",(function(t,e){if(t)throw t;e.forEach((function(t){t.date=r(t.date),t.value=+t.value}));var a=s.entries(e);c(a),i.domain(a[0].values.map((function(t){return t.date}))),u.domain(a.map((function(t){return t.key}))),o.domain([0,d3.max(e,(function(t){return t.value}))]).range([u.rangeBand(),0]);var n=p.selectAll(".d3-bar-group").data(a).enter().append("g").attr("class","d3-bar-group").attr("transform",(function(t){return"translate(0,"+u(t.key)+")"}));n.append("text").attr("class","d3-group-label").attr("x",-60).attr("y",(function(t){return o(t.values[0].value/2)})).attr("dy",".35em").text((function(t){return"Group "+t.key})),n.selectAll(".d3-bar").data((function(t){return t.values})).enter().append("rect").attr("class","d3-bar").style("fill",(function(t){return f(t.group)})).attr("x",(function(t){return i(t.date)})).attr("y",(function(t){return o(t.value)})).attr("width",i.rangeBand()).attr("height",(function(t){return u.rangeBand()-o(t.value)})),n.filter((function(t,e){return!e})).append("g").attr("class","d3-axis d3-xaxis").attr("transform","translate(0,"+u.rangeBand()+")").call(d),d3.selectAll(".smradio").on("change",g);var l=setTimeout((function(){d3.select('input[value="stacked"]').property("checked",!0).each(g)}),2e3);function g(){var t;clearTimeout(l),"multiples"===this.value?((t=p.transition().duration(750).selectAll(".d3-bar-group").attr("transform",(function(t){return"translate(0,"+u(t.key)+")"}))).selectAll(".d3-bar").attr("y",(function(t){return o(t.value)})),t.select(".d3-group-label").attr("y",(function(t){return o(t.values[0].value/2)}))):function(){var t=p.transition().duration(750).selectAll(".d3-bar-group").attr("transform","translate(0,"+u(u.domain()[0])+")");t.selectAll(".d3-bar").attr("y",(function(t){return o(t.value+t.valueOffset)})),t.select(".d3-group-label").attr("y",(function(t){return o(t.values[0].value/2+t.values[0].valueOffset)}))}()}})),$(window).on("resize",v),$(".menu-toggle").on("click",v)}));