echarts-stat
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -57,9 +57,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
module.exports = __webpack_require__(1); | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { | ||
@@ -69,6 +62,6 @@ | ||
clustering: __webpack_require__(2), | ||
regression: __webpack_require__(6), | ||
statistics: __webpack_require__(7), | ||
histogram: __webpack_require__(16) | ||
clustering: __webpack_require__(1), | ||
regression: __webpack_require__(5), | ||
statistics: __webpack_require__(6), | ||
histogram: __webpack_require__(15) | ||
@@ -80,3 +73,3 @@ }; | ||
/***/ }), | ||
/* 2 */ | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -86,4 +79,5 @@ | ||
var dataPreprocess = __webpack_require__(3); | ||
var array = __webpack_require__(4); | ||
var dataProcess = __webpack_require__(2); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
var array = __webpack_require__(3); | ||
var arraySize = array.size; | ||
@@ -178,3 +172,3 @@ var sumOfColumn = array.sumOfColumn; | ||
* @param {Array} data two-dimension array. | ||
* @param {[type]} k the number of clusters in a dataset | ||
* @param {[type]} k the number of clusters in a dataset. It has to be greater than 1. | ||
* @param {boolean} stepByStep | ||
@@ -184,3 +178,5 @@ * @return {} | ||
function hierarchicalKMeans(data, k, stepByStep) { | ||
if (k < 2 ) { | ||
return; | ||
} | ||
var dataSet = dataPreprocess(data); | ||
@@ -358,3 +354,3 @@ var size = arraySize(dataSet); | ||
/***/ }), | ||
/* 3 */ | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -364,6 +360,6 @@ | ||
var array = __webpack_require__(4); | ||
var array = __webpack_require__(3); | ||
var isArray = array.isArray; | ||
var size = array.size; | ||
var number = __webpack_require__(5); | ||
var number = __webpack_require__(4); | ||
var isNumber = number.isNumber; | ||
@@ -415,7 +411,22 @@ | ||
return dataPreprocess; | ||
/** | ||
* @param {string|number} val | ||
* @return {number} | ||
*/ | ||
function getPrecision(val) { | ||
var str = val.toString(); | ||
// scientific notation is not considered | ||
var dotIndex = str.indexOf('.'); | ||
return dotIndex < 0 ? 0 : str.length - 1 - dotIndex; | ||
} | ||
return { | ||
dataPreprocess: dataPreprocess, | ||
getPrecision: getPrecision | ||
}; | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 4 */ | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -576,3 +587,3 @@ | ||
/***/ }), | ||
/* 5 */ | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -589,3 +600,3 @@ | ||
value = (value === null ? NaN : +value); | ||
value = value === null ? NaN : +value; | ||
return typeof value === 'number' && !isNaN(value); | ||
@@ -611,3 +622,3 @@ } | ||
/***/ }), | ||
/* 6 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -617,3 +628,4 @@ | ||
var dataPreprocess = __webpack_require__(3); | ||
var dataProcess = __webpack_require__(2); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
@@ -919,3 +931,3 @@ var regreMethods = { | ||
/***/ }), | ||
/* 7 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -927,10 +939,10 @@ | ||
statistics.max = __webpack_require__(8); | ||
statistics.deviation = __webpack_require__(9); | ||
statistics.mean = __webpack_require__(11); | ||
statistics.median = __webpack_require__(13); | ||
statistics.min = __webpack_require__(15); | ||
statistics.max = __webpack_require__(14); | ||
statistics.max = __webpack_require__(10); | ||
statistics.sum = __webpack_require__(12); | ||
statistics.max = __webpack_require__(7); | ||
statistics.deviation = __webpack_require__(8); | ||
statistics.mean = __webpack_require__(10); | ||
statistics.median = __webpack_require__(12); | ||
statistics.min = __webpack_require__(14); | ||
statistics.quantile = __webpack_require__(13); | ||
statistics.sampleVariance = __webpack_require__(9); | ||
statistics.sum = __webpack_require__(11); | ||
@@ -942,3 +954,3 @@ return statistics; | ||
/***/ }), | ||
/* 8 */ | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -948,3 +960,3 @@ | ||
var number = __webpack_require__(5); | ||
var number = __webpack_require__(4); | ||
var isNumber = number.isNumber; | ||
@@ -974,3 +986,3 @@ | ||
/***/ }), | ||
/* 9 */ | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -980,3 +992,3 @@ | ||
var variance = __webpack_require__(10); | ||
var variance = __webpack_require__(9); | ||
@@ -997,3 +1009,3 @@ /** | ||
/***/ }), | ||
/* 10 */ | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1003,5 +1015,5 @@ | ||
var number = __webpack_require__(5); | ||
var number = __webpack_require__(4); | ||
var isNumber = number.isNumber; | ||
var mean = __webpack_require__(11); | ||
var mean = __webpack_require__(10); | ||
@@ -1031,3 +1043,3 @@ /** | ||
} | ||
return sum / data.length - 1; | ||
return sum / (data.length - 1); | ||
} | ||
@@ -1040,4 +1052,5 @@ } | ||
/***/ }), | ||
/* 11 */ | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1047,3 +1060,3 @@ | ||
var sum = __webpack_require__(12); | ||
var sum = __webpack_require__(11); | ||
@@ -1074,3 +1087,3 @@ /** | ||
/***/ }), | ||
/* 12 */ | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1080,3 +1093,3 @@ | ||
var number = __webpack_require__(5); | ||
var number = __webpack_require__(4); | ||
var isNumber = number.isNumber; | ||
@@ -1111,3 +1124,3 @@ | ||
/***/ }), | ||
/* 13 */ | ||
/* 12 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1117,3 +1130,3 @@ | ||
var quantile = __webpack_require__(14); | ||
var quantile = __webpack_require__(13); | ||
@@ -1135,3 +1148,3 @@ /** | ||
/***/ }), | ||
/* 14 */ | ||
/* 13 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1172,3 +1185,3 @@ | ||
/***/ }), | ||
/* 15 */ | ||
/* 14 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1178,3 +1191,3 @@ | ||
var number = __webpack_require__(5); | ||
var number = __webpack_require__(4); | ||
var isNumber = number.isNumber; | ||
@@ -1204,3 +1217,3 @@ | ||
/***/ }), | ||
/* 16 */ | ||
/* 15 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1210,13 +1223,15 @@ | ||
var max = __webpack_require__(8); | ||
var min = __webpack_require__(15); | ||
var quantile = __webpack_require__(14); | ||
var deviation = __webpack_require__(9); | ||
var dataPreprocess = __webpack_require__(3); | ||
var array = __webpack_require__(4); | ||
var max = __webpack_require__(7); | ||
var min = __webpack_require__(14); | ||
var quantile = __webpack_require__(13); | ||
var deviation = __webpack_require__(8); | ||
var dataProcess = __webpack_require__(2); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
var getPrecision = dataProcess.getPrecision; | ||
var array = __webpack_require__(3); | ||
var ascending = array.ascending; | ||
var map = array.map; | ||
var range = __webpack_require__(17); | ||
var range = __webpack_require__(16); | ||
var bisect = array.bisect; | ||
var tickStep = __webpack_require__(18); | ||
var tickStep = __webpack_require__(17); | ||
@@ -1232,10 +1247,6 @@ /** | ||
if (threshold == null) { | ||
threshold = thresholdMethod.squareRoot; | ||
} | ||
else { | ||
threshold = thresholdMethod[threshold]; | ||
} | ||
@@ -1245,9 +1256,14 @@ var values = dataPreprocess(data); | ||
var minValue = min(values); | ||
var binsNumber = threshold(values, minValue, maxValue); | ||
var step = tickStep(minValue, maxValue, binsNumber); | ||
var precision = -Math.floor(Math.log(Math.abs(maxValue - minValue) / binsNumber) / Math.LN10); | ||
// return the xAxis coordinate for each bins, except the end point of the value | ||
var rangeArray = range(Math.ceil(minValue / step) * step, Math.floor(maxValue / step) * step, step); | ||
var rangeArray = range( | ||
// use function toFixed() to avoid data like '0.700000001' | ||
+((Math.ceil(minValue / step) * step).toFixed(precision)), | ||
+((Math.floor(maxValue / step) * step).toFixed(precision)), | ||
step, | ||
precision | ||
); | ||
@@ -1261,3 +1277,3 @@ var len = rangeArray.length; | ||
bins[i].sample = []; | ||
bins[i].x0 = i > 0 // 不要数组直接挂属性,改成Object | ||
bins[i].x0 = i > 0 | ||
? rangeArray[i - 1] | ||
@@ -1281,12 +1297,17 @@ : (rangeArray[i] - minValue) === step | ||
var data = map(bins, function (bin) { | ||
return [(bin.x0 + bin.x1) / 2, bin.sample.length]; | ||
// use function toFixed() to avoid data like '6.5666638489' | ||
return [+((bin.x0 + bin.x1) / 2).toFixed(precision), bin.sample.length]; | ||
}); | ||
var customData = map(bins, function (bin) { | ||
return [bin.x0, bin.x1, bin.sample.length]; | ||
}); | ||
return { | ||
bins: bins, | ||
data: data | ||
data: data, | ||
customData: customData | ||
}; | ||
} | ||
/** | ||
@@ -1333,3 +1354,3 @@ * Four kinds of threshold methods used to | ||
/***/ }), | ||
/* 17 */ | ||
/* 16 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1339,10 +1360,15 @@ | ||
var dataProcess = __webpack_require__(2); | ||
var getPrecision = dataProcess.getPrecision; | ||
/** | ||
* Computing range array | ||
* Computing range array. | ||
* Adding param precision to fix range value, avoiding range[i] = 0.7000000001. | ||
* @param {number} start | ||
* @param {number} stop | ||
* @param {number} end | ||
* @param {number} step | ||
* @param {number} precision | ||
* @return {Array.<number>} | ||
*/ | ||
return function (start, stop, step) { | ||
return function (start, end, step, precision) { | ||
@@ -1352,3 +1378,3 @@ var len = arguments.length; | ||
if (len < 2) { | ||
stop = start; | ||
end = start; | ||
start = 0; | ||
@@ -1360,11 +1386,14 @@ step = 1; | ||
} | ||
else { | ||
else if (len < 4) { | ||
step = +step; | ||
precision = getPrecision(step); | ||
} | ||
else { | ||
precision = +precision; | ||
} | ||
var n = Math.ceil((stop - start) / step); | ||
var n = Math.ceil(((end - start) / step).toFixed(precision)); | ||
var range = new Array(n + 1); | ||
for (var i = 0; i < n + 1; i++) { | ||
range[i] = start + i * step; | ||
range[i] = +(start + i * step).toFixed(precision); | ||
} | ||
@@ -1377,3 +1406,3 @@ return range; | ||
/***/ }), | ||
/* 18 */ | ||
/* 17 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -1393,3 +1422,4 @@ | ||
var step0 = Math.abs(stop - start) / count; | ||
var step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)); | ||
var precision = Math.floor(Math.log(step0) / Math.LN10); | ||
var step1 = Math.pow(10, precision); | ||
var error = step0 / step1; | ||
@@ -1406,3 +1436,3 @@ | ||
} | ||
return stop >= start ? step1 : -step1; | ||
return +((stop >= start ? step1 : -step1).toFixed(-precision)); | ||
@@ -1409,0 +1439,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.ecStat=n():r.ecStat=n()}(this,function(){return function(r){function n(e){if(t[e])return t[e].exports;var o=t[e]={exports:{},id:e,loaded:!1};return r[e].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=r,n.c=t,n.p="",n(0)}([function(r,n,t){r.exports=t(12)},function(r,n,t){var e;e=function(r){function n(r){return r=null===r?NaN:+r,"number"==typeof r&&!isNaN(r)}function t(r){return isFinite(r)&&r===Math.round(r)}return{isNumber:n,isInteger:t}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return function(r,n){var t=r.length;if(!t)return 0;if(n<=0||t<2)return r[0];if(n>=1)return r[t-1];var e=(t-1)*n,o=Math.floor(e),a=r[o],u=r[o+1];return a+(u-a)*(e-o)}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){for(var n=[];t(r);)n.push(r.length),r=r[0];return n}function t(r){return"[object Array]"===l.call(r)}function e(r,n){for(var t=[],e=0;e<r;e++){t[e]=[];for(var o=0;o<n;o++)t[e][o]=0}return t}function o(r){for(var n=0,t=0;t<r.length;t++)n+=r[t];return n}function a(r,n){for(var t=0,e=0;e<r.length;e++)t+=r[e][n];return t}function u(r,n){return r>n?1:r<n?-1:r===n?0:NaN}function i(r,n,t,e){for(null==t&&(t=0),null==e&&(e=r.length);t<e;){var o=Math.floor((t+e)/2),a=u(r[o],n);if(a>0)e=o;else{if(!(a<0))return o+1;t=o+1}}return t}function f(r,n,t){if(r&&n){if(r.map&&r.map===h)return r.map(n,t);for(var e=[],o=0,a=r.length;o<a;o++)e.push(n.call(t,r[o],o,r));return e}}var l=Object.prototype.toString,s=Array.prototype,h=s.map;return{size:n,isArray:t,zeros:e,sum:o,sumOfColumn:a,ascending:u,bisect:i,map:f}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){if(!o(r))throw new Error("Invalid data type, you should input an array");var n=[],t=a(r);if(1===t.length)for(var e=0;e<t[0];e++)i(r[e])&&n.push(r[e]);else if(2===t.length)for(var e=0;e<t[0];e++){for(var u=!0,f=0;f<t[1];f++)i(r[e][f])||(u=!1);u&&n.push(r[e])}return n}var e=t(3),o=e.isArray,a=e.size,u=t(1),i=u.isNumber;return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){var n=t(9);return function(r){var t=n(r);return t?Math.sqrt(t):t}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){for(var n=-(1/0),t=0;t<r.length;t++)o(r[t])&&r[t]>n&&(n=r[t]);return n}var e=t(1),o=e.isNumber;return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){var n=r.length;return n?e(r)/r.length:0}var e=t(10);return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){for(var n=1/0,t=0;t<r.length;t++)o(r[t])&&r[t]<n&&(n=r[t]);return n}var e=t(1),o=e.isNumber;return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){var n=r.length;if(!n||n<2)return 0;if(r.length>=2){for(var t,e=a(r),u=0,i=0;i<r.length;i++)o(r[i])&&(t=r[i]-e,u+=t*t);return u/r.length-1}}var e=t(1),o=e.isNumber,a=t(7);return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){var n=r.length;if(!n)return 0;for(var t=0,e=0;e<n;e++)o(r[e])&&(t+=r[e]);return t}var e=t(1),o=e.isNumber;return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r,n){for(var t,o,i,f,s=l(r),h=c(s[0],2),v=a(r,n),p=!0;p;){p=!1;for(var d=0;d<s[0];d++){t=1/0,o=-1;for(var M=0;M<n;M++)i=u(r[d],v[M]),i<t&&(t=i,o=M);h[d][0]!==o&&(p=!0),h[d][0]=o,h[d][1]=g(t,2)}for(var d=0;d<n;d++){f=[];for(var M=0;M<h.length;M++)h[M][0]===d&&f.push(r[M]);v[d]=e(f)}}var x={centroids:v,clusterAssigned:h};return x}function e(r){for(var n,t,e=l(r),o=[],a=0;a<e[1];a++){n=0;for(var u=0;u<e[0];u++)n+=r[u][a];t=n/e[0],o.push(t)}return o}function o(r,t,o){function a(){if(E<t){y=1/0;for(var r,e,o,a=0;a<x.length;a++){b=[],w=[];for(var u=0;u<d.length;u++)d[u][0]===a?b.push(v[u]):w.push(d[u][1]);N=n(b,2),A=s(N.clusterAssigned,1),q=h(w),A+q<y&&(y=q+A,r=a,e=N.centroids,o=N.clusterAssigned)}for(var u=0;u<o.length;u++)0===o[u][0]?o[u][0]=r:1===o[u][0]&&(o[u][0]=x.length);for(x[r]=e[0],x.push(e[1]),u=0,a=0;u<d.length&&a<o.length;u++)d[u][0]===r&&(d[u][0]=o[a][0],d[u][1]=o[a++][1]);for(var i=[],u=0;u<x.length;u++){i[u]=[];for(var a=0;a<d.length;a++)d[a][0]===u&&i[u].push(v[a])}j.clusterAssment=d,j.centroids=x,j.pointsInCluster=i,E++}else j.isEnd=!0;return j}for(var f,v=i(r),p=l(v),d=c(p[0],2),M=e(v),x=[M],m=0;m<p[0];m++)f=u(v[m],M),d[m][1]=g(f,2);var y,b,w,N,A,q,E=1,j={isEnd:!1},z={next:a};if(o)return z;for(var j;!(j=z.next()).isEnd;);return j}function a(r,n){for(var t,e,o,a=l(r),u=c(n,a[1]),i=0;i<a[1];i++){t=r[0][i],e=r[0][i];for(var f=1;f<a[0];f++)r[f][i]<t&&(t=r[f][i]),r[f][i]>e&&(e=r[f][i]);o=e-t;for(var f=0;f<n;f++)u[f][i]=t+o*Math.random()}return u}function u(r,n){if(!v(r)&&!v(n))return p(g(r-n,2));for(var t=0,e=0;e<r.length;e++)t+=g(r[e]-n[e],2);return p(t)}var i=t(4),f=t(3),l=f.size,s=f.sumOfColumn,h=f.sum,c=f.zeros,v=f.isArray,p=Math.sqrt,g=Math.pow;return{kMeans:n,hierarchicalKMeans:o}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return{clustering:t(11),regression:t(14),statistics:t(15),histogram:t(13)}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r,n){n=null==n?p.squareRoot:p[n];for(var t=i(r),a=e(t),u=o(t),f=n(t,u,a),l=v(u,a,f),g=h(Math.ceil(u/l)*l,Math.floor(a/l)*l,l),d=g.length,M=new Array(d+1),x=0;x<=d;x++)M[x]={},M[x].sample=[],M[x].x0=x>0?g[x-1]:g[x]-u===l?u:g[x]-l,M[x].x1=x<d?g[x]:a-g[x-1]===l?a:g[x-1]+l;for(var x=0;x<t.length;x++)u<=t[x]&&t[x]<=a&&M[c(g,t[x],0,d)].sample.push(t[x]);var r=s(M,function(r){return[(r.x0+r.x1)/2,r.sample.length]});return{bins:M,data:r}}var e=t(6),o=t(8),a=t(2),u=t(5),i=t(4),f=t(3),l=f.ascending,s=f.map,h=t(17),c=f.bisect,v=t(18),p={squareRoot:function(r){var n=Math.ceil(Math.sqrt(r.length));return n>50?50:n},scott:function(r,n,t){return Math.ceil((t-n)/(3.5*u(r)*Math.pow(r.length,-1/3)))},freedmanDiaconis:function(r,n,t){return r.sort(l),Math.ceil((t-n)/(2*(a(r,.75)-a(r,.25))*Math.pow(r.length,-1/3)))},sturges:function(r){return Math.ceil(Math.log(r.length)/Math.LN2)+1}};return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r,n){for(var t=0;t<r.length-1;t++){for(var e=t,o=t+1;o<r.length-1;o++)Math.abs(r[t][o])>Math.abs(r[t][e])&&(e=o);for(var a=t;a<r.length;a++){var u=r[a][t];r[a][t]=r[a][e],r[a][e]=u}for(var i=t+1;i<r.length-1;i++)for(var f=r.length-1;f>=t;f--)r[f][i]-=r[f][t]/r[t][t]*r[t][i]}for(var l=new Array(n),s=r.length-1,o=r.length-2;o>=0;o--){for(var u=0,t=o+1;t<r.length-1;t++)u+=r[t][o]*l[t];l[o]=(r[s][o]-u)/r[o][o]}return l}var e=t(4),o={linear:function(r){for(var n=e(r),t=0,o=0,a=0,u=0,i=n.length,f=0;f<i;f++)t+=n[f][0],o+=n[f][1],a+=n[f][0]*n[f][1],u+=n[f][0]*n[f][0];for(var l=(i*a-t*o)/(i*u-t*t),s=o/i-l*t/i,h=[],c=0;c<n.length;c++){var v=[n[c][0],l*n[c][0]+s];h.push(v)}var p="y = "+Math.round(100*l)/100+"x + "+Math.round(100*s)/100;return{points:h,parameter:{gradient:l,intercept:s},expression:p}},linearThroughOrigin:function(r){for(var n=e(r),t=0,o=0,a=0;a<n.length;a++)t+=n[a][0]*n[a][0],o+=n[a][0]*n[a][1];for(var u=o/t,i=[],f=0;f<n.length;f++){var l=[n[f][0],n[f][0]*u];i.push(l)}var s="y = "+Math.round(100*u)/100+"x";return{points:i,parameter:{gradient:u},expression:s}},exponential:function(r){for(var n=e(r),t=0,o=0,a=0,u=0,i=0,f=0,l=0;l<n.length;l++)t+=n[l][0],o+=n[l][1],f+=n[l][0]*n[l][1],a+=n[l][0]*n[l][0]*n[l][1],u+=n[l][1]*Math.log(n[l][1]),i+=n[l][0]*n[l][1]*Math.log(n[l][1]);for(var s=o*a-f*f,h=Math.pow(Math.E,(a*u-f*i)/s),c=(o*i-f*u)/s,v=[],p=0;p<n.length;p++){var g=[n[p][0],h*Math.pow(Math.E,c*n[p][0])];v.push(g)}var d="y = "+Math.round(100*h)/100+"e^("+Math.round(100*c)/100+"x)";return{points:v,parameter:{coefficient:h,index:c},expression:d}},logarithmic:function(r){for(var n=e(r),t=0,o=0,a=0,u=0,i=0;i<n.length;i++)t+=Math.log(n[i][0]),o+=n[i][1]*Math.log(n[i][0]),a+=n[i][1],u+=Math.pow(Math.log(n[i][0]),2);for(var f=(i*o-a*t)/(i*u-t*t),l=(a-f*t)/i,s=[],h=0;h<n.length;h++){var c=[n[h][0],f*Math.log(n[h][0])+l];s.push(c)}var v="y = "+Math.round(100*l)/100+" + "+Math.round(100*f)/100+"ln(x)";return{points:s,parameter:{gradient:f,intercept:l},expression:v}},polynomial:function(r,t){var o=e(r);"undefined"==typeof t&&(t=2);for(var a=[],u=[],i=t+1,f=0;f<i;f++){for(var l=0,s=0;s<o.length;s++)l+=o[s][1]*Math.pow(o[s][0],f);u.push(l);for(var h=[],c=0;c<i;c++){for(var v=0,p=0;p<o.length;p++)v+=Math.pow(o[p][0],f+c);h.push(v)}a.push(h)}a.push(u);for(var g=n(a,i),d=[],f=0;f<o.length;f++){for(var M=0,s=0;s<g.length;s++)M+=g[s]*Math.pow(o[f][0],s);d.push([o[f][0],M])}for(var x="y = ",f=g.length-1;f>=0;f--)x+=f>1?Math.round(g[f]*Math.pow(10,f+1))/Math.pow(10,f+1)+"x^"+f+" + ":1===f?Math.round(100*g[f])/100+"x + ":Math.round(100*g[f])/100;return{points:d,parameter:g,expression:x}}},a=function(r,n,t){return o[r](n,t)};return a}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){var n={};return n.max=t(6),n.deviation=t(5),n.mean=t(7),n.median=t(16),n.min=t(8),n.max=t(2),n.max=t(9),n.sum=t(10),n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){function n(r){return e(r,.5)}var e=t(2);return n}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return function(r,n,t){var e=arguments.length;e<2?(n=r,r=0,t=1):t=e<3?1:+t;for(var o=Math.ceil((n-r)/t),a=new Array(o+1),u=0;u<o+1;u++)a[u]=r+u*t;return a}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))},function(r,n,t){var e;e=function(r){return function(r,n,t){var e=Math.abs(n-r)/t,o=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),a=e/o;return a>=Math.sqrt(50)?o*=10:a>=Math.sqrt(10)?o*=5:a>=Math.sqrt(2)&&(o*=2),n>=r?o:-o}}.call(n,t,n,r),!(void 0!==e&&(r.exports=e))}])}); | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ecStat=t():r.ecStat=t()}(this,function(){return function(r){function t(e){if(n[e])return n[e].exports;var o=n[e]={exports:{},id:e,loaded:!1};return r[e].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=r,t.c=n,t.p="",t(0)}([function(r,t,n){var e;e=function(r){return{clustering:n(11),regression:n(13),statistics:n(14),histogram:n(12)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){return r=null===r?NaN:+r,"number"==typeof r&&!isNaN(r)}function n(r){return isFinite(r)&&r===Math.round(r)}return{isNumber:t,isInteger:n}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){if(!a(r))throw new Error("Invalid data type, you should input an array");var t=[],n=u(r);if(1===n.length)for(var e=0;e<n[0];e++)f(r[e])&&t.push(r[e]);else if(2===n.length)for(var e=0;e<n[0];e++){for(var o=!0,i=0;i<n[1];i++)f(r[e][i])||(o=!1);o&&t.push(r[e])}return t}function e(r){var t=r.toString(),n=t.indexOf(".");return n<0?0:t.length-1-n}var o=n(4),a=o.isArray,u=o.size,i=n(1),f=i.isNumber;return{dataPreprocess:t,getPrecision:e}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){return function(r,t){var n=r.length;if(!n)return 0;if(t<=0||n<2)return r[0];if(t>=1)return r[n-1];var e=(n-1)*t,o=Math.floor(e),a=r[o],u=r[o+1];return a+(u-a)*(e-o)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){for(var t=[];n(r);)t.push(r.length),r=r[0];return t}function n(r){return"[object Array]"===l.call(r)}function e(r,t){for(var n=[],e=0;e<r;e++){n[e]=[];for(var o=0;o<t;o++)n[e][o]=0}return n}function o(r){for(var t=0,n=0;n<r.length;n++)t+=r[n];return t}function a(r,t){for(var n=0,e=0;e<r.length;e++)n+=r[e][t];return n}function u(r,t){return r>t?1:r<t?-1:r===t?0:NaN}function i(r,t,n,e){for(null==n&&(n=0),null==e&&(e=r.length);n<e;){var o=Math.floor((n+e)/2),a=u(r[o],t);if(a>0)e=o;else{if(!(a<0))return o+1;n=o+1}}return n}function f(r,t,n){if(r&&t){if(r.map&&r.map===c)return r.map(t,n);for(var e=[],o=0,a=r.length;o<a;o++)e.push(t.call(n,r[o],o,r));return e}}var l=Object.prototype.toString,s=Array.prototype,c=s.map;return{size:t,isArray:n,zeros:e,sum:o,sumOfColumn:a,ascending:u,bisect:i,map:f}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){var t=n(9);return function(r){var n=t(r);return n?Math.sqrt(n):n}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){for(var t=-(1/0),n=0;n<r.length;n++)o(r[n])&&r[n]>t&&(t=r[n]);return t}var e=n(1),o=e.isNumber;return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){var t=r.length;return t?e(r)/r.length:0}var e=n(10);return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){for(var t=1/0,n=0;n<r.length;n++)o(r[n])&&r[n]<t&&(t=r[n]);return t}var e=n(1),o=e.isNumber;return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){var t=r.length;if(!t||t<2)return 0;if(r.length>=2){for(var n,e=a(r),u=0,i=0;i<r.length;i++)o(r[i])&&(n=r[i]-e,u+=n*n);return u/(r.length-1)}}var e=n(1),o=e.isNumber,a=n(7);return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){var t=r.length;if(!t)return 0;for(var n=0,e=0;e<t;e++)o(r[e])&&(n+=r[e]);return n}var e=n(1),o=e.isNumber;return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r,t){for(var n,o,i,f,l=s(r),c=v(l[0],2),h=a(r,t),p=!0;p;){p=!1;for(var g=0;g<l[0];g++){n=1/0,o=-1;for(var M=0;M<t;M++)i=u(r[g],h[M]),i<n&&(n=i,o=M);c[g][0]!==o&&(p=!0),c[g][0]=o,c[g][1]=d(n,2)}for(var g=0;g<t;g++){f=[];for(var M=0;M<c.length;M++)c[M][0]===g&&f.push(r[M]);h[g]=e(f)}}var x={centroids:h,clusterAssigned:c};return x}function e(r){for(var t,n,e=s(r),o=[],a=0;a<e[1];a++){t=0;for(var u=0;u<e[0];u++)t+=r[u][a];n=t/e[0],o.push(n)}return o}function o(r,n,o){function a(){if(F<n){y=1/0;for(var r,e,o,a=0;a<x.length;a++){b=[],w=[];for(var u=0;u<g.length;u++)g[u][0]===a?b.push(l[u]):w.push(g[u][1]);N=t(b,2),A=c(N.clusterAssigned,1),q=h(w),A+q<y&&(y=q+A,r=a,e=N.centroids,o=N.clusterAssigned)}for(var u=0;u<o.length;u++)0===o[u][0]?o[u][0]=r:1===o[u][0]&&(o[u][0]=x.length);for(x[r]=e[0],x.push(e[1]),u=0,a=0;u<g.length&&a<o.length;u++)g[u][0]===r&&(g[u][0]=o[a][0],g[u][1]=o[a++][1]);for(var i=[],u=0;u<x.length;u++){i[u]=[];for(var a=0;a<g.length;a++)g[a][0]===u&&i[u].push(l[a])}P.clusterAssment=g,P.centroids=x,P.pointsInCluster=i,F++}else P.isEnd=!0;return P}if(!(n<2)){for(var i,l=f(r),p=s(l),g=v(p[0],2),M=e(l),x=[M],m=0;m<p[0];m++)i=u(l[m],M),g[m][1]=d(i,2);var y,b,w,N,A,q,F=1,P={isEnd:!1},E={next:a};if(o)return E;for(var P;!(P=E.next()).isEnd;);return P}}function a(r,t){for(var n,e,o,a=s(r),u=v(t,a[1]),i=0;i<a[1];i++){n=r[0][i],e=r[0][i];for(var f=1;f<a[0];f++)r[f][i]<n&&(n=r[f][i]),r[f][i]>e&&(e=r[f][i]);o=e-n;for(var f=0;f<t;f++)u[f][i]=n+o*Math.random()}return u}function u(r,t){if(!p(r)&&!p(t))return g(d(r-t,2));for(var n=0,e=0;e<r.length;e++)n+=d(r[e]-t[e],2);return g(n)}var i=n(2),f=i.dataPreprocess,l=n(4),s=l.size,c=l.sumOfColumn,h=l.sum,v=l.zeros,p=l.isArray,g=Math.sqrt,d=Math.pow;return{kMeans:t,hierarchicalKMeans:o}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r,t){t=null==t?g.squareRoot:g[t];for(var n=f(r),a=e(n),u=o(n),i=t(n,u,a),l=p(u,a,i),s=-Math.floor(Math.log(Math.abs(a-u)/i)/Math.LN10),d=h(+(Math.ceil(u/l)*l).toFixed(s),+(Math.floor(a/l)*l).toFixed(s),l,s),M=d.length,x=new Array(M+1),m=0;m<=M;m++)x[m]={},x[m].sample=[],x[m].x0=m>0?d[m-1]:d[m]-u===l?u:d[m]-l,x[m].x1=m<M?d[m]:a-d[m-1]===l?a:d[m-1]+l;for(var m=0;m<n.length;m++)u<=n[m]&&n[m]<=a&&x[v(d,n[m],0,M)].sample.push(n[m]);var r=c(x,function(r){return[+((r.x0+r.x1)/2).toFixed(s),r.sample.length]}),y=c(x,function(r){return[r.x0,r.x1,r.sample.length]});return{bins:x,data:r,customData:y}}var e=n(6),o=n(8),a=n(3),u=n(5),i=n(2),f=i.dataPreprocess,l=(i.getPrecision,n(4)),s=l.ascending,c=l.map,h=n(16),v=l.bisect,p=n(17),g={squareRoot:function(r){var t=Math.ceil(Math.sqrt(r.length));return t>50?50:t},scott:function(r,t,n){return Math.ceil((n-t)/(3.5*u(r)*Math.pow(r.length,-1/3)))},freedmanDiaconis:function(r,t,n){return r.sort(s),Math.ceil((n-t)/(2*(a(r,.75)-a(r,.25))*Math.pow(r.length,-1/3)))},sturges:function(r){return Math.ceil(Math.log(r.length)/Math.LN2)+1}};return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r,t){for(var n=0;n<r.length-1;n++){for(var e=n,o=n+1;o<r.length-1;o++)Math.abs(r[n][o])>Math.abs(r[n][e])&&(e=o);for(var a=n;a<r.length;a++){var u=r[a][n];r[a][n]=r[a][e],r[a][e]=u}for(var i=n+1;i<r.length-1;i++)for(var f=r.length-1;f>=n;f--)r[f][i]-=r[f][n]/r[n][n]*r[n][i]}for(var l=new Array(t),s=r.length-1,o=r.length-2;o>=0;o--){for(var u=0,n=o+1;n<r.length-1;n++)u+=r[n][o]*l[n];l[o]=(r[s][o]-u)/r[o][o]}return l}var e=n(2),o=e.dataPreprocess,a={linear:function(r){for(var t=o(r),n=0,e=0,a=0,u=0,i=t.length,f=0;f<i;f++)n+=t[f][0],e+=t[f][1],a+=t[f][0]*t[f][1],u+=t[f][0]*t[f][0];for(var l=(i*a-n*e)/(i*u-n*n),s=e/i-l*n/i,c=[],h=0;h<t.length;h++){var v=[t[h][0],l*t[h][0]+s];c.push(v)}var p="y = "+Math.round(100*l)/100+"x + "+Math.round(100*s)/100;return{points:c,parameter:{gradient:l,intercept:s},expression:p}},linearThroughOrigin:function(r){for(var t=o(r),n=0,e=0,a=0;a<t.length;a++)n+=t[a][0]*t[a][0],e+=t[a][0]*t[a][1];for(var u=e/n,i=[],f=0;f<t.length;f++){var l=[t[f][0],t[f][0]*u];i.push(l)}var s="y = "+Math.round(100*u)/100+"x";return{points:i,parameter:{gradient:u},expression:s}},exponential:function(r){for(var t=o(r),n=0,e=0,a=0,u=0,i=0,f=0,l=0;l<t.length;l++)n+=t[l][0],e+=t[l][1],f+=t[l][0]*t[l][1],a+=t[l][0]*t[l][0]*t[l][1],u+=t[l][1]*Math.log(t[l][1]),i+=t[l][0]*t[l][1]*Math.log(t[l][1]);for(var s=e*a-f*f,c=Math.pow(Math.E,(a*u-f*i)/s),h=(e*i-f*u)/s,v=[],p=0;p<t.length;p++){var g=[t[p][0],c*Math.pow(Math.E,h*t[p][0])];v.push(g)}var d="y = "+Math.round(100*c)/100+"e^("+Math.round(100*h)/100+"x)";return{points:v,parameter:{coefficient:c,index:h},expression:d}},logarithmic:function(r){for(var t=o(r),n=0,e=0,a=0,u=0,i=0;i<t.length;i++)n+=Math.log(t[i][0]),e+=t[i][1]*Math.log(t[i][0]),a+=t[i][1],u+=Math.pow(Math.log(t[i][0]),2);for(var f=(i*e-a*n)/(i*u-n*n),l=(a-f*n)/i,s=[],c=0;c<t.length;c++){var h=[t[c][0],f*Math.log(t[c][0])+l];s.push(h)}var v="y = "+Math.round(100*l)/100+" + "+Math.round(100*f)/100+"ln(x)";return{points:s,parameter:{gradient:f,intercept:l},expression:v}},polynomial:function(r,n){var e=o(r);"undefined"==typeof n&&(n=2);for(var a=[],u=[],i=n+1,f=0;f<i;f++){for(var l=0,s=0;s<e.length;s++)l+=e[s][1]*Math.pow(e[s][0],f);u.push(l);for(var c=[],h=0;h<i;h++){for(var v=0,p=0;p<e.length;p++)v+=Math.pow(e[p][0],f+h);c.push(v)}a.push(c)}a.push(u);for(var g=t(a,i),d=[],f=0;f<e.length;f++){for(var M=0,s=0;s<g.length;s++)M+=g[s]*Math.pow(e[f][0],s);d.push([e[f][0],M])}for(var x="y = ",f=g.length-1;f>=0;f--)x+=f>1?Math.round(g[f]*Math.pow(10,f+1))/Math.pow(10,f+1)+"x^"+f+" + ":1===f?Math.round(100*g[f])/100+"x + ":Math.round(100*g[f])/100;return{points:d,parameter:g,expression:x}}},u=function(r,t,n){return a[r](t,n)};return u}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){var t={};return t.max=n(6),t.deviation=n(5),t.mean=n(7),t.median=n(15),t.min=n(8),t.quantile=n(3),t.sampleVariance=n(9),t.sum=n(10),t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){function t(r){return e(r,.5)}var e=n(3);return t}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){var t=n(2),e=t.getPrecision;return function(r,t,n,o){var a=arguments.length;a<2?(t=r,r=0,n=1):a<3?n=1:a<4?(n=+n,o=e(n)):o=+o;for(var u=Math.ceil(((t-r)/n).toFixed(o)),i=new Array(u+1),f=0;f<u+1;f++)i[f]=+(r+f*n).toFixed(o);return i}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))},function(r,t,n){var e;e=function(r){return function(r,t,n){var e=Math.abs(t-r)/n,o=Math.floor(Math.log(e)/Math.LN10),a=Math.pow(10,o),u=e/a;return u>=Math.sqrt(50)?a*=10:u>=Math.sqrt(10)?a*=5:u>=Math.sqrt(2)&&(a*=2),+(t>=r?a:-a).toFixed(-o)}}.call(t,n,t,r),!(void 0!==e&&(r.exports=e))}])}); |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./src/ecStat'); | ||
module.exports = require('./dist/ecStat.js'); |
{ | ||
"name": "echarts-stat", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "a statistical tool for ECharts", | ||
"main": "index.js", | ||
"types": "src/ecStat.d.ts", | ||
"author": { | ||
"name": "Deqing", | ||
"name": "Deqing Li", | ||
"email": "annong035@gmail.com" | ||
@@ -19,2 +20,2 @@ }, | ||
} | ||
} | ||
} |
@@ -35,3 +35,3 @@ # ecStat | ||
A histogram is a graphical representation of the distribution of numerical data. It is an estimate of the probability distribution of a quantitative variable. It is a kind of bar graph. To construct a histogram, the first step is to "bin" the range of values - that is, divide the entire range of values into a series of intervals - and then count how many values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable. Here the bins(intervals) must be adjacent, and are of equal size. | ||
A histogram is a graphical representation of the distribution of numerical data. It is an estimate of the probability distribution of a quantitative variable. It is a kind of bar graph. To construct a histogram, the first step is to "bin" the range of values - that is, divide the entire range of values into a series of intervals - and then count how many original sample values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable. Here the bins(intervals) must be adjacent, and are of equal size. | ||
@@ -52,5 +52,5 @@ #### Syntax | ||
* `binMethod` - `string`. There are four methods to calculate the number of bins, which are `squareRoot`, `scott`, `freedmanDiaconis`, and `sturges`. Of course, there is no "best" number of bins, and different bin sizes can reveal different features of the data. | ||
* `binMethod` - `string`. There are four methods to calculate the number of bin, which are `squareRoot`, `scott`, `freedmanDiaconis`, and `sturges`. Of course, there is no "best" number of bin, and different bin size can reveal different feature of data. | ||
* `squareRoot` - This is the default method, which is also used by Excel histograms. Returns the number of bins according to [Square-root choice](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
* `squareRoot` - This is the default method, which is also used by Excel histogram. Returns the number of bin according to [Square-root choice](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
```js | ||
@@ -60,3 +60,3 @@ var bins = ecStat.histogram(data); | ||
* `scott` - Returns the number of bins according to [Scott's normal reference Rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
* `scott` - Returns the number of bin according to [Scott's normal reference Rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
```js | ||
@@ -66,3 +66,3 @@ var bins = ecStat.histogram(data, 'scott'); | ||
* `freedmanDiaconis` - Returns the number of bins according to [The Freedman-Diaconis rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
* `freedmanDiaconis` - Returns the number of bin according to [The Freedman-Diaconis rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
```js | ||
@@ -72,3 +72,3 @@ var bins = ecStat.histogram(data, 'freedmanDiaconis'); | ||
* `sturges` - Returns the number of bins according to [Sturges' formula](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
* `sturges` - Returns the number of bin according to [Sturges' formula](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition): | ||
```js | ||
@@ -80,3 +80,3 @@ var bins = ecStat.histogram(data, 'sturges'); | ||
* `bins` - `Object`. Contain detailed messages of each bin and data used for [ECharts](https://github.com/ecomfe/echarts) to draw the bar chart. | ||
* `bins` - `Object`. Contain detailed messages of each bin and data used for [ECharts](https://github.com/ecomfe/echarts) to draw the histogram. | ||
* `bins.bins` - `Array.<Object>`. An array of bins, where each bin is an object, containing three attributes: | ||
@@ -86,7 +86,8 @@ * `x0` - `number`. The lower bound of the bin (inclusive). | ||
* `sample` - `Array.<number>`. Containing the associated elements from the input data. | ||
* `bins.data` - `Array.<Array.<number>>`. An array of bins data, each bins data is an array not only containing the mean value of `x0` and `x1`, but also the length of `sample`, which is the number of sample values in that bin. | ||
* `bins.data` - `Array.<Array.<number>>`. Used for bar chart to draw the histogram, each bin data is an array not only containing the mean value of `x0` and `x1`, but also the length of `sample`, which is the number of sample values in this bin. | ||
* `bins.customData` - `Array.<Array<number>>`. Used for custom chart to draw the histogram, each custom data is an array not only containing the `x0` and `x1`, but also the length of `sample`, which is the number of sample values in this bin. | ||
#### Examples | ||
When using ECharts bar chart to draw the histogram, we must notice that, setting the `xAxis.scale` as `true`. | ||
This example using ECharts custom chart to draw the histogram, which is the best type of chart we recommend. | ||
@@ -101,6 +102,5 @@ ```html | ||
... | ||
xAxis: [{ | ||
type: 'value', | ||
// this must be set as true, otherwise barWidth and bins width can not corresponding on | ||
scale: true | ||
series: [{ | ||
type: 'custom', | ||
... | ||
}], | ||
@@ -127,3 +127,3 @@ ... | ||
* `data` - `two-dimensional Numeric Array`. Each data point can have more than two numeric attributes in the original data set. In the following example, `data[0]` is called `data point` and `data[0][1]` is one of the numeric attributes of `data[0]`. | ||
* `data` - `Array.<Array.<number>>`. Two-dimensional numeric array, each data point can have more than two numeric attributes in the original data set. In the following example, `data[0]` is called `data point` and `data[0][1]` is one of the numeric attributes of `data[0]`. | ||
@@ -138,3 +138,3 @@ ```js | ||
``` | ||
* `clusterNumer` - `number`. The number of clusters generated | ||
* `clusterNumer` - `number`. The number of clusters generated. **Note that it has to be greater than 1.** | ||
* `stepByStep` - `boolean`. Control whether doing the clustering step by step | ||
@@ -154,3 +154,3 @@ | ||
// indicate which cluster each data point belonging to, and the distance to cluster centroids | ||
// Indicate which cluster each data point belonging to, and the distance to cluster centroids | ||
result.clusterAssment = [ | ||
@@ -164,3 +164,3 @@ | ||
// concrete data point in each cluster | ||
// Concrete data point in each cluster | ||
result.pointsInCluster = [ | ||
@@ -180,5 +180,5 @@ [ | ||
Note: the clustering algorithm can handle multiple numeric attributes, but for the convenience of visualization, two numeric attributes are chosen here as an example. | ||
**Note: the clustering algorithm can handle multiple numeric attributes, but for the convenience of visualization, two numeric attributes are chosen here as an example.** | ||
##### Directly visualize the results of clustering | ||
##### Directly visualize the final results of clustering | ||
@@ -228,4 +228,4 @@ ```html | ||
* `regressionType` - `string`. There are four types of regression, whice are `linear`, `exponential`, `logarithmic`, `polynomial` | ||
* `data` - `two-dimensional Numeric Array`. Each data object should have two numeric attributes in the original data set. For Example: | ||
* `regressionType` - `string`. There are four types of regression, whice are `'linear'`, `'exponential'`, `'logarithmic'`, `'polynomial'`. | ||
* `data` - `Array.<Array.<number>>`. Two-dimensional numeric array, Each data object should have two numeric attributes in the original data set. For Example: | ||
@@ -240,3 +240,3 @@ ```js | ||
``` | ||
* `order` - `number`. The order of polynomial. If you choose other types of regression, you can ignore it | ||
* `order` - `number`. The order of polynomial. If you choose other types of regression, you can ignore it. | ||
@@ -254,3 +254,3 @@ ##### Return Value | ||
// this is the parameter of linear regression, for other types, it shoule be a little different | ||
// This is the parameter of linear regression, for other types, it shoule be a little different | ||
myRegression.parameter = { | ||
@@ -257,0 +257,0 @@ gradient: 1.695, |
define(function (require) { | ||
var dataPreprocess = require('./util/dataPreprocess'); | ||
var dataProcess = require('./util/dataProcess'); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
var array = require('./util/array'); | ||
@@ -94,3 +95,3 @@ var arraySize = array.size; | ||
* @param {Array} data two-dimension array. | ||
* @param {[type]} k the number of clusters in a dataset | ||
* @param {[type]} k the number of clusters in a dataset. It has to be greater than 1. | ||
* @param {boolean} stepByStep | ||
@@ -100,3 +101,5 @@ * @return {} | ||
function hierarchicalKMeans(data, k, stepByStep) { | ||
if (k < 2 ) { | ||
return; | ||
} | ||
var dataSet = dataPreprocess(data); | ||
@@ -103,0 +106,0 @@ var size = arraySize(dataSet); |
@@ -7,3 +7,5 @@ define(function (require) { | ||
var deviation = require('./statistics/deviation'); | ||
var dataPreprocess = require('./util/dataPreprocess'); | ||
var dataProcess = require('./util/dataProcess'); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
var getPrecision = dataProcess.getPrecision; | ||
var array = require('./util/array'); | ||
@@ -25,10 +27,6 @@ var ascending = array.ascending; | ||
if (threshold == null) { | ||
threshold = thresholdMethod.squareRoot; | ||
} | ||
else { | ||
threshold = thresholdMethod[threshold]; | ||
} | ||
@@ -38,9 +36,14 @@ var values = dataPreprocess(data); | ||
var minValue = min(values); | ||
var binsNumber = threshold(values, minValue, maxValue); | ||
var step = tickStep(minValue, maxValue, binsNumber); | ||
var precision = -Math.floor(Math.log(Math.abs(maxValue - minValue) / binsNumber) / Math.LN10); | ||
// return the xAxis coordinate for each bins, except the end point of the value | ||
var rangeArray = range(Math.ceil(minValue / step) * step, Math.floor(maxValue / step) * step, step); | ||
var rangeArray = range( | ||
// use function toFixed() to avoid data like '0.700000001' | ||
+((Math.ceil(minValue / step) * step).toFixed(precision)), | ||
+((Math.floor(maxValue / step) * step).toFixed(precision)), | ||
step, | ||
precision | ||
); | ||
@@ -54,3 +57,3 @@ var len = rangeArray.length; | ||
bins[i].sample = []; | ||
bins[i].x0 = i > 0 // 不要数组直接挂属性,改成Object | ||
bins[i].x0 = i > 0 | ||
? rangeArray[i - 1] | ||
@@ -74,12 +77,17 @@ : (rangeArray[i] - minValue) === step | ||
var data = map(bins, function (bin) { | ||
return [(bin.x0 + bin.x1) / 2, bin.sample.length]; | ||
// use function toFixed() to avoid data like '6.5666638489' | ||
return [+((bin.x0 + bin.x1) / 2).toFixed(precision), bin.sample.length]; | ||
}); | ||
var customData = map(bins, function (bin) { | ||
return [bin.x0, bin.x1, bin.sample.length]; | ||
}); | ||
return { | ||
bins: bins, | ||
data: data | ||
data: data, | ||
customData: customData | ||
}; | ||
} | ||
/** | ||
@@ -86,0 +94,0 @@ * Four kinds of threshold methods used to |
define(function (require) { | ||
var dataPreprocess = require('./util/dataPreprocess'); | ||
var dataProcess = require('./util/dataProcess'); | ||
var dataPreprocess = dataProcess.dataPreprocess; | ||
@@ -5,0 +6,0 @@ var regreMethods = { |
@@ -10,4 +10,4 @@ define(function (require) { | ||
statistics.min = require('./statistics/min'); | ||
statistics.max = require('./statistics/quantile'); | ||
statistics.max = require('./statistics/sampleVariance'); | ||
statistics.quantile = require('./statistics/quantile'); | ||
statistics.sampleVariance = require('./statistics/sampleVariance'); | ||
statistics.sum = require('./statistics/sum'); | ||
@@ -14,0 +14,0 @@ |
@@ -30,3 +30,3 @@ define(function (require) { | ||
} | ||
return sum / data.length - 1; | ||
return sum / (data.length - 1); | ||
} | ||
@@ -37,2 +37,2 @@ } | ||
}); | ||
}); |
@@ -10,3 +10,3 @@ define(function (require) { | ||
value = (value === null ? NaN : +value); | ||
value = value === null ? NaN : +value; | ||
return typeof value === 'number' && !isNaN(value); | ||
@@ -13,0 +13,0 @@ } |
define(function (require) { | ||
var dataProcess = require('./dataProcess'); | ||
var getPrecision = dataProcess.getPrecision; | ||
/** | ||
* Computing range array | ||
* Computing range array. | ||
* Adding param precision to fix range value, avoiding range[i] = 0.7000000001. | ||
* @param {number} start | ||
* @param {number} stop | ||
* @param {number} end | ||
* @param {number} step | ||
* @param {number} precision | ||
* @return {Array.<number>} | ||
*/ | ||
return function (start, stop, step) { | ||
return function (start, end, step, precision) { | ||
@@ -15,3 +20,3 @@ var len = arguments.length; | ||
if (len < 2) { | ||
stop = start; | ||
end = start; | ||
start = 0; | ||
@@ -23,11 +28,14 @@ step = 1; | ||
} | ||
else { | ||
else if (len < 4) { | ||
step = +step; | ||
precision = getPrecision(step); | ||
} | ||
else { | ||
precision = +precision; | ||
} | ||
var n = Math.ceil((stop - start) / step); | ||
var n = Math.ceil(((end - start) / step).toFixed(precision)); | ||
var range = new Array(n + 1); | ||
for (var i = 0; i < n + 1; i++) { | ||
range[i] = start + i * step; | ||
range[i] = +(start + i * step).toFixed(precision); | ||
} | ||
@@ -34,0 +42,0 @@ return range; |
@@ -13,3 +13,4 @@ define(function (require) { | ||
var step0 = Math.abs(stop - start) / count; | ||
var step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)); | ||
var precision = Math.floor(Math.log(step0) / Math.LN10); | ||
var step1 = Math.pow(10, precision); | ||
var error = step0 / step1; | ||
@@ -26,3 +27,3 @@ | ||
} | ||
return stop >= start ? step1 : -step1; | ||
return +((stop >= start ? step1 : -step1).toFixed(-precision)); | ||
@@ -29,0 +30,0 @@ }; |
@@ -13,3 +13,3 @@ require.config({ | ||
main: 'echarts', | ||
location: '../../echarts/src', | ||
location: '../../echarts/dist', | ||
name: 'echarts' | ||
@@ -19,3 +19,3 @@ }, | ||
main: 'zrender', | ||
location: '../../zrender/src', | ||
location: '../../zrender/dist', | ||
name: 'zrender' | ||
@@ -22,0 +22,0 @@ } |
@@ -6,3 +6,3 @@ var PROD = process.argv.indexOf('-p') >= 0; | ||
entry: { | ||
'ecStat': __dirname + '/index.js' | ||
'ecStat': __dirname + '/src/ecStat.js' | ||
}, | ||
@@ -9,0 +9,0 @@ output: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
685097
49
2926