Skip to content

Render visible point labels on interactive graphs#3749

Draft
EmiliaPalaghita wants to merge 9 commits into
mainfrom
showlabels/02-renderer-and-flag
Draft

Render visible point labels on interactive graphs#3749
EmiliaPalaghita wants to merge 9 commits into
mainfrom
showlabels/02-renderer-and-flag

Conversation

@EmiliaPalaghita

@EmiliaPalaghita EmiliaPalaghita commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Renders visible point labels on interactive graphs when showPointLabels: true is set on the graph JSON and the perseus-enable-point-label-field feature flag is on.

All graph types are covered with the exception of vector and none.

Schema and parser for showPointLabels already shipped in #3725.

The PR covers the following requirements:

  • the implementation is using a new feature flag perseus-enable-point-label-field
  • the visible labels are implemented using TeX as requrested by the UX, similarly to the locked figures
  • the labels must have the halo effect white border around
  • the labels should not overlap with the rest of the graph at various dragged points

Known Issues

The label overlap is more technically complex and requires potential handling on each graph type. As a partial solution, this PR is moving the labels based on 2 conditions:

  • quadrant placement: label sits outside the plotted region towards the associated corners
  • edge of the diagram: the labels bounces back if in close proximity of the edge

An attempt to a more appropriate solution will be attempted in a follow-up PR.

Storybook

The flag appears in the Storybook toolbar's "Feature Flags" dropdown automatically (the toolbar iterates PerseusFeatureFlags). Two stories also pre-set the flag via globals: {featureFlags: ["perseus-enable-point-label-field"]} so they're useful out of the box without toolbar fiddling: PointWithVisibleLabels and PolygonWithVisibleLabels.

Test plan

  • pnpm tsc
  • pnpm lint
  • pnpm test
    • New movable-point-labels.test.ts
    • New movable-point-labels-layer.test.tsx
    • New mafs-graph.test.tsx
  • Manual Storybook verification of all graph types with the flag on

Related

Issue: AITQ-385

…nt labels on interactive graphs when the`perseus-enable-point-label-field` flag is on and the graph's`showPointLabels` field is true. Labels render via TeX in an HTML overlayso authors can include math (`$A$`, `$\theta$`, …) and stay outside theplotted region as a point is dragged toward an edge. Covers point,circle, angle, polygon, sinusoid, linear, linear-system, ray, andsegment in this release; remaining graph types follow in a per-graphseries. Existing content that sets `pointLabels` for screen-readerpurposes is unaffected — visible rendering requires both the flag and`showPointLabels: true`.
@EmiliaPalaghita EmiliaPalaghita self-assigned this Jun 9, 2026
@EmiliaPalaghita EmiliaPalaghita changed the title docs(changeset): Render visible point labels on interactive graphs when theperseus-enable-point-label-field flag is on and the graph'sshowPointLabels field is true. Labels render via TeX in an HTML overlayso authors can include math ($A$, $\theta$, …) and stay outside theplotted region as a point is dragged toward an edge. Covers point,circle, angle, polygon, sinusoid, linear, linear-system, ray, andsegment in this release; remaining graph types follow in a per-graphseries. Existing content that sets pointLabels for screen-readerpurposes is unaffected — visible rendering requires both the flag andshowPointLabels: true. docs(changeset): Render visible point labels on interactive graphs Jun 9, 2026
@EmiliaPalaghita EmiliaPalaghita changed the title docs(changeset): Render visible point labels on interactive graphs Render visible point labels on interactive graphs Jun 9, 2026
@github-actions github-actions Bot added schema-change Attached to PRs when we detect Perseus Schema changes in it and removed schema-change Attached to PRs when we detect Perseus Schema changes in it labels Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR3749

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

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

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

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

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Size Change: +1.5 kB (+0.29%)

Total Size: 509 kB

📦 View Changed
Filename Size Change
packages/perseus-core/dist/es/index.js 26.3 kB +22 B (+0.08%)
packages/perseus/dist/es/index.js 201 kB +1.47 kB (+0.74%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.6 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.32 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 12 kB
packages/perseus-editor/dist/es/index.js 105 kB
packages/perseus-linter/dist/es/index.js 9.8 kB
packages/perseus-score/dist/es/index.js 10.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 8.6 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@ivyolamit ivyolamit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@EmiliaPalaghita I've done a first pass on your draft PR. I think the logic you have here make sense to me. I've added few suggestions, comments, and question. And I think what's not clear to me yet is how will khan migo access this? 🤔 from what you mentioned before it's something that will be used by khan migo, i'm also not super familiar with our api or how khan migo is calling our widgets atm.

Comment thread packages/perseus-editor/src/testing/feature-flags-util.ts Outdated
Comment thread packages/perseus/src/testing/feature-flags-util.ts Outdated
Comment thread packages/perseus/src/widgets/interactive-graphs/graphs/angle.tsx
Comment thread packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx Outdated
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