[Interactive Graph] POC Add logarithm graph in Interactive Graph widget#3322
[Interactive Graph] POC Add logarithm graph in Interactive Graph widget#3322
Conversation
🗄️ Schema Change: Changes Detected
|
|
Size Change: +4.65 kB (+0.96%) Total Size: 491 kB
ℹ️ View Unchanged
|
🛠️ Item Splitting: Changes Detected
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (1d208b0) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR3322If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR3322If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR3322 |
96dafe6 to
915a9d7
Compare
| const FOCUS_RING_PAD = 2; | ||
| const FOCUS_RING_STROKE = 2; | ||
|
|
||
| function AsymptoteDragHandle(props: { |
There was a problem hiding this comment.
add this in packages/perseus/src/widgets/interactive-graphs/graphs/components/
There was a problem hiding this comment.
This file is very long, this should only contain the LogarithmGraph move other logic in its own component or util file. Maybe have packages/perseus/src/widgets/interactive-graphs/graphs/components/logarithm/ folder to contain all files and logic related to logarithm.
| <OptionItem value="linear" label="Linear function" /> | ||
| <OptionItem value="quadratic" label="Quadratic function" /> | ||
| <OptionItem value="sinusoid" label="Sinusoid function" /> | ||
| <OptionItem value="logarithm" label="Logarithm function" /> |
There was a problem hiding this comment.
Hide this behind a feature flag
| }; | ||
| } | ||
|
|
||
| if (state.type === "logarithm" && initialGraph.type === "logarithm") { |
There was a problem hiding this comment.
Base on new-graph-type.md guide
Make sure this is added before the final throw at the bottom of the function.
|
|
||
| static getLogarithmEquationString(props: Props): string { | ||
| const coords = | ||
| // @ts-expect-error - TS2339 - Property 'coords' does not exist on type 'PerseusGraphType'. |
There was a problem hiding this comment.
fix this in actual implementation
| // @ts-expect-error - TS2339 - Property 'coords' does not exist on type 'PerseusGraphType'. | ||
| props.userInput.coords || | ||
| InteractiveGraph.defaultLogarithmCoords(props); | ||
| // @ts-expect-error - TS2339 - Property 'asymptote' does not exist on type 'PerseusGraphType'. |
There was a problem hiding this comment.
fix this in actual implementation
| [0.55, 0.5], | ||
| [0.75, 0.75], | ||
| ]; | ||
| // @ts-expect-error - TS2345 - Argument of type 'number[][]' is not assignable to parameter of type 'readonly Coord[]'. |
There was a problem hiding this comment.
fix this in actual implementation
| }; | ||
| } | ||
|
|
||
| // Compute logarithm coefficients from two points and an asymptote. |
There was a problem hiding this comment.
This file is already getting long, move this in a different file for code maintainability.
There was a problem hiding this comment.
Missing logic based on guide in start-coords-settings.tsx
🔗 https://github.com/Khan/perseus/blob/main/packages/perseus/src/widgets/interactive-graphs/__docs__/notes/new-graph-type.md#11-add-start-coords-support-in-the-editor
| type: props.userInput.type, | ||
| startCoords: props.userInput.startCoords, | ||
| }; | ||
| case "logarithm": |
There was a problem hiding this comment.
Hide this behind a feature flag
…logarithm answer type in Interactive Graph
…dd logarithm graph in Interactive Graph widget
1. Keyboard constraint now enforces same-side-of-asymptote — Added check (coord[X] > asymptoteX) !== otherPointSide to isValidPosition(). Points can no longer arrow-key past the asymptote.
2. Keyboard constraint no longer risks infinite loop — Replaced the two separate if-then-skip checks with a unified isValidPosition() validator inside a bounded loop (max 3 attempts). If no valid position is found, the point stays in place instead of returning an invalid coordinate.
3. Stale comment fixed — "Draggable dashed vertical asymptote line" → "Draggable vertical asymptote line"
Accessibility Fixed
1. Asymptote aria-label is now localized — Added srLogarithmAsymptote string to strings.ts (both translatable definition and mock). The label now reads: "Vertical asymptote at x equals {x}. Use left and right arrow keys to move." — formatted with srFormatNumber for locale support.
2. Asymptote position changes are now announced — Added aria-live="polite" to the asymptote <g> element. When the aria-label updates on move, screen readers will announce the new position.
3. role="button" kept as-is — After checking the codebase, all draggable elements (movable lines, points, circles) consistently use role="button". Changing to role="slider" would break the established pattern.
…the keyboard navigation, the drag handle cannot move cross the curve
…ng the curve to the opposite side of the asymptote
2a771f6 to
1d208b0
Compare
| // would land between or on the curve points, snap past all points in the | ||
| // movement direction. This mirrors the reducer's snap-through logic but | ||
| // uses explicit direction (keyboard always moves one step at a time). | ||
| const constrainAsymptoteKeyboard = ( |
There was a problem hiding this comment.
move this in a util file
Summary:
POC Add logarithm answer type in Interactive Graph
f(x) = a * ln(b * x + c)with two movable curve points and a fully draggable vertical asymptoteKey features
useDraggable+SVGLinepattern asMovableLine, with a pill-shaped drag handle for visual affordancePlot.OfXwith a restricteddomainprop (no segment-splitting workaround needed, unlike tangent)approximateDeepEqualcomparison of[a, b, c]coefficients (no canonical normalization needed)Files changed
perseus-core/data-schema.ts, parser, generatorgraphs/logarithm.tsx(new — 430 lines)doMovePoint+doMoveCenter), init, statescore-interactive-graph.tswithgetLogarithmCoeffs()mafs-graph.tsx,interactive-graph.tsx, state-to-graph conversionstrings.ts(5 new SR strings), AI utilsIssue: LEMS-3950
Co-Authored by Claude (Opus)
Test plan: