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'; ...@@ -2,11 +2,17 @@ import _ from 'lodash';
import { colors, getColorFromHexRgbOrName } from '@grafana/ui'; import { colors, getColorFromHexRgbOrName } from '@grafana/ui';
import TimeSeries from 'app/core/time_series2'; import TimeSeries from 'app/core/time_series2';
import config from 'app/core/config'; import config from 'app/core/config';
import { LegacyResponseData, TimeRange } from '@grafana/ui';
type Options = {
dataList: LegacyResponseData[];
range?: TimeRange;
};
export class DataProcessor { export class DataProcessor {
constructor(private panel) {} constructor(private panel) {}
getSeriesList(options) { getSeriesList(options: Options): TimeSeries[] {
if (!options.dataList || options.dataList.length === 0) { if (!options.dataList || options.dataList.length === 0) {
return []; return [];
} }
...@@ -49,6 +55,8 @@ export class DataProcessor { ...@@ -49,6 +55,8 @@ export class DataProcessor {
return this.customHandler(firstItem); return this.customHandler(firstItem);
} }
} }
return [];
} }
getAutoDetectXAxisMode(firstItem) { getAutoDetectXAxisMode(firstItem) {
...@@ -102,7 +110,7 @@ export class DataProcessor { ...@@ -102,7 +110,7 @@ export class DataProcessor {
} }
} }
timeSeriesHandler(seriesData, index, options) { timeSeriesHandler(seriesData: LegacyResponseData, index: number, options: Options) {
const datapoints = seriesData.datapoints || []; const datapoints = seriesData.datapoints || [];
const alias = seriesData.target; const alias = seriesData.target;
...@@ -120,7 +128,8 @@ export class DataProcessor { ...@@ -120,7 +128,8 @@ export class DataProcessor {
if (datapoints && datapoints.length > 0) { if (datapoints && datapoints.length > 0) {
const last = datapoints[datapoints.length - 1][1]; const last = datapoints[datapoints.length - 1][1];
const from = options.range.from; const from = options.range.from;
if (last - from < -10000) {
if (last - from.valueOf() < -10000) {
series.isOutsideRange = true; series.isOutsideRange = true;
} }
} }
......
...@@ -10,15 +10,16 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk'; ...@@ -10,15 +10,16 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk';
import { DataProcessor } from './data_processor'; import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor'; import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config'; 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 { class GraphCtrl extends MetricsPanelCtrl {
static template = template; static template = template;
renderError: boolean; renderError: boolean;
hiddenSeries: any = {}; hiddenSeries: any = {};
seriesList: any = []; seriesList: TimeSeries[] = [];
dataList: any = []; dataList: LegacyResponseData[] = [];
annotations: any = []; annotations: any = [];
alertState: any; alertState: any;
...@@ -186,7 +187,7 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -186,7 +187,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render([]); this.render([]);
} }
onDataReceived(dataList) { onDataReceived(dataList: LegacyResponseData[]) {
this.dataList = dataList; this.dataList = dataList;
this.seriesList = this.processor.getSeriesList({ this.seriesList = this.processor.getSeriesList({
dataList: dataList, 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