Commit 23d461af by Ryan McKinley Committed by Torkel Ödegaard

Graph: Add some typescript types for data (#16484)

* add some types on graph

* set some types in graph

* Fixed typings
parent 4f46e739
......@@ -2,11 +2,17 @@ import _ from 'lodash';
import { colors, getColorFromHexRgbOrName } from '@grafana/ui';
import TimeSeries from 'app/core/time_series2';
import config from 'app/core/config';
import { LegacyResponseData, TimeRange } from '@grafana/ui';
type Options = {
dataList: LegacyResponseData[];
range?: TimeRange;
};
export class DataProcessor {
constructor(private panel) {}
getSeriesList(options) {
getSeriesList(options: Options): TimeSeries[] {
if (!options.dataList || options.dataList.length === 0) {
return [];
}
......@@ -49,6 +55,8 @@ export class DataProcessor {
return this.customHandler(firstItem);
}
}
return [];
}
getAutoDetectXAxisMode(firstItem) {
......@@ -102,7 +110,7 @@ export class DataProcessor {
}
}
timeSeriesHandler(seriesData, index, options) {
timeSeriesHandler(seriesData: LegacyResponseData, index: number, options: Options) {
const datapoints = seriesData.datapoints || [];
const alias = seriesData.target;
......@@ -120,7 +128,8 @@ export class DataProcessor {
if (datapoints && datapoints.length > 0) {
const last = datapoints[datapoints.length - 1][1];
const from = options.range.from;
if (last - from < -10000) {
if (last - from.valueOf() < -10000) {
series.isOutsideRange = true;
}
}
......
......@@ -10,15 +10,16 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk';
import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config';
import { getColorFromHexRgbOrName } from '@grafana/ui';
import TimeSeries from 'app/core/time_series2';
import { getColorFromHexRgbOrName, LegacyResponseData } from '@grafana/ui';
class GraphCtrl extends MetricsPanelCtrl {
static template = template;
renderError: boolean;
hiddenSeries: any = {};
seriesList: any = [];
dataList: any = [];
seriesList: TimeSeries[] = [];
dataList: LegacyResponseData[] = [];
annotations: any = [];
alertState: any;
......@@ -186,7 +187,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render([]);
}
onDataReceived(dataList) {
onDataReceived(dataList: LegacyResponseData[]) {
this.dataList = dataList;
this.seriesList = this.processor.getSeriesList({
dataList: dataList,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment