Skip to content

feat: add showAngle field to LockedPolygonPointType#3730

Open
mojadem wants to merge 2 commits into
mojadem/locked-polygon-point/1from
mojadem/locked-polygon-point/2
Open

feat: add showAngle field to LockedPolygonPointType#3730
mojadem wants to merge 2 commits into
mojadem/locked-polygon-point/1from
mojadem/locked-polygon-point/2

Conversation

@mojadem

@mojadem mojadem commented Jun 5, 2026

Copy link
Copy Markdown

Summary

This is a follow-up to #3705.

  • Added showAngle to locked polygon points, defaulting to false for parsed legacy data and newly created
    points.
  • Reused existing polygon angle-label rendering so locked polygons can selectively show interior angle labels
    per vertex.
  • Added editor controls for toggling angle labels on individual locked polygon points.
  • Updated defaults, fixtures, and tests for the new field.

Test plan

  • pnpm test

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Size Change: +156 B (+0.03%)

Total Size: 507 kB

📦 View Changed
Filename Size Change
packages/perseus-core/dist/es/index.item-splitting.js 12.1 kB +15 B (+0.12%)
packages/perseus-core/dist/es/index.js 26.2 kB +16 B (+0.06%)
packages/perseus-editor/dist/es/index.js 105 kB +40 B (+0.04%)
packages/perseus/dist/es/index.js 199 kB +85 B (+0.04%)
ℹ️ 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-linter/dist/es/index.js 9.42 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.55 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR3730

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

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

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

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

{points.map((point, i) => {
const previous = points.at(i - 1);
const next = points.at((i + 1) % points.length);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is mirroring the pattern in packages/perseus/src/widgets/interactive-graphs/graphs/polygon.tsx.

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.

We could probably improve the undefined check to avoid the strict boolean expressions :) I think the old logic predated the inclusion of the linter rule

@github-actions github-actions Bot added schema-change Attached to PRs when we detect Perseus Schema changes in it item-splitting-change labels Jun 5, 2026
…ld to `LockedPolygonPointType`. This option controls the display of an angle label per-vertex. It defaults to false.

@jeremywiebe jeremywiebe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the Chromatic version of Storybook, the editor layout looks pretty janky.

Image

Could you double-check that before landing, please? If you need design help, please ask Caitlyn about the layout.

Comment on lines 348 to 359
<Button
kind="tertiary"
startIcon={plusCircle}
onClick={() => {
props.onChangeProps({
points: [...points, {coord: [0, 0]}],
points: [
...points,
{coord: [0, 0], showAngle: false},
],
});
}}
>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this button predates your change, but would you mind adding an aria-label to this button (it took me a bit to decipher that it was the "add point" button... right? 😬 ).

showAngles={point.showAngle}
// Locked polygons don't snap; "grid" is chosen as a
// default to preserve decimal angle labels.
snapTo="grid"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thought: This is an unfortunate instance where we propagate a value from higher up and its meaning is completely different inside this component. Ideally, this prop would be named something like roundLabelAngleToInteger or something.

No change required.

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.

Yeah this does seem like a potential ticket I could throw in our LEMS backlog, since it's a little outside of this PR


const parseLockedPolygonPointType = object({
coord: pairOfNumbers,
showAngle: defaulted(boolean, () => false),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@SonicScrewdriver SonicScrewdriver 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.

Great work! Overall this is nearly there I think we just need to polish up the design a little!

showAngle: newValue,
};
props.onChangeProps({points: newPoints});
}}

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.

I do think this needs some tweaking in the editor UI, as the option is clipping and doesn't quite match the rest of the styles. Unfortunately we're quite constrained in the width of the editor settings area right now. I'm happy to pair if you want to discuss how we could approach the layout!

I did notice that the start coordinates handle the extra input for a point by adding a new surrounding box:

Image

{points.map((point, i) => {
const previous = points.at(i - 1);
const next = points.at((i + 1) % points.length);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions

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.

We could probably improve the undefined check to avoid the strict boolean expressions :) I think the old logic predated the inclusion of the linter rule

showAngles={point.showAngle}
// Locked polygons don't snap; "grid" is chosen as a
// default to preserve decimal angle labels.
snapTo="grid"

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.

Yeah this does seem like a potential ticket I could throw in our LEMS backlog, since it's a little outside of this PR

{coord: [-6.5, -4.5], showAngle: false},
],
weight,
color: "pink",

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.

It'd be great if you could also add a story to this storybook regression test where showAngle is on for a locked polygon. These stories get snapshot and checked by Chromatic/Storybook so that we're notified on a PR if anything changes visually, which has been quite helpful for our Interactive Graph Widget.

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

Labels

item-splitting-change olc-5.0.7fb98 schema-change Attached to PRs when we detect Perseus Schema changes in it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants