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
c9c7bfbc
Unverified
Commit
c9c7bfbc
authored
Feb 02, 2021
by
Ryan McKinley
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transforms: allow boolean in field calculations (#30802)
parent
25ef563a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
3 deletions
+62
-3
packages/grafana-data/src/transformations/transformers/calculateField.test.ts
+38
-2
packages/grafana-data/src/transformations/transformers/calculateField.ts
+4
-0
packages/grafana-data/src/vector/AsNumberVector.ts
+16
-0
packages/grafana-data/src/vector/index.ts
+1
-0
public/app/core/components/TransformersUI/CalculateFieldTransformerEditor.tsx
+3
-1
No files found.
packages/grafana-data/src/transformations/transformers/calculateField.test.ts
View file @
c9c7bfbc
...
...
@@ -21,6 +21,7 @@ const seriesBC = toDataFrame({
{
name
:
'B'
,
type
:
FieldType
.
number
,
values
:
[
2
,
200
]
},
{
name
:
'C'
,
type
:
FieldType
.
number
,
values
:
[
3
,
300
]
},
{
name
:
'D'
,
type
:
FieldType
.
string
,
values
:
[
'first'
,
'second'
]
},
{
name
:
'E'
,
type
:
FieldType
.
boolean
,
values
:
[
true
,
false
]
},
],
});
...
...
@@ -48,6 +49,7 @@ describe('calculateField transformer w/ timeseries', () => {
B
:
2
,
C
:
3
,
D
:
'first'
,
E
:
true
,
'The Total'
:
6
,
TheTime
:
1000
,
},
...
...
@@ -56,6 +58,7 @@ describe('calculateField transformer w/ timeseries', () => {
B
:
200
,
C
:
300
,
D
:
'second'
,
E
:
false
,
'The Total'
:
600
,
TheTime
:
2000
,
},
...
...
@@ -129,7 +132,7 @@ describe('calculateField transformer w/ timeseries', () => {
mode
:
CalculateFieldMode
.
BinaryOperation
,
binary
:
{
left
:
'B'
,
operat
ion
:
BinaryOperationID
.
Add
,
operat
or
:
BinaryOperationID
.
Add
,
right
:
'C'
,
},
replaceFields
:
true
,
...
...
@@ -160,7 +163,7 @@ describe('calculateField transformer w/ timeseries', () => {
mode
:
CalculateFieldMode
.
BinaryOperation
,
binary
:
{
left
:
'B'
,
operat
ion
:
BinaryOperationID
.
Add
,
operat
or
:
BinaryOperationID
.
Add
,
right
:
'2'
,
},
replaceFields
:
true
,
...
...
@@ -183,4 +186,37 @@ describe('calculateField transformer w/ timeseries', () => {
]);
});
});
it
(
'boolean field'
,
async
()
=>
{
const
cfg
=
{
id
:
DataTransformerID
.
calculateField
,
options
:
{
mode
:
CalculateFieldMode
.
BinaryOperation
,
binary
:
{
left
:
'E'
,
operator
:
BinaryOperationID
.
Multiply
,
right
:
'1'
,
},
replaceFields
:
true
,
},
};
await
expect
(
transformDataFrame
([
cfg
],
[
seriesBC
])).
toEmitValuesWith
((
received
)
=>
{
const
data
=
received
[
0
];
const
filtered
=
data
[
0
];
const
rows
=
new
DataFrameView
(
filtered
).
toArray
();
expect
(
rows
).
toMatchInlineSnapshot
(
`
Array [
Object {
"E * 1": 1,
"TheTime": 1000,
},
Object {
"E * 1": 0,
"TheTime": 2000,
},
]
`
);
});
});
});
packages/grafana-data/src/transformations/transformers/calculateField.ts
View file @
c9c7bfbc
...
...
@@ -7,6 +7,7 @@ import { getFieldMatcher } from '../matchers';
import
{
FieldMatcherID
}
from
'../matchers/ids'
;
import
{
RowVector
}
from
'../../vector/RowVector'
;
import
{
ArrayVector
,
BinaryOperationVector
,
ConstantVector
}
from
'../../vector'
;
import
{
AsNumberVector
}
from
'../../vector/AsNumberVector'
;
import
{
getTimeField
}
from
'../../dataframe/processDataFrame'
;
import
defaults
from
'lodash/defaults'
;
import
{
BinaryOperationID
,
binaryOperators
}
from
'../../utils/binaryOperators'
;
...
...
@@ -187,6 +188,9 @@ function findFieldValuesWithNameOrConstant(frame: DataFrame, name: string, allFr
for
(
const
f
of
frame
.
fields
)
{
if
(
name
===
getFieldDisplayName
(
f
,
frame
,
allFrames
))
{
if
(
f
.
type
===
FieldType
.
boolean
)
{
return
new
AsNumberVector
(
f
.
values
);
}
return
f
.
values
;
}
}
...
...
packages/grafana-data/src/vector/AsNumberVector.ts
0 → 100644
View file @
c9c7bfbc
import
{
Vector
}
from
'../types'
;
import
{
FunctionalVector
}
from
'./FunctionalVector'
;
export
class
AsNumberVector
extends
FunctionalVector
<
number
>
{
constructor
(
private
field
:
Vector
)
{
super
();
}
get
length
()
{
return
this
.
field
.
length
;
}
get
(
index
:
number
)
{
return
+
this
.
field
.
get
(
index
);
}
}
packages/grafana-data/src/vector/index.ts
View file @
c9c7bfbc
...
...
@@ -6,5 +6,6 @@ export * from './BinaryOperationVector';
export
*
from
'./SortedVector'
;
export
*
from
'./FormattedVector'
;
export
*
from
'./IndexVector'
;
export
*
from
'./AsNumberVector'
;
export
{
vectorator
}
from
'./FunctionalVector'
;
public/app/core/components/TransformersUI/CalculateFieldTransformerEditor.tsx
View file @
c9c7bfbc
...
...
@@ -39,6 +39,8 @@ const calculationModes = [
{
value
:
CalculateFieldMode
.
ReduceRow
,
label
:
'Reduce row'
},
];
const
okTypes
=
new
Set
<
FieldType
>
([
FieldType
.
time
,
FieldType
.
number
,
FieldType
.
string
]);
export
class
CalculateFieldTransformerEditor
extends
React
.
PureComponent
<
CalculateFieldTransformerEditorProps
,
CalculateFieldTransformerEditorState
...
...
@@ -86,7 +88,7 @@ export class CalculateFieldTransformerEditor extends React.PureComponent<
for
(
const
frame
of
input
)
{
for
(
const
field
of
frame
.
fields
)
{
if
(
field
.
type
!==
FieldType
.
number
)
{
if
(
!
okTypes
.
has
(
field
.
type
)
)
{
continue
;
}
...
...
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