-
Notifications
You must be signed in to change notification settings - Fork 122
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
refactor: DRY up measureText code #1535
Merged
markov00
merged 15 commits into
elastic:master
from
markov00:2021_12_22-dry_textmeasure
Dec 24, 2021
Merged
refactor: DRY up measureText code #1535
markov00
merged 15 commits into
elastic:master
from
markov00:2021_12_22-dry_textmeasure
Dec 24, 2021
Conversation
This file contains 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
markov00
force-pushed
the
2021_12_22-dry_textmeasure
branch
from
December 22, 2021 15:42
1796a34
to
ca528a7
Compare
markov00
force-pushed
the
2021_12_22-dry_textmeasure
branch
2 times, most recently
from
December 23, 2021 08:44
e97fb2c
to
d6e26b5
Compare
markov00
force-pushed
the
2021_12_22-dry_textmeasure
branch
from
December 23, 2021 10:55
d6e26b5
to
e344f5d
Compare
monfera
approved these changes
Dec 23, 2021
packages/charts/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts
Outdated
Show resolved
Hide resolved
packages/charts/src/chart_types/heatmap/state/selectors/compute_chart_dimensions.ts
Outdated
Show resolved
Hide resolved
jenkins test this |
markov00
force-pushed
the
2021_12_22-dry_textmeasure
branch
from
December 24, 2021 10:56
c150965
to
e344f5d
Compare
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The PR DRYs up the usage of
measureText
and relatives (TextMeasure
type,textMeasure
fn etc).Only one type and one method is now used and available: all the code is available in
packages/charts/src/utils/bbox/canvas_text_bbox_calculator.ts
The two function to use are:
withTextMeasure
(that encapsulate the creation of thecanvas
element and doesn't append the canvas element to the DOM, avoiding the style recalculation and fixing Safari performance issue with bar charts #1533)measureText
that use an existing canvas (it doesn't save/restore the context so it's only used where we are restoring the context manually)The removal of the
append
,remove
calls of thecanvas
elements to compute the text metrics improved the rendering speed in Safari when a high number of data series are used. This, together with the reuse of a singlemeasureText
function shared on the geometries call reduce the number of DOM Style Recalculation required improving the speed significantly in Safari (Chrome and Firefox gain also a bit of speed).The change created a large diff of VRTs (~600) due to the removal of the default 1px padding applied to the text calculation. I have removed that padding because we no longer need to pad the text to "align" the browser rendering: each browser renders slightly differently the text (both on HTML and on canvas) and slight (subpixel/pixel differences are unavoidable). We actually don't care much about these differences because our tests are per-browser.
There are some major (but fine) noticeable differences in the VRTs diffs:
1 or 2 pixels shift of the chart caused by the padding removal
in partition charts, some texts are pushed from within the chart to outside the chart in linked labels (again minor differences)
due to the padding removal, some fitted area are shown/hidden (the problem is already known Rendering fitted end point shows periodically #1473)
fix #1533
For reviewers
Please just consider the TS changes, don't waste too much time on VRTs diffs