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: outside rect annotation placement and group relations #2471

Merged
merged 11 commits into from
Jun 24, 2024

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Jun 23, 2024

Summary

This PR fixes an issue with RectAnnotation when defined as outside. Now all outside RectAnnotations render correctly within their respective Axis.

Zight Recording 2024-06-23 at 03 48 12 PM

Details

This prop is meant to render the annotation outside of the chart in the axis area, however this only works when there is an arbitrary groupId applied, because this would cause the yScale to be undefined as if it's the same case as fixed in #842.

This was due to a combination of errors in the logic. First was the missing rotation when looking up the axis specs here...

const { xAxis, yAxis } = getAxesSpecForSpecId(axesSpecs, groupId);

This would provide wrong axis for the given annotation. I have now made the rotation argument required to avoid this error in the future.

Secondly, the logic to determine the placement dimensions of the outside annotation was extremely limiting for all cases particularly related to chart rotations.

const isLeftSide =
(chartRotation === 0 && xAxis?.position === Position.Bottom) ||
(chartRotation === 180 && xAxis?.position === Position.Top) ||
(chartRotation === -90 && yAxis?.position === Position.Right) ||
(chartRotation === 90 && yAxis?.position === Position.Left);

This was fixed by factoring in each case for rotation and domain, as is done for the LineAnnotation markers.

Issues

fixes #2470

Checklist

  • The proper chart type label has been added (e.g. :xy, :partition)
  • The proper feature labels have been added (e.g. :interactions, :axis)
  • All related issues have been linked (i.e. closes #123, fixes #123)
  • New public API exports have been added to packages/charts/src/index.ts
  • Unit tests have been added or updated to match the most common scenarios
  • The proper documentation and/or storybook story has been added or updated

@nickofthyme nickofthyme added :annotation Annotation (line, rect, text) related issue :xy Bar/Line/Area chart related labels Jun 23, 2024
@@ -40,7 +43,7 @@ export function computeRectAnnotationDimensions(
isHistogram: boolean = false,
): AnnotationRectProps[] | null {
const { dataValues, groupId, outside, id: annotationSpecId } = annotationSpec;
const { xAxis, yAxis } = getAxesSpecForSpecId(axesSpecs, groupId);
const { xAxis, yAxis } = getAxesSpecForSpecId(axesSpecs, groupId, chartRotation);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed to match to correct axis

Comment on lines +104 to +108
if (outside) {
if (hasXValues && hasYValues) {
Logger.warn(
`The RectAnnotation (${annotationSpecId}) was defined as outside but has both x and y values defined.`,
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Warns when attempting to render annotation as outside but both x and y coordinates are defined. The outside annotation should be limited to a single axis. Renders inside as fallback to avoid not rendering at all.

@nickofthyme
Copy link
Collaborator Author

buildkite update screenshots

@nickofthyme
Copy link
Collaborator Author

buildkite update screenshots

@nickofthyme nickofthyme marked this pull request as ready for review June 24, 2024 14:50
@nickofthyme nickofthyme changed the title fix: outside rect annotation when used without groupId fix: outside rect annotation placement and group relations Jun 24, 2024
@nickofthyme nickofthyme merged commit d46fb41 into elastic:main Jun 24, 2024
14 checks passed
@nickofthyme nickofthyme deleted the fix-outside-rect-anno branch June 24, 2024 15:51
nickofthyme pushed a commit that referenced this pull request Jun 24, 2024
## [66.0.4](v66.0.3...v66.0.4) (2024-06-24)

### Bug Fixes

* **deps:** update dependency @elastic/eui to v95 ([#2462](#2462)) ([040c354](040c354))
* option to disable the isolated point styles on line and area charts ([#2472](#2472)) ([ae16815](ae16815))
* outside rect annotation placement and group relations ([#2471](#2471)) ([d46fb41](d46fb41))
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 :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defining a RectAnnotation as outside has not affect
1 participant