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

feat(LEMS-2484): add aria labels to sinusoid function graph #2070

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-shoes-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

add aria labels for sinusoid function graphs
10 changes: 10 additions & 0 deletions packages/perseus/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ export type PerseusStrings = {
endingSideX: string;
endingSideY: string;
}) => string;
srSinusoidGraphAriaLabel: string;
srSinusoidExtremumPoint: ({x, y}: {x: string; y: string}) => string;
srSinusoidMidlineIntersection: ({x, y}: {x: string; y: string}) => string;
// The above strings are used for interactive graph SR descriptions.
};

Expand Down Expand Up @@ -478,6 +481,9 @@ export const strings: {
srAngleGraphAriaLabel: "An angle on a coordinate plane.",
srAngleGraphAriaDescription:
"The angle measure is %(angleMeasure)s degrees with a vertex at %(vertexX)s comma %(vertexY)s, a point on the starting side at %(startingSideX)s comma %(startingSideY)s and a point on the ending side at %(endingSideX)s comma %(endingSideY)s",
srSinusoidGraphAriaLabel: "A sinusoid function on a coordinate plane.",
srSinusoidExtremumPoint: "Extremum Point at %(x)s comma %(y)s.",
srSinusoidMidlineIntersection: "Midline Intersection at %(x)s comma %(y)s.",
// The above strings are used for interactive graph SR descriptions.
};

Expand Down Expand Up @@ -695,5 +701,9 @@ export const mockStrings: PerseusStrings = {
endingSideY,
}) =>
`The angle measure is ${angleMeasure} degrees with a vertex at ${vertexX} comma ${vertexY}, a point on the starting side at ${startingSideX} comma ${startingSideY} and a point on the ending side at ${endingSideX} comma ${endingSideY}.`,
srSinusoidGraphAriaLabel: "A sinusoid function on a coordinate plane.",
srSinusoidExtremumPoint: ({x, y}) => `Extremum Point at ${x} comma ${y}.`,
srSinusoidMidlineIntersection: ({x, y}) =>
`Midline Intersection at ${x} comma ${y}.`,
// The above strings are used for interactive graph SR descriptions.
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {color} from "@khanacademy/wonder-blocks-tokens";
import {Plot} from "mafs";
import {Plot, type vec} from "mafs";
import * as React from "react";

import {usePerseusI18n} from "../../../components/i18n-context";
import {X, Y} from "../math";
import {actions} from "../reducer/interactive-graph-action";

import {MovablePoint} from "./components/movable-point";
import {srFormatNumber} from "./screenreader-text";

import type {Coord} from "../../../interactive2/types";
import type {
Expand Down Expand Up @@ -59,23 +61,40 @@ function SinusoidGraph(props: SinusoidGraphProps) {
coeffRef.current = coeffs;
}

const {strings, locale} = usePerseusI18n();

function getMoveablePointAriaLabel(
index: number,
coordinate: vec.Vector2,
): string {
const coordsObj = {
x: srFormatNumber(coordinate[0], locale),
y: srFormatNumber(coordinate[1], locale),
};

return index === 1
? strings.srSinusoidExtremumPoint(coordsObj)
: strings.srSinusoidMidlineIntersection(coordsObj);
}

return (
<>
<g aria-label={strings.srSinusoidGraphAriaLabel}>
<Plot.OfX
y={(x) => computeSine(x, coeffRef.current)}
color={color.blue}
/>
{coords.map((coord, i) => (
<MovablePoint
key={"point-" + i}
ariaLabel={getMoveablePointAriaLabel(i, coord)}
point={coord}
sequenceNumber={i + 1}
onMove={(destination) =>
dispatch(actions.sinusoid.movePoint(i, destination))
}
/>
))}
</>
</g>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ describe("MafsGraph", () => {
/>,
);

expectLabelInDoc("Point 1 at -1 comma 1");
expectLabelInDoc("Point 2 at 0 comma 0");
expectLabelInDoc("Midline Intersection at -1 comma 1.");
expectLabelInDoc("Extremum Point at 0 comma 0.");
});

it("renders ARIA labels for each point (point)", () => {
Expand Down
Loading