-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3dev.v0.min.js
1 lines (1 loc) · 1.5 KB
/
d3dev.v0.min.js
1
(function(){d3dev={version:"0.0.1"},d3dev.device=function(e){function t(e){}d3dev.device.id||(d3dev.device.id=0);var n=e||"d3-device-"+d3dev.device.id++;return t},d3dev.stats={},d3dev.stats.summary=function(){function e(e){return e=t(e),isNaN(e)||(n++,s+=e,o+=e*e,e<r&&(r=e),e>i&&(i=e)),e}var t=function(e){return e},n=0,r=Infinity,i=-Infinity,s=0,o=0;return e.value=function(n){return arguments.length?(t=n,e):t},e.max=function(){return i},e.min=function(){return r},e.range=function(){return[r,i]},e.width=function(){return i-r},e.avg=function(){return s/n},e.avg2=function(){return o/n},e.sum=function(){return s},e.sum2=function(){return o},e.n=function(){return n},e.var=function(){var t=e.avg(),r=e.sum2()/(n-1);return r-n*t*t/(n-1)},e.sd=function(){return Math.sqrt(e.var())},e},d3dev.stats.fit=function(){function e(e){var s=t(e)*n(e);return isNaN(s)||(i++,r+=s),s}var t=summary().value(function(e){return e[0]}),n=summary().value(function(e){return e[1]}),r=0,i=0;e.fit=function(){var e=r/i,s=(e-t.avg()*n.avg())/(t.avg2()-t.avg()*t.avg());return[n.avg()-s*t.avg()]},e.x=function(n){return arguments.length?(t=n,e):t},e.y=function(t){return arguments.length?(n=t,e):n}},d3dev.stats.nclass=function(e){function t(e){return n(e)}methods={sturges:function(e){return Math.ceil(Math.log(e.n())/Math.log(2)+1)},scott:function(e){var t=3.5*e.sd()*Math.pow(e.n(),-1/3);return t>0?Math.ceil(e.width()/t):1}};var n=methods[e||"sturges"];return t.method=function(e){return arguments.length?(typeof e=="string"?n=methods[e]:n=e,t):n},t}})();