-
Notifications
You must be signed in to change notification settings - Fork 354
docs(changeset): Interactive Graph code cleaup and bug fix for edge-based label positioning. #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…p and bug fix for edge-based label positioning.
Size Change: +211 B (+0.04%) Total Size: 474 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (77adf83) and published it to npm. You 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 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
packages/perseus/src/widgets/interactive-graphs/backgrounds/utils.ts
Outdated
Show resolved
Hide resolved
|
||
// Return the maximum of the two | ||
return Math.max(maxDigitsInRange, tickStepSigFigs); | ||
}; |
There was a problem hiding this comment.
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!
…ils.ts Co-authored-by: Nisha Yerunkar <[email protected]>
const isRelativelyCloseToZero = | ||
graphInfo.range[X][MIN] < 0 && | ||
Math.abs(graphInfo.range[X][MIN]) < | ||
(graphInfo.range[X][MAX] - graphInfo.range[X][MIN]) * 0.05; |
There was a problem hiding this comment.
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]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YESSSSS
There was a problem hiding this 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.
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>
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:
Screenshot: