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

[Lens] Multiple y axes #69911

Merged
merged 15 commits into from
Jul 1, 2020
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Jun 25, 2020

Fixes #53663
Fixes #68260

This PR adds the ability to configure two separate y axes in XY charts.

Screenshot 2020-06-26 at 14 32 11

Screenshot 2020-06-26 at 14 34 16

These changes are limited to the xy visualization, expect for one small fix in x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx - there is a flag enableDimensionEditor on the dimension group whether to show a second visualization-controlled tab in the dimension editor, but it wasn't used to actually determine whether to show the editor or not.

Axis assignment

The process of assigning metric to axes follows this algorithm:

  • Split up all metrics by their type (auto/left/right) - this results in three lists
  • Move all "auto" metrics to either left or right:
    • If a metrics formatter is compatible with all formatters of other left axis metrics, it becomes a left axis metric
    • If a metrics formatter is compatible with all formatters of other right axis metrics, it becomes a right axis metric
    • Otherwise it will be added to whatever axis has fewer metrics assigned
  • If the left/right axis list is not empty, take the formatter of the first metric in the list as the formatter for the axis
  • Assign all metrics of the left/right axis list to the same group

A formatter is compatible if it has the same type, e.g. number or bytes.

There are other ways of handling this (e.g. displaying multiple axes on a single side if the formatters don't match), but all approaches (including the chosen one) have non-optimal edge cases. These can only be really fixed by providing a more sophisticated way of editing axes which would be out of scope for this PR. We can add this in a later iteration by providing a separate axis management menu in the toolbar.

Subtle changes

  • Prior to this, an axis with non-matching formatters would simply fall back to a plain number formatter. This is confusing in a lot of cases (e.g. [Lens] Field Formatters not working for multiple layers #68260), so this PR changes the logic by just using the first one if the case can't be solved by using two y axes
  • There is a separate yTitle and xTitle argument on the expression to label the axes - so far xTitle was only used when there was no column name provided by the data source (never in practice). As we can have multiple y axes now as well, by default the names of the participating columns are used, with the yTitle as fallback (like it's happening for xTitle).

Expression integration

Currently y axis series are specified by listing out the columns in the accessors argument. To stay compatible with previous versions and not introduce too much new structure, this PR simply adds an yAxisConfiguration argument that can be specified multiple times, setting the axis mode to either left, right or auto. As long as the user didn't select anything, no state is written and "auto" mode is assumed. If the user manually picks an axis mode, a lens_xy_yAxisConfiguration sub-expression is added:

lens_xy_chart {...} yConfig={lens_xy_yConfig forAccessor="a" axisMode="right"}

Related to that: In x-pack/plugins/lens/public/xy_visualization/types.ts there were expression functions for YState and XConfig which were unused, I removed them as part of this PR.

lens_xy_yConfig can be extended later to add things like metric color overrides.

elastic-charts integration

To use multiple axes, they have to be defined with a groupId, then series can be mapped to them by specifying the same groupId. Currently there is a single series element in the spec for each layer, but it's possible to have a single layer mapped to different axes. This PR makes this possible, by splitting up each layer for each y accessor, keeping all other properties the same except for the group id which is mapped for each accessor individually. That changes existing specs with more than one metric (e.g. turning one LineSeries element into multiple ones).

@flash1293 flash1293 marked this pull request as ready for review June 26, 2020 17:57
@flash1293 flash1293 requested a review from a team June 26, 2020 17:57
@flash1293 flash1293 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Jun 26, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

So far I've tested the behavior, and it's looking promising. Did something change with the way we do axis titles in this PR? I'm noticing the comma-separated titles more.

Will review code next week.

@mbondyra
Copy link
Contributor

@elasticmachine merge upstream

@flash1293
Copy link
Contributor Author

@wylieconlon I added this logic, but as you are mentioning it I remembered we chose to only use the first series as label here to avoid overly long axis labels. Rolled back that change

@mbondyra Renamed the expression functions so we can add colors in there as well. Also, I fixed the bug with the unformatted value in the tooltip.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

tested on Firefox, it works great! Code looks good to me!

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Overall LGTM, thanks for making those changes!

@@ -276,6 +276,9 @@ export function XYChart({
legendPosition={legend.position}
showLegendExtra={false}
theme={chartTheme}
tooltip={{
headerFormatter: (d) => xAxisFormatter.convert(d.value),
Copy link
Contributor

Choose a reason for hiding this comment

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

This does of course fail if there are non-matching types on the X axis, but I think we can't fix that case.

@flash1293 flash1293 merged commit e1665e8 into elastic:master Jul 1, 2020
flash1293 added a commit to flash1293/kibana that referenced this pull request Jul 1, 2020
flash1293 added a commit that referenced this pull request Jul 1, 2020
Bamieh pushed a commit to Bamieh/kibana that referenced this pull request Jul 1, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 1, 2020
…-based-rbac

* upstream/master: (38 commits)
  Move logger configuration integration test to jest (elastic#70378)
  Changes observability plugin codeowner (elastic#70439)
  update (elastic#70424)
  [Logs UI] Avoid CCS-incompatible index name resolution (elastic#70179)
  Enable "Explore underlying data" actions for Lens visualizations (elastic#70047)
  Initial work on uptime homepage API (elastic#70135)
  expressions indexPattern function (elastic#70315)
  [Discover] Deangularization context error message refactoring (elastic#70090)
  [Lens] Add "no data" popover (elastic#69147)
  [Lens] Move chart switcher over (elastic#70182)
  chore: add missing mjs extension (elastic#70326)
  [Lens] Multiple y axes (elastic#69911)
  skip flaky suite (elastic#70386)
  fix bug to add timeline to case (elastic#70343)
  [QA][Code Coverage] Drop catchError and use try / catch instead, (elastic#69198)
  [QA] [Code Coverage] Integrate with Team Assignment Pipeline and Add Research and Development Indexes and Cluster (elastic#69348)
  [Metrics UI] Add context.reason and alertOnNoData to Inventory alerts (elastic#70260)
  Resolver refactoring (elastic#70312)
  [Ingest Manager] Fix agent ack after input format change (elastic#70335)
  [eslint][ts] Enable prefer-ts-expect-error (elastic#70022)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.9.0 v8.0.0
Projects
None yet
5 participants