-
Notifications
You must be signed in to change notification settings - Fork 121
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
fix(annotations): fix alignment at the edges #641
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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
1859c36
to
ff4120d
Compare
There was a problem hiding this 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
58f78a8
to
85917d8
Compare
There was a problem hiding this 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.
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.
src/chart_types/xy_chart/annotations/line/dimensions.integration.test.ts
Show resolved
Hide resolved
@@ -352,8 +330,7 @@ export function computeLineAnnotationDimensions( | |||
axisPosition, | |||
chartDimensions, | |||
lineColor, | |||
xScaleOffset, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts
Show resolved
Hide resolved
src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts
Show resolved
Hide resolved
// allow picking up the last spec added as the top most or use it's zIndex value | ||
const zIndexSortedSpecs = annotationSpecs | ||
.slice() | ||
.reverse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is reverse
requried?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
const zIndexSortedSpecs = annotationSpecs | |
const sortedSpecs = annotationSpecs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed here: 32dbf1f
# [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.
🎉 This PR is included in version 19.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [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.
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 they1
value refers to the maximum value of the y domain.fix #586
Checklist
Delete any items that are not applicable to this PR.