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
.resize no longer works with explicit size #9049
Comments
Right, the sets are never equal on a responsive chart, because of |
Because `this._listeners` may contain both event handlers from options and internal event handlers for responsive support, the `setsEqual` check would often fail, causing event handlers to be unnecessarily detached and reattached and fired. If I'm understanding correctly, this is the root cause of chartjs#9049.
Thanks. I started creating a PR for this; see #9050. However, if I'm understanding the code correctly, ignoring those listeners may introduce another issue; right now, the Is Chart.js supposed to update its events when |
@joshkel I think your suggestion of two separate sets would be most maintainable solution |
@kurkle Thanks. I updated the PR; feedback welcome. |
* Fix detecting changed events Because `this._listeners` may contain both event handlers from options and internal event handlers for responsive support, the `setsEqual` check would often fail, causing event handlers to be unnecessarily detached and reattached and fired. If I'm understanding correctly, this is the root cause of #9049. * Use a separate object for responsive listeners Correctly update events when responsive property changes as well as when requested events change. * Code review feedback
Expected and Current Behavior
Calling the
.resize
method with an explicit width and height no longer works after upgrading from Chart.js 3.1.1 to 3.2.0; it instead automatically sizes the chart to its current size.Possible Solution
From stepping through the code with a debugger, the problem appears to have been introduced in #8928. (See here.) The
if (me.options.responsive) {
block withinbindEvents
causesresize()
to be called with default arguments, which causes the just-set width and height to be reset.Steps to Reproduce
See https://codepen.io/joshkel/pen/YzZPrjj.
When Chart.js 3.1.1 is loaded:
When Chart.js 3.2.0 or 3.2.1 is loaded:
Context
I'm using an explicit width and height as part of responsive printing support. (And that approach to printing does feel like a bit of a hack - see #8149 - so if there's a better approach here, please let me know.)
Environment
The text was updated successfully, but these errors were encountered: