forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TSVB] Integrates the color service (elastic#93749)
* [TSVB] Integrates the color service * Fix i18n failure * Sync colors :) * Fix unit tests * Apply the multiple colors also for gauge * Fix * More unit tests * Cleanup * Be backwards compatible * Fetch palettesService on vis renderer * Fix eslint * Fix jest test * Fix color mapping for empty labels Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
432649b
commit d1b6c8f
Showing
23 changed files
with
556 additions
and
231 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
64 changes: 64 additions & 0 deletions
64
src/plugins/vis_type_timeseries/public/application/components/palette_picker.test.tsx
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,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import React from 'react'; | ||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import { ReactWrapper } from 'enzyme'; | ||
import { PalettePicker, PalettePickerProps } from './palette_picker'; | ||
import { chartPluginMock } from '../../../../charts/public/mocks'; | ||
import { EuiColorPalettePicker } from '@elastic/eui'; | ||
import { PALETTES } from '../../../common/types'; | ||
|
||
describe('PalettePicker', function () { | ||
let props: PalettePickerProps; | ||
let component: ReactWrapper<PalettePickerProps>; | ||
|
||
beforeAll(() => { | ||
props = { | ||
palettes: chartPluginMock.createPaletteRegistry(), | ||
activePalette: { | ||
type: 'palette', | ||
name: 'kibana_palette', | ||
}, | ||
setPalette: jest.fn(), | ||
color: '#68BC00', | ||
}; | ||
}); | ||
|
||
it('renders the EuiPalettePicker', () => { | ||
component = mountWithIntl(<PalettePicker {...props} />); | ||
expect(component.find(EuiColorPalettePicker).length).toBe(1); | ||
}); | ||
|
||
it('renders the default palette if not activePalette is given', function () { | ||
const { activePalette, ...newProps } = props; | ||
component = mountWithIntl(<PalettePicker {...newProps} />); | ||
const palettePicker = component.find(EuiColorPalettePicker); | ||
expect(palettePicker.props().valueOfSelected).toBe('default'); | ||
}); | ||
|
||
it('renders the activePalette palette if given', function () { | ||
component = mountWithIntl(<PalettePicker {...props} />); | ||
const palettePicker = component.find(EuiColorPalettePicker); | ||
expect(palettePicker.props().valueOfSelected).toBe('kibana_palette'); | ||
}); | ||
|
||
it('renders two additional palettes, rainbow and gradient', function () { | ||
component = mountWithIntl(<PalettePicker {...props} />); | ||
const palettePicker = component.find(EuiColorPalettePicker); | ||
expect(palettePicker.props().palettes).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
value: PALETTES.RAINBOW, | ||
}), | ||
expect.objectContaining({ | ||
value: PALETTES.GRADIENT, | ||
}), | ||
]) | ||
); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
src/plugins/vis_type_timeseries/public/application/components/palette_picker.tsx
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,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { PaletteOutput, PaletteRegistry } from 'src/plugins/charts/public'; | ||
import { EuiColorPalettePicker } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { rainbowColors } from '../lib/rainbow_colors'; | ||
import { computeGradientFinalColor } from '../lib/compute_gradient_final_color'; | ||
import { PALETTES } from '../../../common/types'; | ||
|
||
export interface PalettePickerProps { | ||
activePalette?: PaletteOutput; | ||
palettes: PaletteRegistry; | ||
setPalette: (value: PaletteOutput) => void; | ||
color: string; | ||
} | ||
|
||
export function PalettePicker({ activePalette, palettes, setPalette, color }: PalettePickerProps) { | ||
const finalGradientColor = computeGradientFinalColor(color); | ||
|
||
return ( | ||
<EuiColorPalettePicker | ||
fullWidth | ||
data-test-subj="visEditorPalettePicker" | ||
compressed | ||
palettes={[ | ||
...palettes | ||
.getAll() | ||
.filter(({ internal }) => !internal) | ||
.map(({ id, title, getColors }) => { | ||
return { | ||
value: id, | ||
title, | ||
type: 'fixed' as const, | ||
palette: getColors(10), | ||
}; | ||
}), | ||
{ | ||
value: PALETTES.GRADIENT, | ||
title: i18n.translate('visTypeTimeseries.timeSeries.gradientLabel', { | ||
defaultMessage: 'Gradient', | ||
}), | ||
type: 'fixed', | ||
palette: palettes | ||
.get('custom') | ||
.getColors(10, { colors: [color, finalGradientColor], gradient: true }), | ||
}, | ||
{ | ||
value: PALETTES.RAINBOW, | ||
title: i18n.translate('visTypeTimeseries.timeSeries.rainbowLabel', { | ||
defaultMessage: 'Rainbow', | ||
}), | ||
type: 'fixed', | ||
palette: palettes | ||
.get('custom') | ||
.getColors(10, { colors: rainbowColors.slice(0, 10), gradient: false }), | ||
}, | ||
]} | ||
onChange={(newPalette) => { | ||
if (newPalette === PALETTES.RAINBOW) { | ||
setPalette({ | ||
type: 'palette', | ||
name: PALETTES.RAINBOW, | ||
params: { | ||
colors: rainbowColors, | ||
gradient: false, | ||
}, | ||
}); | ||
} else if (newPalette === PALETTES.GRADIENT) { | ||
setPalette({ | ||
type: 'palette', | ||
name: PALETTES.GRADIENT, | ||
params: { | ||
colors: [color, finalGradientColor], | ||
gradient: true, | ||
}, | ||
}); | ||
} else { | ||
setPalette({ | ||
type: 'palette', | ||
name: newPalette, | ||
}); | ||
} | ||
}} | ||
valueOfSelected={activePalette?.name || 'default'} | ||
selectionDisplay={'palette'} | ||
/> | ||
); | ||
} |
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
Oops, something went wrong.