ArrayDataFrame: use normal property for fields and length (#24145)

This commit is contained in:
Ryan McKinley
2020-05-01 07:41:55 -07:00
committed by GitHub
parent 442c087f98
commit 4710f6bebe
3 changed files with 21 additions and 13 deletions
@@ -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.theFields = names.map(name => {
this.fields = 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.theFields = Object.keys(obj).map(name => {
this.fields = 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
*/