[9.4] [Lens as code] Fix temporal scale on x axis and histogram brush (#264134)#264482
Merged
kibanamachine merged 1 commit intoelastic:9.4from Apr 20, 2026
Merged
Conversation
…tic#264134) ## Summary API generated charts currently doesn't contain information if a XY chart is actually a time based chart or a categorical chart. We have left this information to be computed/decided at runtime (as it's currently done when you create a chart from the Lens UI). But information about the current timeField is required: - to filter the chart in the configured time range - to property assign the X axis scale type - to enable the timeseries brushing This PR fixes this problem by correctly picking the timeField when necessary and clear the dataview cache that was polluted with the initial adhoc dataview without timefield. Right after ESQL query is executed, I'm adjusting the x scale to time if the table column layer type is date. For ESQL folks, I've just extracted the getESQLTimeField into its own file, so it can be easily reused without the need to touch the DataViews as it was initially used. fix elastic#262425 fix elastic#262181 (cherry picked from commit fb3adea)
Comment on lines
+44
to
+47
| const xScaleType = | ||
| table.columns.find((column) => column.id === accessors.xAccessor)?.meta.type === 'date' | ||
| ? XScaleTypes.TIME | ||
| : args.xScaleType; |
Contributor
There was a problem hiding this comment.
🟡 Medium expression_functions/extended_data_layer_fn.ts:44
The comparison column.id === accessors.xAccessor on line 45 assumes accessors.xAccessor is a string, but getAccessors can return it as an ExpressionValueVisDimension object. When it's an object, the comparison always fails, so date columns are never detected as XScaleTypes.TIME and isHistogram is calculated incorrectly. Use getColumnByAccessor to handle both accessor types.
- const xScaleType =
- table.columns.find((column) => column.id === accessors.xAccessor)?.meta.type === 'date'
- ? XScaleTypes.TIME
- : args.xScaleType;🤖 Copy this AI Prompt to have your agent fix this:
In file src/platform/plugins/shared/chart_expressions/expression_xy/common/expression_functions/extended_data_layer_fn.ts around lines 44-47:
The comparison `column.id === accessors.xAccessor` on line 45 assumes `accessors.xAccessor` is a string, but `getAccessors` can return it as an `ExpressionValueVisDimension` object. When it's an object, the comparison always fails, so date columns are never detected as `XScaleTypes.TIME` and `isHistogram` is calculated incorrectly. Use `getColumnByAccessor` to handle both accessor types.
Evidence trail:
1. `extended_data_layer_fn.ts` lines 25-27: `getAccessors<string | ExpressionValueVisDimension, ExtendedDataLayerArgs>()` shows `xAccessor` can be either type
2. `extended_data_layer_fn.ts` lines 43-46: Uses `column.id === accessors.xAccessor` directly
3. `expression_value_dimension.ts` lines 12-19: Shows `ExpressionValueVisDimension` is an object type with nested accessor
4. `accessors.ts` lines 113-125: `getColumnByAccessor` handles both types correctly
5. `visualization.ts` line 18: Same package uses the correct pattern `getColumnByAccessor(l.xAccessor, l.table.columns)?.meta.type === 'date'`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto9.4:Questions ?
Please refer to the Backport tool documentation