From 0607189ed557fb99de92abb12dd17adfd93f7a4d Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Thu, 12 Sep 2019 09:55:15 +0200 Subject: [PATCH] TimeSeries: Replace fieldName with fieldIndex (#19030) --- public/app/core/time_series2.ts | 9 +++------ public/app/plugins/panel/graph/data_processor.ts | 9 +++++---- .../specs/__snapshots__/data_processor.test.ts.snap | 12 ++++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/public/app/core/time_series2.ts b/public/app/core/time_series2.ts index fdf31e99339..6f88d13d784 100644 --- a/public/app/core/time_series2.ts +++ b/public/app/core/time_series2.ts @@ -77,11 +77,8 @@ export default class TimeSeries { id: string; // Represents index of original data frame in the quey response dataFrameIndex: number; - /** - * Name of the field the time series was created from - * Used in graph panel to retrieve value from the original data frame - */ - fieldName: string; + // Represents index of field in the data frame + fieldIndex: number; label: string; alias: string; aliasEscaped: string; @@ -122,8 +119,8 @@ export default class TimeSeries { this.stats = {}; this.legend = true; this.unit = opts.unit; - this.fieldName = opts.fieldName; this.dataFrameIndex = opts.dataFrameIndex; + this.fieldIndex = opts.fieldIndex; this.hasMsResolution = this.isMsResolutionNeeded(); } diff --git a/public/app/plugins/panel/graph/data_processor.ts b/public/app/plugins/panel/graph/data_processor.ts index 07bc71e24f5..cd68c4993e2 100644 --- a/public/app/plugins/panel/graph/data_processor.ts +++ b/public/app/plugins/panel/graph/data_processor.ts @@ -28,7 +28,8 @@ export class DataProcessor { } const seriesName = series.name ? series.name : series.refId; - for (const field of series.fields) { + for (let j = 0; j < series.fields.length; j++) { + const field = series.fields[j]; if (field.type !== FieldType.number) { continue; } @@ -43,8 +44,7 @@ export class DataProcessor { for (let r = 0; r < series.length; r++) { datapoints.push([field.values.get(r), timeField.values.get(r)]); } - - list.push(this.toTimeSeries(field, name, i, datapoints, list.length, range)); + list.push(this.toTimeSeries(field, name, i, j, datapoints, list.length, range)); } } @@ -65,6 +65,7 @@ export class DataProcessor { field: Field, alias: string, dataFrameIndex: number, + fieldIndex: number, datapoints: any[][], index: number, range?: TimeRange @@ -77,8 +78,8 @@ export class DataProcessor { alias: alias, color: getColorFromHexRgbOrName(color, config.theme.type), unit: field.config ? field.config.unit : undefined, - fieldName: field.name, dataFrameIndex, + fieldIndex, }); if (datapoints && datapoints.length > 0 && range) { diff --git a/public/app/plugins/panel/graph/specs/__snapshots__/data_processor.test.ts.snap b/public/app/plugins/panel/graph/specs/__snapshots__/data_processor.test.ts.snap index 5cbc58d8074..0c2265b9a8f 100644 --- a/public/app/plugins/panel/graph/specs/__snapshots__/data_processor.test.ts.snap +++ b/public/app/plugins/panel/graph/specs/__snapshots__/data_processor.test.ts.snap @@ -24,7 +24,7 @@ Array [ 1003, ], ], - "fieldName": "Value", + "fieldIndex": 0, "hasMsResolution": false, "id": "Value", "label": "Value", @@ -55,7 +55,7 @@ Array [ 1003, ], ], - "fieldName": "v1", + "fieldIndex": 1, "hasMsResolution": false, "id": "table_data v1", "label": "table_data v1", @@ -86,7 +86,7 @@ Array [ 1003, ], ], - "fieldName": "v2", + "fieldIndex": 2, "hasMsResolution": false, "id": "table_data v2", "label": "table_data v2", @@ -117,7 +117,7 @@ Array [ 1003, ], ], - "fieldName": "v1", + "fieldIndex": 0, "hasMsResolution": false, "id": "series v1", "label": "series v1", @@ -148,7 +148,7 @@ Array [ 1003, ], ], - "fieldName": "v2", + "fieldIndex": 1, "hasMsResolution": false, "id": "series v2", "label": "series v2", @@ -232,7 +232,7 @@ Array [ 1003, ], ], - "fieldName": "Value", + "fieldIndex": 0, "hasMsResolution": false, "id": "Value", "label": "Value",