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