-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
dataFrame.ts
304 lines (254 loc) · 8.11 KB
/
dataFrame.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import { HideSeriesConfig } from '@grafana/schema';
import { ScopedVars } from './ScopedVars';
import { QueryResultBase, Labels, NullValueMode } from './data';
import { DataLink, LinkModel } from './dataLink';
import { DecimalCount, DisplayProcessor, DisplayValue, DisplayValueAlignmentFactors } from './displayValue';
import { FieldColor } from './fieldColor';
import { ThresholdsConfig } from './thresholds';
import { ValueMapping } from './valueMapping';
/** @public */
export enum FieldType {
time = 'time', // or date
number = 'number',
string = 'string',
boolean = 'boolean',
// Used to detect that the value is some kind of trace data to help with the visualisation and processing.
trace = 'trace',
geo = 'geo',
enum = 'enum',
other = 'other', // Object, Array, etc
frame = 'frame', // DataFrame
// @alpha Nested DataFrames. This is for example used with tables where expanding a row will show a nested table.
// The value should be DataFrame[] even if it is a single frame.
nestedFrames = 'nestedFrames',
}
/**
* @public
* Every property is optional
*
* Plugins may extend this with additional properties. Something like series overrides
*/
export interface FieldConfig<TOptions = any> {
/**
* The display value for this field. This supports template variables blank is auto.
* If you are a datasource plugin, do not set this. Use `field.value` and if that
* is not enough, use `field.config.displayNameFromDS`.
*/
displayName?: string;
/**
* This can be used by data sources that need to customize how values are named.
* When this property is configured, this value is used rather than the default naming strategy.
*/
displayNameFromDS?: string;
/**
* Human readable field metadata
*/
description?: string;
/**
* An explict path to the field in the datasource. When the frame meta includes a path,
* This will default to `${frame.meta.path}/${field.name}
*
* When defined, this value can be used as an identifier within the datasource scope, and
* may be used to update the results
*/
path?: string;
/**
* True if data source can write a value to the path. Auth/authz are supported separately
*/
writeable?: boolean;
/**
* True if data source field supports ad-hoc filters
*/
filterable?: boolean;
// Numeric Options
unit?: string;
decimals?: DecimalCount; // Significant digits (for display)
min?: number | null;
max?: number | null;
// Interval indicates the expected regular step between values in the series.
// When an interval exists, consumers can identify "missing" values when the expected value is not present.
// The grafana timeseries visualization will render disconnected values when missing values are found it the time field.
// The interval uses the same units as the values. For time.Time, this is defined in milliseconds.
interval?: number | null;
// Convert input values into a display string
mappings?: ValueMapping[];
// Map numeric values to states
thresholds?: ThresholdsConfig;
// Map values to a display color
color?: FieldColor;
// Used when reducing field values
nullValueMode?: NullValueMode;
// The behavior when clicking on a result
links?: DataLink[];
// Alternative to empty string
noValue?: string;
// The field type may map to specific config
type?: FieldTypeConfig;
// Panel Specific Values
custom?: TOptions;
// Calculate min max per field
fieldMinMax?: boolean;
}
export interface FieldTypeConfig {
enum?: EnumFieldConfig;
}
export interface EnumFieldConfig {
text?: string[];
color?: string[];
icon?: string[];
description?: string[];
}
/** @public */
export interface ValueLinkConfig {
/**
* Result of field reduction
*/
calculatedValue?: DisplayValue;
/**
* Index of the value row within Field. Should be provided only when value is not a result of a reduction
*/
valueRowIndex?: number;
}
export interface Field<T = any> {
/**
* Name of the field (column)
*/
name: string;
/**
* Field value type (string, number, etc)
*/
type: FieldType;
/**
* Meta info about how field and how to display it
*/
config: FieldConfig;
/**
* The raw field values
*/
values: T[];
/**
* When type === FieldType.Time, this can optionally store
* the nanosecond-precison fractions as integers between
* 0 and 999999.
*/
nanos?: number[];
labels?: Labels;
/**
* Cached values with appropriate display and id values
*/
state?: FieldState | null;
/**
* Convert a value for display
*/
display?: DisplayProcessor;
/**
* Get value data links with variables interpolated
*/
getLinks?: (config: ValueLinkConfig) => Array<LinkModel<Field>>;
}
/** @alpha */
export interface FieldState {
/**
* An appropriate name for the field (does not include frame info)
*/
displayName?: string | null;
/**
* Cache of reduced values
*/
calcs?: FieldCalcs;
/**
* The numeric range for values in this field. This value will respect the min/max
* set in field config, or when set to `auto` this will have the min/max for all data
* in the response
*/
range?: NumericRange;
/**
* Appropriate values for templating
*/
scopedVars?: ScopedVars;
/**
* Series index is index for this field in a larger data set that can span multiple DataFrames
* Useful for assigning color to series by looking up a color in a palette using this index
*/
seriesIndex?: number;
/**
* Location of this field within the context frames results
*
* @internal -- we will try to make this unnecessary
*/
origin?: DataFrameFieldIndex;
/**
* Boolean value is true if field is in a larger data set with multiple frames.
* This is only related to the cached displayName property above.
*/
multipleFrames?: boolean;
/**
* Boolean value is true if a null filling threshold has been applied
* against the frame of the field. This is used to avoid cases in which
* this would applied more than one time.
*/
nullThresholdApplied?: boolean;
/**
* Can be used by visualizations to cache max display value lengths to aid alignment.
* It's up to each visualization to calculate and set this.
*/
alignmentFactors?: DisplayValueAlignmentFactors;
/**
* This is the current ad-hoc state of whether this series is hidden in viz, tooltip, and legend.
*
* Currently this will match field.config.custom.hideFrom because fieldOverrides applies the special __system
* override to the actual config during toggle via legend. This should go away once we have a unified system
* for layering ad hoc field overrides and options but still being able to get the stateless fieldConfig and panel options
*/
hideFrom?: HideSeriesConfig;
}
/** @public */
export interface NumericRange {
min?: number | null;
max?: number | null;
delta: number;
}
export interface DataFrame extends QueryResultBase {
name?: string;
fields: Field[]; // All fields of equal length
// The number of rows
length: number;
}
// Data frame that include aggregate value, for use by timeSeriesTableTransformer / chart cell type
export interface DataFrameWithValue extends DataFrame {
value: number | null;
}
/**
* @public
* Like a field, but properties are optional and values may be a simple array
*/
export interface FieldDTO<T = any> {
name: string; // The column name
type?: FieldType;
config?: FieldConfig;
values?: T[];
labels?: Labels;
}
/**
* @public
* Like a DataFrame, but fields may be a FieldDTO
*/
export interface DataFrameDTO extends QueryResultBase {
name?: string;
fields: Array<FieldDTO | Field>;
}
export interface FieldCalcs extends Record<string, any> {}
/** @deprecated check data plane docs: https://grafana.com/developers/dataplane/heatmap **/
export const TIME_SERIES_VALUE_FIELD_NAME = 'Value';
export const TIME_SERIES_TIME_FIELD_NAME = 'Time';
export const TIME_SERIES_METRIC_FIELD_NAME = 'Metric';
/**
* Describes where a specific data frame field is located within a
* dataset of type DataFrame[]
*
* @internal -- we will try to make this unnecessary
*/
export interface DataFrameFieldIndex {
frameIndex: number;
fieldIndex: number;
}