@grafana/data#DataFrameDTO TypeScript Examples

The following examples show how to use @grafana/data#DataFrameDTO. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputDatasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
function getLength(data?: DataFrameDTO | DataFrame) {
  if (!data || !data.fields || !data.fields.length) {
    return 0;
  }
  if (data.hasOwnProperty('length')) {
    return (data as DataFrame).length;
  }
  return data.fields[0].values.length;
}
Example #2
Source File: InputDatasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function describeDataFrame(data: Array<DataFrameDTO | DataFrame>): string {
  if (!data || !data.length) {
    return '';
  }
  if (data.length > 1) {
    const count = data.reduce((acc, series) => {
      return acc + getLength(series);
    }, 0);
    return `${data.length} Series, ${count} Rows`;
  }
  const series = data[0];
  if (!series.fields) {
    return 'Missing Fields';
  }
  const length = getLength(series);
  return `${series.fields.length} Fields, ${length} Rows`;
}
Example #3
Source File: utils.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function dataFrameToCSV(dto?: DataFrameDTO[]) {
  if (!dto || !dto.length) {
    return '';
  }
  return toCSV(dto.map(v => toDataFrame(v)));
}