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

accessibilityLayer should respect a reversed XAxis #4225

Merged
merged 13 commits into from Feb 29, 2024

Conversation

julianna-langston
Copy link
Contributor

@julianna-langston julianna-langston commented Feb 22, 2024

Description

The AccessibilityManager (which manages the behavior for the accessibilityLayer prop) will take into account if there is an <XAxis reversed={true} /> child. If so, the left/right arrow keys will reverse, so that they align with the chart's visuals.

Related Issue

#4214

Motivation and Context

How Has This Been Tested?

Tested manually, and added test cases

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • [NA] My change requires a change to the documentation.
  • [NA] I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • [NA] I have added a storybook story or extended an existing story to show my changes
  • All new and existing tests passed.

@julianna-langston
Copy link
Contributor Author

@ckifer I can't remember, should this target 3.x or master?

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up!

src/chart/generateCategoricalChart.tsx Outdated Show resolved Hide resolved
src/chart/generateCategoricalChart.tsx Outdated Show resolved Hide resolved
src/util/types.ts Outdated Show resolved Hide resolved
@ckifer
Copy link
Member

ckifer commented Feb 22, 2024

It could exist in both, if we want to backport it to 2.x as a bugfix I can release it in 2.12.2, I have something else to release as well

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM.

@PavelVanecek from an API perspective do you think reversed should exist on the base axis? Imo Z axis is a totally different category and shouldn't really share any props, but since they already do... Better to be on the individual components maybe?

@PavelVanecek
Copy link
Collaborator

I don't understand the purpose of reversed axis, any of them. If an axis is reversed then the whole chart should be reversed, no? So then I would do data={data.reverse()}, why separate prop?

@julianna-langston
Copy link
Contributor Author

julianna-langston commented Feb 24, 2024

It's for RTL languages (Arabic, hebrew, etc). The charts origin would be in the bottom right, rather than the bottom left.

@ckifer
Copy link
Member

ckifer commented Feb 24, 2024

Yeah +1. Can't just change your data order if we always assume you read left to right.

@julianna-langston I think we should move reversed to exist only on the XAxis. We don't need to support RTL vertically correct?

@julianna-langston
Copy link
Contributor Author

So, reversed already exists on the YAxis (as well as XAxis). I'm not trying to add it here... I was just getting typescript errors when I tried to rely on xAxisMap values having the reversed property, and I thought the type definitions were out of sync.

Since that change is going to leak into the ZAxus, I'll see if I can find another way to wrangle the types.

@ckifer
Copy link
Member

ckifer commented Feb 24, 2024

Lol oops my bad, I was thinking it was new.

Maybe we could type narrow somehow to the specific axis types. Imo all good to put TS-expect-error there for now so we know to fix it later

@PavelVanecek
Copy link
Collaborator

If it's for RTL reading should this be limited to xAxis only? Should we also revert Legend?

Also, reverse implies that there's one correct direction and one reversed direction. Which one is correct one depends on culture.

So should we then have a direction=ltr|rtl as a whole chart prop?

@ckifer
Copy link
Member

ckifer commented Feb 24, 2024

It was already a thing in YAxis before any of us, without thinking of RTL, etc. you were able to reverse both Axes.

If we had a chart prop then yeah it should only affect XAxis.

Chart prop could take precedence over reversed.

As for Legend, we could ask the issue requester, he would know better than us. But it's easier to make a custom legend than a custom axis

src/chart/AccessibilityManager.ts Outdated Show resolved Hide resolved
@@ -1099,6 +1100,8 @@ export const generateCategoricalChart = ({
coordinateList: this.state.tooltipTicks,
mouseHandlerCallback: this.triggeredAfterMouseMove,
layout: this.props.layout,
// Assuming there's only 1 <XAxis />, check to see if it has reversed={true}. If so, this is an RTL chart
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if there are multiple axes?

src/util/ChartUtils.ts Outdated Show resolved Hide resolved
@@ -172,6 +195,83 @@ describe('AccessibilityLayer', () => {
expect(mockMouseMovements.mock.instances).toHaveLength(0);
});

test('Left/right arrow pays attention to if the XAxis is reversed', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

<3

test/chart/AccessibilityLayer.spec.tsx Outdated Show resolved Hide resolved
Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

🚀🚢🚀🚢

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.26%. Comparing base (1ce9b2f) to head (4d224c4).

Additional details and impacted files
@@           Coverage Diff           @@
##              3.x    #4225   +/-   ##
=======================================
  Coverage   93.25%   93.26%           
=======================================
  Files          95       95           
  Lines       20130    20159   +29     
  Branches     2736     2746   +10     
=======================================
+ Hits        18772    18801   +29     
  Misses       1347     1347           
  Partials       11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ckifer
Copy link
Member

ckifer commented Feb 29, 2024

@julianna-langston just merging 3.x into your branch so that coverage generates correctly

@ckifer ckifer merged commit 1fd1c77 into recharts:3.x Feb 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants