DataFrame: split DataFrameHelper into MutableDataFrame and FieldCache (#18795)

* add appending utility

* add appending utility

* update comment

* rename to mutable

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* turn DataFrameHelper into FieldCache

* guess time from name

* graph the numbers

* return the timeField, not just the index

* just warn on duplicate field names

* only use a parser if the input is a string

* append init all fields to the same length

* typo

* only parse string if value is a string

* DataFrame: test fixes

* Switch to null for missing values

* Fixed tests
This commit is contained in:
Ryan McKinley
2019-09-01 05:44:22 -07:00
committed by Torkel Ödegaard
parent 13f55bc5e8
commit c777301535
30 changed files with 579 additions and 301 deletions

View File

@@ -1,4 +1,4 @@
import { DataFrameHelper, FieldType, LogRowModel } from '@grafana/data';
import { FieldType, LogRowModel, MutableDataFrame } from '@grafana/data';
import { getRowContexts } from './LogRowContextProvider';
import { Labels, LogLevel } from '@grafana/data/src';
import { DataQueryResponse } from '../../types';
@@ -6,7 +6,7 @@ import { DataQueryResponse } from '../../types';
describe('getRowContexts', () => {
describe('when called with a DataFrame and results are returned', () => {
it('then the result should be in correct format', async () => {
const firstResult = new DataFrameHelper({
const firstResult = new MutableDataFrame({
refId: 'B',
labels: {},
fields: [
@@ -14,7 +14,7 @@ describe('getRowContexts', () => {
{ name: 'line', type: FieldType.string, values: ['3', '2', '1'] },
],
});
const secondResult = new DataFrameHelper({
const secondResult = new MutableDataFrame({
refId: 'B',
labels: {},
fields: [

View File

@@ -1,5 +1,5 @@
import { getFieldProperties, getFieldDisplayValues, GetFieldDisplayValuesOptions } from './fieldDisplay';
import { ReducerID, Threshold, DataFrameHelper } from '@grafana/data';
import { ReducerID, Threshold, toDataFrame } from '@grafana/data';
import { GrafanaThemeType } from '../types/theme';
import { getTheme } from '../themes/index';
@@ -34,7 +34,7 @@ describe('FieldDisplay', () => {
// Simple test dataset
const options: GetFieldDisplayValuesOptions = {
data: [
new DataFrameHelper({
toDataFrame({
name: 'Series Name',
fields: [
{ name: 'Field 1', values: ['a', 'b', 'c'] },

View File

@@ -7,6 +7,7 @@ import {
DisplayValue,
GraphSeriesValue,
DataFrameView,
getTimeField,
} from '@grafana/data';
import toNumber from 'lodash/toNumber';
@@ -82,17 +83,6 @@ export interface GetFieldDisplayValuesOptions {
export const DEFAULT_FIELD_DISPLAY_VALUES_LIMIT = 25;
const getTimeColumnIdx = (series: DataFrame) => {
let timeColumn = -1;
for (let i = 0; i < series.fields.length; i++) {
if (series.fields[i].type === FieldType.time) {
timeColumn = i;
break;
}
}
return timeColumn;
};
export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): FieldDisplay[] => {
const { data, replaceVariables, fieldOptions } = options;
const { defaults, override } = fieldOptions;
@@ -117,7 +107,7 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
scopedVars[DataLinkBuiltInVars.seriesName] = { text: 'Series', value: series.name };
const timeColumn = getTimeColumnIdx(series);
const { timeField } = getTimeField(series);
const view = new DataFrameView(series);
for (let i = 0; i < series.fields.length && !hitLimit; i++) {
@@ -184,9 +174,9 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
let sparkline: GraphSeriesValue[][] | undefined = undefined;
// Single sparkline for every reducer
if (options.sparkline && timeColumn >= 0) {
if (options.sparkline && timeField) {
sparkline = getFlotPairs({
xField: series.fields[timeColumn],
xField: timeField,
yField: series.fields[i],
});
}

View File

@@ -1,8 +1,8 @@
import { getFlotPairs } from './flotPairs';
import { DataFrameHelper } from '@grafana/data';
import { MutableDataFrame } from '@grafana/data';
describe('getFlotPairs', () => {
const series = new DataFrameHelper({
const series = new MutableDataFrame({
fields: [
{ name: 'a', values: [1, 2, 3] },
{ name: 'b', values: [100, 200, 300] },