Skip to content

[ Interactive Graph | Vector Graph ] PR2: State Management#3434

Open
SonicScrewdriver wants to merge 3 commits intoLEMS-3971/vector-pr1from
LEMS-3971/vector-pr2
Open

[ Interactive Graph | Vector Graph ] PR2: State Management#3434
SonicScrewdriver wants to merge 3 commits intoLEMS-3971/vector-pr1from
LEMS-3971/vector-pr2

Conversation

@SonicScrewdriver
Copy link
Copy Markdown
Contributor

@SonicScrewdriver SonicScrewdriver commented Mar 31, 2026

Summary

This PR was created with the help of AI, albeit with heavy oversight and review.

This is part of a series of PRs implementing the vector graph type for the Interactive Graph widget:

PR1 – type definitions and schema
▶️ PR2 – state management (this PR)
PR3 – rendering & accessibility
PR4 – scoring
PR5 – editor support

Issue: LEMS-3971

  • Added state management logic for the vector graph type
  • The graph is now stateful and interactive but not yet visible — rendering still throws "Not implemented" from PR 1's stub. This is a pure additive change — no runtime behavior is altered and all existing tests continue to pass.

Changes:

  • interactive-graph-action.ts — Adds vector: { moveTip, moveVector } to the actions object. moveTip dispatches movePoint(1, destination) for the tip (the only draggable point). moveVector dispatches moveLine(0, delta) for body translation.
  • initialize-graph-state.ts — Replaces the PR 1 stub with a real case "vector". Adds and exports getVectorCoords() with the standard three-path fallback: explicit coords → startCoords → normalized defaults. Default is a horizontal vector from [-5, 0] to [5, 0].
  • interactive-graph-reducer.ts — Adds vector case in doMovePoint (snap to grid, enforce bounds, reject if tip would overlap with tail). Adds "vector" to the existing doMoveLine case alongside "linear" / "ray" for body translation.
  • interactive-graph-state.ts — Adds getGradableGraph() branch for vector (coords passthrough, same shape as ray).
  • interactive-graph-question-builder.ts — Adds withVector() builder method and VectorGraphConfig class (matches RayGraphConfig pattern).
  • interactive-graph-widget-generator.ts — Adds generateIGVectorGraph() generator function (new pattern, replacing builder long-term).
  • perseus-core/src/index.ts — Re-exports generateIGVectorGraph.
  • perseus/src/index.ts — Re-exports getVectorCoords.
  • interactive-graph.testdata.ts — Adds vectorQuestion and vectorQuestionWithDefaultCorrect test fixtures.

Test plan:

  • pnpm tsc — no new type errors
  • pnpm test packages/perseus/src/widgets/interactive-graphs/reducer/ — 143 tests pass, including 9 new vector tests:
    • 3 initialization tests (explicit coords, startCoords fallback, defaults)
    • 3 moveTip tests (basic move, hasBeenInteractedWith, overlap rejection)
    • 3 moveVector tests (body translation, hasBeenInteractedWith, bounds enforcement)
  • No existing interactive graph tests regress

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions bot added item-splitting-change schema-change Attached to PRs when we detect Perseus Schema changes in it labels Mar 31, 2026
@SonicScrewdriver SonicScrewdriver changed the title docs(changeset): Implementation of state management logic for new Vector graph [ Interactive Graph | Vector Graph ] PR2: State Management Mar 31, 2026
@github-actions github-actions bot removed the schema-change Attached to PRs when we detect Perseus Schema changes in it label Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (68ae5c4) and published it to npm. You
can install it using the tag PR3434.

Example:

pnpm add @khanacademy/perseus@PR3434

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3434

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR3434

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

Size Change: +88 B (+0.02%)

Total Size: 495 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 25.1 kB +12 B (+0.05%)
packages/perseus/dist/es/index.js 193 kB +76 B (+0.04%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.5 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.21 kB
packages/math-input/dist/es/index.js 98.5 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 11.9 kB
packages/perseus-editor/dist/es/index.js 101 kB
packages/perseus-linter/dist/es/index.js 9.3 kB
packages/perseus-score/dist/es/index.js 9.66 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 8.09 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants