Skip to content

Commit

Permalink
Upgrade Mafs to v0.19.0 (Domain-restricted functions) (#1451)
Browse files Browse the repository at this point in the history
## Summary:
With this upgrade, Mafs now supports domain restrictions when plotting functions. Once this upgrade is in place, locked functions will have domain restrictions as an option.

Issue: LEMS-2140

## Test plan:
1. Launch Storybook (yarn start)
1. Navigate to Perseus => Widgets => Interactive Graph => Locked Functions
   * [Minimum domain](http://localhost:6006/?path=/story/perseus-widgets-interactive-graph-locked-functions--domain-restricted-min): Starts at x=-5 and plots all values greater (i.e. to the right).
   * [Maximum domain](http://localhost:6006/?path=/story/perseus-widgets-interactive-graph-locked-functions--domain-restricted-max): Ends at x=5 and plots all values less than (i.e. to the left).
   * [Combined restrictions](http://localhost:6006/?path=/story/perseus-widgets-interactive-graph-locked-functions--domain-restricted-both): Starts at x=-5 and ends at x=5 and plots values in between.

## Expected Outcomes:

**Minimum domain:**
![Minimum domain](https://github.com/user-attachments/assets/2227accd-067a-40f9-b1cc-55bc53ddee86)

**Maximum domain:**
![Maximum domain](https://github.com/user-attachments/assets/888c19ad-8ce6-4b3c-97be-89e7a4adfa69)

**Combined restrictions:**
![Combined restrictions](https://github.com/user-attachments/assets/bdac1da4-c226-44f8-b7df-d556cd34ddea)

Author: mark-fitzgerald

Reviewers: benchristel, nishasy

Required Reviewers:

Approved By: benchristel, nishasy

Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1451
  • Loading branch information
mark-fitzgerald authored Jul 26, 2024
1 parent 7e71f8e commit 9bc4812
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-fireants-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

Upgrade Mafs Dependency to v0.19.0 for Domain Restricted Functions
2 changes: 1 addition & 1 deletion packages/perseus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@khanacademy/pure-markdown": "^0.3.7",
"@khanacademy/simple-markdown": "^0.13.0",
"@use-gesture/react": "^10.2.27",
"mafs": "0.18.7"
"mafs": "0.19.0"
},
"devDependencies": {
"@khanacademy/wonder-blocks-banner": "3.0.42",
Expand Down
6 changes: 1 addition & 5 deletions packages/perseus/src/perseus-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import type {Interval, vec} from "mafs";
// Range is replaced within this file with Interval, but it is used elsewhere
// and exported from the package, so we need to keep it around.
export type Range = Interval;
export type Domain = {
min?: number;
max?: number;
};
export type Size = [number, number];
export type CollinearTuple = [vec.Vector2, vec.Vector2];
export type ShowSolutions = "all" | "selected" | "none";
Expand Down Expand Up @@ -745,7 +741,7 @@ export type LockedFunctionType = {
[k: string]: any;
};
directionalAxis: "x" | "y";
domain?: Domain;
domain?: Interval;
};

export type PerseusGraphType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const DomainRestrictedMin = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI
{...mafsOptions}
question={segmentWithLockedFunction("sin(x)", {
domain: {min: -5},
domain: [-5, Infinity],
})}
/>
);
Expand All @@ -58,7 +58,7 @@ export const DomainRestrictedMax = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI
{...mafsOptions}
question={segmentWithLockedFunction("sin(x)", {
domain: {max: 5},
domain: [-Infinity, 5],
})}
/>
);
Expand All @@ -67,7 +67,7 @@ export const DomainRestrictedBoth = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI
{...mafsOptions}
question={segmentWithLockedFunction("sin(x)", {
domain: {min: -5, max: 5},
domain: [-5, 5],
})}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ describe("InteractiveGraphQuestionBuilder", () => {
color: "green",
strokeStyle: "dashed",
directionalAxis: "y",
domain: {min: -5, max: 5},
domain: [-5, 5],
})
.build();
const graph = question.widgets["interactive-graph 1"];
Expand All @@ -988,7 +988,7 @@ describe("InteractiveGraphQuestionBuilder", () => {
color: "green",
strokeStyle: "dashed",
directionalAxis: "y",
domain: {min: -5, max: 5},
domain: [-5, 5],
},
]);
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11679,10 +11679,10 @@ lz-string@^1.5.0:
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941"
integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==

mafs@0.18.7:
version "0.18.7"
resolved "https://registry.yarnpkg.com/mafs/-/mafs-0.18.7.tgz#1e17de9fc54d1a1253c6b0125fb42a5449344dae"
integrity sha512-NGUORtHXFZDK87A0R6wWNNZ/sTq8vpbwt92Z0RdT3nImZiNHRYEZ05X7Uv2Sd7WlqxdxJI1X/i1bSOjoLC3L9A==
mafs@0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/mafs/-/mafs-0.19.0.tgz#23b534d8602f194a7b1be7c4ff2e000afde9c240"
integrity sha512-mDHQhCbkIYjpuycY8mMV8O+o3ZOIGPgxliipcRE6aBGOXFvlwP2qvz9FQFdIr5W/BfcMY7CkgOqbPQJiKCr74w==
dependencies:
"@use-gesture/react" "^10.2.27"
computer-modern "^0.1.2"
Expand Down

0 comments on commit 9bc4812

Please sign in to comment.