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

Resizing the window sets needle back to original position. #35

Closed
NetrushGarrett opened this issue Jan 20, 2020 · 6 comments
Closed

Resizing the window sets needle back to original position. #35

NetrushGarrett opened this issue Jan 20, 2020 · 6 comments

Comments

@NetrushGarrett
Copy link

If I have a Gauge where I frequently update the percent and then the window resizes it will set the needle back to whatever the first percent I passed was.

Here is an example. let the gauge update twice and then resize the window you will see it go back to the original

https://codesandbox.io/s/pedantic-heisenberg-03qd1?fontsize=14&hidenavigation=1&theme=dark

@NetrushGarrett
Copy link
Author

I was able to get around this by unmounting and remounting the component every time I change the value instead of relying on prop change to update, That way when it does resize there's no prevProps for it to look at.

@aaroncrawford
Copy link

Receiving this as well. Had to put extra logic in to ensure that the gauge never received zero data before my state was changed with it's final set of data.

@dominicboston
Copy link
Contributor

dominicboston commented Nov 30, 2020

I'm having the same issue here, but it is triggered by scrolling down to the bottom of the page on mobile. I also made a sandbox to confirm this with the resize reset. Click the button then resize the window. Can we turn this issue report into an official bug?
video of problem https://dab-online.co.uk/RPReplay_Final1606780028.MP4
https://codesandbox.io/s/reactgaugeresize-wwbct?file=/src/App.js

dominicboston added a commit to dominicboston/react-gauge-chart that referenced this issue Dec 1, 2020
Moved window resize listener into useEffect to prevent resetting values to default on window resize.
Fixes issue Martin36#35
@dominicboston
Copy link
Contributor

Thanks for merge - this issue can now be closed.

@jeff1evesque
Copy link

I was able to keep using react-gauge-chart at version 0.3.0, and followed an above recommendation:

(base) jeff1evesque@AlienWareMacBook supercode % git diff jsx
diff --git a/jsx/import/xyz/flashy-popsicles.jsx b/jsx/import/xyz/flashy-popsicles.jsx
index 12b62c2..e9bfa63 100644
--- a/jsx/import/xyz/flashy-popsicles.jsx
+++ b/jsx/import/xyz/flashy-popsicles.jsx
@@ -110,6 +110,21 @@ class Chart extends Component {
             colors: colors,
             arcs_length: arcs_length
         }
+
+        this.resize = this.resize.bind(this);
+    }
+
+    resize() {
+        if (
+            'percent' in this.props
+            && checkValidFloat(this.props.percent)
+        ) {
+            this.setState({ percent: this.props.percent });
+        }
+    }
+
+    componentDidMount() {
+        window.addEventListener('resize', this.resize);
     }
 
     componentDidUpdate(prevProps, prevState) {
(base) jeff1evesque@AlienWareMacBook supercode % 

@jeff1evesque
Copy link

My workaround is still a bit glitchy, since its not very smooth between transition of the needle being forced to a (re)render on window resize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants