Add categorical to controls

This commit is contained in:
Colin Megill
2017-12-24 01:37:40 -08:00
parent 61c35960a7
commit 324133875e
+40 -4
View File
@@ -5,6 +5,7 @@ const Controls = (state = {
allCellsOnClient: null, /* this comes from cells endpoint, this is world */
currentCellSelection: null, /* this comes from user actions, this is current cell selection */
graphMap: null,
categoricalAsBooleansMap: null,
colorAccessor: null,
colorScale: null,
graphBrushSelection: null,
@@ -12,9 +13,9 @@ const Controls = (state = {
axesHaveBeenDrawn: false,
}, action) => {
switch (action.type) {
/* * * * * * * * * * * * * * * * * *
Keep a copy of data
* * * * * * * * * * * * * * * * * */
/**********************************
Keep a copy of 'universe'
***********************************/
case "initialize success":
return Object.assign({}, state, {
_ranges: action.data.data.ranges
@@ -27,11 +28,32 @@ const Controls = (state = {
cell["__selected__"] = true;
cell["__color__"] = "rgba(0,0,0,1)" /* initial color for all cells in all charts */
});
/*
construct a copy of the ranges object that only has categorical
replace all counts with bool flags
ie., everything starts out checked
we mutate this map in the actions below
*/
const categoricalAsBooleansMap = {};
_.each(action.data.data.ranges, (value, key) => {
if (
key !== "CellName" &&
value.options /* it's categorical, it has options instead of ranges */
) {
const optionsAsBooleans = {}
_.each(value.options, (_value, _key) => {
optionsAsBooleans[_key] = true;
})
categoricalAsBooleansMap[key] = optionsAsBooleans;
}
})
// console.log("Copy of ranges obj w/ bools instead of counts:", categoricalAsBooleansMap)
return Object.assign({}, state, {
allCellsOnClient: action.data.data,
currentCellSelection,
graphMap,
categoricalAsBooleansMap,
graphBrushSelection: null, /* if we are getting new cells from the server, the layout (probably? definitely?) just changed, so this is now irrelevant, and we WILL need to call a function to reset state of this kind when cells success happens */
});
/* * * * * * * * * * * * * * * * * *
@@ -55,8 +77,21 @@ const Controls = (state = {
case "graph brush deselect":
return Object.assign({}, state, {
graphBrushSelection: null,
currentCellSelection: action.newSelection
currentCellSelection: action.newSelection /* this comes from middleware */
})
case "categorical metadata filter select":
return Object.assign({}, state, {
categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */
currentCellSelection: action.newSelection /* this comes from middleware */
})
case "categorical metadata filter deselect":
return Object.assign({}, state, {
categoricalAsBooleansMap: action.newCategoricalAsBooleansMap, /* this comes from middleware */
currentCellSelection: action.newSelection /* this comes from middleware */
})
/*******************************
Color Scale
*******************************/
case "color by continuous metadata":
return Object.assign({}, state, {
colorAccessor: action.colorAccessor,
@@ -72,6 +107,7 @@ const Controls = (state = {
colorAccessor: action.colorAccessor, /* pass the scale through additionally, and it's a legend! */
currentCellSelection: action.currentSelectionWithUpdatedColors /* this comes from middleware */
})
default:
return state;
}