diff --git a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.test.ts b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.test.ts index d7252f2b9977c..a368857613fec 100644 --- a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.test.ts @@ -5,7 +5,11 @@ * 2.0. */ -import { getAssignedColorConfig, getColorAssignments } from './color_assignment'; +import { + getAssignedColorConfig, + getColorAssignments, + getLayerPaletteName, +} from './color_assignment'; import type { FormatFactory } from '../../../common/types'; import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { XYDataLayerConfig } from './types'; @@ -230,6 +234,28 @@ describe('color_assignment', () => { }); }); + describe('getLayerPaletteName', () => { + it('should fall back to line-optimized palette for line series with no explicit palette', () => { + const layer: XYDataLayerConfig = { + ...layers[0], + seriesType: 'line', + palette: undefined, + colorMapping: undefined, + }; + expect(getLayerPaletteName(layer)).toEqual(KbnPalette.ElasticLineOptimized); + }); + + it('should fall back to default palette for bar series with no explicit palette', () => { + const layer: XYDataLayerConfig = { + ...layers[0], + seriesType: 'bar', + palette: undefined, + colorMapping: undefined, + }; + expect(getLayerPaletteName(layer)).toEqual(KbnPalette.Default); + }); + }); + describe('colorMapping palette support', () => { it('should group layers by colorMapping.paletteId when present', () => { const lineLayer: XYDataLayerConfig = { @@ -318,5 +344,45 @@ describe('color_assignment', () => { expect(paletteService.get).toHaveBeenCalledWith('default'); expect(defaultGetCategoricalColor).toHaveBeenCalled(); }); + + it('should group bar layers under the default palette', () => { + const barLayer1: XYDataLayerConfig = { + ...layers[0], + layerId: '1', + seriesType: 'bar', + palette: undefined, + colorMapping: undefined, + }; + const barLayer2: XYDataLayerConfig = { + ...layers[1], + layerId: '2', + seriesType: 'bar', + palette: undefined, + colorMapping: undefined, + }; + const assignments = getColorAssignments([barLayer1, barLayer2], data, formatFactory); + expect(assignments[KbnPalette.ElasticLineOptimized]).toBeUndefined(); + expect(assignments[KbnPalette.Default]).toBeDefined(); + }); + + it('should group multiple line layers under the line-optimized palette', () => { + const lineLayer1: XYDataLayerConfig = { + ...layers[0], + layerId: '1', + seriesType: 'line', + palette: undefined, + colorMapping: undefined, + }; + const lineLayer2: XYDataLayerConfig = { + ...layers[1], + layerId: '2', + seriesType: 'line', + palette: undefined, + colorMapping: undefined, + }; + const assignments = getColorAssignments([lineLayer1, lineLayer2], data, formatFactory); + expect(assignments[KbnPalette.ElasticLineOptimized]).toBeDefined(); + expect(assignments[KbnPalette.Default]).toBeUndefined(); + }); }); }); diff --git a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.ts b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.ts index baed001b72966..e2bbe024b3d8f 100644 --- a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.ts +++ b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/color_assignment.ts @@ -25,13 +25,14 @@ import { getSingleColorConfig, } from './reference_line_helpers'; import type { XYDataLayerConfig, XYLayerConfig } from './types'; +import { getDefaultPalette } from './default_palette'; const isPrimitive = (value: unknown): boolean => value != null && typeof value !== 'object'; export const defaultReferenceLineColor = euiLightVars.euiColorDarkShade; export const getLayerPaletteName = (layer: XYDataLayerConfig): string => - layer.colorMapping?.paletteId ?? layer.palette?.name ?? 'default'; + layer.colorMapping?.paletteId ?? layer.palette?.name ?? getDefaultPalette(layer.seriesType); const getPaletteDefinition = (paletteService: PaletteRegistry, paletteName: string) => paletteService.get(paletteName) ?? paletteService.get('default'); diff --git a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.tsx b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.tsx index ad76b6d17af03..4f5e6fe7077c7 100644 --- a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.tsx +++ b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.tsx @@ -78,6 +78,7 @@ import { getColorAssignments, getLayerPaletteName, } from './color_assignment'; +import { getDefaultPalette } from './default_palette'; import { getAnnotationLayerErrors, isHorizontalChart, @@ -494,7 +495,9 @@ export const getXyVisualization = ({ }) .unsubscribe(); } else { - const palette = paletteService.get(dataLayer.palette?.name || 'default'); + const palette = paletteService.get( + dataLayer.palette?.name || getDefaultPalette(dataLayer.seriesType) + ); colors = palette.getCategoricalColors(10, dataLayer.palette?.params); } diff --git a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/xy_config_panel/dimension_editor.tsx b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/xy_config_panel/dimension_editor.tsx index 242ee128536bf..024fdf0d53624 100644 --- a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/xy_config_panel/dimension_editor.tsx +++ b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/xy_config_panel/dimension_editor.tsx @@ -12,7 +12,7 @@ import { ColorPicker } from '@kbn/visualization-ui-components'; import { EuiButtonGroup, EuiFormRow, htmlIdGenerator } from '@elastic/eui'; import type { PaletteRegistry, ColorMapping, PaletteOutput } from '@kbn/coloring'; -import { canCreateCustomMatch } from '@kbn/coloring'; +import { DEFAULT_COLOR_MAPPING_CONFIG, canCreateCustomMatch } from '@kbn/coloring'; import { getColorCategories } from '@kbn/chart-expressions-common'; import type { ValuesType } from 'utility-types'; import type { KbnPalettes } from '@kbn/palettes'; @@ -31,6 +31,7 @@ import { getAssignedColorConfig, getLayerPaletteName, } from '../color_assignment'; +import { getDefaultPalette } from '../default_palette'; import { ColorMappingByTerms } from '../../../shared_components/coloring/color_mapping_by_terms'; export const idPrefix = htmlIdGenerator()(); @@ -170,11 +171,15 @@ export function DataDimensionEditor( formatter = props.formatFactory(columnMeta?.params); } + const defaultColorMapping = !layer.palette + ? { ...DEFAULT_COLOR_MAPPING_CONFIG, paletteId: getDefaultPalette(layer.seriesType) } + : undefined; + return !layer.collapseFn ? (