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
493bf0c7
Unverified
Commit
493bf0c7
authored
May 03, 2019
by
Ryan McKinley
Committed by
GitHub
May 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: rename statsCalculator to fieldReducer (#16867)
parent
bb64a067
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
55 additions
and
51 deletions
+55
-51
packages/grafana-ui/src/components/SingleStatShared/SingleStatValueEditor.tsx
+3
-3
packages/grafana-ui/src/components/SingleStatShared/shared.ts
+4
-4
packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx
+3
-3
packages/grafana-ui/src/utils/fieldReducer.test.ts
+26
-26
packages/grafana-ui/src/utils/fieldReducer.ts
+0
-0
packages/grafana-ui/src/utils/index.ts
+1
-1
public/app/plugins/panel/bargauge/types.ts
+2
-2
public/app/plugins/panel/gauge/types.ts
+2
-2
public/app/plugins/panel/graph2/getGraphSeriesModel.ts
+7
-3
public/app/plugins/panel/piechart/types.ts
+2
-2
public/app/plugins/panel/singlestat2/SingleStatPanel.tsx
+3
-3
public/app/plugins/panel/singlestat2/types.ts
+2
-2
No files found.
packages/grafana-ui/src/components/SingleStatShared/SingleStatValueEditor.tsx
View file @
493bf0c7
...
...
@@ -8,7 +8,7 @@ import {
PanelOptionsGroup
,
StatsPicker
,
UnitPicker
,
Stat
ID
,
Reducer
ID
,
SelectOptionItem
,
}
from
'@grafana/ui'
;
...
...
@@ -27,7 +27,7 @@ export class SingleStatValueEditor extends PureComponent<Props> {
onUnitChange
=
(
unit
:
SelectOptionItem
<
string
>
)
=>
this
.
props
.
onChange
({
...
this
.
props
.
value
,
unit
:
unit
.
value
});
onStatsChange
=
(
stats
:
string
[])
=>
{
const
stat
=
stats
[
0
]
||
Stat
ID
.
mean
;
const
stat
=
stats
[
0
]
||
Reducer
ID
.
mean
;
this
.
props
.
onChange
({
...
this
.
props
.
value
,
stat
});
};
...
...
@@ -65,7 +65,7 @@ export class SingleStatValueEditor extends PureComponent<Props> {
<
StatsPicker
width=
{
12
}
placeholder=
"Choose Stat"
defaultStat=
{
Stat
ID
.
mean
}
defaultStat=
{
Reducer
ID
.
mean
}
allowMultiple=
{
false
}
stats=
{
[
stat
]
}
onChange=
{
this
.
onStatsChange
}
...
...
packages/grafana-ui/src/components/SingleStatShared/shared.ts
View file @
493bf0c7
...
...
@@ -11,7 +11,7 @@ import {
SeriesData
,
InterpolateFunction
,
}
from
'../../types'
;
import
{
get
StatsCalculators
,
calculateStats
}
from
'../../utils/statsCalculato
r'
;
import
{
get
FieldReducers
,
reduceField
}
from
'../../utils/fieldReduce
r'
;
import
{
getDisplayProcessor
}
from
'../../utils/displayValue'
;
export
{
SingleStatValueEditor
}
from
'./SingleStatValueEditor'
;
...
...
@@ -66,10 +66,10 @@ export const getSingleStatDisplayValues = (options: GetSingleStatDisplayValueOpt
// Show all fields that are not 'time'
if
(
column
.
type
===
FieldType
.
number
)
{
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
,
fieldIndex
:
i
,
stat
s
:
[
stat
],
// The stats to calculate
reducer
s
:
[
stat
],
// The stats to calculate
nullValueMode
:
NullValueMode
.
Null
,
});
...
...
@@ -124,7 +124,7 @@ export const sharedSingleStatMigrationCheck = (panel: PanelModel<SingleStatBaseO
// avg -> mean, current -> last, total -> sum
const
{
valueOptions
}
=
options
;
if
(
valueOptions
&&
valueOptions
.
stat
)
{
valueOptions
.
stat
=
get
StatsCalculato
rs
([
valueOptions
.
stat
]).
map
(
s
=>
s
.
id
)[
0
];
valueOptions
.
stat
=
get
FieldReduce
rs
([
valueOptions
.
stat
]).
map
(
s
=>
s
.
id
)[
0
];
}
}
return
options
;
...
...
packages/grafana-ui/src/components/StatsPicker/StatsPicker.tsx
View file @
493bf0c7
...
...
@@ -5,7 +5,7 @@ import difference from 'lodash/difference';
import
{
Select
}
from
'../index'
;
import
{
get
StatsCalculators
}
from
'../../utils/statsCalculato
r'
;
import
{
get
FieldReducers
}
from
'../../utils/fieldReduce
r'
;
import
{
SelectOptionItem
}
from
'../Select/Select'
;
interface
Props
{
...
...
@@ -34,7 +34,7 @@ export class StatsPicker extends PureComponent<Props> {
checkInput
=
()
=>
{
const
{
stats
,
allowMultiple
,
defaultStat
,
onChange
}
=
this
.
props
;
const
current
=
get
StatsCalculato
rs
(
stats
);
const
current
=
get
FieldReduce
rs
(
stats
);
if
(
current
.
length
!==
stats
.
length
)
{
const
found
=
current
.
map
(
v
=>
v
.
id
);
const
notFound
=
difference
(
stats
,
found
);
...
...
@@ -65,7 +65,7 @@ export class StatsPicker extends PureComponent<Props> {
render
()
{
const
{
width
,
stats
,
allowMultiple
,
defaultStat
,
placeholder
}
=
this
.
props
;
const
options
=
get
StatsCalculato
rs
().
map
(
s
=>
{
const
options
=
get
FieldReduce
rs
().
map
(
s
=>
{
return
{
value
:
s
.
id
,
label
:
s
.
name
,
...
...
packages/grafana-ui/src/utils/
statsCalculato
r.test.ts
→
packages/grafana-ui/src/utils/
fieldReduce
r.test.ts
View file @
493bf0c7
import
{
get
StatsCalculators
,
StatID
,
calculateStats
}
from
'./statsCalculato
r'
;
import
{
get
FieldReducers
,
ReducerID
,
reduceField
}
from
'./fieldReduce
r'
;
import
_
from
'lodash'
;
...
...
@@ -10,28 +10,28 @@ describe('Stats Calculators', () => {
it
(
'should load all standard stats'
,
()
=>
{
const
names
=
[
Stat
ID
.
sum
,
Stat
ID
.
max
,
Stat
ID
.
min
,
Stat
ID
.
logmin
,
Stat
ID
.
mean
,
Stat
ID
.
last
,
Stat
ID
.
first
,
Stat
ID
.
count
,
Stat
ID
.
range
,
Stat
ID
.
diff
,
Stat
ID
.
step
,
Stat
ID
.
delta
,
//
Stat
ID.allIsZero,
//
Stat
ID.allIsNull,
Reducer
ID
.
sum
,
Reducer
ID
.
max
,
Reducer
ID
.
min
,
Reducer
ID
.
logmin
,
Reducer
ID
.
mean
,
Reducer
ID
.
last
,
Reducer
ID
.
first
,
Reducer
ID
.
count
,
Reducer
ID
.
range
,
Reducer
ID
.
diff
,
Reducer
ID
.
step
,
Reducer
ID
.
delta
,
//
Reducer
ID.allIsZero,
//
Reducer
ID.allIsNull,
];
const
stats
=
get
StatsCalculato
rs
(
names
);
const
stats
=
get
FieldReduce
rs
(
names
);
expect
(
stats
.
length
).
toBe
(
names
.
length
);
});
it
(
'should fail to load unknown stats'
,
()
=>
{
const
names
=
[
'not a stat'
,
StatID
.
max
,
Stat
ID
.
min
,
'also not a stat'
];
const
stats
=
get
StatsCalculato
rs
(
names
);
const
names
=
[
'not a stat'
,
ReducerID
.
max
,
Reducer
ID
.
min
,
'also not a stat'
];
const
stats
=
get
FieldReduce
rs
(
names
);
expect
(
stats
.
length
).
toBe
(
2
);
const
found
=
stats
.
map
(
v
=>
v
.
id
);
...
...
@@ -42,10 +42,10 @@ describe('Stats Calculators', () => {
});
it
(
'should calculate basic stats'
,
()
=>
{
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
:
basicTable
,
fieldIndex
:
0
,
stat
s
:
[
'first'
,
'last'
,
'mean'
],
reducer
s
:
[
'first'
,
'last'
,
'mean'
],
});
// First
...
...
@@ -59,10 +59,10 @@ describe('Stats Calculators', () => {
});
it
(
'should support a single stat also'
,
()
=>
{
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
:
basicTable
,
fieldIndex
:
0
,
stat
s
:
[
'first'
],
reducer
s
:
[
'first'
],
});
// Should do the simple version that just looks up value
...
...
@@ -71,10 +71,10 @@ describe('Stats Calculators', () => {
});
it
(
'should get non standard stats'
,
()
=>
{
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
:
basicTable
,
fieldIndex
:
0
,
stats
:
[
StatID
.
distinctCount
,
Stat
ID
.
changeCount
],
reducers
:
[
ReducerID
.
distinctCount
,
Reducer
ID
.
changeCount
],
});
expect
(
stats
.
distinctCount
).
toEqual
(
2
);
...
...
@@ -82,10 +82,10 @@ describe('Stats Calculators', () => {
});
it
(
'should calculate step'
,
()
=>
{
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
:
{
fields
:
[{
name
:
'A'
}],
rows
:
[[
100
],
[
200
],
[
300
],
[
400
]]
},
fieldIndex
:
0
,
stats
:
[
StatID
.
step
,
Stat
ID
.
delta
],
reducers
:
[
ReducerID
.
step
,
Reducer
ID
.
delta
],
});
expect
(
stats
.
step
).
toEqual
(
100
);
...
...
packages/grafana-ui/src/utils/
statsCalculato
r.ts
→
packages/grafana-ui/src/utils/
fieldReduce
r.ts
View file @
493bf0c7
This diff is collapsed.
Click to expand it.
packages/grafana-ui/src/utils/index.ts
View file @
493bf0c7
...
...
@@ -5,7 +5,7 @@ export * from './namedColorsPalette';
export
*
from
'./thresholds'
;
export
*
from
'./string'
;
export
*
from
'./csv'
;
export
*
from
'./
statsCalculato
r'
;
export
*
from
'./
fieldReduce
r'
;
export
*
from
'./displayValue'
;
export
*
from
'./deprecationWarning'
;
export
*
from
'./logs'
;
...
...
public/app/plugins/panel/bargauge/types.ts
View file @
493bf0c7
import
{
VizOrientation
,
SelectOptionItem
,
Stat
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
import
{
VizOrientation
,
SelectOptionItem
,
Reducer
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
export
interface
BarGaugeOptions
extends
SingleStatBaseOptions
{
minValue
:
number
;
...
...
@@ -24,7 +24,7 @@ export const defaults: BarGaugeOptions = {
orientation
:
VizOrientation
.
Horizontal
,
valueOptions
:
{
unit
:
'none'
,
stat
:
Stat
ID
.
mean
,
stat
:
Reducer
ID
.
mean
,
prefix
:
''
,
suffix
:
''
,
decimals
:
null
,
...
...
public/app/plugins/panel/gauge/types.ts
View file @
493bf0c7
import
{
VizOrientation
,
Stat
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
import
{
VizOrientation
,
Reducer
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
export
interface
GaugeOptions
extends
SingleStatBaseOptions
{
maxValue
:
number
;
...
...
@@ -16,7 +16,7 @@ export const defaults: GaugeOptions = {
prefix
:
''
,
suffix
:
''
,
decimals
:
null
,
stat
:
Stat
ID
.
mean
,
stat
:
Reducer
ID
.
mean
,
unit
:
'none'
,
},
valueMappings
:
[],
...
...
public/app/plugins/panel/graph2/getGraphSeriesModel.ts
View file @
493bf0c7
import
{
GraphSeriesXY
,
NullValueMode
,
calculateStats
,
reduceField
,
colors
,
getFlotPairs
,
getColorFromHexRgbOrName
,
...
...
@@ -45,8 +45,12 @@ export const getGraphSeriesModel = (
});
if
(
points
.
length
>
0
)
{
const
seriesStats
=
calculateStats
({
series
,
stats
:
legendOptions
.
stats
,
fieldIndex
:
field
.
index
});
let
statsDisplayValues
;
const
seriesStats
=
reduceField
({
series
,
reducers
:
legendOptions
.
stats
,
fieldIndex
:
field
.
index
,
});
let
statsDisplayValues
:
DisplayValue
[];
if
(
legendOptions
.
stats
)
{
statsDisplayValues
=
legendOptions
.
stats
.
map
<
DisplayValue
>
(
stat
=>
{
...
...
public/app/plugins/panel/piechart/types.ts
View file @
493bf0c7
import
{
PieChartType
,
Stat
ID
,
VizOrientation
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
import
{
PieChartType
,
Reducer
ID
,
VizOrientation
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
export
interface
PieChartOptions
extends
SingleStatBaseOptions
{
pieType
:
PieChartType
;
...
...
@@ -10,7 +10,7 @@ export const defaults: PieChartOptions = {
strokeWidth
:
1
,
valueOptions
:
{
unit
:
'short'
,
stat
:
Stat
ID
.
last
,
stat
:
Reducer
ID
.
last
,
suffix
:
''
,
prefix
:
''
,
},
...
...
public/app/plugins/panel/singlestat2/SingleStatPanel.tsx
View file @
493bf0c7
...
...
@@ -16,7 +16,7 @@ import {
PanelProps
,
getDisplayProcessor
,
NullValueMode
,
calculateStats
,
reduceField
,
FieldCache
,
FieldType
,
}
from
'@grafana/ui'
;
...
...
@@ -57,10 +57,10 @@ export class SingleStatPanel extends PureComponent<PanelProps<SingleStatOptions>
for
(
let
i
=
0
;
i
<
numberFields
.
length
;
i
++
)
{
const
field
=
numberFields
[
i
];
const
stats
=
calculateStats
({
const
stats
=
reduceField
({
series
,
fieldIndex
:
field
.
index
,
stat
s
:
[
stat
],
// The stats to calculate
reducer
s
:
[
stat
],
// The stats to calculate
nullValueMode
:
NullValueMode
.
Null
,
});
...
...
public/app/plugins/panel/singlestat2/types.ts
View file @
493bf0c7
import
{
VizOrientation
,
Stat
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
import
{
VizOrientation
,
Reducer
ID
,
SingleStatBaseOptions
}
from
'@grafana/ui'
;
export
interface
SparklineOptions
{
show
:
boolean
;
...
...
@@ -33,7 +33,7 @@ export const defaults: SingleStatOptions = {
prefix
:
''
,
suffix
:
''
,
decimals
:
null
,
stat
:
Stat
ID
.
mean
,
stat
:
Reducer
ID
.
mean
,
unit
:
'none'
,
},
valueMappings
:
[],
...
...
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