qlik-oss / picasso.js

A charting library streamlined for building interactive visualizations for the Qlik product suites.
https://qlik.dev/libraries-and-tools/picassojs
MIT License
188 stars 55 forks source link

Fit container #653

Closed jansivans closed 2 years ago

jansivans commented 2 years ago

I am trying to implement a chart which automatically fits parent's container. I have tried using resize observer which calls chart.update() every time parent's dimensions change. This works, but maybe there is a better way which I am missing? Every example I have seen just sets parent container with fixed dimensions (width, height).

cbt1 commented 2 years ago

chart.update() would be the way to go. Since you are not providing any new data, it will re-create the chart layout and some components may appear or disappear depending on the space available, as in a responsive behaviour.

jansivans commented 2 years ago

@cbt1 thanks for answer! Only issue I have with this approach is that brush selections gets cleared each time I call chart.update().

T-Wizard commented 2 years ago

try using chart.update({ partialData: true }) I think that should skip clearing brush selections

jansivans commented 2 years ago

@T-Wizard it does, but it also removes some components from chart and sometimes a whole chart doesn't get rendered at all. As an example, you can add partialData: true here https://github.com/qlik-oss/picasso.js/blob/master/examples/hammer/index.js#L190 and check what happens.

jansivans commented 2 years ago

Right now I am just using this workaround:

const brush = chart.brush('select');
brush.clear = () => { };

This way calling chart.update() will re-render everything responsively and selections won't be cleared.