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
2f8dd898
Commit
2f8dd898
authored
Mar 19, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flot pairs
parent
f69f0c2c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
3 deletions
+71
-3
packages/grafana-ui/src/utils/floatPairs.test.ts
+24
-0
packages/grafana-ui/src/utils/flotPairs.ts
+38
-0
packages/grafana-ui/src/utils/processTimeSeries.ts
+9
-3
No files found.
packages/grafana-ui/src/utils/floatPairs.test.ts
0 → 100644
View file @
2f8dd898
import
{
getFlotPairs
}
from
'./flotPairs'
;
describe
(
'getFlotPairs'
,
()
=>
{
const
table
=
{
rows
:
[[
1
,
100
,
'a'
],
[
2
,
200
,
'b'
],
[
3
,
300
,
'c'
]],
};
it
(
'should get X and y'
,
()
=>
{
const
pairs
=
getFlotPairs
({
rows
:
table
.
rows
,
xIndex
:
0
,
yIndex
:
1
});
expect
(
pairs
.
length
).
toEqual
(
3
);
expect
(
pairs
[
0
].
length
).
toEqual
(
2
);
expect
(
pairs
[
0
][
0
]).
toEqual
(
1
);
expect
(
pairs
[
0
][
1
]).
toEqual
(
100
);
});
it
(
'should work with strings'
,
()
=>
{
const
pairs
=
getFlotPairs
({
rows
:
table
.
rows
,
xIndex
:
0
,
yIndex
:
2
});
expect
(
pairs
.
length
).
toEqual
(
3
);
expect
(
pairs
[
0
].
length
).
toEqual
(
2
);
expect
(
pairs
[
0
][
0
]).
toEqual
(
1
);
expect
(
pairs
[
0
][
1
]).
toEqual
(
'a'
);
});
});
packages/grafana-ui/src/utils/flotPairs.ts
0 → 100644
View file @
2f8dd898
// Types
import
{
NullValueMode
}
from
'../types/index'
;
export
interface
FloatPairsOptions
{
rows
:
any
[][];
xIndex
:
number
;
yIndex
:
number
;
nullValueMode
?:
NullValueMode
;
}
export
function
getFlotPairs
({
rows
,
xIndex
,
yIndex
,
nullValueMode
}:
FloatPairsOptions
):
any
[][]
{
const
ignoreNulls
=
nullValueMode
===
NullValueMode
.
Ignore
;
const
nullAsZero
=
nullValueMode
===
NullValueMode
.
AsZero
;
const
pairs
:
any
[][]
=
[];
for
(
let
i
=
0
;
i
<
rows
.
length
;
i
++
)
{
const
x
=
rows
[
i
][
xIndex
];
let
y
=
rows
[
i
][
yIndex
];
if
(
y
===
null
)
{
if
(
ignoreNulls
)
{
continue
;
}
if
(
nullAsZero
)
{
y
=
0
;
}
}
// X must be a value
if
(
x
===
null
)
{
continue
;
}
pairs
.
push
([
x
,
y
]);
}
return
pairs
;
}
packages/grafana-ui/src/utils/processTimeSeries.ts
View file @
2f8dd898
...
...
@@ -5,6 +5,7 @@ import { colors } from './colors';
// Types
import
{
TimeSeries
,
TimeSeriesVMs
,
NullValueMode
,
TimeSeriesValue
}
from
'../types'
;
import
{
getFlotPairs
}
from
'./flotPairs'
;
interface
Options
{
timeSeries
:
TimeSeries
[];
...
...
@@ -15,7 +16,14 @@ export function processTimeSeries({ timeSeries, nullValueMode }: Options): TimeS
const
vmSeries
=
timeSeries
.
map
((
item
,
index
)
=>
{
const
colorIndex
=
index
%
colors
.
length
;
const
label
=
item
.
target
;
const
result
=
[];
// Use external calculator just to make sure it works :)
const
result
=
getFlotPairs
({
rows
:
item
.
datapoints
,
xIndex
:
1
,
yIndex
:
0
,
nullValueMode
,
});
// stat defaults
let
total
=
0
;
...
...
@@ -118,8 +126,6 @@ export function processTimeSeries({ timeSeries, nullValueMode }: Options): TimeS
allIsZero
=
false
;
}
}
result
.
push
([
currentTime
,
currentValue
]);
}
if
(
max
===
-
Number
.
MAX_VALUE
)
{
...
...
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