Resize gauge and donut on resize events #276
Draft
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.
Work in progress
NB: This is a cleaner version of #272, which will be abandoned due to my fork being rather polluted at the time.
Introduction
It is somewhat inconvenient that the gauge/donut does not adapt to the element it is included in. Therefore it is not straight-forward to use gauge.js in responsive pages. Even though #64 tries to deal with this upon creation, we would like it to happen dynamically as well. Also, some of the later improvements make a bit harder to find the best scaling approach.
This PR is an attempt to support automatic rescaling and rerendering as the page or parent element changes size. It uses the
ResizeObserver
pattern that was introduced around 2021 and is supported by all browsers. If used in older, deprecated browsers whereResizeObserver
is not available, resizing will not be possible.Details
This PR potentially introduces breaking changes.
Using
ResizeObserver
, the code will automatically attach a handler for resizing events at creation of bothGauge
andDonut
objects and should thus work for both. In order for it to work properly, be aware of:<canvas>
element MUST be assigned a uniqueid
. For example `.detachAll()
method on each gauge/donut object.Regarding point 2 above: