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

fix(annotations): fix alignment at the edges #641

Merged
merged 9 commits into from
Apr 28, 2020

Conversation

markov00
Copy link
Member

Summary

This commit fixed the alignment of rect and line annotations near the edge of a data domain. It
aligns the x/y position specified by the dataValues of the annotation to the domain of the chart.

BREAKING CHANGE: In the rectangular annotation, the y0 parameter of the coordinates now refers to the minimum value and the y1 value refers to the maximum value of the y domain.

fix #586

Checklist

Delete any items that are not applicable to this PR.

  • Unit tests were updated or added to match the most common scenarios

@markov00 markov00 added bug Something isn't working :annotation Annotation (line, rect, text) related issue labels Apr 21, 2020
@markov00 markov00 requested review from nickofthyme and rshen91 April 21, 2020 13:17
@markov00 markov00 marked this pull request as draft April 21, 2020 16:06
@codecov-io
Copy link

codecov-io commented Apr 24, 2020

Codecov Report

Merging #641 into master will increase coverage by 0.31%.
The diff coverage is 87.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #641      +/-   ##
==========================================
+ Coverage   72.43%   72.74%   +0.31%     
==========================================
  Files         247      264      +17     
  Lines        8184     8487     +303     
  Branches     1605     1655      +50     
==========================================
+ Hits         5928     6174     +246     
- Misses       2223     2275      +52     
- Partials       33       38       +5     
Impacted Files Coverage Δ
src/chart_types/xy_chart/legend/legend.ts 84.61% <ø> (-0.39%) ⬇️
...ypes/xy_chart/renderer/canvas/annotations/index.ts 30.00% <ø> (ø)
...ypes/xy_chart/renderer/canvas/annotations/lines.ts 25.00% <ø> (ø)
...types/xy_chart/renderer/canvas/annotations/rect.ts 23.52% <ø> (ø)
..._types/xy_chart/renderer/canvas/primitives/rect.ts 5.35% <ø> (ø)
.../chart_types/xy_chart/renderer/canvas/xy_chart.tsx 86.30% <ø> (ø)
src/chart_types/xy_chart/utils/specs.ts 100.00% <ø> (ø)
src/scales/index.ts 100.00% <ø> (ø)
src/chart_types/xy_chart/annotations/tooltip.ts 64.70% <64.70%> (ø)
src/mocks/specs/specs.ts 74.71% <79.16%> (ø)
... and 43 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f411771...4f3e295. Read the comment docs.

This commit fixed the alignment of rect and line annotations near the edge of a data domain. It
aligns the x/y position specified by the dataValues of the annotation to the domain of the chart.

BREAKING CHANGE: In the rectangular annotation, the `y0` parameter of the coordinates now refers to
the minimum value and the `y1` value refers to the maximum value of the y domain. Previously, this
was the opposite.

fix elastic#586
@markov00 markov00 force-pushed the 2020_04_09-fix_annotations_extent branch from 1859c36 to ff4120d Compare April 24, 2020 16:45
@markov00 markov00 marked this pull request as ready for review April 27, 2020 15:19
Copy link
Contributor

@rshen91 rshen91 left a comment

Choose a reason for hiding this comment

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

This looks awesome! Tested the storybook locally on Chrome. Awesome addition of mock tests

@markov00 markov00 force-pushed the 2020_04_09-fix_annotations_extent branch from 58f78a8 to 85917d8 Compare April 28, 2020 12:30
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Code changes look good, just a few comments nothing blocking.

Verified storybook stories/playground in Chrome, Firefox and IE11.

Confirmed original issue is fixed with these changes.

Screen Recording 2020-04-28 at 09 23 AM

One thing I still don't like is that rect annotations really only coexist with the Follow tooltip, any others the normal tooltip takes over. I think we should look into this with the tooltip redesign.

Screen Recording 2020-04-28 at 09 15 AM

@@ -352,8 +330,7 @@ export function computeLineAnnotationDimensions(
axisPosition,
chartDimensions,
lineColor,
xScaleOffset,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this offset no longer used?

Copy link
Member Author

Choose a reason for hiding this comment

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

we compute the xScaleOffset internally, from the scale, we don't need anymore to pass it from the outside

// allow picking up the last spec added as the top most or use it's zIndex value
const zIndexSortedSpecs = annotationSpecs
.slice()
.reverse()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is reverse requried?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not required, I think we should think about that more broadly in the future.
I'm reversing the array because if I write a chart configuration like

<RectAnnotation dataValues={dataValuesGreen} id="rect3" style={{ fill: 'green' }} />
<RectAnnotation dataValues={dataValuesBlue} id="rect2" style={{ fill: 'blue' }} />
<RectAnnotation dataValues={dataValuesRed} id="rect1" style={{ fill: 'red' }} />

where I want to have the green on the back, and blue and red on top. My personal preference here is, when writing the spec, the first spec on the top will be rendered first, following a top-down => background->foreground order.

On the tooltip instead, I need to pick up the topmost rendered annotation (the red in our example), that is the last rendered. If I start traversing the annotationSpecs array in the "original" order and the green annotation is large enough to cover fully the chart, that the first annotation picked up by that algorithm is the green one.
Reversing it, I have the possibility to pick up the red as the first available annotation.

I know, this is for sure a naive approach, we can find a better way to handle that

chartDimensions: Dimensions,
): AnnotationTooltipState | null {
// allow picking up the last spec added as the top most or use it's zIndex value
const zIndexSortedSpecs = annotationSpecs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we don't really care how these are sorted in the variable name.

Suggested change
const zIndexSortedSpecs = annotationSpecs
const sortedSpecs = annotationSpecs

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed here: 32dbf1f

src/chart_types/xy_chart/annotations/tooltip.ts Outdated Show resolved Hide resolved
src/mocks/store/store.ts Show resolved Hide resolved
@markov00 markov00 merged commit 43c5a59 into elastic:master Apr 28, 2020
@markov00 markov00 deleted the 2020_04_09-fix_annotations_extent branch April 28, 2020 16:47
markov00 pushed a commit that referenced this pull request Apr 28, 2020
# [19.0.0](v18.4.2...v19.0.0) (2020-04-28)

### Bug Fixes

* tooltip container scroll issue ([#647](#647)) ([f411771](f411771))
* **annotations:** fix alignment at the edges ([#641](#641)) ([43c5a59](43c5a59)), closes [#586](#586)

### Features

* shift click legend items & partition legend hover ([#648](#648)) ([ed91744](ed91744))
* **brush:** add multi axis brushing ([#625](#625)) ([9e49534](9e49534)), closes [#587](#587) [#620](#620)

### BREAKING CHANGES

* **brush:** The type used by the `BrushEndListener` is now in the following form `{ x?: [number, number]; y?: Array<{ groupId: GroupId; values: [number,
number]; }> }` where `x` contains an array of `[min, max]` values, and the  `y` property is an optional array of objects, containing the `GroupId` and the values of the brush for that specific axis.
* **annotations:** In the rectangular annotation, the y0 parameter of the coordinates now refers to the minimum value and the y1 value refers to the maximum value of the y domain.
@markov00
Copy link
Member Author

🎉 This PR is included in version 19.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Apr 28, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [19.0.0](elastic/elastic-charts@v18.4.2...v19.0.0) (2020-04-28)

### Bug Fixes

* tooltip container scroll issue ([opensearch-project#647](elastic/elastic-charts#647)) ([f0af34b](elastic/elastic-charts@f0af34b))
* **annotations:** fix alignment at the edges ([opensearch-project#641](elastic/elastic-charts#641)) ([c698d08](elastic/elastic-charts@c698d08)), closes [opensearch-project#586](elastic/elastic-charts#586)

### Features

* shift click legend items & partition legend hover ([opensearch-project#648](elastic/elastic-charts#648)) ([cf15ca1](elastic/elastic-charts@cf15ca1))
* **brush:** add multi axis brushing ([opensearch-project#625](elastic/elastic-charts#625)) ([382cb14](elastic/elastic-charts@382cb14)), closes [opensearch-project#587](elastic/elastic-charts#587) [opensearch-project#620](elastic/elastic-charts#620)

### BREAKING CHANGES

* **brush:** The type used by the `BrushEndListener` is now in the following form `{ x?: [number, number]; y?: Array<{ groupId: GroupId; values: [number,
number]; }> }` where `x` contains an array of `[min, max]` values, and the  `y` property is an optional array of objects, containing the `GroupId` and the values of the brush for that specific axis.
* **annotations:** In the rectangular annotation, the y0 parameter of the coordinates now refers to the minimum value and the y1 value refers to the maximum value of the y domain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:annotation Annotation (line, rect, text) related issue bug Something isn't working released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotation does not cover all of x-axis
4 participants