Browse Source

AMBARI-25546 Prevent negative float and NaN value in heatmap metrics page (akiyamaneko via dgrinenko) (#3223)

neko 5 years ago
parent
commit
93f1824179

+ 10 - 1
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js

@@ -93,7 +93,7 @@ App.MainChartHeatmapMetric = Em.Object.extend({
    * 
    */
   slotDefinitions: function () {
-    var max = this.get('maximumValue') ? parseFloat(this.get('maximumValue')) : 0;
+    var max = this.getMaximumValue();
     var slotCount = this.get('numberOfSlots');
     var units = this.get('units');
     var delta = (max - this.get('minimumValue')) / slotCount;
@@ -174,6 +174,15 @@ App.MainChartHeatmapMetric = Em.Object.extend({
     return hatchStyle;
   },
 
+  /**
+   * compatible with special input value, such as negative float number or string
+   * @return {float}
+   */
+  getMaximumValue: function getMaximumValue() {
+    var max = this.get('maximumValue') ? parseFloat(this.get('maximumValue')) : 0;
+    return isNaN(max) ? 0 : Math.max(0, max);
+  },
+  
   /**
    * In slot definitions this value is used to construct the label by appending
    * it to slot min-max values. For example giving '%' here would result in slot