Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a1b5aae9
Commit
a1b5aae9
authored
Jan 27, 2016
by
Carl Bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3866 from daniellee/issue3852
fix(graph): narrow panels shows correct date format on x-axis
parents
70c42ddc
f43e1ab2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
9 deletions
+40
-9
public/app/plugins/panel/graph/graph.js
+8
-5
public/app/plugins/panel/graph/specs/graph_specs.ts
+32
-4
No files found.
public/app/plugins/panel/graph/graph.js
View file @
a1b5aae9
...
...
@@ -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"
;
...
...
public/app/plugins/panel/graph/specs/graph_specs.ts
View file @
a1b5aae9
...
...
@@ -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
(
"<div style='width:
500
px' grafana-graph><div>"
);
var
element
=
angular
.
element
(
"<div style='width:
"
+
elementWidth
+
"
px' grafana-graph><div>"
);
scope
.
height
=
'200px'
;
scope
.
panel
=
{
...
...
@@ -43,8 +44,8 @@ describe('grafanaGraph', function() {
scope
.
hiddenSeries
=
{};
scope
.
dashboard
=
{
timezone
:
'browser'
};
scope
.
range
=
{
from
:
new
Date
(
'2014-08-09 10:00:00'
),
to
:
new
Date
(
'2014-09-09 13:00:00'
)
from
:
moment
([
2015
,
1
,
1
,
10
]
),
to
:
moment
([
2015
,
1
,
1
,
22
]
)
};
ctx
.
data
=
[];
ctx
.
data
.
push
(
new
TimeSeries
({
...
...
@@ -227,4 +228,31 @@ describe('grafanaGraph', function() {
expect
(
axis
.
tickFormatter
(
100
,
axis
)).
to
.
be
(
"100%"
);
});
});
graphScenario
(
'when panel too narrow to show x-axis dates in same granularity as wide panels'
,
function
(
ctx
)
{
describe
(
'and the range is less than 24 hours'
,
function
()
{
ctx
.
setup
(
function
(
scope
)
{
scope
.
range
.
from
=
moment
([
2015
,
1
,
1
,
10
]);
scope
.
range
.
to
=
moment
([
2015
,
1
,
1
,
22
]);
});
it
(
'should format dates as hours minutes'
,
function
()
{
var
axis
=
ctx
.
plotOptions
.
xaxis
;
expect
(
axis
.
timeformat
).
to
.
be
(
'%H:%M'
);
});
});
describe
(
'and the range is less than one year'
,
function
()
{
ctx
.
setup
(
function
(
scope
)
{
scope
.
range
.
from
=
moment
([
2015
,
1
,
1
]);
scope
.
range
.
to
=
moment
([
2015
,
11
,
20
]);
});
it
(
'should format dates as month days'
,
function
()
{
var
axis
=
ctx
.
plotOptions
.
xaxis
;
expect
(
axis
.
timeformat
).
to
.
be
(
'%m/%d'
);
});
});
},
10
);
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment