Skip to content

Conversation

SonicScrewdriver
Copy link
Contributor

@SonicScrewdriver SonicScrewdriver commented Jun 23, 2025

Summary:

This PR improves our labelPosition calculations for our Axis Labels so that they take the length of the tick step labels into account.

We're doing this by (roughly) calculating the width of the labels by getting the maximum number of digits between the axis label (for example: yMin = 1000, tickStep = 1) and the tickStep (for example: yMin = 0, tickStep = 0.001). This should cover all the graph edge cases.

While working on this ticket, I was unable to get Storybook to hot reload as it was throwing errors that we were unable to quick reload React due to the exported functions in our React component files. I have moved the offending functions into their relevant util files, with the added bonus of cleaning the component files up a little.

Issue: LEMS-3215

Test plan:

  • Updated tests pass

Screenshot:

Screenshot 2025-06-23 at 3 56 46 PM

Copy link
Contributor

github-actions bot commented Jun 23, 2025

Size Change: +211 B (+0.04%)

Total Size: 474 kB

Filename Size Change
packages/perseus/dist/es/index.js 202 kB +211 B (+0.1%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.7 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.js 20.6 kB
packages/perseus-editor/dist/es/index.js 91.3 kB
packages/perseus-linter/dist/es/index.js 7.14 kB
packages/perseus-score/dist/es/index.js 9.22 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.56 kB
packages/pure-markdown/dist/es/index.js 1.22 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Jun 23, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2635

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

./tools/bump_perseus_version.ts -t PR2635

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

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

@SonicScrewdriver SonicScrewdriver requested a review from nishasy June 23, 2025 22:57
Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

Just waiting for the confirmation that this resolves the issue in the article we saw in prod, and then I'll approve!

maxDigits * (fontSize * 0.75) +
(graphInfo.range[Y][MIN] < 0 && graphInfo.range[X][MIN] <= 0
? fontSize * 0.5
: 0); // Add space for negative sign if needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!


// Return the maximum of the two
return Math.max(maxDigitsInRange, tickStepSigFigs);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an FYI that we have this upcoming ticket that makes it so that all axis labels will have the same number of decimal places. I think your solution already covers this case, so I don't think we'll have to change anything!

https://khanacademy.atlassian.net/browse/LEMS-3216

const isRelativelyCloseToZero =
graphInfo.range[X][MIN] < 0 &&
Math.abs(graphInfo.range[X][MIN]) <
(graphInfo.range[X][MAX] - graphInfo.range[X][MIN]) * 0.05;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yessss

if (isRelativelyCloseToZero) {
yAxisLabelLocation[X] =
yAxisLabelLocation[X] - graphInfo.range[X][MIN];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

YESSSSS

Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

Yes! I'm gonna call it there. Nice work whacking all those moles.

@SonicScrewdriver SonicScrewdriver merged commit a203332 into main Jul 2, 2025
8 checks passed
@SonicScrewdriver SonicScrewdriver deleted the label-without-a-cause branch July 2, 2025 23:08
handeyeco pushed a commit that referenced this pull request Jul 7, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @khanacademy/[email protected]

### Major Changes

- [#2666](#2666)
[`d738f44d5`](d738f44)
Thanks [@benchristel](https://github.com/benchristel)! - Remove
`"chi2Table"`, `"tTable"`, and `"zTable"` from the `ItemExtras` type
exported from `@khanacademy/perseus-core`. These properties weren't
used. This is a breaking change because consumers might see type errors
if they set chi2Table, tTable, or zTable properties on the `answerArea`
object of a `PerseusItem`. The fix is to avoid setting those properties.

### Minor Changes

- [#2676](#2676)
[`3aa2b8e85`](3aa2b8e)
Thanks [@handeyeco](https://github.com/handeyeco)! - Radio: use
userInput/handleUserInput

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions


- [#2630](#2630)
[`da170e42a`](da170e4)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixed
bugs related to numCorrect not updating properly for the Radio widget,
and cleaning up deriveNumCorrect.

## @khanacademy/[email protected]

### Minor Changes

- [#2676](#2676)
[`3aa2b8e85`](3aa2b8e)
Thanks [@handeyeco](https://github.com/handeyeco)! - Radio: use
userInput/handleUserInput


- [#2635](#2635)
[`a20333281`](a203332)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! -
Interactive Graph code cleaup and bug fix for edge-based label
positioning.

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions


- [#2666](#2666)
[`d738f44d5`](d738f44)
Thanks [@benchristel](https://github.com/benchristel)! - Remove
`"chi2Table"`, `"tTable"`, and `"zTable"` from the `ItemExtras` type
exported from `@khanacademy/perseus-core`. These properties weren't
used. This is a breaking change because consumers might see type errors
if they set chi2Table, tTable, or zTable properties on the `answerArea`
object of a `PerseusItem`. The fix is to avoid setting those properties.

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`2a38ef534`](2a38ef5),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Minor Changes

- [#2666](#2666)
[`d738f44d5`](d738f44)
Thanks [@benchristel](https://github.com/benchristel)! - Remove
`"chi2Table"`, `"tTable"`, and `"zTable"` from the `ItemExtras` type
exported from `@khanacademy/perseus-core`. These properties weren't
used. This is a breaking change because consumers might see type errors
if they set chi2Table, tTable, or zTable properties on the `answerArea`
object of a `PerseusItem`. The fix is to avoid setting those properties.

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions


- [#2630](#2630)
[`da170e42a`](da170e4)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixed
bugs related to numCorrect not updating properly for the Radio widget,
and cleaning up deriveNumCorrect.

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`2a38ef534`](2a38ef5),
[`a20333281`](a203332),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2574](#2574)
[`2a38ef534`](2a38ef5)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Added
a check to Numeric and Input Widgets to ensure we're parsing decimals in
user input according to locale

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions

- Updated dependencies
\[[`c44219a98`](c44219a)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#2672](#2672)
[`c44219a98`](c44219a)
Thanks [@benchristel](https://github.com/benchristel)! - Update peer
dependency versions

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`3aa2b8e85`](3aa2b8e),
[`c44219a98`](c44219a),
[`d738f44d5`](d738f44),
[`da170e42a`](da170e4)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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