mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 20:48:12 +08:00
reset colorAccessor and colorMode if colored diffexp gene is removed (#843)
* add action to clear colorMode and colorAccessor if diffexp is removed * create new colorHelper function * creater colorHelper for conditionally setting state * add abbr * revert abbr
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createColors } from "../util/stateManager";
|
import { ColorHelpers } from "../util/stateManager";
|
||||||
|
|
||||||
const ColorsReducer = (
|
const ColorsReducer = (
|
||||||
state = {
|
state = {
|
||||||
@@ -17,7 +17,7 @@ const ColorsReducer = (
|
|||||||
const { world } = nextSharedState;
|
const { world } = nextSharedState;
|
||||||
const colorMode = null;
|
const colorMode = null;
|
||||||
const colorAccessor = null;
|
const colorAccessor = null;
|
||||||
const { rgb, scale } = createColors(world, colorMode);
|
const { rgb, scale } = ColorHelpers.createColors(world, colorMode);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
colorAccessor,
|
colorAccessor,
|
||||||
@@ -29,9 +29,23 @@ const ColorsReducer = (
|
|||||||
|
|
||||||
case "set clip quantiles":
|
case "set clip quantiles":
|
||||||
case "set World to current selection": {
|
case "set World to current selection": {
|
||||||
|
const { world: prevWorld, controls: prevControls } = prevSharedState;
|
||||||
|
const resetColorState = ColorHelpers.checkIfColorByDiffexpAndResetColors(
|
||||||
|
prevControls,
|
||||||
|
state,
|
||||||
|
prevWorld
|
||||||
|
);
|
||||||
|
if (resetColorState) {
|
||||||
|
return resetColorState;
|
||||||
|
}
|
||||||
|
|
||||||
const { colorMode, colorAccessor } = state;
|
const { colorMode, colorAccessor } = state;
|
||||||
const { world } = nextSharedState;
|
const { world } = nextSharedState;
|
||||||
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
|
const { rgb, scale } = ColorHelpers.createColors(
|
||||||
|
world,
|
||||||
|
colorMode,
|
||||||
|
colorAccessor
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
rgb,
|
rgb,
|
||||||
@@ -40,14 +54,9 @@ const ColorsReducer = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "reset colorscale": {
|
case "reset colorscale": {
|
||||||
const { world } = prevSharedState;
|
|
||||||
const { rgb, scale } = createColors(world);
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
colorMode: null,
|
...ColorHelpers.resetColors(prevSharedState.world)
|
||||||
colorAccessor: null,
|
|
||||||
rgb,
|
|
||||||
scale
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +71,11 @@ const ColorsReducer = (
|
|||||||
const colorMode = !resetCurrent ? action.type : null;
|
const colorMode = !resetCurrent ? action.type : null;
|
||||||
const colorAccessor = !resetCurrent ? action.colorAccessor : null;
|
const colorAccessor = !resetCurrent ? action.colorAccessor : null;
|
||||||
|
|
||||||
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
|
const { rgb, scale } = ColorHelpers.createColors(
|
||||||
|
world,
|
||||||
|
colorMode,
|
||||||
|
colorAccessor
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
colorMode,
|
colorMode,
|
||||||
@@ -81,7 +94,11 @@ const ColorsReducer = (
|
|||||||
const colorMode = !resetCurrent ? action.type : null;
|
const colorMode = !resetCurrent ? action.type : null;
|
||||||
const colorAccessor = !resetCurrent ? action.gene : null;
|
const colorAccessor = !resetCurrent ? action.gene : null;
|
||||||
|
|
||||||
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
|
const { rgb, scale } = ColorHelpers.createColors(
|
||||||
|
world,
|
||||||
|
colorMode,
|
||||||
|
colorAccessor
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
colorMode,
|
colorMode,
|
||||||
@@ -91,6 +108,19 @@ const ColorsReducer = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "clear differential expression": {
|
||||||
|
const { world: prevWorld, controls: prevControls } = prevSharedState;
|
||||||
|
const resetColorState = ColorHelpers.checkIfColorByDiffexpAndResetColors(
|
||||||
|
prevControls,
|
||||||
|
state,
|
||||||
|
prevWorld
|
||||||
|
);
|
||||||
|
if (resetColorState) {
|
||||||
|
return resetColorState;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ create new colors state object. Paramters:
|
|||||||
"color by continuous metadata", "color by categorical metadata"
|
"color by continuous metadata", "color by categorical metadata"
|
||||||
-
|
-
|
||||||
*/
|
*/
|
||||||
function createColors(world, colorMode = null, colorAccessor = null) {
|
export function createColors(world, colorMode = null, colorAccessor = null) {
|
||||||
switch (colorMode) {
|
switch (colorMode) {
|
||||||
case "color by categorical metadata": {
|
case "color by categorical metadata": {
|
||||||
return createColorsByCategoricalMetadata(world, colorAccessor);
|
return createColorsByCategoricalMetadata(world, colorAccessor);
|
||||||
@@ -117,4 +117,26 @@ function createColorsByExpression(world, accessor) {
|
|||||||
return { rgb, scale };
|
return { rgb, scale };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createColors;
|
export const resetColors = world => {
|
||||||
|
const { rgb, scale } = createColors(world);
|
||||||
|
return {
|
||||||
|
colorMode: null,
|
||||||
|
colorAccessor: null,
|
||||||
|
rgb,
|
||||||
|
scale
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkIfColorByDiffexpAndResetColors = (
|
||||||
|
prevControls,
|
||||||
|
state,
|
||||||
|
prevWorld
|
||||||
|
) => {
|
||||||
|
if (prevControls.diffexpGenes.includes(state.colorAccessor)) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
...resetColors(prevWorld)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ This is all VERY tightly integrated with reducers and actions, and
|
|||||||
exists to support those concepts.
|
exists to support those concepts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { default as createColors } from "./colorHelpers";
|
export * as ColorHelpers from "./colorHelpers";
|
||||||
export * as Universe from "./universe";
|
export * as Universe from "./universe";
|
||||||
export * as World from "./world";
|
export * as World from "./world";
|
||||||
export * as WorldUtil from "./worldUtil";
|
export * as WorldUtil from "./worldUtil";
|
||||||
|
|||||||
Reference in New Issue
Block a user