Skip to content

Commit

Permalink
same path for all series
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed May 9, 2019
1 parent 2330ff5 commit 1f18bc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
56 changes: 21 additions & 35 deletions public/app/plugins/panel/graph/data_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import _ from 'lodash';
import { colors, getColorFromHexRgbOrName, FieldCache, FieldType, SeriesData, Field } from '@grafana/ui';
import TimeSeries from 'app/core/time_series2';
import config from 'app/core/config';
import { LegacyResponseData, TimeRange } from '@grafana/ui';
import { getProcessedSeriesData } from 'app/features/dashboard/state/PanelQueryState';
import { TimeRange } from '@grafana/ui';

type Options = {
dataList: LegacyResponseData[];
dataList: SeriesData[];
range?: TimeRange;
};

Expand All @@ -29,17 +28,15 @@ export class DataProcessor {
}
}

const series = getProcessedSeriesData(options.dataList);

switch (this.panel.xaxis.mode) {
case 'series':
case 'time': {
return this.getTimeSeries(series, options);
return this.getTimeSeries(options.dataList, options);
}
case 'histogram': {
let histogramDataList: SeriesData[];
if (this.panel.stack) {
histogramDataList = series;
histogramDataList = options.dataList;
} else {
histogramDataList = [
{
Expand Down Expand Up @@ -114,38 +111,27 @@ export class DataProcessor {
getTimeSeries(seriesData: SeriesData[], options: Options) {
const list: TimeSeries[] = [];
for (const series of seriesData) {
const { fields, name } = series;
if (fields.length > 2) {
const cache = new FieldCache(fields);
const time = cache.getFirstFieldOfType(FieldType.time);
if (!time) {
const { fields } = series;
const cache = new FieldCache(fields);
const time = cache.getFirstFieldOfType(FieldType.time);
if (!time) {
continue;
}

const seriesName = series.name ? series.name : series.refId;
const prefix = seriesData.length > 1 ? seriesName + ' ' : '';

for (let i = 0; i < fields.length; i++) {
if (fields[i].type !== FieldType.number) {
continue;
}
const seriesName = series.name ? series.name : series.refId;
const prefix = seriesData.length > 1 ? seriesName + ' ' : '';
for (let i = 0; i < fields.length; i++) {
if (fields[i].type !== FieldType.number) {
continue;
}
list.push(
this.toTimeSeries(
fields[i],
prefix + fields[i].name, // Alias
series.rows.map(row => {
return [row[i], row[time.index]];
}),
list.length,
options.range
)
);
}
} else {
// Simple timeseris
list.push(
this.toTimeSeries(
fields[0],
name, // Alias
series.rows,
fields[i],
prefix + fields[i].name, // Alias
series.rows.map(row => {
return [row[i], row[time.index]];
}),
list.length,
options.range
)
Expand Down
7 changes: 4 additions & 3 deletions public/app/plugins/panel/graph/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import { DataProcessor } from './data_processor';
import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config';
import TimeSeries from 'app/core/time_series2';
import { getColorFromHexRgbOrName, LegacyResponseData } from '@grafana/ui';
import { getColorFromHexRgbOrName, LegacyResponseData, SeriesData } from '@grafana/ui';
import { getProcessedSeriesData } from 'app/features/dashboard/state/PanelQueryState';

class GraphCtrl extends MetricsPanelCtrl {
static template = template;

renderError: boolean;
hiddenSeries: any = {};
seriesList: TimeSeries[] = [];
dataList: LegacyResponseData[] = [];
dataList: SeriesData[] = [];
annotations: any = [];
alertState: any;

Expand Down Expand Up @@ -188,7 +189,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}

onDataReceived(dataList: LegacyResponseData[]) {
this.dataList = dataList;
this.dataList = getProcessedSeriesData(dataList);
this.seriesList = this.processor.getSeriesList({
dataList: dataList,
range: this.range,
Expand Down
5 changes: 3 additions & 2 deletions public/app/plugins/panel/graph/specs/data_processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DataProcessor } from '../data_processor';
import { getProcessedSeriesData } from 'app/features/dashboard/state/PanelQueryState';

describe('Graph DataProcessor', () => {
const panel: any = {
Expand All @@ -14,12 +15,12 @@ describe('Graph DataProcessor', () => {
panel.xaxis.values = [];

processor.getSeriesList({
dataList: [
dataList: getProcessedSeriesData([
{
type: 'docs',
datapoints: [{ hostname: 'server1', avg: 10 }],
},
],
]),
});
});

Expand Down

0 comments on commit 1f18bc5

Please sign in to comment.