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] Usable reference lines for xyVis. #132192

Merged

Conversation

Kuznietsov
Copy link
Contributor

Summary

Closes part of the issue.
Added referenceLine expression, which is usable for users. It enables the possibility to provide static value for the reference line at the xyVis expression function.

Example

kibana
| selectFilter
| demodata
| tail 10
| xyVis seriesType="line" xAccessor="@timestamp" accessors="price" 
  referenceLines={referenceLine value=10 color="rgba(101, 232, 89, 0.5)" icon="asterisk" fill="below" } 
  referenceLines={referenceLine value=60 icon="bolt" color="blue" fill="above" }
| render

Usage

Screenshot 2022-05-13 at 15 14 28

@Kuznietsov Kuznietsov added the WIP Work in progress label May 13, 2022
@Kuznietsov Kuznietsov self-assigned this May 13, 2022
@Kuznietsov Kuznietsov mentioned this pull request May 13, 2022
31 tasks
# Conflicts:
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/layered_xy_vis.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts
# Conflicts:
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/common_reference_line_layer_args.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/extended_reference_line_layer.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/reference_line_layer.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts
#	src/plugins/chart_expressions/expression_xy/common/types/expression_functions.ts
@Kuznietsov Kuznietsov added loe:medium Medium Level of Effort Team:Visualizations Visualization editors, elastic-charts and infrastructure release_note:skip Skip the PR/issue when compiling release notes impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. backport:skip This commit does not require backporting NeededFor:Canvas Feature:Canvas labels May 16, 2022
@kibanamachine kibanamachine added the Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas label May 16, 2022
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

Copy link
Contributor

@mdefazio mdefazio left a comment

Choose a reason for hiding this comment

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

Just seeing a file rename. 👍

# Conflicts:
#	packages/kbn-optimizer/limits.yml
# Conflicts:
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts
#	src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts
@flash1293
Copy link
Contributor

High level feedback: It seems like this change is only relevant for being able to conveniently place reference lines via expression, but the change propagates through to the actual elastic-charts spec too, including some duplication of logic in reference_line vs reference_line_layer. It seems like we can avoid this additional complexity by absorbing the difference of "reference line layer" vs "reference line" on the expression level by creating the same context structure for both "types" of reference lines (which would involve creating a dummy table for the single value but that doesn't seem like a big problem). This will make it easier to keep the behavior of the reference lines in the charts identical (I'm concerned in the current structure a lot of changes would have to be done in two places but it's very easy to miss one of them) and also reduce the amount of redundant code, making it easier to understand what's going on.

@Kuznietsov
Copy link
Contributor Author

High level feedback: It seems like this change is only relevant for being able to conveniently place reference lines via expression, but the change propagates through to the actual elastic-charts spec too, including some duplication of logic in reference_line vs reference_line_layer. It seems like we can avoid this additional complexity by absorbing the difference of "reference line layer" vs "reference line" on the expression level by creating the same context structure for both "types" of reference lines (which would involve creating a dummy table for the single value but that doesn't seem like a big problem). This will make it easier to keep the behavior of the reference lines in the charts identical (I'm concerned in the current structure a lot of changes would have to be done in two places but it's very easy to miss one of them) and also reduce the amount of redundant code, making it easier to understand what's going on.

@flash1293, on the other hand, I can't agree with such a point of view. Here are some arguments for the current solution and against merging those two logics:

  1. We can simplify the understanding experience for developers by splitting the logic into different logical blocks with individual behavior. If the output of the expression is simple, and it is used directly at the component without any magic logic of looking for some value at some synthetic datatable. "Merging" logics of the components, which have different natures and structures is increasing the complexity. I'm talking mostly about this accessors -> yConfig.forAccessor logic and the other magic of this implementation.
  2. I'm sure, there will be a point, at which those two logics will be separated and will go on their own roads. Len's one will be supporting a lot of Lens internal logic, which will be not reproducible from the Canvas (the question of a couple of versions). So, it is better to keep them separated from each other because they are not the same at all. The only common thing there is the elastic-charts components and their configuration.
  3. For the purpose of avoiding missing some features, all the configuration of the elastic-charts was unified.
    WDYT?

@flash1293
Copy link
Contributor

I'm sure, there will be a point, at which those two logics will be separated and will go on their own roads. Len's one will be supporting a lot of Lens internal logic, which will be not reproducible from the Canvas (the question of a couple of versions). So, it is better to keep them separated from each other because they are not the same at all

I don't agree with this view - the point of a unified renderer is to keep it aligned in terms of features and code. Branching out into different implementations should be avoided as much as possible and in the current state I'm seeing a bunch of opportunities to avoid branching. For example the files src/plugins/chart_expressions/expression_xy/public/components/reference_lines/reference_line_layer.tsx and src/plugins/chart_expressions/expression_xy/public/components/reference_lines/reference_line.tsx are very similar with the biggest difference being the way the data and config is passed in (table vs value, single y config vs multiple y configs) together with shared bits like calling helper functions in the exact same way and configuring the elastic-chart spec elements in the same way (with duplicated constants like styling) - it seems like one is a special case of the other.

@flash1293
Copy link
Contributor

Breaks Lens:
Screenshot 2022-05-19 at 17 54 41

In terms of inspector integration reference layers are similar to regular data layers and they should be reported in the same way.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
expressionXY 94 98 +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressionXY 128 129 +1
lens 457 459 +2
total +3

Async chunks

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

id before after diff
expressionXY 73.9KB 75.0KB +1.1KB
lens 1.2MB 1.2MB -8.0B
total +1.1KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
expressionXY 13 14 +1

Page load bundle

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

id before after diff
expressionXY 30.0KB 31.6KB +1.7KB
Unknown metric groups

API count

id before after diff
expressionXY 138 139 +1
lens 532 534 +2
total +3

History

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

cc @Kunzetsov

@Kuznietsov
Copy link
Contributor Author

Kuznietsov commented May 19, 2022

Breaks Lens: Screenshot 2022-05-19 at 17 54 41

In terms of inspector integration reference layers are similar to regular data layers and they should be reported in the same way.

@flash1293, sure, sorry, that is a merge conflict resolving problem... Will fix it today

@flash1293, I fill like you should restart your kibana.

Screenshot 2022-05-19 at 20 59 01

Screenshot 2022-05-19 at 21 00 40

@flash1293
Copy link
Contributor

Tested around and from what I can tell this works really well. One thing I noticed - the standalone reference lines do not try to do the segmenting if they color into the same direction: https://github.com/elastic/kibana/pull/132192/files#diff-f588e9251dfe7febff5c66997c7f3acbcfbd16e41f0d123109cabeef96fb21bdR64

This results in overlapping colors:
Screenshot 2022-05-20 at 09 20 50
Screenshot 2022-05-20 at 09 16 57

What about adopting the same logic of the reference line layer for all standalone reference lines? It's a neat use case to be able to color the areas in the same direction to create "sections" in the chart.

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.

Approving to not block the PR

@Kuznietsov
Copy link
Contributor Author

@flash1293, I'll add the feature you've mentioned at the follow-up PR. Thanks for the really good point. I've totally missed it 😃

@Kuznietsov Kuznietsov merged commit 3982bfd into elastic:main May 20, 2022
@Kuznietsov Kuznietsov removed the WIP Work in progress label May 20, 2022
j-bennet pushed a commit to j-bennet/kibana that referenced this pull request Jun 2, 2022
* ReferenceLineLayer -> referenceLine.

* Added the referenceLine and splitted the logic at ReferenceLineAnnotations.

* Fixed formatters of referenceLines

* Added referenceLines keys.

* Added test for the referenceLine fn.

* Added some tests for reference_lines.

* Unified the two different approaches of referenceLines.

* Fixed types at tests and limits.
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:Canvas impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. loe:medium Medium Level of Effort release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants