Browse Source

HUE-5091 [charts] Stabilize map chart

Enrico Berti 9 years ago
parent
commit
7578aec95a

+ 8 - 5
desktop/core/src/desktop/static/desktop/js/ko.charts.js

@@ -522,12 +522,15 @@
 
             if (huePubSub) {
               huePubSub.subscribe('resize.leaflet.map', function(){
-                $(element).data('_map').invalidateSize();
-                if ($(element).data('_markerLayer')) {
-                  try {
-                    $(element).data('_map').fitBounds(_bounds);
+                if ($(element).data('_map')) {
+                  $(element).data('_map').invalidateSize();
+                  if ($(element).data('_markerLayer')) {
+                    try {
+                      $(element).data('_map').fitBounds(_bounds);
+                    }
+                    catch (e) {
+                    }
                   }
-                  catch (e) {}
                 }
               });
             }

+ 74 - 54
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -2606,6 +2606,10 @@ ${ hueIcons.symbols() }
     }
   }
 
+  function isNotNullForCharts(val) {
+    return val !== 'NULL' && val !== null;
+  }
+
   function pieChartDataTransformer(rawDatum) {
     var _data = [];
 
@@ -2622,16 +2626,18 @@ ${ hueIcons.symbols() }
       });
       var colors = HueColors.cuiD3Scale();
       $(rawDatum.counts()).each(function (cnt, item) {
-        var val = item[_idxValue] * 1;
-        if (isNaN(val)) {
-          val = 0;
+        if (isNotNullForCharts(item[_idxValue])) {
+          var val = item[_idxValue] * 1;
+          if (isNaN(val)) {
+            val = 0;
+          }
+          _data.push({
+            label: hueUtils.html2text(item[_idxLabel]),
+            value: val,
+            color: colors[cnt % colors.length],
+            obj: item
+          });
         }
-        _data.push({
-          label: hueUtils.html2text(item[_idxLabel]),
-          value: val,
-          color: colors[cnt % colors.length],
-          obj: item
-        });
       });
     }
 
@@ -2664,11 +2670,13 @@ ${ hueIcons.symbols() }
       });
 
       $(rawDatum.counts()).each(function (cnt, item) {
-        _data.push({
-          label: item[_idxRegion],
-          value: item[_idxValue],
-          obj: item
-        });
+        if (isNotNullForCharts(item[_idxValue]) && isNotNullForCharts(item[_idxRegion])) {
+          _data.push({
+            label: item[_idxRegion],
+            value: item[_idxValue],
+            obj: item
+          });
+        }
       });
     }
 
@@ -2676,8 +2684,8 @@ ${ hueIcons.symbols() }
   }
 
   // The leaflet map can freeze the browser with numbers outside the map
-  var MIN_LAT = -85;
-  var MAX_LAT = 85;
+  var MIN_LAT = -90;
+  var MAX_LAT = 90;
   var MIN_LNG = -180;
   var MAX_LNG = 180;
 
@@ -2700,20 +2708,24 @@ ${ hueIcons.symbols() }
       });
       if (rawDatum.snippet.chartMapLabel() != null) {
         $(rawDatum.counts()).each(function (cnt, item) {
-          _data.push({
-            lat: Math.min(Math.max(MIN_LAT, item[_idxLat]), MAX_LAT),
-            lng: Math.min(Math.max(MIN_LNG, item[_idxLng]), MAX_LNG),
-            label: hueUtils.html2text(item[_idxLabel]),
-            obj: item
-          });
+          if (isNotNullForCharts(item[_idxLat]) && isNotNullForCharts(item[_idxLng])) {
+            _data.push({
+              lat: Math.min(Math.max(MIN_LAT, item[_idxLat]), MAX_LAT),
+              lng: Math.min(Math.max(MIN_LNG, item[_idxLng]), MAX_LNG),
+              label: hueUtils.html2text(item[_idxLabel]),
+              obj: item
+            });
+          }
         });
       } else {
         $(rawDatum.counts()).each(function (cnt, item) {
-          _data.push({
-            lat: Math.min(Math.max(MIN_LAT, item[_idxLat]), MAX_LAT),
-            lng: Math.min(Math.max(MIN_LNG, item[_idxLng]), MAX_LNG),
-            obj: item
-          });
+          if (isNotNullForCharts(item[_idxLat]) && isNotNullForCharts(item[_idxLng])) {
+            _data.push({
+              lat: Math.min(Math.max(MIN_LAT, item[_idxLat]), MAX_LAT),
+              lng: Math.min(Math.max(MIN_LNG, item[_idxLng]), MAX_LNG),
+              obj: item
+            });
+          }
         });
       }
     }
@@ -2743,13 +2755,15 @@ ${ hueIcons.symbols() }
           var _data = [];
           var colors = HueColors.cuiD3Scale();
           $(rawDatum.counts()).each(function (cnt, item) {
-            _data.push({
-              series: _plottedSerie,
-              x: new Date(moment(hueUtils.html2text(item[_idxLabel])).valueOf()),
-              y: item[_idxValue] * 1,
-              color: colors[_plottedSerie % colors.length],
-              obj: item
-            });
+            if (isNotNullForCharts(item[_idxLabel]) && isNotNullForCharts(item[_idxValue])) {
+              _data.push({
+                series: _plottedSerie,
+                x: new Date(moment(hueUtils.html2text(item[_idxLabel])).valueOf()),
+                y: item[_idxValue] * 1,
+                color: colors[_plottedSerie % colors.length],
+                obj: item
+              });
+            }
           });
           if (rawDatum.sorting == "asc") {
             _data.sort(function (a, b) {
@@ -2808,12 +2822,14 @@ ${ hueIcons.symbols() }
               var _data = [];
               $(rawDatum.counts()).each(function (cnt, item) {
                 if (item[_idxPivot] === val) {
-                  _data.push({
-                    x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
-                    y: item[_idxValue] * 1,
-                    color: colors[pivotCnt % colors.length],
-                    obj: item
-                  });
+                  if (isNotNullForCharts(item[_idxValue]) && isNotNullForCharts(item[_idxLabel])) {
+                    _data.push({
+                      x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
+                      y: item[_idxValue] * 1,
+                      color: colors[pivotCnt % colors.length],
+                      obj: item
+                    });
+                  }
                 }
               });
               if (rawDatum.sorting == "asc") {
@@ -2855,13 +2871,15 @@ ${ hueIcons.symbols() }
               var _data = [];
               var colors = HueColors.cuiD3Scale();
               $(rawDatum.counts()).each(function (cnt, item) {
-                _data.push({
-                  series: _plottedSerie,
-                  x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
-                  y: item[_idxValue] * 1,
-                  color: colors[cnt % colors.length],
-                  obj: item
-                });
+                if (isNotNullForCharts(item[_idxValue]) && isNotNullForCharts(item[_idxLabel])) {
+                  _data.push({
+                    series: _plottedSerie,
+                    x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
+                    y: item[_idxValue] * 1,
+                    color: colors[cnt % colors.length],
+                    obj: item
+                  });
+                }
               });
               if (rawDatum.sorting == "asc") {
                 _data.sort(function (a, b) {
@@ -2914,13 +2932,15 @@ ${ hueIcons.symbols() }
           var _data = [];
           $(rawDatum.counts()).each(function (cnt, item) {
             if (_idxGroup == -1 || item[_idxGroup] == col) {
-              _data.push({
-                x: item[_idxX],
-                y: item[_idxY],
-                shape: 'circle',
-                size: _idxSize > -1 ? item[_idxSize] : 100,
-                obj: item
-              });
+              if (isNotNullForCharts(item[_idxX]) && isNotNullForCharts(item[_idxY])) {
+                _data.push({
+                  x: item[_idxX],
+                  y: item[_idxY],
+                  shape: 'circle',
+                  size: _idxSize > -1 ? item[_idxSize] : 100,
+                  obj: item
+                });
+              }
             }
           });
           _datum.push({