diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 1ebf75d9e73..257ddb875b1 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -296,7 +296,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) { max: max, label: "Datetime", ticks: ticks, - timeformat: time_format(scope.interval, ticks, min, max), + timeformat: time_format(ticks, min, max), }; } @@ -436,20 +436,23 @@ function (angular, $, moment, _, kbn, GraphTooltip) { }; } - function time_format(interval, ticks, min, max) { + function time_format(ticks, min, max) { if (min && max && ticks) { - var secPerTick = ((max - min) / ticks) / 1000; + var range = max - min; + var secPerTick = (range/ticks) / 1000; + var oneDay = 86400000; + var oneYear = 31536000000; if (secPerTick <= 45) { return "%H:%M:%S"; } - if (secPerTick <= 7200) { + if (secPerTick <= 7200 || range <= oneDay) { return "%H:%M"; } if (secPerTick <= 80000) { return "%m/%d %H:%M"; } - if (secPerTick <= 2419200) { + if (secPerTick <= 2419200 || range <= oneYear) { return "%m/%d"; } return "%Y-%m"; diff --git a/public/app/plugins/panel/graph/specs/graph_specs.ts b/public/app/plugins/panel/graph/specs/graph_specs.ts index e07033583b7..fa1d01a88f8 100644 --- a/public/app/plugins/panel/graph/specs/graph_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_specs.ts @@ -7,12 +7,13 @@ import angular from 'angular'; import $ from 'jquery'; import helpers from '../../../../../test/specs/helpers'; import TimeSeries from '../../../../core/time_series2'; +import moment from 'moment'; describe('grafanaGraph', function() { beforeEach(angularMocks.module('grafana.directives')); - function graphScenario(desc, func) { + function graphScenario(desc, func, elementWidth = 500) { describe(desc, function() { var ctx: any = {}; @@ -24,7 +25,7 @@ describe('grafanaGraph', function() { beforeEach(angularMocks.inject(function($rootScope, $compile) { var scope = $rootScope.$new(); - var element = angular.element("