@vitessce/utils 3.3.2 → 3.3.4
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 +48 -15636
- package/dist-tsc/index.d.ts +1 -2
- package/dist-tsc/index.d.ts.map +1 -1
- package/dist-tsc/index.js +1 -2
- package/dist-tsc/root.d.ts +36 -0
- package/dist-tsc/root.d.ts.map +1 -1
- package/dist-tsc/root.js +59 -0
- package/package.json +2 -3
- package/src/index.ts +4 -3
- package/src/root.ts +67 -0
- package/dist-tsc/interpolate-colors.d.ts +0 -28
- package/dist-tsc/interpolate-colors.d.ts.map +0 -1
- package/dist-tsc/interpolate-colors.js +0 -88
- package/dist-tsc/interpolate-colors.test.d.ts +0 -2
- package/dist-tsc/interpolate-colors.test.d.ts.map +0 -1
- package/dist-tsc/interpolate-colors.test.js +0 -25
- package/src/interpolate-colors.test.ts +0 -30
- package/src/interpolate-colors.ts +0 -114
package/dist-tsc/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { fromEntries, commaNumber, capitalize, pluralize, getLongestString, getNextScope, } from './root.js';
|
|
1
|
+
export { fromEntries, commaNumber, capitalize, pluralize, getLongestString, getNextScope, getNextScopeNumeric, createPrefixedGetNextScopeNumeric, getInitialCoordinationScopePrefix, getInitialCoordinationScopeName, } from './root.js';
|
|
2
2
|
export { DEFAULT_DARK_COLOR, DEFAULT_LIGHT_COLOR, getDefaultColor, PALETTE, VIEWER_PALETTE, PATHOLOGY_PALETTE, LARGE_PATHOLOGY_PALETTE, COLORMAP_OPTIONS, DEFAULT_GL_OPTIONS, createDefaultUpdateStatus, createDefaultUpdateCellsSelection, createDefaultUpdateCellsHover, createDefaultUpdateGenesHover, createDefaultUpdateTracksHover, createDefaultUpdateViewInfo, createDefaultClearPleaseWait, copyUint8Array, asEsModule, formatBytes, } from './components.js';
|
|
3
3
|
export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js';
|
|
4
|
-
export { getCellColors, } from './interpolate-colors.js';
|
|
5
4
|
export { default as Pool } from './Pool.js';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist-tsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,GAChC,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
package/dist-tsc/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line react-refresh/only-export-components
|
|
2
|
-
export { fromEntries, commaNumber, capitalize, pluralize, getLongestString, getNextScope, } from './root.js';
|
|
2
|
+
export { fromEntries, commaNumber, capitalize, pluralize, getLongestString, getNextScope, getNextScopeNumeric, createPrefixedGetNextScopeNumeric, getInitialCoordinationScopePrefix, getInitialCoordinationScopeName, } from './root.js';
|
|
3
3
|
// eslint-disable-next-line react-refresh/only-export-components
|
|
4
4
|
export { DEFAULT_DARK_COLOR, DEFAULT_LIGHT_COLOR, getDefaultColor, PALETTE, VIEWER_PALETTE, PATHOLOGY_PALETTE, LARGE_PATHOLOGY_PALETTE, COLORMAP_OPTIONS, DEFAULT_GL_OPTIONS, createDefaultUpdateStatus, createDefaultUpdateCellsSelection, createDefaultUpdateCellsHover, createDefaultUpdateGenesHover, createDefaultUpdateTracksHover, createDefaultUpdateViewInfo, createDefaultClearPleaseWait, copyUint8Array, asEsModule, formatBytes, } from './components.js';
|
|
5
5
|
export { getValueTransformFunction, VALUE_TRANSFORM_OPTIONS, } from './gating.js';
|
|
6
|
-
export { getCellColors, } from './interpolate-colors.js';
|
|
7
6
|
export { default as Pool } from './Pool.js';
|
package/dist-tsc/root.d.ts
CHANGED
|
@@ -31,4 +31,40 @@ export declare function getLongestString(strings: string[]): string;
|
|
|
31
31
|
* @returns {string} The new scope name.
|
|
32
32
|
*/
|
|
33
33
|
export declare function getNextScope(prevScopes: string[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Generate a new scope name which does not
|
|
36
|
+
* conflict / overlap with a previous scope name.
|
|
37
|
+
* Really these just need to be unique within the coordination object.
|
|
38
|
+
* So in theory they could be String(Math.random()) or uuidv4() or something.
|
|
39
|
+
* In this version we use an incrementing integer starting from 0.
|
|
40
|
+
* @param {string[]} prevScopes Previous scope names.
|
|
41
|
+
* @returns {string} The new scope name.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getNextScopeNumeric(prevScopes: string[]): string;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a getNextScopeNumeric function which includes a prefix.
|
|
46
|
+
* @param {string} prefix The prefix to use.
|
|
47
|
+
* @returns {Function} The getNextScope function.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createPrefixedGetNextScopeNumeric(prefix: string): (prevScopes: string[]) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Get the prefix for an automatically-initialized coordination scope.
|
|
52
|
+
* @param datasetUid The dataset UID.
|
|
53
|
+
* @param dataType The dataType corresponding to the fileType
|
|
54
|
+
* whose loader defines the initial coordination values.
|
|
55
|
+
* @returns The prefix for the initial coordination scope
|
|
56
|
+
* like "init_<datasetUid>_<dataType>_".
|
|
57
|
+
*/
|
|
58
|
+
export declare function getInitialCoordinationScopePrefix(datasetUid: string, dataType: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Get the name for an automatically-initialized coordination scope.
|
|
61
|
+
* @param datasetUid The dataset UID.
|
|
62
|
+
* @param dataType The dataType corresponding to the fileType
|
|
63
|
+
* whose loader defines the initial coordination values.
|
|
64
|
+
* @param i Optional. If null, the initial coordination scope
|
|
65
|
+
* name will be "init_<datasetUid>_<dataType>_0".
|
|
66
|
+
* @returns The name for the initial coordination scope
|
|
67
|
+
* like "init_<datasetUid>_<dataType>_<i>".
|
|
68
|
+
*/
|
|
69
|
+
export declare function getInitialCoordinationScopeName(datasetUid: string, dataType: string, i?: number | null): string;
|
|
34
70
|
//# sourceMappingURL=root.d.ts.map
|
package/dist-tsc/root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAQA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAG7E;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAGpC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,UAE7C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,OAElE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,UAMjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAqChD"}
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAQA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAG7E;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAGpC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,UAE7C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,GAAG,IAAW,OAElE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,UAMjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAqChD;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,UAQvD;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,MAAM,gBAC1C,MAAM,EAAE,YAS7B;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAGrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,GAAE,MAAM,GAAG,IAAW,UAI9D"}
|
package/dist-tsc/root.js
CHANGED
|
@@ -83,3 +83,62 @@ export function getNextScope(prevScopes) {
|
|
|
83
83
|
} while (prevScopes.includes(nextScope));
|
|
84
84
|
return nextScope;
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Generate a new scope name which does not
|
|
88
|
+
* conflict / overlap with a previous scope name.
|
|
89
|
+
* Really these just need to be unique within the coordination object.
|
|
90
|
+
* So in theory they could be String(Math.random()) or uuidv4() or something.
|
|
91
|
+
* In this version we use an incrementing integer starting from 0.
|
|
92
|
+
* @param {string[]} prevScopes Previous scope names.
|
|
93
|
+
* @returns {string} The new scope name.
|
|
94
|
+
*/
|
|
95
|
+
export function getNextScopeNumeric(prevScopes) {
|
|
96
|
+
let nextScopeInt = 0;
|
|
97
|
+
let nextScopeStr;
|
|
98
|
+
do {
|
|
99
|
+
nextScopeStr = `${nextScopeInt}`;
|
|
100
|
+
nextScopeInt += 1;
|
|
101
|
+
} while (prevScopes.includes(nextScopeStr));
|
|
102
|
+
return nextScopeStr;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generate a getNextScopeNumeric function which includes a prefix.
|
|
106
|
+
* @param {string} prefix The prefix to use.
|
|
107
|
+
* @returns {Function} The getNextScope function.
|
|
108
|
+
*/
|
|
109
|
+
export function createPrefixedGetNextScopeNumeric(prefix) {
|
|
110
|
+
return (prevScopes) => {
|
|
111
|
+
let nextScopeInt = 0;
|
|
112
|
+
let nextScopeStr;
|
|
113
|
+
do {
|
|
114
|
+
nextScopeStr = `${prefix}${nextScopeInt}`;
|
|
115
|
+
nextScopeInt += 1;
|
|
116
|
+
} while (prevScopes.includes(nextScopeStr));
|
|
117
|
+
return nextScopeStr;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the prefix for an automatically-initialized coordination scope.
|
|
122
|
+
* @param datasetUid The dataset UID.
|
|
123
|
+
* @param dataType The dataType corresponding to the fileType
|
|
124
|
+
* whose loader defines the initial coordination values.
|
|
125
|
+
* @returns The prefix for the initial coordination scope
|
|
126
|
+
* like "init_<datasetUid>_<dataType>_".
|
|
127
|
+
*/
|
|
128
|
+
export function getInitialCoordinationScopePrefix(datasetUid, dataType) {
|
|
129
|
+
return `init_${datasetUid}_${dataType}_`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the name for an automatically-initialized coordination scope.
|
|
133
|
+
* @param datasetUid The dataset UID.
|
|
134
|
+
* @param dataType The dataType corresponding to the fileType
|
|
135
|
+
* whose loader defines the initial coordination values.
|
|
136
|
+
* @param i Optional. If null, the initial coordination scope
|
|
137
|
+
* name will be "init_<datasetUid>_<dataType>_0".
|
|
138
|
+
* @returns The name for the initial coordination scope
|
|
139
|
+
* like "init_<datasetUid>_<dataType>_<i>".
|
|
140
|
+
*/
|
|
141
|
+
export function getInitialCoordinationScopeName(datasetUid, dataType, i = null) {
|
|
142
|
+
const prefix = getInitialCoordinationScopePrefix(datasetUid, dataType);
|
|
143
|
+
return `${prefix}${i === null ? 0 : i}`;
|
|
144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/utils",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"bowser": "^2.11.0",
|
|
20
20
|
"lodash-es": "^4.17.21",
|
|
21
21
|
"lz-string": "^1.4.4",
|
|
22
|
-
"pluralize": "^8.0.0"
|
|
23
|
-
"@vitessce/sets-utils": "3.3.2"
|
|
22
|
+
"pluralize": "^8.0.0"
|
|
24
23
|
},
|
|
25
24
|
"scripts": {
|
|
26
25
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,10 @@ export {
|
|
|
6
6
|
pluralize,
|
|
7
7
|
getLongestString,
|
|
8
8
|
getNextScope,
|
|
9
|
+
getNextScopeNumeric,
|
|
10
|
+
createPrefixedGetNextScopeNumeric,
|
|
11
|
+
getInitialCoordinationScopePrefix,
|
|
12
|
+
getInitialCoordinationScopeName,
|
|
9
13
|
} from './root.js';
|
|
10
14
|
// eslint-disable-next-line react-refresh/only-export-components
|
|
11
15
|
export {
|
|
@@ -33,7 +37,4 @@ export {
|
|
|
33
37
|
getValueTransformFunction,
|
|
34
38
|
VALUE_TRANSFORM_OPTIONS,
|
|
35
39
|
} from './gating.js';
|
|
36
|
-
export {
|
|
37
|
-
getCellColors,
|
|
38
|
-
} from './interpolate-colors.js';
|
|
39
40
|
export { default as Pool } from './Pool.js';
|
package/src/root.ts
CHANGED
|
@@ -95,3 +95,70 @@ export function getNextScope(prevScopes: string[]) {
|
|
|
95
95
|
} while (prevScopes.includes(nextScope));
|
|
96
96
|
return nextScope;
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Generate a new scope name which does not
|
|
101
|
+
* conflict / overlap with a previous scope name.
|
|
102
|
+
* Really these just need to be unique within the coordination object.
|
|
103
|
+
* So in theory they could be String(Math.random()) or uuidv4() or something.
|
|
104
|
+
* In this version we use an incrementing integer starting from 0.
|
|
105
|
+
* @param {string[]} prevScopes Previous scope names.
|
|
106
|
+
* @returns {string} The new scope name.
|
|
107
|
+
*/
|
|
108
|
+
export function getNextScopeNumeric(prevScopes: string[]) {
|
|
109
|
+
let nextScopeInt = 0;
|
|
110
|
+
let nextScopeStr: string;
|
|
111
|
+
do {
|
|
112
|
+
nextScopeStr = `${nextScopeInt}`;
|
|
113
|
+
nextScopeInt += 1;
|
|
114
|
+
} while (prevScopes.includes(nextScopeStr));
|
|
115
|
+
return nextScopeStr;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Generate a getNextScopeNumeric function which includes a prefix.
|
|
120
|
+
* @param {string} prefix The prefix to use.
|
|
121
|
+
* @returns {Function} The getNextScope function.
|
|
122
|
+
*/
|
|
123
|
+
export function createPrefixedGetNextScopeNumeric(prefix: string) {
|
|
124
|
+
return (prevScopes: string[]) => {
|
|
125
|
+
let nextScopeInt = 0;
|
|
126
|
+
let nextScopeStr: string;
|
|
127
|
+
do {
|
|
128
|
+
nextScopeStr = `${prefix}${nextScopeInt}`;
|
|
129
|
+
nextScopeInt += 1;
|
|
130
|
+
} while (prevScopes.includes(nextScopeStr));
|
|
131
|
+
return nextScopeStr;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get the prefix for an automatically-initialized coordination scope.
|
|
137
|
+
* @param datasetUid The dataset UID.
|
|
138
|
+
* @param dataType The dataType corresponding to the fileType
|
|
139
|
+
* whose loader defines the initial coordination values.
|
|
140
|
+
* @returns The prefix for the initial coordination scope
|
|
141
|
+
* like "init_<datasetUid>_<dataType>_".
|
|
142
|
+
*/
|
|
143
|
+
export function getInitialCoordinationScopePrefix(
|
|
144
|
+
datasetUid: string, dataType: string,
|
|
145
|
+
) {
|
|
146
|
+
return `init_${datasetUid}_${dataType}_`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get the name for an automatically-initialized coordination scope.
|
|
151
|
+
* @param datasetUid The dataset UID.
|
|
152
|
+
* @param dataType The dataType corresponding to the fileType
|
|
153
|
+
* whose loader defines the initial coordination values.
|
|
154
|
+
* @param i Optional. If null, the initial coordination scope
|
|
155
|
+
* name will be "init_<datasetUid>_<dataType>_0".
|
|
156
|
+
* @returns The name for the initial coordination scope
|
|
157
|
+
* like "init_<datasetUid>_<dataType>_<i>".
|
|
158
|
+
*/
|
|
159
|
+
export function getInitialCoordinationScopeName(
|
|
160
|
+
datasetUid: string, dataType: string, i: number | null = null,
|
|
161
|
+
) {
|
|
162
|
+
const prefix = getInitialCoordinationScopePrefix(datasetUid, dataType);
|
|
163
|
+
return `${prefix}${i === null ? 0 : i}`;
|
|
164
|
+
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare const interpolateRdBu: (t: number) => number[];
|
|
2
|
-
export declare const interpolatePlasma: (t: number) => number[];
|
|
3
|
-
declare type GetCellColorsParams = {
|
|
4
|
-
cellSetSelection: string[][] | null;
|
|
5
|
-
cellSetColor: {
|
|
6
|
-
path: string[];
|
|
7
|
-
color: [number, number, number];
|
|
8
|
-
}[] | null;
|
|
9
|
-
cellSets: object;
|
|
10
|
-
obsIndex: string[] | null;
|
|
11
|
-
theme: 'light' | 'dark' | null;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Get a mapping of cell IDs to cell colors based on
|
|
15
|
-
* gene / cell set selection coordination state.
|
|
16
|
-
* @param {object} params
|
|
17
|
-
* @param {array[]} params.cellSetSelection Selected cell sets.
|
|
18
|
-
* @param {object[]} params.cellSetColor Array of cell set color
|
|
19
|
-
* objects, each containing a path and color [r, g, b].
|
|
20
|
-
* @param {string[]} params.obsIndex Array of cell IDs,
|
|
21
|
-
* in order to initialize all cells to the default color.
|
|
22
|
-
* @param {string} params.theme The current theme,
|
|
23
|
-
* in order to get the theme-based default color.
|
|
24
|
-
* @returns {Map} Mapping from cell IDs to [r, g, b] color arrays.
|
|
25
|
-
*/
|
|
26
|
-
export declare function getCellColors(params: GetCellColorsParams): Map<string, number[]>;
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=interpolate-colors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate-colors.d.ts","sourceRoot":"","sources":["../src/interpolate-colors.ts"],"names":[],"mappings":"AAuEA,eAAO,MAAM,eAAe,MAnCb,MAAM,aAmCyC,CAAC;AAC/D,eAAO,MAAM,iBAAiB,MAJjB,MAAM,aAIsD,CAAC;AAE1E,aAAK,mBAAmB,GAAG;IACzB,gBAAgB,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC;IACpC,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;CAChC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAkBhF"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-nested-ternary */
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
import { treeToCellColorsBySetNames } from '@vitessce/sets-utils';
|
|
4
|
-
import { getDefaultColor } from './components.js';
|
|
5
|
-
// The functions defined here have been adapted from d3-interpolate,
|
|
6
|
-
// d3-color, and d3-scale-chromatic.
|
|
7
|
-
// Color string "rgb(r,g,b)" representations are replaced by color array [r, g, b]
|
|
8
|
-
// representations, to allow them to work nicely with deck.gl,
|
|
9
|
-
// without the need to converting back and forth between string and array formats.
|
|
10
|
-
// Reference: https://github.com/d3/d3-scale-chromatic/blob/431d21da776f97c632f53a855bd822edfbbcd56e/src/diverging/RdBu.js
|
|
11
|
-
// eslint-disable-next-line max-len
|
|
12
|
-
const schemeRdBu = [[103, 0, 31], [178, 24, 43], [214, 96, 77], [244, 165, 130], [253, 219, 199], [247, 247, 247], [209, 229, 240], [146, 197, 222], [67, 147, 195], [33, 102, 172], [5, 48, 97]];
|
|
13
|
-
// eslint-disable-next-line max-len
|
|
14
|
-
const schemePlasma = [[13, 8, 135], [16, 7, 136], [19, 7, 137], [22, 7, 138], [25, 6, 140], [27, 6, 141], [29, 6, 142], [32, 6, 143], [34, 6, 144], [36, 6, 145], [38, 5, 145], [40, 5, 146], [42, 5, 147], [44, 5, 148], [46, 5, 149], [47, 5, 150], [49, 5, 151], [51, 5, 151], [53, 4, 152], [55, 4, 153], [56, 4, 154], [58, 4, 154], [60, 4, 155], [62, 4, 156], [63, 4, 156], [65, 4, 157], [67, 3, 158], [68, 3, 158], [70, 3, 159], [72, 3, 159], [73, 3, 160], [75, 3, 161], [76, 2, 161], [78, 2, 162], [80, 2, 162], [81, 2, 163], [83, 2, 163], [85, 2, 164], [86, 1, 164], [88, 1, 164], [89, 1, 165], [91, 1, 165], [92, 1, 166], [94, 1, 166], [96, 1, 166], [97, 0, 167], [99, 0, 167], [100, 0, 167], [102, 0, 167], [103, 0, 168], [105, 0, 168], [106, 0, 168], [108, 0, 168], [110, 0, 168], [111, 0, 168], [113, 0, 168], [114, 1, 168], [116, 1, 168], [117, 1, 168], [119, 1, 168], [120, 1, 168], [122, 2, 168], [123, 2, 168], [125, 3, 168], [126, 3, 168], [128, 4, 168], [129, 4, 167], [131, 5, 167], [132, 5, 167], [134, 6, 166], [135, 7, 166], [136, 8, 166], [138, 9, 165], [139, 10, 165], [141, 11, 165], [142, 12, 164], [143, 13, 164], [145, 14, 163], [146, 15, 163], [148, 16, 162], [149, 17, 161], [150, 19, 161], [152, 20, 160], [153, 21, 159], [154, 22, 159], [156, 23, 158], [157, 24, 157], [158, 25, 157], [160, 26, 156], [161, 27, 155], [162, 29, 154], [163, 30, 154], [165, 31, 153], [166, 32, 152], [167, 33, 151], [168, 34, 150], [170, 35, 149], [171, 36, 148], [172, 38, 148], [173, 39, 147], [174, 40, 146], [176, 41, 145], [177, 42, 144], [178, 43, 143], [179, 44, 142], [180, 46, 141], [181, 47, 140], [182, 48, 139], [183, 49, 138], [184, 50, 137], [186, 51, 136], [187, 52, 136], [188, 53, 135], [189, 55, 134], [190, 56, 133], [191, 57, 132], [192, 58, 131], [193, 59, 130], [194, 60, 129], [195, 61, 128], [196, 62, 127], [197, 64, 126], [198, 65, 125], [199, 66, 124], [200, 67, 123], [201, 68, 122], [202, 69, 122], [203, 70, 121], [204, 71, 120], [204, 73, 119], [205, 74, 118], [206, 75, 117], [207, 76, 116], [208, 77, 115], [209, 78, 114], [210, 79, 113], [211, 81, 113], [212, 82, 112], [213, 83, 111], [213, 84, 110], [214, 85, 109], [215, 86, 108], [216, 87, 107], [217, 88, 106], [218, 90, 106], [218, 91, 105], [219, 92, 104], [220, 93, 103], [221, 94, 102], [222, 95, 101], [222, 97, 100], [223, 98, 99], [224, 99, 99], [225, 100, 98], [226, 101, 97], [226, 102, 96], [227, 104, 95], [228, 105, 94], [229, 106, 93], [229, 107, 93], [230, 108, 92], [231, 110, 91], [231, 111, 90], [232, 112, 89], [233, 113, 88], [233, 114, 87], [234, 116, 87], [235, 117, 86], [235, 118, 85], [236, 119, 84], [237, 121, 83], [237, 122, 82], [238, 123, 81], [239, 124, 81], [239, 126, 80], [240, 127, 79], [240, 128, 78], [241, 129, 77], [241, 131, 76], [242, 132, 75], [243, 133, 75], [243, 135, 74], [244, 136, 73], [244, 137, 72], [245, 139, 71], [245, 140, 70], [246, 141, 69], [246, 143, 68], [247, 144, 68], [247, 145, 67], [247, 147, 66], [248, 148, 65], [248, 149, 64], [249, 151, 63], [249, 152, 62], [249, 154, 62], [250, 155, 61], [250, 156, 60], [250, 158, 59], [251, 159, 58], [251, 161, 57], [251, 162, 56], [252, 163, 56], [252, 165, 55], [252, 166, 54], [252, 168, 53], [252, 169, 52], [253, 171, 51], [253, 172, 51], [253, 174, 50], [253, 175, 49], [253, 177, 48], [253, 178, 47], [253, 180, 47], [253, 181, 46], [254, 183, 45], [254, 184, 44], [254, 186, 44], [254, 187, 43], [254, 189, 42], [254, 190, 42], [254, 192, 41], [253, 194, 41], [253, 195, 40], [253, 197, 39], [253, 198, 39], [253, 200, 39], [253, 202, 38], [253, 203, 38], [252, 205, 37], [252, 206, 37], [252, 208, 37], [252, 210, 37], [251, 211, 36], [251, 213, 36], [251, 215, 36], [250, 216, 36], [250, 218, 36], [249, 220, 36], [249, 221, 37], [248, 223, 37], [248, 225, 37], [247, 226, 37], [247, 228, 37], [246, 230, 38], [246, 232, 38], [245, 233, 38], [245, 235, 39], [244, 237, 39], [243, 238, 39], [243, 240, 39], [242, 242, 39], [241, 244, 38], [241, 245, 37], [240, 247, 36], [240, 249, 33]];
|
|
15
|
-
// Reference: https://github.com/d3/d3-interpolate/blob/96d54051d1c2fec55f240edd0ec5401715b10390/src/rgb.js
|
|
16
|
-
function rgbSpline(spline) {
|
|
17
|
-
return (colors) => {
|
|
18
|
-
const n = colors.length;
|
|
19
|
-
const r = new Array(n);
|
|
20
|
-
const g = new Array(n);
|
|
21
|
-
const b = new Array(n);
|
|
22
|
-
let i;
|
|
23
|
-
let color;
|
|
24
|
-
// eslint-disable-next-line no-plusplus
|
|
25
|
-
for (i = 0; i < n; ++i) {
|
|
26
|
-
color = [colors[i][0], colors[i][1], colors[i][2]];
|
|
27
|
-
r[i] = color[0] || 0;
|
|
28
|
-
g[i] = color[1] || 0;
|
|
29
|
-
b[i] = color[2] || 0;
|
|
30
|
-
}
|
|
31
|
-
const rFunc = spline(r);
|
|
32
|
-
const gFunc = spline(g);
|
|
33
|
-
const bFunc = spline(b);
|
|
34
|
-
return (t) => [rFunc(t), gFunc(t), bFunc(t)];
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
// Reference: https://github.com/d3/d3-interpolate/blob/594a32af1fe1118812b439012c2cb742e907c0c0/src/basis.js
|
|
38
|
-
function basis(values) {
|
|
39
|
-
function innerBasis(t1, v0, v1, v2, v3) {
|
|
40
|
-
const t2 = t1 * t1;
|
|
41
|
-
const t3 = t2 * t1;
|
|
42
|
-
return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
|
43
|
-
+ (4 - 6 * t2 + 3 * t3) * v1
|
|
44
|
-
+ (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
|
45
|
-
+ t3 * v3) / 6;
|
|
46
|
-
}
|
|
47
|
-
const n = values.length - 1;
|
|
48
|
-
return (t) => {
|
|
49
|
-
const i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n);
|
|
50
|
-
const v1 = values[i];
|
|
51
|
-
const v2 = values[i + 1];
|
|
52
|
-
const v0 = i > 0 ? values[i - 1] : 2 * v1 - v2;
|
|
53
|
-
const v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
|
54
|
-
return innerBasis((t - i / n) * n, v0, v1, v2, v3);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// Reference: https://github.com/d3/d3-scale-chromatic/blob/ade54c13e8dfdb9807801a794eaec1a37f926b8a/src/ramp.js
|
|
58
|
-
const interpolateRgbBasis = rgbSpline(basis);
|
|
59
|
-
function interpolateSequentialMulti(range) {
|
|
60
|
-
const n = range.length;
|
|
61
|
-
return (t) => range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
|
62
|
-
}
|
|
63
|
-
export const interpolateRdBu = interpolateRgbBasis(schemeRdBu);
|
|
64
|
-
export const interpolatePlasma = interpolateSequentialMulti(schemePlasma);
|
|
65
|
-
/**
|
|
66
|
-
* Get a mapping of cell IDs to cell colors based on
|
|
67
|
-
* gene / cell set selection coordination state.
|
|
68
|
-
* @param {object} params
|
|
69
|
-
* @param {array[]} params.cellSetSelection Selected cell sets.
|
|
70
|
-
* @param {object[]} params.cellSetColor Array of cell set color
|
|
71
|
-
* objects, each containing a path and color [r, g, b].
|
|
72
|
-
* @param {string[]} params.obsIndex Array of cell IDs,
|
|
73
|
-
* in order to initialize all cells to the default color.
|
|
74
|
-
* @param {string} params.theme The current theme,
|
|
75
|
-
* in order to get the theme-based default color.
|
|
76
|
-
* @returns {Map} Mapping from cell IDs to [r, g, b] color arrays.
|
|
77
|
-
*/
|
|
78
|
-
export function getCellColors(params) {
|
|
79
|
-
const { cellSets, cellSetSelection, cellSetColor, obsIndex, theme, } = params;
|
|
80
|
-
if (cellSetSelection && cellSets) {
|
|
81
|
-
// TODO(ts): fix typing here once better typing in sets-utils.
|
|
82
|
-
return treeToCellColorsBySetNames(cellSets, cellSetSelection, cellSetColor, theme);
|
|
83
|
-
}
|
|
84
|
-
if (obsIndex && theme) {
|
|
85
|
-
return new Map(obsIndex.map(o => ([o, getDefaultColor(theme)])));
|
|
86
|
-
}
|
|
87
|
-
return new Map();
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate-colors.test.d.ts","sourceRoot":"","sources":["../src/interpolate-colors.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { interpolateRdBu, interpolatePlasma } from './interpolate-colors.js';
|
|
3
|
-
const expectRgb = ([testR, testG, testB], [r, g, b]) => ([
|
|
4
|
-
expect(testR).toBeCloseTo(r),
|
|
5
|
-
expect(testG).toBeCloseTo(g),
|
|
6
|
-
expect(testB).toBeCloseTo(b),
|
|
7
|
-
]);
|
|
8
|
-
describe('components/interpolate-colors', () => {
|
|
9
|
-
describe('interpolateRdBu()', () => {
|
|
10
|
-
it('maps 0 to a red color', () => {
|
|
11
|
-
expectRgb(interpolateRdBu(0), [103, 0, 31]);
|
|
12
|
-
});
|
|
13
|
-
it('maps 1 to a blue color', () => {
|
|
14
|
-
expectRgb(interpolateRdBu(1), [5, 48, 97]);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('interpolatePlasma()', () => {
|
|
18
|
-
it('maps 0 to dark cool color', () => {
|
|
19
|
-
expectRgb(interpolatePlasma(0), [13, 8, 135]);
|
|
20
|
-
});
|
|
21
|
-
it('maps 1 to bright warm color', () => {
|
|
22
|
-
expectRgb(interpolatePlasma(1), [240, 249, 33]);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { interpolateRdBu, interpolatePlasma } from './interpolate-colors.js';
|
|
3
|
-
|
|
4
|
-
const expectRgb = ([testR, testG, testB]: number[], [r, g, b]: number[]) => ([
|
|
5
|
-
expect(testR).toBeCloseTo(r),
|
|
6
|
-
expect(testG).toBeCloseTo(g),
|
|
7
|
-
expect(testB).toBeCloseTo(b),
|
|
8
|
-
]);
|
|
9
|
-
|
|
10
|
-
describe('components/interpolate-colors', () => {
|
|
11
|
-
describe('interpolateRdBu()', () => {
|
|
12
|
-
it('maps 0 to a red color', () => {
|
|
13
|
-
expectRgb(interpolateRdBu(0), [103, 0, 31]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('maps 1 to a blue color', () => {
|
|
17
|
-
expectRgb(interpolateRdBu(1), [5, 48, 97]);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('interpolatePlasma()', () => {
|
|
22
|
-
it('maps 0 to dark cool color', () => {
|
|
23
|
-
expectRgb(interpolatePlasma(0), [13, 8, 135]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('maps 1 to bright warm color', () => {
|
|
27
|
-
expectRgb(interpolatePlasma(1), [240, 249, 33]);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-nested-ternary */
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
import { treeToCellColorsBySetNames } from '@vitessce/sets-utils';
|
|
4
|
-
import { getDefaultColor } from './components.js';
|
|
5
|
-
|
|
6
|
-
// The functions defined here have been adapted from d3-interpolate,
|
|
7
|
-
// d3-color, and d3-scale-chromatic.
|
|
8
|
-
// Color string "rgb(r,g,b)" representations are replaced by color array [r, g, b]
|
|
9
|
-
// representations, to allow them to work nicely with deck.gl,
|
|
10
|
-
// without the need to converting back and forth between string and array formats.
|
|
11
|
-
|
|
12
|
-
// Reference: https://github.com/d3/d3-scale-chromatic/blob/431d21da776f97c632f53a855bd822edfbbcd56e/src/diverging/RdBu.js
|
|
13
|
-
// eslint-disable-next-line max-len
|
|
14
|
-
const schemeRdBu = [[103, 0, 31], [178, 24, 43], [214, 96, 77], [244, 165, 130], [253, 219, 199], [247, 247, 247], [209, 229, 240], [146, 197, 222], [67, 147, 195], [33, 102, 172], [5, 48, 97]];
|
|
15
|
-
// eslint-disable-next-line max-len
|
|
16
|
-
const schemePlasma = [[13, 8, 135], [16, 7, 136], [19, 7, 137], [22, 7, 138], [25, 6, 140], [27, 6, 141], [29, 6, 142], [32, 6, 143], [34, 6, 144], [36, 6, 145], [38, 5, 145], [40, 5, 146], [42, 5, 147], [44, 5, 148], [46, 5, 149], [47, 5, 150], [49, 5, 151], [51, 5, 151], [53, 4, 152], [55, 4, 153], [56, 4, 154], [58, 4, 154], [60, 4, 155], [62, 4, 156], [63, 4, 156], [65, 4, 157], [67, 3, 158], [68, 3, 158], [70, 3, 159], [72, 3, 159], [73, 3, 160], [75, 3, 161], [76, 2, 161], [78, 2, 162], [80, 2, 162], [81, 2, 163], [83, 2, 163], [85, 2, 164], [86, 1, 164], [88, 1, 164], [89, 1, 165], [91, 1, 165], [92, 1, 166], [94, 1, 166], [96, 1, 166], [97, 0, 167], [99, 0, 167], [100, 0, 167], [102, 0, 167], [103, 0, 168], [105, 0, 168], [106, 0, 168], [108, 0, 168], [110, 0, 168], [111, 0, 168], [113, 0, 168], [114, 1, 168], [116, 1, 168], [117, 1, 168], [119, 1, 168], [120, 1, 168], [122, 2, 168], [123, 2, 168], [125, 3, 168], [126, 3, 168], [128, 4, 168], [129, 4, 167], [131, 5, 167], [132, 5, 167], [134, 6, 166], [135, 7, 166], [136, 8, 166], [138, 9, 165], [139, 10, 165], [141, 11, 165], [142, 12, 164], [143, 13, 164], [145, 14, 163], [146, 15, 163], [148, 16, 162], [149, 17, 161], [150, 19, 161], [152, 20, 160], [153, 21, 159], [154, 22, 159], [156, 23, 158], [157, 24, 157], [158, 25, 157], [160, 26, 156], [161, 27, 155], [162, 29, 154], [163, 30, 154], [165, 31, 153], [166, 32, 152], [167, 33, 151], [168, 34, 150], [170, 35, 149], [171, 36, 148], [172, 38, 148], [173, 39, 147], [174, 40, 146], [176, 41, 145], [177, 42, 144], [178, 43, 143], [179, 44, 142], [180, 46, 141], [181, 47, 140], [182, 48, 139], [183, 49, 138], [184, 50, 137], [186, 51, 136], [187, 52, 136], [188, 53, 135], [189, 55, 134], [190, 56, 133], [191, 57, 132], [192, 58, 131], [193, 59, 130], [194, 60, 129], [195, 61, 128], [196, 62, 127], [197, 64, 126], [198, 65, 125], [199, 66, 124], [200, 67, 123], [201, 68, 122], [202, 69, 122], [203, 70, 121], [204, 71, 120], [204, 73, 119], [205, 74, 118], [206, 75, 117], [207, 76, 116], [208, 77, 115], [209, 78, 114], [210, 79, 113], [211, 81, 113], [212, 82, 112], [213, 83, 111], [213, 84, 110], [214, 85, 109], [215, 86, 108], [216, 87, 107], [217, 88, 106], [218, 90, 106], [218, 91, 105], [219, 92, 104], [220, 93, 103], [221, 94, 102], [222, 95, 101], [222, 97, 100], [223, 98, 99], [224, 99, 99], [225, 100, 98], [226, 101, 97], [226, 102, 96], [227, 104, 95], [228, 105, 94], [229, 106, 93], [229, 107, 93], [230, 108, 92], [231, 110, 91], [231, 111, 90], [232, 112, 89], [233, 113, 88], [233, 114, 87], [234, 116, 87], [235, 117, 86], [235, 118, 85], [236, 119, 84], [237, 121, 83], [237, 122, 82], [238, 123, 81], [239, 124, 81], [239, 126, 80], [240, 127, 79], [240, 128, 78], [241, 129, 77], [241, 131, 76], [242, 132, 75], [243, 133, 75], [243, 135, 74], [244, 136, 73], [244, 137, 72], [245, 139, 71], [245, 140, 70], [246, 141, 69], [246, 143, 68], [247, 144, 68], [247, 145, 67], [247, 147, 66], [248, 148, 65], [248, 149, 64], [249, 151, 63], [249, 152, 62], [249, 154, 62], [250, 155, 61], [250, 156, 60], [250, 158, 59], [251, 159, 58], [251, 161, 57], [251, 162, 56], [252, 163, 56], [252, 165, 55], [252, 166, 54], [252, 168, 53], [252, 169, 52], [253, 171, 51], [253, 172, 51], [253, 174, 50], [253, 175, 49], [253, 177, 48], [253, 178, 47], [253, 180, 47], [253, 181, 46], [254, 183, 45], [254, 184, 44], [254, 186, 44], [254, 187, 43], [254, 189, 42], [254, 190, 42], [254, 192, 41], [253, 194, 41], [253, 195, 40], [253, 197, 39], [253, 198, 39], [253, 200, 39], [253, 202, 38], [253, 203, 38], [252, 205, 37], [252, 206, 37], [252, 208, 37], [252, 210, 37], [251, 211, 36], [251, 213, 36], [251, 215, 36], [250, 216, 36], [250, 218, 36], [249, 220, 36], [249, 221, 37], [248, 223, 37], [248, 225, 37], [247, 226, 37], [247, 228, 37], [246, 230, 38], [246, 232, 38], [245, 233, 38], [245, 235, 39], [244, 237, 39], [243, 238, 39], [243, 240, 39], [242, 242, 39], [241, 244, 38], [241, 245, 37], [240, 247, 36], [240, 249, 33]];
|
|
17
|
-
|
|
18
|
-
// Reference: https://github.com/d3/d3-interpolate/blob/96d54051d1c2fec55f240edd0ec5401715b10390/src/rgb.js
|
|
19
|
-
function rgbSpline(spline: (values: number[]) => ((t: number) => number)) {
|
|
20
|
-
return (colors: number[][]) => {
|
|
21
|
-
const n = colors.length;
|
|
22
|
-
const r: number[] = new Array(n);
|
|
23
|
-
const g: number[] = new Array(n);
|
|
24
|
-
const b: number[] = new Array(n);
|
|
25
|
-
let i; let
|
|
26
|
-
color;
|
|
27
|
-
// eslint-disable-next-line no-plusplus
|
|
28
|
-
for (i = 0; i < n; ++i) {
|
|
29
|
-
color = [colors[i][0], colors[i][1], colors[i][2]];
|
|
30
|
-
r[i] = color[0] || 0;
|
|
31
|
-
g[i] = color[1] || 0;
|
|
32
|
-
b[i] = color[2] || 0;
|
|
33
|
-
}
|
|
34
|
-
const rFunc: (t: number) => number = spline(r);
|
|
35
|
-
const gFunc: (t: number) => number = spline(g);
|
|
36
|
-
const bFunc: (t: number) => number = spline(b);
|
|
37
|
-
return (t: number) => [rFunc(t), gFunc(t), bFunc(t)];
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Reference: https://github.com/d3/d3-interpolate/blob/594a32af1fe1118812b439012c2cb742e907c0c0/src/basis.js
|
|
42
|
-
function basis(values: number[]) {
|
|
43
|
-
function innerBasis(t1: number, v0: number, v1: number, v2: number, v3: number) {
|
|
44
|
-
const t2 = t1 * t1; const
|
|
45
|
-
t3 = t2 * t1;
|
|
46
|
-
return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
|
47
|
-
+ (4 - 6 * t2 + 3 * t3) * v1
|
|
48
|
-
+ (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
|
49
|
-
+ t3 * v3) / 6;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const n = values.length - 1;
|
|
53
|
-
return (t: number) => {
|
|
54
|
-
const i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n);
|
|
55
|
-
const v1 = values[i];
|
|
56
|
-
const v2 = values[i + 1];
|
|
57
|
-
const v0 = i > 0 ? values[i - 1] : 2 * v1 - v2;
|
|
58
|
-
const v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
|
59
|
-
return innerBasis((t - i / n) * n, v0, v1, v2, v3);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// Reference: https://github.com/d3/d3-scale-chromatic/blob/ade54c13e8dfdb9807801a794eaec1a37f926b8a/src/ramp.js
|
|
65
|
-
const interpolateRgbBasis = rgbSpline(basis);
|
|
66
|
-
|
|
67
|
-
function interpolateSequentialMulti(range: number[][]) {
|
|
68
|
-
const n = range.length;
|
|
69
|
-
return (t: number) => range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const interpolateRdBu = interpolateRgbBasis(schemeRdBu);
|
|
73
|
-
export const interpolatePlasma = interpolateSequentialMulti(schemePlasma);
|
|
74
|
-
|
|
75
|
-
type GetCellColorsParams = {
|
|
76
|
-
cellSetSelection: string[][] | null;
|
|
77
|
-
cellSetColor: { path: string[]; color: [number, number, number] }[] | null;
|
|
78
|
-
cellSets: object; // TODO(ts): more strict typing here
|
|
79
|
-
obsIndex: string[] | null;
|
|
80
|
-
theme: 'light' | 'dark' | null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Get a mapping of cell IDs to cell colors based on
|
|
85
|
-
* gene / cell set selection coordination state.
|
|
86
|
-
* @param {object} params
|
|
87
|
-
* @param {array[]} params.cellSetSelection Selected cell sets.
|
|
88
|
-
* @param {object[]} params.cellSetColor Array of cell set color
|
|
89
|
-
* objects, each containing a path and color [r, g, b].
|
|
90
|
-
* @param {string[]} params.obsIndex Array of cell IDs,
|
|
91
|
-
* in order to initialize all cells to the default color.
|
|
92
|
-
* @param {string} params.theme The current theme,
|
|
93
|
-
* in order to get the theme-based default color.
|
|
94
|
-
* @returns {Map} Mapping from cell IDs to [r, g, b] color arrays.
|
|
95
|
-
*/
|
|
96
|
-
export function getCellColors(params: GetCellColorsParams): Map<string, number[]> {
|
|
97
|
-
const {
|
|
98
|
-
cellSets,
|
|
99
|
-
cellSetSelection,
|
|
100
|
-
cellSetColor,
|
|
101
|
-
obsIndex,
|
|
102
|
-
theme,
|
|
103
|
-
} = params;
|
|
104
|
-
if (cellSetSelection && cellSets) {
|
|
105
|
-
// TODO(ts): fix typing here once better typing in sets-utils.
|
|
106
|
-
return treeToCellColorsBySetNames(
|
|
107
|
-
cellSets, cellSetSelection, cellSetColor as object[], theme as string,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if (obsIndex && theme) {
|
|
111
|
-
return new Map(obsIndex.map(o => ([o, getDefaultColor(theme)])));
|
|
112
|
-
}
|
|
113
|
-
return new Map();
|
|
114
|
-
}
|