svelteplot 0.4.6-pr-213.3 → 0.4.6

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.
Files changed (59) hide show
  1. package/dist/helpers/colors.d.ts +1 -1
  2. package/dist/helpers/index.d.ts +2 -2
  3. package/dist/helpers/scales.d.ts +2 -2
  4. package/dist/helpers/scales.js +10 -21
  5. package/dist/helpers/typeChecks.d.ts +4 -4
  6. package/dist/marks/AreaX.svelte.d.ts +1 -2
  7. package/dist/marks/AreaY.svelte.d.ts +1 -2
  8. package/dist/marks/AxisX.svelte.d.ts +1 -1
  9. package/dist/marks/AxisY.svelte.d.ts +1 -1
  10. package/dist/marks/BarX.svelte.d.ts +1 -1
  11. package/dist/marks/BollingerX.svelte.d.ts +74 -2
  12. package/dist/marks/BollingerY.svelte.d.ts +74 -2
  13. package/dist/marks/CustomMark.svelte.d.ts +81 -2
  14. package/dist/marks/DifferenceY.svelte.d.ts +67 -7
  15. package/dist/marks/Line.svelte.d.ts +2 -2
  16. package/dist/marks/LineX.svelte.d.ts +1 -2
  17. package/dist/marks/LineY.svelte.d.ts +1 -2
  18. package/dist/marks/helpers/RectPath.svelte.d.ts +63 -3
  19. package/dist/marks/helpers/Regression.svelte +1 -1
  20. package/dist/transforms/bollinger.d.ts +67 -1
  21. package/dist/transforms/group.d.ts +12 -4
  22. package/dist/transforms/interval.d.ts +124 -2
  23. package/dist/transforms/recordize.d.ts +4 -1
  24. package/dist/transforms/select.d.ts +434 -7
  25. package/dist/transforms/sort.d.ts +246 -3
  26. package/dist/transforms/stack.d.ts +23 -3
  27. package/dist/transforms/window.d.ts +130 -2
  28. package/dist/types/scale.d.ts +0 -6
  29. package/package.json +128 -128
  30. package/dist/regression/exponential.d.ts +0 -17
  31. package/dist/regression/exponential.js +0 -56
  32. package/dist/regression/index.d.ts +0 -10
  33. package/dist/regression/index.js +0 -10
  34. package/dist/regression/linear.d.ts +0 -17
  35. package/dist/regression/linear.js +0 -59
  36. package/dist/regression/loess.d.ts +0 -14
  37. package/dist/regression/loess.js +0 -122
  38. package/dist/regression/logarithmic.d.ts +0 -20
  39. package/dist/regression/logarithmic.js +0 -60
  40. package/dist/regression/polynomial.d.ts +0 -21
  41. package/dist/regression/polynomial.js +0 -160
  42. package/dist/regression/power.d.ts +0 -18
  43. package/dist/regression/power.js +0 -56
  44. package/dist/regression/quadratic.d.ts +0 -19
  45. package/dist/regression/quadratic.js +0 -70
  46. package/dist/regression/types.d.ts +0 -4
  47. package/dist/regression/types.js +0 -1
  48. package/dist/regression/utils/determination.d.ts +0 -6
  49. package/dist/regression/utils/determination.js +0 -16
  50. package/dist/regression/utils/geometry.d.ts +0 -9
  51. package/dist/regression/utils/geometry.js +0 -12
  52. package/dist/regression/utils/interpose.d.ts +0 -6
  53. package/dist/regression/utils/interpose.js +0 -37
  54. package/dist/regression/utils/median.d.ts +0 -4
  55. package/dist/regression/utils/median.js +0 -8
  56. package/dist/regression/utils/ols.d.ts +0 -6
  57. package/dist/regression/utils/ols.js +0 -9
  58. package/dist/regression/utils/points.d.ts +0 -11
  59. package/dist/regression/utils/points.js +0 -45
@@ -1,21 +0,0 @@
1
- /**
2
- * Adapted from https://github.com/HarryStevens/d3-regression
3
- */
4
- import type { PredictFunction, Accessor, DataPoint, Domain } from './types';
5
- export type PolynomialOutput = [DataPoint, DataPoint] & {
6
- coefficients: number[];
7
- predict: PredictFunction;
8
- rSquared: number;
9
- };
10
- export interface PolynomialRegression<T> {
11
- (data: T[]): PolynomialOutput;
12
- domain(): Domain;
13
- domain(domain?: Domain): this;
14
- x(): Accessor<T>;
15
- x(x: Accessor<T>): this;
16
- y(): Accessor<T>;
17
- y(y: Accessor<T>): this;
18
- order(): number;
19
- order(order: number): this;
20
- }
21
- export default function polynomial<T = DataPoint>(): PolynomialRegression<T>;
@@ -1,160 +0,0 @@
1
- /**
2
- * Adapted from https://github.com/HarryStevens/d3-regression
3
- */
4
- // Adapted from regression-js by Tom Alexander
5
- // Source: https://github.com/Tom-Alexander/regression-js/blob/master/src/regression.js#L246
6
- // License: https://github.com/Tom-Alexander/regression-js/blob/master/LICENSE
7
- // ...with ideas from vega-statistics by Jeffrey Heer
8
- // Source: https://github.com/vega/vega/blob/f21cb8792b4e0cbe2b1a3fd44b0f5db370dbaadb/packages/vega-statistics/src/regression/poly.js
9
- // License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
10
- import { determination } from './utils/determination';
11
- import { interpose } from './utils/interpose';
12
- import { points, visitPoints } from './utils/points';
13
- import linear from './linear';
14
- import quad from './quadratic';
15
- export default function polynomial() {
16
- let x = (d) => d[0], y = (d) => d[1], order = 3, domain;
17
- const polynomialRegression = function polynomialRegression(data) {
18
- // Shortcut for lower-order polynomials:
19
- if (order === 1) {
20
- const o = linear().x(x).y(y).domain(domain)(data);
21
- const result = [o[0], o[1]];
22
- result.coefficients = [o.b, o.a];
23
- result.predict = o.predict;
24
- result.rSquared = o.rSquared;
25
- return result;
26
- }
27
- if (order === 2) {
28
- const o = quad().x(x).y(y).domain(domain)(data);
29
- const result = [o[0], o[1]];
30
- result.coefficients = [o.c, o.b, o.a];
31
- result.predict = o.predict;
32
- result.rSquared = o.rSquared;
33
- return result;
34
- }
35
- const [xv, yv, ux, uy] = points(data, x, y);
36
- const n = xv.length;
37
- const k = order + 1;
38
- const lhs = [];
39
- const rhs = [];
40
- let Y = 0, n0 = 0, xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity;
41
- visitPoints(data, x, y, (dx, dy) => {
42
- n0++;
43
- Y += (dy - Y) / n0;
44
- if (!domain) {
45
- if (dx < xmin)
46
- xmin = dx;
47
- if (dx > xmax)
48
- xmax = dx;
49
- }
50
- });
51
- // Build normal equations
52
- for (let i = 0; i < k; i++) {
53
- // LHS
54
- let v = 0;
55
- for (let l = 0; l < n; l++) {
56
- v += Math.pow(xv[l], i) * yv[l];
57
- }
58
- lhs.push(v);
59
- // RHS
60
- const c = new Float64Array(k);
61
- for (let j = 0; j < k; j++) {
62
- let v2 = 0;
63
- for (let l = 0; l < n; l++) {
64
- v2 += Math.pow(xv[l], i + j);
65
- }
66
- c[j] = v2;
67
- }
68
- rhs.push(c);
69
- }
70
- rhs.push(new Float64Array(lhs));
71
- const coef = gaussianElimination(rhs);
72
- const fn = (xx) => {
73
- let shifted = xx - ux;
74
- let val = uy + coef[0];
75
- for (let i = 1; i < k; i++) {
76
- val += coef[i] * Math.pow(shifted, i);
77
- }
78
- return val;
79
- };
80
- const out = interpose(xmin, xmax, fn);
81
- out.coefficients = uncenter(k, coef, -ux, uy);
82
- out.predict = fn;
83
- out.rSquared = determination(data, x, y, Y, fn);
84
- return out;
85
- };
86
- polynomialRegression.domain = function (arr) {
87
- if (!arguments.length)
88
- return domain;
89
- domain = arr;
90
- return polynomialRegression;
91
- };
92
- polynomialRegression.x = function (fn) {
93
- if (!arguments.length)
94
- return x;
95
- x = fn;
96
- return polynomialRegression;
97
- };
98
- polynomialRegression.y = function (fn) {
99
- if (!arguments.length)
100
- return y;
101
- y = fn;
102
- return polynomialRegression;
103
- };
104
- polynomialRegression.order = function (n) {
105
- if (!arguments.length)
106
- return order;
107
- order = n;
108
- return polynomialRegression;
109
- };
110
- return polynomialRegression;
111
- }
112
- function uncenter(k, a, x, y) {
113
- const z = new Array(k).fill(0);
114
- for (let i = k - 1; i >= 0; --i) {
115
- let v = a[i];
116
- z[i] += v;
117
- let c = 1;
118
- for (let j = 1; j <= i; ++j) {
119
- c *= (i + 1 - j) / j; // binomial coefficient
120
- z[i - j] += v * Math.pow(x, j) * c;
121
- }
122
- }
123
- // bias term
124
- z[0] += y;
125
- return z;
126
- }
127
- // Solve A * x = b using Gaussian elimination
128
- function gaussianElimination(matrix) {
129
- const n = matrix.length - 1;
130
- const coef = new Array(n);
131
- for (let i = 0; i < n; i++) {
132
- let r = i;
133
- // find pivot row
134
- for (let j = i + 1; j < n; j++) {
135
- if (Math.abs(matrix[i][j]) > Math.abs(matrix[i][r])) {
136
- r = j;
137
- }
138
- }
139
- // swap columns
140
- for (let k = i; k < n + 1; k++) {
141
- const t = matrix[k][i];
142
- matrix[k][i] = matrix[k][r];
143
- matrix[k][r] = t;
144
- }
145
- // reduce
146
- for (let j = i + 1; j < n; j++) {
147
- for (let k = n; k >= i; k--) {
148
- matrix[k][j] -= (matrix[k][i] * matrix[i][j]) / matrix[i][i];
149
- }
150
- }
151
- }
152
- for (let j = n - 1; j >= 0; j--) {
153
- let t = 0;
154
- for (let k = j + 1; k < n; k++) {
155
- t += matrix[k][j] * coef[k];
156
- }
157
- coef[j] = (matrix[n][j] - t) / matrix[j][j];
158
- }
159
- return coef;
160
- }
@@ -1,18 +0,0 @@
1
- import type { PredictFunction, DataPoint, Accessor, Domain } from './types.js';
2
- export type PowerOutput = [DataPoint, DataPoint] & {
3
- a: number;
4
- b: number;
5
- predict: PredictFunction;
6
- rSquared: number;
7
- };
8
- interface PowerRegression<T> {
9
- (data: T[]): PowerOutput;
10
- domain(): Domain;
11
- domain(domain?: Domain): this;
12
- x(): Accessor<T>;
13
- x(x: Accessor<T>): this;
14
- y(): Accessor<T>;
15
- y(y: Accessor<T>): this;
16
- }
17
- export default function power<T = DataPoint>(): PowerRegression<T>;
18
- export {};
@@ -1,56 +0,0 @@
1
- /**
2
- * Adapted from https://github.com/HarryStevens/d3-regression
3
- */
4
- import { determination } from './utils/determination.js';
5
- import { interpose } from './utils/interpose.js';
6
- import { ols } from './utils/ols.js';
7
- import { visitPoints } from './utils/points.js';
8
- export default function power() {
9
- let x = (d) => d[0], y = (d) => d[1], domain;
10
- const powerRegression = function powerRegression(data) {
11
- let n = 0, X = 0, Y = 0, XY = 0, X2 = 0, YS = 0, xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity;
12
- visitPoints(data, x, y, (dx, dy) => {
13
- const lx = Math.log(dx), ly = Math.log(dy);
14
- ++n;
15
- X += (lx - X) / n;
16
- Y += (ly - Y) / n;
17
- XY += (lx * ly - XY) / n;
18
- X2 += (lx * lx - X2) / n;
19
- YS += (dy - YS) / n;
20
- if (!domain) {
21
- if (dx < xmin)
22
- xmin = dx;
23
- if (dx > xmax)
24
- xmax = dx;
25
- }
26
- });
27
- let [a, b] = ols(X, Y, XY, X2);
28
- a = Math.exp(a);
29
- const fn = (xx) => a * Math.pow(xx, b);
30
- const out = interpose(xmin, xmax, fn);
31
- out.a = a;
32
- out.b = b;
33
- out.predict = fn;
34
- out.rSquared = determination(data, x, y, YS, fn);
35
- return out;
36
- };
37
- powerRegression.domain = function (arr) {
38
- if (!arguments.length)
39
- return domain;
40
- domain = arr;
41
- return powerRegression;
42
- };
43
- powerRegression.x = function (fn) {
44
- if (!arguments.length)
45
- return x;
46
- x = fn;
47
- return powerRegression;
48
- };
49
- powerRegression.y = function (fn) {
50
- if (!arguments.length)
51
- return y;
52
- y = fn;
53
- return powerRegression;
54
- };
55
- return powerRegression;
56
- }
@@ -1,19 +0,0 @@
1
- import type { Accessor, DataPoint, PredictFunction, Domain } from './types.js';
2
- export type QuadraticOutput = [DataPoint, DataPoint] & {
3
- a: number;
4
- b: number;
5
- c: number;
6
- predict: PredictFunction;
7
- rSquared: number;
8
- };
9
- interface QuadraticRegression<T> {
10
- (data: T[]): QuadraticOutput;
11
- domain(): Domain;
12
- domain(domain?: Domain): this;
13
- x(): Accessor<T>;
14
- x(x: Accessor<T>): this;
15
- y(): Accessor<T>;
16
- y(y: Accessor<T>): this;
17
- }
18
- export default function quadratic<T = DataPoint>(): QuadraticRegression<T>;
19
- export {};
@@ -1,70 +0,0 @@
1
- /**
2
- * Adapted from https://github.com/HarryStevens/d3-regression
3
- */
4
- import { determination } from './utils/determination.js';
5
- import { interpose } from './utils/interpose.js';
6
- import { points, visitPoints } from './utils/points.js';
7
- export default function quadratic() {
8
- let x = (d) => d[0], y = (d) => d[1], domain;
9
- const quadraticRegression = function quadraticRegression(data) {
10
- const [xv, yv, ux, uy] = points(data, (dd) => x(dd), (dd) => y(dd));
11
- const n = xv.length;
12
- let X2 = 0, X3 = 0, X4 = 0, XY = 0, X2Y = 0, i, dx, dy, x2;
13
- for (i = 0; i < n;) {
14
- dx = xv[i];
15
- dy = yv[i++];
16
- x2 = dx * dx;
17
- X2 += (x2 - X2) / i;
18
- X3 += (x2 * dx - X3) / i;
19
- X4 += (x2 * x2 - X4) / i;
20
- XY += (dx * dy - XY) / i;
21
- X2Y += (x2 * dy - X2Y) / i;
22
- }
23
- let Y = 0, n0 = 0, xmin = domain ? +domain[0] : Infinity, xmax = domain ? +domain[1] : -Infinity;
24
- visitPoints(data, x, y, (dx2, dy2) => {
25
- n0++;
26
- Y += (dy2 - Y) / n0;
27
- if (!domain) {
28
- if (dx2 < xmin)
29
- xmin = dx2;
30
- if (dx2 > xmax)
31
- xmax = dx2;
32
- }
33
- });
34
- const X2X2 = X4 - X2 * X2;
35
- const d = X2 * X2X2 - X3 * X3;
36
- const a = (X2Y * X2 - XY * X3) / d;
37
- const b = (XY * X2X2 - X2Y * X3) / d;
38
- const c = -a * X2;
39
- const fn = (xx) => {
40
- const shifted = xx - ux;
41
- return a * shifted * shifted + b * shifted + c + uy;
42
- };
43
- const out = interpose(xmin, xmax, fn);
44
- out.a = a;
45
- out.b = b - 2 * a * ux;
46
- out.c = c - b * ux + a * ux * ux + uy;
47
- out.predict = fn;
48
- out.rSquared = determination(data, x, y, Y, fn);
49
- return out;
50
- };
51
- quadraticRegression.domain = function (arr) {
52
- if (!arguments.length)
53
- return domain;
54
- domain = arr;
55
- return quadraticRegression;
56
- };
57
- quadraticRegression.x = function (fn) {
58
- if (!arguments.length)
59
- return x;
60
- x = fn;
61
- return quadraticRegression;
62
- };
63
- quadraticRegression.y = function (fn) {
64
- if (!arguments.length)
65
- return y;
66
- y = fn;
67
- return quadraticRegression;
68
- };
69
- return quadraticRegression;
70
- }
@@ -1,4 +0,0 @@
1
- export type DataPoint = [number, number];
2
- export type Accessor<T> = (d: T, i?: number, data?: T[]) => number;
3
- export type PredictFunction = (x: number) => number;
4
- export type Domain = [number, number] | undefined;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { Accessor, PredictFunction } from '../types';
2
- /**
3
- * Given a dataset, x- and y-accessors, the mean center of the y-values (uY),
4
- * and a prediction function, return the coefficient of determination, R^2.
5
- */
6
- export declare function determination<T>(data: T[], x: Accessor<T>, y: Accessor<T>, uY: number, predict: PredictFunction): number;
@@ -1,16 +0,0 @@
1
- import { visitPoints } from './points';
2
- /**
3
- * Given a dataset, x- and y-accessors, the mean center of the y-values (uY),
4
- * and a prediction function, return the coefficient of determination, R^2.
5
- */
6
- export function determination(data, x, y, uY, predict) {
7
- let SSE = 0, // Sum of Squared Errors
8
- SST = 0; // Total Sum of Squares
9
- visitPoints(data, x, y, (dx, dy) => {
10
- const sse = dy - predict(dx);
11
- const sst = dy - uY;
12
- SSE += sse * sse;
13
- SST += sst * sst;
14
- });
15
- return 1 - SSE / SST;
16
- }
@@ -1,9 +0,0 @@
1
- import type { DataPoint } from '../types';
2
- /**
3
- * Returns the angle of a line in degrees.
4
- */
5
- export declare function angle(line: [DataPoint, DataPoint]): number;
6
- /**
7
- * Returns the midpoint of a line.
8
- */
9
- export declare function midpoint(line: [DataPoint, DataPoint]): DataPoint;
@@ -1,12 +0,0 @@
1
- /**
2
- * Returns the angle of a line in degrees.
3
- */
4
- export function angle(line) {
5
- return Math.atan2(line[1][1] - line[0][1], line[1][0] - line[0][0]) * (180 / Math.PI);
6
- }
7
- /**
8
- * Returns the midpoint of a line.
9
- */
10
- export function midpoint(line) {
11
- return [(line[0][0] + line[1][0]) / 2, (line[0][1] + line[1][1]) / 2];
12
- }
@@ -1,6 +0,0 @@
1
- import type { PredictFunction, DataPoint } from '../types';
2
- /**
3
- * Given a start point (xmin), an end point (xmax),
4
- * and a prediction function, returns a smooth line.
5
- */
6
- export declare function interpose(xmin: number, xmax: number, predict: PredictFunction): [DataPoint, DataPoint];
@@ -1,37 +0,0 @@
1
- import { angle, midpoint } from './geometry';
2
- /**
3
- * Given a start point (xmin), an end point (xmax),
4
- * and a prediction function, returns a smooth line.
5
- */
6
- export function interpose(xmin, xmax, predict) {
7
- const l = (Math.log(xmax - xmin) * Math.LOG10E + 1) | 0;
8
- const precision = Math.pow(10, -l / 2 - 1);
9
- const maxIter = 1e4;
10
- let points = [px(xmin), px(xmax)];
11
- let iter = 0;
12
- while (find(points) && iter < maxIter)
13
- ;
14
- return points;
15
- function px(x) {
16
- return [x, predict(x)];
17
- }
18
- function find(points) {
19
- iter++;
20
- const n = points.length;
21
- let found = false;
22
- for (let i = 0; i < n - 1; i++) {
23
- const p0 = points[i];
24
- const p1 = points[i + 1];
25
- const m = midpoint([p0, p1]);
26
- const mp = px(m[0]);
27
- const a0 = angle([p0, m]);
28
- const a1 = angle([p0, mp]);
29
- const a = Math.abs(a0 - a1);
30
- if (a > precision) {
31
- points.splice(i + 1, 0, mp);
32
- found = true;
33
- }
34
- }
35
- return found;
36
- }
37
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the median value of an array of numbers.
3
- */
4
- export declare function median(arr: Float64Array): number;
@@ -1,8 +0,0 @@
1
- /**
2
- * Returns the median value of an array of numbers.
3
- */
4
- export function median(arr) {
5
- arr.sort((a, b) => a - b);
6
- var i = arr.length / 2;
7
- return i % 1 === 0 ? (arr[i - 1] + arr[i]) / 2 : arr[Math.floor(i)];
8
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Ordinary Least Squares from vega-statistics by Jeffrey Heer
3
- * License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
4
- * Source: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/packages/vega-statistics/src/regression/ols.js
5
- */
6
- export declare function ols(uX: number, uY: number, uXY: number, uX2: number): [number, number];
@@ -1,9 +0,0 @@
1
- /**
2
- * Ordinary Least Squares from vega-statistics by Jeffrey Heer
3
- * License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
4
- * Source: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/packages/vega-statistics/src/regression/ols.js
5
- */
6
- export function ols(uX, uY, uXY, uX2) {
7
- const delta = uX2 - uX * uX, slope = Math.abs(delta) < 1e-24 ? 0 : (uXY - uX * uY) / delta, intercept = uY - slope * uX;
8
- return [intercept, slope];
9
- }
@@ -1,11 +0,0 @@
1
- import type { Accessor } from '../types';
2
- /**
3
- * Adapted from vega-statistics by Jeffrey Heer
4
- * License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
5
- * Source: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/packages/vega-statistics/src/regression/points.js
6
- */
7
- export declare function points<T>(data: T[], x: Accessor<T>, y: Accessor<T>, sort?: boolean): [Float64Array, Float64Array, number, number];
8
- /**
9
- * Iterates over valid data points, invoking a callback for each.
10
- */
11
- export declare function visitPoints<T>(data: T[], x: Accessor<T>, y: Accessor<T>, cb: (dx: number, dy: number, index: number) => void): void;
@@ -1,45 +0,0 @@
1
- /**
2
- * Adapted from vega-statistics by Jeffrey Heer
3
- * License: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/LICENSE
4
- * Source: https://github.com/vega/vega/blob/f058b099decad9db78301405dd0d2e9d8ba3d51a/packages/vega-statistics/src/regression/points.js
5
- */
6
- export function points(data, x, y, sort) {
7
- data = data.filter((d, i) => {
8
- let u = x(d, i), v = y(d, i);
9
- return u != null && isFinite(u) && v != null && isFinite(v);
10
- });
11
- if (sort) {
12
- data.sort((a, b) => x(a) - x(b));
13
- }
14
- const n = data.length, X = new Float64Array(n), Y = new Float64Array(n);
15
- // extract values, calculate means
16
- let ux = 0, uy = 0, xv, yv, d;
17
- for (let i = 0; i < n;) {
18
- d = data[i];
19
- X[i] = xv = +x(d, i, data);
20
- Y[i] = yv = +y(d, i, data);
21
- ++i;
22
- ux += (xv - ux) / i;
23
- uy += (yv - uy) / i;
24
- }
25
- // mean center the data
26
- for (let i = 0; i < n; ++i) {
27
- X[i] -= ux;
28
- Y[i] -= uy;
29
- }
30
- return [X, Y, ux, uy];
31
- }
32
- /**
33
- * Iterates over valid data points, invoking a callback for each.
34
- */
35
- export function visitPoints(data, x, y, cb) {
36
- let iterations = 0;
37
- for (let i = 0; i < data.length; i++) {
38
- const d = data[i];
39
- const dx = +x(d, i, data);
40
- const dy = +y(d, i, data);
41
- if (dx != null && isFinite(dx) && dy != null && isFinite(dy)) {
42
- cb(dx, dy, iterations++);
43
- }
44
- }
45
- }