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(annotation): annotation rendering with no yDomain or groupId #842

Merged
merged 19 commits into from
Oct 12, 2020

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Oct 1, 2020

Summary

Fixes #438 and #798 where <Annotations /> were not shown in cases where they should be.

  • The below story shows <Annotations /> when the y domain is [0, 0] or spans only one value (domain fit is true). In these cases, annotations will now take the chartDimension height:

PR842_zero

  • The below story shows <Annotations /> rendering on the x axis if there is no provided group Id. If there is no group id provided and two y axes, the annotation will not still not show and this behavior is expected since the annotation will not know what y axis to mount onto:

PR842_group

Stories (Zero Domain and With Group Id) are added in Annotations -> Rect section in storybook.

Checklist

Delete any items that are not applicable to this PR.

  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

@rshen91 rshen91 added bug Something isn't working :annotation Annotation (line, rect, text) related issue labels Oct 1, 2020
@codecov-commenter
Copy link

Codecov Report

Merging #842 into master will increase coverage by 0.40%.
The diff coverage is 76.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #842      +/-   ##
==========================================
+ Coverage   70.01%   70.41%   +0.40%     
==========================================
  Files         319      334      +15     
  Lines       10474    10767     +293     
  Branches     2221     2266      +45     
==========================================
+ Hits         7333     7582     +249     
- Misses       3132     3170      +38     
- Partials        9       15       +6     
Flag Coverage Δ
#unittests 69.91% <76.19%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...hart_types/xy_chart/annotations/rect/dimensions.ts 89.13% <75.00%> (-0.03%) ⬇️
src/chart_types/xy_chart/annotations/utils.ts 100.00% <100.00%> (ø)
src/utils/d3-delaunay/index.ts 48.69% <0.00%> (-1.49%) ⬇️
src/mocks/series/series_identifiers.ts 100.00% <0.00%> (ø)
src/mocks/geometries.ts 86.84% <0.00%> (ø)
src/mocks/series/data.ts 100.00% <0.00%> (ø)
src/mocks/store/index.ts 100.00% <0.00%> (ø)
src/mocks/series/index.ts 100.00% <0.00%> (ø)
src/mocks/series/series.ts 88.13% <0.00%> (ø)
src/mocks/utils.ts 100.00% <0.00%> (ø)
... and 9 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 4186962...2f51cdb. Read the comment docs.

@codecov-io
Copy link

codecov-io commented Oct 6, 2020

Codecov Report

Merging #842 into master will increase coverage by 0.55%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #842      +/-   ##
==========================================
+ Coverage   70.01%   70.56%   +0.55%     
==========================================
  Files         321      336      +15     
  Lines       10508    10801     +293     
  Branches     2221     2182      -39     
==========================================
+ Hits         7357     7622     +265     
- Misses       3142     3164      +22     
- Partials        9       15       +6     
Flag Coverage Δ
#unittests 70.06% <95.23%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...es/xy_chart/state/selectors/compute_annotations.ts 100.00% <ø> (ø)
...hart_types/xy_chart/annotations/rect/dimensions.ts 91.30% <95.00%> (+2.14%) ⬆️
src/chart_types/xy_chart/annotations/utils.ts 100.00% <100.00%> (ø)
src/mocks/theme.ts 100.00% <0.00%> (ø)
src/mocks/specs/specs.ts 82.75% <0.00%> (ø)
src/mocks/series/index.ts 100.00% <0.00%> (ø)
src/mocks/utils.ts 100.00% <0.00%> (ø)
src/mocks/series/utils.ts 100.00% <0.00%> (ø)
src/mocks/geometries.ts 86.84% <0.00%> (ø)
src/mocks/specs/index.ts 100.00% <0.00%> (ø)
... and 9 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 66e1311...63a2df1. Read the comment docs.

@rshen91 rshen91 marked this pull request as ready for review October 6, 2020 21:15
@rshen91 rshen91 changed the title fix: annotation rendering with chartDimension.height fix: annotation rendering with no yDomain Oct 7, 2020
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.

LGTM, I just made a few minor comments to fix before merging.

@@ -92,6 +92,7 @@ describe('annotation utils', () => {
showOverlappingLabels: false,
position: Position.Left,
style,
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 63a2df1

@@ -105,6 +106,7 @@ describe('annotation utils', () => {
showOverlappingLabels: false,
position: Position.Bottom,
style,
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope 😅 ! 63a2df1

@@ -38,7 +38,6 @@ export const computeAnnotationDimensionsSelector = createCachedSelector(
computeSeriesGeometriesSelector,
getAxisSpecsSelector,
isHistogramModeEnabledSelector,
getAxisSpecsSelector,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines -34 to -41
/** @internal */
export interface BrushExtent {
minX: number;
minY: number;
maxX: number;
maxY: number;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

Comment on lines 301 to 321
it('annotation with group id should render with x0 and x1 values', () => {
const store = MockStore.default({ top: 0, left: 0, width: 20, height: 200 });
const settings = MockGlobalSpec.settingsNoMargins();
const annotation = MockAnnotationSpec.rect({
groupId: 'group1',
dataValues: [{ coordinates: { x0: 2, x1: 4 } }],
});
const bar = MockSeriesSpec.bar({
data: [
{ x: 1, y: 0 },
{ x: 2, y: 5 },
{ x: 4, y: 10 },
],
});
MockStore.addSpecs([settings, annotation, bar], store);
const expected = computeAnnotationDimensionsSelector(store.getState());
const [resultAnnotation] = expected.get('rect_annotation_1') ?? [];
expect(resultAnnotation).toMatchObject({
rect: { height: 200 },
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could make these more explicit that the expected value is the height being passed.

Suggested change
it('annotation with group id should render with x0 and x1 values', () => {
const store = MockStore.default({ top: 0, left: 0, width: 20, height: 200 });
const settings = MockGlobalSpec.settingsNoMargins();
const annotation = MockAnnotationSpec.rect({
groupId: 'group1',
dataValues: [{ coordinates: { x0: 2, x1: 4 } }],
});
const bar = MockSeriesSpec.bar({
data: [
{ x: 1, y: 0 },
{ x: 2, y: 5 },
{ x: 4, y: 10 },
],
});
MockStore.addSpecs([settings, annotation, bar], store);
const expected = computeAnnotationDimensionsSelector(store.getState());
const [resultAnnotation] = expected.get('rect_annotation_1') ?? [];
expect(resultAnnotation).toMatchObject({
rect: { height: 200 },
});
});
it('annotation with group id should render with x0 and x1 values', () => {
const height = 200;
const store = MockStore.default({ top: 0, left: 0, width: 20, height });
const settings = MockGlobalSpec.settingsNoMargins();
const annotation = MockAnnotationSpec.rect({
groupId: 'group1',
dataValues: [{ coordinates: { x0: 2, x1: 4 } }],
});
const bar = MockSeriesSpec.bar({
data: [
{ x: 1, y: 0 },
{ x: 2, y: 5 },
{ x: 4, y: 10 },
],
});
MockStore.addSpecs([settings, annotation, bar], store);
const expected = computeAnnotationDimensionsSelector(store.getState());
const [resultAnnotation] = expected.get('rect_annotation_1') ?? [];
expect(resultAnnotation).toMatchObject({
rect: { height },
});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! Makes sense to make this explicit and clear that it's the same as the chartStore height - addressed in 63a2df1

@rshen91 rshen91 merged commit f173b49 into master Oct 12, 2020
@rshen91 rshen91 deleted the annotations-wip branch October 12, 2020 16:38
@rshen91 rshen91 changed the title fix: annotation rendering with no yDomain fix(annotation): annotation rendering with no yDomain or groupId Oct 12, 2020
markov00 pushed a commit that referenced this pull request Oct 19, 2020
# [24.0.0](v23.2.1...v24.0.0) (2020-10-19)

### Bug Fixes

* **annotation:** annotation rendering with no yDomain or groupId ([#842](#842)) ([f173b49](f173b49)), closes [#438](#438) [#798](#798)

### Features

* **bar_chart:** add Alignment offset to value labels ([#784](#784)) ([363aeb4](363aeb4))
* **bar_chart:** add shadow prop for value labels ([#785](#785)) ([9b29392](9b29392))
* **bar_chart:** scaled font size for value labels ([#789](#789)) ([3bdd1ee](3bdd1ee)), closes [#788](#788)
* **heatmap:** allow fixed right margin ([#873](#873)) ([16cf73c](16cf73c))

### BREAKING CHANGES

* **bar_chart:** The `DisplayValueStyle` `fontSize` property can now express an upper and lower bound as size, used for the automatic scaling.
* **bar_chart:** The `DisplayValueStyle` `fill` property can now express a border color and width, or let the library pick the best match based on contrast using the textInvertible parameter.
@markov00
Copy link
Member

🎉 This PR is included in version 24.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Oct 19, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [24.0.0](elastic/elastic-charts@v23.2.1...v24.0.0) (2020-10-19)

### Bug Fixes

* **annotation:** annotation rendering with no yDomain or groupId ([opensearch-project#842](elastic/elastic-charts#842)) ([6bad0d7](elastic/elastic-charts@6bad0d7)), closes [opensearch-project#438](elastic/elastic-charts#438) [opensearch-project#798](elastic/elastic-charts#798)

### Features

* **bar_chart:** add Alignment offset to value labels ([opensearch-project#784](elastic/elastic-charts#784)) ([106d924](elastic/elastic-charts@106d924))
* **bar_chart:** add shadow prop for value labels ([opensearch-project#785](elastic/elastic-charts#785)) ([de95b44](elastic/elastic-charts@de95b44))
* **bar_chart:** scaled font size for value labels ([opensearch-project#789](elastic/elastic-charts#789)) ([8b74a9d](elastic/elastic-charts@8b74a9d)), closes [opensearch-project#788](elastic/elastic-charts#788)
* **heatmap:** allow fixed right margin ([opensearch-project#873](elastic/elastic-charts#873)) ([dd34574](elastic/elastic-charts@dd34574))

### BREAKING CHANGES

* **bar_chart:** The `DisplayValueStyle` `fontSize` property can now express an upper and lower bound as size, used for the automatic scaling.
* **bar_chart:** The `DisplayValueStyle` `fill` property can now express a border color and width, or let the library pick the best match based on contrast using the textInvertible parameter.
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.

Annotations should be able to handle scenarios where the min value matches the max value of the dataset
5 participants