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
55723235
Unverified
Commit
55723235
authored
Mar 24, 2019
by
Torkel Ödegaard
Committed by
GitHub
Mar 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16173 from ryantxu/no-process-timeseries
remove TimeSeriesStats and processTimeSeries
parents
4db91457
e48767a1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
237 deletions
+17
-237
packages/grafana-ui/src/types/data.ts
+0
-17
packages/grafana-ui/src/utils/index.ts
+0
-1
packages/grafana-ui/src/utils/processTimeSeries.ts
+0
-200
public/app/plugins/panel/graph2/GraphPanel.tsx
+17
-18
public/app/plugins/panel/piechart/PieChartPanel.tsx
+0
-1
No files found.
packages/grafana-ui/src/types/data.ts
View file @
55723235
...
...
@@ -20,27 +20,10 @@ export interface TimeSeriesVM {
label
:
string
;
color
:
string
;
data
:
TimeSeriesValue
[][];
stats
:
TimeSeriesStats
;
allIsNull
:
boolean
;
allIsZero
:
boolean
;
}
export
interface
TimeSeriesStats
{
[
key
:
string
]:
number
|
null
;
total
:
number
|
null
;
max
:
number
|
null
;
min
:
number
|
null
;
logmin
:
number
;
avg
:
number
|
null
;
current
:
number
|
null
;
first
:
number
|
null
;
delta
:
number
;
diff
:
number
|
null
;
range
:
number
|
null
;
timeStep
:
number
;
count
:
number
;
}
export
enum
NullValueMode
{
Null
=
'null'
,
Ignore
=
'connected'
,
...
...
packages/grafana-ui/src/utils/index.ts
View file @
55723235
export
*
from
'./processTimeSeries'
;
export
*
from
'./processTableData'
;
export
*
from
'./valueFormats/valueFormats'
;
export
*
from
'./colors'
;
...
...
packages/grafana-ui/src/utils/processTimeSeries.ts
deleted
100644 → 0
View file @
4db91457
// Libraries
import
isNumber
from
'lodash/isNumber'
;
import
{
colors
}
from
'./colors'
;
// Types
import
{
getFlotPairs
}
from
'./flotPairs'
;
import
{
TimeSeriesVMs
,
NullValueMode
,
TimeSeriesValue
,
TableData
}
from
'../types'
;
interface
Options
{
data
:
TableData
[];
xColumn
?:
number
;
// Time (or null to guess)
yColumn
?:
number
;
// Value (or null to guess)
nullValueMode
:
NullValueMode
;
}
// NOTE: this should move to processTableData.ts
// I left it as is so the merge changes are more clear.
export
function
processTimeSeries
({
data
,
xColumn
,
yColumn
,
nullValueMode
}:
Options
):
TimeSeriesVMs
{
const
vmSeries
=
data
.
map
((
item
,
index
)
=>
{
if
(
!
isNumber
(
xColumn
))
{
xColumn
=
1
;
// Default timeseries colum. TODO, find first time field!
}
if
(
!
isNumber
(
yColumn
))
{
yColumn
=
0
;
// TODO, find first non-time field
}
// TODO? either % or throw error?
if
(
xColumn
>=
item
.
columns
.
length
)
{
throw
new
Error
(
'invalid colum: '
+
xColumn
);
}
if
(
yColumn
>=
item
.
columns
.
length
)
{
throw
new
Error
(
'invalid colum: '
+
yColumn
);
}
const
colorIndex
=
index
%
colors
.
length
;
const
label
=
item
.
columns
[
yColumn
].
text
;
// Use external calculator just to make sure it works :)
const
result
=
getFlotPairs
({
rows
:
item
.
rows
,
xIndex
:
xColumn
,
yIndex
:
yColumn
,
nullValueMode
,
});
// stat defaults
let
total
=
0
;
let
max
:
TimeSeriesValue
=
-
Number
.
MAX_VALUE
;
let
min
:
TimeSeriesValue
=
Number
.
MAX_VALUE
;
let
logmin
=
Number
.
MAX_VALUE
;
let
avg
:
TimeSeriesValue
=
null
;
let
current
:
TimeSeriesValue
=
null
;
let
first
:
TimeSeriesValue
=
null
;
let
delta
:
TimeSeriesValue
=
0
;
let
diff
:
TimeSeriesValue
=
null
;
let
range
:
TimeSeriesValue
=
null
;
let
timeStep
=
Number
.
MAX_VALUE
;
let
allIsNull
=
true
;
let
allIsZero
=
true
;
const
ignoreNulls
=
nullValueMode
===
NullValueMode
.
Ignore
;
const
nullAsZero
=
nullValueMode
===
NullValueMode
.
AsZero
;
let
currentTime
:
TimeSeriesValue
=
null
;
let
currentValue
:
TimeSeriesValue
=
null
;
let
nonNulls
=
0
;
let
previousTime
:
TimeSeriesValue
=
null
;
let
previousValue
=
0
;
let
previousDeltaUp
=
true
;
for
(
let
i
=
0
;
i
<
item
.
rows
.
length
;
i
++
)
{
currentValue
=
item
.
rows
[
i
][
yColumn
];
currentTime
=
item
.
rows
[
i
][
xColumn
];
if
(
typeof
currentTime
!==
'number'
)
{
continue
;
}
if
(
currentValue
!==
null
&&
typeof
currentValue
!==
'number'
)
{
throw
{
message
:
'Time series contains non number values'
};
}
// Due to missing values we could have different timeStep all along the series
// so we have to find the minimum one (could occur with aggregators such as ZimSum)
if
(
previousTime
!==
null
&&
currentTime
!==
null
)
{
const
currentStep
=
currentTime
-
previousTime
;
if
(
currentStep
<
timeStep
)
{
timeStep
=
currentStep
;
}
}
previousTime
=
currentTime
;
if
(
currentValue
===
null
)
{
if
(
ignoreNulls
)
{
continue
;
}
if
(
nullAsZero
)
{
currentValue
=
0
;
}
}
if
(
currentValue
!==
null
)
{
if
(
isNumber
(
currentValue
))
{
total
+=
currentValue
;
allIsNull
=
false
;
nonNulls
++
;
}
if
(
currentValue
>
max
)
{
max
=
currentValue
;
}
if
(
currentValue
<
min
)
{
min
=
currentValue
;
}
if
(
first
===
null
)
{
first
=
currentValue
;
}
else
{
if
(
previousValue
>
currentValue
)
{
// counter reset
previousDeltaUp
=
false
;
if
(
i
===
item
.
rows
.
length
-
1
)
{
// reset on last
delta
+=
currentValue
;
}
}
else
{
if
(
previousDeltaUp
)
{
delta
+=
currentValue
-
previousValue
;
// normal increment
}
else
{
delta
+=
currentValue
;
// account for counter reset
}
previousDeltaUp
=
true
;
}
}
previousValue
=
currentValue
;
if
(
currentValue
<
logmin
&&
currentValue
>
0
)
{
logmin
=
currentValue
;
}
if
(
currentValue
!==
0
)
{
allIsZero
=
false
;
}
}
}
if
(
max
===
-
Number
.
MAX_VALUE
)
{
max
=
null
;
}
if
(
min
===
Number
.
MAX_VALUE
)
{
min
=
null
;
}
if
(
result
.
length
&&
!
allIsNull
)
{
avg
=
total
/
nonNulls
;
current
=
result
[
result
.
length
-
1
][
1
];
if
(
current
===
null
&&
result
.
length
>
1
)
{
current
=
result
[
result
.
length
-
2
][
1
];
}
}
if
(
max
!==
null
&&
min
!==
null
)
{
range
=
max
-
min
;
}
if
(
current
!==
null
&&
first
!==
null
)
{
diff
=
current
-
first
;
}
const
count
=
result
.
length
;
return
{
data
:
result
,
label
:
label
,
color
:
colors
[
colorIndex
],
allIsZero
,
allIsNull
,
stats
:
{
total
,
min
,
max
,
current
,
logmin
,
avg
,
diff
,
delta
,
timeStep
,
range
,
count
,
first
,
},
};
});
return
vmSeries
;
}
public/app/plugins/panel/graph2/GraphPanel.tsx
View file @
55723235
...
...
@@ -2,17 +2,9 @@
import
_
from
'lodash'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
{
Graph
,
PanelProps
,
NullValueMode
,
colors
,
TimeSeriesVMs
,
ColumnType
,
getFirstTimeColumn
,
processTimeSeries
,
}
from
'@grafana/ui'
;
import
{
Graph
,
PanelProps
,
NullValueMode
,
colors
,
TimeSeriesVMs
,
ColumnType
,
getFirstTimeColumn
}
from
'@grafana/ui'
;
import
{
Options
}
from
'./types'
;
import
{
getFlotPairs
}
from
'@grafana/ui/src/utils/flotPairs'
;
interface
Props
extends
PanelProps
<
Options
>
{}
...
...
@@ -33,16 +25,23 @@ export class GraphPanel extends PureComponent<Props> {
// Show all numeric columns
if
(
column
.
type
===
ColumnType
.
number
)
{
const
tsvm
=
processTimeSeries
({
data
:
[
table
],
xColumn
:
timeColumn
,
yColumn
:
i
,
// Use external calculator just to make sure it works :)
const
points
=
getFlotPairs
({
rows
:
table
.
rows
,
xIndex
:
timeColumn
,
yIndex
:
i
,
nullValueMode
:
NullValueMode
.
Null
,
})
[
0
]
;
});
const
colorIndex
=
vmSeries
.
length
%
colors
.
length
;
tsvm
.
color
=
colors
[
colorIndex
];
vmSeries
.
push
(
tsvm
);
vmSeries
.
push
({
label
:
column
.
text
,
data
:
points
,
color
:
colors
[
vmSeries
.
length
%
colors
.
length
],
// TODO (calculate somewhere)
allIsNull
:
false
,
allIsZero
:
false
,
});
}
}
}
...
...
public/app/plugins/panel/piechart/PieChartPanel.tsx
View file @
55723235
...
...
@@ -18,7 +18,6 @@ export class PieChartPanel extends PureComponent<Props> {
render
()
{
const
{
width
,
height
,
options
}
=
this
.
props
;
// TODO -- only process when the data/config changes
const
values
=
getSingleStatValues
(
this
.
props
);
return
(
...
...
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