diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6232e6ba685..8cc36f49b11 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690))
- Updated `EuiNavDrawer` to accept React fragments ([#2710](https://github.com/elastic/eui/pull/2710))
- Added `EuiFormFieldset` and `EuiFormLegend` components ([#2706](https://github.com/elastic/eui/pull/2706))
+- Adjusted colors of color blind viz palette ([#2686](https://github.com/elastic/eui/pull/2686))
**Bug fixes**
@@ -15,6 +16,12 @@
- Fixed bug in `EuiDataGrid` where resizing columns changed the active DOM element ([#2724](https://github.com/elastic/eui/pull/#2724))
- Fixed position of scrollbar in `EuiCodeBlock` ([#2727](https://github.com/elastic/eui/pull/#2727))
+**Breaking changes**
+
+- Changed accepted properties of the `color_palette` method to accept an array of colors ([#2686](https://github.com/elastic/eui/pull/#2686))
+- Removed the `palette` export to export each palette function directly ([#2686](https://github.com/elastic/eui/pull/#2686))
+- Changed the palette functions to be methods that accept a number of steps and removed `.colors` key ([#2686](https://github.com/elastic/eui/pull/#2686))
+
## [`17.3.1`](https://github.com/elastic/eui/tree/v17.3.1)
**Bug fixes**
diff --git a/package.json b/package.json
index 138dbe51cc8..777880cea3a 100644
--- a/package.json
+++ b/package.json
@@ -44,10 +44,12 @@
"test-staged"
],
"dependencies": {
+ "@types/chroma-js": "^1.4.3",
"@types/lodash": "^4.14.116",
"@types/numeral": "^0.0.25",
"@types/react-beautiful-dnd": "^10.1.0",
"classnames": "^2.2.5",
+ "chroma-js": "^2.0.4",
"highlight.js": "^9.12.0",
"html": "^1.0.0",
"keymirror": "^0.1.1",
@@ -106,7 +108,6 @@
"chai-webdriverio": "^0.4.3",
"chalk": "^2.4.1",
"chokidar": "^1.7.0",
- "chroma-js": "^2.0.4",
"chromedriver": "2.37.0",
"circular-dependency-plugin": "^5.0.2",
"core-js": "^2.5.1",
diff --git a/src-docs/src/components/guide_components.scss b/src-docs/src/components/guide_components.scss
index 3750c9f5944..a37483cf9bc 100644
--- a/src-docs/src/components/guide_components.scss
+++ b/src-docs/src/components/guide_components.scss
@@ -163,7 +163,7 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
.guideCharts__customLegend {
font-size: $euiFontSizeXS;
position: absolute;
- width: 123px;
+ width: 93px;
right: 0;
bottom: 0;
padding: $euiSizeXS;
@@ -229,23 +229,6 @@ $guideZLevelHighest: $euiZLevel9 + 1000;
margin-left: 0;
width: 100%;
}
-
- .euiFlexGroup--responsive > .euiFlexItem.guideColorPalette__swatch {
- margin-bottom: 0 !important;
-
- span {
- height: $euiSize;
- width: $euiSizeL;
- }
-
- &:first-child span {
- border-radius: $euiBorderRadius $euiBorderRadius 0 0;
- }
-
- &:last-child span {
- border-radius: 0 0 $euiBorderRadius $euiBorderRadius;
- }
- }
}
.euiDataGridRowCell--favoriteFranchise {
diff --git a/src-docs/src/views/color_palette/color_palette.js b/src-docs/src/views/color_palette/color_palette.js
index 34b67d010fc..f392b99f11f 100644
--- a/src-docs/src/views/color_palette/color_palette.js
+++ b/src-docs/src/views/color_palette/color_palette.js
@@ -7,34 +7,63 @@ import {
EuiSpacer,
} from '../../../../src/components';
-import { palettes } from '../../../../src/services';
+import { euiPaletteColorBlind } from '../../../../src/services';
+import { ColorPaletteFlexItem, ColorPaletteCopyCode } from './shared';
-const paletteData = palettes;
-const paletteNames = Object.keys(paletteData);
+const customPalettes = [
+ {
+ title: 'Max 10 colors',
+ palette: euiPaletteColorBlind(),
+ },
+ {
+ title: 'More than 10 colors are needed',
+ palette: euiPaletteColorBlind(2),
+ },
+ {
+ title:
+ 'Series have multiple metrics and so the colors must coordinate but be distinguishable',
+ palette: euiPaletteColorBlind(3, 'group'),
+ },
+];
export default () => (
- {paletteNames.map((paletteName, i) => (
-
-
- {paletteName}
+ {customPalettes.map((palette, i) => (
+
+
+ {palette.title}
-
- {paletteData[paletteName].colors.map((hexCode, j) => (
-
-
-
- ))}
+
+
+
+ {palette.palette.map(hexCode => (
+
+ ))}
+
+
+
+ 0 ? i + 1 : ''}${
+ i > 1 ? ", 'group'" : ''
+ })`}
+ code={`euiPaletteColorBlind(${i > 0 ? i + 1 : ''}${
+ i > 1 ? ", 'group'" : ''
+ })`}
+ />
+
-
-
+
+
))}
);
diff --git a/src-docs/src/views/color_palette/color_palette_custom.js b/src-docs/src/views/color_palette/color_palette_custom.js
index ef4682e1b61..88b5640f899 100644
--- a/src-docs/src/views/color_palette/color_palette_custom.js
+++ b/src-docs/src/views/color_palette/color_palette_custom.js
@@ -1,69 +1,68 @@
-import React, { Fragment } from 'react';
+import React, { Fragment, useState } from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
- EuiTitle,
+ EuiRange,
+ EuiFormRow,
EuiSpacer,
} from '../../../../src/components';
-import { colorPalette, palettes } from '../../../../src/services';
+import { euiPaletteColorBlind, colorPalette } from '../../../../src/services';
+import { ColorPaletteFlexItem, ColorPaletteCopyCode } from './shared';
-const euiColors = palettes.euiPaletteForLightBackground.colors;
+const customPalettes = [
+ [euiPaletteColorBlind()[3]],
+ [euiPaletteColorBlind()[3], euiPaletteColorBlind()[4]],
+ [euiPaletteColorBlind()[3], euiPaletteColorBlind()[4]],
+];
-export default () => (
-
-
- For mapping density, low to high
-
-
- {euiColors.map((color, j) => (
-
-
- {colorPalette('FFFFFF', color, 20).map((hexCode, k) => (
-
-
-
- ))}
+export default () => {
+ const [length, setLength] = useState(10);
+
+ const onLengthChange = e => {
+ setLength(e.currentTarget.value);
+ };
+
+ return (
+
+
+
+
+
+
+
+ {customPalettes.map((palette, i) => (
+
+
+
+ {colorPalette(palette, Number(length), i > 1).map(hexCode => (
+
+ ))}
+
+
+
+ 1 ? ', true' : ''
+ });`}
+ code={`colorPalette([${palette}], ${length}${
+ i > 1 ? ', true' : ''
+ });`}
+ />
+
-
-
- ))}
-
-
- For communicating state, trending negative
-
-
-
- {colorPalette('#FBEFD3', '#BD4C48').map((hexCode, l) => (
-
-
-
- ))}
-
-
-
- For communicating state, trending positive
-
-
-
- {colorPalette('#FFFFE0', '#017F75').map((hexCode, l) => (
-
-
-
))}
-
-
-);
+
+ );
+};
diff --git a/src-docs/src/views/color_palette/color_palette_example.js b/src-docs/src/views/color_palette/color_palette_example.js
index 6084e66f22f..3c424ebdfb4 100644
--- a/src-docs/src/views/color_palette/color_palette_example.js
+++ b/src-docs/src/views/color_palette/color_palette_example.js
@@ -1,21 +1,37 @@
import React from 'react';
+import { Link } from 'react-router';
import { renderToHtml } from '../../services';
import { GuideSectionTypes } from '../../components';
-import { EuiCode } from '../../../../src/components';
+import { EuiCode, EuiText, EuiSpacer } from '../../../../src/components';
import ColorPalette from './color_palette';
const colorPaletteSource = require('!!raw-loader!./color_palette');
const colorPaletteHtml = renderToHtml(ColorPalette);
+import ColorPaletteQuant from './color_palette_quantitative';
+const colorPaletteQuantSource = require('!!raw-loader!./color_palette_quantitative');
+const colorPaletteQuantHtml = renderToHtml(ColorPaletteQuant);
+
import ColorPaletteCustom from './color_palette_custom';
const colorPaletteCustomSource = require('!!raw-loader!./color_palette_custom');
const colorPaletteCustomHtml = renderToHtml(ColorPaletteCustom);
export const ColorPaletteExample = {
title: 'Color Palettes',
+ intro: (
+ <>
+
+
+ EUI provides a base set of color palettes that return an array of
+ hexadecimal color for use in other EUI components or charts.
+
+
+
+ >
+ ),
sections: [
{
title: 'Preset qualitative palettes',
@@ -32,22 +48,52 @@ export const ColorPaletteExample = {
text: (
- The eui_palettes.js file provides a base set of
- color palettes in an array format. The hexadecimal color codes in
- these sets consist of both color safe and EUI themed colors. Import
- the file, then use JavaScript to read and apply the color array
- values to other EUI components, such as charts.
+ Qualitative palettes are best suited for communicating and comparing
+ discrete data series. EUI recommends using the{' '}
+ euiPaletteColorBlind() for qualitative and
+ categorical data.
- Quantitative palettes are best suited for communicating and
- comparing discrete data series.
+ This palette is restricted to only 10 colors. However, you can add
+ more groups of 10 which are alternates of the original. This is
+ better than allowing the initial set to loop.
),
demo: ,
+ snippet: ['euiPaletteColorBlind()', "euiPaletteColorBlind(3, 'group')"],
},
{
title: 'Recommended quantitative palettes',
+ source: [
+ {
+ type: GuideSectionTypes.JS,
+ code: colorPaletteQuantSource,
+ },
+ {
+ type: GuideSectionTypes.HTML,
+ code: colorPaletteQuantHtml,
+ },
+ ],
+ text: (
+
+
+ Quantitative palettes are best suited for displaying data on a
+ continuum, as in the case of health statuses and large geographic or
+ demographic-based data sets.
+
+
+ EUI provides the following common palettes for quantitative data and{' '}
+ charts. Just pass
+ in the number of steps needed and the function will interpolate
+ between the colors.
+
+
+ ),
+ demo: ,
+ },
+ {
+ title: 'Custom palettes',
source: [
{
type: GuideSectionTypes.JS,
@@ -62,22 +108,19 @@ export const ColorPaletteExample = {
Use the colorPalette service to generate a
- custom, gradiated palette array of any length from two hexadecimal
- color codes. For example, obtain an array of yellow-to-green health
- status colors using
-
- colorPalette('#FFFF6D', '#1EA593', 20)
-
- .
-
-
- Custom palettes are best suited for displaying data on a continuum,
- as in the case of health statuses and large geographic or
- demographic-based data sets.
+ custom, gradiated palette array of any length from one or more
+ hexadecimal color codes. The third parameter{' '}
+ divergent , will interpolate between the two
+ halves of the spectrums separately. If a middle point is not
+ provided, it will graduate to light gray.
),
demo: ,
+ snippet: [
+ "colorPalette(['#fff'. '#000'], 11);",
+ "colorPalette(['#fff'. '#000'], 11, divergent = true);",
+ ],
},
],
};
diff --git a/src-docs/src/views/color_palette/color_palette_quantitative.js b/src-docs/src/views/color_palette/color_palette_quantitative.js
new file mode 100644
index 00000000000..c7fb55d0c8e
--- /dev/null
+++ b/src-docs/src/views/color_palette/color_palette_quantitative.js
@@ -0,0 +1,79 @@
+import React, { Fragment, useState } from 'react';
+
+import {
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiRange,
+ EuiFormRow,
+ EuiSpacer,
+} from '../../../../src/components';
+
+import { ColorPaletteFlexItem, ColorPaletteCopyCode } from './shared';
+
+import {
+ euiPaletteComplimentary,
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteGray,
+} from '../../../../src/services';
+const paletteData = {
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteComplimentary,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteGray,
+};
+const paletteNames = Object.keys(paletteData);
+
+export default () => {
+ const [length, setLength] = useState(5);
+
+ const onLengthChange = e => {
+ setLength(e.currentTarget.value);
+ };
+
+ return (
+
+
+
+
+
+
+
+ {paletteNames.map(paletteName => (
+
+
+
+ {paletteData[paletteName](Number(length)).map(hexCode => (
+
+ ))}
+
+
+
+
+
+
+ ))}
+
+ );
+};
diff --git a/src-docs/src/views/color_palette/shared.js b/src-docs/src/views/color_palette/shared.js
new file mode 100644
index 00000000000..705753ddbe8
--- /dev/null
+++ b/src-docs/src/views/color_palette/shared.js
@@ -0,0 +1,37 @@
+import React from 'react';
+import classNames from 'classnames';
+
+import {
+ EuiFlexItem,
+ EuiCopy,
+ EuiCode,
+ EuiLink,
+} from '../../../../src/components';
+
+export const ColorPaletteFlexItem = ({ hexCode, className, ...rest }) => {
+ return (
+
+
+
+ );
+};
+
+export const ColorPaletteCopyCode = ({ textToCopy, code }) => {
+ return (
+
+
+ {copy => (
+
+ {code}
+
+ )}
+
+
+ );
+};
diff --git a/src-docs/src/views/color_picker/color_picker.js b/src-docs/src/views/color_picker/color_picker.js
index 20f83723721..5fc8b2f548a 100644
--- a/src-docs/src/views/color_picker/color_picker.js
+++ b/src-docs/src/views/color_picker/color_picker.js
@@ -7,7 +7,7 @@ export class ColorPicker extends Component {
constructor(props) {
super(props);
this.state = {
- color: '#DB1374',
+ color: '#D36086',
};
}
diff --git a/src-docs/src/views/color_picker/color_stops.js b/src-docs/src/views/color_picker/color_stops.js
index e92f36a631f..b625c54aeb1 100644
--- a/src-docs/src/views/color_picker/color_stops.js
+++ b/src-docs/src/views/color_picker/color_stops.js
@@ -10,15 +10,15 @@ export const ColorStops = () => {
const [extendedColorStops, setExtendedColorStops] = useState([
{
stop: 100,
- color: '#00B3A4',
+ color: '#5BBAA0',
},
{
stop: 250,
- color: '#DB1374',
+ color: '#D36086',
},
{
stop: 350,
- color: '#490092',
+ color: '#9170B8',
},
]);
diff --git a/src-docs/src/views/color_picker/color_stops_range.js b/src-docs/src/views/color_picker/color_stops_range.js
index 2a3aa879c99..10c18c6f35c 100644
--- a/src-docs/src/views/color_picker/color_stops_range.js
+++ b/src-docs/src/views/color_picker/color_stops_range.js
@@ -22,7 +22,7 @@ export const ColorStopsRange = () => {
};
const [singleColorStops, setSingleColorStops] = useState([
- { stop: 10, color: '#DB1374' },
+ { stop: 10, color: '#D36086' },
]);
const handleSingleChange = colorStops => {
@@ -30,7 +30,7 @@ export const ColorStopsRange = () => {
};
const [singleColorStops2, setSingleColorStops2] = useState([
- { stop: 10, color: '#DB1374' },
+ { stop: 10, color: '#D36086' },
]);
const handleSingleChange2 = colorStops => {
@@ -38,7 +38,7 @@ export const ColorStopsRange = () => {
};
const [singleColorStops3, setSingleColorStops3] = useState([
- { stop: 10, color: '#DB1374' },
+ { stop: 10, color: '#D36086' },
]);
const handleSingleChange3 = colorStops => {
diff --git a/src-docs/src/views/color_picker/kitchen_sink.js b/src-docs/src/views/color_picker/kitchen_sink.js
index 258af45a6c7..7d5d1cec3d5 100644
--- a/src-docs/src/views/color_picker/kitchen_sink.js
+++ b/src-docs/src/views/color_picker/kitchen_sink.js
@@ -10,7 +10,7 @@ import { DisplayToggles } from '../form_controls/display_toggles';
import { useColorPicker, useColorStop } from './utils';
export const KitchenSink = () => {
- const [color, setColor] = useColorPicker('#DB1374');
+ const [color, setColor] = useColorPicker('#D36086');
const [colorStops, setColorStops, addStop] = useColorStop(true);
return (
diff --git a/src-docs/src/views/color_picker/modes.js b/src-docs/src/views/color_picker/modes.js
index 762950fb9a1..f264d20ae53 100644
--- a/src-docs/src/views/color_picker/modes.js
+++ b/src-docs/src/views/color_picker/modes.js
@@ -10,7 +10,7 @@ import {
import { useColorPicker, useColorStop } from './utils';
export const Modes = () => {
- const [color, setColor, errors] = useColorPicker('#DB1374');
+ const [color, setColor, errors] = useColorPicker('#D36086');
const [colorStops, setColorStops] = useColorStop();
return (
diff --git a/src-docs/src/views/color_picker/utils.js b/src-docs/src/views/color_picker/utils.js
index d375427c3d9..1a385e08eeb 100644
--- a/src-docs/src/views/color_picker/utils.js
+++ b/src-docs/src/views/color_picker/utils.js
@@ -10,15 +10,15 @@ export const useColorStop = (useRandomColor = false) => {
const [colorStops, setColorStops] = useState([
{
stop: 20,
- color: '#00B3A4',
+ color: '#5BBAA0',
},
{
stop: 50,
- color: '#DB1374',
+ color: '#D36086',
},
{
stop: 65,
- color: '#490092',
+ color: '#9170B8',
},
]);
diff --git a/src-docs/src/views/combo_box/colors.js b/src-docs/src/views/combo_box/colors.js
index bbed1d8f9a1..ea806efbc2b 100644
--- a/src-docs/src/views/combo_box/colors.js
+++ b/src-docs/src/views/combo_box/colors.js
@@ -18,7 +18,7 @@ export default class extends Component {
},
{
label: 'Mimas',
- color: '#DB1374',
+ color: '#D36086',
},
{
label: 'Dione',
@@ -39,15 +39,15 @@ export default class extends Component {
{
label:
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology",
- color: '#F98510',
+ color: '#F19F58',
},
{
label: 'Tethys',
- color: '#FEB6DB',
+ color: '#EEAFCF',
},
{
label: 'Hyperion',
- color: '#BFA180',
+ color: '#CDBD9D',
},
];
diff --git a/src-docs/src/views/combo_box/render_option.js b/src-docs/src/views/combo_box/render_option.js
index 23be0a45f1c..9472ed6e8a4 100644
--- a/src-docs/src/views/combo_box/render_option.js
+++ b/src-docs/src/views/combo_box/render_option.js
@@ -31,7 +31,7 @@ export default class extends Component {
size: 15,
},
label: 'Mimas',
- color: '#DB1374',
+ color: '#D36086',
},
{
value: {
@@ -67,21 +67,21 @@ export default class extends Component {
},
label:
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology",
- color: '#F98510',
+ color: '#F19F58',
},
{
value: {
size: 9,
},
label: 'Tethys',
- color: '#FEB6DB',
+ color: '#EEAFCF',
},
{
value: {
size: 4,
},
label: 'Hyperion',
- color: '#BFA180',
+ color: '#CDBD9D',
},
];
diff --git a/src-docs/src/views/elastic_charts/shared.js b/src-docs/src/views/elastic_charts/shared.js
index 9c00575c801..111810e15fc 100644
--- a/src-docs/src/views/elastic_charts/shared.js
+++ b/src-docs/src/views/elastic_charts/shared.js
@@ -179,68 +179,3 @@ export class MultiChartCard extends Component {
);
}
}
-
-/**
- * The following function is very messy and hopefully will be replaced by something provided by elastic-charts
- */
-import chroma from 'chroma-js';
-export function createSpectrum(
- colors,
- steps = 5,
- diverging = false,
- correctLightness = true,
- bezier = true
-) {
- if (colors.length < 2) {
- console.warn(
- 'createSpectrum expects the colors array to have at least 2 colors'
- );
- return;
- }
-
- diverging = diverging || colors.length > 2;
-
- const even = steps % 2 === 0;
- const numStepsLeft = diverging
- ? Math.ceil(steps / 2) + (even ? 1 : 0)
- : steps;
- const numStepsRight = diverging ? Math.ceil(steps / 2) + (even ? 1 : 0) : 0;
-
- const numColorsHalf =
- Math.ceil(colors.length / 2) + (colors.length % 2 === 0 ? 1 : 0);
-
- const colorsLeft = colors.filter(function(item, index) {
- if (index < numColorsHalf) {
- return true; // keep it
- }
- });
- const colorsRight =
- diverging &&
- colors
- .reverse()
- .filter(function(item, index) {
- if (index < numColorsHalf) {
- return true; // keep it
- }
- })
- .reverse();
-
- function createSteps(colors, steps) {
- return colors.length
- ? chroma
- .scale(bezier && colors.length > 1 ? chroma.bezier(colors) : colors)
- .correctLightness(correctLightness)
- .colors(steps)
- : [];
- }
-
- const stepsLeft = createSteps(colorsLeft, numStepsLeft);
- const stepsRight = createSteps(colorsRight, numStepsRight);
-
- const spectrum = (even && diverging
- ? stepsLeft.slice(0, stepsLeft.length - 1)
- : stepsLeft
- ).concat(stepsRight.slice(1));
-
- return spectrum;
-}
diff --git a/src-docs/src/views/elastic_charts/sparklines.js b/src-docs/src/views/elastic_charts/sparklines.js
index 070c11aa2af..fd5c919f12b 100644
--- a/src-docs/src/views/elastic_charts/sparklines.js
+++ b/src-docs/src/views/elastic_charts/sparklines.js
@@ -26,7 +26,10 @@ import {
} from '../../../../src/components';
import { TIME_DATA_SMALL } from './data';
-import { palettes } from '../../../../src/services';
+import {
+ euiPaletteForDarkBackground,
+ euiPaletteForLightBackground,
+} from '../../../../src/services';
const getColorsMap = (color, specId) => {
const map = new Map();
@@ -71,6 +74,12 @@ class _Sparklines extends Component {
data={TIME_DATA_SMALL}
xAccessor={0}
yAccessors={[1]}
+ customSeriesColors={getColorsMap(
+ isDarkTheme
+ ? euiPaletteForDarkBackground()[1]
+ : euiPaletteForLightBackground()[1],
+ 'numbers'
+ )}
/>
@@ -93,8 +102,8 @@ class _Sparklines extends Component {
yAccessors={[1]}
customSeriesColors={getColorsMap(
isDarkTheme
- ? palettes.euiPaletteForDarkBackground.colors[1]
- : palettes.euiPaletteForLightBackground.colors[1],
+ ? euiPaletteForDarkBackground()[1]
+ : euiPaletteForLightBackground()[1],
'increase'
)}
/>
@@ -127,8 +136,8 @@ class _Sparklines extends Component {
yAccessors={[1]}
customSeriesColors={getColorsMap(
isDarkTheme
- ? palettes.euiPaletteForDarkBackground.colors[3]
- : palettes.euiPaletteForLightBackground.colors[3],
+ ? euiPaletteForDarkBackground()[3]
+ : euiPaletteForLightBackground()[3],
'major'
)}
/>
@@ -153,8 +162,8 @@ class _Sparklines extends Component {
yAccessors={[1]}
customSeriesColors={getColorsMap(
isDarkTheme
- ? palettes.euiPaletteForDarkBackground.colors[3]
- : palettes.euiPaletteForLightBackground.colors[3],
+ ? euiPaletteForDarkBackground()[3]
+ : euiPaletteForLightBackground()[3],
'subtle'
)}
/>
diff --git a/src-docs/src/views/elastic_charts/theming.js b/src-docs/src/views/elastic_charts/theming.js
index e444ca8889a..8d5be26f78f 100644
--- a/src-docs/src/views/elastic_charts/theming.js
+++ b/src-docs/src/views/elastic_charts/theming.js
@@ -1,4 +1,4 @@
-import React, { Component, Fragment } from 'react';
+import React, { useState, Fragment } from 'react';
import { withTheme } from '../../components';
import {
Chart,
@@ -9,88 +9,159 @@ import {
DataGenerator,
} from '@elastic/charts';
+import {
+ EuiSpacer,
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiSuperSelect,
+} from '../../../../src/components';
+
import {
EUI_CHARTS_THEME_DARK,
EUI_CHARTS_THEME_LIGHT,
} from '../../../../src/themes/charts/themes';
-import { colorPalette } from '../../../../src/services';
-
-class _Theming extends Component {
- constructor(props) {
- super(props);
+import {
+ euiPaletteColorBlind,
+ euiPaletteComplimentary,
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteGray,
+} from '../../../../src/services';
+const paletteData = {
+ euiPaletteColorBlind,
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteComplimentary,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteGray,
+};
+const paletteNames = Object.keys(paletteData);
- this.state = {
- chartType: 'LineSeries',
- };
- }
+const _Theming = props => {
+ /**
+ * Create palette select
+ */
+ const paletteOptions = paletteNames.map((paletteName, index) =>
+ createPaletteOption(paletteName, index)
+ );
- onMultiChange = multiObject => {
- this.setState({
- ...multiObject,
- });
+ const [barPalette, setBarPalette] = useState('5');
+ const onBarPaletteChange = value => {
+ setBarPalette(value);
};
- onChartTypeChange = chartType => {
- this.setState({
- chartType: chartType,
- });
- };
+ /**
+ * Create data
+ */
+ const dg = new DataGenerator();
+ const data1 = dg.generateGroupedSeries(20, 1);
+ const data2 = dg.generateGroupedSeries(20, 5);
- render() {
- const dg = new DataGenerator();
- const data1 = dg.generateGroupedSeries(20, 1);
- const data2 = dg.generateGroupedSeries(20, 5);
+ /**
+ * Setup theme based on current light/dark theme
+ */
+ const isDarkTheme = props.theme.includes('dark');
+ const theme = isDarkTheme
+ ? EUI_CHARTS_THEME_DARK.theme
+ : EUI_CHARTS_THEME_LIGHT.theme;
- const isDarkTheme = this.props.theme.includes('dark');
- const theme = isDarkTheme
- ? EUI_CHARTS_THEME_DARK.theme
- : EUI_CHARTS_THEME_LIGHT.theme;
+ const customColors = {
+ colors: {
+ vizColors: paletteData[paletteNames[Number(barPalette)]](5),
+ },
+ };
- const customColors = {
- colors: {
- vizColors: colorPalette('#FFFFE0', '#017F75', 5),
- },
- };
+ const data1CustomSeriesColors = new Map();
+ const data1DataSeriesColorValues = {
+ colorValues: [],
+ specId: 'control',
+ };
+ data1CustomSeriesColors.set(data1DataSeriesColorValues, 'black');
- const data1CustomSeriesColors = new Map();
- const data1DataSeriesColorValues = {
- colorValues: [],
- specId: 'control',
- };
- data1CustomSeriesColors.set(data1DataSeriesColorValues, 'black');
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
- return (
+const createPaletteOption = function(paletteName, index) {
+ return {
+ value: String(index),
+ inputDisplay: createPalette(
+ paletteData[paletteNames[index]](index > 0 ? 10 : 1)
+ ),
+ dropdownDisplay: (
-
-
-
-
-
-
-
+ {paletteName}
+
+ {createPalette(paletteData[paletteNames[index]](index > 0 ? 10 : 1))}
- );
- }
-}
+ ),
+ };
+};
+
+const createPalette = function(palette) {
+ return (
+
+ {palette.map(hexCode => (
+
+
+
+ ))}
+
+ );
+};
export const Theming = withTheme(_Theming);
diff --git a/src-docs/src/views/elastic_charts/theming_categorical.js b/src-docs/src/views/elastic_charts/theming_categorical.js
index bd5baad5d14..d13e8503914 100644
--- a/src-docs/src/views/elastic_charts/theming_categorical.js
+++ b/src-docs/src/views/elastic_charts/theming_categorical.js
@@ -23,8 +23,13 @@ import {
EuiTitle,
} from '../../../../src/components';
-import { CHART_COMPONENTS, createSpectrum, ChartCard } from './shared';
-import { palettes } from '../../../../src/services';
+import { CHART_COMPONENTS, ChartCard } from './shared';
+import {
+ euiPaletteColorBlind,
+ euiPalettePositive,
+ euiPaletteForStatus,
+ euiPaletteGray,
+} from '../../../../src/services';
const getColorsMap = (color, specId) => {
const map = new Map();
@@ -36,20 +41,20 @@ class _Categorical extends Component {
constructor(props) {
super(props);
- this.highlightColor = palettes.euiPaletteColorBlind.colors[2];
+ this.highlightColor = euiPaletteColorBlind()[2];
this.colorTypeRadios = [
{
id: `${this.idPrefix}3`,
- label: 'Category',
+ label: 'Categorical',
},
{
id: `${this.idPrefix}0`,
- label: 'Quantity',
+ label: 'Sequential',
},
{
id: `${this.idPrefix}1`,
- label: 'Trend',
+ label: 'Diverging',
},
{
id: `${this.idPrefix}2`,
@@ -64,7 +69,8 @@ class _Categorical extends Component {
numCharts: '3',
data: null,
dataString: '[{x: 1, y: 5.5, g: 0}]',
- vizColors: palettes.euiPaletteColorBlind.colors,
+ vizColors: euiPaletteColorBlind(),
+ vizColorsString: 'euiPaletteColorBlind()',
chartType: 'LineSeries',
};
}
@@ -103,13 +109,13 @@ class _Categorical extends Component {
updateCorrectChart = (numCharts, chartType) => {
switch (chartType) {
- case 'Category':
+ case 'Categorical':
this.createCategoryChart(numCharts);
break;
- case 'Quantity':
+ case 'Sequential':
this.createQuantityChart(numCharts);
break;
- case 'Trend':
+ case 'Diverging':
this.createTrendChart(numCharts);
break;
case 'Highlight':
@@ -131,24 +137,21 @@ class _Categorical extends Component {
const dg = new DataGenerator();
const data = dg.generateGroupedSeries(20, numCharts).map(item => {
const index = Number(item.g);
- item.g = `Category ${index + 1}`;
+ item.g = `Categorical ${index + 1}`;
return item;
});
this.setState({
data,
- dataString: "[{x: 1, y: 5.5, g: 'Category 1'}]",
- vizColors: palettes.euiPaletteColorBlind.colors,
+ dataString: "[{x: 1, y: 5.5, g: 'Categorical 1'}]",
+ vizColors: euiPaletteColorBlind(),
+ vizColorsString: 'euiPaletteColorBlind()',
chartType: 'LineSeries',
});
};
createQuantityChart = numCharts => {
- const vizColors = createSpectrum(
- ['#FFFFFF', palettes.euiPaletteColorBlind.colors[0]],
- numCharts + 1
- );
- vizColors.shift();
+ const vizColors = euiPalettePositive(numCharts);
// convert series labels to percentages
const dg = new DataGenerator();
@@ -168,15 +171,13 @@ class _Categorical extends Component {
data,
dataString: "[{x: 1, y: 5.5, g: '0 - 100%'}]",
vizColors,
+ vizColorsString: `euiPaletteCool(${numCharts})`,
chartType: 'BarSeries',
});
};
createTrendChart = numCharts => {
- const vizColors = createSpectrum(
- ['#58ba6d', '#ebdf62', '#d75949'],
- numCharts
- );
+ const vizColors = euiPaletteForStatus(numCharts);
// convert series labels to better/worse
const oddSeries = numCharts % 2;
@@ -207,15 +208,13 @@ class _Categorical extends Component {
data,
dataString: "[{x: 1, y: 5.5, g: 'Better'}]",
vizColors,
+ vizColorsString: `euiPaletteForStatus(${numCharts})`,
chartType: 'BarSeries',
});
};
createHighlightChart = numCharts => {
- const isDarkTheme = this.props.theme.includes('dark');
- const vizColors = isDarkTheme
- ? createSpectrum(['#343741', '#535966'], numCharts)
- : createSpectrum(['#D3DAE6', '#98A2B3'], numCharts);
+ const vizColors = euiPaletteGray(numCharts);
vizColors[vizColors.length - 1] = this.highlightColor;
const dg = new DataGenerator();
@@ -225,6 +224,7 @@ class _Categorical extends Component {
data,
dataString: "[{x: 1, y: 5.5, g: '0'}]",
vizColors: numCharts < 2 ? [this.highlightColor] : vizColors,
+ vizColorsString: `euiPaletteGray(${numCharts})[length - 1] = this.highlightColor`,
chartType: 'LineSeries',
});
};
@@ -234,6 +234,7 @@ class _Categorical extends Component {
data,
dataString,
vizColors,
+ vizColorsString,
chartType,
numCharts,
colorType,
@@ -266,13 +267,10 @@ class _Categorical extends Component {
const customColors = {
colors: { vizColors },
};
- const customColorsString =
- vizColors !== palettes.euiPaletteColorBlind.colors
- ? `[
- { colors: { vizColors: [${JSON.stringify(vizColors)}] }},
+ const customColorsString = `[
+ { colors: { vizColors: ${vizColorsString} }},
isDarkTheme ? EUI_CHARTS_THEME_DARK.theme : EUI_CHARTS_THEME_LIGHT.theme
-]`
- : null;
+]`;
const charts = [];
let customLegend;
@@ -310,7 +308,7 @@ class _Categorical extends Component {
xAccessor={'x'}
yAccessors={['y']}
customSeriesColors={getColorsMap(
- palettes.euiPaletteColorBlind.colors[index < 2 ? 0 : 1],
+ euiPaletteColorBlind()[index < 2 ? 0 : 1],
`data${index}`
)}
lineSeriesStyle={{
@@ -442,11 +440,7 @@ class _Categorical extends Component {
}
- {`import { colorPalette } from '../../../../src/services';
+ {`import { euiPalettePositive } from '../../../../src/services';
const customColors = {
colors: {
- vizColors: colorPalette('#FFFFE0', '#017F75', 5),
+ vizColors: euiPalettePositive(5),
},
};
diff --git a/src-docs/src/views/form_compressed/complex_example.js b/src-docs/src/views/form_compressed/complex_example.js
index 59814393281..7bac014313f 100644
--- a/src-docs/src/views/form_compressed/complex_example.js
+++ b/src-docs/src/views/form_compressed/complex_example.js
@@ -92,7 +92,7 @@ export default class extends Component {
isSwitchChecked: false,
opacityValue: '20',
buttonGroupIdSelected: `${idPrefix}1`,
- color: '#DB1374',
+ color: '#D36086',
borderValue: 3,
popoverSliderValues: 16,
dualValue: [5, 10],
diff --git a/src-docs/src/views/guidelines/colors.js b/src-docs/src/views/guidelines/colors.js
index 090d47c65d6..336cf15a33f 100644
--- a/src-docs/src/views/guidelines/colors.js
+++ b/src-docs/src/views/guidelines/colors.js
@@ -321,10 +321,10 @@ color: $${color2};`;
- Qualitative visualization palette
+ Categorical visualization palette
The following colors are color-blind safe and should be used in
- qualitative visualizations.
+ categorically seried visualizations.
For more visualization palettes and rendering services, go to the{' '}
diff --git a/src-docs/src/views/guidelines/index.scss b/src-docs/src/views/guidelines/index.scss
index 86e8c708f55..97132d18488 100644
--- a/src-docs/src/views/guidelines/index.scss
+++ b/src-docs/src/views/guidelines/index.scss
@@ -28,19 +28,20 @@
}
.guideColorPalette__swatch {
-
span {
height: $euiSize;
width: $euiSizeL;
}
- &:first-child span {
- border-radius: $euiBorderRadius 0 0 $euiBorderRadius;
+ &--small span {
+ width: auto;
+ height: $euiSizeS;
}
+}
- &:last-child span {
- border-radius: 0 $euiBorderRadius $euiBorderRadius 0;
- }
+.guideColorPalette__swatchHolder {
+ border-radius: $euiBorderRadius;
+ overflow: hidden;
}
// -------------------------------------
diff --git a/src-docs/src/views/icon/icon_colors.js b/src-docs/src/views/icon/icon_colors.js
index c5c25a5ec1e..49bd1108b2e 100644
--- a/src-docs/src/views/icon/icon_colors.js
+++ b/src-docs/src/views/icon/icon_colors.js
@@ -32,7 +32,7 @@ const iconColors = [
'subdued',
'ghost',
'#490',
- '#F98510',
+ '#F19F58',
'#DDDDDD',
];
diff --git a/src-docs/src/views/icon/icon_example.js b/src-docs/src/views/icon/icon_example.js
index 8d1aee965ce..214862b8a35 100644
--- a/src-docs/src/views/icon/icon_example.js
+++ b/src-docs/src/views/icon/icon_example.js
@@ -16,8 +16,8 @@ import {
const iconHtmlWarning = () => (
- HTML preview disabled. Icons use SVG and are not usable without React
- unless you load the icons manually through a separate asset loader.
+ HTML preview disabled. Icons use SVG and are not usable without React unless
+ you load the icons manually through a separate asset loader.
);
@@ -77,7 +77,7 @@ import IconColors from './icon_colors';
const iconColorsSource = require('!!raw-loader!./icon_colors');
const iconColorsSnippet = [
' ',
- ' ',
+ ' ',
];
import Accessibility from './accessibility';
diff --git a/src-docs/src/views/suggest/_global_filter_item.scss b/src-docs/src/views/suggest/_global_filter_item.scss
index f726abf8181..bfda7254583 100644
--- a/src-docs/src/views/suggest/_global_filter_item.scss
+++ b/src-docs/src/views/suggest/_global_filter_item.scss
@@ -25,7 +25,7 @@
bottom: 0;
left: 0;
width: $euiSizeXS;
- background-color: $euiColorVis0;
+ background-color: $euiColorSuccess;
border-top-left-radius: $euiBorderRadius / 2;
border-bottom-left-radius: $euiBorderRadius / 2;
}
diff --git a/src-docs/src/views/suggest/suggest_item.js b/src-docs/src/views/suggest/suggest_item.js
index b3c90b18753..981fc66c0f5 100644
--- a/src-docs/src/views/suggest/suggest_item.js
+++ b/src-docs/src/views/suggest/suggest_item.js
@@ -6,7 +6,7 @@ const shortDescription = 'This is the description';
const sampleItems = [
{
- type: { iconType: 'kqlField', color: 'tint4' },
+ type: { iconType: 'kqlField', color: 'tint5' },
label: 'Field sample',
description: shortDescription,
},
@@ -26,11 +26,11 @@ const sampleItems = [
description: shortDescription,
},
{
- type: { iconType: 'search', color: 'tint8' },
+ type: { iconType: 'search', color: 'tint10' },
label: 'Recent search',
},
{
- type: { iconType: 'save', color: 'tint5' },
+ type: { iconType: 'save', color: 'tint7' },
label: 'Saved query',
},
];
@@ -64,7 +64,7 @@ export default () => (
/>
diff --git a/src/components/avatar/__snapshots__/avatar.test.tsx.snap b/src/components/avatar/__snapshots__/avatar.test.tsx.snap
index 0776c9d38a5..57b4f1fe9d5 100644
--- a/src/components/avatar/__snapshots__/avatar.test.tsx.snap
+++ b/src/components/avatar/__snapshots__/avatar.test.tsx.snap
@@ -5,7 +5,7 @@ exports[`EuiAvatar allows a name composed entirely of whitespace 1`] = `
aria-label="aria-label"
class="euiAvatar euiAvatar--m euiAvatar--user testClass1 testClass2"
data-test-subj="test subject string"
- style="background-image:none;background-color:#DB1374;color:#FFFFFF"
+ style="background-image:none;background-color:#D36086;color:#000000"
title=" "
>
`;
@@ -60,7 +60,7 @@ exports[`EuiAvatar props initials is rendered 1`] = `
@@ -615,10 +615,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -626,10 +626,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -637,10 +637,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -648,10 +648,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -659,10 +659,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -670,10 +670,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -681,10 +681,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -692,10 +692,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
@@ -703,10 +703,10 @@ exports[`renders inline EuiColorPicker 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
diff --git a/src/components/color_picker/color_stops/utils.test.ts b/src/components/color_picker/color_stops/utils.test.ts
index 1b59f2953d1..537ce0035c7 100644
--- a/src/components/color_picker/color_stops/utils.test.ts
+++ b/src/components/color_picker/color_stops/utils.test.ts
@@ -74,7 +74,7 @@ describe('addDefinedStop', () => {
test('Should add stop', () => {
expect(addDefinedStop(colorStops, 1)).toEqual([
{ stop: 0, color: '#FF0000' },
- { stop: 1, color: '#3185FC' },
+ { stop: 1, color: '#6092C0' },
]);
});
diff --git a/src/components/datagrid/column_sorting.tsx b/src/components/datagrid/column_sorting.tsx
index f08614f2e18..02cd4210694 100644
--- a/src/components/datagrid/column_sorting.tsx
+++ b/src/components/datagrid/column_sorting.tsx
@@ -25,7 +25,7 @@ import {
EuiDataGridSchemaDetector,
getDetailsForSchema,
} from './data_grid_schema';
-import { palettes } from '../../services/color/eui_palettes';
+import { euiPaletteColorBlind } from '../../services/color/eui_palettes';
export const useColumnSorting = (
columns: EuiDataGridColumn[],
@@ -35,7 +35,7 @@ export const useColumnSorting = (
): ReactNode => {
const [isOpen, setIsOpen] = useState(false);
const [avilableColumnsisOpen, setAvailableColumnsIsOpen] = useState(false);
- const defaultSchemaColor: string = palettes.euiPaletteColorBlind.colors[4];
+ const defaultSchemaColor: string = euiPaletteColorBlind()[4];
// prune any non-existant/hidden columns from sorting
useEffect(() => {
diff --git a/src/components/datagrid/data_grid_schema.tsx b/src/components/datagrid/data_grid_schema.tsx
index 6976074d215..fd76e35eaed 100644
--- a/src/components/datagrid/data_grid_schema.tsx
+++ b/src/components/datagrid/data_grid_schema.tsx
@@ -7,7 +7,7 @@ import {
import { EuiI18n } from '../i18n';
-import { palettes } from '../../services/color/eui_palettes';
+import { euiPaletteColorBlind } from '../../services/color/eui_palettes';
import { IconType } from '../icon';
export interface EuiDataGridSchemaDetector {
@@ -71,7 +71,7 @@ export const schemaDetectors: EuiDataGridSchemaDetector[] = [
return 0;
},
icon: 'invert',
- color: palettes.euiPaletteColorBlind.colors[5],
+ color: euiPaletteColorBlind()[5],
sortTextAsc: (
),
@@ -189,7 +189,7 @@ export const schemaDetectors: EuiDataGridSchemaDetector[] = [
return 0;
},
icon: 'number',
- color: palettes.euiPaletteColorBlind.colors[0],
+ color: euiPaletteColorBlind()[0],
sortTextAsc: (
),
@@ -221,7 +221,7 @@ export const schemaDetectors: EuiDataGridSchemaDetector[] = [
return 0;
},
icon: 'visVega',
- color: palettes.euiPaletteColorBlind.colors[3],
+ color: euiPaletteColorBlind()[3],
sortTextAsc: (
{
it('should generate the expected palette', () => {
- const actualPalette = colorPalette('#FFFF6D', '#1EA593');
+ const actualPalette = colorPalette(['#FFFF6D', '#1EA593']);
expect(actualPalette).toEqual([
- '#FFFF6D',
- '#E6F571',
- '#CDEB75',
- '#B4E17A',
- '#9BD77E',
- '#82CD82',
- '#69C386',
- '#50B98B',
- '#37AF8F',
- '#1EA593',
+ '#ffff6d',
+ '#ecf573',
+ '#d8eb79',
+ '#c4e07d',
+ '#b0d682',
+ '#9acc86',
+ '#84c28a',
+ '#6bb98d',
+ '#4daf90',
+ '#1ea593',
]);
});
it('should generate a palette with the specified spread', () => {
- const actualPalette = colorPalette('#FFFF6D', '#1EA593', 6);
+ const actualPalette = colorPalette(['#FFFF6D', '#1EA593'], 6);
expect(actualPalette).toEqual([
- '#FFFF6D',
- '#D2ED75',
- '#A5DB7C',
- '#78C984',
- '#4BB78B',
- '#1EA593',
+ '#ffff6d',
+ '#dced77',
+ '#b8da80',
+ '#92c887',
+ '#66b78e',
+ '#1ea593',
]);
});
});
diff --git a/src/services/color/color_palette.ts b/src/services/color/color_palette.ts
index 3d140d297a7..30d32c16651 100644
--- a/src/services/color/color_palette.ts
+++ b/src/services/color/color_palette.ts
@@ -1,98 +1,92 @@
-import { rgbDef } from './color_types';
-import { hexToRgb } from './hex_to_rgb';
+import chroma from 'chroma-js';
-/**
- * Create the color object for manipulation by other functions
- */
-class Color {
- collection: rgbDef;
- text: string;
-
- constructor(public r: number, public g: number, public b: number) {
- this.collection = [r, g, b];
- this.text = createHex(this.collection);
- }
-}
+export const MID_COLOR_STOP = '#EBEFF5';
/**
- * This function takes a color palette name and returns an array of hex color
- * codes for use in UI elements such as charts.
- *
- * @param {string} hexStart The beginning hexadecimal color code
- * @param {string} hexEnd The ending hexadecimal color code
- * @param {number} len The number of colors in the resulting array (default 10)
- * @returns {Array} Returns an array of hexadecimal color codes
+ * This function takes an array of colors and returns an array of interpolated
+ * colors based on the number of steps/len needed for use in UI elements such as charts.
+ * Derived from https://github.com/gka/palettes (Unlicensed)
*/
export function colorPalette(
- hexStart: string,
- hexEnd: string,
- len: number = 10
+ /**
+ * The beginning hexadecimal color code or array of codes
+ */
+ colors: string[],
+ /**
+ * The number of colors in the resulting array (default 10)
+ */
+ len: number = 10,
+ /**
+ * Forces color interpolation to be calculated separately for each side (default false)
+ */
+ diverging: boolean = false,
+ /**
+ * Uses a more static interpolation for non-continuous spectrums
+ */
+ categorical: boolean = false
) {
- if (isHex(hexStart) && isHex(hexEnd)) {
- const colorArray: Color[] = [];
- const hexPalette: string[] = [];
- const count = len - 1;
- const startHex = hexToRgb(hexStart); // get RGB equivalent values as array
- const endHex = hexToRgb(hexEnd); // get RGB equivalent values as array
- colorArray[0] = new Color(startHex[0], startHex[1], startHex[2]); // create first color obj
- colorArray[count] = new Color(endHex[0], endHex[1], endHex[2]); // create last color obj
- const step = stepCalc(count, colorArray[0], colorArray[count]); // create array of step increments
- // build the color palette array
- hexPalette[0] = colorArray[0].text; // set the first color in the array
- for (let i = 1; i < count; i++) {
- // set the intermediate colors in the array
- const r = colorArray[0].r + step[0] * i;
- const g = colorArray[0].g + step[1] * i;
- const b = colorArray[0].b + step[2] * i;
- colorArray[i] = new Color(r, g, b);
- hexPalette[i] = colorArray[i].text;
- } // all the colors in between
- hexPalette[count] = colorArray[count].text; // set the last color in the array
+ let hexStart: string[] = colors.slice();
+ let hexEnd: string[] = [];
+
+ const even = len % 2 === 0;
+ const numColorsLeft = diverging ? Math.ceil(len / 2) + (even ? 1 : 0) : len;
+ const numColorsRight = diverging ? Math.ceil(len / 2) + (even ? 1 : 0) : 0;
- return hexPalette;
- } else {
- throw new Error('Please provide two valid hex color codes.');
+ // If only a single color is provided prepend the mid-point color
+ if (hexStart.length === 1) {
+ hexStart.unshift(MID_COLOR_STOP);
}
-}
-/**
- * Check if argument is a valid 3 or 6 character hexadecimal color code
- */
-function isHex(value: string): boolean {
- return /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value);
-}
+ // If diverging, split the start array and duplicate the mid color
+ if (diverging) {
+ // If there's no midpoint, create one
+ if (hexStart.length < 3) {
+ hexStart[2] = hexStart[1];
+ hexStart[1] = MID_COLOR_STOP;
+ }
-/**
- * Calculate and construct the hexadecimal color code from RGB values
- */
-function createHex(rgbValues: rgbDef): string {
- let result = '';
- let val = 0;
- let piece;
- const base = 16;
- for (let k = 0; k < 3; k++) {
- val = Math.round(rgbValues[k]);
- piece = val.toString(base); // Converts to radix 16 based value (0-9, A-F)
- if (piece.length < 2) {
- piece = `0${piece}`;
+ const numColorsHalf = Math.ceil(hexStart.length / 2);
+
+ const colorsLeft = hexStart.filter(function(item, index) {
+ if (index < numColorsHalf) {
+ return true; // keep it
+ }
+ });
+ const colorsRight = hexStart
+ .reverse()
+ .filter(function(item, index) {
+ if (index < numColorsHalf) {
+ return true; // keep it
+ }
+ })
+ .reverse();
+
+ hexStart = colorsLeft;
+ hexEnd = colorsRight;
+ }
+
+ function createSteps(colors: string[], steps: number) {
+ if (!colors.length) {
+ return colors;
+ }
+
+ if (!categorical) {
+ return chroma
+ .bezier(colors)
+ .scale()
+ .correctLightness()
+ .colors(steps);
+ } else {
+ return chroma.scale(colors).colors(steps);
}
- result = result + piece;
}
- result = `#${result.toUpperCase()}`; // Return in #RRGGBB format
- return result;
-}
-/**
- * Calculate the step increment for each piece of the hexadecimal color code
- */
-function stepCalc(st: number, cStart: Color, cEnd: Color): rgbDef {
- const steps = st;
- const step: rgbDef = [
- (cEnd.r - cStart.r) / steps, // Calc step amount for red value
- (cEnd.g - cStart.g) / steps, // Calc step amount for green value
- (cEnd.b - cStart.b) / steps, // Calc step amount for blue value
- ];
+ const stepsLeft = createSteps(hexStart, numColorsLeft);
+ const stepsRight = createSteps(hexEnd, numColorsRight);
- return step;
+ return (even && diverging
+ ? stepsLeft.slice(0, stepsLeft.length - 1)
+ : stepsLeft
+ ).concat(stepsRight.slice(1));
}
diff --git a/src/services/color/eui_palettes.ts b/src/services/color/eui_palettes.ts
index 7be40f62f46..d691e72ed7e 100644
--- a/src/services/color/eui_palettes.ts
+++ b/src/services/color/eui_palettes.ts
@@ -1,48 +1,176 @@
-interface EuiPalette {
- colors: string[];
-}
-
-const euiPaletteColorBlind: EuiPalette = {
- colors: [
- '#1EA593',
- '#2B70F7',
- '#CE0060',
- '#38007E',
- '#FCA5D3',
- '#F37020',
- '#E49E29',
- '#B0916F',
- '#7B000B',
- '#34130C',
- ],
-};
-
-const euiPaletteForLightBackground: EuiPalette = {
- colors: ['#006BB4', '#017D73', '#F5A700', '#BD271E', '#DD0A73'],
-};
-
-const euiPaletteForDarkBackground: EuiPalette = {
- colors: ['#1BA9F5', '#7DE2D1', '#F990C0', '#F66', '#FFCE7A'],
-};
-
-const euiPaletteForStatus: EuiPalette = {
- colors: [
- '#58BA6D',
- '#6ECE67',
- '#A5E26A',
- '#D2E26A',
- '#EBDF61',
- '#EBD361',
- '#EBC461',
- '#D99D4C',
- '#D97E4C',
- '#D75949',
- ],
-};
-
-export const palettes = {
- euiPaletteColorBlind,
- euiPaletteForLightBackground,
- euiPaletteForDarkBackground,
- euiPaletteForStatus,
+import { HEX } from './color_types';
+import { colorPalette } from './color_palette';
+import { flatten } from 'lodash';
+
+export type EuiPalette = string[];
+
+const euiPalette = function(
+ colors: string[],
+ steps: number,
+ diverge: boolean = false
+): EuiPalette {
+ // This function also trims the lightest color so white is never a color
+ if (!diverge && steps > 1) {
+ const palette = colorPalette(colors, steps + 1);
+ palette.shift();
+ return palette;
+ }
+
+ return colorPalette(colors, steps, diverge);
+};
+
+export const euiPaletteColorBlind = function(
+ /**
+ * How many variations of the series is needed
+ */
+ rotations: number = 1,
+ /**
+ * Order similar colors as `group`s or just `append` each variation
+ */
+ order: 'append' | 'group' = 'append'
+): EuiPalette {
+ let colors: string[] = [];
+
+ const base = [
+ '#5BBAA0', // 0 green
+ '#6092C0', // 1 blue
+ '#D36086', // 2 dark pink
+ '#9170B8', // 3 purple
+ '#EEAFCF', // 4 light pink
+ '#FAE181', // 5 yellow
+ '#CDBD9D', // 6 tan
+ '#F19F58', // 7 orange
+ '#B46F5F', // 8 brown
+ '#E7664C', // 9 red
+ ];
+
+ if (rotations > 1) {
+ const palettes = base.map(color =>
+ euiPalette(['white', color], rotations).reverse()
+ );
+
+ if (order === 'group') {
+ colors = flatten(palettes);
+ } else {
+ for (let i = 0; i < rotations; i++) {
+ const rotation = palettes.map(palette => palette[i]);
+ colors.push(...rotation);
+ }
+ }
+ } else {
+ colors = base;
+ }
+
+ return colors;
+};
+
+export const euiPaletteForLightBackground = function(): EuiPalette {
+ return ['#006BB4', '#017D73', '#F5A700', '#BD271E', '#DD0A73'];
+};
+
+export const euiPaletteForDarkBackground = function(): EuiPalette {
+ return ['#1BA9F5', '#7DE2D1', '#F990C0', '#F66', '#FFCE7A'];
+};
+
+const positiveColor: HEX = '#209280';
+const negativeColor: HEX = '#CC5642';
+const lightNegativeColor: HEX = euiPaletteColorBlind()[9];
+const coolArray: HEX[] = [euiPaletteColorBlind()[1], '#6092C0'];
+const warmArray: HEX[] = [euiPaletteColorBlind()[7], euiPaletteColorBlind()[9]];
+
+export const euiPaletteForStatus = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [euiPaletteColorBlind()[0]];
+ }
+ if (steps <= 3) {
+ return euiPalette(
+ [
+ euiPaletteColorBlind()[0],
+ euiPaletteColorBlind()[5],
+ lightNegativeColor,
+ ],
+ steps,
+ true
+ );
+ }
+ return euiPalette(
+ [
+ positiveColor,
+ euiPaletteColorBlind()[0],
+ euiPaletteColorBlind()[5],
+ lightNegativeColor,
+ negativeColor,
+ ],
+ steps,
+ true
+ );
+};
+
+export const euiPaletteForTemperature = function(steps: number): EuiPalette {
+ const cools = colorPalette([...coolArray.slice().reverse(), '#EBEFF5'], 3);
+ const warms = colorPalette(['#F4F3DB', ...warmArray], 3);
+
+ if (steps === 1) {
+ return [cools[0]];
+ } else if (steps <= 3) {
+ return euiPalette([cools[0], lightNegativeColor], steps, true);
+ }
+
+ return euiPalette([...cools, ...warms], steps, true);
+};
+
+export const euiPaletteComplimentary = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [euiPaletteColorBlind()[1]];
+ }
+
+ return euiPalette(
+ [euiPaletteColorBlind()[1], euiPaletteColorBlind()[7]],
+ steps,
+ true
+ );
+};
+
+export const euiPaletteNegative = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [lightNegativeColor];
+ }
+
+ return euiPalette(['white', negativeColor], steps);
+};
+
+export const euiPalettePositive = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [euiPaletteColorBlind()[0]];
+ }
+
+ return euiPalette(['white', positiveColor], steps);
+};
+
+export const euiPaletteCool = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [coolArray[1]];
+ }
+
+ return euiPalette(['white', ...coolArray], steps);
+};
+
+export const euiPaletteWarm = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return [lightNegativeColor];
+ }
+
+ return euiPalette(['#FBFBDC', ...warmArray], steps);
+};
+
+export const euiPaletteGray = function(steps: number): EuiPalette {
+ if (steps === 1) {
+ return ['#98a2b3'];
+ }
+
+ return euiPalette(
+ ['white', '#d3dae6', '#98a2b3', '#69707d', '#343741'],
+ steps,
+ false
+ );
};
diff --git a/src/services/color/index.ts b/src/services/color/index.ts
index 512ea3c4d69..0f2c99b4ce6 100644
--- a/src/services/color/index.ts
+++ b/src/services/color/index.ts
@@ -15,5 +15,17 @@ export {
DEFAULT_VISUALIZATION_COLOR,
} from './visualization_colors';
export { colorPalette } from './color_palette';
-export { palettes } from './eui_palettes';
+export {
+ euiPaletteForLightBackground,
+ euiPaletteForDarkBackground,
+ euiPaletteColorBlind,
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteComplimentary,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteGray,
+} from './eui_palettes';
export { rgbDef, HSV, RGB } from './color_types';
diff --git a/src/services/color/visualization_colors.ts b/src/services/color/visualization_colors.ts
index dff47febcca..a2535fbf269 100644
--- a/src/services/color/visualization_colors.ts
+++ b/src/services/color/visualization_colors.ts
@@ -1,17 +1,7 @@
// Array of color-blind safe colors to use in visualizations or other
// spots that need a large range of varied, qualitative colors.
+import { euiPaletteColorBlind } from '../../services/color/eui_palettes';
-export const VISUALIZATION_COLORS = [
- '#00B3A4',
- '#3185FC',
- '#DB1374',
- '#490092',
- '#FEB6DB',
- '#E6C220',
- '#F98510',
- '#BFA180',
- '#461A0A',
- '#920000',
-];
+export const VISUALIZATION_COLORS = euiPaletteColorBlind();
export const DEFAULT_VISUALIZATION_COLOR = VISUALIZATION_COLORS[1];
diff --git a/src/services/index.ts b/src/services/index.ts
index 96ae2bc8296..c10903d0ae4 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -30,7 +30,17 @@ export {
VISUALIZATION_COLORS,
DEFAULT_VISUALIZATION_COLOR,
colorPalette,
- palettes,
+ euiPaletteForLightBackground,
+ euiPaletteForDarkBackground,
+ euiPaletteColorBlind,
+ euiPaletteForStatus,
+ euiPaletteForTemperature,
+ euiPaletteComplimentary,
+ euiPaletteNegative,
+ euiPalettePositive,
+ euiPaletteCool,
+ euiPaletteWarm,
+ euiPaletteGray,
HSV,
} from './color';
diff --git a/src/themes/charts/themes.ts b/src/themes/charts/themes.ts
index b06faca05ee..08494264d62 100644
--- a/src/themes/charts/themes.ts
+++ b/src/themes/charts/themes.ts
@@ -1,4 +1,4 @@
-import { palettes } from '../../services/color/eui_palettes';
+import { euiPaletteColorBlind } from '../../services/color/eui_palettes';
import { DEFAULT_VISUALIZATION_COLOR } from '../../services/color/visualization_colors';
import { PartialTheme, LineAnnotationStyle } from '@elastic/charts';
@@ -111,7 +111,7 @@ function createTheme(colors: any) {
},
},
colors: {
- vizColors: palettes.euiPaletteColorBlind.colors,
+ vizColors: euiPaletteColorBlind(),
defaultVizColor: DEFAULT_VISUALIZATION_COLOR,
},
crosshair: {
diff --git a/src/themes/eui-amsterdam/eui_amsterdam_colors_dark.scss b/src/themes/eui-amsterdam/eui_amsterdam_colors_dark.scss
index baa4ff495cf..7590bab3ca9 100644
--- a/src/themes/eui-amsterdam/eui_amsterdam_colors_dark.scss
+++ b/src/themes/eui-amsterdam/eui_amsterdam_colors_dark.scss
@@ -31,17 +31,16 @@ $euiShadowColorLarge: #000;
// Visualization colors
// Currently this is the same as light. It is required to list them for our docs to work
-
-$euiColorVis0: #00B3A4;
-$euiColorVis1: #3185FC;
-$euiColorVis2: #DB1374;
-$euiColorVis3: #490092;
-$euiColorVis4: #FEB6DB;
-$euiColorVis5: #E6C220;
-$euiColorVis6: #BFA180;
-$euiColorVis7: #F98510;
-$euiColorVis8: #461A0A;
-$euiColorVis9: #920000;
+$euiColorVis0: #5BBAA0;
+$euiColorVis1: #6092C0;
+$euiColorVis2: #D36086;
+$euiColorVis3: #9170B8;
+$euiColorVis4: #EEAFCF;
+$euiColorVis5: #FAE181;
+$euiColorVis6: #CDBD9D;
+$euiColorVis7: #F19F58;
+$euiColorVis8: #B46F5F;
+$euiColorVis9: #E7664C;
$euiColorChartLines: #343741;
$euiColorChartBand: #2A2C35;
diff --git a/src/themes/eui/eui_colors_dark.scss b/src/themes/eui/eui_colors_dark.scss
index 63c86aa7511..669de2c7171 100644
--- a/src/themes/eui/eui_colors_dark.scss
+++ b/src/themes/eui/eui_colors_dark.scss
@@ -31,17 +31,16 @@ $euiShadowColorLarge: #000;
// Visualization colors
// Currently this is the same as light. It is required to list them for our docs to work
-
-$euiColorVis0: #00B3A4;
-$euiColorVis1: #3185FC;
-$euiColorVis2: #DB1374;
-$euiColorVis3: #490092;
-$euiColorVis4: #FEB6DB;
-$euiColorVis5: #E6C220;
-$euiColorVis6: #BFA180;
-$euiColorVis7: #F98510;
-$euiColorVis8: #461A0A;
-$euiColorVis9: #920000;
+$euiColorVis0: #5BBAA0;
+$euiColorVis1: #6092C0;
+$euiColorVis2: #D36086;
+$euiColorVis3: #9170B8;
+$euiColorVis4: #EEAFCF;
+$euiColorVis5: #FAE181;
+$euiColorVis6: #CDBD9D;
+$euiColorVis7: #F19F58;
+$euiColorVis8: #B46F5F;
+$euiColorVis9: #E7664C;
$euiColorChartLines: #343741;
$euiColorChartBand: #2A2C35;
diff --git a/yarn.lock b/yarn.lock
index d1fca8a4193..ee3b24bd63e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1221,6 +1221,11 @@
resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.8.tgz#5702f74f78b73e13f1eb1bd435c2c9de61a250d4"
integrity sha512-LzF540VOFabhS2TR2yYFz2Mu/fTfkA+5AwYddtJbOJGwnYrr2e7fHadT7/Z3jNGJJdCRlO3ySxmW26NgRdwhNA==
+"@types/chroma-js@^1.4.3":
+ version "1.4.3"
+ resolved "https://registry.yarnpkg.com/@types/chroma-js/-/chroma-js-1.4.3.tgz#4456e5cb46885a4952324e55a4b6d4064904790c"
+ integrity sha512-m33zg9cRLtuaUSzlbMrr7iLIKNzrD4+M6Unt5+9mCu4BhR5NwnRjVKblINCwzcBXooukIgld8DtEncP8qpvbNg==
+
"@types/classnames@^2.2.6":
version "2.2.6"
resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.6.tgz#dbe8a666156d556ed018e15a4c65f08937c3f628"