From 0994350e8b1f429633126ee2fbfb223d79b6431b Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Thu, 12 Sep 2019 08:47:18 +0200 Subject: [PATCH] TimeSeries: Add data frame index and field name (#19005) --- public/app/core/time_series2.ts | 14 ++++++++++++++ .../app/plugins/panel/graph/data_processor.ts | 17 ++++++++++++++--- .../__snapshots__/data_processor.test.ts.snap | 12 ++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/public/app/core/time_series2.ts b/public/app/core/time_series2.ts index a0760c016c4..fdf31e99339 100644 --- a/public/app/core/time_series2.ts +++ b/public/app/core/time_series2.ts @@ -67,9 +67,21 @@ export function getDataMinMax(data: TimeSeries[]) { return { datamin, datamax }; } +/** + * @deprecated: This class should not be used in new panels + * + * Use DataFrame and helpers instead + */ export default class TimeSeries { datapoints: any; 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; alias: string; aliasEscaped: string; @@ -110,6 +122,8 @@ export default class TimeSeries { this.stats = {}; this.legend = true; this.unit = opts.unit; + this.fieldName = opts.fieldName; + this.dataFrameIndex = opts.dataFrameIndex; 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 6abaa282b43..07bc71e24f5 100644 --- a/public/app/plugins/panel/graph/data_processor.ts +++ b/public/app/plugins/panel/graph/data_processor.ts @@ -20,7 +20,8 @@ export class DataProcessor { return list; } - for (const series of dataList) { + for (let i = 0; i < dataList.length; i++) { + const series = dataList[i]; const { timeField } = getTimeField(series); if (!timeField) { continue; @@ -43,7 +44,7 @@ export class DataProcessor { 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 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 color = this.panel.aliasColors[alias] || colors[colorIndex]; @@ -68,6 +77,8 @@ export class DataProcessor { alias: alias, color: getColorFromHexRgbOrName(color, config.theme.type), unit: field.config ? field.config.unit : undefined, + fieldName: field.name, + dataFrameIndex, }); 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 99c3366fff3..5cbc58d8074 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 @@ -9,6 +9,7 @@ Array [ "fillColor": "#7EB26D", }, "color": "#7EB26D", + "dataFrameIndex": 0, "datapoints": Array [ Array [ 1, @@ -23,6 +24,7 @@ Array [ 1003, ], ], + "fieldName": "Value", "hasMsResolution": false, "id": "Value", "label": "Value", @@ -38,6 +40,7 @@ Array [ "fillColor": "#EAB839", }, "color": "#EAB839", + "dataFrameIndex": 1, "datapoints": Array [ Array [ 0.1, @@ -52,6 +55,7 @@ Array [ 1003, ], ], + "fieldName": "v1", "hasMsResolution": false, "id": "table_data v1", "label": "table_data v1", @@ -67,6 +71,7 @@ Array [ "fillColor": "#6ED0E0", }, "color": "#6ED0E0", + "dataFrameIndex": 1, "datapoints": Array [ Array [ 1.1, @@ -81,6 +86,7 @@ Array [ 1003, ], ], + "fieldName": "v2", "hasMsResolution": false, "id": "table_data v2", "label": "table_data v2", @@ -96,6 +102,7 @@ Array [ "fillColor": "#EF843C", }, "color": "#EF843C", + "dataFrameIndex": 2, "datapoints": Array [ Array [ 0.1, @@ -110,6 +117,7 @@ Array [ 1003, ], ], + "fieldName": "v1", "hasMsResolution": false, "id": "series v1", "label": "series v1", @@ -125,6 +133,7 @@ Array [ "fillColor": "#E24D42", }, "color": "#E24D42", + "dataFrameIndex": 2, "datapoints": Array [ Array [ 1.1, @@ -139,6 +148,7 @@ Array [ 1003, ], ], + "fieldName": "v2", "hasMsResolution": false, "id": "series v2", "label": "series v2", @@ -159,6 +169,7 @@ Array [ "fillColor": "#7EB26D", }, "color": "#7EB26D", + "dataFrameIndex": 0, "datapoints": Array [ Array [ 1, @@ -221,6 +232,7 @@ Array [ 1003, ], ], + "fieldName": "Value", "hasMsResolution": false, "id": "Value", "label": "Value",