Просмотр исходного кода

TimeSeries: Replace fieldName with fieldIndex (#19030)

Dominik Prokop 6 лет назад
Родитель
Сommit
0607189ed5

+ 3 - 6
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();
   }
 

+ 5 - 4
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) {

+ 6 - 6
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",