Commit ea5da627 by Torkel Ödegaard

Panel: Different time periods, panels can override dashboard relative time…

Panel: Different time periods, panels can override dashboard relative time and/or add a time shift, #171, only works for graph panel for now, need feedback for how to do it for singlestat panel
parent 1c8ef716
......@@ -3,6 +3,7 @@
**New features**
- [Issue #1331](https://github.com/grafana/grafana/issues/1331). Graph & Singlestat: New axis/unit format selector and more units (kbytes, Joule, Watt, eV), and new design for graph axis & grid tab and single stat options tab views
- [Issue #1241](https://github.com/grafana/grafana/issues/1242). Timepicker: New option in timepicker (under dashboard settings), to change ``now`` to be for example ``now-1m``, usefull when you want to ignore last minute because it contains incomplete data
- [Issue #171](https://github.com/grafana/grafana/issues/171). Panel: Different time periods, panels can override dashboard relative time and/or add a time shift
**Enhancements**
- [Issue #1297](https://github.com/grafana/grafana/issues/1297). Graphite: Added cumulative and minimumBelow graphite functions
......
......@@ -124,18 +124,19 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
// check panel time overrrides
if ($scope.panel.timeFrom) {
if (_.isString($scope.rangeUnparsed.from)) {
$scope.panelMeta.timeInfo = "Last " + $scope.panel.timeFrom;
$scope.panelMeta.timeInfo = "last " + $scope.panel.timeFrom;
$scope.rangeUnparsed.from = 'now-' + $scope.panel.timeFrom;
$scope.range.from = kbn.parseDate($scope.rangeUnparsed.from);
}
}
// if ($scope.panel.timeShift) {
// // from: now-1h
// // to: now
// // timeshift: 1d
// // from: now-1d-1h
// // to: now-1d
// }
if ($scope.panel.timeShift) {
var timeShift = '-' + $scope.panel.timeShift;
$scope.panelMeta.timeInfo += ' timeshift ' + timeShift;
$scope.range.from = kbn.parseDateMath(timeShift, $scope.range.from);
$scope.range.to = kbn.parseDateMath(timeShift, $scope.range.to);
$scope.rangeUnparsed = $scope.range;
}
if ($scope.panel.maxDataPoints) {
$scope.resolution = $scope.panel.maxDataPoints;
......
......@@ -69,4 +69,15 @@ define([
});
describe('relative time to date parsing', function() {
it('should handle negative time', function() {
var date = kbn.parseDateMath('-2d', new Date(2014,1,5));
expect(date.getTime()).to.equal(new Date(2014, 1, 3).getTime());
});
it('should handle multiple math expressions', function() {
var date = kbn.parseDateMath('-2d-6h', new Date(2014, 1, 5));
expect(date.toString()).to.equal(new Date(2014, 1, 2, 18).toString());
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment