-
Notifications
You must be signed in to change notification settings - Fork 358
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ddb18e6
[label-without-a-cause] Massive cleanup + bug fix
SonicScrewdriver e1563f1
[label-without-a-cause] docs(changeset): Interactive Graph code cleau…
SonicScrewdriver eee1b63
[label-without-a-cause] Minor improvements to base positioning.
SonicScrewdriver 06e0465
Update packages/perseus/src/widgets/interactive-graphs/backgrounds/ut…
SonicScrewdriver 76d3708
[label-without-a-cause] Fix another edge case
SonicScrewdriver 5a2d1ac
[label-without-a-cause] Might have added extra padding in here
SonicScrewdriver 1381836
[label-without-a-cause] Maybe it was 1.25
SonicScrewdriver f3c4107
[label-without-a-cause] Fix 0.04
SonicScrewdriver c0a7d2e
[label-without-a-cause] pr requests
SonicScrewdriver 77adf83
[label-without-a-cause] increase threshold
SonicScrewdriver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,13 +98,16 @@ export const getLabelPosition = ( | |
? [0, fontSize * 3] // Move the label down by 2 font sizes if the y-axis min is positive | ||
: [0, fontSize * 1.5]; // Move the label down by 1.5 font sizes if the y-axis min is negative | ||
|
||
// Determine if the x-axis min is negative and close to zero. | ||
const isCloseToZero = | ||
graphInfo.range[X][MIN] < 0 && graphInfo.range[X][MIN] > -0.05; | ||
// Determine if the x-axis min is negative and relatively close to zero, based on the scale of the x-axis range. | ||
const isRelativelyCloseToZero = | ||
graphInfo.range[X][MIN] < 0 && | ||
Math.abs(graphInfo.range[X][MIN]) < | ||
(graphInfo.range[X][MAX] - graphInfo.range[X][MIN]) * 0.05; | ||
|
||
// Determine if the tick labels extend beyond the left edge of the graph, either | ||
// because the x-axis is wholly positive or because the x-axis min is negative and close to zero. | ||
const needsExtraSpacing = graphInfo.range[X][MIN] >= 0 || isCloseToZero; | ||
const needsExtraSpacing = | ||
graphInfo.range[X][MIN] >= 0 || isRelativelyCloseToZero; | ||
|
||
// When tick labels extend beyond the left edge of the graph, we need to account for their | ||
// width to prevent the main axis label from overlapping with them. | ||
|
@@ -140,6 +143,13 @@ export const getLabelPosition = ( | |
(graphInfo.range[Y][MIN] + graphInfo.range[Y][MAX]) / 2, | ||
]; | ||
|
||
// If we're VERY close to zero, we want to account for the strange grid offset to avoid | ||
// the y-axis label from getting too far from the tick labels. | ||
if (isRelativelyCloseToZero) { | ||
yAxisLabelLocation[X] = | ||
yAxisLabelLocation[X] - graphInfo.range[X][MIN]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. YESSSSS |
||
|
||
// Convert the Vector2 coordinates to pixel coordinates and add the offsets | ||
const xLabel = vec.add( | ||
pointToPixel(xAxisLabelLocation, graphInfo), | ||
|
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
Oops, something went wrong.
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.
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