diff --git a/x-pack/plugins/lens/public/metric_visualization/expression.scss b/x-pack/plugins/lens/public/metric_visualization/expression.scss index ad2a175b5b5fc..bf72015637356 100644 --- a/x-pack/plugins/lens/public/metric_visualization/expression.scss +++ b/x-pack/plugins/lens/public/metric_visualization/expression.scss @@ -16,5 +16,6 @@ .lnsMetricExpression__title { font-size: $euiSizeXL; + color: $euiTextColor; } } \ No newline at end of file diff --git a/x-pack/plugins/lens/public/metric_visualization/expression.test.tsx b/x-pack/plugins/lens/public/metric_visualization/expression.test.tsx index 56bb9235aa3a1..aee83fe4fcae9 100644 --- a/x-pack/plugins/lens/public/metric_visualization/expression.test.tsx +++ b/x-pack/plugins/lens/public/metric_visualization/expression.test.tsx @@ -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'; @@ -94,6 +94,7 @@ describe('metric_expression', () => { ).toMatchInlineSnapshot(` {
3
@@ -132,6 +132,7 @@ describe('metric_expression', () => { ).toMatchInlineSnapshot(` {
last
@@ -169,6 +169,7 @@ describe('metric_expression', () => { ).toMatchInlineSnapshot(` {
3
@@ -206,6 +206,7 @@ describe('metric_expression', () => { ).toMatchInlineSnapshot(` {
3
@@ -287,6 +287,7 @@ describe('metric_expression', () => { ).toMatchInlineSnapshot(` {
0
@@ -337,7 +337,7 @@ describe('metric_expression', () => { colors: ['red', 'yellow', 'green'], }; - const instance = shallow( + const instance = mount( { /> ); - 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', }) @@ -368,7 +370,7 @@ describe('metric_expression', () => { continuity: 'above', }; - const instance = shallow( + const instance = mount( { ); 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), @@ -400,7 +402,7 @@ describe('metric_expression', () => { continuity: 'below', }; - const instance = shallow( + const instance = mount( { ); 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), @@ -433,7 +435,7 @@ describe('metric_expression', () => { continuity: 'none', }; - const instance = shallow( + const instance = mount( { ); 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), @@ -466,7 +468,7 @@ describe('metric_expression', () => { continuity: 'none', }; - const instance = shallow( + const instance = mount( { ); 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), @@ -499,7 +501,7 @@ describe('metric_expression', () => { continuity: 'all', }; - const instance = shallow( + const instance = mount( { /> ); - 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', }) @@ -530,7 +534,7 @@ describe('metric_expression', () => { continuity: 'all', }; - const instance = shallow( + const instance = mount( { /> ); - 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', }) diff --git a/x-pack/plugins/lens/public/metric_visualization/expression.tsx b/x-pack/plugins/lens/public/metric_visualization/expression.tsx index b9a79963510ed..38bb92bb342ef 100644 --- a/x-pack/plugins/lens/public/metric_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/metric_visualization/expression.tsx @@ -98,7 +98,8 @@ function getColorStyling( [cssProp]: color, }; if (colorMode === ColorMode.Background && color) { - styling.color = getContrastColor(color, isDarkTheme); + // set to "euiTextColor" for both light and dark color, depending on the theme + styling.color = getContrastColor(color, isDarkTheme, 'euiTextColor', 'euiTextColor'); } return styling; } @@ -143,13 +144,17 @@ export function MetricChart({ const color = getColorStyling(rawValue, colorMode, palette, uiSettings.get('theme:darkMode')); return ( - + -
+
{value}
{mode === 'full' && ( -
+
{metricTitle}
)} diff --git a/x-pack/plugins/lens/public/shared_components/coloring/utils.ts b/x-pack/plugins/lens/public/shared_components/coloring/utils.ts index 6b61b4e568cf4..7cd89b2464c4e 100644 --- a/x-pack/plugins/lens/public/shared_components/coloring/utils.ts +++ b/x-pack/plugins/lens/public/shared_components/coloring/utils.ts @@ -293,9 +293,17 @@ export function getColorStops( return freshColorStops; } -export function getContrastColor(color: string, isDarkTheme: boolean) { - const darkColor = isDarkTheme ? euiDarkVars.euiColorInk : euiLightVars.euiColorInk; - const lightColor = isDarkTheme ? euiDarkVars.euiColorGhost : euiLightVars.euiColorGhost; +export function getContrastColor( + color: string, + isDarkTheme: boolean, + darkTextProp: 'euiColorInk' | 'euiTextColor' = 'euiColorInk', + lightTextProp: 'euiColorGhost' | 'euiTextColor' = 'euiColorGhost' +) { + // when in light theme both text color and colorInk are dark and the choice + // may depends on the specific context. + const darkColor = isDarkTheme ? euiDarkVars.euiColorInk : euiLightVars[darkTextProp]; + // Same thing for light color in dark theme + const lightColor = isDarkTheme ? euiDarkVars[lightTextProp] : euiLightVars.euiColorGhost; const backgroundColor = isDarkTheme ? euiDarkVars.euiPageBackgroundColor : euiLightVars.euiPageBackgroundColor; diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts index 0b0fc672e364b..0a892e96381cb 100644 --- a/x-pack/test/functional/page_objects/lens_page.ts +++ b/x-pack/test/functional/page_objects/lens_page.ts @@ -1020,7 +1020,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>((memo, cssLine) => { const [prop, value] = cssLine.split(':');