4 ms·
In chart.js we have a very complex solution for dealing with this. We've gone through a number of iterations, but settled on a using ResizeObserver. You also ne
by etimberg 5y ago
In chart.js we have a very complex solution for dealing with this. We've gone through a number of iterations, but settled on a using ResizeObserver. You also need to listen to `window.resize` to get notified about DPR changes which can happen when a browser window is dragged from one screen to another.
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js#L187-L225 https://github.com/chartjs/Chart.js/blob/master/src/platform...
- dvh 5y ago>we have a very complex solution This is my experience as well, to do it correctly, it needs to get many minute details exactly right. They still developing canvas so my proposal is to forget about these extremely complex solutions and add new property to canvas that would make width/height same as client width/height (perhaps with one event to let canvas know it was resized).
- c_s_guy 5y agoMay I ask why `window.resize` is used over `matchMedia`[0] to detect DPR changes? Is one approach better than the other? [0] https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes https://developer.mozilla.org/en-US/docs/Web/API/Window/devi...
- ygra 5y agoThe resize event is compatible with IE < 10. Depending on compatibility guarantees this can be a reason.