Skip to content

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

[Feat] Redesign color range to use chormajs and d3 color function (#2835)

Igor Dykhta21538366122c
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index 627009158..b16862099 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -77,7 +77,6 @@ export {LayerBlendingSelector, default as LayerManagerFactory} from './side-pane
export {default as ColorPalette} from './side-panel/layer-panel/color-palette';
export {
ALL_TYPES,
- ColorPaletteGroup,
default as ColorRangeSelector,
PaletteConfig
} from './side-panel/layer-panel/color-range-selector';
@@ -101,8 +100,14 @@ export * from './side-panel/layer-panel/channel-by-value-selector';
export * from './side-panel/layer-panel/color-breaks-panel';
export * from './side-panel/layer-panel/color-range-selector';
export * from './side-panel/layer-panel/color-scale-selector';
-export * from './side-panel/layer-panel/custom-palette';
-export {default as CustomPalette} from './side-panel/layer-panel/custom-palette';
+export {
+ AddColorStop,
+ default as CustomPalette,
+ DeleteColorStop,
+ ColorPaletteItem,
+ ColorSwatch,
+ EditableColorRange
+} from './side-panel/layer-panel/custom-palette';
export {default as CustomPicker} from './side-panel/layer-panel/custom-picker';
export {default as DatasetLayerGroupFactory} from './side-panel/layer-panel/dataset-layer-group';
export {default as DatasetLayerSectionFactory} from './side-panel/layer-panel/dataset-layer-section';
diff --git a/src/components/src/side-panel/common/dataset-title.tsx b/src/components/src/side-panel/common/dataset-title.tsx
index 8a9907170..683488cb2 100644
--- a/src/components/src/side-panel/common/dataset-title.tsx
+++ b/src/components/src/side-panel/common/dataset-title.tsx
@@ -161,11 +161,7 @@ export default function DatasetTitleFactory(
top={-50}
onClose={_handleClosePicker}
>
- <CustomPicker
- color={rgbToHex(dataset.color)}
- onChange={_handleCustomPicker}
- onSwatchClose={_handleClosePicker}
- />
+ <CustomPicker color={rgbToHex(dataset.color)} onChange={_handleCustomPicker} />
</Portaled>
{showDatasetTable ? (
<CenterFlexbox className="source-data-arrow">
diff --git a/src/components/src/side-panel/layer-panel/color-range-selector.tsx b/src/components/src/side-panel/layer-panel/color-range-selector.tsx
index c2fddbbaf..b21ddb683 100644
--- a/src/components/src/side-panel/layer-panel/color-range-selector.tsx
+++ b/src/components/src/side-panel/layer-panel/color-range-selector.tsx
@@ -1,22 +1,29 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import uniq from 'lodash.uniq';
import React, {MouseEvent, useCallback, useMemo} from 'react';
import styled from 'styled-components';
-
-import {COLOR_RANGES, ColorRange} from '@kepler.gl/constants';
+import {KEPLER_COLOR_PALETTES, PALETTE_TYPES, ColorRange, ColorPalette} from '@kepler.gl/constants';
import {FormattedMessage} from '@kepler.gl/localization';
import {ColorUI, NestedPartial} from '@kepler.gl/types';
-import {hasColorMap, numberSort, reverseColorRange, updateColorRange} from '@kepler.gl/utils';
+import {
+ hasColorMap,
+ updateColorRangeBySelectedPalette,
+ paletteIsSteps,
+ paletteIsType,
+ paletteIsColorBlindSafe
+} from '@kepler.gl/utils';
import ItemSelector from '../../common/item-selector/item-selector';
import {PanelLabel, Tooltip} from '../../common/styled-components';
import Switch from '../../common/switch';
-import ColorPalette from './color-palette';
+import ColorPalettePanel from './color-palette';
import CustomPaletteFactory from './custom-palette';
+import {capitalizeFirstLetter} from '@kepler.gl/utils';
+import {range} from 'd3-array';
+
type ColorRangeSelectorProps = {
- colorRanges?: ColorRange[];
+ colorPalettes?: ColorPalette[];
colorPaletteUI: ColorUI;
selectedColorRange: ColorRange;
onSelectColorRange: (p: ColorRange, e: MouseEvent) => void;
@@ -36,20 +43,10 @@ type PaletteConfigProps = {
reason?: string;
};
-type ColorPaletteGroupProps = {
- reversed?: boolean;
- selected: ColorRange;
- colorRanges: ColorRange[];
- onSelect: (p: ColorRange, e: MouseEvent) => void;
-};
-
-export const ALL_TYPES: string[] = uniq(
- COLOR_RANGES.map(c => c.type)
- .filter(ctype => ctype)
- .concat(['all', 'custom']) as string[]
-);
-
-export const ALL_STEPS: number[] = uniq(COLOR_RANGES.map(d => d.colors.length)).sort(numberSort);
+// @ts-ignore cant concat 'all' to PALETTE_TYPES values
+export const ALL_TYPES = Object.values(PALETTE_TYPES).concat(['all']);
+const MAX_STEPS = 20;
+const ALL_STEPS = range(2, MAX_STEPS + 1, 1);
const StyledColorConfig = styled.div`
padding: 12px 12px 0 12px;
@@ -96,37 +93,43 @@ const CONFIG_SETTINGS = {
type: 'switch',
options: [true, false]
},
+ colorBlindSafe: {
+ type: 'switch',
+ options: [true, false]
+ },
custom: {
label: 'customPalette',
type: 'switch',
options: [true, false]
}
};
+const displayOption = d => capitalizeFirstLetter(d);
+const getOptionValue = d => d;
ColorRangeSelectorFactory.deps = [CustomPaletteFactory];
function ColorRangeSelectorFactory(
CustomPalette: ReturnType<typeof CustomPaletteFactory>
): React.FC<ColorRangeSelectorProps> {
const ColorRangeSelector: React.FC<ColorRangeSelectorProps> = ({
- colorRanges,
+ colorPalettes,
colorPaletteUI,
setColorPaletteUI,
onSelectColorRange,
selectedColorRange
}) => {
const {customPalette, showSketcher, colorRangeConfig} = colorPaletteUI;
- const {type, steps} = colorRangeConfig;
+ const {type, steps, colorBlindSafe, reversed} = colorRangeConfig;
- const filteredColorRanges = useMemo(() => {
+ const filteredColorPalettes = useMemo(() => {
return (
- colorRanges?.filter(colorRange => {
- const isType = type === 'all' || type === colorRange.type;
- const isStep = Number(steps) === colorRange.colors.length;
-
- return isType && isStep;
- }) ?? []
+ colorPalettes?.filter(
+ palette =>
+ paletteIsType(palette, type) &&
+ paletteIsSteps(palette, steps) &&
+ paletteIsColorBlindSafe(palette, colorBlindSafe)
+ ) ?? []
);
- }, [colorRanges, type, steps]);
+ }, [colorPalettes, colorBlindSafe, steps, type]);
const _updateConfig = useCallback(
({key, value}) => {
@@ -147,12 +150,16 @@ function ColorRangeSelectorFactory(
[customPalette, onSelectColorRange]
);
- const onSelectFromList = useCallback(
- (colorRange, e) => {
- const newColorRange = updateColorRange(selectedColorRange, colorRange);
+ const _onSelectPalette = useCallback(
+ (colorPalette, e) => {
+ const newColorRange = updateColorRangeBySelectedPalette(selectedColorRange, colorPalette, {
+ steps,
+ reversed
+ });
+
onSelectColorRange(newColorRange, e);
},
- [selectedColorRange, onSelectColorRange]
+ [selectedColorRange, reversed, steps, onSelectColorRange]
);
return (
<StyledColorRangeSelector>
@@ -179,7 +186,7 @@ function ColorRangeSelectorFactory(
{colorRangeConfig.custom ? (
<>
<StyledColorPalette>
- <ColorPalette colors={customPalette.colors} />
+ <ColorPalettePanel colors={customPalette.colors} />
</StyledColorPalette>
<CustomPalette
customPalette={customPalette}
@@ -190,19 +197,25 @@ function ColorRangeSelectorFactory(
/>
</>
) : (
- <ColorPaletteGroup
- colorRanges={filteredColorRanges}
- onSelect={onSelectFromList}
- selected={selectedColorRange}
- reversed={colorRangeConfig.reversed}
- />
+ <div className="color-palette__group">
+ {filteredColorPalettes.map((colorPalette, i) => (
+ <ColorPaletteItem
+ key={`${colorPalette.name}-${i}`}
+ colorPalette={colorPalette}
+ selectedColorRange={selectedColorRange}
+ onSelect={_onSelectPalette}
+ reversed={reversed}
+ steps={steps}
+ />
+ ))}
+ </div>
)}
</StyledColorRangeSelector>
);
};
ColorRangeSelector.defaultProps = {
- colorRanges: COLOR_RANGES,
+ colorPalettes: KEPLER_COLOR_PALETTES,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onSelectColorRange: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -248,6 +261,8 @@ export const PaletteConfig: React.FC<PaletteConfigProps> = ({
onChange={updateSelect}
disabled={disabled}
inputTheme="secondary"
+ displayOption={displayOption}
+ getOptionValue={getOptionValue}
/>
)}
{type === 'switch' && (
@@ -280,28 +295,33 @@ const StyledColorRange = styled.div.attrs({
}
`;
-export const ColorPaletteGroup: React.FC<ColorPaletteGroupProps> = ({
- reversed,
+type ColorPaletteItemProps = {
+ reversed?: boolean;
+ selected?: ColorRange;
+ colorPalette: ColorPalette;
+ selectedColorRange: ColorRange;
+ onSelect: (colorPalette: ColorPalette, e: MouseEvent) => void;
+ steps: number;
+};
+
+export const ColorPaletteItem: React.FC<ColorPaletteItemProps> = ({
+ colorPalette,
+ steps,
+ selectedColorRange,
onSelect,
- selected,
- colorRanges
-}) => (
- <div className="color-palette__group">
- {colorRanges.map((colorRange, i) => (
- <StyledColorRange
- key={`${colorRange.name}-${i}`}
- onClick={e =>
- onSelect(reversed ? (reverseColorRange(true, colorRange) as ColorRange) : colorRange, e)
- }
- >
- <ColorPalette
- colors={colorRange.colors}
- isReversed={reversed}
- isSelected={colorRange.name === selected.name && reversed === Boolean(selected.reversed)}
- />
- </StyledColorRange>
- ))}
- </div>
-);
+ reversed
+}) => {
+ const colors = useMemo(() => colorPalette.colors(steps), [colorPalette, steps]);
+ const onClick = useCallback(e => onSelect(colorPalette, e), [colorPalette, onSelect]);
+ return (
+ <StyledColorRange onClick={onClick}>
+ <ColorPalettePanel
+ colors={colors}
+ isReversed={reversed}
+ isSelected={colorPalette.name === selectedColorRange.name}
+ />
+ </StyledColorRange>
+ );
+};
export default ColorRangeSelectorFactory;
diff --git a/src/components/src/side-panel/layer-panel/custom-palette.tsx b/src/components/src/side-panel/layer-panel/custom-palette.tsx
index 8c5f1bf96..3cf08228a 100644
--- a/src/components/src/side-panel/layer-panel/custom-palette.tsx
+++ b/src/components/src/side-panel/layer-panel/custom-palette.tsx
@@ -22,7 +22,7 @@ import styled, {StyledComponent, css} from 'styled-components';
import Portaled from '../../common/portaled';
import {KeyEvent} from '@kepler.gl/constants';
-import {ColorUI, HexColor} from '@kepler.gl/types';
+import {ColorUI, HexColor, NestedPartial} from '@kepler.gl/types';
import {colorMapToColorBreaks, isNumericColorBreaks} from '@kepler.gl/utils';
import {
addCustomPaletteColor,
@@ -42,9 +42,7 @@ export type ActionIcons = {
};
export type EditColorMapFunc = (v: number, i: number) => void;
-export type SetColorUIFunc = (
- newConfig: Partial<{[key in keyof ColorUI]: ColorUI[keyof ColorUI]}>
-) => void;
+export type SetColorUIFunc = (newConfig: NestedPartial<ColorUI>) => void;
/**
* EditableColorRange
@@ -526,8 +524,8 @@ function CustomPaletteFactory(): React.FC<CustomPaletteProps> {
if (!customPalette.colorMap) {
return;
}
- const newColorMap = customPalette.colorMap.map((cm, i) =>
- i === index ? [value, cm[1]] : cm
+ const newColorMap = customPalette.colorMap.map(
+ (cm, i) => (i === index ? [value, cm[1]] : cm) as [string, string]
);
setColorPaletteUI({
customPalette: {
@@ -569,12 +567,8 @@ function CustomPaletteFactory(): React.FC<CustomPaletteProps> {
<DividerLine />
{/* Cancel or Confirm Buttons */}
<BottomAction onCancel={onCancel} onConfirm={onConfirm} />
- <Portaled isOpened={showSketcher !== false} left={280} top={-300}>
- <CustomPicker
- color={colors[Number(showSketcher)]}
- onChange={onPickerUpdate}
- onSwatchClose={onSwatchClose}
- />
+ <Portaled isOpened={showSketcher !== false} left={280} top={-300} onClose={onSwatchClose}>
+ <CustomPicker color={colors[Number(showSketcher)]} onChange={onPickerUpdate} />
</Portaled>
</StyledCustomPalette>
);
diff --git a/src/components/src/side-panel/layer-panel/custom-picker.tsx b/src/components/src/side-panel/layer-panel/custom-picker.tsx
index d944519d8..a8715f203 100644
--- a/src/components/src/side-panel/layer-panel/custom-picker.tsx
+++ b/src/components/src/side-panel/layer-panel/custom-picker.tsx
@@ -7,8 +7,6 @@ import {SketchPicker, ColorChangeHandler} from 'react-color';
import {HexColor} from '@kepler.gl/types';
-import useOnClickOutside from '../../hooks/use-on-click-outside';
-
// This was put in because 3rd party library react-color doesn't yet cater for customized color of child component <SketchField> which contains HEX/RGB input text box
// Issue raised: https://github.com/casesandberg/react-color/issues/631
@@ -63,13 +61,9 @@ type CustomPickerProps = {
panelBackground: string;
};
onChange: ColorChangeHandler;
- onSwatchClose: () => void;
};
-const CustomPicker: React.FC<CustomPickerProps> = props => {
- const {color, onChange, theme} = props;
- const ref = useOnClickOutside<HTMLDivElement>(props.onSwatchClose);
-
+const CustomPicker: React.FC<CustomPickerProps> = ({color, onChange, theme}: CustomPickerProps) => {
const pickerStyle = useMemo(
() => ({
picker: {
@@ -83,7 +77,7 @@ const CustomPicker: React.FC<CustomPickerProps> = props => {
);
return (
- <StyledPicker ref={ref}>
+ <StyledPicker>
<SketchPicker
color={color}
onChange={onChange}
diff --git a/src/components/src/side-panel/layer-panel/single-color-palette.tsx b/src/components/src/side-panel/layer-panel/single-color-palette.tsx
index c14b5bfa0..a425a1619 100644
--- a/src/components/src/side-panel/layer-panel/single-color-palette.tsx
+++ b/src/components/src/side-panel/layer-panel/single-color-palette.tsx
@@ -59,9 +59,6 @@ const ColorPickerTop = ({setMode, mode}) => (
</StyledColorPickerTop>
);
-// eslint-disable-next-line @typescript-eslint/no-empty-function
-const nop = () => {};
-
const SingleColorPalette: React.FC<SingleColorPaletteProps> = ({
selectedColor,
onSelectColor
@@ -85,9 +82,7 @@ const SingleColorPalette: React.FC<SingleColorPaletteProps> = ({
selectedColor={selectedColor}
/>
) : null}
- {mode === MODE.picker ? (
- <CustomPicker color={selectedColor} onChange={onSetColor} onSwatchClose={nop} />
- ) : null}
+ {mode === MODE.picker ? <CustomPicker color={selectedColor} onChange={onSetColor} /> : null}
</div>
);
};
diff --git a/src/components/src/side-panel/map-style-panel/map-layer-group-color-picker.tsx b/src/components/src/side-panel/map-style-panel/map-layer-group-color-picker.tsx
index 1bc2e434c..5c558773a 100644
--- a/src/components/src/side-panel/map-style-panel/map-layer-group-color-picker.tsx
+++ b/src/components/src/side-panel/map-style-panel/map-layer-group-color-picker.tsx
@@ -80,11 +80,7 @@ function LayerGroupColorPickerFactory() {
top={-50}
onClose={onClosePicker}
>
- <CustomPicker
- color={rgbToHex(color)}
- onChange={onCustomPickerChange}
- onSwatchClose={onClosePicker}
- />
+ <CustomPicker color={rgbToHex(color)} onChange={onCustomPickerChange} />
</Portaled>
</LayerGroupColorPickerWrapper>
);
diff --git a/src/constants/package.json b/src/constants/package.json
index 061182796..498a9cb7a 100644
--- a/src/constants/package.json
+++ b/src/constants/package.json
@@ -33,8 +33,10 @@
"@kepler.gl/types": "3.1.0-alpha.1",
"@types/d3-scale": "^3.2.2",
"@types/keymirror": "^0.1.1",
+ "chroma-js": "2.1.2",
"colorbrewer": "^1.5.0",
"d3-scale": "^3.2.3",
+ "d3-scale-chromatic": "2.0.0",
"global": "^4.3.0",
"keymirror": "^0.1.1"
},
diff --git a/src/constants/src/color-palettes.ts b/src/constants/src/color-palettes.ts
new file mode 100644
index 000000000..b089665ed
--- /dev/null
+++ b/src/constants/src/color-palettes.ts
@@ -0,0 +1,594 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import * as d3ScaleChromatic from 'd3-scale-chromatic';
+import {range} from 'd3-array';
+import chroma from 'chroma-js';
+import Console from 'global/console';
+import {color as d3Color} from 'd3-color';
+import {HexColor, ValueOf} from '@kepler.gl/types';
+import {MiniColorRange} from './layers';
+
+type GetColors = (steps: number) => HexColor[];
+// linear interpolator
+type GetLinear = () => (n: number) => string;
+
+export type CategoricalPalette = {
+ name: string;
+ type: 'qualitative';
+ category: ValueOf<typeof CATEGORIES>;
+ colorBlindSafe: boolean;
+
+ colors: GetColors;
+ // categorical palette
+ maxStep: number;
+};
+
+export type SequentialPalette = {
+ name: string;
+ type: 'sequential' | 'diverging' | 'cyclical';
+ category: ValueOf<typeof CATEGORIES>;
+ colorBlindSafe: boolean;
+ colors: GetColors;
+ // sequential palette
+ linear: GetLinear;
+};
+
+export type ColorPalette = CategoricalPalette | SequentialPalette;
+
+export const CATEGORIES = {
+ COLORBREWER: 'ColorBrewer',
+ D3: 'D3',
+ UBER: 'Uber',
+ COLORBLIND: 'ColorBlind'
+};
+
+export const PALETTE_TYPES: {
+ SEQ: 'sequential';
+ QUA: 'qualitative';
+ DIV: 'diverging';
+ CYC: 'cyclical';
+} = {
+ SEQ: 'sequential',
+ QUA: 'qualitative',
+ DIV: 'diverging',
+ CYC: 'cyclical'
+};
+
+export const COLORBREWER_SCHEME = {
+ [PALETTE_TYPES.SEQ]: [
+ 'BuGn',
+ 'BuPu',
+ 'GnBu',
+ 'OrRd',
+ 'PuBu',
+ 'PuBuGn',
+ 'PuRd',
+ 'RdPu',
+ 'YlGn',
+ 'YlGnBu',
+ 'YlOrBr',
+ 'YlOrRd',
+ 'Blues',
+ 'Greens',
+ 'Greys',
+ 'Oranges',
+ 'Purples',
+ 'Reds'
+ ], // 18 + 9 + 8
+ // singlehue: ['Blues', 'Greens', 'Greys', 'Oranges', 'Purples', 'Reds'],
+ [PALETTE_TYPES.DIV]: [
+ 'BrBG',
+ 'PiYG',
+ 'PRGn',
+ 'PuOr',
+ 'RdBu',
+ 'RdGy',
+ 'RdYlBu',
+ 'RdYlGn',
+ 'Spectral'
+ ],
+ [PALETTE_TYPES.QUA]: ['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3']
+};
+
+// https://rdrr.io/cran/RColorBrewer/man/ColorBrewer.html
+const COLOR_BLIND_SAFE_MAP = {
+ // colorbrewer
+ BrBG: true,
+ PiYG: true,
+ PRGn: true,
+ PuOr: true,
+ RdBu: true,
+ RdGy: false,
+ RdYlBu: true,
+ RdYlGn: false,
+ Spectral: false,
+ Accent: false,
+ Dark2: true,
+ Paired: true,
+ Pastel1: false,
+ Pastel2: false,
+ Set1: false,
+ Set2: true,
+ Set3: false,
+ Blues: true,
+ BuGn: true,
+ BuPu: true,
+ GnBu: true,
+ Greens: true,
+ Greys: true,
+ Oranges: true,
+ OrRd: true,
+ PuBu: true,
+ PuBuGn: true,
+ PuRd: true,
+ Purples: true,
+ RdPu: true,
+ Reds: true,
+ YlGn: true,
+ YlGnBu: true,
+ YlOrBr: true,
+ YlOrRd: true,
+
+ // d3 scale chromatic
+ Sinebow: true,
+ Rainbow: false,
+ Turbo: true,
+ Viridis: true,
+ Inferno: true,
+ Magma: true,
+ Plasma: true,
+ Cividis: true,
+ Warm: true,
+ Cool: false,
+ CubehelixDefault: true,
+ Tableau10: false
+};
+
+export const D3_COLOR_CHROMATIC_SCHEME = {
+ [PALETTE_TYPES.CYC]: ['Sinebow', 'Rainbow'],
+ [PALETTE_TYPES.SEQ]: [
+ 'Turbo',
+ 'Viridis',
+ 'Inferno',
+ 'Magma',
+ 'Plasma',
+ 'Cividis',
+ 'Warm',
+ 'Cool',
+ 'CubehelixDefault'
+ ],
+ [PALETTE_TYPES.QUA]: ['Tableau10']
+};
+
+export const DataVizColors = {
+ aqua: '#12939A',
+ tumbleweed: '#DDB27C',
+ mule_fawn: '#88572C',
+ tree_poppy: '#FF991F',
+ flame: '#F15C17',
+ sapphire: '#223F9A',
+ orchid: '#DA70BF',
+ chathams_blue: '#125C77',
+ med_aquamarine: '#4DC19C',
+ crocodile: '#776E57',
+ java: '#17B8BE',
+ chalky: '#F6D18A',
+ light_taupe: '#B7885E',
+ peach_orange: '#FFCB99',
+ apricot: '#F89570',
+ portage: '#829AE3',
+ light_orchid: '#E79FD5',
+ blue_green: '#1E96BE',
+ bermuda: '#89DAC1',
+ cloudy: '#B3AD9E'
+};
+
+const UberVizDiverging = {
+ name: 'Uber Viz Diverging',
+ category: CATEGORIES.UBER,
+ type: PALETTE_TYPES.DIV,
+ colors: ['#00939C', '#E6FAFA'],
+ colors2: ['#FEEEE8', '#C22E00'],
+ diverging: true,
+ correctLightness: false,
+ colorBlindSafe: true
+};
+
+const UberVizSequential = {
+ name: 'Uber Viz Sequential',
+ category: CATEGORIES.UBER,
+ type: PALETTE_TYPES.SEQ,
+ colors: ['#00939C', '#E6FAFA'],
+ colorBlindSafe: true
+};
+
+const UberPool = {
+ name: 'UberPool',
+ type: PALETTE_TYPES.DIV,
+ category: CATEGORIES.UBER,
+ colors: ['#223F9A', '#CF1750', '#FAE300'],
+ correctLightness: false,
+ colorBlindSafe: true
+};
+
+const IceAndFire = {
+ name: 'Ice And Fire',
+ type: PALETTE_TYPES.DIV,
+ category: CATEGORIES.UBER,
+ colors: ['#0198BD', '#FAFEB3'],
+ colors2: ['#FEEDB1', '#D50255'],
+ diverging: true,
+ colorBlindSafe: true
+};
+
+const GlobalWarming = {
+ name: 'Global Warming',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#4C0035', '#AC1C17', '#FFC300'],
+ colorBlindSafe: true
+};
+
+const Sunrise = {
+ name: 'Sunrise',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#355C7D', '#C06C84', '#F8B195'],
+ colorBlindSafe: true
+};
+
+const OceanGreen = {
+ name: 'Ocean Green',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#37535E', '#3EACA8', '#E5EEC1'],
+ colorBlindSafe: true
+};
+
+const PinkWine = {
+ name: 'Pink Wine',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#2C1E3D', '#956485', '#EDD1CA'],
+ colorBlindSafe: true
+};
+
+const PurpleBlueYellow = {
+ name: 'Purple Blue Yellow',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#383C65', '#49838A', '#D6DEBF'],
+ mode: 'hsl',
+ colorBlindSafe: true
+};
+
+const ViovetOcean = {
+ name: 'ViovetOcean',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#7400B8', '#5E60CE', '#4EA8DE', '#56CFE1', '#72EFDD'],
+ colorBlindSafe: false
+};
+
+const SummerSky = {
+ name: 'SummerSky',
+ type: PALETTE_TYPES.SEQ,
+ category: CATEGORIES.UBER,
+ colors: ['#184E77', '#168AAD', '#76C893', '#D9ED92'],
+ colorBlindSafe: false
+};
+
+const UberVizQualitative = {
+ name: 'Uber Viz Qualitative',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.UBER,
+ colors: Object.values(DataVizColors),
+ colorBlindSafe: false
+};
+
+// https://personal.sron.nl/~pault/#sec:qualitative
+// A set of Qualitative Colors designed by Paul Tol that are color blind friendly
+const TolBright = {
+ name: 'Tol Bright',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: ['#4477AA', '#EE6677', '#228833', '#CCBB44', '#66CCEE', '#AA3377', '#BBBBBB'],
+ colorBlindSafe: true
+};
+// Bad Data: #BBBBBB
+
+const TolVibrant = {
+ name: 'Tol Vibrant',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: ['#EE7733', '#0077BB', '#33BBEE', '#EE3377', '#CC3311', '#009988', '#BBBBBB'],
+ colorBlindSafe: true
+};
+// Bad Data: #BBBBBB
+
+const TolMuted = {
+ name: 'Tol Muted',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: [
+ '#CC6677',
+ '#332288',
+ '#DDCC77',
+ '#117733',
+ '#88CCEE',
+ '#882255',
+ '#44AA99',
+ '#999933',
+ '#AA4499'
+ ],
+ colorBlindSafe: true
+};
+// Bad Data: #DDDDDD
+
+const TolMediumContrast = {
+ name: 'Tol Medium Contrast',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: ['#6699CC', '#004488', '#EECC66', '#994455', '#997700', '#EE99AA'],
+ colorBlindSafe: true
+};
+
+const TolLight = {
+ name: 'Tol Light',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: ['#77AADD', '#EE8866', '#EEDD88', '#FFAABB', '#99DDFF', '#44BB99', '#BBCC33', '#AAAA00'],
+ colorBlindSafe: true
+};
+
+// https://jfly.uni-koeln.de/color/
+const OkabeIto = {
+ name: 'Okabe Ito',
+ type: PALETTE_TYPES.QUA,
+ category: CATEGORIES.COLORBLIND,
+ colors: ['#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2', '#D55E00', '#CC79A7', '#000000'],
+ colorBlindSafe: true
+};
+// Bad Data: #DDDDDD
+
+/**
+ * Build Categorical color palette
+ */
+export function buildCategoricalPalette({
+ name,
+ category,
+ colors,
+ colorBlindSafe
+}: {
+ name: string;
+ category: ValueOf<typeof CATEGORIES>;
+ colors?: HexColor[];
+ colorBlindSafe?: boolean;
+}): CategoricalPalette {
+ let allColors;
+ // find d3 color scheme
+ const scheme = d3ScaleChromatic[`scheme${name}`];
+
+ if (!scheme && !colors) {
+ Console.warn(`scheme${name} cant not be found in d3 scale chromatic, needs to provide colors`);
+ allColors = ['#DDDDDD'];
+ } else if (!scheme) {
+ // build from colors
+ allColors = colors;
+ } else {
+ allColors = scheme;
+ }
+
+ if (!allColors.length) {
+ Console.warn('Needs to provide valid d3 color scheme name or an array of colors');
+ }
+
+ return {
+ name,
+ category,
+ type: PALETTE_TYPES.QUA,
+ colorBlindSafe: colorBlindSafe ?? COLOR_BLIND_SAFE_MAP[name],
+ maxStep: allColors.length,
+ colors: numColors => {
+ // if numColors > maxSteps, will return allColors
+ return allColors.slice(0, numColors).map(_colorToUppercase);
+ }
+ };
+}
+
+function _colorToUppercase(c) {
+ return d3Color(c).formatHex().toUpperCase();
+}
+/**
+ * All sequantial palette is based on palette in d3-scale-chromatic
+ * https://github.com/d3/d3-scale-chromatic/blob/main/src/index.js
+ */
+function buildSequentialPalette({name, type, category}) {
+ if (!Object.prototype.hasOwnProperty.call(COLOR_BLIND_SAFE_MAP, name)) {
+ Console.warn(`${name} does not exists in COLOR_BLIND_SAFE_MAP`);
+ }
+ const interpolator = d3ScaleChromatic[`interpolate${name}`];
+
+ return {
+ name,
+ type,
+ category,
+ colorBlindSafe: COLOR_BLIND_SAFE_MAP[name],
+ colors: numColors => {
+ return range(0, numColors, 1)
+ .map(d => interpolator(d / (numColors - 1)))
+ .map(_colorToUppercase);
+ },
+ linear: () => {
+ return interpolator;
+ }
+ };
+}
+
+function buildCustomPalette({
+ colors,
+ colors2 = [],
+ correctLightness = true,
+ bezier = false,
+ diverging = false,
+ mode = 'lch',
+ name,
+ type,
+ category,
+ colorBlindSafe
+}: {
+ colors: HexColor[];
+ colors2?: HexColor[];
+ correctLightness?: boolean;
+ bezier?: boolean;
+ diverging?: boolean;
+ mode?: string;
+ name: string;
+ type: SequentialPalette['type'];
+ category: ValueOf<typeof CATEGORIES>;
+ colorBlindSafe: boolean;
+}): SequentialPalette | undefined {
+ const palette: SequentialPalette = {
+ name,
+ type,
+ category,
+ colorBlindSafe,
+ colors: () => [],
+ linear: () => () => ''
+ };
+
+ if (!colors.length) {
+ Console.error('colors has to be an array of colors');
+ return;
+ }
+
+ const scaleLeft = chroma
+ .scale(bezier && colors.length > 1 ? chroma.bezier(colors) : colors)
+ .mode(mode)
+ .correctLightness(correctLightness);
+ let scaleRight;
+ let scaleFull;
+ if (diverging) {
+ if (!colors.length) {
+ Console.error('colors2 has to be an array of colors when diverging = true');
+ return;
+ }
+ scaleRight = chroma
+ .scale(bezier && colors2.length > 1 ? chroma.bezier(colors2) : colors2)
+ .mode(mode)
+ .correctLightness(correctLightness);
+
+ scaleFull = chroma
+ .scale(bezier ? chroma.bezier(colors.concat(colors2)) : colors.concat(colors2))
+ .mode(mode)
+ .correctLightness(correctLightness);
+ }
+
+ // return numColors => (scaleLeft ? stepsLeft.colors(numColors) : []);
+
+ // given number of colors return color steps
+ palette.colors = numColors => {
+ if (diverging) {
+ const even = numColors % 2 === 0;
+
+ const numColorsLeft = Math.ceil(numColors / 2) + (even ? 1 : 0);
+ const numColorsRight = Math.ceil(numColors / 2) + (even ? 1 : 0);
+
+ const colorsLeft = scaleLeft ? scaleLeft.colors(numColorsLeft) : [];
+ const colorsRight = scaleRight ? scaleRight.colors(numColorsRight) : [];
+ const steps = (even ? colorsLeft.slice(0, colorsLeft.length - 1) : colorsLeft)
+ .concat(colorsRight.slice(1))
+ .map(_colorToUppercase);
+
+ return steps;
+ }
+
+ return scaleLeft ? scaleLeft.colors(numColors).map(_colorToUppercase) : [];
+ };
+
+ palette.linear = () => {
+ return diverging ? scaleFull : scaleLeft;
+ };
+
+ return palette;
+}
+
+function buildPaletteBySchemeGroups(
+ schemeGroups: typeof COLORBREWER_SCHEME | typeof D3_COLOR_CHROMATIC_SCHEME,
+ category: ValueOf<typeof CATEGORIES>
+): ColorPalette[] {
+ return Object.entries(schemeGroups).reduce((accu, [type, palettes]) => {
+ return [
+ ...accu,
+ ...palettes.reduce((group, name) => {
+ const colorPalette =
+ type === PALETTE_TYPES.QUA
+ ? buildCategoricalPalette({name, category})
+ : // @ts-ignore jsdoc cant figure out type of 'type'
+ buildSequentialPalette({name, type, category});
+ // @ts-ignore type is not assignable to never[]
+ group.push(colorPalette);
+ return group;
+ }, [])
+ ];
+ }, []);
+}
+
+const COLORBREWER_PALETTES = buildPaletteBySchemeGroups(COLORBREWER_SCHEME, CATEGORIES.COLORBREWER);
+const D3_COLOR_PALETTES = buildPaletteBySchemeGroups(D3_COLOR_CHROMATIC_SCHEME, CATEGORIES.D3);
+const UBER_PALETTES: ColorPalette[] = [
+ UberVizDiverging,
+ UberVizSequential,
+ UberPool,
+ IceAndFire,
+ GlobalWarming,
+ Sunrise,
+ OceanGreen,
+ PinkWine,
+ PurpleBlueYellow,
+ ViovetOcean,
+ SummerSky,
+ UberVizQualitative,
+ TolBright,
+ TolVibrant,
+ TolMuted,
+ TolMediumContrast,
+ TolLight,
+ OkabeIto
+]
+ .map(recipe =>
+ recipe.type === PALETTE_TYPES.QUA ? buildCategoricalPalette(recipe) : buildCustomPalette(recipe)
+ )
+ .filter(Boolean) as ColorPalette[];
+
+export const KEPLER_COLOR_PALETTES: ColorPalette[] = [
+ ...UBER_PALETTES,
+ ...COLORBREWER_PALETTES,
+ ...D3_COLOR_PALETTES
+];
+
+/**
+ * create color range from palette, with steps and reversed as config
+ */
+export function colorPaletteToColorRange(
+ colorPalette: ColorPalette,
+ colorConfig: {
+ reversed: boolean;
+ steps: number;
+ }
+): MiniColorRange {
+ const {steps, reversed} = colorConfig;
+ const colors = colorPalette.colors(steps).slice();
+ if (reversed) {
+ colors.reverse();
+ }
+
+ return {
+ name: colorPalette.name,
+ type: colorPalette.type,
+ category: colorPalette.category,
+ colors,
+ ...(reversed ? {reversed} : {})
+ };
+}
diff --git a/src/constants/src/color-ranges.ts b/src/constants/src/color-ranges.ts
deleted file mode 100644
index 966d935e5..000000000
--- a/src/constants/src/color-ranges.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright contributors to the kepler.gl project
-
-import {HexColor} from '@kepler.gl/types';
-import colorbrewer from 'colorbrewer';
-import {VizColorPalette} from './custom-color-ranges';
-
-export type ColorMap = [string[] | string | number | null, HexColor][];
-// Key is HexColor but as key we can use only string
-export type ColorLegends = {[key: HexColor]: string};
-
-export type ColorRange = {
- name?: string;
- type?: string;
- category?: string;
- colors: HexColor[];
- reversed?: boolean;
- colorMap?: ColorMap;
- colorLegends?: ColorLegends;
-};
-
-// Add colorbrewer color schemes (Data Science requirement)
-// See http://colorbrewer2.org/
-
-const colorBrewerMap = Object.entries(colorbrewer.schemeGroups).reduce(
- (accu, [type, palettes]: [string, any]) => ({
- ...accu,
- ...palettes.reduce(
- (group, name) => ({
- ...group,
- [name]: type
- }),
- {}
- )
- }),
- {}
-);
-
-const colorRanges: ColorRange[] = [...VizColorPalette];
-
-for (const [keyName, colorScheme] of Object.entries(colorbrewer)) {
- if (keyName !== 'schemeGroups') {
- for (const [lenKey, colors] of Object.entries(colorScheme as any)) {
- colorRanges.push({
- name: `ColorBrewer ${keyName}-${lenKey}`,
- type: colorBrewerMap[keyName],
- category: 'ColorBrewer',
- colors: colors as HexColor[]
- });
- }
- }
-}
-
-export const COLOR_RANGES: ColorRange[] = colorRanges;
-
-export const DEFAULT_COLOR_RANGE: ColorRange = colorRanges.find(
- ({name}) => name === 'Global Warming'
-) || {
- name: 'Global Warming',
- type: 'SEQ',
- category: 'Uber',
- colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
-};
diff --git a/src/constants/src/color-palette.ts b/src/constants/src/colors-by-theme.ts
similarity index 97%
rename from src/constants/src/color-palette.ts
rename to src/constants/src/colors-by-theme.ts
index 748199dd1..8bf714e3a 100644
--- a/src/constants/src/color-palette.ts
+++ b/src/constants/src/colors-by-theme.ts
@@ -1,8 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
+import {HexColor} from '@kepler.gl/types';
+
/* eslint-disable quote-props */
-const COLORS = {
+const COLORS: {
+ [key: string]: HexColor;
+} = {
grey_7: '#898989',
brick_20: '#B77B6A',
brick_21: '#8B574F',
@@ -494,7 +498,11 @@ const COLORS = {
export default COLORS;
-export const ColorsByTheme = Object.keys(COLORS).reduce((accu, key) => {
+export const ColorsByTheme: {
+ [theme: string]: {
+ [idx: string]: HexColor;
+ };
+} = Object.keys(COLORS).reduce((accu, key) => {
if (!key.includes('_')) {
return accu;
}
@@ -510,7 +518,7 @@ export const ColorsByTheme = Object.keys(COLORS).reduce((accu, key) => {
}, {});
// theme name in order wheel order
-export const Themes = [
+export const Themes: string[] = [
'yellow',
'gold',
'amber',
diff --git a/src/constants/src/custom-color-ranges.ts b/src/constants/src/custom-color-ranges.ts
deleted file mode 100644
index b2e4f6dea..000000000
--- a/src/constants/src/custom-color-ranges.ts
+++ /dev/null
@@ -1,534 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright contributors to the kepler.gl project
-
-/**
- *
- * Great tool to create color palette
- * http://www.perbang.dk/rgbgradient/
- */
-
-export const SEQ = 'sequential';
-export const SIN = 'singlehue';
-export const QUA = 'qualitative';
-export const DIV = 'diverging';
-
-export const DataVizColors = {
- aqua: '#12939A',
- tumbleweed: '#DDB27C',
- mule_fawn: '#88572C',
- tree_poppy: '#FF991F',
- flame: '#F15C17',
- sapphire: '#223F9A',
- orchid: '#DA70BF',
- chathams_blue: '#125C77',
- med_aquamarine: '#4DC19C',
- crocodile: '#776E57',
- java: '#17B8BE',
- chalky: '#F6D18A',
- light_taupe: '#B7885E',
- peach_orange: '#FFCB99',
- apricot: '#F89570',
- portage: '#829AE3',
- light_orchid: '#E79FD5',
- blue_green: '#1E96BE',
- bermuda: '#89DAC1',
- cloudy: '#B3AD9E'
-};
-
-const quaColors = Object.values(DataVizColors);
-
-const qualitativeColors = [
- {
- name: 'Uber Viz Qualitative 0',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 3)
- },
- {
- name: 'Uber Viz Qualitative 0.5',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 4)
- },
- {
- name: 'Uber Viz Qualitative 1',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 5)
- },
- {
- name: 'Uber Viz Qualitative 1.2',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 6)
- },
- {
- name: 'Uber Viz Qualitative 1.4',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 7)
- },
- {
- name: 'Uber Viz Qualitative 1.6',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 8)
- },
- {
- name: 'Uber Viz Qualitative 1.8',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 9)
- },
- {
- name: 'Uber Viz Qualitative 2',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 10)
- },
- {
- name: 'Uber Viz Qualitative 3',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 15)
- },
- {
- name: 'Uber Viz Qualitative 4',
- type: QUA,
- category: 'Uber',
- colors: quaColors.slice(0, 20)
- }
-];
-
-const sequantialColors = [
- {
- name: 'Uber Viz Sequential 1',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#89C6CA', '#00939C']
- },
- {
- name: 'Uber Viz Sequential 2',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
- },
- {
- name: 'Uber Viz Sequential 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#B8E0E1', '#89C6CA', '#56ACB3', '#00939C']
- },
- {
- name: 'Uber Viz Sequential 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#C1E5E6', '#9DD0D4', '#75BBC1', '#4BA7AF', '#00939C']
- },
- {
- name: 'Uber Viz Sequential 5',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#C1E5E6', '#9DD0D4', '#75BBC1', '#4BA7AF', '#00939C', '#108188']
- },
- {
- name: 'Uber Viz Sequential 6',
- type: SEQ,
- category: 'Uber',
- colors: ['#E6FAFA', '#C1E5E6', '#9DD0D4', '#75BBC1', '#4BA7AF', '#00939C', '#108188', '#0E7077']
- }
-];
-
-const divergingColors = [
- {
- name: 'Uber Viz Diverging 0',
- type: DIV,
- category: 'Uber',
- colors: ['#C22E00', '#FEEEE8', '#00939C'].reverse()
- },
- {
- name: 'Uber Viz Diverging 0.5',
- type: DIV,
- category: 'Uber',
- colors: ['#C22E00', '#EFBEAE', '#A2D4D7', '#00939C'].reverse()
- },
- {
- name: 'Uber Viz Diverging 1',
- type: DIV,
- category: 'Uber',
- colors: ['#C22E00', '#EC9370', '#FEEEE8', '#85C4C8', '#00939C'].reverse()
- },
- {
- name: 'Uber Viz Diverging 1.5',
- type: DIV,
- category: 'Uber',
- colors: ['#C22E00', '#DD7755', '#F8C0AA', '#BAE1E2', '#5DBABF', '#00939C'].reverse()
- },
- {
- name: 'Uber Viz Diverging 2',
- type: DIV,
- category: 'Uber',
- colors: ['#C22E00', '#E17449', '#F5B097', '#FEEEE8', '#A2D4D7', '#65B3BA', '#00939C'].reverse()
- },
- {
- name: 'Uber Viz Diverging 2.5',
- type: DIV,
- category: 'Uber',
- colors: [
- '#C22E00',
- '#D45F39',
- '#E68F71',
- '#F8C0AA',
- '#BAE1E2',
- '#7CC7CB',
- '#3EADB3',
- '#00939C'
- ].reverse()
- },
- {
- name: 'Uber Viz Diverging 3',
- type: DIV,
- category: 'Uber',
- colors: [
- '#C22E00',
- '#DA6436',
- '#EC9370',
- '#F8C0AA',
- '#FEEEE8',
- '#B2DCDF',
- '#65B3BA',
- '#49A6AE',
- '#00939C'
- ].reverse()
- },
- {
- name: 'Uber Viz Diverging 3.5',
- type: DIV,
- category: 'Uber',
- colors: [
- '#C22E00',
- '#D0532B',
- '#DD7755',
- '#EB9C80',
- '#F8C0AA',
- '#BAE1E2',
- '#8CCED1',
- '#5DBABF',
- '#2FA7AE',
- '#00939C'
- ].reverse()
- },
- {
- name: 'Uber Viz Diverging 4',
- type: DIV,
- category: 'Uber',
- colors: [
- '#C22E00',
- '#D55A2B',
- '#E68059',
- '#F2A587',
- '#F8C0AA',
- '#FEEEE8',
- '#BAE1E2',
- '#97CED1',
- '#71BABF',
- '#49A6AE',
- '#00939C'
- ].reverse()
- }
-];
-
-const customPalette = [
- {
- name: 'UberPool',
- type: DIV,
- category: 'Uber',
- colors: [
- '#223F9A',
- '#2C51BE',
- '#482BBD',
- '#7A0DA6',
- '#AE0E7F',
- '#CF1750',
- '#E31A1A',
- '#FD7900',
- '#FAC200',
- '#FAE300'
- ]
- },
- {
- name: 'UberPool 9',
- type: DIV,
- category: 'Uber',
- colors: [
- '#2C51BE',
- '#482BBD',
- '#7A0DA6',
- '#AE0E7F',
- '#CF1750',
- '#E31A1A',
- '#FD7900',
- '#FAC200',
- '#FAE300'
- ]
- },
- {
- name: 'UberPool 8',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#3C1FA7', '#811CB5', '#C318B0', '#D01367', '#DE0F0E', '#EC7007', '#F9E200']
- },
- {
- name: 'UberPool 7',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#461FA9', '#9B1BBA', '#CA168E', '#DA102C', '#E95E08', '#F9E200']
- },
- {
- name: 'UberPool 6',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#551EAD', '#C019BD', '#D31256', '#E6470A', '#F9E200']
- },
- {
- name: 'UberPool 5',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#6E1DB2', '#CA168E', '#E2260C', '#F9E200']
- },
- {
- name: 'UberPool 4',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#9B1BBA', '#DA102C', '#F9E200']
- },
- {
- name: 'UberPool 3',
- type: DIV,
- category: 'Uber',
- colors: ['#213E9A', '#CA168E', '#F9E200']
- },
- {
- name: 'Ice And Fire 3',
- type: DIV,
- category: 'Uber',
- colors: ['#0198BD', '#FAFEB3', '#D50255']
- },
- {
- name: 'Ice And Fire 4',
- type: DIV,
- category: 'Uber',
- colors: ['#0198BD', '#E8FEB5', '#FEAD54', '#D50255']
- },
- {
- name: 'Ice And Fire 5',
- type: DIV,
- category: 'Uber',
- colors: ['#0198BD', '#49E3CE', '#FAFEB3', '#FEAD54', '#D50255']
- },
- {
- name: 'Ice And Fire',
- type: DIV,
- category: 'Uber',
- colors: ['#0198BD', '#49E3CE', '#E8FEB5', '#FEEDB1', '#FEAD54', '#D50255']
- },
- {
- name: 'Ice And Fire 7',
- type: DIV,
- category: 'Uber',
- colors: ['#0198BD', '#54BAB9', '#A7DCB6', '#FAFEB3', '#FCD583', '#FEAD54', '#D50255']
- },
- {
- name: 'Ice And Fire 8',
- type: DIV,
- category: 'Uber',
- colors: ['#007A99', '#0198BD', '#49E3CE', '#E8FEB5', '#FEEDB1', '#FEAD54', '#D50255', '#7F1941']
- },
- {
- name: 'Global Warming 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#5A1846', '#C70039', '#FFC300']
- },
- {
- name: 'Global Warming 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#5A1846', '#831A3D', '#E3611C', '#FFC300']
- },
- {
- name: 'Global Warming 5',
- type: SEQ,
- category: 'Uber',
- colors: ['#5A1846', '#831A3D', '#AC1C17', '#D55D0E', '#FFC300']
- },
- {
- name: 'Global Warming',
- type: SEQ,
- category: 'Uber',
- colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
- },
- {
- name: 'Global Warming 7',
- type: SEQ,
- category: 'Uber',
- colors: ['#5A1846', '#751A43', '#911932', '#AC1C17', '#C84411', '#E37B0A', '#FFC300']
- },
- {
- name: 'Global Warming 8',
- type: SEQ,
- category: 'Uber',
- colors: ['#4C0035', '#650031', '#7F0023', '#98000A', '#B21800', '#CB4600', '#E57F00', '#FFC300']
- },
- {
- name: 'Sunrise 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#355C7D', '#C06C84', '#F8B195']
- },
- {
- name: 'Sunrise 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#355C7D', '#9A627C', '#C86A7E', '#F8B195']
- },
- {
- name: 'Sunrise',
- type: SEQ,
- category: 'Uber',
- colors: ['#355C7D', '#6C5B7B', '#C06C84', '#F67280', '#F8B195']
- },
- {
- name: 'Sunrise 6',
- type: SEQ,
- category: 'Uber',
- colors: ['#355C7D', '#63617F', '#916681', '#D88185', '#E8998D', '#F8B195']
- },
- {
- name: 'Sunrise 7',
- type: SEQ,
- category: 'Uber',
- colors: ['#355C7D', '#63617F', '#916681', '#C06C84', '#D28389', '#E59A8F', '#F8B195']
- },
- {
- name: 'Sunrise 8',
- type: SEQ,
- category: 'Uber',
- colors: ['#194266', '#355C7D', '#63617F', '#916681', '#C06C84', '#D28389', '#E59A8F', '#F8B195']
- },
- {
- name: 'Ocean Green 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#3A748A', '#3EACA8', '#E5EEc1']
- },
- {
- name: 'Ocean Green 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#547A82', '#3EACA8', '#A2D4AB', '#E5EEc1']
- },
- {
- name: 'Ocean Green 5',
- type: SEQ,
- category: 'Uber',
- colors: ['#3A748A', '#54A38F', '#73BC84', '#A9D597', '#E5EEc1']
- },
- {
- name: 'Ocean Green 6',
- type: SEQ,
- category: 'Uber',
- colors: ['#37535E', '#3A748A', '#4095B5', '#52AEC9', '#72BFC4', '#93CFBF']
- },
- {
- name: 'Ocean Green 7',
- type: SEQ,
- category: 'Uber',
- colors: ['#3A748A', '#4B9A95', '#5EAB8B', '#73BC84', '#92CC8B', '#BEDDA5', '#E5EEc1']
- },
- {
- name: 'Ocean Green 8',
- type: SEQ,
- category: 'Uber',
- colors: ['#37535E', '#3A748A', '#4B9A95', '#5EAB8B', '#73BC84', '#92CC8B', '#BEDDA5', '#E5EEc1']
- },
- {
- name: 'Pink Wine 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#50315E', '#956485', '#EDD1CA']
- },
- {
- name: 'Pink Wine 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#50315E', '#774976', '#B28294', '#EDD1CA']
- },
- {
- name: 'Pink Wine 5',
- type: SEQ,
- category: 'Uber',
- colors: ['#50315E', '#643D68', '#956485', '#C1939D', '#EDD1CA']
- },
- {
- name: 'Pink Wine 6',
- type: SEQ,
- category: 'Uber',
- colors: ['#2C1E3D', '#573660', '#83537C', '#A6758E', '#C99DA4', '#EDD1CA']
- },
- {
- name: 'Pink Wine 7',
- type: SEQ,
- category: 'Uber',
- colors: ['#2C1E3D', '#4F315A', '#774976', '#956485', '#B28294', '#CFA4A8', '#EDD1CA']
- },
- {
- name: 'Pink Wine',
- type: SEQ,
- category: 'Uber',
- colors: ['#2C1E3D', '#50315E', '#764476', '#9A5B88', '#B77495', '#CF91A3', '#E0B1B3', '#EDD1CA']
- },
- {
- name: 'Purple Blue Yellow 3',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#5EA28D', '#D6DEBF']
- },
- {
- name: 'Purple Blue Yellow 4',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#466373', '#7BA889', '#D6DEBF']
- },
- {
- name: 'Purple Blue Yellow 5',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#3A4B66', '#5F8E86', '#8BB68D', '#D6DEBF']
- },
- {
- name: 'Purple Blue Yellow 6',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#343D5E', '#4F777E', '#709E87', '#99BE95', '#D6DEBF']
- },
- {
- name: 'Purple Blue Yellow 7',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#303558', '#466373', '#5F8E86', '#7BA889', '#A4C39B', '#D6DEBF']
- },
- {
- name: 'Purple Blue Yellow',
- type: SEQ,
- category: 'Uber',
- colors: ['#2B1E3E', '#383C65', '#3E5F7E', '#49838A', '#5EA28D', '#82BB92', '#AECEA1', '#D6DEBF']
- }
-];
-
-export const VizColorPalette = [
- ...divergingColors,
- ...sequantialColors,
- ...qualitativeColors,
- ...customPalette
-];
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index f971eb104..bb0a43269 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -845,6 +845,9 @@ export const DEFAULT_LAYER_COLOR = {
request_lat: '#52A353'
};
+export const DEFAULT_LAYER_COLOR_PALETTE = 'Global Warming';
+export const DEFAULT_LAYER_COLOR_PALETTE_STEPS = 6;
+
// let user pass in default tooltip fields
export const DEFAULT_TOOLTIP_FIELDS: any[] = [];
diff --git a/src/constants/src/index.ts b/src/constants/src/index.ts
index 4a341a94a..663dd8668 100644
--- a/src/constants/src/index.ts
+++ b/src/constants/src/index.ts
@@ -3,9 +3,8 @@
// Constants
-export * from './color-palette';
-export * from './color-ranges';
-export * from './custom-color-ranges';
+export * from './colors-by-theme';
+export * from './color-palettes';
export * from './default-settings';
export * from './layers';
export {default as KeyEvent} from './keyevent';
diff --git a/src/constants/src/layers.ts b/src/constants/src/layers.ts
index 3c0b291dc..b78c995c9 100644
--- a/src/constants/src/layers.ts
+++ b/src/constants/src/layers.ts
@@ -3,16 +3,41 @@
import keyMirror from 'keymirror';
-import {ColorRange, DEFAULT_COLOR_RANGE} from './color-ranges';
-import {AGGREGATION_TYPES} from './default-settings';
-
+import {
+ AGGREGATION_TYPES,
+ DEFAULT_LAYER_COLOR_PALETTE,
+ DEFAULT_LAYER_COLOR_PALETTE_STEPS
+} from './default-settings';
import {
ColorUI,
+ HexColor,
LayerTextConfig,
LayerTextLabel,
LayerVisConfigSettings,
RGBAColor
} from '@kepler.gl/types';
+import {ColorPalette, KEPLER_COLOR_PALETTES, colorPaletteToColorRange} from './color-palettes';
+
+export type ColorMap = [string[] | string | number | null, HexColor][];
+// Key is HexColor but as key we can use only string
+export type ColorLegends = {[key: HexColor]: string};
+
+export type ColorRange = {
+ name?: string;
+ type?: string;
+ category?: string;
+ colors: HexColor[];
+ reversed?: boolean;
+ colorMap?: ColorMap;
+ colorLegends?: ColorLegends;
+};
+
+export type MiniColorRange = {
+ name: string;
+ type: string;
+ category: string;
+ colors: HexColor[];
+};
export type AggregationTypes = keyof typeof AGGREGATION_TYPES;
@@ -32,7 +57,6 @@ export const PROPERTY_GROUPS = keyMirror({
export const DEFAULT_LAYER_OPACITY = 0.8;
export const DEFAULT_HIGHLIGHT_COLOR: RGBAColor = [252, 242, 26, 255];
export const DEFAULT_LAYER_LABEL = 'new layer';
-export {DEFAULT_COLOR_RANGE};
export const DEFAULT_TEXT_LABEL: LayerTextLabel = {
field: null,
@@ -47,6 +71,15 @@ export const DEFAULT_TEXT_LABEL: LayerTextLabel = {
backgroundColor: [0, 0, 200, 255]
};
+const DEFAULT_COLOR_PALETTE = KEPLER_COLOR_PALETTES.find(
+ ({name}) => name === DEFAULT_LAYER_COLOR_PALETTE
+) as ColorPalette;
+
+export const DEFAULT_COLOR_RANGE = colorPaletteToColorRange(DEFAULT_COLOR_PALETTE, {
+ reversed: false,
+ steps: DEFAULT_LAYER_COLOR_PALETTE_STEPS
+});
+
export const DEFAULT_CUSTOM_PALETTE: ColorRange = {
name: 'color.customPalette',
type: 'custom',
@@ -70,6 +103,7 @@ export const DEFAULT_COLOR_UI: ColorUI = {
type: 'all',
steps: 6,
reversed: false,
+ colorBlindSafe: false,
custom: false,
customBreaks: false
}
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index dc08118a5..c1ce2772d 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -16,7 +16,6 @@ import {
ALL_FIELD_TYPES,
CHANNEL_SCALES,
CHANNEL_SCALE_SUPPORTED_FIELDS,
- COLOR_RANGES,
ColorRange,
DEFAULT_COLOR_UI,
DEFAULT_CUSTOM_PALETTE,
@@ -34,17 +33,15 @@ import {
TEXT_OUTLINE_MULTIPLIER,
UNKNOWN_COLOR_KEY
} from '@kepler.gl/constants';
-
import {
DataContainerInterface,
- getColorGroupByName,
getLatLngBounds,
getSampleContainerData,
hasColorMap,
hexToRgb,
isPlainObject,
- reverseColorRange,
- isDomainStops
+ isDomainStops,
+ updateColorRangeByMatchingPalette
} from '@kepler.gl/utils';
import {generateHashId, toArray, notNullorUndefined} from '@kepler.gl/common-utils';
import {Datasets, GpuFilter, KeplerTable} from '@kepler.gl/table';
@@ -965,7 +962,7 @@ class Layer {
// only update colorRange if changes in UI is made to 'reversed', 'steps' or steps
const shouldUpdate =
newConfig.colorRangeConfig &&
- ['reversed', 'steps'].some(
+ ['reversed', 'steps', 'colorBlindSafe', 'type'].some(
key =>
Object.prototype.hasOwnProperty.call(newConfig.colorRangeConfig, key) &&
newConfig.colorRangeConfig[key] !==
@@ -974,27 +971,11 @@ class Layer {
if (!shouldUpdate) return;
const {colorUI, visConfig} = this.config;
- const {steps, reversed} = colorUI[prop].colorRangeConfig;
- const colorRange = visConfig[prop];
- // find based on step or reversed
- let update;
- if (Object.prototype.hasOwnProperty.call(newConfig.colorRangeConfig, 'steps')) {
- const group = getColorGroupByName(colorRange);
-
- if (group) {
- const sameGroup = COLOR_RANGES.filter(cr => getColorGroupByName(cr) === group);
-
- update = sameGroup.find(cr => cr.colors.length === steps);
- if (update && colorRange.reversed) {
- update = reverseColorRange(true, update);
- }
- }
- }
-
- if (Object.prototype.hasOwnProperty.call(newConfig.colorRangeConfig, 'reversed')) {
- update = reverseColorRange(reversed, update || colorRange);
- }
+ const update = updateColorRangeByMatchingPalette(
+ visConfig[prop],
+ colorUI[prop].colorRangeConfig
+ );
if (update) {
this.updateLayerVisConfig({[prop]: update});
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index b62f2f1ca..f2940df43 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -569,10 +569,10 @@ ${'```'}
},
color: {
customPalette: 'Custom Palette',
- steps: 'steps',
- type: 'type',
- reversed: 'reversed',
- opacity: 'Opacity',
+ steps: 'Steps',
+ type: 'Type',
+ colorBlindSafe: 'Colorblind Safe',
+ reversed: 'Reversed',
disableStepReason: `Can't change number of steps with custom color breaks, use custom palette to edit steps`,
preset: 'Preset Colors',
picker: 'Color Picker'
diff --git a/src/schemas/src/vis-state-schema.ts b/src/schemas/src/vis-state-schema.ts
index e2e36c4c0..345afb161 100644
--- a/src/schemas/src/vis-state-schema.ts
+++ b/src/schemas/src/vis-state-schema.ts
@@ -4,7 +4,7 @@
import pick from 'lodash.pick';
import {VERSIONS} from './versions';
import {LAYER_VIS_CONFIGS, FILTER_VIEW_TYPES} from '@kepler.gl/constants';
-import {isFilterValidToSave, findById} from '@kepler.gl/utils';
+import {colorRangeBackwardCompatibility, isFilterValidToSave, findById} from '@kepler.gl/utils';
import {notNullorUndefined} from '@kepler.gl/common-utils';
import Schema from './schema';
import cloneDeep from 'lodash.clonedeep';
@@ -507,13 +507,22 @@ const visConfigModificationV1 = {
class VisConfigSchemaV1 extends Schema {
key = 'visConfig';
-
+ // layer.config.visConfig
+ // colorRange
load(visConfig, parents, accumulated) {
const [layer] = parents.slice(-2, -1);
const modified = visConfigModificationV1[layer.type]
? visConfigModificationV1[layer.type](visConfig, parents, accumulated)
: {};
const loadedVisConfig = {...visConfig, ...modified};
+
+ // backward compatibility, load colorRange and change the name to match new color Palette
+ ['colorRange', 'strokeColorRange'].forEach(prop => {
+ if (loadedVisConfig?.[prop]) {
+ loadedVisConfig[prop] = colorRangeBackwardCompatibility(loadedVisConfig[prop]);
+ }
+ });
+
return {
visConfig: loadedVisConfig
};
diff --git a/src/types/layers.d.ts b/src/types/layers.d.ts
index 15da495ce..0669d9d4e 100644
--- a/src/types/layers.d.ts
+++ b/src/types/layers.d.ts
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
+import {ColorRange} from '@kepler.gl/constants';
+
export type LayerBaseConfig = {
dataId: string | null;
label: string;
@@ -145,6 +147,15 @@ export type LayerTextLabel = {
backgroundColor: RGBAColor;
};
+export type ColorRangeConfig = {
+ type: string;
+ steps: number;
+ reversed: boolean;
+ custom: boolean;
+ customBreaks: boolean;
+ colorBlindSafe: boolean;
+};
+
export type ColorUI = {
// customPalette in edit
customPalette: ColorRange;
@@ -155,13 +166,7 @@ export type ColorUI = {
// show color scale chart
showColorChart: boolean;
// color range selector config
- colorRangeConfig: {
- type: string;
- steps: number;
- reversed: boolean;
- custom: boolean;
- customBreaks: boolean;
- };
+ colorRangeConfig: ColorRangeConfig;
};
export type VisConfig = {
diff --git a/src/utils/src/color-utils.ts b/src/utils/src/color-utils.ts
index 764f3644a..26bedae26 100644
--- a/src/utils/src/color-utils.ts
+++ b/src/utils/src/color-utils.ts
@@ -1,11 +1,18 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {ColorRange} from '@kepler.gl/constants';
-import {HexColor, RGBColor} from '@kepler.gl/types';
+import {
+ CategoricalPalette,
+ ColorPalette,
+ ColorRange,
+ colorPaletteToColorRange
+} from '@kepler.gl/constants';
+import {ColorRangeConfig, HexColor, RGBColor} from '@kepler.gl/types';
import {rgb as d3Rgb} from 'd3-color';
import {interpolate} from 'd3-interpolate';
import {arrayInsert, arrayMove} from './utils';
+import Console from 'global/console';
+import {KEPLER_COLOR_PALETTES, PALETTE_TYPES} from '@kepler.gl/constants';
/**
* get r g b from hex code
@@ -48,33 +55,6 @@ export function rgbToHex([r, g, b]: RGBColor): HexColor {
return `#${[r, g, b].map(n => PadNum(n)).join('')}`.toUpperCase();
}
-/**
- * Get color group name by parsing name, discard step in the name
- * e.g. Global Warming 6 -> Global Warming
- *
- * @param colorRange
- */
-export function getColorGroupByName(colorRange: ColorRange): string | null {
- if (!colorRange || typeof colorRange.name !== 'string') {
- return null;
- }
-
- return colorRange.name.replace(/\b[^a-zA-Z]+$/, '');
-}
-
-/**
- * Get a reversed colorRange
- * @param reversed
- * @param colorRange
- */
-export function reverseColorRange(reversed: boolean, colorRange: ColorRange): ColorRange | null {
- const newColors = colorRange?.colors.slice().reverse();
- const updated = replaceColorsInColorRange(colorRange, newColors);
- updated.reversed = reversed;
-
- return updated;
-}
-
/**
* Whether color range has custom color map
*/
@@ -137,10 +117,21 @@ export function normalizeColor(color: number[]): number[] {
return color.map(component => component / 255.0);
}
-export function interpolateHex(hex1, hex2) {
- return d3Rgb(interpolate(hex1, hex2)(0.5))
- .hex()
- .toUpperCase();
+/**
+ * Convert color to Hex
+ */
+export function colorMaybeToHex(color: unknown): HexColor {
+ const rgbColor = colorMaybeToRGB(color);
+ if (rgbColor) return rgbToHex(rgbColor);
+ return '#000000';
+}
+
+/**
+ * Convert color to Hex
+ */
+
+export function interpolateHex(hex1: HexColor, hex2: HexColor): HexColor {
+ return d3Rgb(interpolate(hex1, hex2)(0.5)).hex().toUpperCase();
}
export function addNewQuantativeColorBreakAtIndex(colorMap, index, newColors) {
@@ -302,15 +293,133 @@ export function updateCustomPaletteColor(
}
/**
- * Update color range, copy over colorMap and colorLegends
+ * Get a reversed colorRange
+ */
+export function reverseColorRange(reversed: boolean, colorRange: ColorRange): ColorRange {
+ const newColors = colorRange?.colors.slice().reverse();
+ const updated = replaceColorsInColorRange(colorRange, newColors);
+ updated.reversed = reversed;
+
+ return updated;
+}
+
+/**
+ * Whether palette matches current ColorBlindSafe config
+ */
+export function paletteIsColorBlindSafe(palette: ColorPalette, colorBlindSafe: boolean) {
+ return !colorBlindSafe || (colorBlindSafe && palette.colorBlindSafe);
+}
+
+/**
+ * Whether palette matches current steps config
+ */
+export function isQuaPalette(palette: ColorPalette): palette is CategoricalPalette {
+ return palette.type === PALETTE_TYPES.QUA;
+}
+
+/**
+ * Whether palette matches current steps config
*/
-export function updateColorRange(oldColorRange: ColorRange, newColorRange: ColorRange): ColorRange {
+export function paletteIsSteps(palette: ColorPalette, steps: number): boolean {
+ return !isQuaPalette(palette) || palette.maxStep >= steps;
+}
+
+/**
+ * Whether palette matches current type config
+ */
+export function paletteIsType(palette: ColorPalette, type: string): boolean {
+ return type === 'all' || type === palette.type;
+}
+/**
+ * Find best match palette based on config, update color range by it
+ */
+export function updateColorRangeByMatchingPalette(
+ currentColorRange: ColorRange,
+ config: ColorRangeConfig
+): ColorRange {
+ const {steps, colorBlindSafe, type} = config;
+
+ const matchingPalette = KEPLER_COLOR_PALETTES.filter(
+ palette =>
+ // palette match type
+ paletteIsType(palette, type) &&
+ // palette has same step
+ paletteIsSteps(palette, steps) &&
+ // palette is colorBlindSafe
+ paletteIsColorBlindSafe(palette, colorBlindSafe)
+ );
+
+ const bestMatch = matchingPalette.length
+ ? matchingPalette.find(p => p.name === currentColorRange.name) || matchingPalette[0]
+ : null;
+
+ if (bestMatch) {
+ return updateColorRangeBySelectedPalette(currentColorRange, bestMatch, config);
+ }
+ // we do nothing
+ Console.warn(
+ `we cant find any preset palette matches requirments: steps=${steps} && colorBlindSafe=${colorBlindSafe}`
+ );
+
+ return currentColorRange;
+}
+
+/**
+ * Update color range after selecting a palette from color range selectoer
+ * Copy over colorMap and colorLegends
+ */
+export function updateColorRangeBySelectedPalette(
+ oldColorRange: ColorRange,
+ colorPalette: ColorPalette,
+ colorConfig: {
+ reversed: boolean;
+ steps: number;
+ }
+): ColorRange {
+ // const {reversed} = colorConfig;
+
const colorRange = {
- ...newColorRange,
- colors: oldColorRange.colors,
+ ...colorPaletteToColorRange(colorPalette, colorConfig),
+ // ...(reversed ? {reversed} : {}),
...(oldColorRange.colorMap ? {colorMap: oldColorRange.colorMap} : {}),
...(oldColorRange.colorLegends ? {colorLegends: oldColorRange.colorLegends} : {})
};
- return replaceColorsInColorRange(colorRange, newColorRange.colors);
+ return replaceColorsInColorRange(colorRange, colorRange.colors);
+}
+
+const UberNameRegex = new RegExp(/^([A-Za-z ])+/g);
+const ColorBrewerRegex = new RegExp(/^ColorBrewer ([A-Za-z1-9])+/g);
+
+/**
+ * convert saved colorRange to colorPalette objevt type/name/category/isColorBlind
+ */
+export function colorRangeBackwardCompatibility(colorRange: ColorRange): ColorRange {
+ if (!colorRange || colorRange.type === 'custom' || colorRange.colorMap) {
+ // don't do anything to custom color palette, or palette with custom breaks
+ return colorRange;
+ }
+ let trimName;
+ if (colorRange.category === 'Uber') {
+ const matchName = (colorRange.name ?? '').match(UberNameRegex);
+ trimName = matchName ? matchName[0].trim() : null;
+ // match Uber Viz Qualitative 1.4 -> Uber Viz Qualitative
+ } else if (colorRange.category === 'ColorBrewer') {
+ const matchName = (colorRange.name ?? '').match(ColorBrewerRegex);
+ trimName = matchName ? matchName[0].replace('ColorBrewer ', '').trim() : null;
+ }
+
+ if (trimName) {
+ const matchingPalette = KEPLER_COLOR_PALETTES.find(p => p.name === trimName);
+ if (matchingPalette) {
+ return {
+ ...colorRange,
+ name: trimName,
+ type: matchingPalette?.type,
+ category: matchingPalette.category
+ };
+ }
+ }
+
+ return colorRange;
}
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index 000dfdce3..856596f69 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -5,8 +5,8 @@
export {
colorMaybeToRGB,
+ colorRangeBackwardCompatibility,
createLinearGradient,
- getColorGroupByName,
hasColorMap,
hexToRgb,
isHexColor,
@@ -14,11 +14,15 @@ export {
normalizeColor,
reverseColorRange,
rgbToHex,
- updateColorRange,
addCustomPaletteColor,
removeCustomPaletteColor,
sortCustomPaletteColor,
- updateCustomPaletteColor
+ updateCustomPaletteColor,
+ updateColorRangeBySelectedPalette,
+ paletteIsSteps,
+ paletteIsType,
+ paletteIsColorBlindSafe,
+ updateColorRangeByMatchingPalette
} from './color-utils';
export {errorNotification} from './notifications-utils';
diff --git a/test/browser/components/map/map-legend-test.js b/test/browser/components/map/map-legend-test.js
index a2da91944..c24a4aab6 100644
--- a/test/browser/components/map/map-legend-test.js
+++ b/test/browser/components/map/map-legend-test.js
@@ -154,13 +154,13 @@ function testPointLayerLegend(t, pointLegend, onLayerVisConfigChange) {
'point layer legend should render color by measure: gps_data.types'
);
- // colors: ["#E6FAFA", "#AAD7DA", "#68B4BB", "#00939C"]
+ // colors: ['#00939C', '#6BB5B9', '#AAD7D9', '#E6FAFA']
// colorDomain ["driver_analytics", "driver_analytics_0", "driver_gps"]
t.equal(pointLegend.find(LegendRow).length, 3, 'Should render 3 legends');
const expectedLegend = [
- ['#E6FAFA', 'driver_analytics'],
- ['#AAD7DA', 'driver_analytics_0'],
- ['#68B4BB', 'driver_gps']
+ ['#00939C', 'driver_analytics'],
+ ['#6BB5B9', 'driver_analytics_0'],
+ ['#AAD7D9', 'driver_gps']
];
for (let i = 0; i < 3; i++) {
const rect = pointLegend
@@ -199,7 +199,7 @@ function testPointLayerLegend(t, pointLegend, onLayerVisConfigChange) {
);
t.deepEqual(
onLayerVisConfigChange.args[0][1].colorRange.colorLegends,
- {'#E6FAFA': 'taro'},
+ {'#00939C': 'taro'},
'second arg should contain colorLegends'
);
}
@@ -248,7 +248,7 @@ test('Components -> MapLegend.render -> with colorLegends', t => {
ptLayer.config.visConfig.colorRange = {
...ptLayer.config.visConfig.colorRange,
colorLegends: {
- '#E6FAFA': 'taro'
+ '#00939C': 'taro'
}
};
let wrapper;
diff --git a/test/browser/components/side-panel/channel-by-value-selctor-test.js b/test/browser/components/side-panel/channel-by-value-selctor-test.js
index 1e0cf3c36..8b80f195b 100644
--- a/test/browser/components/side-panel/channel-by-value-selctor-test.js
+++ b/test/browser/components/side-panel/channel-by-value-selctor-test.js
@@ -29,7 +29,7 @@ import {
EditableColorRange
} from '@kepler.gl/components';
-import {StateWFilesFiltersLayerColor} from 'test/helpers/mock-state';
+import {StateWFilesFiltersLayerColor, expectedColorRangeInLayer} from 'test/helpers/mock-state';
const ChannelByValueSelector = appInjector.get(ChannelByValueSelectorFactory);
const DimensionScaleSelector = appInjector.get(DimensionScaleSelectorFactory);
@@ -44,15 +44,15 @@ function nop() {
const ExpectedCustomPalette = {
customPalette: {
- name: 'Uber Viz Sequential 2',
+ name: 'Uber Viz Sequential',
type: 'sequential',
category: 'Uber',
- colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C'],
+ colors: expectedColorRangeInLayer.colors,
colorMap: [
- [3032, '#E6FAFA'],
- [6063, '#AAD7DA'],
- [9093, '#68B4BB'],
- [null, '#00939C']
+ [3032, expectedColorRangeInLayer.colors[0]],
+ [6063, expectedColorRangeInLayer.colors[1]],
+ [9093, expectedColorRangeInLayer.colors[2]],
+ [null, expectedColorRangeInLayer.colors[3]]
]
},
showSketcher: false,
@@ -63,7 +63,8 @@ const ExpectedCustomPalette = {
steps: 6,
reversed: false,
custom: false,
- customBreaks: true
+ customBreaks: true,
+ colorBlindSafe: false
}
};
@@ -225,6 +226,7 @@ test('Components -> ChannelByValueSelector -> ColorScaleSelector -> ColorBreakDi
fields: updatedState.visState.datasets[pointLayer1.config.dataId].fields,
setColorUI
};
+
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
@@ -260,10 +262,10 @@ test('Components -> ChannelByValueSelector -> ColorScaleSelector -> ColorBreakDi
t.equal(wrapper.find(ColorPaletteItem).length, 4, 'Should render 4 ColorPaletteItem');
const expectedText = [
- ['#E6FAFA', '1', '3032'],
- ['#AAD7DA', '3032', '6063'],
- ['#68B4BB', '6063', '9093'],
- ['#00939C', '9093', '12120']
+ [expectedColorRangeInLayer.colors[0], '1', '3032'],
+ [expectedColorRangeInLayer.colors[1], '3032', '6063'],
+ [expectedColorRangeInLayer.colors[2], '6063', '9093'],
+ [expectedColorRangeInLayer.colors[3], '9093', '12120']
];
for (let i = 0; i < 4; i++) {
@@ -366,10 +368,10 @@ test('Components -> ChannelByValueSelector -> ColorScaleSelector -> ColorBreakDi
const expectedCustomPalette1 = {
...ExpectedCustomPalette.customPalette,
colorMap: [
- [3032, '#E6FAFA'],
- [5000, '#AAD7DA'],
- [9093, '#68B4BB'],
- [null, '#00939C']
+ [3032, expectedColorRangeInLayer.colors[0]],
+ [5000, expectedColorRangeInLayer.colors[1]],
+ [9093, expectedColorRangeInLayer.colors[2]],
+ [null, expectedColorRangeInLayer.colors[3]]
]
};
diff --git a/test/browser/components/side-panel/color-selector-test.js b/test/browser/components/side-panel/color-selector-test.js
index 30684c441..60c855706 100644
--- a/test/browser/components/side-panel/color-selector-test.js
+++ b/test/browser/components/side-panel/color-selector-test.js
@@ -12,10 +12,8 @@ import {appInjector, Button, ColorPalette} from '@kepler.gl/components';
import {
AddColorStop,
- ALL_TYPES,
ArcLayerColorSelectorFactory,
ColorBlock,
- ColorPaletteGroup,
ColorRangeSelectorFactory,
ColorSelectorFactory,
ColorSelectorInput,
@@ -32,11 +30,12 @@ import {
SingleColorPalette
} from '@kepler.gl/components';
-import {COLOR_RANGES} from '@kepler.gl/constants';
+import {KEPLER_COLOR_PALETTES} from '@kepler.gl/constants';
import {hexToRgb} from '@kepler.gl/utils';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
import {StateWFilesFiltersLayerColor, StateWTrips} from 'test/helpers/mock-state';
+import {clickItemSelector} from '../../../helpers/component-utils';
const ColorSelector = appInjector.get(ColorSelectorFactory);
const LayerColorSelector = appInjector.get(LayerColorSelectorFactory);
@@ -363,7 +362,7 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector', t => {
t.end();
});
-test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRangeSelector -> select type', t => {
+test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRangeSelector -> select palette', t => {
const initialState = StateWTrips.visState;
const {layers} = initialState;
@@ -400,21 +399,111 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
const crs = wrapper.find(ColorRangeSelector);
t.equal(crs.length, 1, 'should render 1 ColorRangeSelector');
- const pc = crs.find(PaletteConfig);
- t.equal(pc.length, 4, 'should render 4 PaletteConfig');
+ const item = crs.find('ColorPaletteItem');
+ t.equal(item.length, 62, `should render ${KEPLER_COLOR_PALETTES.length} Palettes`);
- const cpg = crs.find(ColorPaletteGroup);
- t.equal(cpg.length, 1, 'should render 1 ColorPaletteGroup');
+ t.equal(
+ item.at(0).find(ColorPalette).find('.color-range-palette__block').length,
+ 8,
+ 'should render 8 color block'
+ );
- const expectedGroups = COLOR_RANGES.filter(cr => cr.colors.length === 6).length + 1;
+ const expectedColor = `rgb(${hexToRgb('#00939C').join(', ')})`;
+ const firstColor = item
+ .at(0)
+ .find(ColorPalette)
+ .find('.color-range-palette__block')
+ .at(0)
+ .getDOMNode()
+ .style.getPropertyValue('background-color');
- t.equal(
- wrapper.find(ColorPalette).length,
- expectedGroups,
- `should render ${expectedGroups} ColorPalette`
+ t.equal(firstColor, expectedColor, 'should render correct background color');
+
+ // click 1st item
+ item.at(0).find('.color-palette-outer').simulate('click');
+ t.ok(updateLayerVisConfig.calledOnce, 'should call updateLayerVisConfig');
+
+ t.deepEqual(
+ updateLayerVisConfig.args[0][0].colorRange,
+ {
+ name: 'Uber Viz Diverging',
+ type: 'diverging',
+ category: 'Uber',
+ colors: [
+ '#C22E00',
+ '#D9653D',
+ '#EB9373',
+ '#F8C0AC',
+ '#B9E0E1',
+ '#8BC6C9',
+ '#5AACB2',
+ '#00939C'
+ ],
+ reversed: true
+ },
+ 'should call updateLayerVisConfig with updated colorRange'
);
+
+ t.end();
+});
+
+test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRangeSelector -> select type', t => {
+ const initialState = StateWTrips.visState;
+ const {layers} = initialState;
+
+ // set showDropdown to true
+ const pointLayer = layers
+ .find(l => l.type === 'point')
+ .updateLayerColorUI('colorRange', {showDropdown: 0});
+ // color range
+ // {
+ // name: 'Ice And Fire 8',
+ // type: 'diverging',
+ // category: 'Uber',
+ // colors: [
+ // '#7F1941', '#D50255',
+ // '#FEAD54', '#FEEDB1',
+ // '#E8FEB5', '#49E3CE',
+ // '#0198BD', '#007A99'
+ // ],
+ // reversed: true
+ // }
+ const updateLayerConfig = sinon.spy();
+ const updateLayerVisConfig = sinon.spy();
+ const updateLayerColorUI = sinon.spy();
+
+ const mockProps = {
+ layer: pointLayer,
+ datasets: initialState.datasets,
+ updateLayerConfig,
+ updateLayerVisConfig,
+ updateLayerColorUI
+ };
+ const visConfiguratorProps = getVisConfiguratorProps(mockProps);
+ let wrapper;
+
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LayerColorRangeSelector {...visConfiguratorProps} />
+ </IntlWrapper>
+ );
+ }, 'Should not fail render color range select');
+
+ // open color dropdown
+ t.equal(wrapper.find('.color-range-selector').length, 1, 'should render 1 color-range-selector');
+
+ const crs = wrapper.find(ColorRangeSelector);
+ t.equal(crs.length, 1, 'should render 1 ColorRangeSelector');
+
+ const pc = crs.find(PaletteConfig);
+ t.equal(pc.length, 5, 'should render 5 PaletteConfig');
+
+ const cpg = crs.find('ColorPaletteItem');
+ t.equal(cpg.length, 62, `should render ${KEPLER_COLOR_PALETTES.length} Palettes`);
+
const typeSelect = crs.find(PaletteConfig).at(0);
- t.equal(typeSelect.find('.side-panel-panel__label').text(), 'type', 'should render type');
+ t.equal(typeSelect.find('.side-panel-panel__label').text(), 'Type', 'should render type');
// click on type select
t.equal(
@@ -423,16 +512,16 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
'should render item selector dropdown input'
);
- typeSelect.find('.item-selector__dropdown').at(0).simulate('click');
+ clickItemSelector(typeSelect);
wrapper.update();
const listItem = wrapper.find('.list__item');
- t.equal(listItem.length, 6, 'should render item selector typeahead');
+ t.equal(listItem.length, 5, 'should render item selector typeahead');
t.deepEqual(
listItem.map(nd => nd.at(0).find('.list__item__anchor').at(0).text()),
- ALL_TYPES,
+ ['Sequential', 'Qualitative', 'Diverging', 'Cyclical', 'All'],
'should render all types'
);
@@ -443,7 +532,7 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
'colorRange',
{
colorRangeConfig: {
- type: 'qualitative'
+ type: 'diverging'
}
}
];
@@ -457,7 +546,7 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
const reverseSwitch = crs.find(PaletteConfig).at(2);
t.equal(
reverseSwitch.find('.side-panel-panel__label').text(),
- 'reversed',
+ 'Reversed',
'should render reversed switch'
);
@@ -479,10 +568,37 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
t.deepEqual(
updateLayerColorUI.args[1],
expectedArgs1,
- 'should call updateLayerColorUI with reversed: true'
+ 'should call updateLayerColorUI with reversed: false'
);
- const customSwitch = crs.find(PaletteConfig).at(3);
+ const colorBlindSwitch = crs.find(PaletteConfig).at(3);
+ t.equal(
+ colorBlindSwitch.find('.side-panel-panel__label').text(),
+ 'Colorblind Safe',
+ 'should render Colorblind Safe switch'
+ );
+
+ colorBlindSwitch.find('input').at(0).simulate('change');
+
+ t.ok(
+ updateLayerColorUI.callCount === 3,
+ 'updateLayerColorUI should be called when click custom switch'
+ );
+ const expectedArgs3 = [
+ 'colorRange',
+ {
+ colorRangeConfig: {
+ colorBlindSafe: true
+ }
+ }
+ ];
+ t.deepEqual(
+ updateLayerColorUI.args[2],
+ expectedArgs3,
+ 'should call updateLayerColorUI with colorBlindSwitch: true'
+ );
+
+ const customSwitch = crs.find(PaletteConfig).at(4);
t.equal(
customSwitch.find('.side-panel-panel__label').text(),
'Custom Palette',
@@ -492,10 +608,10 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
customSwitch.find('input').at(0).simulate('change');
t.ok(
- updateLayerColorUI.callCount === 3,
+ updateLayerColorUI.callCount === 4,
'updateLayerColorUI should be called when click custom switch'
);
- const expectedArgs3 = [
+ const expectedArgs4 = [
'colorRange',
{
colorRangeConfig: {
@@ -504,8 +620,8 @@ test('Components -> LayerColorRangeSelector.render -> ColorSelector -> ColorRang
}
];
t.deepEqual(
- updateLayerColorUI.args[2],
- expectedArgs3,
+ updateLayerColorUI.args[3],
+ expectedArgs4,
'should call updateLayerColorUI with custom: true'
);
t.end();
diff --git a/test/browser/layer-tests/heatmap-layer-specs.js b/test/browser/layer-tests/heatmap-layer-specs.js
index d8e56a35f..56941c882 100644
--- a/test/browser/layer-tests/heatmap-layer-specs.js
+++ b/test/browser/layer-tests/heatmap-layer-specs.js
@@ -67,15 +67,15 @@ test('#Heatmaplayer -> formatLayerData -> w/ GpuFilter', t => {
0,
'rgba(0,0,0,0)',
0.14285714285714285,
- 'rgb(90,24,70)',
+ 'rgb(76,0,53)',
0.2857142857142857,
- 'rgb(144,12,63)',
+ 'rgb(136,0,48)',
0.42857142857142855,
- 'rgb(199,0,57)',
+ 'rgb(183,47,21)',
0.5714285714285714,
- 'rgb(227,97,28)',
+ 'rgb(214,97,10)',
0.7142857142857143,
- 'rgb(241,146,14)',
+ 'rgb(239,145,0)',
0.8571428571428571,
'rgb(255,195,0)'
],
diff --git a/test/fixtures/config_v0_geojson_point.js b/test/fixtures/config_v0_geojson_point.js
index 913bcd663..d71127ced 100644
--- a/test/fixtures/config_v0_geojson_point.js
+++ b/test/fixtures/config_v0_geojson_point.js
@@ -112,14 +112,14 @@ export const parsedConfigV0 = {
sizeField: null,
visConfig: {
colorRange: {
- name: 'ColorBrewer Dark2-6',
+ name: 'Dark2',
type: 'qualitative',
category: 'ColorBrewer',
colors: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02'],
reversed: false
},
strokeColorRange: {
- name: 'ColorBrewer Dark2-6',
+ name: 'Dark2',
type: 'qualitative',
category: 'ColorBrewer',
colors: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02'],
diff --git a/test/fixtures/config_v0_geojson_poly_fill_ele.js b/test/fixtures/config_v0_geojson_poly_fill_ele.js
index c4ece183d..913b0ea41 100644
--- a/test/fixtures/config_v0_geojson_poly_fill_ele.js
+++ b/test/fixtures/config_v0_geojson_poly_fill_ele.js
@@ -167,14 +167,14 @@ export const parsedConfigV0 = {
colorRange: {
category: 'ColorBrewer',
colors: ['#ffffcc', '#d9f0a3', '#addd8e', '#78c679', '#31a354', '#006837'],
- name: 'ColorBrewer YlGn-6',
+ name: 'YlGn',
reversed: false,
type: 'sequential'
},
strokeColorRange: {
category: 'ColorBrewer',
colors: ['#ffffcc', '#d9f0a3', '#addd8e', '#78c679', '#31a354', '#006837'],
- name: 'ColorBrewer YlGn-6',
+ name: 'YlGn',
reversed: false,
type: 'sequential'
},
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 7d65d7cce..fa1bb8936 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -1364,7 +1364,7 @@ mergedLayer4.config = {
radiusScale: 'linear',
visConfig: {
colorRange: {
- name: 'Uber Viz Qualitative 3',
+ name: 'Uber Viz Qualitative',
type: 'qualitative',
category: 'Uber',
colors: [
@@ -1387,7 +1387,7 @@ mergedLayer4.config = {
reversed: false
},
strokeColorRange: {
- name: 'Uber Viz Qualitative 3',
+ name: 'Uber Viz Qualitative',
type: 'qualitative',
category: 'Uber',
colors: [
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index af5ff8ca0..3de975207 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -928,7 +928,7 @@ mergedLayer0.config = {
opacity: 0.8,
thickness: 2,
colorRange: {
- name: 'ColorBrewer YlGnBu-9',
+ name: 'YlGnBu',
type: 'sequential',
category: 'ColorBrewer',
colors: [
@@ -945,7 +945,7 @@ mergedLayer0.config = {
reversed: true
},
strokeColorRange: {
- name: 'ColorBrewer YlGnBu-9',
+ name: 'YlGnBu',
type: 'sequential',
category: 'ColorBrewer',
colors: [
diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.js
index 8b8d6b62b..54e33fdc0 100644
--- a/test/fixtures/state-saved-v1-3.js
+++ b/test/fixtures/state-saved-v1-3.js
@@ -386,14 +386,14 @@ mergedLayer0.config = {
filled: true,
thickness: 2,
colorRange: {
- name: 'ColorBrewer YlGn-6',
+ name: 'YlGn',
type: 'sequential',
category: 'ColorBrewer',
colors: ['#006837', '#31a354', '#78c679', '#addd8e', '#d9f0a3', '#ffffcc'],
reversed: true
},
strokeColorRange: {
- name: 'ColorBrewer YlGn-6',
+ name: 'YlGn',
type: 'sequential',
category: 'ColorBrewer',
colors: ['#006837', '#31a354', '#78c679', '#addd8e', '#d9f0a3', '#ffffcc'],
@@ -446,7 +446,7 @@ mergedLayer1.config = {
worldUnitSize: 2.73,
resolution: 8,
colorRange: {
- name: 'Uber Viz Diverging 1',
+ name: 'Uber Viz Diverging',
type: 'diverging',
category: 'Uber',
colors: ['#00939C', '#85C4C8', '#FEEEE8', '#EC9370', '#C22E00'],
diff --git a/test/fixtures/state-saved-v1-5.js b/test/fixtures/state-saved-v1-5.js
index 7b6a5859a..0ffde0897 100644
--- a/test/fixtures/state-saved-v1-5.js
+++ b/test/fixtures/state-saved-v1-5.js
@@ -7,13 +7,7 @@ import tripGeojson, {
dataToTimeStamp
} from 'test/fixtures/trip-geojson';
import {KeplerGlLayers} from '@kepler.gl/layers';
-import {
- DEFAULT_LAYER_OPACITY,
- DEFAULT_TEXT_LABEL,
- DEFAULT_COLOR_RANGE,
- DEFAULT_COLOR_UI
-} from '@kepler.gl/constants';
-
+import {DEFAULT_LAYER_OPACITY, DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from '@kepler.gl/constants';
const {TripLayer} = KeplerGlLayers;
export const savedStateV1TripGeoJson = {
@@ -265,7 +259,12 @@ mergedLayer0.config = {
visConfig: {
opacity: DEFAULT_LAYER_OPACITY,
thickness: 0.5,
- colorRange: DEFAULT_COLOR_RANGE,
+ colorRange: {
+ name: 'Global Warming',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
+ },
trailLength: 180,
fadeTrail: true,
billboard: false,
diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.js
index 73237c192..f20d680e9 100644
--- a/test/fixtures/test-hex-id-data.js
+++ b/test/fixtures/test-hex-id-data.js
@@ -284,7 +284,7 @@ mergedH3Layer.config = {
name: 'Global Warming',
type: 'sequential',
category: 'Uber',
- colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
+ colors: ['#4C0035', '#880030', '#B72F15', '#D6610A', '#EF9100', '#FFC300']
},
strokeOpacity: 0.8,
thickness: 2,
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 379ca1601..85a109876 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -4,15 +4,14 @@
import test from 'tape-catch';
import cloneDeep from 'lodash.clonedeep';
import {drainTasksForTesting, succeedTaskWithValues} from 'react-palm/tasks';
-
+import {colorPaletteToColorRange} from '@kepler.gl/constants';
import {
getInitialInputStyle,
keplerGlReducerCore as keplerGlReducer,
syncTimeFilterWithLayerTimelineUpdater
} from '@kepler.gl/reducers';
-
import {
- VizColorPalette,
+ KEPLER_COLOR_PALETTES,
COMPARE_TYPES,
DEFAULT_LAYER_OPACITY,
DEFAULT_TEXT_LABEL,
@@ -658,12 +657,11 @@ export function mockStateWithLayerDimensions(state) {
);
const colorFieldPayload = [layer0, {colorField}, 'color'];
-
- const colorRangePayload = [
- layer0,
- {colorRange: VizColorPalette.find(c => c.name === 'Uber Viz Sequential 2')},
- 'color'
- ];
+ const colorRange = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(({name}) => name === 'Uber Viz Sequential'),
+ {steps: 4}
+ );
+ const colorRangePayload = [layer0, {colorRange}, 'color'];
const textLabelField = initialState.visState.datasets[testCsvDataId].fields.find(
f => f.name === 'date'
@@ -967,6 +965,14 @@ export const expectedLoadedLayer0 = {
}
};
+// result of Uber Viz Sequential step 4
+export const expectedColorRangeInLayer = {
+ name: 'Uber Viz Sequential',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#00939C', '#6BB5B9', '#AAD7D9', '#E6FAFA']
+};
+
export const expectedSavedLayer1 = {
id: 'point-0',
type: 'point',
@@ -1000,12 +1006,7 @@ export const expectedSavedLayer1 = {
outline: false,
filled: true,
thickness: 2,
- colorRange: {
- name: 'Uber Viz Sequential 2',
- type: 'sequential',
- category: 'Uber',
- colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
- },
+ colorRange: expectedColorRangeInLayer,
strokeColorRange: DEFAULT_COLOR_RANGE,
strokeColor: null,
radiusRange: [0, 50],
@@ -1049,12 +1050,7 @@ export const expectedLoadedLayer1 = {
opacity: DEFAULT_LAYER_OPACITY,
outline: false,
thickness: 2,
- colorRange: {
- name: 'Uber Viz Sequential 2',
- type: 'sequential',
- category: 'Uber',
- colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
- },
+ colorRange: expectedColorRangeInLayer,
strokeColorRange: DEFAULT_COLOR_RANGE,
filled: true,
strokeColor: null,
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 8b6e55fd7..7c444f0ab 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -48,7 +48,9 @@ import {
BINS,
INTERVAL,
LAYER_TYPES,
- SYNC_TIMELINE_MODES
+ SYNC_TIMELINE_MODES,
+ KEPLER_COLOR_PALETTES,
+ colorPaletteToColorRange
} from '@kepler.gl/constants';
const {ArcLayer, PointLayer, GeojsonLayer, LineLayer, TripLayer} = KeplerGlLayers;
@@ -4215,6 +4217,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. show dropdown', t => {
...DEFAULT_COLOR_UI,
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4235,7 +4238,6 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. show dropdown', t => {
test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
const initialState = CloneDeep(StateWFilesFiltersLayerColor.visState);
const pointLayer = initialState.layers[0];
-
const oldColorRange = CloneDeep(pointLayer.config.visConfig.colorRange);
t.equal(oldColorRange.colors.length, 4, 'old color range should have 4 colors');
@@ -4262,6 +4264,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
...DEFAULT_COLOR_UI,
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 6,
reversed: false,
@@ -4271,12 +4274,11 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
}
};
- const expectedColorRange = {
- name: 'Uber Viz Sequential 4',
- type: 'sequential',
- category: 'Uber',
- colors: ['#E6FAFA', '#C1E5E6', '#9DD0D4', '#75BBC1', '#4BA7AF', '#00939C']
- };
+ const expectedColorRange = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(({name}) => name === 'Uber Viz Sequential'),
+ {steps: 6, reversed: false}
+ );
+
t.deepEqual(
nextState.layers[0].config.colorUI,
expectedColorUI,
@@ -4303,6 +4305,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
...DEFAULT_COLOR_UI,
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 6,
reversed: true,
@@ -4312,13 +4315,10 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
}
};
- const expectedColorRange2 = {
- name: 'Uber Viz Sequential 4',
- type: 'sequential',
- category: 'Uber',
- colors: ['#00939C', '#4BA7AF', '#75BBC1', '#9DD0D4', '#C1E5E6', '#E6FAFA'],
- reversed: true
- };
+ const expectedColorRange2 = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(({name}) => name === 'Uber Viz Sequential'),
+ {steps: 6, reversed: true}
+ );
t.deepEqual(
nextState2.layers[0].config.colorUI,
@@ -4346,6 +4346,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
...DEFAULT_COLOR_UI,
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 8,
reversed: true,
@@ -4355,22 +4356,10 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
}
};
- const expectedColorRange3 = {
- name: 'Uber Viz Sequential 6',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#E6FAFA',
- '#C1E5E6',
- '#9DD0D4',
- '#75BBC1',
- '#4BA7AF',
- '#00939C',
- '#108188',
- '#0E7077'
- ].reverse(),
- reversed: true
- };
+ const expectedColorRange3 = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(({name}) => name === 'Uber Viz Sequential'),
+ {steps: 8, reversed: true}
+ );
t.deepEqual(
nextState3.layers[0].config.colorUI,
@@ -4387,7 +4376,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
const nextState4 = reducer(
nextState,
VisStateActions.layerColorUIChange(nextState3.layers[0], 'colorRange', {
- colorRangeConfig: {steps: 11}
+ colorRangeConfig: {type: 'diverging'}
})
);
@@ -4398,14 +4387,20 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
...DEFAULT_COLOR_UI,
showDropdown: 0,
colorRangeConfig: {
- type: 'all',
- steps: 11,
+ colorBlindSafe: false,
+ type: 'diverging',
+ steps: 8,
reversed: true,
custom: false,
customBreaks: false
}
}
};
+ const expectedColorRange8 = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(({name}) => name === 'Uber Viz Diverging'),
+ {steps: 8, reversed: true}
+ );
+
t.deepEqual(
nextState4.layers[0].config.colorUI,
expectedColorUI4,
@@ -4413,8 +4408,8 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. colorRangeConfig.step', t => {
);
t.deepEqual(
nextState4.layers[0].config.visConfig.colorRange,
- expectedColorRange3,
- 'should note update visConfig.colorRange when no match'
+ expectedColorRange8,
+ 'should get first valid visConfig.colorRange when no match'
);
t.end();
@@ -4454,6 +4449,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
},
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4489,6 +4485,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
},
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4526,6 +4523,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
},
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4561,6 +4559,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
},
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4614,6 +4613,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
},
showDropdown: 0,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4686,6 +4686,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
showDropdown: 0,
showColorChart: false,
colorRangeConfig: {
+ colorBlindSafe: false,
type: 'all',
steps: 4,
reversed: false,
@@ -4706,7 +4707,6 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom Palette', t => {
test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom breaks', t => {
const initialState = CloneDeep(StateWFilesFiltersLayerColor.visState);
const pointLayer = initialState.layers[0];
- const oldColorRange = CloneDeep(pointLayer.config.visConfig.colorRange);
const nextState = reducer(
initialState,
@@ -4721,15 +4721,19 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom breaks', t => {
colorRange: {
...DEFAULT_COLOR_UI,
customPalette: {
- ...oldColorRange,
+ name: 'Uber Viz Sequential',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#00939C', '#6BB5B9', '#AAD7D9', '#E6FAFA'],
colorMap: [
- ['driver_analytics', '#E6FAFA'],
- ['driver_analytics_0', '#AAD7DA'],
- ['driver_gps', '#68B4BB']
+ ['driver_analytics', '#00939C'],
+ ['driver_analytics_0', '#6BB5B9'],
+ ['driver_gps', '#AAD7D9']
]
},
colorRangeConfig: {
type: 'all',
+ colorBlindSafe: false,
steps: 6,
reversed: false,
custom: false,
@@ -4743,49 +4747,7 @@ test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom breaks', t => {
expectedColorUI,
'should set customBreaks: true and update colorUI.customPalette with default colorMap'
);
- t.end();
-});
-
-test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. custom breaks', t => {
- const initialState = CloneDeep(StateWFilesFiltersLayerColor.visState);
- const pointLayer = initialState.layers[0];
- const oldColorRange = CloneDeep(pointLayer.config.visConfig.colorRange);
-
- const nextState = reducer(
- initialState,
- VisStateActions.layerColorUIChange(pointLayer, 'colorRange', {
- colorRangeConfig: {customBreaks: true}
- })
- );
-
- const expectedColorUI = {
- color: DEFAULT_COLOR_UI,
- strokeColorRange: DEFAULT_COLOR_UI,
- colorRange: {
- ...DEFAULT_COLOR_UI,
- customPalette: {
- ...oldColorRange,
- colorMap: [
- ['driver_analytics', '#E6FAFA'],
- ['driver_analytics_0', '#AAD7DA'],
- ['driver_gps', '#68B4BB']
- ]
- },
- colorRangeConfig: {
- type: 'all',
- steps: 6,
- reversed: false,
- custom: false,
- customBreaks: true
- }
- }
- };
- t.deepEqual(
- nextState.layers[0].config.colorUI,
- expectedColorUI,
- 'should set customBreaks: true and update colorUI.customPalette with default colorMap'
- );
t.end();
});
diff --git a/test/node/utils/color-util-test.js b/test/node/utils/color-util-test.js
index b6caa2d15..44b96818d 100644
--- a/test/node/utils/color-util-test.js
+++ b/test/node/utils/color-util-test.js
@@ -3,12 +3,14 @@
import {
addCustomPaletteColor,
+ colorRangeBackwardCompatibility,
createLinearGradient,
removeCustomPaletteColor,
sortCustomPaletteColor,
updateCustomPaletteColor
} from '@kepler.gl/utils';
import test from 'tape';
+import {KEPLER_COLOR_PALETTES, colorPaletteToColorRange} from '@kepler.gl/constants';
test('createLinearGradient', t => {
let colors = [[100, 100, 100]];
@@ -292,3 +294,313 @@ test('ColorUtil -> updateCustomPaletteColor', t => {
t.end();
});
+
+test('ColorUtil -> colorPaletteToColorRange', t => {
+ const TEST_CASES = [
+ {
+ name: 'YlOrRd',
+ steps: 8,
+ colors: [
+ '#FFFFCC',
+ '#FFEA9A',
+ '#FECD6A',
+ '#FEA246',
+ '#FC6932',
+ '#E92A21',
+ '#C00624',
+ '#800026'
+ ]
+ },
+ {name: 'Cividis', steps: 4, colors: ['#002051', '#575C6E', '#A49D78', '#FDEA45']},
+ {name: 'Paired', steps: 4, colors: ['#A6CEE3', '#1F78B4', '#B2DF8A', '#33A02C']},
+ {
+ name: 'Accent',
+ steps: 10,
+ colors: [
+ '#7FC97F',
+ '#BEAED4',
+ '#FDC086',
+ '#FFFF99',
+ '#386CB0',
+ '#F0027F',
+ '#BF5B17',
+ '#666666'
+ ]
+ },
+ {name: 'Uber Viz Sequential', steps: 4, colors: ['#00939C', '#6BB5B9', '#AAD7D9', '#E6FAFA']},
+ {
+ name: 'Uber Viz Diverging',
+ steps: 8,
+ colors: [
+ '#00939C',
+ '#5AACB2',
+ '#8BC6C9',
+ '#B9E0E1',
+ '#F8C0AC',
+ '#EB9373',
+ '#D9653D',
+ '#C22E00'
+ ]
+ },
+ {
+ name: 'Tol Vibrant',
+ steps: 6,
+ colors: ['#EE7733', '#0077BB', '#33BBEE', '#EE3377', '#CC3311', '#009988']
+ }
+ ];
+
+ TEST_CASES.forEach(tc => {
+ const colorRange = colorPaletteToColorRange(
+ KEPLER_COLOR_PALETTES.find(p => p.name === tc.name),
+ {steps: tc.steps}
+ );
+
+ t.deepEqual(colorRange.colors, tc.colors, `Should build correct palette: ${tc.name}`);
+ });
+
+ t.end();
+});
+
+test('ColorUtil -> colorRangeBackwardCompatibility', t => {
+ const OLD_COLOR_RANGES_CUSTOM = [
+ {
+ savedColorRange: {
+ name: 'Uber Viz Qualitative 0',
+ type: 'qualitative',
+ category: 'Uber',
+ colors: ['#12939A', '#DDB27C']
+ },
+ loadedColorRange: {
+ name: 'Uber Viz Qualitative',
+ type: 'qualitative',
+ category: 'Uber',
+ colors: ['#12939A', '#DDB27C']
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'Uber Viz Diverging 0.5',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#000000', '#111111', '#222222']
+ },
+ loadedColorRange: {
+ name: 'Uber Viz Diverging',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#000000', '#111111', '#222222']
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'Uber Viz Sequential 1',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#333333', '#444444', '#555555']
+ },
+ loadedColorRange: {
+ name: 'Uber Viz Sequential',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#333333', '#444444', '#555555']
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'UberPool',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#AAAAAA', '#BBBBBB', '#CCCCCC']
+ },
+ loadedColorRange: {
+ name: 'UberPool',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#AAAAAA', '#BBBBBB', '#CCCCCC']
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'UberPool 9',
+ type: 'sequential',
+ category: 'Uber',
+ colors: ['#DDDDDD', '#EEEEEE', '#FFFFFF']
+ },
+ loadedColorRange: {
+ name: 'UberPool',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#DDDDDD', '#EEEEEE', '#FFFFFF']
+ }
+ }
+ ];
+
+ const OLD_COLOR_RANGES_COLORBREWER = [
+ {
+ savedColorRange: {
+ name: 'ColorBrewer YlGn-3',
+ category: 'ColorBrewer',
+ colors: ['#000000', '#1111111'],
+ type: 'sequential'
+ },
+ loadedColorRange: {
+ name: 'YlGn',
+ category: 'ColorBrewer',
+ colors: ['#000000', '#1111111'],
+ type: 'sequential'
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'ColorBrewer RdYlBu-11',
+ category: 'ColorBrewer',
+ colors: ['#222222', '#333333'],
+ type: 'diverging'
+ },
+ loadedColorRange: {
+ name: 'RdYlBu',
+ category: 'ColorBrewer',
+ colors: ['#222222', '#333333'],
+ type: 'diverging'
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'ColorBrewer Accent-3',
+ category: 'ColorBrewer',
+ colors: ['#444444', '#555555'],
+ type: 'sequantial'
+ },
+ loadedColorRange: {
+ name: 'Accent',
+ category: 'ColorBrewer',
+ colors: ['#444444', '#555555'],
+ type: 'qualitative'
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'ColorBrewer Set3-4',
+ category: 'ColorBrewer',
+ colors: ['#666666', '#777777'],
+ type: 'sequantial'
+ },
+ loadedColorRange: {
+ name: 'Set3',
+ category: 'ColorBrewer',
+ colors: ['#666666', '#777777'],
+ type: 'qualitative'
+ }
+ }
+ ];
+
+ const CUSTOM_COLOR_BREAK = [
+ {
+ savedColorRange: {
+ category: 'Uber',
+ colors: ['#2FA7AE', '#C22E00'],
+ name: 'Uber Viz Diverging 3.5',
+ reversed: false,
+ type: 'diverging',
+ colorMap: [
+ [200500, '#2FA7AE'],
+ [null, '#C22E00']
+ ]
+ },
+ loadedColorRange: {
+ category: 'Uber',
+ colors: ['#2FA7AE', '#C22E00'],
+ name: 'Uber Viz Diverging 3.5',
+ reversed: false,
+ type: 'diverging',
+ colorMap: [
+ [200500, '#2FA7AE'],
+ [null, '#C22E00']
+ ]
+ }
+ },
+ {
+ savedColorRange: {
+ name: 'color.customPalette',
+ type: 'custom',
+ category: 'Custom',
+ colors: ['#631C80', '#E6FAFA'],
+ colorLegends: {'#631C80': 'purple'}
+ },
+ loadedColorRange: {
+ name: 'color.customPalette',
+ type: 'custom',
+ category: 'Custom',
+ colors: ['#631C80', '#E6FAFA'],
+ colorLegends: {'#631C80': 'purple'}
+ }
+ }
+ ];
+
+ const CUSTOM_COLOR_LEGENDS = [
+ {
+ savedColorRange: {
+ name: 'Ice And Fire 3',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#0198BD', '#FAFEB3', '#D50255'],
+ colorLegends: {'#0198BD': 'hwllo'}
+ },
+ loadedColorRange: {
+ name: 'Ice And Fire',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#0198BD', '#FAFEB3', '#D50255'],
+ colorLegends: {'#0198BD': 'hwllo'}
+ }
+ }
+ ];
+
+ const NEW_COLOR_RANGES = [
+ {
+ name: 'Uber Viz Diverging',
+ type: 'diverging',
+ category: 'Uber',
+ colors: ['#00939C', '#8BC6C9', '#EB9373', '#C22E00']
+ },
+ {
+ name: 'Okabe Ito',
+ type: 'qualitative',
+ category: 'ColorBlind',
+ colors: ['#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2'],
+ colorLegends: {}
+ },
+ {
+ name: 'PuBu',
+ type: 'sequential',
+ category: 'ColorBrewer',
+ colors: ['#FFF7FB', '#CED1E6', '#72A8CF', '#0D72AD', '#023858'],
+ colorLegends: {}
+ }
+ ];
+
+ // load old color range
+ [
+ ...OLD_COLOR_RANGES_CUSTOM,
+ ...OLD_COLOR_RANGES_COLORBREWER,
+ ...CUSTOM_COLOR_BREAK,
+ ...CUSTOM_COLOR_LEGENDS
+ ].forEach(tc => {
+ t.deepEqual(
+ colorRangeBackwardCompatibility(tc.savedColorRange),
+ tc.loadedColorRange,
+ `should rename and load ${tc.savedColorRange.name} type ${tc.savedColorRange.type} as ${tc.loadedColorRange.name}`
+ );
+ });
+
+ // load new color palettes
+ NEW_COLOR_RANGES.forEach(tc => {
+ t.deepEqual(
+ colorRangeBackwardCompatibility(tc),
+ tc,
+ `should keep load new color palette ${tc.name}`
+ );
+ });
+
+ t.end();
+});
diff --git a/yarn.lock b/yarn.lock
index c952389dd..efbc4211e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3320,8 +3320,10 @@ __metadata:
"@kepler.gl/types": "npm:3.1.0-alpha.1"
"@types/d3-scale": "npm:^3.2.2"
"@types/keymirror": "npm:^0.1.1"
+ chroma-js: "npm:2.1.2"
colorbrewer: "npm:^1.5.0"
d3-scale: "npm:^3.2.3"
+ d3-scale-chromatic: "npm:2.0.0"
global: "npm:^4.3.0"
keymirror: "npm:^0.1.1"
languageName: unknown
@@ -12688,6 +12690,15 @@ __metadata:
languageName: node
linkType: hard
+"chroma-js@npm:2.1.2":
+ version: 2.1.2
+ resolution: "chroma-js@npm:2.1.2"
+ dependencies:
+ cross-env: "npm:^6.0.3"
+ checksum: 10c0/f3760059b76240bab7387f335c798bbf55a4edf937534be7bc5c16ecad9b358dcfd891ca4fffa2c34742f45d5c3e96c8927c6a9906a13905da2bfa4c9ad30418
+ languageName: node
+ linkType: hard
+
"chrome-trace-event@npm:^1.0.2":
version: 1.0.4
resolution: "chrome-trace-event@npm:1.0.4"
@@ -13455,6 +13466,18 @@ __metadata:
languageName: node
linkType: hard
+"cross-env@npm:^6.0.3":
+ version: 6.0.3
+ resolution: "cross-env@npm:6.0.3"
+ dependencies:
+ cross-spawn: "npm:^7.0.0"
+ bin:
+ cross-env: src/bin/cross-env.js
+ cross-env-shell: src/bin/cross-env-shell.js
+ checksum: 10c0/0d176b91c730abb08589431970a59771148f8fbf338959f5e3aa71b866d38ba390fc67f5330306d0a37d7cb74675224d0f23086f291661b944abbf5a00bd7080
+ languageName: node
+ linkType: hard
+
"cross-spawn@npm:^6.0.0, cross-spawn@npm:^6.0.5":
version: 6.0.6
resolution: "cross-spawn@npm:6.0.6"
@@ -13870,6 +13893,16 @@ __metadata:
languageName: node
linkType: hard
+"d3-scale-chromatic@npm:2.0.0":
+ version: 2.0.0
+ resolution: "d3-scale-chromatic@npm:2.0.0"
+ dependencies:
+ d3-color: "npm:1 - 2"
+ d3-interpolate: "npm:1 - 2"
+ checksum: 10c0/93cafe497b00046b1d4e237a8bb8981fbb35ba03070f420bd913872f6e9d2c9628ed8bb8c84c6a6ffe16029359fa74b646c5c5129732ef4186ab059a77da3021
+ languageName: node
+ linkType: hard
+
"d3-scale@npm:^3.2.3":
version: 3.3.0
resolution: "d3-scale@npm:3.3.0"