FieldValues: Use standard array functions (#67012)
This commit is contained in:
@@ -119,7 +119,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
// Make sure the field starts with a given length
|
||||
if (startLength) {
|
||||
while (field.values.length < startLength) {
|
||||
field.values.add(MISSING_VALUE);
|
||||
field.values.push(MISSING_VALUE);
|
||||
}
|
||||
} else {
|
||||
this.validate();
|
||||
@@ -137,7 +137,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
// Add empty elements until everything matches
|
||||
for (const field of this.fields) {
|
||||
while (field.values.length !== length) {
|
||||
field.values.add(MISSING_VALUE);
|
||||
field.values.push(MISSING_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
if (f.type !== FieldType.string && isString(v)) {
|
||||
v = this.parseValue(f, v);
|
||||
}
|
||||
f.values.add(v);
|
||||
f.values.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
val = MISSING_VALUE;
|
||||
}
|
||||
|
||||
field.values.add(val);
|
||||
field.values.push(val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
|
||||
const obj = (value as any) || {};
|
||||
for (const field of this.fields) {
|
||||
field.values.set(index, obj[field.name]);
|
||||
field.values[index] = obj[field.name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
get(idx: number): T {
|
||||
const v: any = {};
|
||||
for (const field of this.fields) {
|
||||
v[field.name] = field.values.get(idx);
|
||||
v[field.name] = field.values[idx];
|
||||
}
|
||||
return v as T;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { isNumber } from 'lodash';
|
||||
|
||||
import { dateTime, isDateTimeInput } from '../datetime';
|
||||
import { Field, FieldType } from '../types/dataFrame';
|
||||
import { Vector } from '../types/vector';
|
||||
|
||||
type IndexComparer = (a: number, b: number) => number;
|
||||
|
||||
@@ -79,12 +78,12 @@ const falsyComparer = (a: unknown, b: unknown): number => {
|
||||
return 0;
|
||||
};
|
||||
|
||||
const timestampIndexComparer = (values: Vector<number>, reverse: boolean): IndexComparer => {
|
||||
const timestampIndexComparer = (values: number[], reverse: boolean): IndexComparer => {
|
||||
let mult = reverse ? -1 : 1;
|
||||
return (a: number, b: number): number => mult * (values[a] - values[b]);
|
||||
};
|
||||
|
||||
const timeIndexComparer = (values: Vector<unknown>, reverse: boolean): IndexComparer => {
|
||||
const timeIndexComparer = (values: unknown[], reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA = values[a];
|
||||
const vB = values[b];
|
||||
@@ -92,7 +91,7 @@ const timeIndexComparer = (values: Vector<unknown>, reverse: boolean): IndexComp
|
||||
};
|
||||
};
|
||||
|
||||
const booleanIndexComparer = (values: Vector<boolean>, reverse: boolean): IndexComparer => {
|
||||
const booleanIndexComparer = (values: boolean[], reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA = values[a];
|
||||
const vB = values[b];
|
||||
@@ -100,7 +99,7 @@ const booleanIndexComparer = (values: Vector<boolean>, reverse: boolean): IndexC
|
||||
};
|
||||
};
|
||||
|
||||
const numericIndexComparer = (values: Vector<number>, reverse: boolean): IndexComparer => {
|
||||
const numericIndexComparer = (values: number[], reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA = values[a];
|
||||
const vB = values[b];
|
||||
@@ -108,7 +107,7 @@ const numericIndexComparer = (values: Vector<number>, reverse: boolean): IndexCo
|
||||
};
|
||||
};
|
||||
|
||||
const stringIndexComparer = (values: Vector<string>, reverse: boolean): IndexComparer => {
|
||||
const stringIndexComparer = (values: string[], reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA = values[a];
|
||||
const vB = values[b];
|
||||
|
||||
@@ -290,7 +290,7 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
||||
previousDeltaUp: true,
|
||||
};
|
||||
|
||||
const data = field.values.toArray(); // toArray() ensures we handle all vector types
|
||||
const data = field.values;
|
||||
calcs.count = ignoreNulls ? data.length : data.filter((val) => val != null).length;
|
||||
|
||||
const isNumberField = field.type === FieldType.number || FieldType.time;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { map } from 'rxjs/operators';
|
||||
|
||||
import { MutableDataFrame } from '../../dataframe';
|
||||
import { getFieldDisplayName } from '../../field/fieldState';
|
||||
import { DataFrame, DataTransformerInfo, Field, FieldType, SpecialValue, Vector } from '../../types';
|
||||
import { DataFrame, DataTransformerInfo, Field, FieldType, SpecialValue } from '../../types';
|
||||
import { fieldMatchers } from '../matchers';
|
||||
import { FieldMatcherID } from '../matchers/ids';
|
||||
|
||||
@@ -111,8 +111,8 @@ export const groupingToMatrixTransformer: DataTransformerInfo<GroupingToMatrixTr
|
||||
),
|
||||
};
|
||||
|
||||
function uniqueValues(values: Vector): any[] {
|
||||
const unique = new Set();
|
||||
function uniqueValues<T>(values: T[]): T[] {
|
||||
const unique = new Set<T>();
|
||||
|
||||
for (let index = 0; index < values.length; index++) {
|
||||
unique.add(values[index]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import intersect from 'fast_array_intersect';
|
||||
|
||||
import { getTimeField, sortDataFrame } from '../../dataframe';
|
||||
import { DataFrame, Field, FieldMatcher, FieldType, Vector } from '../../types';
|
||||
import { DataFrame, Field, FieldMatcher, FieldType } from '../../types';
|
||||
import { fieldMatchers } from '../matchers';
|
||||
import { FieldMatcherID } from '../matchers/ids';
|
||||
|
||||
@@ -351,7 +351,7 @@ export function join(tables: AlignedData[], nullModes?: number[][], mode: JoinMo
|
||||
|
||||
// Test a few samples to see if the values are ascending
|
||||
// Only exported for tests
|
||||
export function isLikelyAscendingVector(data: Vector | [], samples = 50) {
|
||||
export function isLikelyAscendingVector(data: any[], samples = 50) {
|
||||
const len = data.length;
|
||||
|
||||
// empty or single value
|
||||
|
||||
@@ -23,8 +23,8 @@ export function getFlotPairs({ xField, yField, nullValueMode }: FlotPairsOptions
|
||||
const pairs: any[][] = [];
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const x = vX.get(i);
|
||||
let y = vY.get(i);
|
||||
const x = vX[i];
|
||||
let y = vY[i];
|
||||
|
||||
if (y === null) {
|
||||
if (ignoreNulls) {
|
||||
|
||||
@@ -135,7 +135,7 @@ export class Sparkline extends PureComponent<SparklineProps, State> {
|
||||
return [sparkline.timeRange.from.valueOf(), sparkline.timeRange.to.valueOf()];
|
||||
}
|
||||
const vals = sparkline.x.values;
|
||||
return [vals.get(0), vals.get(vals.length - 1)];
|
||||
return [vals[0], vals[vals.length - 1]];
|
||||
}
|
||||
return [0, sparkline.y.values.length - 1];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user