Skip to content

Commit

Permalink
Refactor: rename SeriesData to DataFrame (grafana#17854)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu authored Jul 1, 2019
1 parent c9f4cf8 commit e7c3d0e
Show file tree
Hide file tree
Showing 49 changed files with 231 additions and 231 deletions.
4 changes: 2 additions & 2 deletions packages/grafana-ui/src/components/Table/Table.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions packages/grafana-ui/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -44,7 +44,7 @@ export interface Props extends Themeable {
interface State {
sortBy?: number;
sortDirection?: SortDirectionType;
data: SeriesData;
data: DataFrame;
}

interface ColumnRenderInfo {
Expand Down Expand Up @@ -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') });
}
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
}}
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/grafana-ui/src/components/Table/TableInputCSV.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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 {
config?: CSVConfig;
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[];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/grafana-ui/src/components/Table/examples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SeriesData } from '../../types/data';
import { DataFrame } from '../../types/data';
import { ColumnStyle } from './TableCellBuilder';
import { getColorDefinitionByName } from '../../utils/namedColorsPalette';

Expand All @@ -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[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/grafana-ui/src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][];
Expand Down
10 changes: 5 additions & 5 deletions packages/grafana-ui/src/types/datasource.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/grafana-ui/src/types/panel.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +14,7 @@ export interface PanelPluginMeta extends PluginMeta {

export interface PanelData {
state: LoadingState;
series: SeriesData[];
series: DataFrame[];
request?: DataQueryRequest;
error?: DataQueryError;

Expand Down
16 changes: 8 additions & 8 deletions packages/grafana-ui/src/utils/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export class CSVReader {
}
};

readCSV(text: string): SeriesData[] {
readCSV(text: string): DataFrame[] {
this.data = [this.series];

const papacfg = {
Expand Down Expand Up @@ -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 '';
}
Expand Down
6 changes: 3 additions & 3 deletions packages/grafana-ui/src/utils/fieldDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
FieldType,
NullValueMode,
GrafanaTheme,
SeriesData,
DataFrame,
InterpolateFunction,
Field,
ScopedVars,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +72,7 @@ export interface FieldDisplay {
}

export interface GetFieldDisplayValuesOptions {
data?: SeriesData[];
data?: DataFrame[];
fieldOptions: FieldDisplayOptions;
replaceVariables: InterpolateFunction;
sparkline?: boolean; // Calculate the sparkline
Expand Down
16 changes: 8 additions & 8 deletions packages/grafana-ui/src/utils/fieldReducer.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -378,7 +378,7 @@ function calculateChangeCount(
}

function calculateDistinctCount(
data: SeriesData,
data: DataFrame,
fieldIndex: number,
ignoreNulls: boolean,
nullAsZero: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/grafana-ui/src/utils/flotPairs.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/grafana-ui/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './processSeriesData';
export * from './processDataFrame';
export * from './valueFormats/valueFormats';
export * from './colors';
export * from './namedColorsPalette';
Expand Down
4 changes: 2 additions & 2 deletions packages/grafana-ui/src/utils/logs.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 }],
Expand Down
Loading

0 comments on commit e7c3d0e

Please sign in to comment.