Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions .changeset/heavy-deers-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-core": minor
"@khanacademy/perseus-editor": minor
---

Creation of initial types and stubs for Vector graph
19 changes: 17 additions & 2 deletions packages/perseus-core/src/data-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,8 @@ export type PerseusGraphType =
| PerseusGraphTypeSegment
| PerseusGraphTypeSinusoid
| PerseusGraphTypeExponential
| PerseusGraphTypeTangent;
| PerseusGraphTypeTangent
| PerseusGraphTypeVector;

export type PerseusGraphTypeAngle = {
type: "angle";
Expand Down Expand Up @@ -1263,6 +1264,14 @@ export type PerseusGraphTypeRay = {
startCoords?: CollinearTuple;
};

export type PerseusGraphTypeVector = {
type: "vector";
/** The tail and tip coordinates of the vector: [tail, tip] */
coords?: CollinearTuple | null;
/** The initial coordinates the graph renders with. */
startCoords?: CollinearTuple;
};

type AbsoluteValueGraphCorrect = {
type: "absolute-value";
coords: [Coord, Coord];
Expand Down Expand Up @@ -1337,6 +1346,11 @@ type RayGraphCorrect = {
coords: CollinearTuple;
};

type VectorGraphCorrect = {
type: "vector";
coords: CollinearTuple;
};

export type PerseusGraphCorrectType =
| AbsoluteValueGraphCorrect
| AngleGraphCorrect
Expand All @@ -1351,7 +1365,8 @@ export type PerseusGraphCorrectType =
| SegmentGraphCorrect
| SinusoidGraphCorrect
| ExponentialGraphCorrect
| TangentGraphCorrect;
| TangentGraphCorrect
| VectorGraphCorrect;

/** Options for the label-image widget. Asks learners to label image parts. */
export type PerseusLabelImageWidgetOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ const parsePerseusGraphTypeTangent = object({
startCoords: optional(array(pairOfNumbers)),
});

const parsePerseusGraphTypeVector = object({
type: constant("vector"),
coords: optional(nullable(pair(pairOfNumbers, pairOfNumbers))),
startCoords: optional(pair(pairOfNumbers, pairOfNumbers)),
});

export const parsePerseusGraphType = discriminatedUnionOn("type")
.withBranch("absolute-value", parsePerseusGraphTypeAbsoluteValue)
.withBranch("angle", parsePerseusGraphTypeAngle)
Expand All @@ -151,7 +157,8 @@ export const parsePerseusGraphType = discriminatedUnionOn("type")
.withBranch("ray", parsePerseusGraphTypeRay)
.withBranch("segment", parsePerseusGraphTypeSegment)
.withBranch("sinusoid", parsePerseusGraphTypeSinusoid)
.withBranch("tangent", parsePerseusGraphTypeTangent).parser;
.withBranch("tangent", parsePerseusGraphTypeTangent)
.withBranch("vector", parsePerseusGraphTypeVector).parser;

const parseLockedFigureColor = enumeration(...lockedFigureColorNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ function mergeGraphs(
case "tangent":
invariant(b.type === "tangent");
return {...a, ...b};
case "vector":
invariant(b.type === "vector");
return {...a, ...b};
default:
throw new UnreachableCaseError(a);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export const shouldShowStartCoordsUI = (
case "segment":
case "sinusoid":
case "absolute-value":
case "vector":
return true;
default:
throw new UnreachableCaseError(graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ const getGraphOptionsForProps = (
type: props.userInput.type,
startCoords: props.userInput.startCoords,
};
case "vector":
return {
type: props.userInput.type,
startCoords: props.userInput.startCoords,
};
default:
throw new UnreachableCaseError(type);
}
Expand Down Expand Up @@ -334,6 +339,10 @@ const getUserInput = (userInput: PerseusGraphType): UserInput => {
coords: userInput.coords,
asymptote: userInput.asymptote,
};
case "vector":
return {
coords: userInput.coords,
};
default:
throw new UnreachableCaseError(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ class InteractiveGraph extends React.Component<Props, State> {
return InteractiveGraph.getExponentialEquationString(props);
case "tangent":
return InteractiveGraph.getTangentEquationString(props);
case "vector":
return "";
default:
throw new UnreachableCaseError(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ const renderGraphElements = (props: {
return renderAbsoluteValueGraph(state, dispatch, i18n);
case "tangent":
return renderTangentGraph(state, dispatch, i18n);
case "vector":
throw new Error("Not implemented");
default:
throw new UnreachableCaseError(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export function mafsStateToInteractiveGraph(
...originalGraph,
coords: state.coords,
};
case "vector":
invariant(originalGraph.type === "vector");
return {
...originalGraph,
coords: state.coords,
};
default:
throw new UnreachableCaseError(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export function initializeGraphState(
type: graph.type,
coords: getTangentCoords(graph, range, step),
};
case "vector":
throw new Error("Not implemented");
default:
throw new UnreachableCaseError(graph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ function doMovePointInFigure(
case "absolute-value":
case "tangent":
case "exponential":
case "vector":
throw new Error(
`Don't use movePointInFigure for ${state.type} graphs. Use movePoint instead!`,
);
Expand Down
8 changes: 7 additions & 1 deletion packages/perseus/src/widgets/interactive-graphs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type InteractiveGraphState =
| QuadraticGraphState
| SinusoidGraphState
| ExponentialGraphState
| TangentGraphState;
| TangentGraphState
| VectorGraphState;

export type UnlimitedGraphState = PointGraphState | PolygonGraphState;

Expand Down Expand Up @@ -90,6 +91,11 @@ export interface RayGraphState extends InteractiveGraphStateCommon {
coords: PairOfPoints;
}

export interface VectorGraphState extends InteractiveGraphStateCommon {
type: "vector";
coords: PairOfPoints;
}

export interface PolygonGraphState extends InteractiveGraphStateCommon {
type: "polygon";
showAngles: boolean;
Expand Down
Loading