-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View Locked Function in the Interactive Graph (#1383)
## Summary: Existing locked figures include lines that are straight. The need exists to also have lines that follow a function/equation. Plotting arbitrary functions as a locked figure will provide content creators with a powerful drawing tool for interactive graphs. Issue: LEMS-1944 ## Test plan: 1. Launch Storybook (yarn start) 1. Navigate to Perseus => Widgets => Interactive Graph => [Locked Functions](http://localhost:6006/?path=/docs/perseus-widgets-interactive-graph-locked-functions--docs) 1. Note that there are multiple stories available to demonstrate various functions and options ## Examples: **Quadratic** ![Quadratic](https://github.com/Khan/perseus/assets/13896410/70abc39b-c1ec-482a-bb63-793626fe28a8) **Sine** ![Sine](https://github.com/Khan/perseus/assets/13896410/c4617d53-5fda-47f4-8792-d3fb4a73942a) **Logarithmic** ![Logarithmic](https://github.com/Khan/perseus/assets/13896410/af903a44-16ad-4d9c-bbf8-5ba95ccd4925) Author: mark-fitzgerald Reviewers: nishasy, mark-fitzgerald, #perseus Required Reviewers: Approved By: 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), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1383
- Loading branch information
1 parent
d229cea
commit 4b56e10
Showing
13 changed files
with
418 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
View Locked Functions in the Interactive Graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/perseus/src/widgets/__stories__/locked-functions.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import * as React from "react"; | ||
|
||
import {RendererWithDebugUI} from "../../../../../testing/renderer-with-debug-ui"; | ||
import {segmentWithLockedFunction} from "../__testdata__/interactive-graph.testdata"; | ||
|
||
export default { | ||
title: "Perseus/Widgets/Interactive Graph/Locked Functions", | ||
}; | ||
|
||
const mafsOptions = { | ||
apiOptions: { | ||
flags: { | ||
mafs: { | ||
segment: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
type StoryArgs = Record<any, any>; | ||
|
||
export const DefaultSettings = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction()} | ||
/> | ||
); | ||
|
||
export const StyledSettings = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("x^2", { | ||
color: "green", | ||
strokeStyle: "dashed", | ||
})} | ||
/> | ||
); | ||
|
||
export const FunctionOfY = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("y^2", { | ||
directionalAxis: "y", | ||
})} | ||
/> | ||
); | ||
|
||
export const DomainRestrictedMin = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("sin(x)", { | ||
domain: {min: -5}, | ||
})} | ||
/> | ||
); | ||
|
||
export const DomainRestrictedMax = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("sin(x)", { | ||
domain: {max: 5}, | ||
})} | ||
/> | ||
); | ||
|
||
export const DomainRestrictedBoth = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("sin(x)", { | ||
domain: {min: -5, max: 5}, | ||
})} | ||
/> | ||
); | ||
|
||
export const Quadratic = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("x^2 + 2x + 3")} | ||
/> | ||
); | ||
|
||
export const QubicPolynomial = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("(1/3)x^3 - 2x^2 + 3x - 4")} | ||
/> | ||
); | ||
|
||
export const Tangent = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("tan(x)")} | ||
/> | ||
); | ||
|
||
export const ArcTangent = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("arctan(x)")} | ||
/> | ||
); | ||
|
||
export const Logarithmic = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("log(x)")} | ||
/> | ||
); | ||
|
||
export const Exponent = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("e^x")} | ||
/> | ||
); | ||
|
||
export const AbsoluteValue = (args: StoryArgs): React.ReactElement => ( | ||
<RendererWithDebugUI | ||
{...mafsOptions} | ||
question={segmentWithLockedFunction("abs(x)")} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.