]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Update bundled D3-based visualization libs
authorAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 30 Oct 2025 07:53:15 +0000 (10:53 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 30 Oct 2025 07:53:15 +0000 (10:53 +0300)
- **D3Evolution** 2.0.2 → 2.0.3
  Improves flexibility for different themes.
- **rspamd-D3Pie** 1.1.0 → 1.1.1
  Fixes a bug where the color was not applied to the label of the placeholder slice.

interface/css/d3evolution.css
interface/css/d3pie.css
interface/js/lib/d3evolution.min.js
interface/js/lib/d3pie.min.js

index beb3deb23e9ed5689258e7871d5381c160b33cc4..aa726c0d1c70452c4b8a6375008e8a191c50e4cf 100644 (file)
@@ -1,6 +1,3 @@
-.d3evolution svg {
-    background-color: white;
-}
 .d3evolution .chart-title {
     font-size: 17px;
 }
index 813ce9fe50980e33ae6384eef4594f1c641d97a9..dbd66ef74f2516edbb5f0430a1ad795f0f58ba30 100644 (file)
@@ -29,7 +29,7 @@
 }
 
 /* pie placeholder */
-.d3pie .slice-g:first-of-type .inner-label {
+.d3pie .slice-g.first-slice .inner-label {
     fill: #cccccc;
 }
 .d3pie defs radialGradient:first-of-type stop {
index 4ef257722ce4a2d0fe70ebfaa37639f5028dc480..ceedf77578621db874037a0a68b16b235d5188f6 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * D3Evolution 2.0.2 (https://github.com/moisseev/D3Evolution)
+ * D3Evolution 2.0.3 (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.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,i=null,l=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 w=d3.select("#"+t).append("svg").classed("d3evolution",!0).attr("width",n.width).attr("height",n.height),R=w.append("g").attr("class","legend"),B=w.append("g").attr("width",o).attr("height",c).attr("transform","translate("+n.margin.left+", "+n.margin.top+")");B.append("g").attr("class","x grid").attr("transform","translate(0,"+c+")").call(g),B.append("g").attr("class","y grid").attr("transform","translate(0,0)").call(v),B.append("g").attr("class","x axis").attr("transform","translate(0,"+c+")").call(y),B.append("g").attr("class","y axis").attr("transform","translate(0,0)").call(f);var C=d3.scaleOrdinal().domain([0]).range([c]),M=d3.axisLeft().scale(C);B.append("g").attr("class","y-zero axis").call(M);var O=B.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=w.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=w.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)),R.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,T=null;function X(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 i=N(e(a[0],r)-1);D.selectAll(".x,.cursor circle").attr("transform","translate("+u(i[0].x)+",0)"),D.selectAll(".y").attr("transform",function(t,e){var r=i[e];return"translate(0,"+(("area"===n.type?s(r.y0+r.y):s(r.y))||0)+")"}).style("display",function(t,e){return i[e].y?null:"none"})}}function H(){D.style("display","none"),N(T)}function Q(){D.style("display",null)}B.append("rect").style("fill","none").style("pointer-events","all").attr("width",o).attr("height",c).on("mousemove",X).on("mouseout",H).on("mouseover",Q);var V=B.append("g"),Y=B.append("g");(D=B.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=[];if("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},[]),t="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})):t="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}),"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%");M.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 M.tickFormat(null),f.tickFormat(null);f.tickValues(d.ticks().length?null:[t[0],t[1]]);const i=d3.transition().duration(n.duration);B.select(".y.grid").transition(i).call(v.scale(d)),B.select(".y.axis").transition(i).call(f.scale(d)),B.select(".y-zero.axis").call(M)},q=function(){var t,e,r;"percentage"===n.convert?(O.transition().duration(n.duration).style("opacity",0),e=(t=i).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):(O.transition().duration(n.duration).style("opacity",1),a=i),T=i[0].length-1,j()};function G(){R.selectAll("g").transition().duration(n.duration).attr("transform",function(t,e){return"translate("+(l+n.legend.space*e+2*n.legend.buttonRadius)+","+2*n.margin.top/3+")"})}var I=[];this.data=function(t){var e=t=>{t.on("click",e=>{const r=t.nodes().indexOf(e.currentTarget);I[r]=0===I[r]?1:0,d3.select("#circle_"+r).transition().duration(n.duration).style("fill-opacity",I[r]+.2),d3.select("#path_"+r).transition().duration(n.duration).style("opacity",I[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?I[n]:n===t?1:0===I[n]?0:.4};Y.selectAll("path.path").style("opacity",function(t,e){return r(e)}).style("fill-opacity",function(t,e){return r(e)})};i=$.extend(!0,[],t),l=n.width-n.margin.right-n.legend.space*i.length,i.forEach(function(t){t.forEach(function(t){t.x*=1e3})});var c=d3.extent(d3.merge(i),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(i);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",X).on("mouseover",function(t,e,n){r(n),Q()}).on("mouseout",function(t,e,n){r(n,!1),H()})),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 I[e]}):d.style("fill","none").style("stroke",function(t,e){return b(e)}).style("opacity",function(t,e){return I[e]}),d.transition().duration(n.duration).attr("d","area"===n.type?A:x);const p=d3.transition().duration(n.duration);B.select(".x.grid").transition(p).call(g.scale(u)),B.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=R.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).style("fill",function(t,e){return b(e)}).style("stroke",function(t,e){return b(e)}).style("fill-opacity",function(t,e){return I[e]+.2}).on("mouseover",function(t,e,n){r(n)}).on("mouseout",function(t,e,n){r(n,!1)})),h.exit().remove(),R.selectAll("circle").transition().duration(n.duration).attr("cx",function(t,e){return l+n.legend.space*e});var k=R.selectAll("g").data(a),w=k.enter().append("g");e(w.append("text").attr("class","name").attr("dy","0.3em").text(function(t,e){return S(e)}).on("mouseover",function(t,e,n){r(n)}).on("mouseout",function(t,e,n){r(n,!1)})),w.append("text").attr("class","value").attr("dy","20"),k.exit().remove(),G();var C=R.selectAll("text.value");return C.transition("opacity").duration(n.duration/2).style("opacity",0).on("end",function(){N(T),C.transition("opacity").duration(n.duration/2).style("opacity",1)}),this},this.legend=function(t){return $.extend(!0,n.legend,t),R.selectAll("circle").transition().duration(n.duration).attr("cx",function(t,e){return l+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)}),R.selectAll("text.name").text(function(t,e){return S(e)}),G(),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(T),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,O.transition().duration(n.duration/2).style("opacity",0).on("end",function(){O.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}}
\ No newline at end of file
+function D3Evolution(t,e){var l=$.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.selectAll("#"+t+" svg").remove()},this.destroy();let n={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 o=null,i=null,c=null,u=l.width-l.margin.left-l.margin.right,r=l.height-l.margin.top-l.margin.bottom,s=d3.scaleTime().range([0,u]),d=null,a=null;function p(){a="log"===l.yScale?(d=d3.scaleLog().clamp(!0).range([r,0]),d3.scaleLog().range([r-30,0])):(d=d3.scaleLinear().range([r,0])).copy()}p();function y(t){return void 0!==l.legend.entries[t]&&void 0!==l.legend.entries[t].color?l.legend.entries[t].color:H(t)}function f(t){return void 0!==l.legend.entries[t]&&void 0!==l.legend.entries[t].label?l.legend.entries[t].label:"path_"+t}var g=d3.axisBottom().scale(s),h=d3.axisLeft().scale(a).ticks(5),m=d3.axisBottom().tickFormat("").scale(s).tickSize(-r,0),v=d3.axisLeft().tickFormat("").scale(a).tickSize(-u,0),D=d3.scaleQuantize().range([r,0]),T=d3.area().x(function(t){return s(t.x)}).y0(function(){return r}).y1(function(t){return D(null===t.y)}).curve(d3.curveStep),x=d3.line().defined(function(t){return null!==t.y}).x(function(t){return s(t.x)}).y(function(t){return d(t.y)}).curve(n[l.interpolate]),A=d3.area().defined(function(t){return null!==t.y}).x(function(t){return s(t.x)}).y0(function(t){return d(t.y0)}).y1(function(t){return d(t.y0+t.y)}).curve(n[l.interpolate]),X=function(t){t.reduce(function(n,t){return t.forEach(function(t,e){t.y0=n.length?n[e].y+n[e].y0:0}),t},[])},H=d3.scaleOrdinal(d3.schemeCategory10),Q=function(t){var n=t.reduce(function(n,t){return t.map(function(t,e){return t.y+(n[e]||0)})},[]),t=$.extend(!0,[],t);return t.forEach(function(t){t.forEach(function(t,e){n[e]&&(t.y/=n[e])})}),t};function k(){if("log"===l.yScale){let e=d.invert(r);o.forEach(function(t){t.forEach(function(t){return 0===t.y?t.y:e})})}}let b=d3.select("#"+t).append("svg").classed("d3evolution",!0).attr("width",l.width).attr("height",l.height);var S=b.append("g").attr("class","legend"),L=b.append("g").attr("width",u).attr("height",r).attr("transform","translate("+l.margin.left+", "+l.margin.top+")"),e=(L.append("g").attr("class","x grid").attr("transform","translate(0,"+r+")").call(m),L.append("g").attr("class","y grid").attr("transform","translate(0,0)").call(v),L.append("g").attr("class","x axis").attr("transform","translate(0,"+r+")").call(g),L.append("g").attr("class","y axis").attr("transform","translate(0,0)").call(h),d3.scaleOrdinal().domain([0]).range([r])),w=d3.axisLeft().scale(e),R=(L.append("g").attr("class","y-zero axis").call(w),L.append("text").attr("class","y label").attr("x",20-l.margin.left).attr("y",-20).style("opacity","percentage"===l.convert?0:1).text(l.yAxisLabel)),B=b.append("svg:text").attr("x",l.width/2).attr("y",l.margin.top/3).attr("text-anchor","middle"),e=(B.append("tspan").attr("class","chart-title").text(l.title+" "),B.timeRange=B.append("tspan"),b.append("svg:text").attr("x",l.width-20).attr("y",l.margin.top/3).attr("text-anchor","end")),V=e.append("tspan").attr("class","cursor-time");e.append("svg:title").text("Current cursor position");let C=function(t){return d3.timeFormat("%Y-%m-%d %H:%M:%S")(new Date(t))};function M(e){var n=o.map(function(t){return t[e]}),t=n[0].x;return V.text(C(t)),S.selectAll("text.value").text(function(t,e){return null===n[e].y?null:d3.format("percentage"===l.convert?".2~%":".6~")(n[e].y)}),n}var O=null,E=null;function Y(t){var n,e=d3.bisector(function(t){return t.x}).left,t=s.invert(d3.pointer(t)[0]);o&&o[0]&&o[0].length&&(n=M(e(o[0],t)-1),O.selectAll(".x,.cursor circle").attr("transform","translate("+s(n[0].x)+",0)"),O.selectAll(".y").attr("transform",function(t,e){e=n[e];return"translate(0,"+(("area"===l.type?d(e.y0+e.y):d(e.y))||0)+")"}).style("display",function(t,e){return n[e].y?null:"none"}))}function j(){O.style("display","none"),M(E)}function q(){O.style("display",null)}L.append("rect").style("fill","none").style("pointer-events","all").attr("width",u).attr("height",r).on("mousemove",Y).on("mouseout",j).on("mouseover",q);function G(){o="percentage"===l.convert?(R.transition().duration(l.duration).style("opacity",0),Q(i)):(R.transition().duration(l.duration).style("opacity",1),i),E=i[0].length-1,z()}var F=L.append("g"),_=L.append("g"),z=((O=L.append("g").attr("class","cursor").style("pointer-events","none").style("display","none")).append("line").attr("class","x background").attr("y1",0).attr("y2",r),O.append("line").attr("class","x foreground").attr("y1",0).attr("y2",r),function(){var t=[];if(t="area"===l.type?(X(o),"log"===l.yScale?d3.extent(d3.merge(o),function(t){return t.y0+t.y===0?null:t.y0+t.y}):d3.extent(d3.merge(o),function(t){return t.y0+t.y})):"log"===l.yScale?d3.extent(d3.merge(o),function(t){return 0===t.y?null:t.y}):d3.extent(d3.merge(o),function(t){return t.y}),"log"===l.yScale?(void 0===t[0]?t=[.0095,.0105]:t[0]===t[1]&&(t[0]*=.9),a.domain([t[0],t[1]]),e=a.invert(r),d.domain([e,t[1]])):(d.domain([0<t[0]?0:t[0],t[1]]),a.domain(d.domain())),"percentage"===l.convert){var i={y:r};let a=d3.format(".0%");w.tickFormat(a),h.tickFormat("log"===l.yScale?function(t){return t=t,e=i,n=a,r=Math.pow(10,Math.round(Math.log(t)/Math.LN10)),Math.abs(r-t)<1e-6||!(Math.abs(d(r)-d(t))<15||e.y-d(t)<15)?(e.y=d(t),n(t)):"";var e,n,r}:a)}else w.tickFormat(null),h.tickFormat(null);h.tickValues(a.ticks().length?null:[t[0],t[1]]);var e=d3.transition().duration(l.duration);L.select(".y.grid").transition(e).call(v.scale(a)),L.select(".y.axis").transition(e).call(h.scale(a)),L.select(".y-zero.axis").call(w)});function I(){S.selectAll("g").transition().duration(l.duration).attr("transform",function(t,e){return"translate("+(c+l.legend.space*e+2*l.legend.buttonRadius)+","+2*l.margin.top/3+")"})}var N=[];this.data=function(t){function r(e,n){function r(t){return!1===n?N[t]:t===e?1:0===N[t]?0:.4}d3.select("#circle_"+e).attr("r",l.legend.buttonRadius*(!1===n?1:1.3)),_.selectAll("path.path").style("opacity",function(t,e){return r(e)}).style("fill-opacity",function(t,e){return r(e)})}var e=e=>{e.on("click",t=>{t=e.nodes().indexOf(t.currentTarget);N[t]=0===N[t]?1:0,d3.select("#circle_"+t).transition().duration(l.duration).style("fill-opacity",N[t]+.2),d3.select("#path_"+t).transition().duration(l.duration).style("opacity",N[t])})};i=$.extend(!0,[],t),c=l.width-l.margin.right-l.legend.space*i.length,i.forEach(function(t){t.forEach(function(t){t.x*=1e3})});var t=d3.extent(d3.merge(i),function(t){return t.x}),t=(s.domain([t[0],t[1]]),B.timeRange.text("[ "+C(t[0])+" / "+C(t[1])+" ]"),F.selectAll("path.path-null").data(i)),t=(t.enter().append("path").attr("class","path-null"),F.selectAll("path.path-null").transition().duration(l.duration/2).style("opacity",0).on("end",function(){F.selectAll("path.path-null").attr("d",T).transition().duration(l.duration/2).style("opacity",1)}),t.exit().remove(),G(),k(),_.selectAll("path.path").data(o)),t=(e(t.enter().append("path").merge(t).attr("class","path").attr("id",function(t,e){return"path_"+e}).on("mousemove",Y).on("mouseover",function(t,e,n){r(n),q()}).on("mouseout",function(t,e,n){r(n,!1),j()})),t.exit().remove(),t=_.selectAll("path.path"),"area"===l.type?t.style("fill",function(t,e){return y(e)}).style("stroke","none").style("fill-opacity",function(t,e){return N[e]}):t.style("fill","none").style("stroke",function(t,e){return y(e)}).style("opacity",function(t,e){return N[e]}),t.transition().duration(l.duration).attr("d","area"===l.type?A:x),d3.transition().duration(l.duration)),t=(L.select(".x.grid").transition(t).call(m.scale(s)),L.select(".x.axis").transition(t).call(g.scale(s)),O.selectAll(".y").data(o)),n=t.enter().append("g").attr("class","y").style("stroke",function(t,e){return y(e)}),n=(n.append("circle").attr("class","background"),n.append("circle").attr("class","foreground"),n.selectAll("circle").attr("r",7).style("fill","none"),n.append("line").attr("class","background"),n.append("line").attr("class","foreground"),n.selectAll("line").attr("x1",0).attr("x2",u),t.exit().remove(),S.selectAll("circle").data(o)),t=(e(n.enter().append("circle").attr("id",function(t,e){return"circle_"+e}).attr("cy",2*l.margin.top/3).attr("r",l.legend.buttonRadius).style("fill",function(t,e){return y(e)}).style("stroke",function(t,e){return y(e)}).style("fill-opacity",function(t,e){return N[e]+.2}).on("mouseover",function(t,e,n){r(n)}).on("mouseout",function(t,e,n){r(n,!1)})),n.exit().remove(),S.selectAll("circle").transition().duration(l.duration).attr("cx",function(t,e){return c+l.legend.space*e}),S.selectAll("g").data(o)),n=t.enter().append("g"),a=(e(n.append("text").attr("class","name").attr("dy","0.3em").text(function(t,e){return f(e)}).on("mouseover",function(t,e,n){r(n)}).on("mouseout",function(t,e,n){r(n,!1)})),n.append("text").attr("class","value").attr("dy","20"),t.exit().remove(),I(),S.selectAll("text.value"));return a.transition("opacity").duration(l.duration/2).style("opacity",0).on("end",function(){M(E),a.transition("opacity").duration(l.duration/2).style("opacity",1)}),this},this.legend=function(t){return $.extend(!0,l.legend,t),S.selectAll("circle").transition().duration(l.duration).attr("cx",function(t,e){return c+l.legend.space*e}).attr("r",l.legend.buttonRadius).style("fill",function(t,e){return y(e)}).style("stroke",function(t,e){return y(e)}),S.selectAll("text.name").text(function(t,e){return f(e)}),I(),_.selectAll("path.path").transition().duration(l.duration).style("fill","area"===l.type?function(t,e){return y(e)}:"none").style("stroke","area"!==l.type?function(t,e){return y(e)}:"none"),O.selectAll(".y").style("stroke",function(t,e){return y(e)}),this},this.convert=function(t){return l.convert=t,G(),M(E),_.selectAll("path.path").data(o).transition().duration(l.duration).attr("d","area"===l.type?A:x),this},this.interpolate=function(t){return l.interpolate=t,A.curve(n[l.interpolate]),x.curve(n[l.interpolate]),_.selectAll("path.path").attr("d","area"===l.type?A:x),this},this.type=function(t){return l.type=t,z(),_.selectAll("path.path").style("stroke","area"!==l.type?function(t,e){return y(e)}:"none").style("fill","area"===l.type?function(t,e){return y(e)}:"none").transition().duration(l.duration).attr("d","area"===l.type?A:x),this},this.yAxisLabel=function(t){return l.yAxisLabel=t,R.transition().duration(l.duration/2).style("opacity",0).on("end",function(){R.text(l.yAxisLabel).transition().duration(l.duration/2).style("opacity",1)}),this},this.yScale=function(t){return l.yScale=t,p(),k(),z(),_.selectAll("path.path").transition().duration(l.duration).attr("d","area"===l.type?A:x),this}}
\ No newline at end of file
index 823f69735928657609dcec078caf6b3d7b0a3e88..968d33444b57defd991f7019f64a402791384343 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * rspamd-D3Pie 1.1.0 (https://github.com/moisseev/rspamd-D3Pie)
+ * rspamd-D3Pie 1.1.1 (https://github.com/moisseev/rspamd-D3Pie)
  * Copyright (c) 2022, Alexander Moisseev, BSD 2-Clause
  */
-function D3Pie(v,t){"use strict";const A=$.extend(!0,{canvasPadding:5,cornerRadius:3,duration:1250,gradient:{enabled:!0,percentage:100},labels:{inner:{hideWhenLessThanPercentage:4,offset:.15},outer:{collideHeight:13,format:"label",pieDistance:30}},padAngle:.01,pieCenterOffset:{x:0,y:0},size:{canvasHeight:400,canvasWidth:600,pieInnerRadius:"20%",pieOuterRadius:"85%"},title:"",total:{enabled:!1}},t),e=(this.destroy=function(){d3.selectAll("#"+v+" svg, #"+v+"-tooltip").remove()},this.destroy(),d3.select("#"+v).append("svg").attr("class","d3pie").attr("width",A.size.canvasWidth).attr("height",A.size.canvasHeight));let l=0;if(""!==A.title){const a=e.append("svg:text").attr("class","chart-title").attr("x",A.size.canvasWidth/2);a.append("tspan").text(A.title+" "),l=a.node().getBBox().height,a.attr("y",l+A.canvasPadding)}const x=e.append("g").attr("transform","translate("+(A.size.canvasWidth/2+A.pieCenterOffset.x)+","+(A.size.canvasHeight/2+l/2+A.pieCenterOffset.y)+")"),y={},m={},{outerRadius:M,innerRadius:R}=function(){function t(t,e){var a;return/%/u.test(t)?(a=Math.max(0,Math.min(99,parseInt(t.replace(/[\D]/u,""),10)))/100,Math.floor(e*a)):parseInt(t,10)}var e=A.size.canvasWidth-2*A.canvasPadding,a=A.size.canvasHeight-2*A.canvasPadding-l;let n=Math.min(e,a)/2;"none"!==A.labels.outer.format&&(e=parseInt(A.labels.outer.pieDistance,10),n>e&&(n-=e));a=t(A.size.pieOuterRadius,n);return{outerRadius:a,innerRadius:t(A.size.pieInnerRadius,a)}}(),w=M+A.labels.outer.pieDistance,z=d3.line().curve(d3.curveCatmullRomOpen),P=d3.select("body").append("div").attr("id",v+"-tooltip").attr("class","d3pie-tooltip"),r=P.append("span").attr("id",v+"-tooltip-text");function I(t){t.on("mouseover",function(t,e){var a=P.datum().total,n=a?Math.round(100*e.data.value/a):NaN;e.data.value?(P.transition().duration(300).style("opacity",1),r.text(e.data.label+(a?": "+e.data.value+" ("+n+"%)":""))):P.transition().duration(300).style("opacity",0),P.each(function(t){t.height=this.getBoundingClientRect().height})}).on("mouseout",function(){P.transition().duration(300).style("opacity",0)}).on("mousemove",t=>{const{pageX:e,pageY:a}=t;P.style("left",e+"px").style("top",function(t){return a-t.height-2+"px"})})}const H=x.append("g");if(I(H),H.append("circle").attr("r",R).style("opacity",0),A.total.enabled){const n=H.append("text").attr("class","total-text");n.append("tspan").attr("class","total-value").style("font-size",.6*R+"px"),n.append("tspan").attr("x","0").attr("dy",.5*R).text(void 0!==A.total.label?A.total.label:"Total")}const O=e.append("defs");this.data=function(t){let l=$.extend(!0,[],t);const d=[],e=l.reduce(function(t,e){return t+(e.value||0)},0),a=(P.datum({total:e}),H.datum({data:{label:void 0!==A.total.label?A.total.label:"Total",value:e}}),A.total.enabled&&H.select(".total-value").text(d3.format(".3~s")(e)),l.unshift({label:"undefined",color:A.gradient.enabled?"steelblue":"#ecf1f5",value:0===e?1:0}),d3.scaleOrdinal(d3.schemeSet1));function n(t,e){return void 0!==t&&void 0!==t.color?t.color:a(e)}function s(t,e,a=e){return d3.arc().innerRadius(e).outerRadius(a).centroid(t)}function c(t){return d3.interpolate(y[t.data.label],t)}function u(t){var e=w-.1;return Math.max(-e,Math.min(e,t))}function r(r,i){m[r.data.label].newAngle=function(){var t=u(d[i].y);let e=Math.sqrt(Math.pow(w,2)-Math.pow(t,2)),a=((r.endAngle+r.startAngle)/2>Math.PI&&(e*=-1),Math.PI/2-Math.atan2(-t,e));return a<0&&(a+=2*Math.PI),{startAngle:a,endAngle:a}}();const o=d3.interpolate(m[r.data.label].currentAngle,m[r.data.label].newAngle);return function(t){var e=s(o(t),w),[a,n]=e,l=0<a?{dx:5,textAnchor:"start"}:{dx:-5,textAnchor:"end"};return d3.select(x.selectAll(".link").nodes()[i]).datum([s(c(r)(t),M),s(c(r)(t),M+5),[a,n],[a+l.dx,n]]).attr("d",z),d3.select(x.selectAll(".outer-label").nodes()[i]).attr("dx",l.dx).style("text-anchor",l.textAnchor),"translate("+e+")"}}t=d3.transition().duration(A.duration);if(A.gradient.enabled){const g=O.selectAll("radialGradient").data(l,function(t){return t.label}),h=g.enter().append("radialGradient").attr("gradientUnits","userSpaceOnUse").attr("cx",0).attr("cy",0).attr("r","120%").attr("id",function(t,e){return v+"-grad"+e});h.append("stop").attr("class","grad-stop-0").style("stop-color",n),h.append("stop").attr("class","grad-stop-1").attr("offset",A.gradient.percentage+"%"),O.selectAll("radialGradient").select(".grad-stop-0").transition(t).style("stop-color",n)}function i(t){return t.data.label}const o=d3.pie().sort(null).value(function(t){return t.value}),p=x.selectAll(".slice-g").data(o(l),i),f=p.enter().append("g").attr("class","slice-g");if(I(f),f.append("path").attr("id",function(t,e){return v+"-slice"+e}).attr("class","slice").attr("fill",function(t,e){return A.gradient.enabled?"url(#"+v+"-grad"+e+")":n(t.data,e)}),p.exit().each(function(t,e){l[e]={value:0,label:t.data.label}}),o(l).forEach(function(t,e){void 0===y[t.data.label]&&(e=e?y[o(l)[e-1].data.label].endAngle:0,y[t.data.label]={startAngle:e,endAngle:e})}),x.selectAll(".slice").data(o(l),i).transition(t).attrTween("d",function(e){return function(t){return d3.arc().padAngle(A.padAngle).cornerRadius(A.cornerRadius).innerRadius(R).outerRadius(M)(c(e)(t))}}).end().then(function(){l=l.filter(function(t,e){return 0===e||t.value}),O.selectAll("radialGradient").data(l,function(t){return t.label}).exit().remove(),x.selectAll(".slice-g").data(o(l),i).exit().each(function(t){delete y[t.data.label],delete m[t.data.label]}).remove();for(const t of o(l))y[t.data.label]=t,"none"!==A.labels.outer.format&&(m[t.data.label].currentAngle=m[t.data.label].newAngle)}).catch(function(t){console.warn(t)}),f.append("text").attr("class","inner-label").attr("dy",".35em"),x.selectAll(".inner-label").data(o(l),i).text(function(t){return"undefined"===t.data.label?"undefined":Math.round(100*t.data.value/e)+"%"}).transition(t).attrTween("opacity",function(e){return e.data.value?function(t){t=c(e)(t);return 100*(t.endAngle-t.startAngle)/(2*Math.PI)<A.labels.inner.hideWhenLessThanPercentage?0:1}:function(){return 0}}).attrTween("transform",function(e){return function(t){return"translate("+s(c(e)(t),R*(1-A.labels.inner.offset),M*(1+A.labels.inner.offset))+")"}}),"none"!==A.labels.outer.format){o(l).forEach(function(t,e){void 0===m[t.data.label]&&(e=e?y[o(l)[e-1].data.label].endAngle:0,m[t.data.label]={currentAngle:{startAngle:e,endAngle:e},newAngle:{startAngle:e,endAngle:e}});let a=0;var[e,n]=s(t,w);t.data.value&&(a=0<=e?A.labels.outer.collideHeight:-A.labels.outer.collideHeight),d.push({fx:a,y:n})}),d3.forceSimulation(d).alphaMin(.5).force("collide",d3.forceCollide(A.labels.outer.collideHeight/2)).force("boundY",function(){for(const t of d)t.y=u(t.y)}).tick(30);const b=f.append("g").attr("class","outer-label-g");b.append("text").attr("class","outer-label").attr("dy",".35em").text(i),b.append("path").attr("class","link"),x.selectAll(".outer-label-g").data(o(l),i).transition(t).style("opacity",function(t,e){return e&&t.value?1:0}).each(function(t,e){$(this).children(".link").attr("stroke",n(t.data,e))}),x.selectAll(".outer-label").data(o(l),i).transition(t).attrTween("transform",r)}}}
\ No newline at end of file
+function D3Pie(g,t){let h=$.extend(!0,{canvasPadding:5,cornerRadius:3,duration:1250,gradient:{enabled:!0,percentage:100},labels:{inner:{hideWhenLessThanPercentage:4,offset:.15},outer:{collideHeight:13,format:"label",pieDistance:30}},padAngle:.01,pieCenterOffset:{x:0,y:0},size:{canvasHeight:400,canvasWidth:600,pieInnerRadius:"20%",pieOuterRadius:"85%"},title:"",total:{enabled:!1}},t);this.destroy=function(){d3.selectAll("#"+g+" svg, #"+g+"-tooltip").remove()},this.destroy();var e,t=d3.select("#"+g).append("svg").attr("class","d3pie").attr("width",h.size.canvasWidth).attr("height",h.size.canvasHeight);let l=0,b=(""!==h.title&&((e=t.append("svg:text").attr("class","chart-title").attr("x",h.size.canvasWidth/2)).append("tspan").text(h.title+" "),l=e.node().getBBox().height,e.attr("y",l+h.canvasPadding)),t.append("g").attr("transform","translate("+(h.size.canvasWidth/2+h.pieCenterOffset.x)+","+(h.size.canvasHeight/2+l/2+h.pieCenterOffset.y)+")")),v={},A={},{outerRadius:x,innerRadius:y}=(()=>{function t(t,e){var a;return/%/u.test(t)?(a=Math.max(0,Math.min(99,parseInt(t.replace(/[\D]/u,""),10)))/100,Math.floor(e*a)):parseInt(t,10)}var e=h.size.canvasWidth-2*h.canvasPadding,a=h.size.canvasHeight-2*h.canvasPadding-l;let n=Math.min(e,a)/2;return"none"!==h.labels.outer.format&&(e=parseInt(h.labels.outer.pieDistance,10),n>e)&&(n-=e),{outerRadius:a=t(h.size.pieOuterRadius,n),innerRadius:t(h.size.pieInnerRadius,a)}})(),m=x+h.labels.outer.pieDistance,M=d3.line().curve(d3.curveCatmullRomOpen),R=d3.select("body").append("div").attr("id",g+"-tooltip").attr("class","d3pie-tooltip"),r=R.append("span").attr("id",g+"-tooltip-text");function w(t){t.on("mouseover",function(t,e){var a=R.datum().total,n=a?Math.round(100*e.data.value/a):NaN;e.data.value?(R.transition().duration(300).style("opacity",1),r.text(e.data.label+(a?": "+e.data.value+" ("+n+"%)":""))):R.transition().duration(300).style("opacity",0),R.each(function(t){t.height=this.getBoundingClientRect().height})}).on("mouseout",function(){R.transition().duration(300).style("opacity",0)}).on("mousemove",t=>{let{pageX:e,pageY:a}=t;R.style("left",e+"px").style("top",function(t){return a-t.height-2+"px"})})}let z=b.append("g"),P=(w(z),z.append("circle").attr("r",y).style("opacity",0),h.total.enabled&&((e=z.append("text").attr("class","total-text")).append("tspan").attr("class","total-value").style("font-size",.6*y+"px"),e.append("tspan").attr("x","0").attr("dy",.5*y).text(void 0!==h.total.label?h.total.label:"Total")),t.append("defs"));this.data=function(t){let l=$.extend(!0,[],t),s=[],e=l.reduce(function(t,e){return t+(e.value||0)},0),a=(R.datum({total:e}),z.datum({data:{label:void 0!==h.total.label?h.total.label:"Total",value:e}}),h.total.enabled&&z.select(".total-value").text(d3.format(".3~s")(e)),l.unshift({label:"undefined",color:h.gradient.enabled?"steelblue":"#ecf1f5",value:0===e?1:0}),d3.scaleOrdinal(d3.schemeSet1));function n(t,e){return void 0!==t&&void 0!==t.color?t.color:a(e)}function o(t,e,a=e){return d3.arc().innerRadius(e).outerRadius(a).centroid(t)}function c(t){return d3.interpolate(v[t.data.label],t)}function u(t){var e=m-.1;return Math.max(-e,Math.min(e,t))}function r(r,i){A[r.data.label].newAngle=(()=>{var t=u(s[i].y);let e=Math.sqrt(Math.pow(m,2)-Math.pow(t,2)),a=((r.endAngle+r.startAngle)/2>Math.PI&&(e*=-1),Math.PI/2-Math.atan2(-t,e));return a<0&&(a+=2*Math.PI),{startAngle:a,endAngle:a}})();let d=d3.interpolate(A[r.data.label].currentAngle,A[r.data.label].newAngle);return function(t){var e=o(d(t),m),[a,n]=e,l=0<a?{dx:5,textAnchor:"start"}:{dx:-5,textAnchor:"end"};return d3.select(b.selectAll(".link").nodes()[i]).datum([o(c(r)(t),x),o(c(r)(t),x+5),[a,n],[a+l.dx,n]]).attr("d",M),d3.select(b.selectAll(".outer-label").nodes()[i]).attr("dx",l.dx).style("text-anchor",l.textAnchor),"translate("+e+")"}}t=d3.transition().duration(h.duration);function i(t){return t.data.label}h.gradient.enabled&&((p=P.selectAll("radialGradient").data(l,function(t){return t.label}).enter().append("radialGradient").attr("gradientUnits","userSpaceOnUse").attr("cx",0).attr("cy",0).attr("r","120%").attr("id",function(t,e){return g+"-grad"+e})).append("stop").attr("class","grad-stop-0").style("stop-color",n),p.append("stop").attr("class","grad-stop-1").attr("offset",h.gradient.percentage+"%"),P.selectAll("radialGradient").select(".grad-stop-0").transition(t).style("stop-color",n));let d=d3.pie().sort(null).value(function(t){return t.value});var p=b.selectAll(".slice-g").data(d(l),i),f=p.enter().append("g").attr("class","slice-g");w(f),f.append("path").attr("id",function(t,e){return g+"-slice"+e}).attr("class","slice").attr("fill",function(t,e){return h.gradient.enabled?"url(#"+g+"-grad"+e+")":n(t.data,e)}),p.exit().each(function(t,e){l[e]={value:0,label:t.data.label}}),d(l).forEach(function(t,e){void 0===v[t.data.label]&&(e=e?v[d(l)[e-1].data.label].endAngle:0,v[t.data.label]={startAngle:e,endAngle:e})}),b.selectAll(".slice").data(d(l),i).transition(t).attrTween("d",function(e){return function(t){return d3.arc().padAngle(h.padAngle).cornerRadius(h.cornerRadius).innerRadius(y).outerRadius(x)(c(e)(t))}}).end().then(function(){l=l.filter(function(t,e){return 0===e||t.value}),P.selectAll("radialGradient").data(l,function(t){return t.label}).exit().remove(),b.selectAll(".slice-g").data(d(l),i).exit().each(function(t){delete v[t.data.label],delete A[t.data.label]}).remove();for(var t of d(l))v[t.data.label]=t,"none"!==h.labels.outer.format&&(A[t.data.label].currentAngle=A[t.data.label].newAngle);b.selectAll(".slice-g").classed("first-slice",!1);var e=b.select(".slice-g");e.empty()||e.classed("first-slice",!0)}).catch(function(t){console.warn(t)}),f.append("text").attr("class","inner-label").attr("dy",".35em"),b.selectAll(".inner-label").data(d(l),i).text(function(t){return"undefined"===t.data.label?"undefined":Math.round(100*t.data.value/e)+"%"}).transition(t).attrTween("opacity",function(e){return e.data.value?function(t){t=c(e)(t);return 100*(t.endAngle-t.startAngle)/(2*Math.PI)<h.labels.inner.hideWhenLessThanPercentage?0:1}:function(){return 0}}).attrTween("transform",function(e){return function(t){return"translate("+o(c(e)(t),y*(1-h.labels.inner.offset),x*(1+h.labels.inner.offset))+")"}}),"none"!==h.labels.outer.format&&(d(l).forEach(function(t,e){void 0===A[t.data.label]&&(e=e?v[d(l)[e-1].data.label].endAngle:0,A[t.data.label]={currentAngle:{startAngle:e,endAngle:e},newAngle:{startAngle:e,endAngle:e}});let a=0;var[e,n]=o(t,m);t.data.value&&(a=0<=e?h.labels.outer.collideHeight:-h.labels.outer.collideHeight),s.push({fx:a,y:n})}),d3.forceSimulation(s).alphaMin(.5).force("collide",d3.forceCollide(h.labels.outer.collideHeight/2)).force("boundY",function(){for(var t of s)t.y=u(t.y)}).tick(30),(p=f.append("g").attr("class","outer-label-g")).append("text").attr("class","outer-label").attr("dy",".35em").text(i),p.append("path").attr("class","link"),b.selectAll(".outer-label-g").data(d(l),i).transition(t).style("opacity",function(t,e){return e&&t.value?1:0}).each(function(t,e){$(this).children(".link").attr("stroke",n(t.data,e))}),b.selectAll(".outer-label").data(d(l),i).transition(t).attrTween("transform",r))}}
\ No newline at end of file