Browse Source

TimeSeries: Add data frame index and field name (#19005)

Dominik Prokop 6 years ago
parent
commit
0994350e8b

+ 14 - 0
public/app/core/time_series2.ts

@@ -67,9 +67,21 @@ export function getDataMinMax(data: TimeSeries[]) {
   return { datamin, datamax };
   return { datamin, datamax };
 }
 }
 
 
+/**
+ * @deprecated: This class should not be used in new panels
+ *
+ * Use DataFrame and helpers instead
+ */
 export default class TimeSeries {
 export default class TimeSeries {
   datapoints: any;
   datapoints: any;
   id: string;
   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;
   label: string;
   label: string;
   alias: string;
   alias: string;
   aliasEscaped: string;
   aliasEscaped: string;
@@ -110,6 +122,8 @@ export default class TimeSeries {
     this.stats = {};
     this.stats = {};
     this.legend = true;
     this.legend = true;
     this.unit = opts.unit;
     this.unit = opts.unit;
+    this.fieldName = opts.fieldName;
+    this.dataFrameIndex = opts.dataFrameIndex;
     this.hasMsResolution = this.isMsResolutionNeeded();
     this.hasMsResolution = this.isMsResolutionNeeded();
   }
   }
 
 

+ 14 - 3
public/app/plugins/panel/graph/data_processor.ts

@@ -20,7 +20,8 @@ export class DataProcessor {
       return list;
       return list;
     }
     }
 
 
-    for (const series of dataList) {
+    for (let i = 0; i < dataList.length; i++) {
+      const series = dataList[i];
       const { timeField } = getTimeField(series);
       const { timeField } = getTimeField(series);
       if (!timeField) {
       if (!timeField) {
         continue;
         continue;
@@ -43,7 +44,7 @@ export class DataProcessor {
           datapoints.push([field.values.get(r), timeField.values.get(r)]);
           datapoints.push([field.values.get(r), timeField.values.get(r)]);
         }
         }
 
 
-        list.push(this.toTimeSeries(field, name, datapoints, list.length, range));
+        list.push(this.toTimeSeries(field, name, i, datapoints, list.length, range));
       }
       }
     }
     }
 
 
@@ -56,10 +57,18 @@ export class DataProcessor {
       }
       }
       return [first];
       return [first];
     }
     }
+
     return list;
     return list;
   }
   }
 
 
-  private toTimeSeries(field: Field, alias: string, datapoints: any[][], index: number, range?: TimeRange) {
+  private toTimeSeries(
+    field: Field,
+    alias: string,
+    dataFrameIndex: number,
+    datapoints: any[][],
+    index: number,
+    range?: TimeRange
+  ) {
     const colorIndex = index % colors.length;
     const colorIndex = index % colors.length;
     const color = this.panel.aliasColors[alias] || colors[colorIndex];
     const color = this.panel.aliasColors[alias] || colors[colorIndex];
 
 
@@ -68,6 +77,8 @@ export class DataProcessor {
       alias: alias,
       alias: alias,
       color: getColorFromHexRgbOrName(color, config.theme.type),
       color: getColorFromHexRgbOrName(color, config.theme.type),
       unit: field.config ? field.config.unit : undefined,
       unit: field.config ? field.config.unit : undefined,
+      fieldName: field.name,
+      dataFrameIndex,
     });
     });
 
 
     if (datapoints && datapoints.length > 0 && range) {
     if (datapoints && datapoints.length > 0 && range) {

+ 12 - 0
public/app/plugins/panel/graph/specs/__snapshots__/data_processor.test.ts.snap

@@ -9,6 +9,7 @@ Array [
       "fillColor": "#7EB26D",
       "fillColor": "#7EB26D",
     },
     },
     "color": "#7EB26D",
     "color": "#7EB26D",
+    "dataFrameIndex": 0,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         1,
         1,
@@ -23,6 +24,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "Value",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "Value",
     "id": "Value",
     "label": "Value",
     "label": "Value",
@@ -38,6 +40,7 @@ Array [
       "fillColor": "#EAB839",
       "fillColor": "#EAB839",
     },
     },
     "color": "#EAB839",
     "color": "#EAB839",
+    "dataFrameIndex": 1,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         0.1,
         0.1,
@@ -52,6 +55,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "v1",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "table_data v1",
     "id": "table_data v1",
     "label": "table_data v1",
     "label": "table_data v1",
@@ -67,6 +71,7 @@ Array [
       "fillColor": "#6ED0E0",
       "fillColor": "#6ED0E0",
     },
     },
     "color": "#6ED0E0",
     "color": "#6ED0E0",
+    "dataFrameIndex": 1,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         1.1,
         1.1,
@@ -81,6 +86,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "v2",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "table_data v2",
     "id": "table_data v2",
     "label": "table_data v2",
     "label": "table_data v2",
@@ -96,6 +102,7 @@ Array [
       "fillColor": "#EF843C",
       "fillColor": "#EF843C",
     },
     },
     "color": "#EF843C",
     "color": "#EF843C",
+    "dataFrameIndex": 2,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         0.1,
         0.1,
@@ -110,6 +117,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "v1",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "series v1",
     "id": "series v1",
     "label": "series v1",
     "label": "series v1",
@@ -125,6 +133,7 @@ Array [
       "fillColor": "#E24D42",
       "fillColor": "#E24D42",
     },
     },
     "color": "#E24D42",
     "color": "#E24D42",
+    "dataFrameIndex": 2,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         1.1,
         1.1,
@@ -139,6 +148,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "v2",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "series v2",
     "id": "series v2",
     "label": "series v2",
     "label": "series v2",
@@ -159,6 +169,7 @@ Array [
       "fillColor": "#7EB26D",
       "fillColor": "#7EB26D",
     },
     },
     "color": "#7EB26D",
     "color": "#7EB26D",
+    "dataFrameIndex": 0,
     "datapoints": Array [
     "datapoints": Array [
       Array [
       Array [
         1,
         1,
@@ -221,6 +232,7 @@ Array [
         1003,
         1003,
       ],
       ],
     ],
     ],
+    "fieldName": "Value",
     "hasMsResolution": false,
     "hasMsResolution": false,
     "id": "Value",
     "id": "Value",
     "label": "Value",
     "label": "Value",