pepstock-org / Charba

J2CL and GWT Charts library based on CHART.JS
https://pepstock-org.github.io/Charba-Wiki/docs
Apache License 2.0
62 stars 6 forks source link

Attach behaviour of Charba charts in GWT #59

Closed MartinSchwarzbauer closed 3 years ago

MartinSchwarzbauer commented 3 years ago

Hi *!

I am using latest charba version (master - 4.0) and I have seen the following behaviour:

Thank you very much, Martin

MartinSchwarzbauer commented 3 years ago

After moving back to menu entry with chart: chart.isChartAttached() returns false! How can i attach it again?

stockiNail commented 3 years ago

@MartinSchwarzbauer the normal behavior is destroy the chart when the panel container is detached.

But there is a property destroyOnDetach (default is true) that you can set which enables do not detach the chart. This property can be set on the options and directly to the chart instance.

LineChart chart  = new LineChart();
chart.setDestroyOnDetach(false);
// or 
chart.getOptions().setDestroyOnDetach(false);
// or if this behavior is for all charts in the application
Defaults.get().getGlobal().setDestroyOnDetach(false);

Let me know if works.

stockiNail commented 3 years ago

@MartinSchwarzbauer it's documented here: https://pepstock-org.github.io/Charba-Wiki/docs/defaults/DefaultsCharts#commons-charts-options

MartinSchwarzbauer commented 3 years ago

Thank you very much! This default behaviour makes sense :)

But I think for Widgets in GWT the behaviour is different !

stockiNail commented 3 years ago

But I think for Widgets in GWT the behaviour is different !

@MartinSchwarzbauer yeah, it depends on the coder. For instance someone is creating the widget every time, someone like hiding the widgets. The default to false was thought in order to reduce the amount of memory consumption but allowing the user to decide the different behavior based on use case.

In the Charba showcase for GWT, using UiBinder , we remove the widget and recreate every time is requested by the user.