/*!
- * D3Evolution 0.0.1 (https://github.com/moisseev/D3Evolution)
- * Copyright (c) 2016, Alexander Moisseev, BSD 2-Clause
+ * D3Evolution 0.0.2 (https://github.com/moisseev/D3Evolution)
+ * Copyright (c) 2016-2017, Alexander Moisseev, BSD 2-Clause
*/
-;function D3Evolution(r,e){var n=$.extend(true,{title:"",width:800,height:400,margin:{top:80,right:60,bottom:40,left:60},yAxisLabel:"",type:"line",duration:1250,interpolate:"linear",legend:{buttonRadius:7,space:130,entries:[]}},e);var A;var y;var k;var s=n.width-n.margin.left-n.margin.right;var q=n.height-n.margin.top-n.margin.bottom;var C=d3.time.scale().range([0,s]);var d=d3.scale.linear().range([q,0]);var i=d3.svg.axis().scale(C);var a=d3.svg.axis().scale(d).orient("left").ticks(5);var m=d3.svg.axis().tickFormat("").scale(C).tickSize(-q,0);var D=d3.svg.axis().tickFormat("").scale(d).orient("left").tickSize(-s,0);var l=d3.scale.quantize().range([q,0]);var o=d3.svg.area().x(function(g){return C(g.x)}).y0(function(g){return q}).y1(function(g){return l(g.y==null)}).interpolate("step");var j=d3.svg.line().defined(function(g){return g.y!=null}).x(function(g){return C(g.x)}).y(function(g){return d(g.y)}).interpolate(n.interpolate);var x=d3.svg.area().defined(function(g){return g.y!=null}).x(function(g){return C(g.x)}).y0(function(g){return d(g.y0)}).y1(function(g){return d(g.y0+g.y)}).interpolate(n.interpolate);var h=function(){var g;if(n.type==="area"){d3.layout.stack()(A);g=d3.extent(d3.merge(A),function(E){return E.y0+E.y})}else{g=d3.extent(d3.merge(A),function(E){return E.y})}d.domain([(g[0]>0)?0:g[0],g[1]]);d3.transition().duration(n.duration).each(function(){w.select(".y.grid").call(D.scale(d));w.select(".y.axis").call(a.scale(d))})};var z=d3.scale.category10();var b=function(g){return(n.legend.entries[g]!==undefined&&n.legend.entries[g].color!==undefined)?n.legend.entries[g].color:z(g)};var v=function(g){return(n.legend.entries[g]!==undefined&&n.legend.entries[g].label!==undefined)?n.legend.entries[g].label:"path_"+g};var f=function(g){var F=g.reduce(function(G,H){return H.map(function(J,I){return J.y+(G[I]?G[I]:0)})},[]);var E=$.extend(true,[],g);E.forEach(function(G){G.forEach(function(I,H){if(F[H]){I.y/=F[H]}})});return E};var u=function(){if(n.convert==="percentage"){a.tickFormat(d3.format(".0%"));t.transition().duration(n.duration).style("opacity",0);A=f(y)}else{a.tickFormat(null);t.transition().duration(n.duration).style("opacity",1);A=y}h()};var p=d3.select("#"+r).append("svg").classed("d3evolution",true).attr("width",n.width).attr("height",n.height);var c=p.append("g").attr("class","legend");var w=p.append("g").attr("width",s).attr("height",q).attr("transform","translate("+n.margin.left+", "+n.margin.top+")");w.append("g").attr("class","x grid").attr("transform","translate(0,"+q+")").call(m);w.append("g").attr("class","y grid").attr("transform","translate(0,0)").call(D);w.append("g").attr("class","x axis").attr("transform","translate(0,"+q+")").call(i);w.append("g").attr("class","y axis").attr("transform","translate(0,0)").call(a);var t=w.append("text").attr("class","y label").attr("x",20-n.margin.left).attr("y",-20).style("opacity",(n.convert==="percentage")?0:1).text(n.yAxisLabel);var B=p.append("svg:text").attr("x",(n.width/2)).attr("y",(n.margin.top/3)).attr("text-anchor","middle");B.append("tspan").attr("class","chart-title").text(n.title+" ");B.timeRange=B.append("tspan");this.data=function(I){y=$.extend(true,[],I);var F=[];k=n.width-n.margin.right-n.legend.space*y.length;y.forEach(function(N){N.forEach(function(O){O.x*=1000})});var J=d3.extent(d3.merge(y),function(N){return N.x});C.domain([J[0],J[1]]);const M=function(N){return d3.time.format("%Y-%m-%d %H:%M:%S")(new Date(N))};B.timeRange.text("[ "+M(J[0])+" / "+M(J[1])+" ]");var K=w.selectAll("path.path-null").data(y);K.enter().append("path").attr("class","path-null");K.transition().duration(n.duration/2).style("opacity",0).each("end",function(){K.attr("d",o).transition().duration(n.duration/2).style("opacity",1)});K.exit().remove();u();var L=w.selectAll("path.path").data(A);L.enter().append("path").attr("class","path").attr("id",function(O,N){return"path_"+N}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)}).style((n.type==="area")?{fill:function(O,N){return b(N)},stroke:"none","fill-opacity":function(O,N){return F[N]}}:{fill:"none",stroke:function(O,N){return b(N)},opacity:function(O,N){return F[N]}});L.transition().duration(n.duration).attr("d",(n.type==="area")?x:j);L.exit().remove();d3.transition().duration(n.duration).each(function(){w.select(".x.grid").call(m.scale(C));w.select(".x.axis").call(i.scale(C))});var H=function(N){F[N]=(F[N]!=0)?0:1;d3.select("#circle_"+N).transition().duration(n.duration).style("fill-opacity",F[N]+0.2);d3.select("#path_"+N).transition().duration(n.duration).style("opacity",F[N])};const g=function(O,N){d3.select("#circle_"+O).attr("r",n.legend.buttonRadius*(N===false?1:1.3));const P=function(Q){if(N===false){return F[Q]}return(Q===O)?1:(F[Q]==0)?0:0.4};w.selectAll("path.path").style("opacity",function(R,Q){return P(Q)}).style("fill-opacity",function(R,Q){return P(Q)})};var G=c.selectAll("circle").data(A);G.enter().append("circle").attr("id",function(O,N){return"circle_"+N}).attr("cy",n.margin.top*2/3).attr("r",n.legend.buttonRadius).style("fill",function(O,N){return b(N)}).style("stroke",function(O,N){return b(N)}).style("fill-opacity",function(O,N){return F[N]+0.2}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)});G.exit().remove();G.transition().duration(n.duration).attr("cx",function(O,N){return k+n.legend.space*N});var E=c.selectAll("text").data(A);E.enter().append("text").attr("y",n.margin.top*2/3).attr("dy","0.3em").text(function(O,N){return v(N)}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)});E.exit().remove();E.transition().duration(n.duration).attr("x",function(O,N){return k+n.legend.space*N+2*n.legend.buttonRadius});return this};this.legend=function(g){$.extend(true,n.legend,g);c.selectAll("circle").transition().duration(n.duration).attr("cx",function(F,E){return k+n.legend.space*E}).attr("r",n.legend.buttonRadius).style("fill",function(F,E){return b(E)}).style("stroke",function(F,E){return b(E)});c.selectAll("text").text(function(F,E){return v(E)}).transition().duration(n.duration).attr("x",function(F,E){return k+n.legend.space*E+2*n.legend.buttonRadius});w.selectAll("path.path").transition().duration(n.duration).style("fill",(n.type==="area")?function(F,E){return b(E)}:"none").style("stroke",(n.type!=="area")?function(F,E){return b(E)}:"none");return this};this.convert=function(g){n.convert=g;u();w.selectAll("path.path").data(A).transition().duration(n.duration).attr("d",(n.type==="area")?x:j);return this};this.interpolate=function(g){n.interpolate=g;x.interpolate(n.interpolate);j.interpolate(n.interpolate);w.selectAll("path.path").attr("d",(n.type==="area")?x:j);return this};this.type=function(g){n.type=g;h();w.selectAll("path.path").style("stroke",(n.type!=="area")?function(F,E){return b(E)}:"none").style("fill",(n.type==="area")?function(F,E){return b(E)}:"none").transition().duration(n.duration).attr("d",(n.type==="area")?x:j);return this};this.destroy=function(){d3.select("svg").remove()}};
\ No newline at end of file
+;function D3Evolution(r,e){var n=$.extend(true,{title:"",width:800,height:400,margin:{top:80,right:60,bottom:40,left:60},yAxisLabel:"",type:"line",duration:1250,interpolate:"linear",legend:{buttonRadius:7,space:130,entries:[]}},e);var A;var y;var k;var s=n.width-n.margin.left-n.margin.right;var q=n.height-n.margin.top-n.margin.bottom;var C=d3.time.scale().range([0,s]);var d=d3.scale.linear().range([q,0]);var i=d3.svg.axis().scale(C);var a=d3.svg.axis().scale(d).orient("left").ticks(5);var m=d3.svg.axis().tickFormat("").scale(C).tickSize(-q,0);var D=d3.svg.axis().tickFormat("").scale(d).orient("left").tickSize(-s,0);var l=d3.scale.quantize().range([q,0]);var o=d3.svg.area().x(function(g){return C(g.x)}).y0(function(g){return q}).y1(function(g){return l(g.y==null)}).interpolate("step");var j=d3.svg.line().defined(function(g){return g.y!=null}).x(function(g){return C(g.x)}).y(function(g){return d(g.y)}).interpolate(n.interpolate);var x=d3.svg.area().defined(function(g){return g.y!=null}).x(function(g){return C(g.x)}).y0(function(g){return d(g.y0)}).y1(function(g){return d(g.y0+g.y)}).interpolate(n.interpolate);var h=function(){var g;if(n.type==="area"){d3.layout.stack()(A);g=d3.extent(d3.merge(A),function(E){return E.y0+E.y})}else{g=d3.extent(d3.merge(A),function(E){return E.y})}d.domain([(g[0]>0)?0:g[0],g[1]]);d3.transition().duration(n.duration).each(function(){w.select(".y.grid").call(D.scale(d));w.select(".y.axis").call(a.scale(d))})};var z=d3.scale.category10();var b=function(g){return(n.legend.entries[g]!==undefined&&n.legend.entries[g].color!==undefined)?n.legend.entries[g].color:z(g)};var v=function(g){return(n.legend.entries[g]!==undefined&&n.legend.entries[g].label!==undefined)?n.legend.entries[g].label:"path_"+g};var f=function(g){var F=g.reduce(function(G,H){return H.map(function(J,I){return J.y+(G[I]?G[I]:0)})},[]);var E=$.extend(true,[],g);E.forEach(function(G){G.forEach(function(I,H){if(F[H]){I.y/=F[H]}})});return E};var u=function(){if(n.convert==="percentage"){a.tickFormat(d3.format(".0%"));t.transition().duration(n.duration).style("opacity",0);A=f(y)}else{a.tickFormat(null);t.transition().duration(n.duration).style("opacity",1);A=y}h()};var p=d3.select("#"+r).append("svg").classed("d3evolution",true).attr("width",n.width).attr("height",n.height);var c=p.append("g").attr("class","legend");var w=p.append("g").attr("width",s).attr("height",q).attr("transform","translate("+n.margin.left+", "+n.margin.top+")");w.append("g").attr("class","x grid").attr("transform","translate(0,"+q+")").call(m);w.append("g").attr("class","y grid").attr("transform","translate(0,0)").call(D);w.append("g").attr("class","x axis").attr("transform","translate(0,"+q+")").call(i);w.append("g").attr("class","y axis").attr("transform","translate(0,0)").call(a);var t=w.append("text").attr("class","y label").attr("x",20-n.margin.left).attr("y",-20).style("opacity",(n.convert==="percentage")?0:1).text(n.yAxisLabel);var B=p.append("svg:text").attr("x",(n.width/2)).attr("y",(n.margin.top/3)).attr("text-anchor","middle");B.append("tspan").attr("class","chart-title").text(n.title+" ");B.timeRange=B.append("tspan");this.data=function(I){y=$.extend(true,[],I);var F=[];k=n.width-n.margin.right-n.legend.space*y.length;y.forEach(function(N){N.forEach(function(O){O.x*=1000})});var J=d3.extent(d3.merge(y),function(N){return N.x});C.domain([J[0],J[1]]);const M=function(N){return d3.time.format("%Y-%m-%d %H:%M:%S")(new Date(N))};B.timeRange.text("[ "+M(J[0])+" / "+M(J[1])+" ]");var K=w.selectAll("path.path-null").data(y);K.enter().append("path").attr("class","path-null");K.transition().duration(n.duration/2).style("opacity",0).each("end",function(){K.attr("d",o).transition().duration(n.duration/2).style("opacity",1)});K.exit().remove();u();var L=w.selectAll("path.path").data(A);L.enter().append("path").attr("class","path").attr("id",function(O,N){return"path_"+N}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)}).style((n.type==="area")?{fill:function(O,N){return b(N)},stroke:"none","fill-opacity":function(O,N){return F[N]}}:{fill:"none",stroke:function(O,N){return b(N)},opacity:function(O,N){return F[N]}});L.transition().duration(n.duration).attr("d",(n.type==="area")?x:j);L.exit().remove();d3.transition().duration(n.duration).each(function(){w.select(".x.grid").call(m.scale(C));w.select(".x.axis").call(i.scale(C))});var H=function(N){F[N]=(F[N]!=0)?0:1;d3.select("#circle_"+N).transition().duration(n.duration).style("fill-opacity",F[N]+0.2);d3.select("#path_"+N).transition().duration(n.duration).style("opacity",F[N])};const g=function(O,N){d3.select("#circle_"+O).attr("r",n.legend.buttonRadius*(N===false?1:1.3));const P=function(Q){if(N===false){return F[Q]}return(Q===O)?1:(F[Q]==0)?0:0.4};w.selectAll("path.path").style("opacity",function(R,Q){return P(Q)}).style("fill-opacity",function(R,Q){return P(Q)})};var G=c.selectAll("circle").data(A);G.enter().append("circle").attr("id",function(O,N){return"circle_"+N}).attr("cy",n.margin.top*2/3).attr("r",n.legend.buttonRadius).style("fill",function(O,N){return b(N)}).style("stroke",function(O,N){return b(N)}).style("fill-opacity",function(O,N){return F[N]+0.2}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)});G.exit().remove();G.transition().duration(n.duration).attr("cx",function(O,N){return k+n.legend.space*N});var E=c.selectAll("text").data(A);E.enter().append("text").attr("y",n.margin.top*2/3).attr("dy","0.3em").text(function(O,N){return v(N)}).on("click",function(O,N){H(N)}).on("mouseover",function(O,N){g(N)}).on("mouseout",function(O,N){g(N,false)});E.exit().remove();E.transition().duration(n.duration).attr("x",function(O,N){return k+n.legend.space*N+2*n.legend.buttonRadius});return this};this.legend=function(g){$.extend(true,n.legend,g);c.selectAll("circle").transition().duration(n.duration).attr("cx",function(F,E){return k+n.legend.space*E}).attr("r",n.legend.buttonRadius).style("fill",function(F,E){return b(E)}).style("stroke",function(F,E){return b(E)});c.selectAll("text").text(function(F,E){return v(E)}).transition().duration(n.duration).attr("x",function(F,E){return k+n.legend.space*E+2*n.legend.buttonRadius});w.selectAll("path.path").transition().duration(n.duration).style("fill",(n.type==="area")?function(F,E){return b(E)}:"none").style("stroke",(n.type!=="area")?function(F,E){return b(E)}:"none");return this};this.convert=function(g){n.convert=g;u();w.selectAll("path.path").data(A).transition().duration(n.duration).attr("d",(n.type==="area")?x:j);return this};this.interpolate=function(g){n.interpolate=g;x.interpolate(n.interpolate);j.interpolate(n.interpolate);w.selectAll("path.path").attr("d",(n.type==="area")?x:j);return this};this.type=function(g){n.type=g;h();w.selectAll("path.path").style("stroke",(n.type!=="area")?function(F,E){return b(E)}:"none").style("fill",(n.type==="area")?function(F,E){return b(E)}:"none").transition().duration(n.duration).attr("d",(n.type==="area")?x:j);return this};this.yAxisLabel=function(g){n.yAxisLabel=g;t.transition().duration(n.duration/2).style("opacity",0).each("end",function(){t.text(n.yAxisLabel).transition().duration(n.duration/2).style("opacity",1)});return this};this.destroy=function(){d3.select("svg").remove()}};
\ No newline at end of file