[Interactive Graph] Add tangent graph rendering, SR strings, and equation string#3354
Open
ivyolamit wants to merge 3 commits intoLEMS-3955/tangent-state-managementfrom
Open
[Interactive Graph] Add tangent graph rendering, SR strings, and equation string#3354ivyolamit wants to merge 3 commits intoLEMS-3955/tangent-state-managementfrom
ivyolamit wants to merge 3 commits intoLEMS-3955/tangent-state-managementfrom
Conversation
…tangent graph visual component, add Storybook coverage, SR strings, and equation string for supporting Tangent graph in Interactive Graph
…nt graph rendering, SR strings, and equation string
Contributor
🗄️ Schema Change: No Changes ✅ |
Contributor
|
Size Change: +1.05 kB (+0.22%) Total Size: 487 kB
ℹ️ View Unchanged
|
Contributor
🛠️ Item Splitting: No Changes ✅ |
Contributor
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (50d3194) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR3354If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR3354If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR3354 |
Contributor
Author
|
Summary of the tangent implementation
|
packages/perseus/src/widgets/interactive-graphs/graphs/tangent.tsx
Outdated
Show resolved
Hide resolved
…ing, where it shows the vertical lines
This was referenced Mar 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
PR series to add tangent graph support to the Interactive Graph widget:
This is the fourth PR in a series to add tangent graph support to the Interactive Graph widget (LEMS-3955). It adds the rendering layer — the Mafs component, accessibility strings, equation string generation, and Storybook coverage.
Created the tangent graph visual component, add Storybook coverage, SR strings, and equation string for supporting Tangent graph in Interactive Graph.
tangent.tsx) withrenderTangentGraph(),computeTangent(), keyboard constraints, and screen reader descriptionssrTangentGraph,srTangentInflectionPoint,srTangentSecondPoint,srTangentDescription,srTangentInteractiveElements)mafs-graph.tsxplaceholder with realrenderTangentGraph()callinteractive-graph.tsxequation string placeholder withgetTangentEquationString()Implementation notes
Tangent component follows the sinusoid pattern.
tangent.tsxmirrorssinusoid.tsxstructurally: two movable control points, coefficient calculation with a ref-based fallback for invalid states, and the same keyboard constraint logic that prevents same-x points.Asymptote handling (vertical line bug fix). Mafs
Plot.OfXrenders a single SVG<path>that draws vertical lines across discontinuities at asymptotes. To fix this, the tangent curve is split into segments between asymptotes:getAsymptotePositions()computes asymptote x-positions within the visible range:x = (c + π/2 + nπ) / bgetPlotSegments()splits the x-range into segments between asymptotes with a small epsilon margin (0.01)Plot.OfXwith adomainprop, so Mafs never draws across a discontinuitycomputeTangent()also returns NaN near asymptotes as a defensive backup. The proximity formula was corrected from the POC — the POC's((arg / Math.PI + 0.5) % 1) - 0.5measures distance from zero crossings (inflection points), not asymptotes. The corrected formula((arg - Math.PI/2) / Math.PI) % 1correctly targets asymptotes atarg = π/2 + nπ.Two
getTangentCoefficientsfunctions exist. The one intangent.tsxreturnsNamedTangentCoefficient | undefined(named object withundefinedfallback for same-x points) for rendering use. The one inkmath/coefficients.tsreturnsTangentCoefficient(numeric tuple, returnsInfinityfor same-x) for scoring use. The UI prevents the same-x case via the reducer's same-x guard, so the difference only matters as a defensive measure.Screen reader descriptions. The tangent graph uses "inflection point" for the first control point (where the curve crosses the midline) and "control point" for the second point (a quarter-period away). This differs from sinusoid which uses "midline intersection" and "maximum/minimum point" — tangent doesn't have a meaningful max/min since it approaches ±∞.
Equation string.
getTangentEquationString()formatsy = a*tan(b*x - c) + dusing the same pattern asgetSinusoidEquationString()but usinggetTangentCoefficientsfrom kmath.No feature flag gate in rendering. The tangent graph renders unconditionally once the graph type is set to "tangent". The feature flag gate is in the editor (PR 6), which controls whether content creators can select "tangent" as a graph type. This follows the existing pattern — no other graph types check feature flags at render time.
References
Co-Authored by Claude Code (Opus)
Issue: LEMS-3955
Test plan:
pnpm tsc— no type errorspnpm lint— no lint errorspnpm prettier . --check— formatting cleanpnpm knip— no unused exportspnpm storybook)