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 @@ -128,6 +128,17 @@ describe("MafsGraph", () => {
expect(line.getAttribute("y2")).toBe(-expectedY2 + "");
});

it("renders X axis label with TeX and Y axis with text", () => {
const basePropsWithTexLabels = {
...getBaseMafsGraphProps(),
labels: ["$1/2$", "1/2"],
};

render(<MafsGraph {...basePropsWithTexLabels} />);
expect(screen.getByText("1/2")).toBeInTheDocument();
expect(screen.getByText("\\text{1/2}")).toBeInTheDocument();
anakaren-rojas marked this conversation as resolved.
Show resolved Hide resolved
});

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