Skip to content

[Lens as API] Add colorMapping support for XY charts (ES|QL data layers)#252051

Merged
mbondyra merged 3 commits intoelastic:mainfrom
mbondyra:api_xy_coloring
Feb 10, 2026
Merged

[Lens as API] Add colorMapping support for XY charts (ES|QL data layers)#252051
mbondyra merged 3 commits intoelastic:mainfrom
mbondyra:api_xy_coloring

Conversation

@mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Feb 6, 2026

Summary

Fixes #248867

This PR extends the Lens API's XY chart schema and state-to-API conversion logic to support colorMapping on the breakdown_by field in ES|QL data layers. Previously, colorMapping was only supported on the breakdown_by field for non-ES|QL (form-based) XY data layers. ES|QL layers used a plain esqlColumnSchema for breakdown_by, which did not allow specifying color mapping configuration.

What changed

Two files were modified:

  1. Schema (config_builder/schema/charts/xy.ts): The breakdown_by field in xyDataLayerSchemaESQL was changed from a plain esqlColumnSchema to an extended version that adds an optional color: colorMappingSchema property — mirroring the pattern already established in the non-ES|QL layer (xyDataLayerSchemaNoESQL) and other chart types (pie, treemap, waffle, mosaic, tagcloud, datatable).

  2. Transform (State → API) (config_builder/transforms/charts/xy/api_layers.ts): The convertDataLayerToAPI function's ES|QL branch (the TextBasedLayer code path) now includes colorMapping from the visualization state when constructing the breakdown_by object in the API output, using the existing fromColorMappingLensStateToAPI utility. This ensures round-trip fidelity: when an ES|QL XY layer has a colorMapping configuration, it is correctly serialized into the API format.

No changes needed for the reverse direction (API → State): The buildDataLayer function in state_layers.ts already handles color on breakdown_by generically via 'color' in layer.breakdown_by, so the existing code at lines 92–94 already picks up the new field and converts it using fromColorMappingAPIToLensState.

@mbondyra mbondyra added Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// release_note:skip Skip the PR/issue when compiling release notes Feature:Lens backport:skip This PR does not require backporting labels Feb 6, 2026
@mbondyra mbondyra changed the title [Lens as API] add colorMapping support for xy charts Feb 6, 2026
@mbondyra mbondyra marked this pull request as ready for review February 6, 2026 13:57
@mbondyra mbondyra requested a review from a team as a code owner February 6, 2026 13:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #54 / Search solution tests Search index details page Solution Nav - Search search index details page has index actions enabled add field button is enabled

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
agentBuilder 566.0KB 566.0KB +53.0B
dashboard 819.6KB 819.6KB +53.0B
discover 1.6MB 1.6MB +53.0B
infra 1.2MB 1.2MB +53.0B
lens 2.0MB 2.0MB +161.0B
observability 1.8MB 1.8MB +53.0B
observabilityAIAssistantApp 286.9KB 286.9KB +53.0B
unifiedDocViewer 395.4KB 395.4KB +53.0B
total +532.0B
Copy link
Contributor

@andrimal andrimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and issue is fixed! ✨

@mbondyra mbondyra merged commit f43b402 into elastic:main Feb 10, 2026
16 checks passed
@mbondyra mbondyra deleted the api_xy_coloring branch February 10, 2026 15:04
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 10, 2026
* commit '7dcc1fe3c205d2de0c3ca3f65804f21de09013c3': (285 commits)
  Enrich kbn-check-saved-objects-cli README with CI and manual usage docs (elastic#252557)
  [Discover] Add feature flag to make ESQL the default query mode (elastic#252268)
  Add maskProps.headerZindexLocation above to inspect component flyout (elastic#252543)
  [Security Solution][Atack/Alerts] Flyout header: Assignees  (elastic#252190)
  Upgrade EUI to v112.3.0 (elastic#252315)
  [Fleet] Make save_knowledge_base async in streaming state machine (elastic#252328)
  Upgrade @smithy/config-resolver 4.3.0 → 4.4.6 (elastic#252457)
  [Lens as API] Add colorMapping support for XY charts (ES|QL data layers) (elastic#252051)
  [WorkplaceAI] Add Google Drive data source and connector (elastic#250677)
  [Scout] Move GlobalSearch FTR tests to Scout (elastic#252201)
  [EDR Workflows] Fix osquery pack results display when agent clock is skewed (elastic#251417)
  [Observability Onboarding] Apply integrations limit after dedup in parseIntegrationsTSV (elastic#252486)
  [Entity Analytics] Update `host.ip` aggregation to remove painless script (elastic#252426)
  Address `@elastic/eui/require-table-caption` lint violations across `@elastic/obs-presentation-team` files (elastic#251050)
  Consolidate JSON stringify dependencies (elastic#251890)
  [index mgmt] Use esql instead of query dsl to get the index count (elastic#252422)
  Add Usage API Plugin (elastic#252434)
  Cases All Templates page (elastic#250372)
  [Agent Builder] Default value for optional params in ESQL tools (elastic#238472)
  [Fleet] Add upgrade_details.metadata.reason to AgentResponseSchema (elastic#252485)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.4.0

4 participants