From 324133875e9603276ac5c4fe393fccd41575ae33 Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Sun, 24 Dec 2017 01:37:40 -0800 Subject: [PATCH] Add categorical to controls --- src/reducers/controls.js | 44 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/reducers/controls.js b/src/reducers/controls.js index 5bfea113..0979e9e3 100644 --- a/src/reducers/controls.js +++ b/src/reducers/controls.js @@ -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; }