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
941b770c
Commit
941b770c
authored
Mar 25, 2019
by
Ryan McKinley
Committed by
Torkel Ödegaard
Mar 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: more TableData to SeriesData renaming (#16206)
parent
dbc2f276
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
47 deletions
+47
-47
packages/grafana-ui/src/components/Table/Table.tsx
+1
-1
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
+1
-1
packages/grafana-ui/src/utils/__snapshots__/processSeriesData.test.ts.snap
+0
-0
packages/grafana-ui/src/utils/index.ts
+1
-1
packages/grafana-ui/src/utils/processSeriesData.test.ts
+16
-16
packages/grafana-ui/src/utils/processSeriesData.ts
+27
-27
packages/grafana-ui/src/utils/statsCalculator.test.ts
+1
-1
No files found.
packages/grafana-ui/src/components/Table/Table.tsx
View file @
941b770c
...
...
@@ -12,7 +12,7 @@ import {
}
from
'react-virtualized'
;
import
{
Themeable
}
from
'../../types/theme'
;
import
{
sortSeriesData
}
from
'../../utils/process
Table
Data'
;
import
{
sortSeriesData
}
from
'../../utils/process
Series
Data'
;
import
{
SeriesData
,
InterpolateFunction
}
from
'@grafana/ui'
;
import
{
...
...
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
View file @
941b770c
import
React
from
'react'
;
import
debounce
from
'lodash/debounce'
;
import
{
parseCSV
,
TableParseOptions
,
TableParseDetails
}
from
'../../utils/process
Table
Data'
;
import
{
parseCSV
,
TableParseOptions
,
TableParseDetails
}
from
'../../utils/process
Series
Data'
;
import
{
SeriesData
}
from
'../../types/data'
;
import
{
AutoSizer
}
from
'react-virtualized'
;
...
...
packages/grafana-ui/src/utils/__snapshots__/process
Table
Data.test.ts.snap
→
packages/grafana-ui/src/utils/__snapshots__/process
Series
Data.test.ts.snap
View file @
941b770c
File moved
packages/grafana-ui/src/utils/index.ts
View file @
941b770c
export
*
from
'./process
Table
Data'
;
export
*
from
'./process
Series
Data'
;
export
*
from
'./valueFormats/valueFormats'
;
export
*
from
'./colors'
;
export
*
from
'./namedColorsPalette'
;
...
...
packages/grafana-ui/src/utils/process
Table
Data.test.ts
→
packages/grafana-ui/src/utils/process
Series
Data.test.ts
View file @
941b770c
import
{
parseCSV
,
toSeriesData
,
guessFieldTypes
,
guessFieldTypeFromValue
}
from
'./process
Table
Data'
;
import
{
parseCSV
,
toSeriesData
,
guessFieldTypes
,
guessFieldTypeFromValue
}
from
'./process
Series
Data'
;
import
{
FieldType
}
from
'../types/data'
;
import
moment
from
'moment'
;
...
...
@@ -11,25 +11,25 @@ describe('processSeriesData', () => {
it
(
'should generate a header and fix widths'
,
()
=>
{
const
text
=
'1
\
n2,3,4
\
n5,6'
;
const
table
=
parseCSV
(
text
,
{
const
series
=
parseCSV
(
text
,
{
headerIsFirstLine
:
false
,
});
expect
(
table
.
rows
.
length
).
toBe
(
3
);
expect
(
series
.
rows
.
length
).
toBe
(
3
);
expect
(
table
).
toMatchSnapshot
();
expect
(
series
).
toMatchSnapshot
();
});
});
});
describe
(
'toSeriesData'
,
()
=>
{
it
(
'converts timeseries to
table
'
,
()
=>
{
it
(
'converts timeseries to
series
'
,
()
=>
{
const
input1
=
{
target
:
'Field Name'
,
datapoints
:
[[
100
,
1
],
[
200
,
2
]],
};
let
table
=
toSeriesData
(
input1
);
expect
(
table
.
fields
[
0
].
name
).
toBe
(
input1
.
target
);
expect
(
table
.
rows
).
toBe
(
input1
.
datapoints
);
let
series
=
toSeriesData
(
input1
);
expect
(
series
.
fields
[
0
].
name
).
toBe
(
input1
.
target
);
expect
(
series
.
rows
).
toBe
(
input1
.
datapoints
);
// Should fill a default name if target is empty
const
input2
=
{
...
...
@@ -37,17 +37,17 @@ describe('toSeriesData', () => {
target
:
''
,
datapoints
:
[[
100
,
1
],
[
200
,
2
]],
};
table
=
toSeriesData
(
input2
);
expect
(
table
.
fields
[
0
].
name
).
toEqual
(
'Value'
);
series
=
toSeriesData
(
input2
);
expect
(
series
.
fields
[
0
].
name
).
toEqual
(
'Value'
);
});
it
(
'keeps
table
Data unchanged'
,
()
=>
{
it
(
'keeps
series
Data unchanged'
,
()
=>
{
const
input
=
{
fields
:
[{
text
:
'A'
},
{
text
:
'B'
},
{
text
:
'C'
}],
rows
:
[[
100
,
'A'
,
1
],
[
200
,
'B'
,
2
],
[
300
,
'C'
,
3
]],
};
const
table
=
toSeriesData
(
input
);
expect
(
table
).
toBe
(
input
);
const
series
=
toSeriesData
(
input
);
expect
(
series
).
toBe
(
input
);
});
it
(
'Guess Colum Types from value'
,
()
=>
{
...
...
@@ -70,12 +70,12 @@ describe('toSeriesData', () => {
expect
(
guessFieldTypeFromValue
(
'xxxx'
)).
toBe
(
FieldType
.
string
);
});
it
(
'Guess Colum Types from
table
'
,
()
=>
{
const
table
=
{
it
(
'Guess Colum Types from
series
'
,
()
=>
{
const
series
=
{
fields
:
[{
name
:
'A (number)'
},
{
name
:
'B (strings)'
},
{
name
:
'C (nulls)'
},
{
name
:
'Time'
}],
rows
:
[[
123
,
null
,
null
,
'2000'
],
[
null
,
'Hello'
,
null
,
'XXX'
]],
};
const
norm
=
guessFieldTypes
(
table
);
const
norm
=
guessFieldTypes
(
series
);
expect
(
norm
.
fields
[
0
].
type
).
toBe
(
FieldType
.
number
);
expect
(
norm
.
fields
[
1
].
type
).
toBe
(
FieldType
.
string
);
expect
(
norm
.
fields
[
2
].
type
).
toBeUndefined
();
...
...
packages/grafana-ui/src/utils/process
Table
Data.ts
→
packages/grafana-ui/src/utils/process
Series
Data.ts
View file @
941b770c
...
...
@@ -7,7 +7,7 @@ import moment from 'moment';
import
Papa
,
{
ParseError
,
ParseMeta
}
from
'papaparse'
;
// Types
import
{
SeriesData
,
Field
,
TimeSeries
,
FieldType
,
TableData
}
from
'../types'
;
import
{
SeriesData
,
Field
,
TimeSeries
,
FieldType
,
TableData
}
from
'../types
/index
'
;
// Subset of all parse options
export
interface
TableParseOptions
{
...
...
@@ -27,13 +27,13 @@ export interface TableParseDetails {
/**
* This makes sure the header and all rows have equal length.
*
* @param
table
(immutable)
* @returns a
new table
that has equal length rows, or the same
*
table
if no changes were needed
* @param
series
(immutable)
* @returns a
series
that has equal length rows, or the same
*
series
if no changes were needed
*/
export
function
matchRowSizes
(
table
:
SeriesData
):
SeriesData
{
const
{
rows
}
=
table
;
let
{
fields
}
=
table
;
export
function
matchRowSizes
(
series
:
SeriesData
):
SeriesData
{
const
{
rows
}
=
series
;
let
{
fields
}
=
series
;
let
sameSize
=
true
;
let
size
=
fields
.
length
;
...
...
@@ -44,7 +44,7 @@ export function matchRowSizes(table: SeriesData): SeriesData {
}
});
if
(
sameSize
)
{
return
table
;
return
series
;
}
// Pad Fields
...
...
@@ -164,8 +164,8 @@ function convertTimeSeriesToSeriesData(timeSeries: TimeSeries): SeriesData {
};
}
export
const
getFirstTimeField
=
(
table
:
SeriesData
):
number
=>
{
const
{
fields
}
=
table
;
export
const
getFirstTimeField
=
(
series
:
SeriesData
):
number
=>
{
const
{
fields
}
=
series
;
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
if
(
fields
[
i
].
type
===
FieldType
.
time
)
{
return
i
;
...
...
@@ -214,8 +214,8 @@ export function guessFieldTypeFromValue(v: any): FieldType {
/**
* Looks at the data to guess the column type. This ignores any existing setting
*/
function
guessFieldTypeFromTable
(
table
:
SeriesData
,
index
:
number
):
FieldType
|
undefined
{
const
column
=
table
.
fields
[
index
];
function
guessFieldTypeFromTable
(
series
:
SeriesData
,
index
:
number
):
FieldType
|
undefined
{
const
column
=
series
.
fields
[
index
];
// 1. Use the column name to guess
if
(
column
.
name
)
{
...
...
@@ -226,8 +226,8 @@ function guessFieldTypeFromTable(table: SeriesData, index: number): FieldType |
}
// 2. Check the first non-null value
for
(
let
i
=
0
;
i
<
table
.
rows
.
length
;
i
++
)
{
const
v
=
table
.
rows
[
i
][
index
];
for
(
let
i
=
0
;
i
<
series
.
rows
.
length
;
i
++
)
{
const
v
=
series
.
rows
[
i
][
index
];
if
(
v
!==
null
)
{
return
guessFieldTypeFromValue
(
v
);
}
...
...
@@ -238,30 +238,30 @@ function guessFieldTypeFromTable(table: SeriesData, index: number): FieldType |
}
/**
* @returns a
table Returns a copy of the table with the best guess for each column
type
* If the
table already has column
types defined, they will be used
* @returns a
copy of the series with the best guess for each field
type
* If the
series already has field
types defined, they will be used
*/
export
const
guessFieldTypes
=
(
table
:
SeriesData
):
SeriesData
=>
{
for
(
let
i
=
0
;
i
<
table
.
fields
.
length
;
i
++
)
{
if
(
!
table
.
fields
[
i
].
type
)
{
export
const
guessFieldTypes
=
(
series
:
SeriesData
):
SeriesData
=>
{
for
(
let
i
=
0
;
i
<
series
.
fields
.
length
;
i
++
)
{
if
(
!
series
.
fields
[
i
].
type
)
{
// Somethign is missing a type return a modified copy
return
{
...
table
,
fields
:
table
.
fields
.
map
((
column
,
index
)
=>
{
if
(
column
.
type
)
{
return
column
;
...
series
,
fields
:
series
.
fields
.
map
((
field
,
index
)
=>
{
if
(
field
.
type
)
{
return
field
;
}
// Replace it with a calculated version
return
{
...
column
,
type
:
guessFieldTypeFromTable
(
table
,
index
),
...
field
,
type
:
guessFieldTypeFromTable
(
series
,
index
),
};
}),
};
}
}
// No changes necessary
return
table
;
return
series
;
};
export
const
isTableData
=
(
data
:
any
):
data
is
SeriesData
=>
data
&&
data
.
hasOwnProperty
(
'columns'
);
...
...
@@ -278,7 +278,7 @@ export const toSeriesData = (data: any): SeriesData => {
if
(
data
.
hasOwnProperty
(
'columns'
))
{
return
convertTableToSeriesData
(
data
);
}
// TODO, try to convert JSON/Array to
table
?
// TODO, try to convert JSON/Array to
seriesta
?
console
.
warn
(
'Can not convert'
,
data
);
throw
new
Error
(
'Unsupported data format'
);
};
...
...
packages/grafana-ui/src/utils/statsCalculator.test.ts
View file @
941b770c
import
{
parseCSV
}
from
'./process
Table
Data'
;
import
{
parseCSV
}
from
'./process
Series
Data'
;
import
{
getStatsCalculators
,
StatID
,
calculateStats
}
from
'./statsCalculator'
;
import
_
from
'lodash'
;
...
...
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