alonho / angular-plotly

MIT License
42 stars 35 forks source link

Destroying & recreating a chart inherits zoom levels #17

Closed molehillrocker closed 8 years ago

molehillrocker commented 8 years ago

Hello,

we are currently facing an issue when we destroy a view where a chart is displayed. This happens quite often in our application, because charts are rendered in a modal only if a user clicked on a button to show details for a given entity. When the modal is closed, the chart is supposed to be destroyed. When the user clicks the same button on another entity, another chart (of the same type, just with different data) is supposed to be drawn inside a modal. However, it seems that the "new" chart inherits zoom levels from the old chart. I thought it might have something to do with a missing scope.$on($destroy, function (){}); in this directive, which is why I added

scope.$on('$destroy', function() {
    Plotly.Plots.purge(graph);
    element.remove();
});

to the bottom of the directive. Unfortunately, this does not change anyhing. New charts are always created with the zoom levels of the old chart. 😒

molehillrocker commented 8 years ago

Well, sometimes it is better to step away and return some time later. I found the bug, it was misuse of angular.extend() when merging deep-leveled layout configuration objects. Using angular.merge() fixed it. 💃