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] Make metric color fill the entire space #122091

Merged
merged 13 commits into from
Jan 18, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

.lnsMetricExpression__title {
font-size: $euiSizeXL;
color: $euiColorFullShade;
}
}
46 changes: 26 additions & 20 deletions x-pack/plugins/lens/public/metric_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { MetricChart } from './expression';
import { MetricConfig, metricChart } from '../../common/expressions';
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks';
import type { IFieldFormat } from '../../../../../src/plugins/field_formats/common';
import { layerTypes } from '../../common';
Expand Down Expand Up @@ -94,14 +94,14 @@ describe('metric_expression', () => {
).toMatchInlineSnapshot(`
<VisualizationContainer
className="lnsMetricExpression__container"
style={Object {}}
>
<AutoScale
key="3"
>
<div
className="lnsMetricExpression__value"
data-test-subj="lns_metric_value"
style={Object {}}
>
3
</div>
Expand Down Expand Up @@ -132,14 +132,14 @@ describe('metric_expression', () => {
).toMatchInlineSnapshot(`
<VisualizationContainer
className="lnsMetricExpression__container"
style={Object {}}
>
<AutoScale
key="last"
>
<div
className="lnsMetricExpression__value"
data-test-subj="lns_metric_value"
style={Object {}}
>
last
</div>
Expand Down Expand Up @@ -169,14 +169,14 @@ describe('metric_expression', () => {
).toMatchInlineSnapshot(`
<VisualizationContainer
className="lnsMetricExpression__container"
style={Object {}}
>
<AutoScale
key="3"
>
<div
className="lnsMetricExpression__value"
data-test-subj="lns_metric_value"
style={Object {}}
>
3
</div>
Expand Down Expand Up @@ -206,14 +206,14 @@ describe('metric_expression', () => {
).toMatchInlineSnapshot(`
<VisualizationContainer
className="lnsMetricExpression__container"
style={Object {}}
>
<AutoScale
key="3"
>
<div
className="lnsMetricExpression__value"
data-test-subj="lns_metric_value"
style={Object {}}
>
3
</div>
Expand Down Expand Up @@ -287,14 +287,14 @@ describe('metric_expression', () => {
).toMatchInlineSnapshot(`
<VisualizationContainer
className="lnsMetricExpression__container"
style={Object {}}
>
<AutoScale
key="0"
>
<div
className="lnsMetricExpression__value"
data-test-subj="lns_metric_value"
style={Object {}}
>
0
</div>
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('metric_expression', () => {
colors: ['red', 'yellow', 'green'],
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -346,7 +346,9 @@ describe('metric_expression', () => {
/>
);

expect(instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')).toEqual(
expect(
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).toEqual(
expect.objectContaining({
color: 'red',
})
Expand All @@ -368,7 +370,7 @@ describe('metric_expression', () => {
continuity: 'above',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -378,7 +380,7 @@ describe('metric_expression', () => {
);

expect(
instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).not.toEqual(
expect.objectContaining({
color: expect.any(String),
Expand All @@ -400,7 +402,7 @@ describe('metric_expression', () => {
continuity: 'below',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -410,7 +412,7 @@ describe('metric_expression', () => {
);

expect(
instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).not.toEqual(
expect.objectContaining({
color: expect.any(String),
Expand All @@ -433,7 +435,7 @@ describe('metric_expression', () => {
continuity: 'none',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -443,7 +445,7 @@ describe('metric_expression', () => {
);

expect(
instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).not.toEqual(
expect.objectContaining({
color: expect.any(String),
Expand All @@ -466,7 +468,7 @@ describe('metric_expression', () => {
continuity: 'none',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -476,7 +478,7 @@ describe('metric_expression', () => {
);

expect(
instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).not.toEqual(
expect.objectContaining({
color: expect.any(String),
Expand All @@ -499,7 +501,7 @@ describe('metric_expression', () => {
continuity: 'all',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -508,7 +510,9 @@ describe('metric_expression', () => {
/>
);

expect(instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')).toEqual(
expect(
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).toEqual(
expect.objectContaining({
color: 'green',
})
Expand All @@ -530,7 +534,7 @@ describe('metric_expression', () => {
continuity: 'all',
};

const instance = shallow(
const instance = mount(
<MetricChart
data={data}
args={args}
Expand All @@ -539,7 +543,9 @@ describe('metric_expression', () => {
/>
);

expect(instance.find('[data-test-subj="lns_metric_value"]').first().prop('style')).toEqual(
expect(
instance.find('[data-test-subj="lnsVisualizationContainer"]').first().prop('style')
).toEqual(
expect.objectContaining({
color: 'red',
})
Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/lens/public/metric_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ export function MetricChart({
const color = getColorStyling(rawValue, colorMode, palette, uiSettings.get('theme:darkMode'));

return (
<VisualizationContainer className="lnsMetricExpression__container">
<VisualizationContainer className="lnsMetricExpression__container" style={color}>
<AutoScale key={value}>
<div data-test-subj="lns_metric_value" className="lnsMetricExpression__value" style={color}>
<div data-test-subj="lns_metric_value" className="lnsMetricExpression__value">
{value}
</div>
{mode === 'full' && (
<div data-test-subj="lns_metric_title" className="lnsMetricExpression__title">
<div
data-test-subj="lns_metric_title"
className="lnsMetricExpression__title"
style={colorMode === ColorMode.Background ? color : undefined}
>
{metricTitle}
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/page_objects/lens_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
},

async getMetricStyle() {
const el = await testSubjects.find('lns_metric_value');
const el = await testSubjects.find('lnsVisualizationContainer');
const styleString = await el.getAttribute('style');
return styleString.split(';').reduce<Record<string, string>>((memo, cssLine) => {
const [prop, value] = cssLine.split(':');
Expand Down