@vitessce/utils 2.0.3-beta.0 → 3.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/dist/index.js +15764 -5
- package/dist-tsc/Pool.d.ts +20 -0
- package/dist-tsc/Pool.d.ts.map +1 -0
- package/dist-tsc/components.d.ts +35 -0
- package/dist-tsc/components.d.ts.map +1 -0
- package/dist-tsc/gating.d.ts +18 -0
- package/dist-tsc/gating.d.ts.map +1 -0
- package/dist-tsc/index.d.ts +6 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +7 -0
- package/dist-tsc/interpolate-colors.d.ts +22 -0
- package/dist-tsc/interpolate-colors.d.ts.map +1 -0
- package/{dist → dist-tsc}/interpolate-colors.js +10 -24
- package/dist-tsc/interpolate-colors.test.d.ts +2 -0
- package/dist-tsc/interpolate-colors.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/interpolate-colors.test.js +1 -1
- package/dist-tsc/root.d.ts +26 -0
- package/dist-tsc/root.d.ts.map +1 -0
- package/package.json +15 -6
- package/src/Pool.js +64 -0
- package/src/components.js +142 -0
- package/src/gating.js +30 -0
- package/src/index.js +12 -0
- package/src/interpolate-colors.js +104 -0
- package/src/interpolate-colors.test.js +29 -0
- package/src/root.js +84 -0
- /package/{dist → dist-tsc}/Pool.js +0 -0
- /package/{dist → dist-tsc}/components.js +0 -0
- /package/{dist → dist-tsc}/gating.js +0 -0
- /package/{dist → dist-tsc}/root.js +0 -0
package/src/root.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* eslint-disable no-plusplus */
|
|
2
|
+
// Originally in src/utils.js
|
|
3
|
+
|
|
4
|
+
// Adapted from https://github.com/feross/fromentries/blob/29b52a850bb3a47c390937631c2638edf3443942/index.js
|
|
5
|
+
export function fromEntries(iterable) {
|
|
6
|
+
return [...iterable]
|
|
7
|
+
.reduce((obj, { 0: key, 1: val }) => Object.assign(obj, { [key]: val }), {});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function commaNumber(n) {
|
|
11
|
+
const nf = new Intl.NumberFormat('en-US');
|
|
12
|
+
return nf.format(n);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Capitalize a the first letter of a string.
|
|
17
|
+
* @param {string} word A string to capitalize.
|
|
18
|
+
* @returns {string} The word parameter with the first letter capitalized.
|
|
19
|
+
*/
|
|
20
|
+
export function capitalize(word) {
|
|
21
|
+
return word ? word.charAt(0).toUpperCase() + word.slice(1) : '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the longest string in the array of strings.
|
|
26
|
+
* @param {string[]} strings The array of strings.
|
|
27
|
+
* @returns The longest string.
|
|
28
|
+
*/
|
|
29
|
+
export function getLongestString(strings) {
|
|
30
|
+
return strings.reduce(
|
|
31
|
+
(prevLongest, currentValue) => (
|
|
32
|
+
prevLongest.length > currentValue.length ? prevLongest : currentValue
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generate a new scope name which does not
|
|
39
|
+
* conflict / overlap with a previous scope name.
|
|
40
|
+
* Really these just need to be unique within the coordination object.
|
|
41
|
+
* So in theory they could be String(Math.random()) or uuidv4() or something.
|
|
42
|
+
* However it may be good to make them more human-readable and memorable
|
|
43
|
+
* since eventually we will want to expose a UI to update the coordination.
|
|
44
|
+
* @param {string[]} prevScopes Previous scope names.
|
|
45
|
+
* @returns {string} The new scope name.
|
|
46
|
+
*/
|
|
47
|
+
export function getNextScope(prevScopes) {
|
|
48
|
+
// Keep an ordered list of valid characters.
|
|
49
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
50
|
+
// Store the value of the next character for each position
|
|
51
|
+
// in the new string.
|
|
52
|
+
// For example, [0] -> "A", [1] -> "B", [0, 1] -> "AB"
|
|
53
|
+
const nextCharIndices = [0];
|
|
54
|
+
|
|
55
|
+
// Generate a new scope name,
|
|
56
|
+
// potentially conflicting with an existing name.
|
|
57
|
+
// Reference: https://stackoverflow.com/a/12504061
|
|
58
|
+
function next() {
|
|
59
|
+
const r = [];
|
|
60
|
+
nextCharIndices.forEach((charIndex) => {
|
|
61
|
+
r.unshift(chars[charIndex]);
|
|
62
|
+
});
|
|
63
|
+
let increment = true;
|
|
64
|
+
for (let i = 0; i < nextCharIndices.length; i++) {
|
|
65
|
+
const val = ++nextCharIndices[i];
|
|
66
|
+
if (val >= chars.length) {
|
|
67
|
+
nextCharIndices[i] = 0;
|
|
68
|
+
} else {
|
|
69
|
+
increment = false;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (increment) {
|
|
74
|
+
nextCharIndices.push(0);
|
|
75
|
+
}
|
|
76
|
+
return r.join('');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let nextScope;
|
|
80
|
+
do {
|
|
81
|
+
nextScope = next();
|
|
82
|
+
} while (prevScopes.includes(nextScope));
|
|
83
|
+
return nextScope;
|
|
84
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|