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

fix: remove double rendering #693

Merged
merged 12 commits into from
Jun 11, 2020

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Jun 1, 2020

Summary

The chart_resizer component sends the first action on mount and then activate the resize observer that subsequentially sends another chart size update.

The PR fixes this behavior letting the ResizeObserver doing his job.

fix #690

Use only the ResizeObseerver to handle chart sizing at the initialization.

fix elastic#690
@markov00 markov00 added :chart Chart element related issue bug Something isn't working chore labels Jun 1, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jun 1, 2020

Codecov Report

Merging #693 into master will increase coverage by 1.99%.
The diff coverage is 78.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #693      +/-   ##
==========================================
+ Coverage   73.13%   75.13%   +1.99%     
==========================================
  Files         271      271              
  Lines        8784     8802      +18     
  Branches     1747     1735      -12     
==========================================
+ Hits         6424     6613     +189     
+ Misses       2309     2132     -177     
- Partials       51       57       +6     
Impacted Files Coverage Δ
...art_types/goal_chart/layout/viewmodel/viewmodel.ts 3.12% <0.00%> (ø)
.../chart_types/goal_chart/state/selectors/tooltip.ts 41.66% <ø> (ø)
src/chart_types/index.ts 100.00% <ø> (ø)
..._types/partition_chart/layout/circline_geometry.ts 98.43% <0.00%> (ø)
src/chart_types/partition_chart/layout/geometry.ts 77.77% <ø> (ø)
...types/partition_chart/layout/types/config_types.ts 100.00% <ø> (ø)
...es/partition_chart/layout/types/viewmodel_types.ts 83.33% <ø> (ø)
...c/chart_types/partition_chart/layout/utils/math.ts 100.00% <ø> (ø)
...hart_types/partition_chart/layout/utils/measure.ts 100.00% <ø> (ø)
...tion_chart/layout/viewmodel/hierarchy_of_arrays.ts 88.88% <ø> (ø)
... and 338 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5581c3c...588bea8. Read the comment docs.

Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @markov00 the PR is effective in that there's no double rendering, I checked it in storybook mode and playground mode.

As a side effect, the way eg. the viewModel is invoked in partition charts (and maybe in Cartesians) seems to have changed a bit, at least when tested via the playground:

  1. viewmodel generation (viewModel.ts main function) is invoked twice (tbh not sure if master does it or not); the first invocation have zeroish width/height so it bails (and the resulting identity viewmodel - emptiness - causes that there's no rendering)
  2. however, now the first invocation not only doesn't have width/height; it also doesn't seem to have the chart spec data

While point 2 is not apparent - because it bails anyway due to zero width/height - I'm mentioning this as you might know of some unintended consequences to this. Also, it's unrelated to the PR but ideally there wouldn't be an initial round of rendering with zero dimensions but I'm not sure if it's accidental and we don't care about the dual pass, or there's some hard async problem for which it's the optimal or developer time efficient solution

Approving the PR as it addresses the issue, and leaving it to your judgment if the apparently different zero-width/height invocation is cause for concern or not; @nickofthyme I see you've made commits in this part of the file, maybe know of something?

src/components/chart_resizer.tsx Show resolved Hide resolved
@monfera
Copy link
Contributor

monfera commented Jun 2, 2020

Jenkins test this

@@ -36,6 +36,8 @@ interface ResizerDispatchProps {

type ResizerProps = ResizerStateProps & ResizerDispatchProps;

const DEFAULT_RESIZE_DEBOUNCE = 200;

class Resizer extends React.Component<ResizerProps> {
private initialResizeComplete = false;
private containerRef: RefObject<HTMLDivElement>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but could be changed when this file needs an update, containerRef could be read only

@nickofthyme
Copy link
Collaborator

Looks to affect the positioning of annotations

image

@markov00 markov00 added the wip work in progress label Jun 3, 2020
@markov00
Copy link
Member Author

markov00 commented Jun 3, 2020

Looks to affect the positioning of annotations

image

@nickofthyme fixed 2b0c472

@markov00
Copy link
Member Author

markov00 commented Jun 3, 2020

Thanks @markov00 the PR is effective in that there's no double rendering, I checked it in storybook mode and playground mode.

As a side effect, the way eg. the viewModel is invoked in partition charts (and maybe in Cartesians) seems to have changed a bit, at least when tested via the playground:

  1. viewmodel generation (viewModel.ts main function) is invoked twice (tbh not sure if master does it or not); the first invocation have zeroish width/height so it bails (and the resulting identity viewmodel - emptiness - causes that there's no rendering)
  2. however, now the first invocation not only doesn't have width/height; it also doesn't seem to have the chart spec data

While point 2 is not apparent - because it bails anyway due to zero width/height - I'm mentioning this as you might know of some unintended consequences to this. Also, it's unrelated to the PR but ideally there wouldn't be an initial round of rendering with zero dimensions but I'm not sure if it's accidental and we don't care about the dual pass, or there's some hard async problem for which it's the optimal or developer time efficient solution

Approving the PR as it addresses the issue, and leaving it to your judgment if the apparently different zero-width/height invocation is cause for concern or not; @nickofthyme I see you've made commits in this part of the file, maybe know of something?

@monfera fixed here 72b6c36
I've basically added the check on the size of the parent before doing any computation

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, seems like the connection between the legend unit test needs to be updated. But the legend stories appear to render fine.

@markov00 markov00 removed the wip work in progress label Jun 10, 2020
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good to me. Tested double render via redux and Chart#render, both show single call. Tested legend changes, all looks unaffected.

image

Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, I also see a single rendering - and a single change that doubles performance across the board 🎉

@markov00 markov00 merged commit ebf2748 into elastic:master Jun 11, 2020
@markov00 markov00 deleted the 2020_06_01-fix_double_rendering branch June 11, 2020 12:54
markov00 pushed a commit that referenced this pull request Jun 15, 2020
# [19.5.0](v19.4.1...v19.5.0) (2020-06-15)

### Bug Fixes

* **tooltip:** show true opaque colors in tooltips ([#629](#629)) ([23290be](23290be)), closes [#628](#628)
* path of stacked area series with missing values ([#703](#703)) ([2541180](2541180))
* remove double rendering ([#693](#693)) ([ebf2748](ebf2748)), closes [#690](#690)

### Features

* **partition:** add 4.5 contrast for text in partition slices ([#608](#608)) ([eded2ac](eded2ac)), closes [#606](#606)
* add screenshot functions to partition/goal ([#697](#697)) ([5581c3c](5581c3c))
@markov00
Copy link
Member Author

🎉 This PR is included in version 19.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jun 15, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [19.5.0](elastic/elastic-charts@v19.4.1...v19.5.0) (2020-06-15)

### Bug Fixes

* **tooltip:** show true opaque colors in tooltips ([opensearch-project#629](elastic/elastic-charts#629)) ([323b325](elastic/elastic-charts@323b325)), closes [opensearch-project#628](elastic/elastic-charts#628)
* path of stacked area series with missing values ([opensearch-project#703](elastic/elastic-charts#703)) ([93f063f](elastic/elastic-charts@93f063f))
* remove double rendering ([#693](elastic/elastic-charts#693)) ([1a9bbb9](elastic/elastic-charts@1a9bbb9)), closes [#690](elastic/elastic-charts#690)

### Features

* **partition:** add 4.5 contrast for text in partition slices ([opensearch-project#608](elastic/elastic-charts#608)) ([59d6d49](elastic/elastic-charts@59d6d49)), closes [opensearch-project#606](elastic/elastic-charts#606)
* add screenshot functions to partition/goal ([opensearch-project#697](elastic/elastic-charts#697)) ([6d2ff64](elastic/elastic-charts@6d2ff64))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :chart Chart element related issue chore released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double rendering of charts on initial load
4 participants