mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
show all columns in singlestats
This commit is contained in:
parent
30f0c35006
commit
c4a503dbc5
@ -4,6 +4,7 @@ import Papa, { ParseError, ParseMeta } from 'papaparse';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { TableData, Column, TimeSeries } from '../types';
|
import { TableData, Column, TimeSeries } from '../types';
|
||||||
|
import { isString } from 'util';
|
||||||
|
|
||||||
// Subset of all parse options
|
// Subset of all parse options
|
||||||
export interface TableParseOptions {
|
export interface TableParseOptions {
|
||||||
@ -146,6 +147,57 @@ function convertTimeSeriesToTableData(timeSeries: TimeSeries): TableData {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns a table Returns a copy of the table with the best guess for each column type
|
||||||
|
*/
|
||||||
|
export const guessColumnTypes = (table: TableData): TableData => {
|
||||||
|
let changed = false;
|
||||||
|
const columns = table.columns.map((column, index) => {
|
||||||
|
if (!column.type) {
|
||||||
|
// 1. Use the column name to guess
|
||||||
|
if (column.text) {
|
||||||
|
const name = column.text.toLowerCase();
|
||||||
|
if (name === 'date' || name === 'time') {
|
||||||
|
changed = true;
|
||||||
|
return {
|
||||||
|
...column,
|
||||||
|
type: 'time',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Check the first non-null value
|
||||||
|
for (let i = 0; i < table.rows.length; i++) {
|
||||||
|
const v = table.rows[i][index];
|
||||||
|
if (v !== null) {
|
||||||
|
let type;
|
||||||
|
if (isNumber(v)) {
|
||||||
|
type = 'number';
|
||||||
|
} else if (isString(v)) {
|
||||||
|
type = 'string';
|
||||||
|
}
|
||||||
|
if (type) {
|
||||||
|
changed = true;
|
||||||
|
return {
|
||||||
|
...column,
|
||||||
|
type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return column;
|
||||||
|
});
|
||||||
|
if (changed) {
|
||||||
|
return {
|
||||||
|
...table,
|
||||||
|
columns,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
};
|
||||||
|
|
||||||
export const isTableData = (data: any): data is TableData => data && data.hasOwnProperty('columns');
|
export const isTableData = (data: any): data is TableData => data && data.hasOwnProperty('columns');
|
||||||
|
|
||||||
export const toTableData = (results?: any[]): TableData[] => {
|
export const toTableData = (results?: any[]): TableData[] => {
|
||||||
|
@ -4,7 +4,7 @@ import React, { PureComponent, CSSProperties } from 'react';
|
|||||||
// Types
|
// Types
|
||||||
import { SingleStatOptions, SingleStatBaseOptions } from './types';
|
import { SingleStatOptions, SingleStatBaseOptions } from './types';
|
||||||
|
|
||||||
import { DisplayValue, PanelProps, processTimeSeries, NullValueMode } from '@grafana/ui';
|
import { DisplayValue, PanelProps, processTimeSeries, NullValueMode, guessColumnTypes } from '@grafana/ui';
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
import { getDisplayProcessor } from '@grafana/ui';
|
import { getDisplayProcessor } from '@grafana/ui';
|
||||||
import { ProcessedValuesRepeater } from './ProcessedValuesRepeater';
|
import { ProcessedValuesRepeater } from './ProcessedValuesRepeater';
|
||||||
@ -24,13 +24,31 @@ export const getSingleStatValues = (props: PanelProps<SingleStatBaseOptions>): D
|
|||||||
theme: config.theme,
|
theme: config.theme,
|
||||||
});
|
});
|
||||||
|
|
||||||
return processTimeSeries({
|
const values: DisplayValue[] = [];
|
||||||
data,
|
data.forEach(t => {
|
||||||
|
const table = guessColumnTypes(t);
|
||||||
|
for (let i = 0; i < table.columns.length; i++) {
|
||||||
|
const column = table.columns[i];
|
||||||
|
|
||||||
|
// Show all columns that are not 'time'
|
||||||
|
if (column.type === 'number') {
|
||||||
|
const series = processTimeSeries({
|
||||||
|
data: [table],
|
||||||
|
xColumn: i,
|
||||||
|
yColumn: i,
|
||||||
nullValueMode: NullValueMode.Null,
|
nullValueMode: NullValueMode.Null,
|
||||||
}).map((series, index) => {
|
})[0];
|
||||||
|
|
||||||
const value = stat !== 'name' ? series.stats[stat] : series.label;
|
const value = stat !== 'name' ? series.stats[stat] : series.label;
|
||||||
return processor(value);
|
values.push(processor(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (values.length === 0) {
|
||||||
|
throw { message: 'Could not find numeric data' };
|
||||||
|
}
|
||||||
|
return values;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class SingleStatPanel extends PureComponent<PanelProps<SingleStatOptions>> {
|
export class SingleStatPanel extends PureComponent<PanelProps<SingleStatOptions>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user