浏览代码

HUE-6093 [frontend] Added resize support for Pie charts

Enrico Berti 8 年之前
父节点
当前提交
64d6c97

+ 14 - 0
desktop/core/src/desktop/static/desktop/js/ko.charts.plotly.js

@@ -34,6 +34,20 @@
   };
 
   ko.bindingHandlers.pieChart = {
+    init: function (element, valueAccessor) {
+      var resizeSubscription = huePubSub.subscribe('resize.plotly.chart', function () {
+        Plotly.Plots.resize(element);
+      });
+      var resizeEvent = function () {
+        Plotly.Plots.resize(element);
+      };
+
+      $(window).on('resize', resizeEvent);
+      ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
+        resizeSubscription.remove();
+        $(window).off('resize', resizeEvent);
+      });
+    },
     update: function (element, valueAccessor) {
       var _options = valueAccessor();
       var plotterTimeout = window.setTimeout(function () {

+ 1 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -679,6 +679,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
         huePubSub.subscribe('split.panel.resized', function() {
           huePubSub.publish('resize.form.actions');
+          huePubSub.publish('resize.plotly.chart');
         });
 
         huePubSub.publish('resize.form.actions');