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:
Severiano Badajoz
2019-07-11 14:12:38 -07:00
committed by GitHub
parent 98b07b1284
commit ca20add577
3 changed files with 66 additions and 14 deletions
+41 -11
View File
@@ -1,4 +1,4 @@
import { createColors } from "../util/stateManager";
import { ColorHelpers } from "../util/stateManager";
const ColorsReducer = (
state = {
@@ -17,7 +17,7 @@ const ColorsReducer = (
const { world } = nextSharedState;
const colorMode = null;
const colorAccessor = null;
const { rgb, scale } = createColors(world, colorMode);
const { rgb, scale } = ColorHelpers.createColors(world, colorMode);
return {
...state,
colorAccessor,
@@ -29,9 +29,23 @@ const ColorsReducer = (
case "set clip quantiles":
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 { world } = nextSharedState;
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
const { rgb, scale } = ColorHelpers.createColors(
world,
colorMode,
colorAccessor
);
return {
...state,
rgb,
@@ -40,14 +54,9 @@ const ColorsReducer = (
}
case "reset colorscale": {
const { world } = prevSharedState;
const { rgb, scale } = createColors(world);
return {
...state,
colorMode: null,
colorAccessor: null,
rgb,
scale
...ColorHelpers.resetColors(prevSharedState.world)
};
}
@@ -62,7 +71,11 @@ const ColorsReducer = (
const colorMode = !resetCurrent ? action.type : null;
const colorAccessor = !resetCurrent ? action.colorAccessor : null;
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
const { rgb, scale } = ColorHelpers.createColors(
world,
colorMode,
colorAccessor
);
return {
...state,
colorMode,
@@ -81,7 +94,11 @@ const ColorsReducer = (
const colorMode = !resetCurrent ? action.type : null;
const colorAccessor = !resetCurrent ? action.gene : null;
const { rgb, scale } = createColors(world, colorMode, colorAccessor);
const { rgb, scale } = ColorHelpers.createColors(
world,
colorMode,
colorAccessor
);
return {
...state,
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: {
return state;
}