Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XY] Allow multiple split accessors #134566

Merged

Conversation

VladLasitsa
Copy link
Contributor

@VladLasitsa VladLasitsa commented Jun 16, 2022

Completes part of #127115

Summary

Allows multiple split accessors for one layer. (splitAccessor -> splitAccessors).
Some refactoring in code related to splitAccessors.

Testing notes:

kibana
| selectFilter
| demodata
| head 15
| xyVis seriesType="area" xAccessor="project" accessors={visdimension "percent_uptime" format="percent"} splitAccessors='cost' splitAccessors='age'
| render

Kuznietsov and others added 30 commits March 16, 2022 18:06
# Conflicts:
#	x-pack/plugins/lens/public/shared_components/axis_title_settings.tsx
#	x-pack/plugins/lens/public/xy_visualization/xy_config_panel/axis_settings_popover.tsx
#	x-pack/plugins/translations/translations/fr-FR.json
# Conflicts:
#	packages/kbn-optimizer/limits.yml
#	x-pack/plugins/lens/public/index.ts
Copy link
Contributor

@Kuznietsov Kuznietsov left a comment

Choose a reason for hiding this comment

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

Thanks, Vlad. Code LGTM 👍

Tested locally, works fine. But I could miss some exceptional cases.

@VladLasitsa VladLasitsa mentioned this pull request Jul 5, 2022
31 tasks
@VladLasitsa VladLasitsa marked this pull request as ready for review July 5, 2022 08:17
@VladLasitsa VladLasitsa requested a review from a team as a code owner July 5, 2022 08:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

@VladLasitsa VladLasitsa requested a review from flash1293 July 5, 2022 08:18
@VladLasitsa
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

expected head sha didn’t match current head ref.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

I couldn't find any issues with behavior, but the performance is very bad (see comments in the code.

I configured a chart with 200 split series (using multi field top values) and getColorAssignments takes over 13s, most of it spent in getAllSeries.

On top of this I noticed that the normalizeTable function is even slower, but that's a separate issue, I'm going to open a bug issue for that.

return {
layerId,
xAccessor: xAccessor === EMPTY_ACCESSOR ? undefined : xAccessor,
yAccessor,
splitAccessor: splitAccessor === EMPTY_ACCESSOR ? undefined : splitAccessor,
splitAccessor: splitAccessors[0] === EMPTY_ACCESSOR ? undefined : splitAccessors,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would splitAccessors[0] be EMPTY_ACCESSOR here or would it be an empty string? In generateSeriesId you are not adding an empty EMPTY_ACCESSOR if there is no split

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added that here

Снимок экрана 2022-07-07 в 11 57 52

@VladLasitsa
Copy link
Contributor Author

@elasticmachine merge upstream

@VladLasitsa VladLasitsa requested a review from flash1293 July 7, 2022 12:35
@flash1293
Copy link
Contributor

Performance is much better, but it's still much slower than necessary. It's a recurring pattern, I found it in two places:

return [...new Set([...acc, ...allRowSeries])];

If you need to calculate something over a large array (like rows or all fields in a data view), do not use reduce and spread an accumulator collection (array or set) into a new way to prevent mutation. Instead either use map or forEach and mutate a singe collection in the outer closure of the function. If this is not than, it has an squared complexity over the number of entries in the array (see #135792) which can make the code run for a very long time for large arrays (which do occur in the wild - I've seen cases with 50k rows in a single table and 600k fields in a single data view).

It doesn't matter much for quick smoke tests with a few hundred data points at max, but it's very important to keep this in mind

@VladLasitsa
Copy link
Contributor Author

Performance is much better, but it's still much slower than necessary. It's a recurring pattern, I found it in two places:

return [...new Set([...acc, ...allRowSeries])];

If you need to calculate something over a large array (like rows or all fields in a data view), do not use reduce and spread an accumulator collection (array or set) into a new way to prevent mutation. Instead either use map or forEach and mutate a singe collection in the outer closure of the function. If this is not than, it has an squared complexity over the number of entries in the array (see #135792) which can make the code run for a very long time for large arrays (which do occur in the wild - I've seen cases with 50k rows in a single table and 600k fields in a single data view).

It doesn't matter much for quick smoke tests with a few hundred data points at max, but it's very important to keep this in mind

Got it. Changed reduce to forEach

@VladLasitsa
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293
Copy link
Contributor

flash1293 commented Jul 11, 2022

When using a multi field top values in Lens for breakdown, the legend filter actions aren't shown anymore (filtering by clicking in the chart doesn't work as well)

@VladLasitsa
Copy link
Contributor Author

When using a multi field top values in Lens for breakdown, the legend filter actions aren't shown anymore (filtering by clicking in the chart doesn't work as well)

Fixed

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested and everything seems to work well now, LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

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
expressionXY 102.6KB 103.3KB +753.0B
lens 1.2MB 1.2MB +1.0B
total +754.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressionXY 32.8KB 32.8KB +20.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @VladLasitsa

@VladLasitsa VladLasitsa merged commit f42fce3 into elastic:main Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:XYAxis XY-Axis charts (bar, area, line) release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.4.0 WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants