ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [46/50] ambari git commit: AMBARI-14765. Too many ticks on the graph if large custom time range is specified (alexantonenko)
Date Tue, 26 Jan 2016 21:45:49 GMT
AMBARI-14765. Too many ticks on the graph if large custom time range is specified (alexantonenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a9c78221
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a9c78221
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a9c78221

Branch: refs/heads/branch-dev-patch-upgrade
Commit: a9c78221f5738171e3b97fa45ac6fc2cc65eea64
Parents: c852a0d
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Tue Jan 26 19:09:31 2016 +0200
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Tue Jan 26 19:16:18 2016 +0200

----------------------------------------------------------------------
 .../mixins/common/widgets/time_range_mixin.js   |  2 +-
 .../app/views/common/chart/linear_time.js       | 49 +++++++-------
 .../test/views/common/chart/linear_time_test.js | 70 +++++++++++++++++++-
 3 files changed, 94 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a9c78221/ambari-web/app/mixins/common/widgets/time_range_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/time_range_mixin.js b/ambari-web/app/mixins/common/widgets/time_range_mixin.js
index e2a9c9b..e2ac94a 100644
--- a/ambari-web/app/mixins/common/widgets/time_range_mixin.js
+++ b/ambari-web/app/mixins/common/widgets/time_range_mixin.js
@@ -127,7 +127,7 @@ App.TimeRangeMixin = Em.Mixin.create({
         defaultEndTime.setMinutes(minutes);
         defaultStartTime = defaultEndTime.getTime() - duration;
       }
-      timeRangePopup.showCustomDatePopup(primary.bind(this), secondary.bind(this), {
+      timeRangePopup.showCustomDatePopup(primary.bind(this), secondary, {
         startDate: App.formatDateTimeWithTimeZone(defaultStartTime, 'MM/DD/YYYY'),
         hoursForStart: App.formatDateTimeWithTimeZone(defaultStartTime, 'hh'),
         minutesForStart: App.formatDateTimeWithTimeZone(defaultStartTime, 'mm'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/a9c78221/ambari-web/app/views/common/chart/linear_time.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/chart/linear_time.js b/ambari-web/app/views/common/chart/linear_time.js
index 7933643..e338e54 100644
--- a/ambari-web/app/views/common/chart/linear_time.js
+++ b/ambari-web/app/views/common/chart/linear_time.js
@@ -619,28 +619,27 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
    * @return Rickshaw.Fixtures.Time
    */
   localeTimeUnit: function (timeUnitSeconds) {
-    var timeUnit = new Rickshaw.Fixtures.Time();
-    switch (timeUnitSeconds) {
-      case 604800:
-        timeUnit = timeUnit.unit('day');
-        break;
-      case 2592000:
-        timeUnit = timeUnit.unit('week');
-        break;
-      case 31104000:
-        timeUnit = timeUnit.unit('month');
-        break;
-      default:
-        timeUnit = {
-          name: timeUnitSeconds / 240 + ' minute',
-          seconds: timeUnitSeconds / 4,
-          formatter: function (d) {
-            // format locale specific time
-            var minutes = dateUtils.dateFormatZeroFirst(d.getMinutes());
-            var hours = dateUtils.dateFormatZeroFirst(d.getHours());
-            return hours + ":" + minutes;
-          }
-        };
+    var timeUnit = new Rickshaw.Fixtures.Time(),
+      unitName;
+    if (timeUnitSeconds < 172800) {
+      timeUnit = {
+        name: timeUnitSeconds / 240 + ' minute',
+        seconds: timeUnitSeconds / 4,
+        formatter: function (d) {
+          // format locale specific time
+          var minutes = dateUtils.dateFormatZeroFirst(d.getMinutes());
+          var hours = dateUtils.dateFormatZeroFirst(d.getHours());
+          return hours + ":" + minutes;
+        }
+      };
+    } else if (timeUnitSeconds < 1209600) {
+      timeUnit = timeUnit.unit('day');
+    } else if (timeUnitSeconds < 5184000) {
+      timeUnit = timeUnit.unit('week');
+    } else if (timeUnitSeconds < 62208000) {
+      timeUnit = timeUnit.unit('month');
+    } else {
+      timeUnit = timeUnit.unit('year');
     }
     return timeUnit;
   },
@@ -1111,11 +1110,11 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
       // Preset time range is specified by user
       var seconds = this.get('timeStates').objectAt(this.get('currentTimeIndex')).seconds;
       this.set('timeUnitSeconds', seconds);
-    } else {
+    } else if (!Em.isNone(this.get('customStartTime')) && !Em.isNone(this.get('customEndTime')))
{
       // Custom start and end time is specified by user
-      this.propertyDidChange('timeUnitSeconds');
+      this.set('timeUnitSeconds', (this.get('customEndTime') - this.get('customStartTime'))
/ 1000);
     }
-  }.observes('currentTimeIndex', 'parentView.childViews.lastObject.customStartTime', 'parentView.childViews.lastObject.customEndTime')
+  }.observes('currentTimeIndex', 'customStartTime', 'customEndTime')
 
 });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a9c78221/ambari-web/test/views/common/chart/linear_time_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/chart/linear_time_test.js b/ambari-web/test/views/common/chart/linear_time_test.js
index 40f11ac..202a6ad 100644
--- a/ambari-web/test/views/common/chart/linear_time_test.js
+++ b/ambari-web/test/views/common/chart/linear_time_test.js
@@ -258,7 +258,8 @@ describe('App.ChartLinearTimeView', function () {
         chartLinearTimeView.setProperties({
           currentTimeIndex: item.currentTimeIndex,
           customStartTime: item.customStartTime,
-          customEndTime: item.customEndTime
+          customEndTime: item.customEndTime,
+          timeUnitSeconds: 3600
         });
         var requestData = Em.Object.create(chartLinearTimeView.getDataForAjaxRequest());
         expect(requestData.getProperties(['fromSeconds', 'toSeconds'])).to.eql({
@@ -390,6 +391,73 @@ describe('App.ChartLinearTimeView', function () {
 
   });
 
+  describe('#localeTimeUnit', function () {
+
+    var cases = [
+      {
+        timeUnitSeconds: 240,
+        localeTimeUnit: '1 minute'
+      },
+      {
+        timeUnitSeconds: 172788,
+        localeTimeUnit: '719.95 minute'
+      },
+      {
+        timeUnitSeconds: 172800,
+        localeTimeUnit: 'day'
+      },
+      {
+        timeUnitSeconds: 1209599,
+        localeTimeUnit: 'day'
+      },
+      {
+        timeUnitSeconds: 1209600,
+        localeTimeUnit: 'week'
+      },
+      {
+        timeUnitSeconds: 5183999,
+        localeTimeUnit: 'week'
+      },
+      {
+        timeUnitSeconds: 5184000,
+        localeTimeUnit: 'month'
+      },
+      {
+        timeUnitSeconds: 62207999,
+        localeTimeUnit: 'month'
+      },
+      {
+        timeUnitSeconds: 622080000,
+        localeTimeUnit: 'year'
+      },
+      {
+        timeUnitSeconds: 700000000,
+        localeTimeUnit: 'year'
+      }
+    ];
+
+    beforeEach(function () {
+      sinon.stub(Rickshaw.Fixtures, 'Time').returns({
+        unit: function (name) {
+          return {
+            name: name
+          };
+        }
+      });
+    });
+
+    afterEach(function () {
+      Rickshaw.Fixtures.Time.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.timeUnitSeconds + 's', function () {
+        expect(chartLinearTimeView.localeTimeUnit(item.timeUnitSeconds).name).to.equal(item.localeTimeUnit);
+      });
+    });
+
+  });
+
 });
 
 


Mime
View raw message