mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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 #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.
|
- [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**
|
**Tech**
|
||||||
- Upgraded from angularjs 1.1.5 to 1.3 beta 17;
|
- Upgraded from angularjs 1.1.5 to 1.3 beta 17;
|
||||||
- Switch from underscore to lodash
|
- Switch from underscore to lodash
|
||||||
|
@ -525,12 +525,35 @@ function($, _, moment) {
|
|||||||
return kbn.nanosFormat(val, decimals);
|
return kbn.nanosFormat(val, decimals);
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return function(val) {
|
return function(val, axis) {
|
||||||
return val % 1 === 0 ? val : val.toFixed(decimals);
|
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) {
|
kbn.msFormat = function(size, decimals) {
|
||||||
// Less than 1 milli, downscale to micro
|
// Less than 1 milli, downscale to micro
|
||||||
if (Math.abs(size) < 1) {
|
if (Math.abs(size) < 1) {
|
||||||
|
@ -23,16 +23,6 @@ function (angular, _, moment, config) {
|
|||||||
$scope.zoom(2);
|
$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() {
|
$scope.set_default = function() {
|
||||||
|
@ -303,9 +303,7 @@ function (angular, $, kbn, moment, _) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configureAxisMode(axis, format) {
|
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) {
|
function time_format(interval, ticks, min, max) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash'
|
|
||||||
],
|
],
|
||||||
function (angular, _) {
|
function (angular) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular
|
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 () {
|
describe('nanosecond formatting', function () {
|
||||||
|
|
||||||
it('should translate 25 to 25 ns', function () {
|
it('should translate 25 to 25 ns', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user