@vitessce/utils 2.0.3 → 3.0.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.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  /* eslint-disable no-param-reassign */
3
3
  import { treeToCellColorsBySetNames } from '@vitessce/sets-utils';
4
- import { getDefaultColor } from './components';
4
+ import { getDefaultColor } from './components.js';
5
5
 
6
6
  // The functions defined here have been adapted from d3-interpolate,
7
7
  // d3-color, and d3-scale-chromatic.
@@ -77,39 +77,24 @@ export const interpolatePlasma = interpolateSequentialMulti(schemePlasma);
77
77
  * Get a mapping of cell IDs to cell colors based on
78
78
  * gene / cell set selection coordination state.
79
79
  * @param {object} params
80
- * @param {object} params.expressionMatrix { rows, cols, matrix }
81
- * @param {array} params.geneSelection Array of selected gene IDs.
82
- * @param {object} params.cellSets The cell sets tree.
83
- * @param {object} params.cellSetSelection Selected cell sets.
84
- * @param {string} params.cellColorEncoding Which to use for
85
- * coloring: gene expression or cell sets?
80
+ * @param {array[]} params.cellSetSelection Selected cell sets.
81
+ * @param {object[]} params.cellSetColor Array of cell set color
82
+ * objects, each containing a path and color [r, g, b].
83
+ * @param {string[]} params.obsIndex Array of cell IDs,
84
+ * in order to initialize all cells to the default color.
85
+ * @param {string} params.theme The current theme,
86
+ * in order to get the theme-based default color.
86
87
  * @returns {Map} Mapping from cell IDs to [r, g, b] color arrays.
87
88
  */
88
89
  export function getCellColors(params) {
89
90
  const {
90
- cellColorEncoding,
91
- expressionData,
92
- cellSets, cellSetSelection,
91
+ cellSets,
92
+ cellSetSelection,
93
93
  cellSetColor,
94
94
  obsIndex,
95
95
  theme,
96
96
  } = params;
97
- if (cellColorEncoding === 'geneSelection' && expressionData && obsIndex) {
98
- // TODO: allow other color maps.
99
- const geneExpColormap = interpolatePlasma;
100
- const colors = new Map();
101
- for (let i = 0; i < expressionData.length; i += 1) {
102
- const value = expressionData[i];
103
- const cellColor = geneExpColormap(value / 255);
104
- colors.set(obsIndex[i], cellColor);
105
- }
106
- return colors;
107
- }
108
- if (cellColorEncoding === 'cellSetSelection' && cellSetSelection && cellSets) {
109
- // Cell sets can potentially lack set colors since the color property
110
- // is not a required part of the schema.
111
- // The `initializeSets` function fills in any empty colors
112
- // with defaults and returns the processed tree object.
97
+ if (cellSetSelection && cellSets) {
113
98
  return treeToCellColorsBySetNames(cellSets, cellSetSelection, cellSetColor, theme);
114
99
  }
115
100
  if (obsIndex && theme) {
@@ -1,4 +1,5 @@
1
- import { interpolateRdBu, interpolatePlasma } from './interpolate-colors';
1
+ import { describe, it, expect } from 'vitest';
2
+ import { interpolateRdBu, interpolatePlasma } from './interpolate-colors.js';
2
3
 
3
4
  const expectRgb = ([testR, testG, testB], [r, g, b]) => ([
4
5
  expect(testR).toBeCloseTo(r),