Skip to content

Commit

Permalink
Add new "middle-out" order prop option to `OuiPaletteColorBlind' (#856)
Browse files Browse the repository at this point in the history
* Add new "middle-out" order prop option to `OuiPaletteColorBlind'

Signed-off-by: Josh Romero <[email protected]>

* update changelog

Signed-off-by: Josh Romero <[email protected]>

---------

Signed-off-by: Josh Romero <[email protected]>
(cherry picked from commit c9d0d62)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Aug 31, 2023
1 parent f269adc commit 5f17de6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src-docs/src/views/color_palette/color_palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ const customPalettes = [
palette: ouiPaletteColorBlind({ rotations: 2 }),
code: 'ouiPaletteColorBlind({rotations: 2})',
},
{
title: 'Lots of colors, with the extremes last',
palette: ouiPaletteColorBlind({
rotations: 9,
direction: 'both',
order: 'middle-out',
}),
code:
"ouiPaletteColorBlind({ rotations: 9, direction: 'both', order: 'middle-out' })",
},
{
title:
'Series may have multiple metrics and so the colors must coordinate but be distinguishable',
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/color_palette/props_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const qualitativePropsInfo = {
},
order: {
description:
'Order similar colors as `group`s or just `append` each variation',
'Order similar colors as `group`s, just `append` each variation (from dark to light), or append from the `middle-out`',
required: false,
type: { name: "'append' | 'group'" },
type: { name: "'append' | 'group' | 'middle-out'" },
defaultValue: { value: "'append'" },
},
direction: {
Expand Down
20 changes: 19 additions & 1 deletion src/services/color/oui_palettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface OuiPaletteColorBlindProps {
/**
* Order similar colors as `group`s or just `append` each variation
*/
order?: 'append' | 'group';
order?: 'append' | 'group' | 'middle-out';
/**
* Specifies if the direction of the color variations
*/
Expand Down Expand Up @@ -134,6 +134,24 @@ export const ouiPaletteColorBlind = ({
colors.push(...rotation);
}
}

// start with the appended order, then pick from both ends
if (order === 'middle-out') {
const shadePalettes = [];
while (colors.length) {
shadePalettes.push(colors.splice(0, base.length));
}
while (shadePalettes.length) {
const firstPalette = shadePalettes.shift();
if (firstPalette) {
colors.unshift(...firstPalette);
}
const lastPalette = shadePalettes.pop();
if (lastPalette) {
colors.unshift(...lastPalette);
}
}
}
} else {
colors = base;
}
Expand Down

0 comments on commit 5f17de6

Please sign in to comment.