From 2b2069bf66245848deb6355a5912c8f1195ae5fd Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 22 Oct 2017 16:35:59 +0800 Subject: [PATCH] modify axis label style of speed chart --- src/scripts/filters/volume.js | 24 +++++++++++++++++--- src/scripts/services/ariaNgMonitorService.js | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/scripts/filters/volume.js b/src/scripts/filters/volume.js index d69fd69..ce322e5 100644 --- a/src/scripts/filters/volume.js +++ b/src/scripts/filters/volume.js @@ -5,11 +5,25 @@ var units = [ 'B', 'KB', 'MB', 'GB' ]; var defaultFractionSize = 2; + var getAutoFractionSize = function (value) { + if (value < 1) { + return 2; + } else if (value < 10) { + return 1; + } else { + return 0; + } + }; + return function (value, fractionSize) { var unit = units[0]; + var actualFractionSize = defaultFractionSize; + var autoFractionSize = false; - if (angular.isUndefined(fractionSize)) { - fractionSize = defaultFractionSize; + if (angular.isNumber(fractionSize)) { + actualFractionSize = fractionSize; + } else if (fractionSize === 'auto') { + autoFractionSize = true; } if (!value) { @@ -29,7 +43,11 @@ } } - value = $filter('number')(value, fractionSize); + if (autoFractionSize) { + actualFractionSize = getAutoFractionSize(value); + } + + value = $filter('number')(value, actualFractionSize); return value + ' ' + unit; }; diff --git a/src/scripts/services/ariaNgMonitorService.js b/src/scripts/services/ariaNgMonitorService.js index 0ae3eb2..e76c67e 100644 --- a/src/scripts/services/ariaNgMonitorService.js +++ b/src/scripts/services/ariaNgMonitorService.js @@ -53,7 +53,7 @@ type: 'value', axisLabel: { formatter: function (value) { - return $filter('readableVolume')(value, 0); + return $filter('readableVolume')(value, 'auto'); } } },