-
Notifications
You must be signed in to change notification settings - Fork 351
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
Implementation of new nested SVGs and Tick Labels for Interactive Graph to solve Safari rendering issues. #1452
Conversation
28e4835
to
d021668
Compare
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (2b2e503) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1452 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1452 |
Size Change: -1.29 kB (-0.15%) Total Size: 859 kB
ℹ️ View Unchanged
|
a82a5a6
to
b04aca0
Compare
f9cec28
to
bc29621
Compare
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.
This file is no longer needed, as the labels were able to be reintegrated with the axis-ticks themselves.
b283d18
to
8a8d3ce
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1452 +/- ##
==========================================
- Coverage 70.52% 70.04% -0.48%
==========================================
Files 548 572 +24
Lines 107317 111560 +4243
Branches 7827 11819 +3992
==========================================
+ Hits 75687 78146 +2459
- Misses 31514 33414 +1900
+ Partials 116 0 -116 see 1119 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
8d1eb80
to
cde544d
Compare
@@ -214,53 +216,9 @@ | |||
.MafsView pattern g { | |||
stroke: rgba(33, 36, 44, 0.32); | |||
} | |||
.axis-tick-labels { |
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.
All of these styles are no longer needed as we're using attributes to ensure proper compatibility with older versions of Safari.
const isMax = n === max; | ||
const shouldRender = isOnStep && !isNegativeOne && !isMin && !isMax; | ||
return shouldRender ? `${n}` : ""; | ||
}; |
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.
This was already unused prior to these changes, and is safe to delete.
@@ -1,72 +0,0 @@ | |||
import {lineLabelText} from "./grid"; |
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.
This is testing a function that was not being used, and has been deleted as part of this PR.
e35ce3e
to
5f553a5
Compare
<> | ||
<AxisTicks /> | ||
<AxisArrows /> | ||
</> |
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.
Both the Axis Ticks and Axis Arrows need to be allowed to render outside of the bounds of the graph, but ALSO need to render below the protractor/interactive/locked figures AND above the gridlines.
Unfortunately this requires the use of two separate nested SVGs so that we can render these elements in the correct order.
const tickSize = 10; | ||
const tickLabelSize = 14; | ||
|
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.
The font size is important for calculating positioning, so we're handling it within the component.
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.
This file is no longer necessary, as we're pairing the ticks and labels back together within the SVG.
if (range[X][MIN] < -1 && range[X][MAX] > 0 && number === -1) { | ||
showLabel = false; | ||
} | ||
|
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.
I split this into a separate function as I had a feeling that we may come up with more scenarios in the future for when we may want to conditionally hide labels. It also helps keep the code a little more organized.
@@ -84,7 +102,7 @@ export const MafsGraph = (props: MafsGraphProps) => { | |||
padding: "25px 25px 0 0", | |||
boxSizing: "content-box", | |||
marginLeft: "20px", | |||
marginBottom: "20px", | |||
marginBottom: "30px", | |||
pointerEvents: props.static ? "none" : "auto", |
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.
We needed a little more breathing room for the labels now that they're within the SVG
86066de
to
0f1d96e
Compare
// whether the x-axis is above, within, or below the graph | ||
const xAdjustment = | ||
range[X][MAX] <= 0 ? tickLabelSize * 1.5 : -tickLabelSize * 1.1; | ||
const xPositionText = xPosition + xAdjustment; |
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.
I'm not a big fan of using 1.1 here, but I found it was the best value to visually line up the labels for our most used gridStep/ranges
// Adjust the X position of the x-axis labels based on | ||
// whether the label is positive or negative, in order to | ||
// account for the width of the negative sign | ||
const xAdjustment = x < 0 ? -2 : 0; |
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.
Magic number fix?
|
||
.MafsView .axis-tick-label { | ||
/* There is a bug in the MathJax font for Safari, so we use KaTeX */ | ||
font-family: "KaTeX_Main"; |
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.
Specify a fallback font
|
||
.MafsView .axis-tick-label { | ||
/* There is a bug in the MathJax font for Safari, so we use KaTeX */ | ||
font-family: "KaTeX_Main"; |
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.
Could we use mathjax for all fonts EXCEPT the one media query with safari to use KaTeX
… be working! Just rewriting comments and tidying up calculateNestedSVGViewBox
0f1d96e
to
8d82012
Compare
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] ### Minor Changes - [#1452](#1452) [`3980a36fa`](3980a36) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Implementation of SVG-based Axis Tick Labels for Interactive Graph ### Patch Changes - [#1609](#1609) [`981047211`](9810472) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph] Remove the start-coords-ui flags - [#1610](#1610) [`e9b317ca0`](e9b317c) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Remove the start coords UI if the graph is static - [#1608](#1608) [`737fe30b4`](737fe30) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph] Remove the interactive-graph-locked-feature-m2b flag ## @khanacademy/[email protected] ### Patch Changes - [#1609](#1609) [`981047211`](9810472) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph] Remove the start-coords-ui flags - [#1607](#1607) [`1b340b197`](1b340b1) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Use Wonder Blocks TextArea in the graph description settings UI - [#1610](#1610) [`e9b317ca0`](e9b317c) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Remove the start coords UI if the graph is static - [#1608](#1608) [`737fe30b4`](737fe30) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph] Remove the interactive-graph-locked-feature-m2b flag - Updated dependencies \[[`981047211`](9810472), [`e9b317ca0`](e9b317c), [`737fe30b4`](737fe30), [`3980a36fa`](3980a36)]: - @khanacademy/[email protected]
Screenshot:
Summary:
This PR introduces a new approach to solving the issues related to re-rendering Axis Ticks Labels in Safari, along with several other related issues related to SVG rendering in Safari.
We are now overriding the overflow rules from Mafs in order to allow our Axis Tick Labels to render outside the bounds of the cartesian grid. This required the addition of two nested SVG elements in order to contain the interactive figures, locked figures, and protractor within the new graph bounds. The elements are bound to the graph edges by adjusting the viewBox attribute on the nested SVGs according to the graph's range.
While researching this issue, we were able to discover that there's a key issue with the MathJax font itself, which has required us to change the Axis Tick Labels back to using the original KaTeX font.
Several stories were updated or added in the Interactive Graph Regression Tests in order to help protect against regressions for key issues related to off-center ranges with locked figures.
This approach also allowed us to reintroduce the text stroke around the axis tick labels in order to improve general legibility.
History:
This nested SVG approach has become necessary in order to solve numerous reported issues related to the rendering of the axis tick labels when using earlier versions of Safari (14-16). Unfortunately, Safari has many long standing bugs related to re-rendering SVGs, particularly when dealing with absolutely positioned elements or more modern features.
Issue: LEMS-2035
Test plan: