mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Graph: Fix for axis format none broken for numbers in exponential notation, Closes #696
This commit is contained in:
parent
87bf6b3800
commit
83e9bc4816
@ -5,6 +5,9 @@
|
||||
- [Issue #578](https://github.com/grafana/grafana/issues/578). Dashboard: Row option to display row title even when the row is visible
|
||||
- [Issue #672](https://github.com/grafana/grafana/issues/672). Dashboard: panel fullscreen & edit state is present in url, can now link to graph in edit & fullscreen mode.
|
||||
|
||||
**Fixes**
|
||||
- [Issue #696](https://github.com/grafana/grafana/issues/696). Graph: fix for y-axis format 'none' when values are in scientific notation (ex 2.3e-13)
|
||||
|
||||
**Tech**
|
||||
- Upgraded from angularjs 1.1.5 to 1.3 beta 17;
|
||||
- Switch from underscore to lodash
|
||||
|
@ -525,12 +525,35 @@ function($, _, moment) {
|
||||
return kbn.nanosFormat(val, decimals);
|
||||
};
|
||||
default:
|
||||
return function(val) {
|
||||
return val % 1 === 0 ? val : val.toFixed(decimals);
|
||||
return function(val, axis) {
|
||||
return kbn.noneFormat(val, axis ? axis.tickDecimals : decimals);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
kbn.noneFormat = function(value, decimals) {
|
||||
var factor = decimals ? Math.pow(10, decimals) : 1;
|
||||
var formatted = String(Math.round(value * factor) / factor);
|
||||
|
||||
// if exponent return directly
|
||||
if (formatted.indexOf('e') !== -1) {
|
||||
return formatted;
|
||||
}
|
||||
|
||||
// If tickDecimals was specified, ensure that we have exactly that
|
||||
// much precision; otherwise default to the value's own precision.
|
||||
|
||||
if (decimals != null) {
|
||||
var decimalPos = formatted.indexOf(".");
|
||||
var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
|
||||
if (precision < decimals) {
|
||||
return (precision ? formatted : formatted + ".") + (String(factor)).substr(1, decimals - precision);
|
||||
}
|
||||
}
|
||||
|
||||
return formatted;
|
||||
};
|
||||
|
||||
kbn.msFormat = function(size, decimals) {
|
||||
// Less than 1 milli, downscale to micro
|
||||
if (Math.abs(size) < 1) {
|
||||
|
@ -23,16 +23,6 @@ function (angular, _, moment, config) {
|
||||
$scope.zoom(2);
|
||||
});
|
||||
|
||||
var count = 0;
|
||||
$scope.$watch(function() {
|
||||
console.log(1);
|
||||
count++;
|
||||
}, function(n, o) {
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
console.log("Total count:" + count);
|
||||
}, 4000);
|
||||
};
|
||||
|
||||
$scope.set_default = function() {
|
||||
|
@ -303,9 +303,7 @@ function (angular, $, kbn, moment, _) {
|
||||
}
|
||||
|
||||
function configureAxisMode(axis, format) {
|
||||
if (format !== 'none') {
|
||||
axis.tickFormatter = kbn.getFormatFunction(format, 1);
|
||||
}
|
||||
axis.tickFormatter = kbn.getFormatFunction(format, 1);
|
||||
}
|
||||
|
||||
function time_format(interval, ticks, min, max) {
|
||||
|
@ -1,8 +1,7 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash'
|
||||
],
|
||||
function (angular, _) {
|
||||
function (angular) {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
|
@ -22,6 +22,20 @@ define([
|
||||
|
||||
});
|
||||
|
||||
describe('high negative exponent, issue #696', function() {
|
||||
it('should ignore decimal correction if exponent', function() {
|
||||
var str = kbn.getFormatFunction('')(2.75e-10, { tickDecimals: 12 });
|
||||
expect(str).to.be('2.75e-10');
|
||||
});
|
||||
});
|
||||
|
||||
describe('none format tests', function() {
|
||||
it('should translate 2 as 2.0000 if axis decimals is 4', function() {
|
||||
var str = kbn.getFormatFunction('')(2, { tickDecimals: 4 });
|
||||
expect(str).to.be('2.0000');
|
||||
});
|
||||
});
|
||||
|
||||
describe('nanosecond formatting', function () {
|
||||
|
||||
it('should translate 25 to 25 ns', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user