File: //proc/1/task/1/root/usr/share/rspamd/www/js/lib/d3evolution.min.js
/*!
* D3Evolution 2.0.4 (https://github.com/moisseev/D3Evolution)
* Copyright (c) 2016-2017, Alexander Moisseev, BSD 2-Clause
*/
function D3Evolution(t,e){"use strict";var n=$.extend(!0,{title:"",width:800,height:400,margin:{top:80,right:60,bottom:40,left:60},yAxisLabel:"",type:"line",yScale:"lin",duration:1250,interpolate:"curveLinear",legend:{buttonRadius:7,space:130,entries:[]}},e);this.destroy=function(){d3.select("#"+t).selectAll("*").on("click",null).on("mousemove",null).on("mouseover",null).on("mouseout",null),d3.selectAll("#"+t+" svg").remove()},this.destroy();const r={curveLinear:d3.curveLinear,curveStep:d3.curveStep,curveStepBefore:d3.curveStepBefore,curveStepAfter:d3.curveStepAfter,curveMonotoneX:d3.curveMonotoneX,curveBasis:d3.curveBasis,curveBasisOpen:d3.curveBasisOpen,curveBundle:d3.curveBundle,curveCardinal:d3.curveCardinal,curveCardinalOpen:d3.curveCardinalOpen,curveCatmullRom:d3.curveCatmullRom,curveCatmullRomOpen:d3.curveCatmullRomOpen,curveNatural:d3.curveNatural};var a=null,l=null,i=null,o=n.width-n.margin.left-n.margin.right,c=n.height-n.margin.top-n.margin.bottom,u=d3.scaleTime().range([0,o]),s=null,d=null;const p=function(){"log"===n.yScale?(s=d3.scaleLog().clamp(!0).range([c,0]),d=d3.scaleLog().range([c-30,0])):(s=d3.scaleLinear().range([c,0]),d=s.copy())};p();var y=d3.axisBottom().scale(u),f=d3.axisLeft().scale(d).ticks(5),g=d3.axisBottom().tickFormat("").scale(u).tickSize(-c,0),v=d3.axisLeft().tickFormat("").scale(d).tickSize(-o,0),h=d3.scaleQuantize().range([c,0]),m=d3.area().x(function(t){return u(t.x)}).y0(function(){return c}).y1(function(t){return h(null===t.y)}).curve(d3.curveStep),x=d3.line().defined(function(t){return null!==t.y}).x(function(t){return u(t.x)}).y(function(t){return s(t.y)}).curve(r[n.interpolate]),A=d3.area().defined(function(t){return null!==t.y}).x(function(t){return u(t.x)}).y0(function(t){return s(t.y0)}).y1(function(t){return s(t.y0+t.y)}).curve(r[n.interpolate]),k=d3.scaleOrdinal(d3.schemeCategory10),b=function(t){return void 0!==n.legend.entries[t]&&void 0!==n.legend.entries[t].color?n.legend.entries[t].color:k(t)},S=function(t){return void 0!==n.legend.entries[t]&&void 0!==n.legend.entries[t].label?n.legend.entries[t].label:"path_"+t};const L=function(){if("log"===n.yScale){const t=s.invert(c);a.forEach(function(e){e.forEach(function(e){return 0===e.y?e.y:t})})}};var O=d3.select("#"+t).append("svg").classed("d3evolution",!0).attr("width",n.width).attr("height",n.height),w=O.append("g").attr("class","legend"),R=O.append("g").attr("width",o).attr("height",c).attr("transform","translate("+n.margin.left+", "+n.margin.top+")");R.append("g").attr("class","x grid").attr("transform","translate(0,"+c+")").call(g),R.append("g").attr("class","y grid").attr("transform","translate(0,0)").call(v),R.append("g").attr("class","x axis").attr("transform","translate(0,"+c+")").call(y),R.append("g").attr("class","y axis").attr("transform","translate(0,0)").call(f);var B=d3.scaleOrdinal().domain([0]).range([c]),C=d3.axisLeft().scale(B);R.append("g").attr("class","y-zero axis").call(C);var M=R.append("text").attr("class","y label").attr("x",20-n.margin.left).attr("y",-20).style("opacity","percentage"===n.convert?0:1).text(n.yAxisLabel),E=O.append("svg:text").attr("x",n.width/2).attr("y",n.margin.top/3).attr("text-anchor","middle");E.append("tspan").attr("class","chart-title").text(n.title+" "),E.timeRange=E.append("tspan");var F=O.append("svg:text").attr("x",n.width-20).attr("y",n.margin.top/3).attr("text-anchor","end"),_=F.append("tspan").attr("class","cursor-time");F.append("svg:title").text("Current cursor position");const z=function(t){return d3.timeFormat("%Y-%m-%d %H:%M:%S")(new Date(t))};function N(t){var e=a.map(function(e){return e[t]}),r=e[0].x;return _.text(z(r)),w.selectAll("text.value").text(function(t,r){return null===e[r].y?null:d3.format("percentage"===n.convert?".2~%":".6~")(e[r].y)}),e}var D=null,X=null;function H(t){var e=d3.bisector(function(t){return t.x}).left,r=u.invert(d3.pointer(t)[0]);if(a&&a[0]&&a[0].length){var l=N(Math.max(0,e(a[0],r)-1));D.selectAll(".x,.cursor circle").attr("transform","translate("+u(l[0].x)+",0)"),D.selectAll(".y").attr("transform",function(t,e){var r=l[e];return"translate(0,"+(("area"===n.type?s(r.y0+r.y):s(r.y))||0)+")"}).style("display",function(t,e){return l[e].y?null:"none"})}}function Q(){D.style("display","none"),N(X)}function T(){D.style("display",null)}R.append("rect").style("fill","none").style("pointer-events","all").attr("width",o).attr("height",c).on("mousemove",H).on("mouseout",Q).on("mouseover",T);var V=R.append("g"),Y=R.append("g");(D=R.append("g").attr("class","cursor").style("pointer-events","none").style("display","none")).append("line").attr("class","x background").attr("y1",0).attr("y2",c),D.append("line").attr("class","x foreground").attr("y1",0).attr("y2",c);var j=function(){var t="area"===n.type?(a.reduce(function(t,e){return e.forEach(function(e,n){e.y0=t.length?t[n].y+t[n].y0:0}),e},[]),"log"===n.yScale?d3.extent(d3.merge(a),function(t){return t.y0+t.y===0?null:t.y0+t.y}):d3.extent(d3.merge(a),function(t){return t.y0+t.y})):"log"===n.yScale?d3.extent(d3.merge(a),function(t){return 0===t.y?null:t.y}):d3.extent(d3.merge(a),function(t){return t.y});if("log"===n.yScale){void 0===t[0]?t=[.0095,.0105]:t[0]===t[1]&&(t[0]*=.9),d.domain([t[0],t[1]]);var e=d.invert(c);s.domain([e,t[1]])}else s.domain([t[0]>0?0:t[0],t[1]]),d.domain(s.domain());if("percentage"===n.convert){var r={y:c};const t=d3.format(".0%");C.tickFormat(t),f.tickFormat("log"===n.yScale?function(e){return function(t,e,n){const r=Math.pow(10,Math.round(Math.log(t)/Math.LN10));return Math.abs(r-t)<1e-6||!(Math.abs(s(r)-s(t))<15||e.y-s(t)<15)?(e.y=s(t),n(t)):""}(e,r,t)}:t)}else C.tickFormat(null),f.tickFormat(null);f.tickValues(d.ticks().length?null:[t[0],t[1]]);const l=d3.transition().duration(n.duration);R.select(".y.grid").transition(l).call(v.scale(d)),R.select(".y.axis").transition(l).call(f.scale(d)),R.select(".y-zero.axis").call(C)},q=function(){var t,e,r;"percentage"===n.convert?(M.transition().duration(n.duration).style("opacity",0),e=(t=l).reduce(function(t,e){return e.map(function(e,n){return e.y+(t[n]?t[n]:0)})},[]),(r=$.extend(!0,[],t)).forEach(function(t){t.forEach(function(t,n){e[n]&&(t.y/=e[n])})}),a=r):(M.transition().duration(n.duration).style("opacity",1),a=l),X=l[0].length-1,j()};function G(t){return"translate("+(i+n.legend.space*t+2*n.legend.buttonRadius)+","+2*n.margin.top/3+")"}function I(t){(t||w.selectAll("g")).transition().duration(n.duration).attr("transform",function(t,e){return G(e)})}var J=[];this.data=function(t){var e=t=>{t.on("click",(t,e)=>{const r=a.indexOf(e);J[r]=0===J[r]?1:0,d3.select("#circle_"+r).transition().duration(n.duration).style("fill-opacity",0===J[r]?.2:1),d3.select("#path_"+r).transition().duration(n.duration).style("opacity",J[r])})};const r=function(t,e){d3.select("#circle_"+t).attr("r",n.legend.buttonRadius*(!1===e?1:1.3));const r=function(n){return!1===e?J[n]:n===t?1:0===J[n]?0:.4};Y.selectAll("path.path").style("opacity",function(t,e){return r(e)}).style("fill-opacity",function(t,e){return r(e)})};for(l=$.extend(!0,[],t),i=n.width-n.margin.right-n.legend.space*l.length;J.length<l.length;)J.push(1);J.length=l.length,l.forEach(function(t){t.forEach(function(t){t.x*=1e3})});var c=d3.extent(d3.merge(l),function(t){return t.x});u.domain([c[0],c[1]]),E.timeRange.text("[ "+z(c[0])+" / "+z(c[1])+" ]");var s=V.selectAll("path.path-null").data(l);s.enter().append("path").attr("class","path-null"),V.selectAll("path.path-null").transition().duration(n.duration/2).style("opacity",0).on("end",function(){V.selectAll("path.path-null").attr("d",m).transition().duration(n.duration/2).style("opacity",1)}),s.exit().remove(),q(),L();var d=Y.selectAll("path.path").data(a);e(d.enter().append("path").merge(d).attr("class","path").attr("id",function(t,e){return"path_"+e}).on("mousemove",H).on("mouseover",(t,e)=>{r(a.indexOf(e)),T()}).on("mouseout",(t,e)=>{r(a.indexOf(e),!1),Q()})),d.exit().remove(),d=Y.selectAll("path.path"),"area"===n.type?d.style("fill",function(t,e){return b(e)}).style("stroke","none").style("fill-opacity",function(t,e){return J[e]}):d.style("fill","none").style("stroke",function(t,e){return b(e)}).style("opacity",function(t,e){return J[e]}),d.transition().duration(n.duration).attr("d","area"===n.type?A:x);const p=d3.transition().duration(n.duration);R.select(".x.grid").transition(p).call(g.scale(u)),R.select(".x.axis").transition(p).call(y.scale(u));var f=D.selectAll(".y").data(a),v=f.enter().append("g").attr("class","y").style("stroke",function(t,e){return b(e)});v.append("circle").attr("class","background"),v.append("circle").attr("class","foreground"),v.selectAll("circle").attr("r",7).style("fill","none"),v.append("line").attr("class","background"),v.append("line").attr("class","foreground"),v.selectAll("line").attr("x1",0).attr("x2",o),f.exit().remove();var h=w.selectAll("circle").data(a);e(h.enter().append("circle").attr("id",function(t,e){return"circle_"+e}).attr("cy",2*n.margin.top/3).attr("r",n.legend.buttonRadius).attr("cx",function(t,e){return i+n.legend.space*e}).style("fill",function(t,e){return b(e)}).style("stroke",function(t,e){return b(e)}).style("fill-opacity",function(t,e){return 0===J[e]?.2:1}).on("mouseover",(t,e)=>r(a.indexOf(e))).on("mouseout",(t,e)=>r(a.indexOf(e),!1))),h.exit().remove(),h.transition().duration(n.duration).attr("cx",function(t,e){return i+n.legend.space*e}).style("fill-opacity",function(t,e){return 0===J[e]?.2:1});var k=w.selectAll("g").data(a),O=k.enter().append("g").attr("transform",function(t,e){return G(e)});e(O.append("text").attr("class","name").attr("dy","0.3em").text(function(t,e){return S(e)}).on("mouseover",(t,e)=>r(a.indexOf(e))).on("mouseout",(t,e)=>r(a.indexOf(e),!1))),O.append("text").attr("class","value").attr("dy","20"),k.exit().remove(),I(k);var B=w.selectAll("text.value");return B.transition("opacity").duration(n.duration/2).style("opacity",0).on("end",function(){N(X),B.transition("opacity").duration(n.duration/2).style("opacity",1)}),this},this.legend=function(t){return $.extend(!0,n.legend,t),w.selectAll("circle").transition().duration(n.duration).attr("cx",function(t,e){return i+n.legend.space*e}).attr("r",n.legend.buttonRadius).style("fill",function(t,e){return b(e)}).style("stroke",function(t,e){return b(e)}),w.selectAll("text.name").text(function(t,e){return S(e)}),I(),Y.selectAll("path.path").transition().duration(n.duration).style("fill","area"===n.type?function(t,e){return b(e)}:"none").style("stroke","area"!==n.type?function(t,e){return b(e)}:"none"),D.selectAll(".y").style("stroke",function(t,e){return b(e)}),this},this.convert=function(t){return n.convert=t,q(),N(X),Y.selectAll("path.path").data(a).transition().duration(n.duration).attr("d","area"===n.type?A:x),this},this.interpolate=function(t){return n.interpolate=t,A.curve(r[n.interpolate]),x.curve(r[n.interpolate]),Y.selectAll("path.path").attr("d","area"===n.type?A:x),this},this.type=function(t){return n.type=t,j(),Y.selectAll("path.path").style("stroke","area"!==n.type?function(t,e){return b(e)}:"none").style("fill","area"===n.type?function(t,e){return b(e)}:"none").transition().duration(n.duration).attr("d","area"===n.type?A:x),this},this.yAxisLabel=function(t){return n.yAxisLabel=t,M.transition().duration(n.duration/2).style("opacity",0).on("end",function(){M.text(n.yAxisLabel).transition().duration(n.duration/2).style("opacity",1)}),this},this.yScale=function(t){return n.yScale=t,p(),L(),j(),Y.selectAll("path.path").transition().duration(n.duration).attr("d","area"===n.type?A:x),this}}