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

[i-like-to-move-it] Ensure that keyboard users can move points across invalid locations for all graphs. (#2264) #2264

Merged
merged 6 commits into from
Feb 24, 2025

Conversation

SonicScrewdriver
Copy link
Contributor

@SonicScrewdriver SonicScrewdriver commented Feb 22, 2025

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:

  • Quadratic
  • Sinsoid
  • Circle
  • All Graphs that use Movable Line
    • Segment
    • Linear
    • Linear System
    • Ray

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:

  • All current tests pass
  • New tests
  • Manual testing in Storybook

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

@SonicScrewdriver SonicScrewdriver self-assigned this Feb 22, 2025
Copy link
Contributor

github-actions bot commented Feb 22, 2025

Size Change: -45 B (-0.01%)

Total Size: 872 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 29.8 kB -45 B (-0.15%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39.5 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 11.1 kB
packages/math-input/dist/es/index.js 78.2 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-editor/dist/es/index.js 276 kB
packages/perseus-linter/dist/es/index.js 22.8 kB
packages/perseus-score/dist/es/index.js 20.6 kB
packages/perseus/dist/es/index.js 367 kB
packages/perseus/dist/es/strings.js 6.57 kB
packages/pure-markdown/dist/es/index.js 4.14 kB
packages/simple-markdown/dist/es/index.js 13.1 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Feb 22, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (e9bf133) and published it to npm. You
can install it using the tag PR2264.

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", () => {
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@SonicScrewdriver SonicScrewdriver changed the title [i-like-to-move-it] Ensure that keyboard users can move Sinusoidal and Quadratic graph points past invalid locations. [i-like-to-move-it] Ensure that keyboard users can move points across invalid locations for all graphs. Feb 22, 2025
…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 = (
Copy link
Contributor Author

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!

Copy link
Contributor

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 () => {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Copy link
Contributor

@nishasy nishasy left a 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 = (
Copy link
Contributor

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);
Copy link
Contributor

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 = (
Copy link
Contributor

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", () => {
Copy link
Contributor

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.

@SonicScrewdriver SonicScrewdriver changed the title [i-like-to-move-it] Ensure that keyboard users can move points across invalid locations for all graphs. [i-like-to-move-it] Ensure that keyboard users can move points across invalid locations for all graphs. (#2264) Feb 24, 2025
@SonicScrewdriver SonicScrewdriver merged commit 4eb9fe0 into main Feb 24, 2025
8 checks passed
@SonicScrewdriver SonicScrewdriver deleted the i-like-to-move-it branch February 24, 2025 21:01
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.

2 participants