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
4710f6be
Unverified
Commit
4710f6be
authored
May 01, 2020
by
Ryan McKinley
Committed by
GitHub
May 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ArrayDataFrame: use normal property for fields and length (#24145)
parent
442c087f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
packages/grafana-data/src/dataframe/ArrayDataFrame.test.ts
+11
-1
packages/grafana-data/src/dataframe/ArrayDataFrame.ts
+5
-12
packages/grafana-data/src/dataframe/processDataFrame.ts
+5
-0
No files found.
packages/grafana-data/src/dataframe/ArrayDataFrame.test.ts
View file @
4710f6be
import
{
ArrayDataFrame
}
from
'./ArrayDataFrame'
;
import
{
toDataFrameDTO
}
from
'./processDataFrame'
;
import
{
FieldType
}
from
'../types'
;
import
{
FieldType
,
DataFrame
}
from
'../types'
;
describe
(
'Array DataFrame'
,
()
=>
{
const
input
=
[
...
...
@@ -92,4 +92,14 @@ describe('Array DataFrame', () => {
}
`
);
});
test
(
'Survives ES6 operations'
,
()
=>
{
const
copy
:
DataFrame
=
{
...
frame
,
name
:
'hello'
,
};
expect
(
copy
.
fields
).
toEqual
(
frame
.
fields
);
expect
(
copy
.
length
).
toEqual
(
frame
.
length
);
expect
(
copy
.
length
).
toEqual
(
input
.
length
);
});
});
packages/grafana-data/src/dataframe/ArrayDataFrame.ts
View file @
4710f6be
...
...
@@ -40,14 +40,16 @@ export class ArrayDataFrame<T = any> extends FunctionalVector<T> implements Data
refId
?:
string
;
meta
?:
QueryResultMeta
;
private
theFields
:
Field
[]
=
[];
fields
:
Field
[]
=
[];
length
=
0
;
constructor
(
private
source
:
T
[],
names
?:
string
[])
{
super
();
this
.
length
=
source
.
length
;
const
first
:
any
=
source
.
length
?
source
[
0
]
:
{};
if
(
names
)
{
this
.
theF
ields
=
names
.
map
(
name
=>
{
this
.
f
ields
=
names
.
map
(
name
=>
{
return
{
name
,
type
:
guessFieldTypeFromNameAndValue
(
name
,
first
[
name
]),
...
...
@@ -64,7 +66,7 @@ export class ArrayDataFrame<T = any> extends FunctionalVector<T> implements Data
* Add a field for each property in the object. This will guess the type
*/
setFieldsFromObject
(
obj
:
any
)
{
this
.
theF
ields
=
Object
.
keys
(
obj
).
map
(
name
=>
{
this
.
f
ields
=
Object
.
keys
(
obj
).
map
(
name
=>
{
return
{
name
,
type
:
guessFieldTypeFromNameAndValue
(
name
,
obj
[
name
]),
...
...
@@ -94,15 +96,6 @@ export class ArrayDataFrame<T = any> extends FunctionalVector<T> implements Data
return
field
;
}
get
fields
():
Field
[]
{
return
this
.
theFields
;
}
// Defined for Vector interface
get
length
()
{
return
this
.
source
.
length
;
}
/**
* Get an object with a property for each field in the DataFrame
*/
...
...
packages/grafana-data/src/dataframe/processDataFrame.ts
View file @
4710f6be
...
...
@@ -19,6 +19,7 @@ import { isDateTime } from '../datetime/moment_wrapper';
import
{
ArrayVector
}
from
'../vector/ArrayVector'
;
import
{
MutableDataFrame
}
from
'./MutableDataFrame'
;
import
{
SortedVector
}
from
'../vector/SortedVector'
;
import
{
ArrayDataFrame
}
from
'./ArrayDataFrame'
;
function
convertTableToDataFrame
(
table
:
TableData
):
DataFrame
{
const
fields
=
table
.
columns
.
map
(
c
=>
{
...
...
@@ -293,6 +294,10 @@ export function toDataFrame(data: any): DataFrame {
return
convertTableToDataFrame
(
data
);
}
if
(
Array
.
isArray
(
data
))
{
return
new
ArrayDataFrame
(
data
);
}
console
.
warn
(
'Can not convert'
,
data
);
throw
new
Error
(
'Unsupported data format'
);
}
...
...
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