Repository: ambari Updated Branches: refs/heads/trunk ed5558742 -> 62898b3d4
AMBARI-11615 Service Dashboard widget graphs do not show unit (not readily apparent what graphs represent). (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/62898b3d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/62898b3d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/62898b3d Branch: refs/heads/trunk Commit: 62898b3d4a29024719ae0086420cdf226398bb89 Parents: ed55587 Author: Andrii Tkach <[email protected]> Authored: Tue Jun 2 16:30:11 2015 +0300 Committer: Andrii Tkach <[email protected]> Committed: Tue Jun 2 18:46:21 2015 +0300 ---------------------------------------------------------------------- .../app/views/common/chart/linear_time.js | 40 +++++++++++--------- .../views/common/widget/graph_widget_view.js | 9 +++++ 2 files changed, 31 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/62898b3d/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 8487f82..dbffe4b 100644 --- a/ambari-web/app/views/common/chart/linear_time.js +++ b/ambari-web/app/views/common/chart/linear_time.js @@ -497,24 +497,14 @@ App.ChartLinearTimeView = Ember.View.extend({ } } - if (displayUnit) { - displayUnit = " " + (displayUnit.length > 3 ? displayUnit.substr(0, 3) + '...' : displayUnit); - series.name = string_utils.pad(series.name.length > 36 ? series.name.substr(0, 36) + '...' : series.name, 40, ' ', 2) + '| ' + - string_utils.pad('min', 5, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(min) + displayUnit, 12, ' ', 3) + - string_utils.pad('avg', 5, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(avg/series.data.compact().length) + displayUnit, 12, ' ', 3) + - string_utils.pad('max', 12, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(max) + displayUnit, 5, ' ', 3); - } else { - series.name = string_utils.pad(series.name.length > 36 ? series.name.substr(0, 36) + '...' : series.name, 40, ' ', 2) + '| ' + - string_utils.pad('min', 5, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(min), 12, ' ', 3) + - string_utils.pad('avg', 5, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(avg/series.data.compact().length), 12, ' ', 3) + - string_utils.pad('max', 12, ' ', 3) + - string_utils.pad(self.get('yAxisFormatter')(max), 5, ' ', 3); - } + + series.name = string_utils.pad(series.name.length > 36 ? series.name.substr(0, 36) + '...' : series.name, 40, ' ', 2) + '| ' + + string_utils.pad('min', 5, ' ', 3) + + string_utils.pad(self.get('yAxisFormatter')(min), 12, ' ', 3) + + string_utils.pad('avg', 5, ' ', 3) + + string_utils.pad(self.get('yAxisFormatter')(avg / series.data.compact().length), 12, ' ', 3) + + string_utils.pad('max', 12, ' ', 3) + + string_utils.pad(self.get('yAxisFormatter')(max), 5, ' ', 3); } if (series.data.length < series_min_length) { series_min_length = series.data.length; @@ -885,6 +875,20 @@ App.ChartLinearTimeView.PercentageFormatter = function (percentage) { }; /** + * A formatter which will turn a number into percentage display like '42%' + * + * @type {Function} + */ +App.ChartLinearTimeView.DisplayUnitFormatter = function (value, displayUnit) { + if (!value || value.length === 0) { + value = '0 ' + displayUnit; + } else { + value = value.toFixed(3).replace(/0+$/, '').replace(/\.$/, '') + " " + displayUnit; + } + return value; +}; + +/** * A formatter which will turn elapsed time into display time like '50 ms', * '5s', '10 m', '3 hr' etc. Time is expected to be provided in milliseconds. * http://git-wip-us.apache.org/repos/asf/ambari/blob/62898b3d/ambari-web/app/views/common/widget/graph_widget_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js index 7b124ab..b5abc96 100644 --- a/ambari-web/app/views/common/widget/graph_widget_view.js +++ b/ambari-web/app/views/common/widget/graph_widget_view.js @@ -225,6 +225,14 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, { displayUnit: function () { return this.get('parentView.content.properties.display_unit'); }.property('parentView.content.properties.display_unit'), + setYAxisFormatter: function () { + var self = this; + if (this.get('displayUnit')) { + this.set('yAxisFormatter', function (value) { + return App.ChartLinearTimeView.DisplayUnitFormatter(value, self.get('displayUnit')); + }); + } + }.observes('displayUnit'), /** * set custom time range for graph widget @@ -278,6 +286,7 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, { }, didInsertElement: function () { + this.setYAxisFormatter(); this.loadData(); var self = this; Em.run.next(function () {
