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

Chart does not resize/not responsive when parent container is resized #182

Open
dez1729 opened this issue Dec 9, 2021 · 5 comments
Open

Comments

@dez1729
Copy link

dez1729 commented Dec 9, 2021

Seems the responsiveness only applies when the browser is resized, but not if the container is resize (say using angular-split or resize under material component etc), so the chart will not resize unless manually trigger the browser resize event in code. Is there any way to listen for resize event within a container?

@andrefarzat
Copy link
Collaborator

andrefarzat commented Dec 10, 2021

@dez1729 I believe you're looking to something like this: https://www.npmjs.com/package/@thalesrc/resize-manager
It watches an element and triggers an event (rxjs' observable) once the width/height of the element changes

A library using it: https://www.npmjs.com/package/@thalesrc/ng-utils#user-content-resize

@dez1729
Copy link
Author

dez1729 commented Dec 10, 2021

I've done just that actually (with built in event from the component I was using), and in my subscription call "window.dispatchEvent(new Event('resize'))" I got from another thread. However, this produces a noticeable lag. Is there a native call that the chart would respond directly instead of being triggered a round-about way.

@andrefarzat
Copy link
Collaborator

you could use the PlotlyService to get the plotly instance and to trigger the redraw there. Like this:

    constructor(public plotlyService: PlotlyService) {}

    this.resizeService.observe(this.el.nativeElement).subscribe(async ({width, height}) => {
            const plotly = await this.plotlyService.getPlotly();

            /** Here you have the plotly object from plotly.js */
            /** ... */
    });

Then you can use the functions from plotly.js such as react and restyle to update the graph.
Reference: https://plotly.com/javascript/plotlyjs-function-reference/#plotlyrestyle

@erwinpenner
Copy link

@dez1729 Same problem here:
I'm using plotly inside a drawer-content. When toggeling the sidenav, everything reacts responsive, as expected, except for the plotly-chart.
It only resizes, when the whole browser window gets resized.

@mohitchauhan4u
Copy link

mohitchauhan4u commented Oct 1, 2022

"window.dispatchEvent(new Event('resize'))"

"window.dispatchEvent(new Event('resize'))"

Just write this statement in the function which opens the side panel for you or resizes parent container for you.
Plotly js will automatically resize itself.

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

4 participants