Преглед на файлове

AMBARI-1034. Metric Charts - display local time rather than UTC. (Srimanth Gunturi via yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1418975 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako преди 12 години
родител
ревизия
b885ee6ce8
променени са 2 файла, в които са добавени 34 реда и са изтрити 1 реда
  1. 3 0
      AMBARI-666-CHANGES.txt
  2. 31 1
      ambari-web/app/views/common/chart/linear_time.js

+ 3 - 0
AMBARI-666-CHANGES.txt

@@ -424,6 +424,9 @@ AMBARI-666 branch (unreleased changes)
 
   IMPROVEMENTS
 
+  AMBARI-1034. Metric Charts - display local time rather than UTC.
+  (Srimanth Gunturi via yusaku)
+
   AMBARI-1033. Nagios and Ganglia links should use public host names in URLs.
   (Srimanth Gunturi via yusaku)
 

+ 31 - 1
ambari-web/app/views/common/chart/linear_time.js

@@ -253,6 +253,22 @@ App.ChartLinearTimeView = Ember.View.extend({
           this._showMessage('info', 'No Data', 'There was no data available.');
         }
       },
+      
+      /**
+       * Returns a custom time unit for the graph's X axis. This is needed
+       * as Rickshaw's default time X axis uses UTC time, which can be confusing
+       * for users expecting locale specific time. This value defaults to
+       * App.ChartLinearTimeView.FifteenMinuteTimeUnit.
+       * 
+       * If <code>null</code> is returned, Rickshaw's default time unit is used.
+       * 
+       * @type Function
+       * @return Rickshaw.Fixtures.Time
+       * @default App.ChartLinearTimeView.FifteenMinuteTimeUnit
+       */
+      localeTimeUnit: function(){
+        return App.ChartLinearTimeView.FifteenMinuteTimeUnit;
+      },
 
       /**
        * @private
@@ -333,7 +349,8 @@ App.ChartLinearTimeView = Ember.View.extend({
         _graph.renderer.unstack = false;
 
         xAxis = new Rickshaw.Graph.Axis.Time({
-          graph: _graph
+          graph: _graph,
+          timeUnit: this.localeTimeUnit()
         });
 
         yAxis = new Rickshaw.Graph.Axis.Y({
@@ -522,4 +539,17 @@ App.ChartLinearTimeView.TimeElapsedFormatter = function (millis) {
     }
   }
   return value;
+};
+
+/**
+ * A time unit which can be used for showing 15 minute intervals on X axis.
+ * 
+ * @type Rickshaw.Fixtures.Time
+ */
+App.ChartLinearTimeView.FifteenMinuteTimeUnit = {
+  name: '15 minute',
+  seconds: 60 * 15,
+  formatter: function (d) {
+    return d.toLocaleString().match(/(\d+:\d+):/)[1];
+  }
 };