text: !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-polygon"),require("d3-weighted-voronoi")):"function"==typeof define&&define.amd?define(["exports","d3-polygon","d3-weighted-voronoi"],n):n(t.d3=t.d3||{},t.d3,t.d3)}(this,function(t,n,e){"use strict";function r(){this.growthChangesLength=l,this.totalAvailableArea=NaN,this.lastAreaError=NaN,this.lastGrowth=NaN,this.growthChanges=[],this.growthChangeWeights=o(this.growthChangesLength),this.growthChangeWeightsSum=a(this.growthChangeWeights)}function i(t,n){return t>=n?1:-1}function o(t){for(var n=3,e=1,r=1,i=n,o=[],a=0;a<t;a++)o.push(i),i-=e,i<r&&(i=r);return o}function a(t){for(var n=0,e=0;e<t.length;e++)n+=t[e];return n}function h(){function t(t,a,g,l){var c,f,p=!1;for(r!==l.clip()&&(r=l.clip(),i=l.extent(),p=!0),p&&e(),c=o+s*l.prng()(),f=h+u*l.prng()();!n.polygonContains(r,[c,f]);)c=o+s*l.prng()(),f=h+u*l.prng()();return[c,f]}function e(){o=i[0][0],a=i[1][0],h=i[0][1],g=i[1][1],s=a-o,u=g-h}var r,i,o,a,h,g,s,u;return t}function g(){function t(t,n,r,i){var h=!1;return o!==i.clip()&&(o=i.clip(),h|=!0),a!==r&&(a=r,h|=!0),h&&e(),[g[0]+Math.cos(l+n*u)*s+.001*(i.prng()()-.5),g[1]+Math.sin(l+n*u)*s+.001*(i.prng()()-.5)]}function e(){g=n.polygonCentroid(o),s=r(g,o)/2,h=a.length,u=2*Math.PI/h}function r(t,n){for(var e,r=1/0,o=0,a=n[n.length-1],h=n[o];o<n.length;)e=i(t,a,h),e<r&&(r=e),o++,a=h,h=n[o];return r}function i(t,n,e){var r=t[0],i=t[1],o=n[0],a=n[1],h=e[0],g=e[1],s=r-o,u=i-a,l=h-o,c=g-a,f=s*l+u*c,p=l*l+c*c,w=-1;0!=p&&(w=f/p);var v,d;w<0?(v=o,d=a):w>1?(v=h,d=g):(v=o+w*l,d=a+w*c);var C=r-v,y=i-d;return Math.sqrt(C*C+y*y)}var o,a,h,g,s,u,l=0;return t.startAngle=function(n){return arguments.length?(l=n,t):l},t}function s(){function t(t,n,o,a){var g=!1;return r!==a.clip()&&(r=a.clip(),g|=!0),i!==o&&(i=o,g|=!0),g&&e(),h}function e(){o=i.length,a=n.polygonArea(r),h=a/o/2}var r,i,o,a,h;return t}function u(){function t(t){return Math.pow(t,2)}function i(n,e){return t(e.x-n.x)+t(e.y-n.y)}function o(t){p(),d=t.length,C=Math.abs(n.polygonArea(S.clip())),y=j*C,q.clear().totalArea(C);var e,r=0,i=w(t),o=!1;for(R(i,r);!(o||r>=E);)i=a(i,q.ratio()),r++,e=f(i),q.add(e),o=e<y,R(i,r);return{polygons:i,iterationCount:r,convergenceRatio:e/C}}function a(t,n){var e;return g(t,n),e=t.map(function(t){return t.site.originalObject}),t=S(e),t.length<d&&console.log("at least 1 site has no area, which is not supposed to arise"),u(t,n),e=t.map(function(t){return t.site.originalObject}),t=S(e),t.length<d&&console.log("at least 1 site has no area, which is not supposed to arise"),t}function g(t,e){var r,i,o,a,h,g,s,u=[],l=.5;r=l*e,i=1-r;for(var c=0;c<d;c++)o=t[c],a=o.site.originalObject,h=n.polygonCentroid(o),g=h[0]-a.x,s=h[1]-a.y,g*=i,s*=i,a.x+=g,a.y+=s,u.push(a);A(u)}function u(t,e){var r,i,o,a,h,g,s=[],u=.1;r=u*e;for(var l=0;l<d;l++)i=t[l],o=i.site.originalObject,a=n.polygonArea(i),h=o.targetedArea/a,h=Math.max(h,1-u+r),h=Math.min(h,1+u-r),g=o.weight*h,g=Math.max(g,L),o.weight=g,s.push(o);A(s)}function l(t){var n,e,r,o,a,h,g,s=0;do{n=!1;for(var u=0;u<d;u++){e=t[u];for(var l=u+1;l<d;l++)if(r=t[l],e.weight>r.weight?(o=e,a=r):(o=r,a=e),h=i(e,r),h<o.weight-a.weight){g=h+a.weight/2,g=Math.max(g,L),o.weight=g,n=!0,s++;break}if(n)break}}while(n)}function c(t){var n,e,r,o,a,h,g,s=0;do{n=!1;for(var u=0;u<d;u++){e=t[u];for(var l=u+1;l<d;l++)if(r=t[l],e.weight>r.weight?(o=e,a=r):(o=r,a=e),h=i(e,r),h<o.weight-a.weight){g=o.weight-a.weight-h,a.weight+=g+L,n=!0,s++;break}if(n)break}}while(n)}function f(t){for(var e,r,i,o=0,a=0;a<d;a++)e=t[a],r=e.site.originalObject,i=n.polygonArea(e),o+=Math.abs(r.targetedArea-i);return o}function p(){switch(z){case 0:A=l;break;case 1:A=c;break;default:console.log("Variant of 'handleOverweighted' is unknown")}}function w(t){var n,e,r=t.reduce(function(t,n){return Math.max(t,P(n))},-(1/0)),i=r*O;return n=t.map(function(t,n,e){return{index:n,weight:Math.max(P(t),i),initialPosition:I(t,n,e,o),initialWeight:F(t,n,e,o),originalData:t}}),e=v(n),S(e)}function v(t){var e,r=t.reduce(function(t,n){return t+=n.weight},0);return t.map(function(t,i,a){return e=t.initialPosition,n.polygonContains(S.clip(),e)||(e=k(t,i,a,o)),{index:t.index,targetedArea:C*t.weight/r,data:t,x:e[0],y:e[1],weight:t.initialWeight}})}var d,C,y,A,b=.01,m=50,M=.01,x=Math.random,N=h(),W=s(),k=h(),L=1,P=function(t){return t.weight},j=b,E=m,O=M,G=x,I=N,F=W,R=function(t,n){return!0},S=e.weightedVoronoi(),q=new r,z=1;return o.weight=function(t){return arguments.length?(P=t,o):P},o.convergenceRatio=function(t){return arguments.length?(j=t,o):j},o.maxIterationCount=function(t){return arguments.length?(E=t,o):E},o.minWeightRatio=function(t){return arguments.length?(O=t,o):O},o.tick=function(t){return arguments.length?(R=t,o):R},o.clip=function(t){return arguments.length?(S.clip(t),o):S.clip()},o.extent=function(t){return arguments.length?(S.extent(t),o):S.extent()},o.size=function(t){return arguments.length?(S.size(t),o):S.size()},o.prng=function(t){return arguments.length?(G=t,o):G},o.initialPosition=function(t){return arguments.length?(I=t,o):I},o.initialWeight=function(t){return arguments.length?(F=t,o):F},o}var l=10;r.prototype.reset=function(){return this.lastAreaError=NaN,this.lastGrowth=NaN,this.growthChanges=[],this.growthChangesLength=l,this.growthChangeWeights=o(this.growthChangesLength),this.growthChangeWeightsSum=a(this.growthChangeWeights),this.totalAvailableArea=NaN,this},r.prototype.clear=function(){return this.lastAreaError=NaN,this.lastGrowth=NaN,this.growthChanges=[],this},r.prototype.length=function(t){return arguments.length?(parseInt(t)>0?(this.growthChangesLength=Math.floor(parseInt(t)),this.growthChangeWeights=o(this.growthChangesLength),this.growthChangeWeightsSum=a(this.growthChangeWeights)):console.warn("FlickeringMitigation.length() accepts only positive integers; unable to handle "+t),this):this.growthChangesLength},r.prototype.totalArea=function(t){return arguments.length?(parseFloat(t)>0?this.totalAvailableArea=parseFloat(t):console.warn("FlickeringMitigation.totalArea() accepts only positive numbers; unable to handle "+t),this):this.totalAvailableArea},r.prototype.add=function(t){var n,e;return n=this.lastAreaError,this.lastAreaError=t,isNaN(n)||(e=this.lastGrowth,this.lastGrowth=i(this.lastAreaError,n)),isNaN(e)||this.growthChanges.unshift(this.lastGrowth!=e),this.growthChanges.length>this.growthChangesLength&&this.growthChanges.pop(),this},r.prototype.ratio=function(){var t,n=0;if(this.growthChanges.length<this.growthChangesLength)return 0;if(this.lastAreaError>this.totalAvailableArea/10)return 0;for(var e=0;e<this.growthChangesLength;e++)this.growthChanges[e]&&(n+=this.growthChangeWeights[e]);return t=n/this.growthChangeWeightsSum,t>0&&console.log("flickering mitigation ratio: "+Math.floor(1e3*t)/1e3),t},t.voronoiMap=u,t.voronoiMapInitialPositionRandom=h,t.voronoiMapInitialPositionPie=g,Object.defineProperty(t,"__esModule",{value:!0})});