-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TSVB] Integrates the color service #93749
Merged
Merged
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f255ceb
[TSVB] Integrates the color service
stratoula 5c01295
Fix i18n failure
stratoula ee76843
Sync colors :)
stratoula 98b1458
Merge branch 'master' into tsvb-color-service
kibanamachine 1ca740e
Fix unit tests
stratoula 86825b2
Merge branch 'master' into tsvb-color-service
kibanamachine 6fe3a53
Apply the multiple colors also for gauge
stratoula faa375b
Merge branch 'master' into tsvb-color-service
kibanamachine 803d816
Merge branch 'master' into tsvb-color-service
kibanamachine 63fc286
Fix
stratoula 7ae5bda
Merge branch 'master' into tsvb-color-service
kibanamachine 73a55d3
Merge branch 'master' into tsvb-color-service
kibanamachine 10a8d10
More unit tests
stratoula 9cebf0f
Cleanup
stratoula 2ba5bd6
Merge branch 'master' into tsvb-color-service
kibanamachine 4bf3c08
Merge branch 'master' into tsvb-color-service
kibanamachine b784936
Merge branch 'master' into tsvb-color-service
kibanamachine 08f54ab
Be backwards compatible
stratoula aedea65
Fetch palettesService on vis renderer
stratoula 2209dfe
Fix eslint
stratoula 72f99c9
Fix jest test
stratoula 643cfa6
Fix color mapping for empty labels
stratoula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be backwards compatible I haven't removed the
split_color_mode
. Otherwise, I had to write a migration script to get its value and use it as the palette name. I preferred to skip the migration script.