Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] add color picker to dataset tag (#1608)

Lera9936b7b7ed6d
diff --git a/src/actions/vis-state-actions.d.ts b/src/actions/vis-state-actions.d.ts
index fa8f00362..ea33b8e07 100644
--- a/src/actions/vis-state-actions.d.ts
+++ b/src/actions/vis-state-actions.d.ts
@@ -204,6 +204,15 @@ export function showDatasetTable(
dataId: string
): Merge<ShowDatasetTableUpdaterAction, {type: ActionTypes.SHOW_DATASET_TABLE}>;
+export type UpdateDatasetColorUpdater = {
+ dataId: string,
+ newColor: RGBColor
+}
+export function updateTableColor(
+ dataId: string,
+ newColor: RGBColor
+): Merge<UpdateDatasetColorUpdater, {type: ActionTypes.UPDATE_TABLE_COLOR}>;
+
export type SortTableColumnUpdaterAction = {
dataId: string;
column: string;
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index a0ff67681..656e9154e 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -111,7 +111,7 @@ export function layerVisConfigChange(oldLayer, newVisConfig) {
/**
* Set the color palette ui for layer color
- * @memberOf visStateActions
+ * @memberof visStateActions
* @param oldLayer - layer to be updated
* @param prop - which color prop
* @param newConfig - to be merged
@@ -338,6 +338,23 @@ export function showDatasetTable(dataId) {
};
}
+/**
+ * Update dataset color to custom by means of color picker
+ * @memberof visStateActions
+ * @param dataId dataset `id` this custom color is associated with
+ * @param newColor custom color in RGBformat
+ * @returns action
+ * @type {typeof import('./vis-state-actions').updateTableColor}
+ * @public
+ */
+export function updateTableColor(dataId, newColor) {
+ return {
+ type: ActionTypes.UPDATE_TABLE_COLOR,
+ dataId,
+ newColor
+ };
+}
+
/**
* Sort dataset column, for table display
* @memberof visStateActions
diff --git a/src/components/common/styled-components.js b/src/components/common/styled-components.js
index bec1da7dd..02044ef1d 100644
--- a/src/components/common/styled-components.js
+++ b/src/components/common/styled-components.js
@@ -351,8 +351,8 @@ export const ButtonGroup = styled.div`
export const DatasetSquare = styled.div`
display: inline-block;
- width: 8px;
- height: 8px;
+ width: 10px;
+ height: 10px;
background-color: rgb(${props => props.color.join(',')});
margin-right: 12px;
`;
diff --git a/src/components/side-panel.js b/src/components/side-panel.js
index 6d49e3810..e1eeae631 100644
--- a/src/components/side-panel.js
+++ b/src/components/side-panel.js
@@ -131,7 +131,7 @@ export default function SidePanelFactory(
} = props;
const {openDeleteModal, toggleModal, toggleSidePanel} = uiStateActions;
const {activeSidePanel} = uiState;
- const {setMapInfo, showDatasetTable} = visStateActions;
+ const {setMapInfo, showDatasetTable, updateTableColor} = visStateActions;
const {hasShare, hasStorage} = availableProviders;
const {title} = mapInfo;
@@ -159,6 +159,10 @@ export default function SidePanelFactory(
}, [title, setMapInfo, toggleModal]);
const onClickShareMap = useCallback(() => toggleModal(SHARE_MAP_ID), [toggleModal]);
const onShowDatasetTable = useCallback(dataId => showDatasetTable(dataId), [showDatasetTable]);
+ const onUpdateTableColor = useCallback(
+ (dataId, newColor) => updateTableColor(dataId, newColor),
+ [updateTableColor]
+ );
const onShowAddDataModal = useCallback(() => toggleModal(ADD_DATA_ID), [toggleModal]);
const onShowAddMapStyleModal = useCallback(() => toggleModal(ADD_MAP_STYLE_ID), [toggleModal]);
const onRemoveDataset = useCallback(dataId => openDeleteModal(dataId), [openDeleteModal]);
@@ -225,6 +229,7 @@ export default function SidePanelFactory(
interactionConfig={interactionConfig}
removeDataset={onRemoveDataset}
showDatasetTable={onShowDatasetTable}
+ updateTableColor={onUpdateTableColor}
showAddDataModal={onShowAddDataModal}
showAddMapStyleModal={onShowAddMapStyleModal}
uiStateActions={uiStateActions}
diff --git a/src/components/side-panel/common/dataset-tag.js b/src/components/side-panel/common/dataset-tag.js
index cc32de4a6..7c051329f 100644
--- a/src/components/side-panel/common/dataset-tag.js
+++ b/src/components/side-panel/common/dataset-tag.js
@@ -19,8 +19,11 @@
// THE SOFTWARE.
import React from 'react';
+import {FormattedMessage} from 'localization';
import styled from 'styled-components';
-import {DatasetSquare} from 'components/common/styled-components';
+import {DatasetSquare, Tooltip} from 'components';
+
+function nop(_) {}
const DatasetTagWrapper = styled.div`
display: flex;
@@ -31,7 +34,7 @@ const DatasetTagWrapper = styled.div`
.dataset-color {
flex-shrink: 0;
- margin-top: 5px;
+ margin-top: 3px;
}
.dataset-name {
@@ -41,11 +44,44 @@ const DatasetTagWrapper = styled.div`
}
`;
+const DatasetColorPicker = styled.div`
+ display: flex;
+`;
+
+const UpdateTableColor = ({updateTableColor = nop, children, id}) => (
+ <DatasetColorPicker
+ className="dataset-action update-color"
+ data-tip
+ data-for={`update-color-${id}`}
+ onClick={e => {
+ e.stopPropagation();
+ updateTableColor(id);
+ }}
+ >
+ {children}
+ </DatasetColorPicker>
+);
+
export default function DatasetTagFactory() {
- const DatasetTag = ({onClick, dataset}) => (
- <DatasetTagWrapper className="source-data-tag" onClick={onClick}>
- <DatasetSquare className="dataset-color" color={dataset.color} />
- <div className="dataset-name" title={dataset.label}>
+ const DatasetTag = ({onClick, onClickSquare, dataset, updateTableColor, id}) => (
+ <DatasetTagWrapper className="source-data-tag" updateTableColor={updateTableColor}>
+ <UpdateTableColor id={dataset.id} updateTableColor={updateTableColor}>
+ <DatasetSquare
+ className="dataset-color"
+ color={dataset.color}
+ onClick={onClickSquare}
+ data-tip
+ data-for={`update-color-${id}`}
+ />
+ {updateTableColor ? (
+ <Tooltip id={`update-color-${id}`} effect="solid">
+ <span>
+ <FormattedMessage id={'Update color'} />
+ </span>
+ </Tooltip>
+ ) : null}
+ </UpdateTableColor>
+ <div className="dataset-name" title={dataset.label} onClick={onClick}>
{dataset.label}
</div>
</DatasetTagWrapper>
diff --git a/src/components/side-panel/common/dataset-title.js b/src/components/side-panel/common/dataset-title.js
index 7a9e967f0..cf08367da 100644
--- a/src/components/side-panel/common/dataset-title.js
+++ b/src/components/side-panel/common/dataset-title.js
@@ -18,13 +18,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {PureComponent} from 'react';
+import React, {createRef, PureComponent} from 'react';
import styled from 'styled-components';
import {FormattedMessage} from 'localization';
import {CenterFlexbox, Tooltip} from 'components/common/styled-components';
import {ArrowRight, Table, Trash} from 'components/common/icons';
import DatasetTagFactory from 'components/side-panel/common/dataset-tag';
+import CustomPicker from '../layer-panel/custom-picker';
+import {Portaled} from 'components';
+import {rgbToHex} from 'utils/color-utils';
function nop(_) {}
@@ -102,6 +105,20 @@ DatasetTitleFactory.deps = [DatasetTagFactory];
export default function DatasetTitleFactory(DatasetTag) {
class DatasetTitle extends PureComponent {
+ state = {
+ displayColorPicker: false
+ };
+
+ _handleClick = () => {
+ this.setState({displayColorPicker: !this.state.displayColorPicker});
+ };
+
+ _handleClosePicker = () => {
+ this.setState({displayColorPicker: false});
+ };
+
+ root = createRef();
+
_onClickTitle = e => {
e.stopPropagation();
if (typeof this.props.onTitleClick === 'function') {
@@ -117,27 +134,44 @@ export default function DatasetTitleFactory(DatasetTag) {
showDeleteDataset,
onTitleClick,
removeDataset,
- dataset
+ dataset,
+ updateTableColor
} = this.props;
return (
- <StyledDatasetTitle
- className="source-data-title"
- clickable={Boolean(showDatasetTable || onTitleClick)}
- >
- <DatasetTag dataset={dataset} onClick={this._onClickTitle} />
- {showDatasetTable ? (
- <CenterFlexbox className="source-data-arrow">
- <ArrowRight height="12px" />
- </CenterFlexbox>
- ) : null}
- {showDatasetTable ? (
- <ShowDataTable id={dataset.id} showDatasetTable={showDatasetTable} />
- ) : null}
- {showDeleteDataset ? (
- <RemoveDataset datasetKey={dataset.id} removeDataset={removeDataset} />
- ) : null}
- </StyledDatasetTitle>
+ <div className="custom-palette-panel" ref={this.root}>
+ <StyledDatasetTitle
+ className="source-data-title"
+ clickable={Boolean(showDatasetTable || onTitleClick)}
+ >
+ <DatasetTag
+ dataset={dataset}
+ onClick={this._onClickTitle}
+ updateTableColor={updateTableColor}
+ onClickSquare={this._handleClick}
+ />
+ <Portaled isOpened={this.state.displayColorPicker !== false} left={110} top={-50}>
+ <CustomPicker
+ color={rgbToHex(dataset.color)}
+ onChange={color =>
+ updateTableColor(dataset.id, [color.rgb.r, color.rgb.g, color.rgb.b])
+ }
+ onSwatchClose={this._handleClosePicker}
+ />
+ </Portaled>
+ {showDatasetTable ? (
+ <CenterFlexbox className="source-data-arrow">
+ <ArrowRight height="12px" />
+ </CenterFlexbox>
+ ) : null}
+ {showDatasetTable ? (
+ <ShowDataTable id={dataset.id} showDatasetTable={showDatasetTable} />
+ ) : null}
+ {showDeleteDataset ? (
+ <RemoveDataset datasetKey={dataset.id} removeDataset={removeDataset} />
+ ) : null}
+ </StyledDatasetTitle>
+ </div>
);
}
}
diff --git a/src/components/side-panel/common/source-data-catalog.js b/src/components/side-panel/common/source-data-catalog.js
index 464377ae5..b3a3ef526 100644
--- a/src/components/side-panel/common/source-data-catalog.js
+++ b/src/components/side-panel/common/source-data-catalog.js
@@ -37,6 +37,7 @@ function SourceDataCatalogFactory(DatasetTitle, DatasetInfo) {
showDatasetTable,
removeDataset,
onTitleClick,
+ updateTableColor,
showDeleteDataset = false
}) => (
<SourceDataCatalogWrapper className="source-data-catalog">
@@ -48,6 +49,7 @@ function SourceDataCatalogFactory(DatasetTitle, DatasetInfo) {
removeDataset={removeDataset}
dataset={dataset}
onTitleClick={onTitleClick}
+ updateTableColor={updateTableColor}
/>
{showDatasetTable ? <DatasetInfo dataset={dataset} /> : null}
</SidePanelSection>
diff --git a/src/components/side-panel/filter-manager.js b/src/components/side-panel/filter-manager.js
index afb89641c..86a5a4bae 100644
--- a/src/components/side-panel/filter-manager.js
+++ b/src/components/side-panel/filter-manager.js
@@ -29,7 +29,14 @@ import FilterPanelFactory from './filter-panel/filter-panel';
FilterManagerFactory.deps = [SourceDataCatalogFactory, FilterPanelFactory];
function FilterManagerFactory(SourceDataCatalog, FilterPanel) {
- const FilterManager = ({filters = [], datasets, layers, showDatasetTable, visStateActions}) => {
+ const FilterManager = ({
+ filters = [],
+ datasets,
+ layers,
+ showDatasetTable,
+ updateTableColor,
+ visStateActions
+ }) => {
const {
addFilter,
enlargeFilter,
@@ -55,7 +62,11 @@ function FilterManagerFactory(SourceDataCatalog, FilterPanel) {
return (
<div className="filter-manager">
- <SourceDataCatalog datasets={datasets} showDatasetTable={showDatasetTable} />
+ <SourceDataCatalog
+ datasets={datasets}
+ showDatasetTable={showDatasetTable}
+ updateTableColor={updateTableColor}
+ />
<SidePanelDivider />
<SidePanelSection>
{reversedIndex.map(idx => (
@@ -93,6 +104,7 @@ function FilterManagerFactory(SourceDataCatalog, FilterPanel) {
layers: PropTypes.arrayOf(PropTypes.any).isRequired,
filters: PropTypes.arrayOf(PropTypes.any).isRequired,
showDatasetTable: PropTypes.func.isRequired,
+ updateTableColor: PropTypes.func.isRequired,
visStateActions: PropTypes.object.isRequired,
// fields can be undefined when dataset is not selected
diff --git a/src/components/side-panel/layer-manager.js b/src/components/side-panel/layer-manager.js
index 067a1b43e..afc2506ea 100644
--- a/src/components/side-panel/layer-manager.js
+++ b/src/components/side-panel/layer-manager.js
@@ -142,7 +142,8 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
visStateActions: PropTypes.object.isRequired,
// functions
removeDataset: PropTypes.func.isRequired,
- showDatasetTable: PropTypes.func.isRequired
+ showDatasetTable: PropTypes.func.isRequired,
+ updateTableColor: PropTypes.func.isRequired
};
state = {
isSorting: false
@@ -192,6 +193,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
intl,
layerOrder,
showAddDataModal,
+ updateTableColor,
showDatasetTable,
removeDataset,
uiStateActions,
@@ -223,6 +225,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
<SourceDataCatalog
datasets={datasets}
showDatasetTable={showDatasetTable}
+ updateTableColor={updateTableColor}
removeDataset={removeDataset}
showDeleteDataset
/>
diff --git a/src/constants/action-types.d.ts b/src/constants/action-types.d.ts
index 9bcaf68e9..66649d23e 100644
--- a/src/constants/action-types.d.ts
+++ b/src/constants/action-types.d.ts
@@ -60,6 +60,7 @@ export type ActionType = {
COPY_TABLE_COLUMN: string;
NEXT_FILE_BATCH: string;
PROCESS_FILE_CONTENT: string;
+ UPDATE_TABLE_COLOR: string;
// mapState
UPDATE_MAP: string;
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 35cb394e4..6afc0c8c1 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -111,6 +111,7 @@ const ActionTypes = {
COPY_TABLE_COLUMN: `${ACTION_PREFIX}COPY_TABLE_COLUMN`,
NEXT_FILE_BATCH: `${ACTION_PREFIX}NEXT_FILE_BATCH`,
PROCESS_FILE_CONTENT: `${ACTION_PREFIX}PROCESS_FILE_CONTENT`,
+ UPDATE_TABLE_COLOR: `${ACTION_PREFIX}UPDATE_TABLE_COLOR`,
// mapState
UPDATE_MAP: `${ACTION_PREFIX}UPDATE_MAP`,
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index b8bbccdda..fbd3d6bf2 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -377,6 +377,10 @@ export function showDatasetTableUpdater(
state: VisState,
action: VisStateActions.ShowDatasetTableUpdaterAction
): VisState;
+export function updateTableColorUpdater(
+ state: VisState,
+ action: VisStateActions.UpdateDatasetColorUpdater
+): VisState;
export function sortTableColumnUpdater(
state: VisState,
action: VisStateActions.SortTableColumnUpdaterAction
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 5fd74dcb6..42eb556e2 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -56,7 +56,7 @@ import {
} from 'utils/filter-utils';
import {assignGpuChannel, setFilterGpuMode} from 'utils/gpu-filter-utils';
import {createNewDataEntry} from 'utils/dataset-utils';
-import {sortDatasetByColumn} from 'utils/table-utils/kepler-table';
+import {sortDatasetByColumn, copyTableAndUpdate} from 'utils/table-utils/kepler-table';
import {set, toArray, arrayInsert, generateHashId} from 'utils/utils';
import {calculateLayerData, findDefaultLayer} from 'utils/layer-utils';
@@ -82,6 +82,7 @@ import {pick_, merge_, swap_} from './composer-helpers';
import {processFileContent} from 'actions/vis-state-actions';
import KeplerGLSchema from 'schemas';
+import {isRGBColor} from 'utils/color-utils';
// type imports
/** @typedef {import('./vis-state-updaters').Field} Field */
@@ -1124,6 +1125,31 @@ export const showDatasetTableUpdater = (state, action) => {
};
};
+/**
+ * Add custom color for datasets and layers
+ * @memberof visStateUpdaters
+ * @type {typeof import('./vis-state-updaters').updateTableColorUpdater}
+ * @public
+ */
+export const updateTableColorUpdater = (state, action) => {
+ const {dataId, newColor} = action;
+ const {datasets} = state;
+
+ if (isRGBColor(newColor)) {
+ const existing = datasets[dataId];
+ existing.updateTableColor(newColor);
+
+ return {
+ ...state,
+ datasets: {
+ ...state.datasets,
+ [dataId]: copyTableAndUpdate(existing, {})
+ }
+ };
+ }
+ return state;
+};
+
/**
* reset visState to initial State
* @memberof visStateUpdaters
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index 5e842f088..0425fde31 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -96,6 +96,8 @@ const actionHandler = {
[ActionTypes.SHOW_DATASET_TABLE]: visStateUpdaters.showDatasetTableUpdater,
+ [ActionTypes.UPDATE_TABLE_COLOR]: visStateUpdaters.updateTableColorUpdater,
+
[ActionTypes.TOGGLE_FILTER_ANIMATION]: visStateUpdaters.toggleFilterAnimationUpdater,
[ActionTypes.UPDATE_FILTER_ANIMATION_SPEED]: visStateUpdaters.updateFilterAnimationSpeedUpdater,
diff --git a/src/utils/color-utils.js b/src/utils/color-utils.js
index 876d54f1d..e6a2518c8 100644
--- a/src/utils/color-utils.js
+++ b/src/utils/color-utils.js
@@ -104,3 +104,20 @@ export function createLinearGradient(direction, colors) {
return `linear-gradient(to ${direction}, ${bands.join(',')})`;
}
+
+/**
+ * Checking if color is RGB
+ * @param {*} color
+ * @returns boolean
+ */
+export function isRGBColor(color) {
+ if (
+ color &&
+ Array.isArray(color) &&
+ color.length === 3 &&
+ color.every(n => Number.isFinite(n) && n <= 255 && n >= 0)
+ ) {
+ return true;
+ }
+ return false;
+}
diff --git a/src/utils/index.d.ts b/src/utils/index.d.ts
index 96ee64d8c..932a43e11 100644
--- a/src/utils/index.d.ts
+++ b/src/utils/index.d.ts
@@ -2,4 +2,4 @@
export {maybeToDate, roundValToStep} from './data-utils';
export {updateAllLayerDomainData} from '../reducers/vis-state-updaters';
// export {getHexFields} from '../layers/h3-hexagon-layer/h3-utils';
-export {default as KeplerTable, Field, findPointFieldPairs} from './table-utils/kepler-table';
\ No newline at end of file
+export {default as KeplerTable, Field, findPointFieldPairs, copyTableAndUpdate} from './table-utils/kepler-table';
\ No newline at end of file
diff --git a/src/utils/index.js b/src/utils/index.js
index 2e27eb815..c40f7b68c 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -46,5 +46,6 @@ export {resetFilterGpuMode, assignGpuChannels} from 'utils/gpu-filter-utils';
export {updateAllLayerDomainData} from '../reducers/vis-state-updaters';
export {getHexFields} from '../layers/h3-hexagon-layer/h3-utils';
export {containValidTime} from '../layers/trip-layer/trip-utils';
-export {default as KeplerTable, findPointFieldPairs} from './table-utils/kepler-table';
+
+export {KeplerTable, findPointFieldPairs, copyTableAndUpdate} from './table-utils/kepler-table';
export {createDataContainer, createIndexedDataContainer} from './table-utils/data-container-utils';
diff --git a/src/utils/table-utils/kepler-table.d.ts b/src/utils/table-utils/kepler-table.d.ts
index eea96c225..7b9753e24 100644
--- a/src/utils/table-utils/kepler-table.d.ts
+++ b/src/utils/table-utils/kepler-table.d.ts
@@ -106,9 +106,11 @@ export class KeplerTable {
getValue(columnName: string, rowIdx: number): any;
updateColumnField(fieldIdx: number, newField: Field): void;
+ updateTableColor(newColor: RGBColor): void;
getColumnFilterProps(fieldName: string): Field['filterProps'] | null | undefined;
filterTable(filters: Filter[], layers: Layer[], opt?: FilterDatasetOpt): KeplerTable;
filterTableCPU(filters: Filter[], layers: Layer[]): KeplerTable;
}
export default KeplerTable;
+export function copyTableAndUpdate(original: KeplerTable, options: {})
\ No newline at end of file
diff --git a/src/utils/table-utils/kepler-table.js b/src/utils/table-utils/kepler-table.js
index 25330055a..6c06b0147 100644
--- a/src/utils/table-utils/kepler-table.js
+++ b/src/utils/table-utils/kepler-table.js
@@ -146,6 +146,14 @@ class KeplerTable {
this.fields = Object.assign([...this.fields], {[fieldIdx]: newField});
}
+ /**
+ * Update dataset color by custom color
+ * @param {import('reducers/types').RGBColor} newColor
+ */
+ updateTableColor(newColor) {
+ this.color = newColor;
+ }
+
/**
* Save filterProps to field and retrieve it
* @param {string} columnName
@@ -467,6 +475,12 @@ export function copyTable(original) {
return Object.assign(Object.create(Object.getPrototypeOf(original)), original);
}
+/**
+ * @type {typeof import('./kepler-table').copyTableAndUpdate}
+ * @param {KeplerTable} original
+ * @param {*} options
+ * @returns
+ */
export function copyTableAndUpdate(original, options = {}) {
return Object.entries(options).reduce((acc, entry) => {
acc[entry[0]] = entry[1];
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 396e157ef..c8af822fb 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -81,6 +81,7 @@ import {
} from 'test/helpers/mock-state';
import {LAYER_VIS_CONFIGS, DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from 'layers/layer-factory';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
+import {assertDatasetIsTable} from '../../helpers/comparison-utils';
const mockData = {
fields: [
@@ -2782,6 +2783,7 @@ test('#visStateReducer -> REMOVE_DATASET w filter and layer', t => {
datasets: {
[testGeoJsonDataId]: oldState.datasets[testGeoJsonDataId]
},
+
interactionConfig: {
tooltip: {
id: 'tooltip',
@@ -3028,6 +3030,7 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
datasets: {
[testCsvDataId]: oldState.datasets[testCsvDataId]
},
+
filters: [],
interactionConfig: {
tooltip: {
@@ -4612,7 +4615,6 @@ test('#visStateReducer -> APPLY_CPU_FILTER has multi datasets', t => {
test('#visStateReducer -> SORT_TABLE_COLUMN', t => {
const initialState = CloneDeep(StateWFiles.visState);
const previousDataset1 = initialState.datasets[testCsvDataId];
-
// sort with default mode
const nextState = reducer(initialState, VisStateActions.sortTableColumn());
t.equal(nextState, initialState, 'state should not change when input is given');
@@ -4711,8 +4713,25 @@ test('#visStateReducer -> SORT_TABLE_COLUMN', t => {
t.end();
});
+test('#visStateReducer -> updateTableColor', t => {
+ const initialState = CloneDeep(StateWFiles.visState);
+ const newColor = [150, 150, 150];
+
+ const nextState = reducer(
+ initialState,
+ VisStateActions.updateTableColor(testCsvDataId, newColor)
+ );
+
+ // test dataset is table
+ assertDatasetIsTable(t, nextState.datasets[testCsvDataId]);
+ t.deepEqual(nextState.datasets[testCsvDataId].color, newColor, 'should update dataset color');
+
+ t.end();
+});
+
test('#visStateReducer -> PIN_TABLE_COLUMN', t => {
const initialState = CloneDeep(StateWFiles.visState);
+
const previousDataset1 = initialState.datasets[testCsvDataId];
// pin with empty arg