Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fitzgerald committed Aug 8, 2024
2 parents 9f98040 + 2ebbc19 commit ffeea6d
Show file tree
Hide file tree
Showing 35 changed files with 390 additions and 122 deletions.
6 changes: 6 additions & 0 deletions .changeset/eleven-paws-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-editor": minor
---

[Hint Mode: Start Coords] Build the foundation for adding start coords UI for angle graphs
5 changes: 5 additions & 0 deletions .changeset/flat-badgers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/math-input": patch
---

Remove old buttons that we weren't using anymore
5 changes: 5 additions & 0 deletions .changeset/strange-trains-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/math-input": patch
---

Remove unused buttons from MathInput; add Lato
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const config: StorybookConfig = {
docs: {
autodocs: true,
},
staticDirs: ["../static"],
};

export default config;
59 changes: 59 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!-- Preload WB fonts to prevent layout shifting due to font rendering -->
<link
rel="preload"
href="fonts/pre/Lato-Regular.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/Lato-Bold.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/Lato-Black.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/Lato-Italic.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/LatoLatin-Regular.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/LatoLatin-Bold.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/LatoLatin-Black.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="fonts/lato/LatoLatin-Italic.woff2"
as="font"
type="font/woff2"
crossorigin
/>

<link rel="stylesheet" href="./lato.css" />
28 changes: 0 additions & 28 deletions packages/math-input/src/components/key-handlers/key-translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const getKeyTranslator = (
LEFT_PAREN: buildGenericCallback("(", ActionType.CMD),
RIGHT_PAREN: buildGenericCallback(")", ActionType.CMD),
SQRT: buildGenericCallback("sqrt", ActionType.CMD),
PHI: buildGenericCallback("\\phi", ActionType.CMD),
PI: buildGenericCallback("pi", ActionType.CMD),
THETA: buildGenericCallback("theta", ActionType.CMD),
RADICAL: buildGenericCallback("nthroot", ActionType.CMD),
Expand All @@ -119,43 +118,16 @@ export const getKeyTranslator = (
}
},

LOG_B: (mathQuill) => {
mathQuill.typedText("log_");
mathQuill.keystroke("Right");
mathQuill.typedText("(");
mathQuill.keystroke("Left");
mathQuill.keystroke("Left");
},

LOG_N: (mathQuill) => {
mathQuill.write("log_{ }\\left(\\right)");
mathQuill.keystroke("Left"); // into parentheses
mathQuill.keystroke("Left"); // out of parentheses
mathQuill.keystroke("Left"); // into index
},

NTHROOT3: (mathQuill) => {
mathQuill.typedText("nthroot3");
mathQuill.keystroke("Right");
},

POW: (mathQuill) => {
const contents = mathQuill.latex();
mathQuill.typedText("^");

// If the input hasn't changed (for example, if we're
// attempting to add an exponent on an empty input or an empty
// denominator), insert our own "a^b"
if (mathQuill.latex() === contents) {
mathQuill.typedText("a^b");
}
},

// These need to be overwritten by the consumer
// if they're going to be used
DISMISS: () => {},
NOOP: () => {},
MANY: () => {},

NUM_0: buildGenericCallback("0"),
NUM_1: buildGenericCallback("1"),
Expand Down
36 changes: 0 additions & 36 deletions packages/math-input/src/components/keypad/button-assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1837,42 +1837,6 @@ export default function ButtonAsset({id}: Props): React.ReactElement {
</g>
</svg>
);

/**
* ANYTHING BELOW IS NOT YET HANDLED
*/
case "MANY":
case "NOOP":
case "PHI":
case "NTHROOT3":
case "POW":
case "LOG_B":
// placeholder
return (
<svg
width="40"
height="40"
viewBox="0 0 40 40"
fill="black"
xmlns="http://www.w3.org/2000/svg"
>
<text
y="20"
textLength="100%"
lengthAdjust="spacingAndGlyphs"
>
{id}
</text>
<text
y="35"
textLength="100%"
lengthAdjust="spacingAndGlyphs"
fill="red"
>
placeholder
</text>
</svg>
);
default:
// this line forces an exhaustive check of all keys;
// if a key is not handled, the compiler will complain.
Expand Down
34 changes: 0 additions & 34 deletions packages/math-input/src/data/key-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,6 @@ const KeyConfigs = (
ariaLabel: strings.theta,
}),
},
NOOP: {
...getDefaultOperatorFields({
key: "NOOP",
keyType: "EMPTY",
}),
},
// Input navigation
UP: {
...getDefaultOperatorFields({
Expand Down Expand Up @@ -366,14 +360,6 @@ const KeyConfigs = (
}),
},

// TODO(charlie): Use the numeral color for the 'Many' key.
MANY: {
...getDefaultOperatorFields({
key: "MANY",
keyType: "MANY",
}),
},

// NUMBERS
NUM_0: {
...getDefaultNumberFields({
Expand Down Expand Up @@ -687,26 +673,6 @@ const KeyConfigs = (
key: "z",
}),
},
PHI: {
...getDefaultValueFields({
key: "PHI",
}),
},
NTHROOT3: {
...getDefaultValueFields({
key: "NTHROOT3",
}),
},
POW: {
...getDefaultValueFields({
key: "POW",
}),
},
LOG_B: {
...getDefaultValueFields({
key: "LOG_B",
}),
},
});

export default KeyConfigs;
9 changes: 0 additions & 9 deletions packages/math-input/src/data/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export const KeyArray = [
"JUMP_INTO_NUMERATOR",
"JUMP_OUT_NUMERATOR",
"JUMP_OUT_DENOMINATOR", // Multi-functional keys.
"NOOP", // mobile native only
"MANY", // A custom key that captures an arbitrary number of symbols but has no 'default' symbol or action.
"NUM_0",
"NUM_1",
"NUM_2",
Expand Down Expand Up @@ -109,13 +107,6 @@ export const KeyArray = [
"X",
"Y",
"Z",

// Currently only used by
// Perseus' Expression MathInput
"PHI",
"NTHROOT3",
"POW",
"LOG_B",
] as const;

type Key = (typeof KeyArray)[number];
Expand Down
3 changes: 0 additions & 3 deletions packages/math-input/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ export const KeyTypes = [
// For buttons that modify the broader keypad state (e.g., by changing
// the visible pane).
"KEYPAD_NAVIGATION",
// For buttons that house multiple buttons and have no action
// themselves.
"MANY",
];
export type KeyType = (typeof KeyTypes)[number];
11 changes: 2 additions & 9 deletions packages/math-input/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ export type IconConfig = {
data: string;
};

export type NonManyKeyConfig = {
export type KeyConfig = {
id: Key;
type: Exclude<KeyType, "MANY">;
type: KeyType;
icon: IconConfig;
ariaLabel: string;
};

export type ManyKeyConfig = Omit<NonManyKeyConfig, "type"> & {
type: Extract<KeyType, "MANY">;
childKeyIds: ReadonlyArray<string>;
};

export type KeyConfig = NonManyKeyConfig | ManyKeyConfig;

export type KeypadConfiguration = {
keypadType: KeypadType;
extraKeys?: ReadonlyArray<Key>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const flags = {
"start-coords-ui-phase-2": true,
"start-coords-ui-point": true,
"start-coords-ui-polygon": true,
"start-coords-ui-angle": true,
},
} satisfies APIOptions["flags"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import * as React from "react";

import {EditorPage} from "..";
import {
angleWithStartingCoordsQuestion,
circleWithStartingCoordsQuestion,
linearSystemWithStartingCoordsQuestion,
linearWithStartingCoordsQuestion,
pointQuestionWithStartingCoords,
polygonQuestion,
polygonWithStartingCoordsQuestion,
quadraticWithStartingCoordsQuestion,
rayWithStartingCoordsQuestion,
segmentWithLockedFigures,
Expand Down Expand Up @@ -111,7 +112,19 @@ export const InteractiveGraphPoint = (): React.ReactElement => (
);

export const InteractiveGraphPolygon = (): React.ReactElement => {
return <EditorPageWithStorybookPreview question={polygonQuestion} />;
return (
<EditorPageWithStorybookPreview
question={polygonWithStartingCoordsQuestion}
/>
);
};

export const InteractiveGraphAngle = (): React.ReactElement => {
return (
<EditorPageWithStorybookPreview
question={angleWithStartingCoordsQuestion}
/>
);
};

export const MafsWithLockedFiguresCurrent = (): React.ReactElement => {
Expand Down
20 changes: 20 additions & 0 deletions packages/perseus-editor/src/components/__tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ describe("getDefaultGraphStartCoords", () => {
[-3, -3],
]);
});

test("should get default start coords for an angle graph", () => {
// Arrange
const graph: PerseusGraphType = {type: "angle"};
const range = [
[-10, 10],
[-10, 10],
] satisfies [Range, Range];
const step = [1, 1] satisfies [number, number];

// Act
const defaultCoords = getDefaultGraphStartCoords(graph, range, step);

// Default correct answer is 20 degree angle at (0, 0)
expect(defaultCoords).toEqual([
[7, 0],
[0, 0],
[6.5778483455013586, 2.394141003279681],
]);
});
});

describe("getSinusoidEquation", () => {
Expand Down
28 changes: 28 additions & 0 deletions packages/perseus-editor/src/components/start-coords-angle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {View} from "@khanacademy/wonder-blocks-core";
import * as React from "react";

import type {Coord, PerseusGraphType} from "@khanacademy/perseus";

type Props = {
startCoords: [Coord, Coord, Coord];
onChange: (startCoords: PerseusGraphType["startCoords"]) => void;
};

const StartCoordsAngle = (props: Props) => {
const {startCoords} = props;
return (
<View>
WIP
<br /> Start coords:
{startCoords.map((coord, index) => {
return (
<View key={index}>
{`Point ${index + 1}: (${coord[0]}, ${coord[1]})`}
</View>
);
})}
</View>
);
};

export default StartCoordsAngle;
Loading

0 comments on commit ffeea6d

Please sign in to comment.