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
40e37586
Unverified
Commit
40e37586
authored
Oct 14, 2018
by
Torkel Ödegaard
Committed by
GitHub
Oct 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13662 from franciscocpg/adding-time-clock
Adding time clock
parents
37548792
b4bca473
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
0 deletions
+126
-0
public/app/core/specs/kbn.test.ts
+71
-0
public/app/core/utils/kbn.ts
+55
-0
No files found.
public/app/core/specs/kbn.test.ts
View file @
40e37586
...
...
@@ -399,6 +399,77 @@ describe('duration', () => {
});
});
describe
(
'clock'
,
()
=>
{
it
(
'null'
,
()
=>
{
const
str
=
kbn
.
toClock
(
null
,
0
);
expect
(
str
).
toBe
(
''
);
});
it
(
'size less than 1 second'
,
()
=>
{
const
str
=
kbn
.
toClock
(
999
,
0
);
expect
(
str
).
toBe
(
'999ms'
);
});
describe
(
'size less than 1 minute'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
59999
);
expect
(
str
).
toBe
(
'59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
59999
,
0
);
expect
(
str
).
toBe
(
'59s'
);
});
});
describe
(
'size less than 1 hour'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
);
expect
(
str
).
toBe
(
'59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
,
0
);
expect
(
str
).
toBe
(
'59m'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
,
1
);
expect
(
str
).
toBe
(
'59m:59s'
);
});
});
describe
(
'size greater than or equal 1 hour'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
);
expect
(
str
).
toBe
(
'01h:59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
0
);
expect
(
str
).
toBe
(
'01h'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
1
);
expect
(
str
).
toBe
(
'01h:59m'
);
});
it
(
'decimals equals 2'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
2
);
expect
(
str
).
toBe
(
'01h:59m:59s'
);
});
});
describe
(
'size greater than or equal 1 day'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
);
expect
(
str
).
toBe
(
'24h:59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
0
);
expect
(
str
).
toBe
(
'24h'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
1
);
expect
(
str
).
toBe
(
'24h:59m'
);
});
it
(
'decimals equals 2'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
2
);
expect
(
str
).
toBe
(
'24h:59m:59s'
);
});
});
});
describe
(
'volume'
,
()
=>
{
it
(
'1000m3'
,
()
=>
{
const
str
=
kbn
.
valueFormats
[
'm3'
](
1000
,
1
,
null
);
...
...
public/app/core/utils/kbn.ts
View file @
40e37586
...
...
@@ -808,6 +808,51 @@ kbn.toDuration = (size, decimals, timeScale) => {
return strings.join('
,
');
};
kbn.toClock = (size, decimals) => {
if (size === null) {
return '';
}
// < 1 second
if (size < 1000) {
return moment.utc(size).format('
SSS
\\
m
\\
s
');
}
// < 1 minute
if (size < 60000) {
let format = '
ss
\\
s
:
SSS
\\
m
\\
s
';
if (decimals === 0) {
format = '
ss
\\
s
';
}
return moment.utc(size).format(format);
}
// < 1 hour
if (size < 3600000) {
let format = '
mm
\\
m
:
ss
\\
s
:
SSS
\\
m
\\
s
';
if (decimals === 0) {
format = '
mm
\\
m
';
} else if (decimals === 1) {
format = '
mm
\\
m
:
ss
\\
s
';
}
return moment.utc(size).format(format);
}
let format = '
mm
\\
m
:
ss
\\
s
:
SSS
\\
m
\\
s
';
const hours = `${('
0
' + Math.floor(moment.duration(size, '
milliseconds
').asHours())).slice(-2)}h`;
if (decimals === 0) {
format = '';
} else if (decimals === 1) {
format = '
mm
\\
m
';
} else if (decimals === 2) {
format = '
mm
\\
m
:
ss
\\
s
';
}
return format ? `${hours}:${moment.utc(size).format(format)}` : hours;
};
kbn.valueFormats.dtdurationms = (size, decimals) => {
return kbn.toDuration(size, decimals, '
millisecond
');
};
...
...
@@ -824,6 +869,14 @@ kbn.valueFormats.timeticks = (size, decimals, scaledDecimals) => {
return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
};
kbn.valueFormats.clockms = (size, decimals) => {
return kbn.toClock(size, decimals);
};
kbn.valueFormats.clocks = (size, decimals) => {
return kbn.toClock(size * 1000, decimals);
};
kbn.valueFormats.dateTimeAsIso = (epoch, isUtc) => {
const time = isUtc ? moment.utc(epoch) : moment(epoch);
...
...
@@ -901,6 +954,8 @@ kbn.getUnitFormats = () => {
{ text: '
duration
(
s
)
', value: '
dtdurations
' },
{ text: '
duration
(
hh
:
mm
:
ss
)
', value: '
dthms
' },
{ text: '
Timeticks
(
s
/
100
)
', value: '
timeticks
' },
{ text: '
clock
(
ms
)
', value: '
clockms
' },
{ text: '
clock
(
s
)
', value: '
clocks
' },
],
},
{
...
...
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