-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[editor-pi] [Interactive Graph] Support tick labels that are multiple…
…s of pi (#2167) ## Summary: Currently, if a graph has tick labels that are multiples of pi, such as in a sinusoid graph, content authors have to set the graph markings to "none" and load in a graphie background image that has the graph with the desired tick markings. This is not only inconvenient for content authors, it also means that the screen reader will not read the correct coordinates for these interactive graphs. It might say "2" when it should be saying "2 pi." Implementing a fix for this to improve the lives of our content authors and our screen reader users. - Editor - Check if the value loaded into NumberInput is a multiple of pi, and not already written in the "pi" format. - If so, and if the `allowPiTrunacation` prop is true, divide this number by pi and append "π" to the value. - This will make it so that the value shown in the text input will show as pi format even if loaded in without it. (6.28... --> "2π") - Mafs graph - In the AxisTicks component, check if the tick step is a multiple of pi. - If so, divide all the ticks by pi and append pi to the value (special cases for 0, 1π, and -1π). - This will result in the ticks showing as integers * pi. Issue: https://khanacademy.atlassian.net/browse/LEMS-2059 ## Test plan: `yarn jest packages/perseus/src/components/__tests__/number-input.test.tsx` `yarn jest packages/perseus/src/util/math-utils.test.ts` `yarn jest packages/perseus/src/widgets/interactive-graphs/backgrounds/axis-ticks.test.ts` `yarn jest packages/perseus/src/widgets/interactive-graphs/interactive-graph.test.tsx` Storybook - http://localhost:6006/?path=/story/perseuseditor-widgets-interactive-graph--interactive-graph-sinusoid <img width="847" alt="image" src="https://github.com/user-attachments/assets/cb2044df-d8c2-496e-b78c-2ee7c6643b7d" /> Author: nishasy Reviewers: SonicScrewdriver, nishasy, catandthemachines Required Reviewers: Approved By: SonicScrewdriver Checks: ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #2167
- Loading branch information
Showing
12 changed files
with
271 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
"@khanacademy/perseus-editor": minor | ||
--- | ||
|
||
[Interactive Graph] Allow axis tick labels to be multiples of pi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {isPiMultiple} from "./math-utils"; | ||
|
||
describe("isPiMultiple", () => { | ||
test.each` | ||
case | number | ||
${"π"} | ${Math.PI} | ||
${"2π"} | ${Math.PI * 2} | ||
${"3π"} | ${Math.PI * 3} | ||
${"-π"} | ${Math.PI * -1} | ||
${"-2π"} | ${Math.PI * -2} | ||
${"π/2"} | ${Math.PI / 2} | ||
${"π/3"} | ${Math.PI / 3} | ||
${"π/4"} | ${Math.PI / 4} | ||
${"π/6"} | ${Math.PI / 6} | ||
${"2π/3"} | ${(Math.PI * 2) / 3} | ||
`("should return true for $case", ({number}) => { | ||
expect(isPiMultiple(number)).toBe(true); | ||
}); | ||
|
||
test.each` | ||
case | number | ||
${"0"} | ${0} | ||
${"1"} | ${1} | ||
${"-1"} | ${-1} | ||
${"3.14"} | ${3.14} | ||
${"3.14159"} | ${3.14159} | ||
${"2.5"} | ${2.5} | ||
${"-1.5"} | ${-1.5} | ||
`("should return false for $case", ({number}) => { | ||
expect(isPiMultiple(number)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function isPiMultiple(value: number): boolean { | ||
// Early return for integers that clearly aren't multiples | ||
// of pi to save some computation. | ||
if (Number.isInteger(value)) { | ||
return false; | ||
} | ||
|
||
return ( | ||
value % Math.PI === 0 || | ||
value % (Math.PI / 2) === 0 || | ||
value % (Math.PI / 3) === 0 || | ||
value % (Math.PI / 4) === 0 || | ||
value % (Math.PI / 6) === 0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.