modify axis label style of speed chart

This commit is contained in:
MaysWind 2017-10-22 16:35:59 +08:00
parent 5dc917d3f2
commit 2b2069bf66
2 changed files with 22 additions and 4 deletions

View file

@ -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;
};

View file

@ -53,7 +53,7 @@
type: 'value',
axisLabel: {
formatter: function (value) {
return $filter('readableVolume')(value, 0);
return $filter('readableVolume')(value, 'auto');
}
}
},