-
Notifications
You must be signed in to change notification settings - Fork 364
[Interactive Graph] Add logarithm graph option in the Interactive Graph Editor #3425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ivyolamit
merged 4 commits into
main
from
LEMS-3953/pr6-logarithm-in-interactive-graph-editor
Apr 8, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
406676f
[LEMS-3953/pr6-logarithm-in-interactive-graph-editor] docs(changeset)…
ivyolamit ec6be37
[LEMS-3953/pr6-logarithm-in-interactive-graph-editor] [Interactive Gr…
ivyolamit 5bc53da
[LEMS-3953/pr6-logarithm-in-interactive-graph-editor] fix claude revi…
ivyolamit 1260652
[LEMS-3953/pr6-logarithm-in-interactive-graph-editor] fix lint error …
ivyolamit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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": minor | ||
| --- | ||
|
|
||
| Add logarithm graph option in the Interactive Graph Editor |
This file contains hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
...ditor/src/widgets/interactive-graph-editor/start-coords/start-coords-logarithm.module.css
This file contains hidden or 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,36 @@ | ||
| /* We have to use !important until wonder blocks is in the shared layer. */ | ||
| /* TODO(LEMS-3686): Remove the !important once we don't need it anymore. */ | ||
| .tile { | ||
| background-color: var( | ||
| --wb-semanticColor-core-background-instructive-subtle | ||
| ) !important; | ||
| margin-top: var(--wb-sizing-size_080) !important; | ||
| padding: var(--wb-sizing-size_120) !important; | ||
| border-radius: var(--wb-sizing-size_080) !important; | ||
| } | ||
|
|
||
| .row { | ||
| display: flex !important; | ||
| flex-direction: row !important; | ||
| align-items: center !important; | ||
| } | ||
|
|
||
| .textFieldWrapper { | ||
| width: var(--wb-sizing-size_800) !important; | ||
| } | ||
|
|
||
| .equationSection { | ||
| margin-top: var(--wb-sizing-size_120) !important; | ||
| } | ||
|
|
||
| .equationBody { | ||
| background-color: var( | ||
| --wb-semanticColor-core-background-neutral-subtle | ||
| ) !important; | ||
| border: var(--wb-border-width-thin) solid | ||
| var(--wb-semanticColor-core-border-neutral-subtle) !important; | ||
| margin-top: var(--wb-sizing-size_080) !important; | ||
| padding-left: var(--wb-sizing-size_080) !important; | ||
| padding-right: var(--wb-sizing-size_080) !important; | ||
| font-size: var(--wb-font-size-xSmall) !important; | ||
| } | ||
118 changes: 118 additions & 0 deletions
118
...rseus-editor/src/widgets/interactive-graph-editor/start-coords/start-coords-logarithm.tsx
This file contains hidden or 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,118 @@ | ||
| import {View} from "@khanacademy/wonder-blocks-core"; | ||
| import {Strut} from "@khanacademy/wonder-blocks-layout"; | ||
| import {spacing} from "@khanacademy/wonder-blocks-tokens"; | ||
| import {BodyMonospace, BodyText} from "@khanacademy/wonder-blocks-typography"; | ||
| import * as React from "react"; | ||
|
|
||
| import CoordinatePairInput from "../../../components/coordinate-pair-input"; | ||
| import ScrolllessNumberTextField from "../../../components/scrollless-number-text-field"; | ||
|
|
||
| import styles from "./start-coords-logarithm.module.css"; | ||
| import {getLogarithmEquation} from "./util"; | ||
|
|
||
| import type {Coord} from "@khanacademy/perseus"; | ||
|
|
||
| type LogarithmStartCoords = { | ||
| coords: [Coord, Coord]; | ||
| asymptote: number; | ||
| }; | ||
|
|
||
| type Props = { | ||
| startCoords: LogarithmStartCoords; | ||
| onChange: (startCoords: LogarithmStartCoords) => void; | ||
| }; | ||
|
|
||
| const StartCoordsLogarithm = (props: Props) => { | ||
| const {startCoords, onChange} = props; | ||
| const {coords, asymptote} = startCoords; | ||
|
|
||
| // Local state for the asymptote x-value text field so the user can type | ||
| // freely without the field resetting mid-keystroke. Pattern from StartCoordsCircle. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The AI really likes to say where it stole things from, but I'm not sure "Pattern from StartCoordsCircle." is particularly helpful |
||
| const [asymptoteXState, setAsymptoteXState] = React.useState( | ||
| asymptote.toString(), | ||
| ); | ||
|
|
||
| // Sync local state when props change (e.g. "Use default start coordinates" button). | ||
| React.useEffect(() => { | ||
| setAsymptoteXState(asymptote.toString()); | ||
| }, [asymptote]); | ||
|
|
||
| function handleAsymptoteXChange(newValue: string) { | ||
| // Update the local state to update the input field immediately. | ||
| setAsymptoteXState(newValue); | ||
|
|
||
| // Assume the user is still typing. Don't update props until a valid number. | ||
| if (isNaN(+newValue) || newValue === "") { | ||
| return; | ||
| } | ||
|
|
||
| // Update the props (updates the graph). | ||
| const newX = parseFloat(newValue); | ||
| // Spread coords into a new array so that startCoords always gets a | ||
| // new reference. StatefulMafsGraph's useEffect only watches startCoords, | ||
| // so a new reference is required to trigger reinitialization even when | ||
| // only the asymptote changes. (Same reason circle creates a new | ||
| // {center, radius} object on every onChange call.) | ||
| onChange({ | ||
| coords: [coords[0], coords[1]], | ||
| asymptote: newX, | ||
| }); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Current equation */} | ||
| <View className={styles.equationSection}> | ||
| <BodyText>Starting equation:</BodyText> | ||
| <BodyMonospace className={styles.equationBody}> | ||
| {getLogarithmEquation(coords, asymptote)} | ||
| </BodyMonospace> | ||
| </View> | ||
|
|
||
| {/* Points UI */} | ||
| <View className={styles.tile}> | ||
| {/* Point 1 */} | ||
| <View className={styles.row}> | ||
| <BodyText weight="bold">Point 1:</BodyText> | ||
| <Strut size={spacing.small_12} /> | ||
| <CoordinatePairInput | ||
| coord={coords[0]} | ||
| labels={["x", "y"]} | ||
| onChange={(value) => | ||
| onChange({coords: [value, coords[1]], asymptote}) | ||
| } | ||
| /> | ||
| </View> | ||
| <Strut size={spacing.small_12} /> | ||
|
|
||
| {/* Point 2 */} | ||
| <View className={styles.row}> | ||
| <BodyText weight="bold">Point 2:</BodyText> | ||
| <Strut size={spacing.small_12} /> | ||
| <CoordinatePairInput | ||
| coord={coords[1]} | ||
| labels={["x", "y"]} | ||
| onChange={(value) => | ||
| onChange({coords: [coords[0], value], asymptote}) | ||
| } | ||
| /> | ||
| </View> | ||
| <Strut size={spacing.small_12} /> | ||
|
|
||
| {/* Asymptote x-value — single number, mirroring radius in StartCoordsCircle */} | ||
| <BodyText weight="bold" tag="label" className={styles.row}> | ||
| Asymptote x = | ||
| <Strut size={spacing.small_12} /> | ||
| <View className={styles.textFieldWrapper}> | ||
| <ScrolllessNumberTextField | ||
| value={asymptoteXState} | ||
| onChange={handleAsymptoteXChange} | ||
| /> | ||
| </View> | ||
| </BodyText> | ||
| </View> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default StartCoordsLogarithm; | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly wonder how many of these
!importants are necessary. I would love it if we made a task to clean up as many of these as possible as part of our project (aka before LEMS-3686, which might be a while).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now it's necessary in editor side. But I agree let's revisit this before our project ends if that ticket linked is something we can pickup as cleanup task.