Skip to content

[Lens as code] preserve all chart style properties during API format round-trip#253597

Closed
ghudgins wants to merge 7 commits intomainfrom
fix/lens-metric-style-api-format-roundtrip
Closed

[Lens as code] preserve all chart style properties during API format round-trip#253597
ghudgins wants to merge 7 commits intomainfrom
fix/lens-metric-style-api-format-roundtrip

Conversation

@ghudgins
Copy link
Copy Markdown
Contributor

@ghudgins ghudgins commented Feb 17, 2026

Summary

Closes #253049

When lens.apiFormat is enabled, visualization style properties are silently dropped during the Lens state <-> API format round-trip conversion on save/load. This causes style changes made in the UI to revert to defaults after saving and reloading a dashboard.

Root cause: The API format schemas for multiple chart types did not include fields for certain visualization state properties. During the enrichConfigurationWithVisualizationProperties (Lens -> API) step they were not written, and during buildVisualizationState (API -> Lens) they were not read back, so they defaulted.

Properties fixed

Chart Type Properties User-configurable
Metric primaryPosition, titleWeight, secondaryAlign Yes
XY reference line decoration_position (renamed from icon_position) Yes
Partition (pie/treemap/mosaic/waffle) legendPosition Yes
Datatable showRowNumbers Yes
Heatmap shouldTruncate, strokeWidth, strokeColor, percentageMode, showTooltip, highlightInHover Partial
Gauge respectRanges, commonLabel No
Shared coloring palette continuity Yes

Fix pattern (same for all)

  1. Schema — add the missing field to the API schema definition
  2. Transform out (Lens -> API) — write the property during serialization
  3. Transform in (API -> Lens) — read the property during deserialization

Files changed

Area Files Change
Metric schema schema/charts/metric.ts Added position, title_weight, secondary alignments
Metric transforms transforms/charts/metric.ts Write/read new props; fix secondaryAlign to read from secondary metric
XY schema schema/charts/xy.ts Added decoration_position (auto/left/right) to reference line
XY transforms transforms/charts/xy/api_layers.ts, state_layers.ts Write/read decoration_position
Partition schemas schema/charts/pie.ts, treemap.ts, mosaic.ts, waffle.ts Added position, values to legend (with maxSize: 2)
Partition transforms transforms/charts/partition.ts Write/read legendPosition
Datatable schema schema/charts/datatable.ts Added show_row_numbers
Datatable transforms to_api/appearance.ts, to_state/appearance.ts Write/read via buildShowRowNumbers helper
Heatmap schema schema/charts/heatmap.ts Added 6 new fields (removed aria_label)
Heatmap transforms transforms/charts/heatmap/to_api.ts, from_api.ts Write/read all new fields
Gauge schema schema/charts/gauge.ts Added respect_ranges, common_label
Gauge transforms transforms/charts/gauge.ts Write/read all new fields
Shared coloring schema schema/color.ts Added continuity to color-by-value
Shared coloring transforms transforms/coloring.ts Write/read continuity
Test mocks 8 mock files across metric, xy, partition, datatable, heatmap, gauge Added non-default values to exercise round-trip coverage

Review feedback addressed

  • Renamed icon_position to decoration_position and limited values to auto|left|right (removed above/below)
  • Removed aria_label from heatmap API (inferred, not user-facing)
  • Removed legendStats from treemap mock (not exposed in treemap UI)
  • Extracted buildShowRowNumbers helper to follow existing datatable pattern
  • Added maxSize: 2 to legend values arrays in partition schemas

Test plan

  • With feature_flags.overrides: { lens.apiFormat: true } in kibana.yml:
    • Create metric chart, change primary position/title weight/secondary alignment, save & reload — verify preserved
    • Create XY chart with reference line, change decoration position, save & reload — verify preserved
    • Create pie/treemap chart, change legend position, save & reload — verify preserved
    • Create datatable, toggle row numbers, save & reload — verify preserved
    • Create heatmap, toggle legend truncation, save & reload — verify preserved
  • Verify the same workflows work without the feature flag (no regression)
  • yarn test:jest src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/ — 273/273 pass
  • yarn test:jest src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/ — 660/660 pass
  • yarn test:type_check --project src/platform/packages/shared/kbn-lens-embeddable-utils/tsconfig.json — passes

…rip (#253049)

When `lens.apiFormat` is enabled, metric chart style properties
(primaryPosition, titleWeight, secondaryAlign) were silently dropped
during the Lens state to API format conversion. This caused style
changes made via the metric chart Style panel to be lost on
dashboard save/reload.

Add `position`, `title_weight` to the primary metric API schema and
`alignments` to the secondary metric API schema, then wire them through
both transform directions so these values survive the round-trip.

Closes #253049

Co-authored-by: Cursor <cursoragent@cursor.com>
@ghudgins ghudgins requested a review from a team as a code owner February 17, 2026 23:18
@ghudgins
Copy link
Copy Markdown
Contributor Author

/ci

@ghudgins ghudgins added backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes labels Feb 17, 2026
…d-trip

Extends the metric chart fix to cover all remaining chart types where
visualization state properties were silently dropped during the Lens
state <-> API format round-trip conversion when lens.apiFormat is enabled.

Properties added across 5 chart types + 1 shared concern:
- XY: reference line iconPosition
- Partition: legendPosition, legendStats (pie/treemap/mosaic/waffle)
- Datatable: showRowNumbers
- Heatmap: shouldTruncate, strokeWidth, strokeColor, percentageMode,
  showTooltip, highlightInHover, ariaLabel
- Gauge: respectRanges, commonLabel, ariaLabel
- Shared coloring: palette continuity

Co-authored-by: Cursor <cursoragent@cursor.com>
@ghudgins ghudgins changed the title fix(lens): preserve metric style properties during API format round-trip fix(lens): preserve all chart style properties during API format round-trip Feb 18, 2026
@walterra walterra changed the title fix(lens): preserve all chart style properties during API format round-trip [Lens as code] preserve all chart style properties during API format round-trip Feb 18, 2026
@walterra
Copy link
Copy Markdown
Contributor

To fix the code scanning warnings you need to add checks like here to the schemas: #253411

Address code scanning warnings for unbounded schema.arrayOf() calls
in pie, treemap, and mosaic legend values schemas.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ghudgins
Copy link
Copy Markdown
Contributor Author

/ci

@ghudgins ghudgins enabled auto-merge (squash) February 18, 2026 22:28
@walterra walterra self-requested a review February 19, 2026 09:00
@@ -37,6 +37,7 @@ function getLegendProps(legend: HeatmapVisualizationState['legend']): HeatmapSta
...stripUndefined<HeatmapState['legend']>({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the settings to have "angled" axis labels in the heatmap doesn't work (it works for regular bar charts).

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

config_builder correctly round-trips the angled orientation value. there is a separate "angled axis labels don't work in heatmap" is a rendering issue in the heatmap visualization expression itself — it receives the -45 rotation value but doesn't render it at an angle. That's a separate bug from this PR's scope #211214 (which is about values being lost during the API format round-trip).

- Rename icon_position to decoration_position and limit to auto|left|right
- Remove aria_label from heatmap API schema and transforms
- Remove legendStats from treemap mock (not exposed in UI)
- Extract buildShowRowNumbers helper in datatable appearance
- Fix reference line mock to use valid icon position value

Co-authored-by: Cursor <cursoragent@cursor.com>
@ghudgins
Copy link
Copy Markdown
Contributor Author

/ci

@walterra walterra added Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.4.0 labels Feb 19, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@markov00 markov00 self-requested a review February 19, 2026 15:39
@ghudgins
Copy link
Copy Markdown
Contributor Author

/ci

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #4 / Endpoint exceptions flyout When valid form state should save endpoint exception with correct os_types based on alert data
  • [job] [logs] Jest Tests #4 / Endpoint exceptions flyout When wildcard warning is active pressing confirm should show confirm modal instead of saving exception

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 569.3KB 571.0KB +1.6KB
dashboard 819.9KB 821.5KB +1.6KB
dashboardAgent 173.3KB 174.9KB +1.6KB
discover 1.6MB 1.6MB +1.6KB
infra 1.2MB 1.2MB +1.6KB
lens 2.0MB 2.0MB +4.0KB
observability 2.0MB 2.0MB +1.6KB
observabilityAIAssistantApp 287.3KB 289.0KB +1.6KB
unifiedDocViewer 398.4KB 400.0KB +1.6KB
total +17.1KB

History

Copy link
Copy Markdown
Contributor

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Thank you Graham for your attempt, but as proved by multiple review comments, allucinations, context missing and no overall schema design process in the generation creates a lot more work on our side as reviewer then for some engineer to pick this task from the beginning and work on that.
I get your willingness to supporting us, but this create way more problems than the the benefits.
I believe is way more useful if, instead of asking LLM to fix these things, you ask LLM to help you idenfity properly every missing parameters, providing a good and validated list of what is missing, from where, what are the parameters available etc. This will help way more then a generated code. The important aspect is the manual Validation: as seen in the review comments, some parameters are just made up, so a manual validation on the interface is greatly appreciated and valuated more then an unsupervised LLM trying its own findings.

We also follows some guidelines on how to correctly reply to PR reviews that creates a structured but simplified process, that in this PR is not followed (if you want I can share the docs on slack as it is not public)

@ghudgins ghudgins closed this Feb 20, 2026
auto-merge was automatically disabled February 20, 2026 13:09

Pull request was closed

@ghudgins ghudgins deleted the fix/lens-metric-style-api-format-roundtrip branch February 20, 2026 13:09
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lens as code] Metric styles configurations are not saved

7 participants