-
Notifications
You must be signed in to change notification settings - Fork 350
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
feat(LEMS-2662): handle angle aria label updates #1940
base: main
Are you sure you want to change the base?
Conversation
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (b055724) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1940 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1940 |
Size Change: +799 B (+0.06%) Total Size: 1.29 MB
ℹ️ View Unchanged
|
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
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 is exciting!
Requesting changes because we're ultimately going to want a different approach to aria-live notifications (see my inline comment about avoiding useState and building for the upcoming Wonder Blocks API) and I'd prefer to start designing for that now.
updateVertexAriaLabel(coords[1]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [showAngles]); | ||
|
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.
I think we could avoid using the useState
and useEffect
hooks here if we:
- compute aria labels from the
graphState
prop - use aria-live to notify the user of changes to the graph
This would ensure that the SR view and the visible view never get out of sync, since both would be pure functions of graphState
. Currently, all the individual graph components are stateless (or nearly so — there are a couple useState
s for hover and dragging effects) and I'd like to keep it that way.
Wonder Blocks is planning an API for sending aria-live notifications, but since it's not built yet, I think what we could do is write a minimal implementation of the same API and swap in the WB one when it's ready. I'd be down to pair or consult on that if you want.
packages/perseus/src/widgets/interactive-graphs/graphs/components/angle-indicators.test.ts
Outdated
Show resolved
Hide resolved
export function getClockwiseCoords( | ||
coords: Vector2[], | ||
vertex: vec.Vector2, | ||
allowReflexAngles: boolean = false, | ||
) { | ||
// Check if the points are clockwise or not, depending on whether we allow reflex angles | ||
const areClockwise = clockwise([...coords, vertex]); | ||
const shouldReverseCoords = areClockwise && !allowReflexAngles; | ||
|
||
// Reverse the coordinates accordingly to ensure the angle is calculated correctly | ||
return shouldReverseCoords ? coords : coords.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.
Thanks for refactoring this code!
It seems like this duplicates some of the logic from getClockwiseAngle
in interactive-graphs/math/angles.ts
. Could we use that function to calculate the angle measure here? getClockwiseAngle
is used for scoring, and it would be nice if we could use the same function to calculate the angle label.
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.
oh yes, you're right, it looks like it combines both the getClockwiseCoords
and the getWholeAngleMeasure
methods into one! let me test it out
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.
ok, so I tested this out and using the getClockwiseAngle
function introduces a regression in the graph 😢
The very small difference between how we determine whether the coordinates should be reversed is the culprit:
In getClockwiseAngle
const shouldReverseCoords = !areClockwise || allowReflexAngles;
In getWholeAngleMeasure
const shouldReverseCoords = areClockwise && !allowReflexAngles;
EDIT:
I realized that using getClockwiseAngle
in angles served the original purpose that these two new methods were supposed to serve, so there's no longer a need to pull this logic out of angle-indicators
; I'm leaving angle-indicators
as-is
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.
I like these tests!
[1, 0], | ||
[0, 0], | ||
]); | ||
}); |
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.
I'm a bit confused by this. The function is called getClockwiseCoords
but it can return counterclockwise coords?
Co-authored-by: Ben Christel <[email protected]>
Summary:
Issue: LEMS-2662
Test plan:
Testing Steps
Angle
Show angle measures
and move pointsAllow reflex angles
and move pointsExpected behavior
Show angle measures
is not enabled, screen reader does not read out angle measureShow angle measures
is enabled, angle measure is read out with vertexShow angle measures
andAllow reflex angles
are enabled, Screen Reader reads out reflex anglesScreen Recordings:
Without angle measures
Screen.Recording.2024-12-03.at.14.53.13.mov
With angle measures
Screen.Recording.2024-12-03.at.14.53.53.mov