Explorar o código

HUE-5035 [charts] Avoid double bar chart rendering on window resize

Enrico Berti %!s(int64=9) %!d(string=hai) anos
pai
achega
dcb17f3

+ 10 - 7
desktop/core/src/desktop/static/desktop/js/ko.charts.js

@@ -999,6 +999,7 @@
 
     if ($(element).is(":visible")) {
       nv.addGraph(function () {
+
         var _chart;
         if (isTimeline) {
           if ($(element).find("svg").length > 0 && $(element).find(".nv-discreteBarWithAxes").length > 0) {
@@ -1143,13 +1144,15 @@
           });
         }
 
-        var _resizeTimeout = -1;
-        nv.utils.windowResize(function () {
-          window.clearTimeout(_resizeTimeout);
-          _resizeTimeout = window.setTimeout(function () {
-            _chart.update();
-          }, 200);
-        });
+        if (!options.skipWindowResize) {
+          var _resizeTimeout = -1;
+          nv.utils.windowResize(function () {
+            window.clearTimeout(_resizeTimeout);
+            _resizeTimeout = window.setTimeout(function () {
+              _chart.update();
+            }, 200);
+          });
+        }
 
         $(element).on("forceUpdate", function () {
           _chart.update();

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1782,7 +1782,7 @@ ${ hueIcons.symbols() }
                 <div data-bind="attr:{'id': 'pieChart_'+id()}, pieChart: {data: {counts: result.data, sorting: chartSorting(), snippet: $data}, fqs: ko.observableArray([]),
                       transformer: pieChartDataTransformer, maxWidth: 350, parentSelector: '.chart-container' }, visible: chartType() == ko.HUE_CHARTS.TYPES.PIECHART" class="chart"></div>
 
-                <div data-bind="attr:{'id': 'barChart_'+id()}, barChart: {datum: {counts: result.data, sorting: chartSorting(), snippet: $data}, fqs: ko.observableArray([]), hideSelection: true,
+                <div data-bind="attr:{'id': 'barChart_'+id()}, barChart: {skipWindowResize: true, datum: {counts: result.data, sorting: chartSorting(), snippet: $data}, fqs: ko.observableArray([]), hideSelection: true,
                       transformer: multiSerieDataTransformer, stacked: false, showLegend: true, isPivot: typeof chartXPivot() !== 'undefined'},  stacked: true, showLegend: true, visible: chartType() == ko.HUE_CHARTS.TYPES.BARCHART" class="chart"></div>
 
                 <div data-bind="attr:{'id': 'lineChart_'+id()}, lineChart: {datum: {counts: result.data, sorting: chartSorting(), snippet: $data},