Skip to content

Commit 4508e7b

Browse files
authored
[SR] Minor improvements to Circle graph SR strings (#2017)
## Summary: - Update the variable names to start with `sr` prefix. - Use `srFormatNumber()` to make sure the numbers are formatted correctly. - Update the coordinate types to `string` in the strings instead of `number` since they are now using `srFormatNumber()` (which returns a string) Issue: https://khanacademy.atlassian.net/browse/LEMS-1706 ## Test plan: `yarn jest` - Go to http://localhost:6006/iframe.html?globals=&args=&id=perseuseditor-widgets-interactive-graph--interactive-graph-circle&viewMode=story - Confirm nothing has changed from before Author: nishasy Reviewers: catandthemachines, anakaren-rojas Required Reviewers: Approved By: catandthemachines Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (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: #2017
1 parent 81f4697 commit 4508e7b

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

.changeset/shiny-houses-promise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
[SR] Minor improvements to Circle graph SR strings

packages/perseus/src/strings.ts

+35-34
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ export type PerseusStrings = {
130130
tan: string;
131131
simulationLoadFail: string;
132132
simulationLocaleWarning: string;
133+
selectAnAnswer: string;
134+
// The following strings are used for interactive graph SR descriptions.
133135
addPoint: string;
134136
removePoint: string;
135137
graphKeyboardPrompt: string;
136-
selectAnAnswer: string;
137-
// The following strings are used for interactive graph SR descriptions.
138138
closePolygon: string;
139139
openPolygon: string;
140140
srPointAtCoordinates: ({
@@ -148,23 +148,23 @@ export type PerseusStrings = {
148148
}) => string;
149149
srInteractiveElements: ({elements}: {elements: string}) => string;
150150
srNoInteractiveElements: string;
151-
circleGraphAriaLabel: string;
152-
circleShapeAriaLabel: ({
151+
srCircleGraph: string;
152+
srCircleShape: ({
153153
centerX,
154154
centerY,
155155
}: {
156-
centerX: number;
157-
centerY: number;
156+
centerX: string;
157+
centerY: string;
158158
}) => string;
159-
circleRadiusPointAriaLabel: ({
159+
srCircleRadiusPoint: ({
160160
radiusPointX,
161161
radiusPointY,
162162
}: {
163-
radiusPointX: number;
164-
radiusPointY: number;
163+
radiusPointX: string;
164+
radiusPointY: string;
165165
}) => string;
166-
circleRadiusDescription: ({radius}: {radius: number}) => string;
167-
circleOuterPointsDescription: ({
166+
srCircleRadius: ({radius}: {radius: number}) => string;
167+
srCircleOuterPoints: ({
168168
point1X,
169169
point1Y,
170170
point2X,
@@ -174,14 +174,14 @@ export type PerseusStrings = {
174174
point4X,
175175
point4Y,
176176
}: {
177-
point1X: number;
178-
point1Y: number;
179-
point2X: number;
180-
point2Y: number;
181-
point3X: number;
182-
point3Y: number;
183-
point4X: number;
184-
point4Y: number;
177+
point1X: string;
178+
point1Y: string;
179+
point2X: string;
180+
point2Y: string;
181+
point3X: string;
182+
point3Y: string;
183+
point4X: string;
184+
point4Y: string;
185185
}) => string;
186186
// The above strings are used for interactive graph SR descriptions.
187187
};
@@ -356,15 +356,16 @@ export const strings: {
356356
simulationLoadFail: "Sorry, this simulation cannot load.",
357357
simulationLocaleWarning:
358358
"Sorry, this simulation isn't available in your language.",
359+
selectAnAnswer: "Select an answer",
360+
361+
// The following strings are used for interactive graph SR descriptions.
359362
addPoint: "Add Point",
360363
removePoint: "Remove Point",
361364
graphKeyboardPrompt: "Press Shift + Enter to interact with the graph",
362365
closePolygon: "Close shape",
363366
openPolygon: "Re-open shape",
364367
srInteractiveElements: "Interactive elements: %(elements)s",
365368
srNoInteractiveElements: "No interactive elements",
366-
selectAnAnswer: "Select an answer",
367-
368369
// TODO(LEMS-2660): The following strings are ones that will need
369370
// translation tickets after all interactive graph SR strings have
370371
// been finalized. Remove this comment after the tickets have been
@@ -373,27 +374,27 @@ export const strings: {
373374
context: "Screenreader-accessible description of a point on a graph",
374375
message: "Point %(num)s at %(x)s comma %(y)s",
375376
},
376-
circleGraphAriaLabel: {
377+
srCircleGraph: {
377378
context: "Aria label for the circle graph as a whole.",
378379
message: "A circle on a coordinate plane.",
379380
},
380-
circleShapeAriaLabel: {
381+
srCircleShape: {
381382
context:
382383
"Aria label for the interactive circle shape in a circle graph.",
383384
message:
384385
"Circle. The center point is at %(centerX)s comma %(centerY)s.",
385386
},
386-
circleRadiusPointAriaLabel: {
387+
srCircleRadiusPoint: {
387388
context:
388389
"Aria label for the interactive point that sits on the edge of the circle in a circle graph. Moving this point updates the radius of the circle",
389390
message: "Radius point at %(radiusPointX)s comma %(radiusPointY)s.",
390391
},
391-
circleRadiusDescription: {
392+
srCircleRadius: {
392393
context:
393394
"Screenreader-only description of the radius of a circle in a circle graph.",
394395
message: "Circle radius is %(radius)s.",
395396
},
396-
circleOuterPointsDescription: {
397+
srCircleOuterPoints: {
397398
context:
398399
"Screenreader-only description of key points on a circle in a circle graph.",
399400
message:
@@ -556,24 +557,24 @@ export const mockStrings: PerseusStrings = {
556557
simulationLoadFail: "Sorry, this simulation cannot load.",
557558
simulationLocaleWarning:
558559
"Sorry, this simulation isn't available in your language.",
559-
addPoint: "Add Point",
560-
removePoint: "Remove Point",
561-
graphKeyboardPrompt: "Press Shift + Enter to interact with the graph",
562560
selectAnAnswer: "Select an answer",
563561

564562
// The following strings are used for interactive graph SR descriptions.
563+
graphKeyboardPrompt: "Press Shift + Enter to interact with the graph",
564+
addPoint: "Add Point",
565+
removePoint: "Remove Point",
565566
closePolygon: "Close shape",
566567
openPolygon: "Re-open shape",
567568
srPointAtCoordinates: ({num, x, y}) => `Point ${num} at ${x} comma ${y}`,
568569
srInteractiveElements: ({elements}) => `Interactive elements: ${elements}`,
569570
srNoInteractiveElements: "No interactive elements",
570-
circleGraphAriaLabel: "A circle on a coordinate plane.",
571-
circleShapeAriaLabel: ({centerX, centerY}) =>
571+
srCircleGraph: "A circle on a coordinate plane.",
572+
srCircleShape: ({centerX, centerY}) =>
572573
`Circle. The center point is at ${centerX} comma ${centerY}.`,
573-
circleRadiusPointAriaLabel: ({radiusPointX, radiusPointY}) =>
574+
srCircleRadiusPoint: ({radiusPointX, radiusPointY}) =>
574575
`Radius point at ${radiusPointX} comma ${radiusPointY}.`,
575-
circleRadiusDescription: ({radius}) => `Circle radius is ${radius}.`,
576-
circleOuterPointsDescription: ({
576+
srCircleRadius: ({radius}) => `Circle radius is ${radius}.`,
577+
srCircleOuterPoints: ({
577578
point1X,
578579
point1Y,
579580
point2X,

packages/perseus/src/widgets/interactive-graphs/graphs/circle.tsx

+19-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {getRadius} from "../reducer/interactive-graph-state";
99
import useGraphConfig from "../reducer/use-graph-config";
1010

1111
import {MovablePoint} from "./components/movable-point";
12+
import {srFormatNumber} from "./screenreader-text";
1213
import {useDraggable} from "./use-draggable";
1314
import {
1415
useTransformDimensionsToPixels,
@@ -39,7 +40,7 @@ function CircleGraph(props: CircleGraphProps) {
3940
const {dispatch, graphState} = props;
4041
const {center, radiusPoint} = graphState;
4142

42-
const {strings} = usePerseusI18n();
43+
const {strings, locale} = usePerseusI18n();
4344
const [radiusPointAriaLive, setRadiusPointAriaLive] =
4445
React.useState<AriaLive>("off");
4546

@@ -50,27 +51,27 @@ function CircleGraph(props: CircleGraphProps) {
5051
const outerPointsId = id + "-outer-points";
5152

5253
// Aria label strings
53-
const circleGraphAriaLabel = strings.circleGraphAriaLabel;
54-
const circleShapeAriaLabel = strings.circleShapeAriaLabel({
55-
centerX: center[0],
56-
centerY: center[1],
54+
const circleGraphAriaLabel = strings.srCircleGraph;
55+
const circleShapeAriaLabel = strings.srCircleShape({
56+
centerX: srFormatNumber(center[0], locale),
57+
centerY: srFormatNumber(center[1], locale),
5758
});
58-
const circleRadiusPointAriaLabel = strings.circleRadiusPointAriaLabel({
59-
radiusPointX: radiusPoint[0],
60-
radiusPointY: radiusPoint[1],
59+
const circleRadiusPointAriaLabel = strings.srCircleRadiusPoint({
60+
radiusPointX: srFormatNumber(radiusPoint[0], locale),
61+
radiusPointY: srFormatNumber(radiusPoint[1], locale),
6162
});
62-
const circleRadiusDescription = strings.circleRadiusDescription({
63+
const circleRadiusDescription = strings.srCircleRadius({
6364
radius,
6465
});
65-
const circleOuterPointsDescription = strings.circleOuterPointsDescription({
66-
point1X: center[0] + radius,
67-
point1Y: center[1],
68-
point2X: center[0],
69-
point2Y: center[1] + radius,
70-
point3X: center[0] - radius,
71-
point3Y: center[1],
72-
point4X: center[0],
73-
point4Y: center[1] - radius,
66+
const circleOuterPointsDescription = strings.srCircleOuterPoints({
67+
point1X: srFormatNumber(center[0] + radius, locale),
68+
point1Y: srFormatNumber(center[1], locale),
69+
point2X: srFormatNumber(center[0], locale),
70+
point2Y: srFormatNumber(center[1] + radius, locale),
71+
point3X: srFormatNumber(center[0] - radius, locale),
72+
point3Y: srFormatNumber(center[1], locale),
73+
point4X: srFormatNumber(center[0], locale),
74+
point4Y: srFormatNumber(center[1] - radius, locale),
7475
});
7576

7677
return (

0 commit comments

Comments
 (0)