mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-27 14:38:12 +08:00
* run eslint --fix * camelcase * camelCase config part 1 * part 2 * part 3 - removing subscripts * fix "class-methods-use-this" * fix "class-methods-use-this" * fix eslint ignores * add eslint ignore for set state in update * reformat comments to appease eslint * add a11y features * sort-comp fix * a11y fix * add ignore for set state in update * add a11y htmlFor * remove unused toast * remove unnecessary bind * add ignore for set state in update * add rel="noopener noreferrer" Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener * use arrow function to bind * remove unused definitions/declarations * prettier * remove unused state * add comments to empty catch blocks remove curly brackets * escape ' * use eqeqeq * switch from default export * remove ignore log * remove static * fix import * revert subscripting config * clean-up * remove unnecessary subscript * fix new errors from master * change category click handler to a class property * fix camelcase changes that slipped by * unused import * Fix newly introduced ESLint errors from addGenes
83 lines
2.1 KiB
JavaScript
83 lines
2.1 KiB
JavaScript
/*
|
|
we have a UI heuristic to pick the default layout, based on assumptions
|
|
about commonly used names. Preferentially, pick in the following order:
|
|
|
|
1. "umap"
|
|
2. "tsne"
|
|
3. "pca"
|
|
4. give up, use the first available
|
|
*/
|
|
function bestDefaultLayout(layouts) {
|
|
const preferredNames = ["umap", "tsne", "pca"];
|
|
const idx = preferredNames.findIndex((name) => layouts.indexOf(name) !== -1);
|
|
if (idx !== -1) return preferredNames[idx];
|
|
return layouts[0];
|
|
}
|
|
|
|
function setToDefaultLayout(world) {
|
|
const { schema } = world;
|
|
const available = schema.layout.obs.map((v) => v.name).sort();
|
|
const current = bestDefaultLayout(available);
|
|
const currentDimNames = schema.layout.obsByName[current].dims;
|
|
return { available, current, currentDimNames };
|
|
}
|
|
|
|
const LayoutChoice = (
|
|
state = {
|
|
available: [], // all available choices
|
|
current: undefined, // name of the current layout, eg, 'umap'
|
|
currentDimNames: [], // dimension name
|
|
},
|
|
action,
|
|
nextSharedState
|
|
) => {
|
|
switch (action.type) {
|
|
case "universe exists, but loading is still in progress": {
|
|
// set default to default
|
|
const { universe } = nextSharedState;
|
|
return {
|
|
...state,
|
|
...setToDefaultLayout(universe),
|
|
};
|
|
}
|
|
|
|
case "set layout choice": {
|
|
const { schema } = nextSharedState.world;
|
|
const current = action.layoutChoice;
|
|
const currentDimNames = schema.layout.obsByName[current].dims;
|
|
return { ...state, current, currentDimNames };
|
|
}
|
|
|
|
case "reembed: add reembedding": {
|
|
const { name } = action.schema;
|
|
const available = Array.from(new Set(state.available).add(name));
|
|
return {
|
|
...state,
|
|
available,
|
|
};
|
|
}
|
|
|
|
case "reembed: clear all reembeddings": {
|
|
const { universe } = nextSharedState;
|
|
const { current } = state;
|
|
const dflt = setToDefaultLayout(universe);
|
|
if (dflt.available.includes(current)) {
|
|
return {
|
|
...state,
|
|
available: dflt.available,
|
|
};
|
|
}
|
|
return {
|
|
...state,
|
|
...dflt,
|
|
};
|
|
}
|
|
|
|
default: {
|
|
return state;
|
|
}
|
|
}
|
|
};
|
|
|
|
export default LayoutChoice;
|