-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds colorPalette service * addressing some feedback * various and sundry feedback changes * code, palettes, docs cleanup
- Loading branch information
Ryan Keairns
authored
Sep 25, 2018
1 parent
cff4915
commit 584fdd2
Showing
19 changed files
with
491 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTitle, | ||
EuiSpacer, | ||
} from '../../../../src/components'; | ||
|
||
import { | ||
palettes, | ||
} from '../../../../src/services'; | ||
|
||
const paletteData = palettes; | ||
const paletteNames = Object.keys(paletteData); | ||
|
||
export default () => ( | ||
<Fragment> | ||
{ | ||
paletteNames.map((paletteName, i) => ( | ||
<div key={paletteName}> | ||
<EuiTitle key={i} size="xxs"><h3>{paletteName}</h3></EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup gutterSize="none" alignItems="flexStart" key={`${paletteName}-${i}`}> | ||
{ | ||
paletteData[paletteName].colors.map((hexCode, j) => ( | ||
<EuiFlexItem key={`${hexCode}-${j}`} grow={false} className={'guideColorPalette__swatch'}> | ||
<span title={hexCode} style={{ backgroundColor: hexCode }} /> | ||
</EuiFlexItem> | ||
)) | ||
} | ||
</EuiFlexGroup> | ||
<EuiSpacer size="l" /> | ||
</div> | ||
)) | ||
} | ||
</Fragment> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { Fragment } from 'react'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTitle, | ||
EuiSpacer, | ||
} from '../../../../src/components'; | ||
|
||
import { | ||
colorPalette, | ||
palettes, | ||
} from '../../../../src/services'; | ||
|
||
const euiColors = palettes.euiPaletteForLightBackground.colors; | ||
|
||
export default () => ( | ||
<Fragment> | ||
<EuiTitle size="xxs"><h3>For mapping density, low to high</h3></EuiTitle> | ||
<EuiSpacer size="s" /> | ||
{ | ||
euiColors.map((color, j) => ( | ||
<div key={j}> | ||
<EuiFlexGroup gutterSize="none" alignItems="flexStart" key={`${color}-${j}`}> | ||
{ | ||
colorPalette('FFFFFF', color, 20).map((hexCode, k) => ( | ||
<EuiFlexItem key={`${hexCode}-${k}`} grow={false} className={'guideColorPalette__swatch'}> | ||
<span title={hexCode} style={{ backgroundColor: hexCode }} /> | ||
</EuiFlexItem> | ||
)) | ||
} | ||
</EuiFlexGroup> | ||
<EuiSpacer size="m" /> | ||
</div> | ||
)) | ||
} | ||
<EuiSpacer size="l" /> | ||
<EuiTitle size="xxs"><h3>For communicating state, trending negaitve</h3></EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup gutterSize="none" alignItems="flexStart"> | ||
{ | ||
colorPalette('#FBEFD3', '#BD4C48').map((hexCode, l) => ( | ||
<EuiFlexItem key={`${hexCode}-${l}`} grow={false} className={'guideColorPalette__swatch'}> | ||
<span title={hexCode} style={{ backgroundColor: hexCode }} /> | ||
</EuiFlexItem> | ||
)) | ||
} | ||
</EuiFlexGroup> | ||
<EuiSpacer size="l" /> | ||
<EuiTitle size="xxs"><h3>For communicating state, trending positive</h3></EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup gutterSize="none" alignItems="flexStart"> | ||
{ | ||
colorPalette('#FFFFE0', '#017F75').map((hexCode, l) => ( | ||
<EuiFlexItem key={`${hexCode}-${l}`} grow={false} className={'guideColorPalette__swatch'}> | ||
<span title={hexCode} style={{ backgroundColor: hexCode }} /> | ||
</EuiFlexItem> | ||
)) | ||
} | ||
</EuiFlexGroup> | ||
</Fragment> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideSectionTypes, | ||
} from '../../components'; | ||
|
||
import { | ||
EuiCode, | ||
} from '../../../../src/components'; | ||
|
||
import ColorPalette from './color_palette'; | ||
const colorPaletteSource = require('!!raw-loader!./color_palette'); | ||
const colorPaletteHtml = renderToHtml(ColorPalette); | ||
|
||
import ColorPaletteCustom from './color_palette_custom'; | ||
const colorPaletteCustomSource = require('!!raw-loader!./color_palette_custom'); | ||
const colorPaletteCustomHtml = renderToHtml(ColorPaletteCustom); | ||
|
||
import ColorPaletteHistogram from './color_palette_histogram'; | ||
const colorPaletteHistogramSource = require('!!raw-loader!./color_palette_histogram'); | ||
const colorPaletteHistogramHtml = renderToHtml(ColorPaletteHistogram); | ||
|
||
export const ColorPaletteExample = { | ||
title: 'Color Palettes', | ||
sections: [{ | ||
title: 'Preset qualitative palettes', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: colorPaletteSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: colorPaletteHtml, | ||
}], | ||
text: ( | ||
<div> | ||
<p> | ||
The <EuiCode>eui_palettes.js</EuiCode> file provides a base set of color palettes in | ||
an array format. The hexidecimal 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. | ||
</p> | ||
<p> | ||
Quantitative palettes are best suited for communicating and comparing discrete | ||
data series. | ||
</p> | ||
</div> | ||
), | ||
demo: <ColorPalette />, | ||
}, { | ||
title: 'Recommended quantitative palettes', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: colorPaletteCustomSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: colorPaletteCustomHtml, | ||
}], | ||
text: ( | ||
<div> | ||
<p> | ||
Use the <EuiCode>colorPalette</EuiCode> service to generate a custom, gradiated palette | ||
array of any length from two hexidecimal color codes. For example, obtain an array of | ||
yellow-to-green health status colors using | ||
<EuiCode>colorPalette('#FFFF6D', '#1EA593', 20)</EuiCode>. | ||
</p> | ||
<p> | ||
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. | ||
</p> | ||
</div> | ||
), | ||
demo: <ColorPaletteCustom />, | ||
}, { | ||
title: 'Usage examples', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: colorPaletteHistogramSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: colorPaletteHistogramHtml, | ||
}], | ||
text: ( | ||
<p> | ||
Apply the colors from <EuiCode>eui_palettes.js</EuiCode> or the <EuiCode>colorPalette</EuiCode> | ||
service to the <EuiCode>color</EuiCode> prop of EUI chart components. | ||
</p> | ||
), | ||
demo: <ColorPaletteHistogram />, | ||
}], | ||
}; |
65 changes: 65 additions & 0 deletions
65
src-docs/src/views/color_palette/color_palette_histogram.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
|
||
import { | ||
EuiSpacer, | ||
} from '../../../../src/components'; | ||
import { | ||
EuiSeriesChart, | ||
EuiHistogramSeries, | ||
EuiSeriesChartUtils, | ||
} from '../../../../src/experimental'; | ||
import { | ||
colorPalette, | ||
palettes, | ||
} from '../../../../src/services/color'; | ||
|
||
const { SCALE } = EuiSeriesChartUtils; | ||
const timestamp = Date.now(); | ||
const ONE_HOUR = 3600000; | ||
const margins = { | ||
top: 10, | ||
left: 80, | ||
right: 0, | ||
bottom: 20, | ||
}; | ||
const qualColors = palettes.euiPaletteColorBlind.colors; | ||
const quantColors = colorPalette('#FFFF6D', '#1EA593', 6); | ||
|
||
function randomizeData(size = 24, max = 8) { | ||
return new Array(size) | ||
.fill(0) | ||
.map((d, i) => ({ | ||
x0: ONE_HOUR * i, | ||
x: ONE_HOUR * (i + 1), | ||
y: Math.floor(Math.random() * max), | ||
})) | ||
.map(el => ({ | ||
x0: el.x0 + timestamp, | ||
x: el.x + timestamp, | ||
y: el.y, | ||
})); | ||
} | ||
function buildData(series) { | ||
const max = Math.ceil(Math.random() * 1000000); | ||
return new Array(series).fill(0).map(() => randomizeData(20, max)); | ||
} | ||
export default class Example extends Component { | ||
state = { | ||
series: 6, | ||
data: buildData(6), | ||
}; | ||
render() { | ||
const { data } = this.state; | ||
return ( | ||
<Fragment> | ||
<EuiSeriesChart width={600} height={200} xType={SCALE.TIME} stackBy="y" margins={margins}> | ||
{data.map((d, i) => <EuiHistogramSeries key={i} name={`Chart ${i}`} data={d} color={qualColors[i]} />)} | ||
</EuiSeriesChart> | ||
<EuiSpacer size="xl" /> | ||
<EuiSeriesChart width={600} height={200} xType={SCALE.TIME} stackBy="y" margins={margins}> | ||
{data.map((d, i) => <EuiHistogramSeries key={i} name={`Chart ${i}`} data={d} color={quantColors[i]} />)} | ||
</EuiSeriesChart> | ||
</Fragment> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.