Skip to content
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
merged 15 commits into from
Dec 24, 2021

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Dec 22, 2021

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 the canvas 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 the canvas 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 single measureText 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)
    all-test-ts-baseline-visual-tests-for-all-stories-sunburst-value-formatted-visually-looks-correct-1-diff

  • due to the padding removal, some fitted area are shown/hidden (the problem is already known Rendering fitted end point shows periodically  #1473)

mixed-stories-test-ts-mixed-series-stories-fitting-functions-stacked-charts-area-charts-ordinal-dataset-no-end-value-should-display-correct-fit-for-type-carry-1-diff

fix #1533

For reviewers

Please just consider the TS changes, don't waste too much time on VRTs diffs

@markov00 markov00 force-pushed the 2021_12_22-dry_textmeasure branch from 1796a34 to ca528a7 Compare December 22, 2021 15:42
@markov00 markov00 force-pushed the 2021_12_22-dry_textmeasure branch 2 times, most recently from e97fb2c to d6e26b5 Compare December 23, 2021 08:44
@markov00 markov00 force-pushed the 2021_12_22-dry_textmeasure branch from d6e26b5 to e344f5d Compare December 23, 2021 10:55
@markov00 markov00 requested a review from monfera December 23, 2021 10:58
@markov00 markov00 enabled auto-merge (squash) December 24, 2021 08:44
@markov00
Copy link
Member Author

jenkins test this
(let's see if the heatmap change is flaky or not)

@markov00 markov00 disabled auto-merge December 24, 2021 10:56
@markov00 markov00 force-pushed the 2021_12_22-dry_textmeasure branch from c150965 to e344f5d Compare December 24, 2021 10:56
@markov00 markov00 merged commit 676a403 into elastic:master Dec 24, 2021
@markov00 markov00 deleted the 2021_12_22-dry_textmeasure branch December 24, 2021 13:45
@nickofthyme nickofthyme mentioned this pull request Jan 20, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safari performance issue with bar charts
2 participants