Skip to content
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

[Lens] Add ability to set colors for y-axis series #70311

Merged
merged 20 commits into from
Jul 3, 2020
Merged
36 changes: 20 additions & 16 deletions x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { debounce } from 'lodash';
import {
EuiButtonGroup,
EuiFormRow,
Expand Down Expand Up @@ -164,7 +165,7 @@ const tooltipContent = {
}),
disabled: i18n.translate('xpack.lens.configPanel.color.tooltip.disabled', {
defaultMessage:
'Individual series cannot be custom colored when the layer includes a “Split by.“',
'Individual series cannot be custom colored when the layer includes a “Break down by“',
}),
};

Expand All @@ -182,25 +183,28 @@ const ColorPicker = ({

const handleColor: EuiColorPickerProps['onChange'] = (text, output) => {
setColor(text);

if (output.isValid || text === '') {
const newYConfigs = [...(layer.yConfig || [])];
const existingIndex = newYConfigs.findIndex((yConfig) => yConfig.forAccessor === accessor);
if (existingIndex !== -1) {
if (text === '') {
delete newYConfigs[existingIndex].color;
} else {
newYConfigs[existingIndex].color = output.hex;
}
updateColorInState(text, output);
}
};

const updateColorInState: EuiColorPickerProps['onChange'] = debounce((text, output) => {
mbondyra marked this conversation as resolved.
Show resolved Hide resolved
const newYConfigs = [...(layer.yConfig || [])];
const existingIndex = newYConfigs.findIndex((yConfig) => yConfig.forAccessor === accessor);
if (existingIndex !== -1) {
if (text === '') {
delete newYConfigs[existingIndex].color;
} else {
newYConfigs.push({
forAccessor: accessor,
color: output.hex,
});
newYConfigs[existingIndex].color = output.hex;
}
setState(updateLayer(state, { ...layer, yConfig: newYConfigs }, index));
} else {
newYConfigs.push({
forAccessor: accessor,
color: output.hex,
});
}
};
setState(updateLayer(state, { ...layer, yConfig: newYConfigs }, index));
}, 256);

return (
<EuiToolTip
Expand Down