Open maxencefrenette opened 7 years ago
Facing the same issue!
Tried to fix it but wasn't able to... anyone had a chance at it?
The reason we don't have this is that HTML elements do not emit resize events that we can bind to, so there are no events we can bind to. We could run check the container size on an interval, but that would be heavy on the performance, so it's less than ideal.
I assume you have the chart in an angular component that can be resized, and probably emits those events, so I would suggest binding to them and triggering the chart update in the aplication itself.
To trigger the update, just change the reference on any property. Example, if your data is called results, you can do this in your resize event listener:
this.results = [...this.results]
which will trigger the chart update and resize.
Alternatively, we can probably use the ResizeObserver API https://wicg.github.io/ResizeObserver/ It still seems to be in draft, but some browsers already support it and there are polyfills for it. We would need to evaluate how it will affect performance.
+1, this is very annoying to deal with
I'm submitting a ... (check one with "x")
One could argue that this could be considered a feature, but I think it should be treated as a bug.
Current behavior
Currently, a chart that is set to fit the container's size will only resize itself when the window.resize event gets triggered.
Expected behavior
It should resize itself even when only the container changes size, but the window isn't resized
Reproduction of the problem
It's pretty obvious from the code itself: https://github.com/swimlane/ngx-charts/blob/f9cc928a0fe51c48a32045c490c15d6bc75f6fd0/src/common/base-chart.component.ts#L140
What is the motivation / use case for changing the behavior?
Sometimes, other things that a window resize can trigger a container resize
Please tell us about your environment:
ngx-charts version: 6.0.0
Angular version: 4.2.5
Browser: all
Language: Typescript 2.3