mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeSeries: Add data frame index and field name (#19005)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user