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

fix(LEMS-2617): Require $ to display TeX in axis labels #1865

Merged
merged 9 commits into from
Nov 15, 2024
5 changes: 5 additions & 0 deletions .changeset/heavy-eels-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Require \$ to display TeX in axis labels
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getDependencies} from "../../../dependencies";
import {pointToPixel} from "../graphs/use-transform";
import {MAX, X, Y} from "../math";
import useGraphConfig from "../reducer/use-graph-config";
import {replaceOutsideTeX} from "../utils";

import type {GraphDimensions} from "../types";

Expand Down Expand Up @@ -42,7 +43,7 @@ export default function AxisLabels() {
transform: "translate(7px, -50%)",
}}
>
<TeX>{xAxisLabelText}</TeX>
<TeX>{replaceOutsideTeX(xAxisLabelText)}</TeX>
</span>
<span
style={{
Expand All @@ -53,7 +54,7 @@ export default function AxisLabels() {
transform: "translate(-50%, 0px)",
}}
>
<TeX>{yAxisLabelText}</TeX>
<TeX>{replaceOutsideTeX(yAxisLabelText)}</TeX>
</span>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ describe("MafsGraph", () => {
expect(line.getAttribute("y2")).toBe(-expectedY2 + "");
});

it("renders TeX in axis Labels", () => {
const basePropsWithTexLabels = {
...getBaseMafsGraphProps(),
labels: ["$1/2$", "$3/4$"],
};

render(<MafsGraph {...basePropsWithTexLabels} />);
expect(screen.getByText("1/2")).toBeInTheDocument();
expect(screen.getByText("3/4")).toBeInTheDocument();
});

it("renders plain text in axis Labels", () => {
const basePropsWithTexLabels = {
...getBaseMafsGraphProps(),
labels: ["4/5", "5/6"],
};

render(<MafsGraph {...basePropsWithTexLabels} />);
expect(screen.getByText("\\text{4/5}")).toBeInTheDocument();
expect(screen.getByText("\\text{5/6}")).toBeInTheDocument();
});

it("renders ARIA labels for each point (segment)", () => {
const state: InteractiveGraphState = {
type: "segment",
Expand Down