@vitessce/utils 2.0.2 → 2.0.3
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.mjs +9995 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +6 -6
- package/src/Pool.js +64 -0
- package/src/components.js +142 -0
- package/{dist → src}/gating.js +16 -16
- package/src/index.js +10 -0
- package/{dist → src}/interpolate-colors.js +78 -60
- package/src/interpolate-colors.test.js +29 -0
- package/src/root.js +84 -0
- package/dist/Pool.js +0 -58
- package/dist/components.js +0 -114
- package/dist/interpolate-colors.test.js +0 -24
- package/dist/root.js +0 -74
package/dist/components.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// Originally in src/components/utils.js
|
|
2
|
-
export const DEFAULT_DARK_COLOR = [50, 50, 50];
|
|
3
|
-
export const DEFAULT_LIGHT_COLOR = [200, 200, 200];
|
|
4
|
-
export function getDefaultColor(theme) {
|
|
5
|
-
return theme === 'dark' ? DEFAULT_DARK_COLOR : DEFAULT_LIGHT_COLOR;
|
|
6
|
-
}
|
|
7
|
-
// From https://personal.sron.nl/~pault/#sec:qualitative
|
|
8
|
-
export const PALETTE = [
|
|
9
|
-
[68, 119, 170],
|
|
10
|
-
[136, 204, 238],
|
|
11
|
-
[68, 170, 153],
|
|
12
|
-
[17, 119, 51],
|
|
13
|
-
[153, 153, 51],
|
|
14
|
-
[221, 204, 119],
|
|
15
|
-
[204, 102, 119],
|
|
16
|
-
[136, 34, 85],
|
|
17
|
-
[170, 68, 153],
|
|
18
|
-
];
|
|
19
|
-
export const VIEWER_PALETTE = [
|
|
20
|
-
[0, 0, 255],
|
|
21
|
-
[0, 255, 0],
|
|
22
|
-
[255, 0, 255],
|
|
23
|
-
[255, 255, 0],
|
|
24
|
-
[0, 255, 255],
|
|
25
|
-
[255, 255, 255],
|
|
26
|
-
[255, 128, 0],
|
|
27
|
-
[255, 0, 0],
|
|
28
|
-
];
|
|
29
|
-
export const COLORMAP_OPTIONS = [
|
|
30
|
-
'viridis',
|
|
31
|
-
'greys',
|
|
32
|
-
'magma',
|
|
33
|
-
'jet',
|
|
34
|
-
'hot',
|
|
35
|
-
'bone',
|
|
36
|
-
'copper',
|
|
37
|
-
'summer',
|
|
38
|
-
'density',
|
|
39
|
-
'inferno',
|
|
40
|
-
];
|
|
41
|
-
export const DEFAULT_GL_OPTIONS = { webgl2: true };
|
|
42
|
-
export function createDefaultUpdateStatus(componentName) {
|
|
43
|
-
return message => console.warn(`${componentName} updateStatus: ${message}`);
|
|
44
|
-
}
|
|
45
|
-
export function createDefaultUpdateCellsSelection(componentName) {
|
|
46
|
-
return cellsSelection => console.warn(`${componentName} updateCellsSelection: ${cellsSelection}`);
|
|
47
|
-
}
|
|
48
|
-
export function createDefaultUpdateCellsHover(componentName) {
|
|
49
|
-
return hoverInfo => console.warn(`${componentName} updateCellsHover: ${hoverInfo.cellId}`);
|
|
50
|
-
}
|
|
51
|
-
export function createDefaultUpdateGenesHover(componentName) {
|
|
52
|
-
return hoverInfo => console.warn(`${componentName} updateGenesHover: ${hoverInfo.geneId}`);
|
|
53
|
-
}
|
|
54
|
-
export function createDefaultUpdateTracksHover(componentName) {
|
|
55
|
-
return hoverInfo => console.warn(`${componentName} updateTracksHover: ${hoverInfo}`);
|
|
56
|
-
}
|
|
57
|
-
export function createDefaultUpdateViewInfo(componentName) {
|
|
58
|
-
return viewInfo => console.warn(`${componentName} updateViewInfo: ${viewInfo}`);
|
|
59
|
-
}
|
|
60
|
-
export function createDefaultClearPleaseWait() {
|
|
61
|
-
return () => { };
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Copy a typed array into a new array buffer.
|
|
65
|
-
* @param {Uint8Array} arr The typed array to be copied.
|
|
66
|
-
* @returns {Uint8Array} The copied array.
|
|
67
|
-
*/
|
|
68
|
-
export function copyUint8Array(arr) {
|
|
69
|
-
const newBuffer = new ArrayBuffer(arr.buffer.byteLength);
|
|
70
|
-
const newArr = new Uint8Array(newBuffer);
|
|
71
|
-
newArr.set(arr);
|
|
72
|
-
return newArr;
|
|
73
|
-
}
|
|
74
|
-
export function asEsModule(component) {
|
|
75
|
-
return {
|
|
76
|
-
__esModule: true,
|
|
77
|
-
default: component,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export function formatBytes(bytes, decimals = 2) {
|
|
81
|
-
if (bytes === 0)
|
|
82
|
-
return '0 Bytes';
|
|
83
|
-
const k = 1024;
|
|
84
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
85
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
86
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
87
|
-
// eslint-disable-next-line no-restricted-properties
|
|
88
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
89
|
-
}
|
|
90
|
-
export const getStatsForResolution = (loader, resolution) => {
|
|
91
|
-
const { shape, labels } = loader[resolution];
|
|
92
|
-
const height = shape[labels.indexOf('y')];
|
|
93
|
-
const width = shape[labels.indexOf('x')];
|
|
94
|
-
const depth = shape[labels.indexOf('z')];
|
|
95
|
-
// eslint-disable-next-line no-bitwise
|
|
96
|
-
const depthDownsampled = Math.max(1, depth >> resolution);
|
|
97
|
-
// Check memory allocation limits for Float32Array (used in XR3DLayer for rendering)
|
|
98
|
-
const totalBytes = 4 * height * width * depthDownsampled;
|
|
99
|
-
return {
|
|
100
|
-
height, width, depthDownsampled, totalBytes,
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
export const canLoadResolution = (loader, resolution) => {
|
|
104
|
-
const { totalBytes, height, width, depthDownsampled, } = getStatsForResolution(loader, resolution);
|
|
105
|
-
const maxHeapSize = window.performance?.memory
|
|
106
|
-
&& window.performance?.memory?.jsHeapSizeLimit / 2;
|
|
107
|
-
const maxSize = maxHeapSize || (2 ** 31) - 1;
|
|
108
|
-
// 2048 is a normal texture size limit although some browsers go larger.
|
|
109
|
-
return (totalBytes < maxSize
|
|
110
|
-
&& height <= 2048
|
|
111
|
-
&& depthDownsampled <= 2048
|
|
112
|
-
&& width <= 2048
|
|
113
|
-
&& depthDownsampled > 1);
|
|
114
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { interpolateRdBu, interpolatePlasma } from './interpolate-colors';
|
|
2
|
-
const expectRgb = ([testR, testG, testB], [r, g, b]) => ([
|
|
3
|
-
expect(testR).toBeCloseTo(r),
|
|
4
|
-
expect(testG).toBeCloseTo(g),
|
|
5
|
-
expect(testB).toBeCloseTo(b),
|
|
6
|
-
]);
|
|
7
|
-
describe('components/interpolate-colors', () => {
|
|
8
|
-
describe('interpolateRdBu()', () => {
|
|
9
|
-
it('maps 0 to a red color', () => {
|
|
10
|
-
expectRgb(interpolateRdBu(0), [103, 0, 31]);
|
|
11
|
-
});
|
|
12
|
-
it('maps 1 to a blue color', () => {
|
|
13
|
-
expectRgb(interpolateRdBu(1), [5, 48, 97]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe('interpolatePlasma()', () => {
|
|
17
|
-
it('maps 0 to dark cool color', () => {
|
|
18
|
-
expectRgb(interpolatePlasma(0), [13, 8, 135]);
|
|
19
|
-
});
|
|
20
|
-
it('maps 1 to bright warm color', () => {
|
|
21
|
-
expectRgb(interpolatePlasma(1), [240, 249, 33]);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
package/dist/root.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-plusplus */
|
|
2
|
-
// Originally in src/utils.js
|
|
3
|
-
// Adapted from https://github.com/feross/fromentries/blob/29b52a850bb3a47c390937631c2638edf3443942/index.js
|
|
4
|
-
export function fromEntries(iterable) {
|
|
5
|
-
return [...iterable]
|
|
6
|
-
.reduce((obj, { 0: key, 1: val }) => Object.assign(obj, { [key]: val }), {});
|
|
7
|
-
}
|
|
8
|
-
export function commaNumber(n) {
|
|
9
|
-
const nf = new Intl.NumberFormat('en-US');
|
|
10
|
-
return nf.format(n);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Capitalize a the first letter of a string.
|
|
14
|
-
* @param {string} word A string to capitalize.
|
|
15
|
-
* @returns {string} The word parameter with the first letter capitalized.
|
|
16
|
-
*/
|
|
17
|
-
export function capitalize(word) {
|
|
18
|
-
return word ? word.charAt(0).toUpperCase() + word.slice(1) : '';
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get the longest string in the array of strings.
|
|
22
|
-
* @param {string[]} strings The array of strings.
|
|
23
|
-
* @returns The longest string.
|
|
24
|
-
*/
|
|
25
|
-
export function getLongestString(strings) {
|
|
26
|
-
return strings.reduce((prevLongest, currentValue) => (prevLongest.length > currentValue.length ? prevLongest : currentValue));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Generate a new scope name which does not
|
|
30
|
-
* conflict / overlap with a previous scope name.
|
|
31
|
-
* Really these just need to be unique within the coordination object.
|
|
32
|
-
* So in theory they could be String(Math.random()) or uuidv4() or something.
|
|
33
|
-
* However it may be good to make them more human-readable and memorable
|
|
34
|
-
* since eventually we will want to expose a UI to update the coordination.
|
|
35
|
-
* @param {string[]} prevScopes Previous scope names.
|
|
36
|
-
* @returns {string} The new scope name.
|
|
37
|
-
*/
|
|
38
|
-
export function getNextScope(prevScopes) {
|
|
39
|
-
// Keep an ordered list of valid characters.
|
|
40
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
41
|
-
// Store the value of the next character for each position
|
|
42
|
-
// in the new string.
|
|
43
|
-
// For example, [0] -> "A", [1] -> "B", [0, 1] -> "AB"
|
|
44
|
-
const nextCharIndices = [0];
|
|
45
|
-
// Generate a new scope name,
|
|
46
|
-
// potentially conflicting with an existing name.
|
|
47
|
-
// Reference: https://stackoverflow.com/a/12504061
|
|
48
|
-
function next() {
|
|
49
|
-
const r = [];
|
|
50
|
-
nextCharIndices.forEach((charIndex) => {
|
|
51
|
-
r.unshift(chars[charIndex]);
|
|
52
|
-
});
|
|
53
|
-
let increment = true;
|
|
54
|
-
for (let i = 0; i < nextCharIndices.length; i++) {
|
|
55
|
-
const val = ++nextCharIndices[i];
|
|
56
|
-
if (val >= chars.length) {
|
|
57
|
-
nextCharIndices[i] = 0;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
increment = false;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (increment) {
|
|
65
|
-
nextCharIndices.push(0);
|
|
66
|
-
}
|
|
67
|
-
return r.join('');
|
|
68
|
-
}
|
|
69
|
-
let nextScope;
|
|
70
|
-
do {
|
|
71
|
-
nextScope = next();
|
|
72
|
-
} while (prevScopes.includes(nextScope));
|
|
73
|
-
return nextScope;
|
|
74
|
-
}
|