mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-23 10:38:11 +08:00
* initial dataframe commit * initial dataframe port of core app * rename variables for clarity * remove unused import * comment out unused code * fix array handling bug in crossfilter dimension creation * allow creation of empty dataframes * handle non-existent columns * handle non-existent columns * revise tests for new dataframe * comments for clarity * comments for clarity * generate bulk add placeholder with real gene names * fix bug in gene name adding * more dataframe unit tests * fix bug - subset from current world, not universe * put cut and pasted code into a single function * improve caching of crossfilter * remove cascading update bug from graph * more performance work * improve state handling for scatterplot * performance optimization of critical path * add column summarization * dataframe utils * add callOnceLazy * fix tests * minor updates found during review * fix misspelling * remove RESTv02 from function names * comment cleanup * cut/icut col parameter defaults to null * break up large test * improve tests and comments on dataframe at/has functions
76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
/* eslint-disable import/prefer-default-export */
|
|
import _ from "lodash";
|
|
|
|
/*
|
|
Various utility functions operating on World/Universe
|
|
*/
|
|
|
|
/*
|
|
Count unique category values, binning first by dim1 then by dim2
|
|
Return:
|
|
|
|
Map {
|
|
dim1_val1: Map {
|
|
dim2_val1: number,
|
|
dim2_val2: number,
|
|
...
|
|
},
|
|
...
|
|
}
|
|
|
|
Parameters are:
|
|
- dim1: dimension 1 name/label
|
|
- dim2: dimension 2 name/label
|
|
- df: dataframe containing dim1 and dim2 on the column axis
|
|
|
|
*/
|
|
function _countCategoryValues2D(dim1, dim2, df) {
|
|
const dimMap = new Map();
|
|
const col1 = df.col(dim1) ? df.col(dim1).asArray() : null;
|
|
const col2 = df.col(dim2) ? df.col(dim2).asArray() : null;
|
|
if (!col1 || !col2) {
|
|
return dimMap;
|
|
}
|
|
|
|
for (let r = 0, l = df.length; r < l; r += 1) {
|
|
const val1 = col1[r];
|
|
const val2 = col2[r];
|
|
let d2Map = dimMap.get(val1);
|
|
if (d2Map === undefined) {
|
|
d2Map = new Map();
|
|
dimMap.set(val1, d2Map);
|
|
}
|
|
let curCount = d2Map.get(val2);
|
|
if (curCount === undefined) {
|
|
curCount = 0;
|
|
}
|
|
d2Map.set(val2, curCount + 1);
|
|
}
|
|
return dimMap;
|
|
}
|
|
|
|
let __worldUtilMemoId__ = 0;
|
|
function _memoizedId(x) {
|
|
if (!x.__worldUtilMemoId__) {
|
|
__worldUtilMemoId__ += 1;
|
|
x.__worldUtilMemoId__ = __worldUtilMemoId__;
|
|
}
|
|
return x.__worldUtilMemoId__;
|
|
}
|
|
function _countCategoryValues2DResolver(...args) {
|
|
const id = args[0] + args[1] + _memoizedId(args[2]);
|
|
return id;
|
|
}
|
|
|
|
export const countCategoryValues2D = _.memoize(
|
|
_countCategoryValues2D,
|
|
_countCategoryValues2DResolver
|
|
);
|
|
|
|
/*
|
|
Clear any cached data within WorldUtil caches, eg, memoized functions
|
|
*/
|
|
export function clearCaches() {
|
|
countCategoryValues2D.cache.clear();
|
|
}
|