@visactor/vutils 0.19.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -12
- package/cjs/common/ascending.js +2 -1
- package/cjs/common/cloneDeep.js +1 -2
- package/cjs/common/extent.d.ts +1 -0
- package/cjs/common/extent.js +30 -0
- package/cjs/common/extent.js.map +1 -0
- package/cjs/common/field.d.ts +12 -0
- package/cjs/common/field.js +36 -0
- package/cjs/common/field.js.map +1 -0
- package/cjs/common/index.d.ts +5 -0
- package/cjs/common/index.js +3 -1
- package/cjs/common/index.js.map +1 -1
- package/cjs/common/isArrayLike.js +2 -1
- package/cjs/common/isEmpty.js +1 -2
- package/cjs/common/isObjectLike.js +1 -1
- package/cjs/common/isPlainObject.js +1 -1
- package/cjs/common/isPrototype.js +1 -1
- package/cjs/common/isRegExp.js +1 -1
- package/cjs/common/isShallowEqual.js +2 -1
- package/cjs/common/isString.js +1 -1
- package/cjs/common/isType.js +1 -1
- package/cjs/common/isUndefined.js +1 -1
- package/cjs/common/isValid.js +1 -1
- package/cjs/common/isValidNumber.js +1 -1
- package/cjs/common/isValidUrl.js +1 -1
- package/cjs/common/lowerFirst.js +1 -1
- package/cjs/common/random.d.ts +2 -0
- package/cjs/common/random.js +18 -1
- package/cjs/common/random.js.map +1 -1
- package/cjs/common/regression-linear.d.ts +8 -0
- package/cjs/common/regression-linear.js +50 -0
- package/cjs/common/regression-linear.js.map +1 -0
- package/cjs/common/toPercent.d.ts +1 -0
- package/cjs/common/toPercent.js +17 -0
- package/cjs/common/toPercent.js.map +1 -0
- package/cjs/common/zero.d.ts +1 -0
- package/cjs/common/zero.js +10 -0
- package/cjs/common/zero.js.map +1 -0
- package/cjs/data-structure/bounds.js +1 -1
- package/cjs/data-structure/hashTable.js +1 -1
- package/cjs/data-structure/index.js +1 -1
- package/cjs/data-structure/matrix.js +1 -1
- package/cjs/data-structure/point.js +1 -1
- package/cjs/fmin/blas1.js +1 -1
- package/cjs/fmin/conjugate-gradient.js +1 -1
- package/cjs/fmin/index.js +1 -1
- package/cjs/fmin/linesearch.js +1 -2
- package/cjs/fmin/nelder-mead.js +1 -1
- package/dist/index.js +145 -2
- package/dist/index.min.js +1 -1
- package/es/common/ascending.js +2 -1
- package/es/common/cloneDeep.js +1 -2
- package/es/common/extent.d.ts +1 -0
- package/es/common/extent.js +21 -0
- package/es/common/extent.js.map +1 -0
- package/es/common/field.d.ts +12 -0
- package/es/common/field.js +24 -0
- package/es/common/field.js.map +1 -0
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +10 -0
- package/es/common/index.js.map +1 -1
- package/es/common/isArrayLike.js +2 -1
- package/es/common/isEmpty.js +1 -2
- package/es/common/isObjectLike.js +1 -1
- package/es/common/isPlainObject.js +1 -1
- package/es/common/isPrototype.js +1 -1
- package/es/common/isRegExp.js +1 -1
- package/es/common/isShallowEqual.js +2 -1
- package/es/common/isString.js +1 -1
- package/es/common/isType.js +1 -1
- package/es/common/isUndefined.js +1 -1
- package/es/common/isValid.js +1 -1
- package/es/common/isValidNumber.js +1 -1
- package/es/common/isValidUrl.js +1 -1
- package/es/common/lowerFirst.js +1 -1
- package/es/common/random.d.ts +2 -0
- package/es/common/random.js +13 -0
- package/es/common/random.js.map +1 -1
- package/es/common/regression-linear.d.ts +8 -0
- package/es/common/regression-linear.js +35 -0
- package/es/common/regression-linear.js.map +1 -0
- package/es/common/toPercent.d.ts +1 -0
- package/es/common/toPercent.js +6 -0
- package/es/common/toPercent.js.map +1 -0
- package/es/common/zero.d.ts +1 -0
- package/es/common/zero.js +2 -0
- package/es/common/zero.js.map +1 -0
- package/es/data-structure/bounds.js +1 -1
- package/es/data-structure/hashTable.js +1 -1
- package/es/data-structure/index.js +1 -1
- package/es/data-structure/matrix.js +1 -1
- package/es/data-structure/point.js +1 -1
- package/es/fmin/blas1.js +1 -1
- package/es/fmin/conjugate-gradient.js +1 -1
- package/es/fmin/index.js +1 -1
- package/es/fmin/linesearch.js +1 -2
- package/es/fmin/nelder-mead.js +1 -1
- package/package.json +21 -18
package/dist/index.js
CHANGED
|
@@ -1514,7 +1514,7 @@
|
|
|
1514
1514
|
}
|
|
1515
1515
|
const reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
|
|
1516
1516
|
const reB = new RegExp(reA.source, 'g');
|
|
1517
|
-
function zero(b) {
|
|
1517
|
+
function zero$1(b) {
|
|
1518
1518
|
return function () {
|
|
1519
1519
|
return b;
|
|
1520
1520
|
};
|
|
@@ -1569,7 +1569,7 @@
|
|
|
1569
1569
|
return s.length < 2
|
|
1570
1570
|
? q[0]
|
|
1571
1571
|
? one(q[0].x)
|
|
1572
|
-
: zero(b)
|
|
1572
|
+
: zero$1(b)
|
|
1573
1573
|
: ((b = q.length),
|
|
1574
1574
|
function (t) {
|
|
1575
1575
|
for (let i = 0, o; i < b; ++i) {
|
|
@@ -1635,6 +1635,137 @@
|
|
|
1635
1635
|
function seedRandom(seed) {
|
|
1636
1636
|
return parseFloat('0.' + Math.sin(seed).toString().substring(6));
|
|
1637
1637
|
}
|
|
1638
|
+
const a = 1664525;
|
|
1639
|
+
const c = 1013904223;
|
|
1640
|
+
const m = 4294967296;
|
|
1641
|
+
function randomLCG(initS = 1) {
|
|
1642
|
+
let s = initS;
|
|
1643
|
+
return () => (s = (a * s + c) % m) / m;
|
|
1644
|
+
}
|
|
1645
|
+
const fakeRandom = () => {
|
|
1646
|
+
let i = -1;
|
|
1647
|
+
const arr = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
|
|
1648
|
+
return () => {
|
|
1649
|
+
i = (i + 1) % arr.length;
|
|
1650
|
+
return arr[i];
|
|
1651
|
+
};
|
|
1652
|
+
};
|
|
1653
|
+
|
|
1654
|
+
const getter = (path) => {
|
|
1655
|
+
return (obj) => get(obj, path);
|
|
1656
|
+
};
|
|
1657
|
+
const fieldSingle = (fieldStr, opt = {}) => {
|
|
1658
|
+
if (isFunction(fieldStr)) {
|
|
1659
|
+
return fieldStr;
|
|
1660
|
+
}
|
|
1661
|
+
const path = [fieldStr];
|
|
1662
|
+
return ((opt && opt.get) || getter)(path);
|
|
1663
|
+
};
|
|
1664
|
+
const field = (fieldStr, opt = {}) => {
|
|
1665
|
+
if (isArray(fieldStr)) {
|
|
1666
|
+
const funcs = fieldStr.map(entry => fieldSingle(entry, opt));
|
|
1667
|
+
return (datum) => {
|
|
1668
|
+
return funcs.map(func => func(datum));
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
return fieldSingle(fieldStr, opt);
|
|
1672
|
+
};
|
|
1673
|
+
const simpleField = (option) => {
|
|
1674
|
+
if (!option) {
|
|
1675
|
+
return null;
|
|
1676
|
+
}
|
|
1677
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
1678
|
+
return () => option;
|
|
1679
|
+
}
|
|
1680
|
+
else if (isFunction(option)) {
|
|
1681
|
+
return option;
|
|
1682
|
+
}
|
|
1683
|
+
return (datum) => datum[option.field];
|
|
1684
|
+
};
|
|
1685
|
+
|
|
1686
|
+
const toPercent = (percent, total) => {
|
|
1687
|
+
if (isNil(percent)) {
|
|
1688
|
+
return total;
|
|
1689
|
+
}
|
|
1690
|
+
return isString(percent) ? (total * parseFloat(percent)) / 100 : percent;
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
const zero = (_) => 0;
|
|
1694
|
+
|
|
1695
|
+
const extent = (array, func) => {
|
|
1696
|
+
const valueGetter = isFunction(func) ? func : (val) => val;
|
|
1697
|
+
let min;
|
|
1698
|
+
let max;
|
|
1699
|
+
if (array && array.length) {
|
|
1700
|
+
const n = array.length;
|
|
1701
|
+
for (let i = 0; i < n; i += 1) {
|
|
1702
|
+
let value = valueGetter(array[i]);
|
|
1703
|
+
if (!isNil(value) && isNumber((value = +value)) && !Number.isNaN(value)) {
|
|
1704
|
+
if (isNil(min)) {
|
|
1705
|
+
min = value;
|
|
1706
|
+
max = value;
|
|
1707
|
+
}
|
|
1708
|
+
else {
|
|
1709
|
+
min = Math.min(min, value);
|
|
1710
|
+
max = Math.max(max, value);
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return [min, max];
|
|
1715
|
+
}
|
|
1716
|
+
return [min, max];
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1719
|
+
function ordinaryLeastSquares(uX, uY, uXY, uX2) {
|
|
1720
|
+
const delta = uX2 - uX * uX;
|
|
1721
|
+
const slope = Math.abs(delta) < 1e-24 ? 0 : (uXY - uX * uY) / delta;
|
|
1722
|
+
const intercept = uY - slope * uX;
|
|
1723
|
+
return [intercept, slope];
|
|
1724
|
+
}
|
|
1725
|
+
function visitPoints(data, x, y, callback) {
|
|
1726
|
+
let i = -1;
|
|
1727
|
+
let u;
|
|
1728
|
+
let v;
|
|
1729
|
+
data.forEach(d => {
|
|
1730
|
+
u = x(d);
|
|
1731
|
+
v = y(d);
|
|
1732
|
+
if (!isNil(u) && (u = +u) >= u && !isNil(v) && (v = +v) >= v) {
|
|
1733
|
+
callback(u, v, ++i);
|
|
1734
|
+
}
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
function rSquared(data, x, y, uY, predict) {
|
|
1738
|
+
let SSE = 0;
|
|
1739
|
+
let SST = 0;
|
|
1740
|
+
visitPoints(data, x, y, (dx, dy) => {
|
|
1741
|
+
const sse = dy - predict(dx);
|
|
1742
|
+
const sst = dy - uY;
|
|
1743
|
+
SSE += sse * sse;
|
|
1744
|
+
SST += sst * sst;
|
|
1745
|
+
});
|
|
1746
|
+
return 1 - SSE / SST;
|
|
1747
|
+
}
|
|
1748
|
+
function regressionLinear(data, x = datum => datum.x, y = datum => datum.y) {
|
|
1749
|
+
let X = 0;
|
|
1750
|
+
let Y = 0;
|
|
1751
|
+
let XY = 0;
|
|
1752
|
+
let X2 = 0;
|
|
1753
|
+
let n = 0;
|
|
1754
|
+
visitPoints(data, x, y, (dx, dy) => {
|
|
1755
|
+
++n;
|
|
1756
|
+
X += (dx - X) / n;
|
|
1757
|
+
Y += (dy - Y) / n;
|
|
1758
|
+
XY += (dx * dy - XY) / n;
|
|
1759
|
+
X2 += (dx * dx - X2) / n;
|
|
1760
|
+
});
|
|
1761
|
+
const coef = ordinaryLeastSquares(X, Y, XY, X2);
|
|
1762
|
+
const predict = (x) => coef[0] + coef[1] * x;
|
|
1763
|
+
return {
|
|
1764
|
+
coef: coef,
|
|
1765
|
+
predict: predict,
|
|
1766
|
+
rSquared: rSquared(data, x, y, Y, predict)
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1638
1769
|
|
|
1639
1770
|
class HashValue {
|
|
1640
1771
|
}
|
|
@@ -6255,6 +6386,9 @@
|
|
|
6255
6386
|
exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
|
|
6256
6387
|
exports.epsilon = epsilon;
|
|
6257
6388
|
exports.exponent = exponent;
|
|
6389
|
+
exports.extent = extent;
|
|
6390
|
+
exports.fakeRandom = fakeRandom;
|
|
6391
|
+
exports.field = field;
|
|
6258
6392
|
exports.findBoundaryAngles = findBoundaryAngles;
|
|
6259
6393
|
exports.findZeroOfFunction = findZeroOfFunction;
|
|
6260
6394
|
exports.fixPrecision = fixPrecision;
|
|
@@ -6290,6 +6424,7 @@
|
|
|
6290
6424
|
exports.getScrollLeft = getScrollLeft;
|
|
6291
6425
|
exports.getScrollTop = getScrollTop;
|
|
6292
6426
|
exports.getTimeFormatter = getTimeFormatter;
|
|
6427
|
+
exports.getter = getter;
|
|
6293
6428
|
exports.halfPi = halfPi;
|
|
6294
6429
|
exports.has = has;
|
|
6295
6430
|
exports.hasParentElement = hasParentElement;
|
|
@@ -6378,6 +6513,7 @@
|
|
|
6378
6513
|
exports.normalizePadding = normalizePadding;
|
|
6379
6514
|
exports.numberSpecifierReg = numberSpecifierReg;
|
|
6380
6515
|
exports.obbSeparation = obbSeparation;
|
|
6516
|
+
exports.ordinaryLeastSquares = ordinaryLeastSquares;
|
|
6381
6517
|
exports.pad = pad;
|
|
6382
6518
|
exports.parseUint8ToImageData = parseUint8ToImageData;
|
|
6383
6519
|
exports.pi = pi;
|
|
@@ -6397,9 +6533,12 @@
|
|
|
6397
6533
|
exports.precisionAdd = precisionAdd;
|
|
6398
6534
|
exports.precisionSub = precisionSub;
|
|
6399
6535
|
exports.quantileSorted = quantileSorted;
|
|
6536
|
+
exports.rSquared = rSquared;
|
|
6400
6537
|
exports.radianToDegree = radianToDegree;
|
|
6538
|
+
exports.randomLCG = randomLCG;
|
|
6401
6539
|
exports.range = range;
|
|
6402
6540
|
exports.rectInsideAnotherRect = rectInsideAnotherRect;
|
|
6541
|
+
exports.regressionLinear = regressionLinear;
|
|
6403
6542
|
exports.rgbToHex = rgbToHex;
|
|
6404
6543
|
exports.rgbToHsl = rgbToHsl;
|
|
6405
6544
|
exports.rotatePoint = rotatePoint;
|
|
@@ -6412,6 +6551,7 @@
|
|
|
6412
6551
|
exports.secondsSetterName = secondsSetterName;
|
|
6413
6552
|
exports.seedRandom = seedRandom;
|
|
6414
6553
|
exports.shuffleArray = shuffleArray;
|
|
6554
|
+
exports.simpleField = simpleField;
|
|
6415
6555
|
exports.sin = sin;
|
|
6416
6556
|
exports.span = span;
|
|
6417
6557
|
exports.sqrt = sqrt;
|
|
@@ -6424,6 +6564,7 @@
|
|
|
6424
6564
|
exports.toCamelCase = toCamelCase;
|
|
6425
6565
|
exports.toDate = toDate;
|
|
6426
6566
|
exports.toNumber = toNumber;
|
|
6567
|
+
exports.toPercent = toPercent;
|
|
6427
6568
|
exports.toValidNumber = toValidNumber;
|
|
6428
6569
|
exports.transformBounds = transformBounds;
|
|
6429
6570
|
exports.transformBoundsWithMatrix = transformBoundsWithMatrix;
|
|
@@ -6454,11 +6595,13 @@
|
|
|
6454
6595
|
exports.utcYearOffset = utcYearOffset;
|
|
6455
6596
|
exports.uuid = uuid;
|
|
6456
6597
|
exports.variance = variance;
|
|
6598
|
+
exports.visitPoints = visitPoints;
|
|
6457
6599
|
exports.weightedSum = weightedSum;
|
|
6458
6600
|
exports.yearCount = yearCount;
|
|
6459
6601
|
exports.yearField = yearField;
|
|
6460
6602
|
exports.yearFloor = yearFloor;
|
|
6461
6603
|
exports.yearOffset = yearOffset;
|
|
6604
|
+
exports.zero = zero;
|
|
6462
6605
|
exports.zeros = zeros;
|
|
6463
6606
|
exports.zerosM = zerosM;
|
|
6464
6607
|
|