Skip to content

Commit

Permalink
Use readonly array for lockedFigures. Rename mafs-locked-layer to gra…
Browse files Browse the repository at this point in the history
…ph-locked-layer.
  • Loading branch information
nishasy committed Mar 13, 2024
1 parent 96ccaf1 commit 1ffe5b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/perseus/src/perseus-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
correct: PerseusGraphType;
// Shapes (points, chords, etc) displayed on the graph that cannot
// be moved by the user.
lockedFigures?: Array<LockedFigure>;
lockedFigures?: ReadonlyArray<LockedFigure>;
};

export type LockedFigure = LockedPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import * as React from "react";
import type {LockedFigure} from "../../perseus-types";

type Props = {
lockedFigures: Array<LockedFigure>;
lockedFigures: ReadonlyArray<LockedFigure>;
};

const MafsLockedLayer = (props: Props) => {
const GraphLockedLayer = (props: Props) => {
const {lockedFigures} = props;
return (
<>
{lockedFigures.map((figure, index) => {
if (figure.type === "point") {
const [x, y] = figure.coord;
return (
<Point
key={`${figure.type}-${index}`}
x={x}
y={y}
svgCircleProps={{style: figure.style}}
/>
);
switch (figure.type) {
case "point":
const [x, y] = figure.coord;
return (
<Point
key={`${figure.type}-${index}`}
x={x}
y={y}
svgCircleProps={{style: figure.style}}
/>
);
}

/**
Expand All @@ -38,4 +39,4 @@ const MafsLockedLayer = (props: Props) => {
);
};

export default MafsLockedLayer;
export default GraphLockedLayer;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {View} from "@khanacademy/wonder-blocks-core";
import {Mafs} from "mafs";
import * as React from "react";

import GraphLockedLayer from "./graph-locked-layer";
import {SegmentGraph} from "./graphs";
import {Grid} from "./grid";
import {interactiveGraphReducer} from "./interactive-graph-reducer";
import {initializeGraphState} from "./interactive-graph-state";
import {getLegacyGrid} from "./legacy-grid";
import MafsLockedLayer from "./mafs-locked-layer";

import type {InteractiveGraphAction} from "./interactive-graph-action";
import type {InteractiveGraphState} from "./interactive-graph-state";
Expand Down Expand Up @@ -100,7 +100,7 @@ export const MafsGraph = React.forwardRef<

{/* Locked layer */}
{props.lockedFigures && (
<MafsLockedLayer lockedFigures={props.lockedFigures} />
<GraphLockedLayer lockedFigures={props.lockedFigures} />
)}

{/* Interactive layer */}
Expand Down

0 comments on commit 1ffe5b5

Please sign in to comment.