Refactor: rename SeriesData to DataFrame (#17854)
This commit is contained in:
@@ -4,7 +4,7 @@ import { Table } from './Table';
|
||||
import { getTheme } from '../../themes';
|
||||
|
||||
import { migratedTestTable, migratedTestStyles, simpleTable } from './examples';
|
||||
import { ScopedVars, SeriesData, GrafanaThemeType } from '../../types/index';
|
||||
import { ScopedVars, DataFrame, GrafanaThemeType } from '../../types/index';
|
||||
import { withFullSizeStory } from '../../utils/storybook/withFullSizeStory';
|
||||
import { number, boolean } from '@storybook/addon-knobs';
|
||||
|
||||
@@ -29,7 +29,7 @@ export function columnIndexToLeter(column: number) {
|
||||
return String.fromCharCode(A + c2);
|
||||
}
|
||||
|
||||
export function makeDummyTable(columnCount: number, rowCount: number): SeriesData {
|
||||
export function makeDummyTable(columnCount: number, rowCount: number): DataFrame {
|
||||
return {
|
||||
fields: Array.from(new Array(columnCount), (x, i) => {
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from 'react-virtualized';
|
||||
import { Themeable } from '../../types/theme';
|
||||
|
||||
import { sortSeriesData } from '../../utils/processSeriesData';
|
||||
import { sortDataFrame } from '../../utils/processDataFrame';
|
||||
|
||||
import {
|
||||
TableCellBuilder,
|
||||
@@ -22,11 +22,11 @@ import {
|
||||
simpleCellBuilder,
|
||||
} from './TableCellBuilder';
|
||||
import { stringToJsRegex } from '@grafana/data';
|
||||
import { SeriesData } from '../../types/data';
|
||||
import { DataFrame } from '../../types/data';
|
||||
import { InterpolateFunction } from '../../types/panel';
|
||||
|
||||
export interface Props extends Themeable {
|
||||
data: SeriesData;
|
||||
data: DataFrame;
|
||||
|
||||
minColumnWidth: number;
|
||||
showHeader: boolean;
|
||||
@@ -44,7 +44,7 @@ export interface Props extends Themeable {
|
||||
interface State {
|
||||
sortBy?: number;
|
||||
sortDirection?: SortDirectionType;
|
||||
data: SeriesData;
|
||||
data: DataFrame;
|
||||
}
|
||||
|
||||
interface ColumnRenderInfo {
|
||||
@@ -115,7 +115,7 @@ export class Table extends Component<Props, State> {
|
||||
// Update the data when data or sort changes
|
||||
if (dataChanged || sortBy !== prevState.sortBy || sortDirection !== prevState.sortDirection) {
|
||||
this.scrollToTop = true;
|
||||
this.setState({ data: sortSeriesData(data, sortBy, sortDirection === 'DESC') });
|
||||
this.setState({ data: sortDataFrame(data, sortBy, sortDirection === 'DESC') });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export class Table extends Component<Props, State> {
|
||||
this.setState({ sortBy: sort, sortDirection: dir });
|
||||
};
|
||||
|
||||
/** Converts the grid coordinates to SeriesData coordinates */
|
||||
/** Converts the grid coordinates to DataFrame coordinates */
|
||||
getCellRef = (rowIndex: number, columnIndex: number): DataIndex => {
|
||||
const { showHeader, rotate } = this.props;
|
||||
const rowOffset = showHeader ? -1 : 0;
|
||||
|
||||
@@ -3,7 +3,7 @@ import React from 'react';
|
||||
import { storiesOf } from '@storybook/react';
|
||||
import TableInputCSV from './TableInputCSV';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { SeriesData } from '../../types/data';
|
||||
import { DataFrame } from '../../types/data';
|
||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
|
||||
const TableInputStories = storiesOf('UI/Table/Input', module);
|
||||
@@ -16,7 +16,7 @@ TableInputStories.add('default', () => {
|
||||
width={400}
|
||||
height={'90vh'}
|
||||
text={'a,b,c\n1,2,3'}
|
||||
onSeriesParsed={(data: SeriesData[], text: string) => {
|
||||
onSeriesParsed={(data: DataFrame[], text: string) => {
|
||||
console.log('Data', data, text);
|
||||
action('Data')(data, text);
|
||||
}}
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
|
||||
import renderer from 'react-test-renderer';
|
||||
import TableInputCSV from './TableInputCSV';
|
||||
import { SeriesData } from '../../types/data';
|
||||
import { DataFrame } from '../../types/data';
|
||||
|
||||
describe('TableInputCSV', () => {
|
||||
it('renders correctly', () => {
|
||||
@@ -12,7 +12,7 @@ describe('TableInputCSV', () => {
|
||||
width={'100%'}
|
||||
height={200}
|
||||
text={'a,b,c\n1,2,3'}
|
||||
onSeriesParsed={(data: SeriesData[], text: string) => {
|
||||
onSeriesParsed={(data: DataFrame[], text: string) => {
|
||||
// console.log('Table:', table, 'from:', text);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import debounce from 'lodash/debounce';
|
||||
import { SeriesData } from '../../types/data';
|
||||
import { DataFrame } from '../../types/data';
|
||||
import { CSVConfig, readCSV } from '../../utils/csv';
|
||||
|
||||
interface Props {
|
||||
@@ -8,12 +8,12 @@ interface Props {
|
||||
text: string;
|
||||
width: string | number;
|
||||
height: string | number;
|
||||
onSeriesParsed: (data: SeriesData[], text: string) => void;
|
||||
onSeriesParsed: (data: DataFrame[], text: string) => void;
|
||||
}
|
||||
|
||||
interface State {
|
||||
text: string;
|
||||
data: SeriesData[];
|
||||
data: DataFrame[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SeriesData } from '../../types/data';
|
||||
import { DataFrame } from '../../types/data';
|
||||
import { ColumnStyle } from './TableCellBuilder';
|
||||
import { getColorDefinitionByName } from '../../utils/namedColorsPalette';
|
||||
|
||||
@@ -22,7 +22,7 @@ export const migratedTestTable = {
|
||||
{ name: 'RangeMappingColored' },
|
||||
],
|
||||
rows: [[1388556366666, 1230, 40, undefined, '', '', 'my.host.com', 'host1', ['value1', 'value2'], 1, 2, 1, 2]],
|
||||
} as SeriesData;
|
||||
} as DataFrame;
|
||||
|
||||
export const migratedTestStyles: ColumnStyle[] = [
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ export interface Labels {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface SeriesData extends QueryResultBase {
|
||||
export interface DataFrame extends QueryResultBase {
|
||||
name?: string;
|
||||
fields: Field[];
|
||||
rows: any[][];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ComponentType, ComponentClass } from 'react';
|
||||
import { TimeRange, RawTimeRange } from './time';
|
||||
import { PluginMeta, GrafanaPlugin } from './plugin';
|
||||
import { TableData, TimeSeries, SeriesData, LoadingState } from './data';
|
||||
import { TableData, TimeSeries, DataFrame, LoadingState } from './data';
|
||||
import { PanelData } from './panel';
|
||||
import { LogRowModel } from './logs';
|
||||
|
||||
@@ -284,11 +284,11 @@ export interface ExploreStartPageProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starting in v6.2 SeriesData can represent both TimeSeries and TableData
|
||||
* Starting in v6.2 DataFrame can represent both TimeSeries and TableData
|
||||
*/
|
||||
export type LegacyResponseData = TimeSeries | TableData | any;
|
||||
|
||||
export type DataQueryResponseData = SeriesData | LegacyResponseData;
|
||||
export type DataQueryResponseData = DataFrame | LegacyResponseData;
|
||||
|
||||
export type DataStreamObserver = (event: DataStreamState) => void;
|
||||
|
||||
@@ -313,7 +313,7 @@ export interface DataStreamState {
|
||||
/**
|
||||
* Series data may not be known yet
|
||||
*/
|
||||
series?: SeriesData[];
|
||||
series?: DataFrame[];
|
||||
|
||||
/**
|
||||
* Error in stream (but may still be running)
|
||||
@@ -323,7 +323,7 @@ export interface DataStreamState {
|
||||
/**
|
||||
* Optionally return only the rows that changed in this event
|
||||
*/
|
||||
delta?: SeriesData[];
|
||||
delta?: DataFrame[];
|
||||
|
||||
/**
|
||||
* Stop listening to this stream
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ComponentClass, ComponentType } from 'react';
|
||||
import { LoadingState, SeriesData } from './data';
|
||||
import { LoadingState, DataFrame } from './data';
|
||||
import { TimeRange } from './time';
|
||||
import { ScopedVars, DataQueryRequest, DataQueryError, LegacyResponseData } from './datasource';
|
||||
import { PluginMeta, GrafanaPlugin } from './plugin';
|
||||
@@ -14,7 +14,7 @@ export interface PanelPluginMeta extends PluginMeta {
|
||||
|
||||
export interface PanelData {
|
||||
state: LoadingState;
|
||||
series: SeriesData[];
|
||||
series: DataFrame[];
|
||||
request?: DataQueryRequest;
|
||||
error?: DataQueryError;
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import defaults from 'lodash/defaults';
|
||||
import isNumber from 'lodash/isNumber';
|
||||
|
||||
// Types
|
||||
import { SeriesData, Field, FieldType } from '../types/index';
|
||||
import { guessFieldTypeFromValue } from './processSeriesData';
|
||||
import { DataFrame, Field, FieldType } from '../types/index';
|
||||
import { guessFieldTypeFromValue } from './processDataFrame';
|
||||
|
||||
export enum CSVHeaderStyle {
|
||||
full,
|
||||
@@ -28,7 +28,7 @@ export interface CSVParseCallbacks {
|
||||
* This can return a modified table to force any
|
||||
* Column configurations
|
||||
*/
|
||||
onHeader: (table: SeriesData) => void;
|
||||
onHeader: (table: DataFrame) => void;
|
||||
|
||||
// Called after each row is read and
|
||||
onRow: (row: any[]) => void;
|
||||
@@ -39,7 +39,7 @@ export interface CSVOptions {
|
||||
callback?: CSVParseCallbacks;
|
||||
}
|
||||
|
||||
export function readCSV(csv: string, options?: CSVOptions): SeriesData[] {
|
||||
export function readCSV(csv: string, options?: CSVOptions): DataFrame[] {
|
||||
return new CSVReader(options).readCSV(csv);
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ export class CSVReader {
|
||||
callback?: CSVParseCallbacks;
|
||||
|
||||
field: FieldParser[];
|
||||
series: SeriesData;
|
||||
series: DataFrame;
|
||||
state: ParseState;
|
||||
data: SeriesData[];
|
||||
data: DataFrame[];
|
||||
|
||||
constructor(options?: CSVOptions) {
|
||||
if (!options) {
|
||||
@@ -193,7 +193,7 @@ export class CSVReader {
|
||||
}
|
||||
};
|
||||
|
||||
readCSV(text: string): SeriesData[] {
|
||||
readCSV(text: string): DataFrame[] {
|
||||
this.data = [this.series];
|
||||
|
||||
const papacfg = {
|
||||
@@ -315,7 +315,7 @@ function getHeaderLine(key: string, fields: Field[], config: CSVConfig): string
|
||||
return '';
|
||||
}
|
||||
|
||||
export function toCSV(data: SeriesData[], config?: CSVConfig): string {
|
||||
export function toCSV(data: DataFrame[], config?: CSVConfig): string {
|
||||
if (!data) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
FieldType,
|
||||
NullValueMode,
|
||||
GrafanaTheme,
|
||||
SeriesData,
|
||||
DataFrame,
|
||||
InterpolateFunction,
|
||||
Field,
|
||||
ScopedVars,
|
||||
@@ -36,7 +36,7 @@ export const VAR_FIELD_NAME = '__field_name';
|
||||
export const VAR_CALC = '__calc';
|
||||
export const VAR_CELL_PREFIX = '__cell_'; // consistent with existing table templates
|
||||
|
||||
function getTitleTemplate(title: string | undefined, stats: string[], data?: SeriesData[]): string {
|
||||
function getTitleTemplate(title: string | undefined, stats: string[], data?: DataFrame[]): string {
|
||||
// If the title exists, use it as a template variable
|
||||
if (title) {
|
||||
return title;
|
||||
@@ -72,7 +72,7 @@ export interface FieldDisplay {
|
||||
}
|
||||
|
||||
export interface GetFieldDisplayValuesOptions {
|
||||
data?: SeriesData[];
|
||||
data?: DataFrame[];
|
||||
fieldOptions: FieldDisplayOptions;
|
||||
replaceVariables: InterpolateFunction;
|
||||
sparkline?: boolean; // Calculate the sparkline
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Libraries
|
||||
import isNumber from 'lodash/isNumber';
|
||||
|
||||
import { SeriesData, NullValueMode } from '../types/index';
|
||||
import { DataFrame, NullValueMode } from '../types/index';
|
||||
|
||||
export enum ReducerID {
|
||||
sum = 'sum',
|
||||
@@ -29,7 +29,7 @@ export interface FieldCalcs {
|
||||
}
|
||||
|
||||
// Internal function
|
||||
type FieldReducer = (data: SeriesData, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean) => FieldCalcs;
|
||||
type FieldReducer = (data: DataFrame, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean) => FieldCalcs;
|
||||
|
||||
export interface FieldReducerInfo {
|
||||
id: string;
|
||||
@@ -64,7 +64,7 @@ export function getFieldReducers(ids?: string[]): FieldReducerInfo[] {
|
||||
}
|
||||
|
||||
interface ReduceFieldOptions {
|
||||
series: SeriesData;
|
||||
series: DataFrame;
|
||||
fieldIndex: number;
|
||||
reducers: string[]; // The stats to calculate
|
||||
nullValueMode?: NullValueMode;
|
||||
@@ -222,7 +222,7 @@ function getById(id: string): FieldReducerInfo | undefined {
|
||||
return index[id];
|
||||
}
|
||||
|
||||
function doStandardCalcs(data: SeriesData, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
function doStandardCalcs(data: DataFrame, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
const calcs = {
|
||||
sum: 0,
|
||||
max: -Number.MAX_VALUE,
|
||||
@@ -340,16 +340,16 @@ function doStandardCalcs(data: SeriesData, fieldIndex: number, ignoreNulls: bool
|
||||
return calcs;
|
||||
}
|
||||
|
||||
function calculateFirst(data: SeriesData, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
function calculateFirst(data: DataFrame, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
return { first: data.rows[0][fieldIndex] };
|
||||
}
|
||||
|
||||
function calculateLast(data: SeriesData, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
function calculateLast(data: DataFrame, fieldIndex: number, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
return { last: data.rows[data.rows.length - 1][fieldIndex] };
|
||||
}
|
||||
|
||||
function calculateChangeCount(
|
||||
data: SeriesData,
|
||||
data: DataFrame,
|
||||
fieldIndex: number,
|
||||
ignoreNulls: boolean,
|
||||
nullAsZero: boolean
|
||||
@@ -378,7 +378,7 @@ function calculateChangeCount(
|
||||
}
|
||||
|
||||
function calculateDistinctCount(
|
||||
data: SeriesData,
|
||||
data: DataFrame,
|
||||
fieldIndex: number,
|
||||
ignoreNulls: boolean,
|
||||
nullAsZero: boolean
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Types
|
||||
import { NullValueMode, GraphSeriesValue, SeriesData } from '../types/index';
|
||||
import { NullValueMode, GraphSeriesValue, DataFrame } from '../types/index';
|
||||
|
||||
export interface FlotPairsOptions {
|
||||
series: SeriesData;
|
||||
series: DataFrame;
|
||||
xIndex: number;
|
||||
yIndex: number;
|
||||
nullValueMode?: NullValueMode;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './processSeriesData';
|
||||
export * from './processDataFrame';
|
||||
export * from './valueFormats/valueFormats';
|
||||
export * from './colors';
|
||||
export * from './namedColorsPalette';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { LogLevel } from '../types/logs';
|
||||
import { SeriesData, FieldType } from '../types/data';
|
||||
import { DataFrame, FieldType } from '../types/data';
|
||||
|
||||
/**
|
||||
* Returns the log level of a log line.
|
||||
@@ -32,7 +32,7 @@ export function getLogLevelFromKey(key: string): LogLevel {
|
||||
return LogLevel.unknown;
|
||||
}
|
||||
|
||||
export function addLogLevelToSeries(series: SeriesData, lineIndex: number): SeriesData {
|
||||
export function addLogLevelToSeries(series: DataFrame, lineIndex: number): DataFrame {
|
||||
return {
|
||||
...series, // Keeps Tags, RefID etc
|
||||
fields: [...series.fields, { name: 'LogLevel', type: FieldType.string }],
|
||||
|
||||
+17
-17
@@ -1,21 +1,21 @@
|
||||
import {
|
||||
isSeriesData,
|
||||
isDataFrame,
|
||||
toLegacyResponseData,
|
||||
isTableData,
|
||||
toSeriesData,
|
||||
toDataFrame,
|
||||
guessFieldTypes,
|
||||
guessFieldTypeFromValue,
|
||||
} from './processSeriesData';
|
||||
import { FieldType, TimeSeries, SeriesData, TableData } from '../types/data';
|
||||
} from './processDataFrame';
|
||||
import { FieldType, TimeSeries, DataFrame, TableData } from '../types/data';
|
||||
import { dateTime } from './moment_wrapper';
|
||||
|
||||
describe('toSeriesData', () => {
|
||||
describe('toDataFrame', () => {
|
||||
it('converts timeseries to series', () => {
|
||||
const input1 = {
|
||||
target: 'Field Name',
|
||||
datapoints: [[100, 1], [200, 2]],
|
||||
};
|
||||
let series = toSeriesData(input1);
|
||||
let series = toDataFrame(input1);
|
||||
expect(series.fields[0].name).toBe(input1.target);
|
||||
expect(series.rows).toBe(input1.datapoints);
|
||||
|
||||
@@ -25,16 +25,16 @@ describe('toSeriesData', () => {
|
||||
target: '',
|
||||
datapoints: [[100, 1], [200, 2]],
|
||||
};
|
||||
series = toSeriesData(input2);
|
||||
series = toDataFrame(input2);
|
||||
expect(series.fields[0].name).toEqual('Value');
|
||||
});
|
||||
|
||||
it('keeps seriesData unchanged', () => {
|
||||
it('keeps dataFrame unchanged', () => {
|
||||
const input = {
|
||||
fields: [{ text: 'A' }, { text: 'B' }, { text: 'C' }],
|
||||
rows: [[100, 'A', 1], [200, 'B', 2], [300, 'C', 3]],
|
||||
};
|
||||
const series = toSeriesData(input);
|
||||
const series = toDataFrame(input);
|
||||
expect(series).toBe(input);
|
||||
});
|
||||
|
||||
@@ -77,12 +77,12 @@ describe('SerisData backwards compatibility', () => {
|
||||
target: 'Field Name',
|
||||
datapoints: [[100, 1], [200, 2]],
|
||||
};
|
||||
const series = toSeriesData(timeseries);
|
||||
expect(isSeriesData(timeseries)).toBeFalsy();
|
||||
expect(isSeriesData(series)).toBeTruthy();
|
||||
const series = toDataFrame(timeseries);
|
||||
expect(isDataFrame(timeseries)).toBeFalsy();
|
||||
expect(isDataFrame(series)).toBeTruthy();
|
||||
|
||||
const roundtrip = toLegacyResponseData(series) as TimeSeries;
|
||||
expect(isSeriesData(roundtrip)).toBeFalsy();
|
||||
expect(isDataFrame(roundtrip)).toBeFalsy();
|
||||
expect(roundtrip.target).toBe(timeseries.target);
|
||||
});
|
||||
|
||||
@@ -91,17 +91,17 @@ describe('SerisData backwards compatibility', () => {
|
||||
columns: [{ text: 'a', unit: 'ms' }, { text: 'b', unit: 'zz' }, { text: 'c', unit: 'yy' }],
|
||||
rows: [[100, 1, 'a'], [200, 2, 'a']],
|
||||
};
|
||||
const series = toSeriesData(table);
|
||||
const series = toDataFrame(table);
|
||||
expect(isTableData(table)).toBeTruthy();
|
||||
expect(isSeriesData(series)).toBeTruthy();
|
||||
expect(isDataFrame(series)).toBeTruthy();
|
||||
|
||||
const roundtrip = toLegacyResponseData(series) as TimeSeries;
|
||||
expect(isTableData(roundtrip)).toBeTruthy();
|
||||
expect(roundtrip).toMatchObject(table);
|
||||
});
|
||||
|
||||
it('converts SeriesData to TableData to series and back again', () => {
|
||||
const series: SeriesData = {
|
||||
it('converts DataFrame to TableData to series and back again', () => {
|
||||
const series: DataFrame = {
|
||||
refId: 'Z',
|
||||
meta: {
|
||||
somethign: 8,
|
||||
+13
-13
@@ -4,10 +4,10 @@ import isString from 'lodash/isString';
|
||||
import isBoolean from 'lodash/isBoolean';
|
||||
|
||||
// Types
|
||||
import { SeriesData, Field, TimeSeries, FieldType, TableData, Column } from '../types/index';
|
||||
import { DataFrame, Field, TimeSeries, FieldType, TableData, Column } from '../types/index';
|
||||
import { isDateTime } from './moment_wrapper';
|
||||
|
||||
function convertTableToSeriesData(table: TableData): SeriesData {
|
||||
function convertTableToDataFrame(table: TableData): DataFrame {
|
||||
return {
|
||||
// rename the 'text' to 'name' field
|
||||
fields: table.columns.map(c => {
|
||||
@@ -23,7 +23,7 @@ function convertTableToSeriesData(table: TableData): SeriesData {
|
||||
};
|
||||
}
|
||||
|
||||
function convertTimeSeriesToSeriesData(timeSeries: TimeSeries): SeriesData {
|
||||
function convertTimeSeriesToDataFrame(timeSeries: TimeSeries): DataFrame {
|
||||
return {
|
||||
name: timeSeries.target,
|
||||
fields: [
|
||||
@@ -84,7 +84,7 @@ export function guessFieldTypeFromValue(v: any): FieldType {
|
||||
/**
|
||||
* Looks at the data to guess the column type. This ignores any existing setting
|
||||
*/
|
||||
export function guessFieldTypeFromSeries(series: SeriesData, index: number): FieldType | undefined {
|
||||
export function guessFieldTypeFromSeries(series: DataFrame, index: number): FieldType | undefined {
|
||||
const column = series.fields[index];
|
||||
|
||||
// 1. Use the column name to guess
|
||||
@@ -111,7 +111,7 @@ export function guessFieldTypeFromSeries(series: SeriesData, index: number): Fie
|
||||
* @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 = (series: SeriesData): SeriesData => {
|
||||
export const guessFieldTypes = (series: DataFrame): DataFrame => {
|
||||
for (let i = 0; i < series.fields.length; i++) {
|
||||
if (!series.fields[i].type) {
|
||||
// Somethign is missing a type return a modified copy
|
||||
@@ -134,26 +134,26 @@ export const guessFieldTypes = (series: SeriesData): SeriesData => {
|
||||
return series;
|
||||
};
|
||||
|
||||
export const isTableData = (data: any): data is SeriesData => data && data.hasOwnProperty('columns');
|
||||
export const isTableData = (data: any): data is DataFrame => data && data.hasOwnProperty('columns');
|
||||
|
||||
export const isSeriesData = (data: any): data is SeriesData => data && data.hasOwnProperty('fields');
|
||||
export const isDataFrame = (data: any): data is DataFrame => data && data.hasOwnProperty('fields');
|
||||
|
||||
export const toSeriesData = (data: any): SeriesData => {
|
||||
export const toDataFrame = (data: any): DataFrame => {
|
||||
if (data.hasOwnProperty('fields')) {
|
||||
return data as SeriesData;
|
||||
return data as DataFrame;
|
||||
}
|
||||
if (data.hasOwnProperty('datapoints')) {
|
||||
return convertTimeSeriesToSeriesData(data);
|
||||
return convertTimeSeriesToDataFrame(data);
|
||||
}
|
||||
if (data.hasOwnProperty('columns')) {
|
||||
return convertTableToSeriesData(data);
|
||||
return convertTableToDataFrame(data);
|
||||
}
|
||||
// TODO, try to convert JSON/Array to seriesta?
|
||||
console.warn('Can not convert', data);
|
||||
throw new Error('Unsupported data format');
|
||||
};
|
||||
|
||||
export const toLegacyResponseData = (series: SeriesData): TimeSeries | TableData => {
|
||||
export const toLegacyResponseData = (series: DataFrame): TimeSeries | TableData => {
|
||||
const { fields, rows } = series;
|
||||
|
||||
if (fields.length === 2) {
|
||||
@@ -182,7 +182,7 @@ export const toLegacyResponseData = (series: SeriesData): TimeSeries | TableData
|
||||
};
|
||||
};
|
||||
|
||||
export function sortSeriesData(data: SeriesData, sortIndex?: number, reverse = false): SeriesData {
|
||||
export function sortDataFrame(data: DataFrame, sortIndex?: number, reverse = false): DataFrame {
|
||||
if (isNumber(sortIndex)) {
|
||||
const copy = {
|
||||
...data,
|
||||
Reference in New Issue
Block a user