Skip to content

Commit 9c9861e

Browse files
authored
[SR][Pi ticks] Add a coefficient before pi-based values that start with negative pi (#2401)
## Summary: We need to add `1` coefficient before pi-based values that start with negative pi, because screen readers may not read the `-` sign, implying the value is positive even when it's not. By adding the `1`, it will read "minus one pi" which is at least correct in terms of meaning, even if it doesn't totally match the spoken vocabulary. In the [Slack conversation about this](https://khanacademy.slack.com/archives/C067UM1QAR4/p1744829758895619), I received confirmation from Charlie that this is an acceptable approach. Issue: https://khanacademy.atlassian.net/browse/LEMS-3041 ## Test plan: `pnpm jest packages/perseus/src/widgets/interactive-graphs/graphs/screenreader-text.test.ts` Storybook - Go to http://localhost:6006/iframe.html?globals=&args=&id=perseuseditor-widgets-interactive-graph--interactive-graph-sinusoid-with-pi-ticks&viewMode=story - Move a point to an x value of -pi - Turn on a screen reader and navigate to the point - Confirm that it reads as "minus one pi" and NOT "pi" Author: nishasy Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ 8 checks were successful Pull Request URL: #2401
1 parent d6f3c50 commit 9c9861e

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

.changeset/nervous-gifts-relax.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
[SR][pi ticks] Add a coefficient before pi-based values that start with negative pi

packages/perseus/src/widgets/interactive-graphs/graphs/screenreader-text.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("srFormatNumber", () => {
3030
});
3131

3232
it("uses pi format when the number is a multiple of pi", () => {
33-
expect(srFormatNumber(Math.PI, "en")).toBe("π");
33+
expect(srFormatNumber(Math.PI, "en")).toBe("");
3434
});
3535
});
3636

@@ -59,20 +59,20 @@ describe("getPiMultiple", () => {
5959

6060
test.each`
6161
num | expectedString
62-
${Math.PI} | ${"π"}
63-
${-Math.PI} | ${"-π"}
62+
${Math.PI} | ${""}
63+
${-Math.PI} | ${"-"}
6464
${2 * Math.PI} | ${"2π"}
6565
${-2 * Math.PI} | ${"-2π"}
6666
${10 * Math.PI} | ${"10π"}
6767
${-10 * Math.PI} | ${"-10π"}
68-
${Math.PI / 2} | ${"π/2"}
69-
${Math.PI / 3} | ${"π/3"}
70-
${Math.PI / 4} | ${"π/4"}
71-
${Math.PI / 6} | ${"π/6"}
72-
${Math.PI / -2} | ${"-π/2"}
73-
${Math.PI / -3} | ${"-π/3"}
74-
${Math.PI / -4} | ${"-π/4"}
75-
${Math.PI / -6} | ${"-π/6"}
68+
${Math.PI / 2} | ${"/2"}
69+
${Math.PI / 3} | ${"/3"}
70+
${Math.PI / 4} | ${"/4"}
71+
${Math.PI / 6} | ${"/6"}
72+
${Math.PI / -2} | ${"-/2"}
73+
${Math.PI / -3} | ${"-/3"}
74+
${Math.PI / -4} | ${"-/4"}
75+
${Math.PI / -6} | ${"-/6"}
7676
${(7 * Math.PI) / 2} | ${"7π/2"}
7777
${3.5 * Math.PI} | ${"7π/2"}
7878
${(2 * Math.PI) / 3} | ${"2π/3"}

packages/perseus/src/widgets/interactive-graphs/graphs/screenreader-text.ts

+10-22
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,11 @@ export function getPiMultiple(a: number): string | null {
3838
// is a multiple of π. Return it here.
3939
// Example: If a = 2π, then truncatedCoefficient = 2, so return "2π"
4040
if (Number.isInteger(truncatedCoefficient)) {
41-
// Return "π" rather than "1π".
42-
if (truncatedCoefficient === 1) {
43-
return "π";
44-
}
45-
46-
// Return "-π" rather than "-1π".
47-
if (truncatedCoefficient === -1) {
48-
return "-π";
49-
}
50-
41+
// NOTE: We are NOT doing a custom check to return -π and π here
42+
// instead of -1π and 1π, because screen readers may not read the
43+
// negative sign at all if it's directly before the π. This could
44+
// completely mess up the understanding of the graph for visually
45+
// impaired users.
5146
return truncatedCoefficient + "π";
5247
}
5348

@@ -72,18 +67,11 @@ export function getPiMultiple(a: number): string | null {
7267
);
7368

7469
if (Number.isInteger(coefficientNumerator)) {
75-
// Handle the case where the coefficient numberator is just 1.
76-
// We don't want to write "π/6" as "1π/6"
77-
if (coefficientNumerator === 1) {
78-
return "π/" + divisor;
79-
}
80-
81-
// Handle the case where the coefficient numberator is just -1.
82-
// We don't want to write "π/6" as "-1π/6"
83-
if (coefficientNumerator === -1) {
84-
return "-π/" + divisor;
85-
}
86-
70+
// NOTE: We are NOT doing a custom check to return -π and π here
71+
// instead of -1π and 1π, because screen readers may not read the
72+
// negative sign at all if it's directly before the π. This could
73+
// completely mess up the understanding of the graph for visually
74+
// impaired users.
8775
return coefficientNumerator + "π/" + divisor;
8876
}
8977
}

0 commit comments

Comments
 (0)