@vitessce/utils 3.2.2 → 3.3.1

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.
@@ -16,12 +16,12 @@ const schemeRdBu = [[103, 0, 31], [178, 24, 43], [214, 96, 77], [244, 165, 130],
16
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
17
 
18
18
  // Reference: https://github.com/d3/d3-interpolate/blob/96d54051d1c2fec55f240edd0ec5401715b10390/src/rgb.js
19
- function rgbSpline(spline) {
20
- return (colors) => {
19
+ function rgbSpline(spline: (values: number[]) => ((t: number) => number)) {
20
+ return (colors: number[][]) => {
21
21
  const n = colors.length;
22
- let r = new Array(n);
23
- let g = new Array(n);
24
- let b = new Array(n);
22
+ const r: number[] = new Array(n);
23
+ const g: number[] = new Array(n);
24
+ const b: number[] = new Array(n);
25
25
  let i; let
26
26
  color;
27
27
  // eslint-disable-next-line no-plusplus
@@ -31,16 +31,16 @@ function rgbSpline(spline) {
31
31
  g[i] = color[1] || 0;
32
32
  b[i] = color[2] || 0;
33
33
  }
34
- r = spline(r);
35
- g = spline(g);
36
- b = spline(b);
37
- return t => [r(t), g(t), b(t)];
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
38
  };
39
39
  }
40
40
 
41
41
  // Reference: https://github.com/d3/d3-interpolate/blob/594a32af1fe1118812b439012c2cb742e907c0c0/src/basis.js
42
- function basis(values) {
43
- function innerBasis(t1, v0, v1, v2, v3) {
42
+ function basis(values: number[]) {
43
+ function innerBasis(t1: number, v0: number, v1: number, v2: number, v3: number) {
44
44
  const t2 = t1 * t1; const
45
45
  t3 = t2 * t1;
46
46
  return ((1 - 3 * t1 + 3 * t2 - t3) * v0
@@ -50,7 +50,7 @@ function basis(values) {
50
50
  }
51
51
 
52
52
  const n = values.length - 1;
53
- return (t) => {
53
+ return (t: number) => {
54
54
  const i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n);
55
55
  const v1 = values[i];
56
56
  const v2 = values[i + 1];
@@ -64,14 +64,21 @@ function basis(values) {
64
64
  // Reference: https://github.com/d3/d3-scale-chromatic/blob/ade54c13e8dfdb9807801a794eaec1a37f926b8a/src/ramp.js
65
65
  const interpolateRgbBasis = rgbSpline(basis);
66
66
 
67
- function interpolateSequentialMulti(range) {
67
+ function interpolateSequentialMulti(range: number[][]) {
68
68
  const n = range.length;
69
- return t => range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
69
+ return (t: number) => range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
70
70
  }
71
71
 
72
72
  export const interpolateRdBu = interpolateRgbBasis(schemeRdBu);
73
73
  export const interpolatePlasma = interpolateSequentialMulti(schemePlasma);
74
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
+ }
75
82
 
76
83
  /**
77
84
  * Get a mapping of cell IDs to cell colors based on
@@ -86,7 +93,7 @@ export const interpolatePlasma = interpolateSequentialMulti(schemePlasma);
86
93
  * in order to get the theme-based default color.
87
94
  * @returns {Map} Mapping from cell IDs to [r, g, b] color arrays.
88
95
  */
89
- export function getCellColors(params) {
96
+ export function getCellColors(params: GetCellColorsParams): Map<string, number[]> {
90
97
  const {
91
98
  cellSets,
92
99
  cellSetSelection,
@@ -95,7 +102,10 @@ export function getCellColors(params) {
95
102
  theme,
96
103
  } = params;
97
104
  if (cellSetSelection && cellSets) {
98
- return treeToCellColorsBySetNames(cellSets, cellSetSelection, cellSetColor, theme);
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
+ );
99
109
  }
100
110
  if (obsIndex && theme) {
101
111
  return new Map(obsIndex.map(o => ([o, getDefaultColor(theme)])));
@@ -0,0 +1,2 @@
1
+ declare module 'pluralize';
2
+ declare module '@vitessce/sets-utils'; // TODO(ts)
@@ -6,12 +6,12 @@ plur.addPluralRule('glomerulus', 'glomeruli');
6
6
  plur.addPluralRule('interstitium', 'interstitia');
7
7
 
8
8
  // Adapted from https://github.com/feross/fromentries/blob/29b52a850bb3a47c390937631c2638edf3443942/index.js
9
- export function fromEntries(iterable) {
9
+ export function fromEntries(iterable: [string, any][]): { [key: string]: any } {
10
10
  return [...iterable]
11
11
  .reduce((obj, { 0: key, 1: val }) => Object.assign(obj, { [key]: val }), {});
12
12
  }
13
13
 
14
- export function commaNumber(n) {
14
+ export function commaNumber(n: number) {
15
15
  const nf = new Intl.NumberFormat('en-US');
16
16
  return nf.format(n);
17
17
  }
@@ -21,7 +21,7 @@ export function commaNumber(n) {
21
21
  * @param {string} word A string to capitalize.
22
22
  * @returns {string} The word parameter with the first letter capitalized.
23
23
  */
24
- export function capitalize(word) {
24
+ export function capitalize(word: string | null) {
25
25
  return word ? word.charAt(0).toUpperCase() + word.slice(1) : '';
26
26
  }
27
27
 
@@ -30,7 +30,7 @@ export function capitalize(word) {
30
30
  * @param {string} word A string to capitalize.
31
31
  * @returns {string} The word parameter with the first letter capitalized.
32
32
  */
33
- export function pluralize(word, count = null) {
33
+ export function pluralize(word: string, count: number | null = null) {
34
34
  return plur(word, count);
35
35
  }
36
36
 
@@ -39,7 +39,7 @@ export function pluralize(word, count = null) {
39
39
  * @param {string[]} strings The array of strings.
40
40
  * @returns The longest string.
41
41
  */
42
- export function getLongestString(strings) {
42
+ export function getLongestString(strings: string[]) {
43
43
  return strings.reduce(
44
44
  (prevLongest, currentValue) => (
45
45
  prevLongest.length > currentValue.length ? prevLongest : currentValue
@@ -57,7 +57,7 @@ export function getLongestString(strings) {
57
57
  * @param {string[]} prevScopes Previous scope names.
58
58
  * @returns {string} The new scope name.
59
59
  */
60
- export function getNextScope(prevScopes) {
60
+ export function getNextScope(prevScopes: string[]) {
61
61
  // Keep an ordered list of valid characters.
62
62
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
63
63
  // Store the value of the next character for each position
@@ -69,7 +69,7 @@ export function getNextScope(prevScopes) {
69
69
  // potentially conflicting with an existing name.
70
70
  // Reference: https://stackoverflow.com/a/12504061
71
71
  function next() {
72
- const r = [];
72
+ const r: string[] = [];
73
73
  nextCharIndices.forEach((charIndex) => {
74
74
  r.unshift(chars[charIndex]);
75
75
  });
package/src/index.js DELETED
@@ -1,12 +0,0 @@
1
- // eslint-disable-next-line react-refresh/only-export-components
2
- export * from './root.js';
3
- // eslint-disable-next-line react-refresh/only-export-components
4
- export * from './components.js';
5
- export {
6
- getValueTransformFunction,
7
- VALUE_TRANSFORM_OPTIONS,
8
- } from './gating.js';
9
- export {
10
- getCellColors,
11
- } from './interpolate-colors.js';
12
- export { default as Pool } from './Pool.js';