-
Notifications
You must be signed in to change notification settings - Fork 351
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
[i-like-to-move-it] Ensure that keyboard users can move points across invalid locations for all graphs. (#2264) #2264
Conversation
…d Quadratic graph points past invalid locations.
…ns for all graphs + new tests
Size Change: -45 B (-0.01%) Total Size: 872 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (e9bf133) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2264 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR2264 |
@@ -328,3 +295,74 @@ describe("describedQuadraticGraph interactive elements", () => { | |||
); | |||
}); | |||
}); | |||
|
|||
describe("getQuadraticCoefficients", () => { |
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 renamed this as it was only testing the getQuadraticCoefficients function.
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.
Thank you for this comment! I'm confused why it can't figure out the body of this is the same as before.
…ove points across invalid locations for all graphs.
} => { | ||
// Create a helper function that moves the point and then checks | ||
// if it overlaps with the center point after the move. | ||
const movePointWithConstraint = ( |
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 function is recreated in a few places, albeit with several differences to support each graph type. I ruminated on whether to move this to a util file, but I think the subtle differences and value of having this logic "in situ" outweigh what we would gain by keeping this more DRY.
I'm open to other interpretations on this, however!
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 could go either way between your current implementation and a util function that you pass in the type to so you can easily see what the differences are. Since you've already written it this way, I say leave it as is.
@@ -768,6 +766,195 @@ describe("MafsGraph", () => { | |||
expect(state.coords).toEqual(expectedCoords); | |||
}); | |||
|
|||
it("Quadratic moves points over invalid locations on keystroke", async () => { |
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 wanted to write these tests in their respective graph testing files, but I was unable to get the graph to update properly in jest after keyboard interaction.
Given that mafs-graphs.test.tsx
was already testing some keyboard functionality, and had the necessary logic for accessing the state directly, I've opted to implement the keyboard tests in this file.
Happy to take any feedback or suggestions on this as well!
@@ -150,10 +150,7 @@ function doFocusPoint( | |||
switch (state.type) { |
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.
Hmm it seems like my settings resulted in removing some white space from this file. I will revert that as there are no other changes.
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.
Nice! This works BEAUTIFULLY in storybook!
} => { | ||
// Create a helper function that moves the point and then checks | ||
// if it overlaps with the center point after the move. | ||
const movePointWithConstraint = ( |
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 could go either way between your current implementation and a util function that you pass in the type to so you can easily see what the differences are. Since you've already written it this way, I say leave it as is.
// If the moved point overlaps with the center point, | ||
// move the point again. | ||
if (vec.dist(movedCoord, center) === 0) { | ||
movedCoord = moveFunc(movedCoord); |
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.
Beautiful
@@ -240,6 +252,54 @@ const Line = (props: LineProps) => { | |||
); | |||
}; | |||
|
|||
export const getMovableLineKeyboardConstraint = ( |
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 love that this fixes the ray overlapping points issue!
(It still happens with mouse, but that is irrelevant here and arguably not an issue.)
@@ -328,3 +295,74 @@ describe("describedQuadraticGraph interactive elements", () => { | |||
); | |||
}); | |||
}); | |||
|
|||
describe("getQuadraticCoefficients", () => { |
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.
Thank you for this comment! I'm confused why it can't figure out the body of this is the same as before.
Summary:
This PR is part of the Interactive Graph Project!
The work in this PR ensures that users can move points across invalid locations for all graph types. This required updates to the following Interactive Graph types:
NOTE: This PR does not change the functionality of the Polygon or Angle Graphs as I believe both have custom implementations that have already been implemented.
Issue: LEMS-2014
Video:
Screen.Recording.2025-02-21.at.5.20.38.PM.mov
Storybook Link:
https://650db21c3f5d1b2f13c02952-ehxlgsxqwf.chromatic.com/
Issue: LEMS-2014
Test plan:
Author: SonicScrewdriver
Reviewers: SonicScrewdriver, nishasy, catandthemachines
Required Reviewers:
Approved By: nishasy
Checks: ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)
Pull Request URL: #2264