vvplot 0.7.0 → 0.7.2
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 +2 -2
- package/dist/base-utils.d.ts +1 -0
- package/dist/base-utils.esm.js +1 -0
- package/dist/base-utils.esm.min.js +1 -0
- package/dist/base.d.ts +1002 -0
- package/dist/base.esm.js +1 -0
- package/dist/base.esm.min.js +1 -0
- package/dist/chunk-GeomViolin.js +26359 -0
- package/dist/chunk-GeomViolin.min.js +27 -0
- package/dist/chunk-base.js +5099 -0
- package/dist/chunk-base.min.js +1 -0
- package/dist/chunk-components.js +8833 -0
- package/dist/chunk-components.min.js +17 -0
- package/dist/chunk-utils.js +503 -0
- package/dist/chunk-utils.min.js +1 -0
- package/dist/chunk-utils2.js +195 -0
- package/dist/chunk-utils2.min.js +1 -0
- package/dist/components.d.ts +160 -0
- package/dist/components.esm.js +3 -0
- package/dist/components.esm.min.js +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.esm.js +3 -0
- package/dist/utils.esm.min.js +1 -0
- package/dist/vvplot.d.ts +1401 -573
- package/dist/vvplot.esm.js +19 -39541
- package/dist/vvplot.esm.min.js +1 -43
- package/dist/vvplot.global.js +10548 -9137
- package/dist/vvplot.global.min.js +26 -26
- package/package.json +20 -4
- package/dist/style.css +0 -6
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { exportSVG, serializeSVG } from "./chunk-utils2.js";
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __esmMin = (fn, res, err) => () => {
|
|
10
|
+
if (err) throw err[0];
|
|
11
|
+
try {
|
|
12
|
+
return fn && (res = fn(fn = 0)), res;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw err = [e], e;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
18
|
+
var __exportAll = (all, flags) => {
|
|
19
|
+
let target = Object.setPrototypeOf({}, null);
|
|
20
|
+
for (var name in all) __defProp(target, name, {
|
|
21
|
+
get: all[name],
|
|
22
|
+
enumerable: true
|
|
23
|
+
});
|
|
24
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
25
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
30
|
+
desc = __getOwnPropDesc(from, key);
|
|
31
|
+
__defProp(to, key, {
|
|
32
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
33
|
+
enumerable: !desc || desc.enumerable
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return to;
|
|
38
|
+
};
|
|
39
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
40
|
+
value: mod,
|
|
41
|
+
enumerable: true
|
|
42
|
+
}) : target, mod));
|
|
43
|
+
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
|
+
// src/js/utils.js
|
|
45
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
46
|
+
Asis: () => Asis,
|
|
47
|
+
EnumElement: () => EnumElement,
|
|
48
|
+
EnumLevel: () => EnumLevel,
|
|
49
|
+
categorize: () => categorize,
|
|
50
|
+
deepEqual: () => deepEqual,
|
|
51
|
+
exportSVG: () => exportSVG,
|
|
52
|
+
interaction: () => interaction,
|
|
53
|
+
intraaction: () => intraaction,
|
|
54
|
+
intrazip: () => intrazip,
|
|
55
|
+
is_categorical: () => is_categorical,
|
|
56
|
+
is_continuous: () => is_continuous,
|
|
57
|
+
numutils: () => numutils,
|
|
58
|
+
obj_merge: () => obj_merge,
|
|
59
|
+
oob_censor: () => oob_censor,
|
|
60
|
+
oob_squish_any: () => oob_squish_any,
|
|
61
|
+
oob_squish_infinite: () => oob_squish_infinite,
|
|
62
|
+
plus: () => plus,
|
|
63
|
+
serializeSVG: () => serializeSVG,
|
|
64
|
+
str_c: () => str_c,
|
|
65
|
+
unique: () => unique,
|
|
66
|
+
vecutils: () => vecutils
|
|
67
|
+
});
|
|
68
|
+
var AsisString = class extends String {
|
|
69
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
70
|
+
constructor(str) {
|
|
71
|
+
const x = String(str);
|
|
72
|
+
if (new.target.#cache.has(x)) return new.target.#cache.get(x);
|
|
73
|
+
super(x);
|
|
74
|
+
new.target.#cache.set(x, this);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var AsisNumber = class extends Number {
|
|
78
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
79
|
+
constructor(num) {
|
|
80
|
+
const n = Number(num);
|
|
81
|
+
if (new.target.#cache.has(n)) return new.target.#cache.get(n);
|
|
82
|
+
super(n);
|
|
83
|
+
new.target.#cache.set(n, this);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var Asis = class {
|
|
87
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
88
|
+
constructor(value) {
|
|
89
|
+
if (typeof value === "string" || value instanceof String) return new AsisString(value);
|
|
90
|
+
if (typeof value === "number" || value instanceof Number) return new AsisNumber(value);
|
|
91
|
+
throw new Error("Unsupported type");
|
|
92
|
+
}
|
|
93
|
+
static [Symbol.hasInstance](obj) {
|
|
94
|
+
return obj instanceof AsisString || obj instanceof AsisNumber;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var EnumElement = class {
|
|
98
|
+
constructor(label, value, level) {
|
|
99
|
+
this.label = label;
|
|
100
|
+
this.value = value;
|
|
101
|
+
this.level = level;
|
|
102
|
+
}
|
|
103
|
+
toString() {
|
|
104
|
+
return this.label;
|
|
105
|
+
}
|
|
106
|
+
valueOf() {
|
|
107
|
+
return this.value;
|
|
108
|
+
}
|
|
109
|
+
toJSON() {
|
|
110
|
+
return this.label;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var EnumLevel = class extends Array {
|
|
114
|
+
/**
|
|
115
|
+
* return:
|
|
116
|
+
* x if x is a EnumLevel
|
|
117
|
+
* new EnumLevel from distinct values of x, ordered by natural order, if x is iterable
|
|
118
|
+
* new EnumLevel from keys of x, orderd by coresponing values, if x is an object
|
|
119
|
+
* @param {*} x
|
|
120
|
+
* @param {function} [sortkey]
|
|
121
|
+
* @returns {EnumLevel}
|
|
122
|
+
*/
|
|
123
|
+
static from(x) {
|
|
124
|
+
if (x instanceof this) return x;
|
|
125
|
+
if (x[Symbol.iterator]) {
|
|
126
|
+
let lvl = unique(Array.from(x).filter((x) => !(x instanceof Asis) && x != null).map((x) => String(x))).sort((a, b) => compare(a, b, { numeric: true }));
|
|
127
|
+
return new this(...lvl);
|
|
128
|
+
} else if (typeof x === "object") {
|
|
129
|
+
let lvl = Object.keys(x).map((x) => String(x)).sort((a, b) => compare(x[a], x[b]));
|
|
130
|
+
return new this(...lvl);
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`Invalid level values: ${x}`);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if two EnumLevel are equal, i.e. they have the same labels in the same order
|
|
136
|
+
* @param {string[]} level
|
|
137
|
+
*/
|
|
138
|
+
static isEqual(a, b) {
|
|
139
|
+
if (a instanceof this && b instanceof this) return a.length === b.length && Array(a.length).fill().every((_, i) => a[i].label === b[i].label);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* build a EnumLevel
|
|
143
|
+
* @param {string[]} level
|
|
144
|
+
*/
|
|
145
|
+
constructor(...level) {
|
|
146
|
+
level = level.map((x, i) => new EnumElement(String(x), i));
|
|
147
|
+
level.forEach((l) => l.level = level);
|
|
148
|
+
level.mapping = Object.fromEntries(level.map((fct) => [fct, fct]));
|
|
149
|
+
Object.setPrototypeOf(level, new.target.prototype);
|
|
150
|
+
return level;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* get the level instance by index or key
|
|
154
|
+
* @param {(number|string)} idx
|
|
155
|
+
* @returns {EnumElement}
|
|
156
|
+
*/
|
|
157
|
+
getItem(idx) {
|
|
158
|
+
if (typeof idx === "number" || idx instanceof Number) return this[idx];
|
|
159
|
+
else return this.mapping[idx];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* convert an array to a GEnum array
|
|
163
|
+
* @param {string[]} arr array to be converted, preferably a string array (items of other types will be converted to string)
|
|
164
|
+
* @returns {EnumElement[]}
|
|
165
|
+
*/
|
|
166
|
+
apply(arr) {
|
|
167
|
+
let result = arr.map((x) => x instanceof Asis ? x : this.mapping[x]);
|
|
168
|
+
result.level = this;
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
function is_continuous(x) {
|
|
173
|
+
return typeof x === "number" || x instanceof Number || x instanceof Date;
|
|
174
|
+
}
|
|
175
|
+
function is_categorical(v) {
|
|
176
|
+
return typeof v === "string" || typeof v === "boolean" || typeof v === "symbol" || typeof v === "object" && v !== null && typeof v.valueOf() !== "number" && typeof v.valueOf() !== "bigint";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Add two numeric values, with special handling of semantic values.
|
|
180
|
+
* - If `a` is `null` or `undefined`, return `a`.
|
|
181
|
+
* - If `a` is a `Date`, return a new `Date` with the time value of `a` plus `b`.
|
|
182
|
+
* - Otherwise, return the sum of `a` and `b`.
|
|
183
|
+
* @param {number|Date|null|undefined} a The first value to add.
|
|
184
|
+
* @param {number} b The second value to add.
|
|
185
|
+
* @returns The sum of the two values.
|
|
186
|
+
*/
|
|
187
|
+
function plus(a, b = 0) {
|
|
188
|
+
if (b == 0 || a == null) return a;
|
|
189
|
+
if (a instanceof Date) return new a.constructor(+a + b);
|
|
190
|
+
return +a + b;
|
|
191
|
+
}
|
|
192
|
+
var numutils = {
|
|
193
|
+
min(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
194
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
195
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
196
|
+
return Array.from(arr).reduce((a, b) => a < b ? a : b, 1e400);
|
|
197
|
+
},
|
|
198
|
+
max(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
199
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
200
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
201
|
+
return Array.from(arr).reduce((a, b) => a > b ? a : b, -1e400);
|
|
202
|
+
},
|
|
203
|
+
sum(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
204
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
205
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
206
|
+
return Array.from(arr).reduce((a, b) => a + b, 0);
|
|
207
|
+
},
|
|
208
|
+
diff(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
209
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
210
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
211
|
+
return Array.from(arr).slice(1).map((v, i) => v - arr[i]);
|
|
212
|
+
},
|
|
213
|
+
mean(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
214
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
215
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
216
|
+
if (arr.length == 0) return NaN;
|
|
217
|
+
return Array.from(arr).reduce((a, v) => a + v, 0) / arr.length;
|
|
218
|
+
},
|
|
219
|
+
sd(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
220
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
221
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
222
|
+
if (arr.length <= 1) return NaN;
|
|
223
|
+
let mean = Array.from(arr).reduce((a, v) => a + v, 0) / arr.length;
|
|
224
|
+
return Math.sqrt(Array.from(arr).reduce((a, v) => a + (v - mean) ** 2, 0) / (arr.length - 1));
|
|
225
|
+
},
|
|
226
|
+
quantile(arr, p, { na_rm = true, infinity_rm = true } = {}) {
|
|
227
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
228
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
229
|
+
if (arr.length == 0) return NaN;
|
|
230
|
+
arr = Array.from(arr).sort((a, b) => a - b);
|
|
231
|
+
let idx = (arr.length - 1) * p, lo = Math.floor(idx), hi = Math.ceil(idx);
|
|
232
|
+
if (lo == hi) return arr[lo];
|
|
233
|
+
return arr[lo] * (hi - idx) + arr[hi] * (idx - lo);
|
|
234
|
+
},
|
|
235
|
+
extent(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
236
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
237
|
+
if (infinity_rm) arr = arr.filter((x) => isFinite(x));
|
|
238
|
+
if (arr.length == 0) return new Array(2);
|
|
239
|
+
let min = Array.from(arr).reduce((a, b) => a < b ? a : b, 1e400), max = Array.from(arr).reduce((a, b) => a > b ? a : b, -1e400);
|
|
240
|
+
return Object.assign([min, max], {
|
|
241
|
+
min,
|
|
242
|
+
max
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var vecutils = {
|
|
247
|
+
coalesce(value, defaultValue) {
|
|
248
|
+
if (Array.isArray(defaultValue)) {
|
|
249
|
+
if (!Array.isArray(value) || value.length != defaultValue.length) throw new Error("Value and defaultValue must be arrays of the same length");
|
|
250
|
+
return value.map((v, i) => v == null ? defaultValue[i] : v);
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(value)) return value.map((v) => v ?? defaultValue);
|
|
253
|
+
return value ?? defaultValue;
|
|
254
|
+
},
|
|
255
|
+
sum(...values) {
|
|
256
|
+
if (values.some((x) => x == null)) return null;
|
|
257
|
+
if (values.some((x) => !Array.isArray(x) && typeof x != "number")) throw new Error("Arguments must be numbers or arrays");
|
|
258
|
+
let nums = values.filter((x) => !Array.isArray(x)).reduce((s, a) => +a + s, 0);
|
|
259
|
+
values = values.filter((x) => Array.isArray(x));
|
|
260
|
+
if (values.length == 0) return [nums];
|
|
261
|
+
let length = values[0].length;
|
|
262
|
+
if (values.some((v) => v.length != length)) throw new Error("Arrays must have the same length");
|
|
263
|
+
return Array.from({ length }, (_, i) => values.reduce((s, a) => +(a[i] ?? void 0) + s, nums));
|
|
264
|
+
},
|
|
265
|
+
opposite(value) {
|
|
266
|
+
if (value == null) return null;
|
|
267
|
+
if (!Array.isArray(value) && typeof value != "number") throw new Error("Arguments must be numbers or arrays");
|
|
268
|
+
if (Array.isArray(value)) return value.map((v) => v == null ? v : -v);
|
|
269
|
+
return -value;
|
|
270
|
+
},
|
|
271
|
+
concat(...values) {
|
|
272
|
+
if (values.some((x) => x == null)) return null;
|
|
273
|
+
let arrs = values.filter((x) => Array.isArray(x));
|
|
274
|
+
if (arrs.length == 0) return [values.join("")];
|
|
275
|
+
if (values.some((v) => v.length == 0)) return [];
|
|
276
|
+
let length = arrs[0].length;
|
|
277
|
+
if (arrs.some((v) => v.length != length)) throw new Error("Arrays must have the same length");
|
|
278
|
+
return Array.from({ length }, (_, i) => values.map((a) => Array.isArray(a) ? a[i] : a).join(""));
|
|
279
|
+
},
|
|
280
|
+
apply(func, ...values) {
|
|
281
|
+
if (values.some((x) => x == null)) return null;
|
|
282
|
+
let arrs = values.filter((x) => Array.isArray(x));
|
|
283
|
+
if (arrs.length == 0) return [func(...values)];
|
|
284
|
+
if (values.some((v) => v.length == 0)) return [];
|
|
285
|
+
let length = arrs[0].length;
|
|
286
|
+
if (arrs.some((v) => v.length != length)) throw new Error("Arrays must have the same length");
|
|
287
|
+
return Array.from({ length }, (_, i) => func(...values.map((a) => Array.isArray(a) ? a[i] : a)));
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* (shallow) merge array of objects, from left to right
|
|
292
|
+
* `undefined` will be ignored
|
|
293
|
+
* `null` will reset the merge
|
|
294
|
+
* @param {Array} arr
|
|
295
|
+
* @returns {Object|null}
|
|
296
|
+
*/
|
|
297
|
+
function obj_merge(...arr) {
|
|
298
|
+
arr = arr.filter((x) => x !== void 0);
|
|
299
|
+
if (arr.length == 0) return void 0;
|
|
300
|
+
arr = arr.slice(arr.findIndex((x) => x == null) + 1);
|
|
301
|
+
if (arr.length == 0) return null;
|
|
302
|
+
return arr.reduce((a, c) => {
|
|
303
|
+
for (let k in c) if (c[k] !== void 0) a[k] = c[k];
|
|
304
|
+
return a;
|
|
305
|
+
}, {});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* concatenate strings, with special handling of `undefined` and `null`
|
|
309
|
+
* - if any argument is `undefined`, return `undefined`
|
|
310
|
+
* - else if any argument is `null`, return `null`
|
|
311
|
+
* - else return concatenated string
|
|
312
|
+
* @param {...(string|undefined|null)} args
|
|
313
|
+
* @returns {string|undefined|null}
|
|
314
|
+
*/
|
|
315
|
+
function str_c(...args) {
|
|
316
|
+
if (args.some((x) => x === void 0)) return void 0;
|
|
317
|
+
if (args.some((x) => x === null)) return null;
|
|
318
|
+
return args.join("");
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* return unique values in an array
|
|
322
|
+
* @param {Array} arr
|
|
323
|
+
* @param {function} [key] function to get the key of an item, default to identity function
|
|
324
|
+
* @param {function} [priority] function to get the priority of an item when there are duplicate keys, default to keep the first one
|
|
325
|
+
* @returns {Array}
|
|
326
|
+
*/
|
|
327
|
+
function unique(arr, key = null, priority = null) {
|
|
328
|
+
let map = /* @__PURE__ */ new Map();
|
|
329
|
+
for (let i in arr) {
|
|
330
|
+
let k = key ? key(arr[i]) : arr[i];
|
|
331
|
+
if (!map.has(k)) map.set(k, arr[i]);
|
|
332
|
+
else if (priority) map.set(k, priority(map.get(k), arr[i]));
|
|
333
|
+
}
|
|
334
|
+
return Array.from(map.values());
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* natural comparation of two item
|
|
338
|
+
* @param {*} a
|
|
339
|
+
* @param {*} b
|
|
340
|
+
* @returns {number}
|
|
341
|
+
*/
|
|
342
|
+
function compare(a, b, { numeric = false } = {}) {
|
|
343
|
+
if (typeof a != "number" || typeof b != "number") return String(a).localeCompare(String(b), void 0, { numeric });
|
|
344
|
+
return a - b;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* turn out-of-bounds values to NaN
|
|
348
|
+
* @param {number} value
|
|
349
|
+
* @param {Object} option
|
|
350
|
+
* @param {number} option.min lower bound
|
|
351
|
+
* @param {number} option.max upper bound
|
|
352
|
+
* @returns {number}
|
|
353
|
+
*/
|
|
354
|
+
function oob_censor(value, { min, max }) {
|
|
355
|
+
if (value < min || value > max) return NaN;
|
|
356
|
+
return value;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* turn out-of-bounds values to bounds
|
|
360
|
+
* @param {number} value
|
|
361
|
+
* @param {Object} option
|
|
362
|
+
* @param {number} option.min lower bound
|
|
363
|
+
* @param {number} option.max upper bound
|
|
364
|
+
* @returns {number}
|
|
365
|
+
*/
|
|
366
|
+
function oob_squish_any(value, { min, max }) {
|
|
367
|
+
if (value < min) return min;
|
|
368
|
+
if (value > max) return max;
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* turn infinite values to bounds
|
|
373
|
+
* @param {number} value
|
|
374
|
+
* @param {Object} option
|
|
375
|
+
* @param {number} option.min lower bound
|
|
376
|
+
* @param {number} option.max upper bound
|
|
377
|
+
* @returns {number}
|
|
378
|
+
*/
|
|
379
|
+
function oob_squish_infinite(value, { min, max }) {
|
|
380
|
+
if (value == -1e400) return min;
|
|
381
|
+
if (value == 1e400) return max;
|
|
382
|
+
return value;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* test deep equality between two values
|
|
386
|
+
* @param {*} a
|
|
387
|
+
* @param {*} b
|
|
388
|
+
* @param {function(*, *, number): boolean | undefined} [comparer] optional comparer function, will be applied before deep comparison, should return true/false or undefined (to continue deep comparison)
|
|
389
|
+
* @param {number} [level=0] the current depth of the comparison
|
|
390
|
+
* @returns {boolean}
|
|
391
|
+
*/
|
|
392
|
+
function deepEqual(a, b, comparer, level = 0) {
|
|
393
|
+
if (level > 25) throw new Error("deepEqual: maximum recursion depth exceeded");
|
|
394
|
+
if (comparer != null && typeof comparer !== "function") throw new Error("comparer must be a function");
|
|
395
|
+
if (a === b) return true;
|
|
396
|
+
if (comparer != null) {
|
|
397
|
+
let res = comparer(a, b, level);
|
|
398
|
+
if (res === true || res === false || res instanceof Boolean) return Boolean(res);
|
|
399
|
+
}
|
|
400
|
+
if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) return false;
|
|
401
|
+
let aKeys = Object.keys(a), bKeys = Object.keys(b);
|
|
402
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
403
|
+
for (let key of aKeys) if (!deepEqual(a[key], b[key], comparer, level + 1)) return false;
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Create a shallow categorical representation for a list of object.
|
|
408
|
+
* @param {object[]} array
|
|
409
|
+
* @param {function} [comparer] optional comparer function, will be passed to `deepEqual` to decide equality.
|
|
410
|
+
* @returns {number[]} result
|
|
411
|
+
* @returns {Array[]} result.categories
|
|
412
|
+
*/
|
|
413
|
+
function categorize(array, comparer) {
|
|
414
|
+
if (!Array.isArray(array)) throw new Error("Argument must be an array");
|
|
415
|
+
let categories = [], result = [];
|
|
416
|
+
for (let i = 0; i < array.length; i++) {
|
|
417
|
+
let obj = array[i];
|
|
418
|
+
let idx = categories.findIndex((cat) => deepEqual(cat, obj, comparer));
|
|
419
|
+
if (idx === -1) {
|
|
420
|
+
categories.push(obj);
|
|
421
|
+
idx = categories.length - 1;
|
|
422
|
+
}
|
|
423
|
+
result.push(idx);
|
|
424
|
+
}
|
|
425
|
+
result.categories = categories;
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Create a categorical representation for lists of data.
|
|
430
|
+
* i.e. `categorize` for multiple arrays
|
|
431
|
+
* @param {...any} arrays
|
|
432
|
+
* @returns {number[]} result
|
|
433
|
+
* @returns {Array[]} result.categories
|
|
434
|
+
*/
|
|
435
|
+
function interaction(...arrays) {
|
|
436
|
+
if (arrays.length == 0) return null;
|
|
437
|
+
let length = arrays.filter((x) => Array.isArray(x)).reduce((l, arr) => {
|
|
438
|
+
if (Array.isArray(arr)) {
|
|
439
|
+
if (l == null) return arr.length;
|
|
440
|
+
if (l != arr.length) throw new Error("Arrays must have the same length");
|
|
441
|
+
}
|
|
442
|
+
return l;
|
|
443
|
+
}, null) ?? 0;
|
|
444
|
+
let categories = [], result = [];
|
|
445
|
+
for (let i = 0; i < length; i++) {
|
|
446
|
+
let arr = arrays.map((x) => Array.isArray(x) ? x[i] : x);
|
|
447
|
+
let idx = categories.findIndex((x) => x.every((v, j) => v === arr[j]));
|
|
448
|
+
if (idx === -1) {
|
|
449
|
+
categories.push(arr);
|
|
450
|
+
idx = categories.length - 1;
|
|
451
|
+
}
|
|
452
|
+
result.push(idx);
|
|
453
|
+
}
|
|
454
|
+
result.categories = categories;
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Create a categorical representation for lists of data.
|
|
459
|
+
* i.e. `interaction` with key names
|
|
460
|
+
* @param {Object} arrays
|
|
461
|
+
* @returns {number[]} result
|
|
462
|
+
* @returns {object[]} result.categories
|
|
463
|
+
*/
|
|
464
|
+
function intraaction(arrays) {
|
|
465
|
+
if (Object.keys(arrays).length == 0) return null;
|
|
466
|
+
let length = Object.values(arrays).filter((x) => Array.isArray(x)).reduce((l, arr) => {
|
|
467
|
+
if (Array.isArray(arr)) {
|
|
468
|
+
if (l == null) return arr.length;
|
|
469
|
+
if (l != arr.length) throw new Error("Arrays must have the same length");
|
|
470
|
+
}
|
|
471
|
+
return l;
|
|
472
|
+
}, null) ?? 0;
|
|
473
|
+
let keys = Object.keys(arrays);
|
|
474
|
+
let categories = [], result = [];
|
|
475
|
+
for (let i = 0; i < length; i++) {
|
|
476
|
+
let arr = Object.fromEntries(keys.map((k) => [k, Array.isArray(arrays[k]) ? arrays[k][i] : arrays[k]]));
|
|
477
|
+
let idx = categories.findIndex((x) => keys.every((k) => x[k] === arr[k]));
|
|
478
|
+
if (idx === -1) {
|
|
479
|
+
categories.push(arr);
|
|
480
|
+
idx = categories.length - 1;
|
|
481
|
+
}
|
|
482
|
+
result.push(idx);
|
|
483
|
+
}
|
|
484
|
+
result.categories = categories;
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Turn dict of arrays into array of dicts
|
|
489
|
+
* @param {Object} arrays dict of arrays
|
|
490
|
+
* @returns {object[]} array of dicts
|
|
491
|
+
*/
|
|
492
|
+
function intrazip(arrays) {
|
|
493
|
+
if (Object.keys(arrays).length == 0) return [];
|
|
494
|
+
let length = Object.values(arrays).filter((x) => Array.isArray(x)).reduce((l, arr) => {
|
|
495
|
+
if (Array.isArray(arr)) {
|
|
496
|
+
if (l == null) return arr.length;
|
|
497
|
+
if (l != arr.length) throw new Error("Arrays must have the same length");
|
|
498
|
+
}
|
|
499
|
+
return l;
|
|
500
|
+
}, null) ?? 0;
|
|
501
|
+
return Array.from({ length }, (_, i) => Object.fromEntries(Object.keys(arrays).map((k) => [k, Array.isArray(arrays[k]) ? arrays[k][i] : arrays[k]])));
|
|
502
|
+
}
|
|
503
|
+
export { Asis, EnumElement, EnumLevel, __commonJSMin, __esmMin, __exportAll, __toCommonJS, __toESM, categorize, deepEqual, interaction, intraaction, intrazip, is_categorical, is_continuous, numutils, obj_merge, oob_censor, oob_squish_any, oob_squish_infinite, plus, str_c, unique, utils_exports, vecutils };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,s as t}from"./chunk-utils2.min.js";var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},l=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),u=(e,t)=>{let n=Object.setPrototypeOf({},null);for(var i in e)r(n,i,{get:e[i],enumerable:!0});return t&1||r(n,Symbol.toStringTag,{value:`Module`}),t&2?n:Object.preventExtensions(n)},d=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of a(t))!s.call(e,c)&&c!==n&&(o=i(t,c),r(e,c,{get:o&&o.get&&!o.configurable?o.get:()=>t[c],enumerable:!o||o.enumerable}));return e},f=(e,t,i)=>(i=e==null?{}:n(o(e)),d(t||!e||!e.__esModule||!s.call(e,`default`)?r(i,`default`,{value:e,enumerable:!0}):i,e)),p=e=>s.call(e,`module.exports`)?e[`module.exports`]:d(r({},`__esModule`,{value:!0}),e),m=/* @__PURE__ */ u({Asis:()=>_,EnumElement:()=>v,EnumLevel:()=>y,categorize:()=>N,deepEqual:()=>M,exportSVG:()=>e,interaction:()=>P,intraaction:()=>F,intrazip:()=>I,is_categorical:()=>x,is_continuous:()=>b,numutils:()=>C,obj_merge:()=>T,oob_censor:()=>k,oob_squish_any:()=>A,oob_squish_infinite:()=>j,plus:()=>S,serializeSVG:()=>t,str_c:()=>E,unique:()=>D,vecutils:()=>w}),h=class extends String{static#e=/* @__PURE__ */ new Map;constructor(e){let t=String(e);if(new.target.#e.has(t))return new.target.#e.get(t);super(t),new.target.#e.set(t,this)}},g=class extends Number{static#e=/* @__PURE__ */ new Map;constructor(e){let t=Number(e);if(new.target.#e.has(t))return new.target.#e.get(t);super(t),new.target.#e.set(t,this)}},_=class{constructor(e){if(typeof e==`string`||e instanceof String)return new h(e);if(typeof e==`number`||e instanceof Number)return new g(e);throw Error(`Unsupported type`)}static[Symbol.hasInstance](e){return e instanceof h||e instanceof g}},v=class{constructor(e,t,n){this.label=e,this.value=t,this.level=n}toString(){return this.label}valueOf(){return this.value}toJSON(){return this.label}},y=class extends Array{static from(e){if(e instanceof this)return e;if(e[Symbol.iterator]){let t=D(Array.from(e).filter(e=>!(e instanceof _)&&e!=null).map(e=>String(e))).sort((e,t)=>O(e,t,{numeric:!0}));return new this(...t)}if(typeof e==`object`){let t=Object.keys(e).map(e=>String(e)).sort((t,n)=>O(e[t],e[n]));return new this(...t)}throw Error(`Invalid level values: ${e}`)}static isEqual(e,t){if(e instanceof this&&t instanceof this)return e.length===t.length&&Array(e.length).fill().every((n,r)=>e[r].label===t[r].label)}constructor(...e){return e=e.map((e,t)=>new v(String(e),t)),e.forEach(t=>t.level=e),e.mapping=Object.fromEntries(e.map(e=>[e,e])),Object.setPrototypeOf(e,new.target.prototype),e}getItem(e){return typeof e==`number`||e instanceof Number?this[e]:this.mapping[e]}apply(e){let t=e.map(e=>e instanceof _?e:this.mapping[e]);return t.level=this,t}};function b(e){return typeof e==`number`||e instanceof Number||e instanceof Date}function x(e){return typeof e==`string`||typeof e==`boolean`||typeof e==`symbol`||typeof e==`object`&&!!e&&typeof e.valueOf()!=`number`&&typeof e.valueOf()!=`bigint`}function S(e,t=0){return t==0||e==null?e:e instanceof Date?new e.constructor(+e+t):+e+t}var C={min(e,{na_rm:t=!0,infinity_rm:n=!0}={}){return t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),Array.from(e).reduce((e,t)=>e<t?e:t,1/0)},max(e,{na_rm:t=!0,infinity_rm:n=!0}={}){return t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),Array.from(e).reduce((e,t)=>e>t?e:t,-1/0)},sum(e,{na_rm:t=!0,infinity_rm:n=!0}={}){return t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),Array.from(e).reduce((e,t)=>e+t,0)},diff(e,{na_rm:t=!0,infinity_rm:n=!0}={}){return t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),Array.from(e).slice(1).map((t,n)=>t-e[n])},mean(e,{na_rm:t=!0,infinity_rm:n=!0}={}){return t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),e.length==0?NaN:Array.from(e).reduce((e,t)=>e+t,0)/e.length},sd(e,{na_rm:t=!0,infinity_rm:n=!0}={}){if(t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),e.length<=1)return NaN;let r=Array.from(e).reduce((e,t)=>e+t,0)/e.length;return Math.sqrt(Array.from(e).reduce((e,t)=>e+(t-r)**2,0)/(e.length-1))},quantile(e,t,{na_rm:n=!0,infinity_rm:r=!0}={}){if(n&&(e=e.filter(b)),r&&(e=e.filter(e=>isFinite(e))),e.length==0)return NaN;e=Array.from(e).sort((e,t)=>e-t);let i=(e.length-1)*t,a=Math.floor(i),o=Math.ceil(i);return a==o?e[a]:e[a]*(o-i)+e[o]*(i-a)},extent(e,{na_rm:t=!0,infinity_rm:n=!0}={}){if(t&&(e=e.filter(b)),n&&(e=e.filter(e=>isFinite(e))),e.length==0)return[,,];let r=Array.from(e).reduce((e,t)=>e<t?e:t,1/0),i=Array.from(e).reduce((e,t)=>e>t?e:t,-1/0);return Object.assign([r,i],{min:r,max:i})}},w={coalesce(e,t){if(Array.isArray(t)){if(!Array.isArray(e)||e.length!=t.length)throw Error(`Value and defaultValue must be arrays of the same length`);return e.map((e,n)=>e??t[n])}return Array.isArray(e)?e.map(e=>e??t):e??t},sum(...e){if(e.some(e=>e==null))return null;if(e.some(e=>!Array.isArray(e)&&typeof e!=`number`))throw Error(`Arguments must be numbers or arrays`);let t=e.filter(e=>!Array.isArray(e)).reduce((e,t)=>+t+e,0);if(e=e.filter(e=>Array.isArray(e)),e.length==0)return[t];let n=e[0].length;if(e.some(e=>e.length!=n))throw Error(`Arrays must have the same length`);return Array.from({length:n},(n,r)=>e.reduce((e,t)=>+(t[r]??void 0)+e,t))},opposite(e){if(e==null)return null;if(!Array.isArray(e)&&typeof e!=`number`)throw Error(`Arguments must be numbers or arrays`);return Array.isArray(e)?e.map(e=>e==null?e:-e):-e},concat(...e){if(e.some(e=>e==null))return null;let t=e.filter(e=>Array.isArray(e));if(t.length==0)return[e.join(``)];if(e.some(e=>e.length==0))return[];let n=t[0].length;if(t.some(e=>e.length!=n))throw Error(`Arrays must have the same length`);return Array.from({length:n},(t,n)=>e.map(e=>Array.isArray(e)?e[n]:e).join(``))},apply(e,...t){if(t.some(e=>e==null))return null;let n=t.filter(e=>Array.isArray(e));if(n.length==0)return[e(...t)];if(t.some(e=>e.length==0))return[];let r=n[0].length;if(n.some(e=>e.length!=r))throw Error(`Arrays must have the same length`);return Array.from({length:r},(n,r)=>e(...t.map(e=>Array.isArray(e)?e[r]:e)))}};function T(...e){if(e=e.filter(e=>e!==void 0),e.length!=0)return e=e.slice(e.findIndex(e=>e==null)+1),e.length==0?null:e.reduce((e,t)=>{for(let n in t)t[n]!==void 0&&(e[n]=t[n]);return e},{})}function E(...e){if(!e.some(e=>e===void 0))return e.some(e=>e===null)?null:e.join(``)}function D(e,t=null,n=null){let r=/* @__PURE__ */ new Map;for(let i in e){let a=t?t(e[i]):e[i];r.has(a)?n&&r.set(a,n(r.get(a),e[i])):r.set(a,e[i])}return Array.from(r.values())}function O(e,t,{numeric:n=!1}={}){return typeof e!=`number`||typeof t!=`number`?String(e).localeCompare(String(t),void 0,{numeric:n}):e-t}function k(e,{min:t,max:n}){return e<t||e>n?NaN:e}function A(e,{min:t,max:n}){return e<t?t:e>n?n:e}function j(e,{min:t,max:n}){return e==-1/0?t:e==1/0?n:e}function M(e,t,n,r=0){if(r>25)throw Error(`deepEqual: maximum recursion depth exceeded`);if(n!=null&&typeof n!=`function`)throw Error(`comparer must be a function`);if(e===t)return!0;if(n!=null){let i=n(e,t,r);if(i===!0||i===!1||i instanceof Boolean)return!!i}if(typeof e!=`object`||typeof t!=`object`||e==null||t==null)return!1;let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let a of i)if(!M(e[a],t[a],n,r+1))return!1;return!0}function N(e,t){if(!Array.isArray(e))throw Error(`Argument must be an array`);let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=n.findIndex(e=>M(e,a,t));o===-1&&(n.push(a),o=n.length-1),r.push(o)}return r.categories=n,r}function P(...e){if(e.length==0)return null;let t=e.filter(e=>Array.isArray(e)).reduce((e,t)=>{if(Array.isArray(t)){if(e==null)return t.length;if(e!=t.length)throw Error(`Arrays must have the same length`)}return e},null)??0,n=[],r=[];for(let i=0;i<t;i++){let t=e.map(e=>Array.isArray(e)?e[i]:e),a=n.findIndex(e=>e.every((e,n)=>e===t[n]));a===-1&&(n.push(t),a=n.length-1),r.push(a)}return r.categories=n,r}function F(e){if(Object.keys(e).length==0)return null;let t=Object.values(e).filter(e=>Array.isArray(e)).reduce((e,t)=>{if(Array.isArray(t)){if(e==null)return t.length;if(e!=t.length)throw Error(`Arrays must have the same length`)}return e},null)??0,n=Object.keys(e),r=[],i=[];for(let a=0;a<t;a++){let t=Object.fromEntries(n.map(t=>[t,Array.isArray(e[t])?e[t][a]:e[t]])),o=r.findIndex(e=>n.every(n=>e[n]===t[n]));o===-1&&(r.push(t),o=r.length-1),i.push(o)}return i.categories=r,i}function I(e){if(Object.keys(e).length==0)return[];let t=Object.values(e).filter(e=>Array.isArray(e)).reduce((e,t)=>{if(Array.isArray(t)){if(e==null)return t.length;if(e!=t.length)throw Error(`Arrays must have the same length`)}return e},null)??0;return Array.from({length:t},(t,n)=>Object.fromEntries(Object.keys(e).map(t=>[t,Array.isArray(e[t])?e[t][n]:e[t]])))}export{u as C,c as S,f as T,E as _,M as a,w as b,I as c,C as d,T as f,S as g,j as h,N as i,x as l,A as m,v as n,P as o,k as p,y as r,F as s,_ as t,b as u,D as v,p as w,l as x,m as y};
|