@grafana/scenes 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/esm/components/EmbeddedScene.js.map +1 -1
  3. package/dist/esm/components/NestedScene.js +1 -28
  4. package/dist/esm/components/NestedScene.js.map +1 -1
  5. package/dist/esm/components/SceneByFrameRepeater.js.map +1 -1
  6. package/dist/esm/components/SceneCanvasText.js +0 -12
  7. package/dist/esm/components/SceneCanvasText.js.map +1 -1
  8. package/dist/esm/components/SceneReactObject.js.map +1 -1
  9. package/dist/esm/components/SceneRefreshPicker.js.map +1 -1
  10. package/dist/esm/components/SceneTimePicker.js.map +1 -1
  11. package/dist/esm/components/SceneToolbarButton.js.map +1 -1
  12. package/dist/esm/components/VizPanel/VizPanel.js +95 -9
  13. package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
  14. package/dist/esm/components/VizPanel/VizPanelMenu.js.map +1 -1
  15. package/dist/esm/components/VizPanel/VizPanelRenderer.js +20 -13
  16. package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
  17. package/dist/esm/components/VizPanel/colorSeriesConfigFactory.js +72 -0
  18. package/dist/esm/components/VizPanel/colorSeriesConfigFactory.js.map +1 -0
  19. package/dist/esm/components/VizPanel/seriesVisibilityConfigFactory.js +164 -0
  20. package/dist/esm/components/VizPanel/seriesVisibilityConfigFactory.js.map +1 -0
  21. package/dist/esm/components/layout/SceneFlexLayout.js.map +1 -1
  22. package/dist/esm/components/layout/grid/SceneGridLayout.js.map +1 -1
  23. package/dist/esm/core/SceneComponentWrapper.js +1 -10
  24. package/dist/esm/core/SceneComponentWrapper.js.map +1 -1
  25. package/dist/esm/core/SceneDataNode.js +29 -1
  26. package/dist/esm/core/SceneDataNode.js.map +1 -1
  27. package/dist/esm/core/SceneObjectBase.js +44 -20
  28. package/dist/esm/core/SceneObjectBase.js.map +1 -1
  29. package/dist/esm/core/events.js.map +1 -1
  30. package/dist/esm/core/types.js.map +1 -1
  31. package/dist/esm/core/utils.js +1 -15
  32. package/dist/esm/core/utils.js.map +1 -1
  33. package/dist/esm/querying/SceneDataTransformer.js.map +1 -1
  34. package/dist/esm/querying/SceneQueryRunner.js +14 -14
  35. package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
  36. package/dist/esm/services/UrlSyncManager.js +9 -10
  37. package/dist/esm/services/UrlSyncManager.js.map +1 -1
  38. package/dist/esm/variables/components/VariableValueSelectors.js.map +1 -1
  39. package/dist/esm/variables/interpolation/defaults.js +1 -8
  40. package/dist/esm/variables/interpolation/defaults.js.map +1 -1
  41. package/dist/esm/variables/interpolation/sceneInterpolator.js +12 -8
  42. package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
  43. package/dist/esm/variables/macros/DataValueMacro.js +60 -0
  44. package/dist/esm/variables/macros/DataValueMacro.js.map +1 -0
  45. package/dist/esm/variables/macros/index.js +3 -1
  46. package/dist/esm/variables/macros/index.js.map +1 -1
  47. package/dist/esm/variables/macros/types.js.map +1 -1
  48. package/dist/esm/variables/sets/SceneVariableSet.js +28 -29
  49. package/dist/esm/variables/sets/SceneVariableSet.js.map +1 -1
  50. package/dist/esm/variables/types.js.map +1 -1
  51. package/dist/esm/variables/variants/query/QueryVariable.js +14 -15
  52. package/dist/esm/variables/variants/query/QueryVariable.js.map +1 -1
  53. package/dist/index.d.ts +112 -95
  54. package/dist/index.js +723 -363
  55. package/dist/index.js.map +1 -1
  56. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var data = require('@grafana/data');
6
+ var schema = require('@grafana/schema');
6
7
  var React = require('react');
7
8
  var rxjs = require('rxjs');
8
9
  var uuid = require('uuid');
9
10
  var ui = require('@grafana/ui');
10
- var schema = require('@grafana/schema');
11
11
  var lodash = require('lodash');
12
12
  var runtime = require('@grafana/runtime');
13
13
  var e2eSelectors = require('@grafana/e2e-selectors');
@@ -32,33 +32,33 @@ class SceneObjectStateChangedEvent extends data.BusEventWithPayload {
32
32
  }
33
33
  SceneObjectStateChangedEvent.type = "scene-object-state-change";
34
34
 
35
- var __defProp$i = Object.defineProperty;
36
- var __defProps$7 = Object.defineProperties;
37
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
38
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
39
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
40
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
41
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
42
- var __spreadValues$i = (a, b) => {
35
+ var __defProp$k = Object.defineProperty;
36
+ var __defProps$9 = Object.defineProperties;
37
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
38
+ var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
39
+ var __hasOwnProp$l = Object.prototype.hasOwnProperty;
40
+ var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
41
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
42
+ var __spreadValues$k = (a, b) => {
43
43
  for (var prop in b || (b = {}))
44
- if (__hasOwnProp$j.call(b, prop))
45
- __defNormalProp$i(a, prop, b[prop]);
46
- if (__getOwnPropSymbols$j)
47
- for (var prop of __getOwnPropSymbols$j(b)) {
48
- if (__propIsEnum$j.call(b, prop))
49
- __defNormalProp$i(a, prop, b[prop]);
44
+ if (__hasOwnProp$l.call(b, prop))
45
+ __defNormalProp$k(a, prop, b[prop]);
46
+ if (__getOwnPropSymbols$l)
47
+ for (var prop of __getOwnPropSymbols$l(b)) {
48
+ if (__propIsEnum$l.call(b, prop))
49
+ __defNormalProp$k(a, prop, b[prop]);
50
50
  }
51
51
  return a;
52
52
  };
53
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
53
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
54
54
  var __objRest$1 = (source, exclude) => {
55
55
  var target = {};
56
56
  for (var prop in source)
57
- if (__hasOwnProp$j.call(source, prop) && exclude.indexOf(prop) < 0)
57
+ if (__hasOwnProp$l.call(source, prop) && exclude.indexOf(prop) < 0)
58
58
  target[prop] = source[prop];
59
- if (source != null && __getOwnPropSymbols$j)
60
- for (var prop of __getOwnPropSymbols$j(source)) {
61
- if (exclude.indexOf(prop) < 0 && __propIsEnum$j.call(source, prop))
59
+ if (source != null && __getOwnPropSymbols$l)
60
+ for (var prop of __getOwnPropSymbols$l(source)) {
61
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$l.call(source, prop))
62
62
  target[prop] = source[prop];
63
63
  }
64
64
  return target;
@@ -67,17 +67,8 @@ function SceneComponentWrapperWithoutMemo(_a) {
67
67
  var _b = _a, { model } = _b, otherProps = __objRest$1(_b, ["model"]);
68
68
  var _a2;
69
69
  const Component = (_a2 = model.constructor["Component"]) != null ? _a2 : EmptyRenderer;
70
- React.useEffect(() => {
71
- if (!model.isActive) {
72
- model.activate();
73
- }
74
- return () => {
75
- if (model.isActive) {
76
- model.deactivate();
77
- }
78
- };
79
- }, [model]);
80
- return /* @__PURE__ */ React__default["default"].createElement(Component, __spreadProps$7(__spreadValues$i({}, otherProps), {
70
+ React.useEffect(() => model.activate(), [model]);
71
+ return /* @__PURE__ */ React__default["default"].createElement(Component, __spreadProps$9(__spreadValues$k({}, otherProps), {
81
72
  model
82
73
  }));
83
74
  }
@@ -86,38 +77,24 @@ function EmptyRenderer(_) {
86
77
  return null;
87
78
  }
88
79
 
89
- var __defProp$h = Object.defineProperty;
90
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
91
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
92
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
93
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
94
- var __spreadValues$h = (a, b) => {
80
+ var __defProp$j = Object.defineProperty;
81
+ var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
82
+ var __hasOwnProp$k = Object.prototype.hasOwnProperty;
83
+ var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
84
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
85
+ var __spreadValues$j = (a, b) => {
95
86
  for (var prop in b || (b = {}))
96
- if (__hasOwnProp$i.call(b, prop))
97
- __defNormalProp$h(a, prop, b[prop]);
98
- if (__getOwnPropSymbols$i)
99
- for (var prop of __getOwnPropSymbols$i(b)) {
100
- if (__propIsEnum$i.call(b, prop))
101
- __defNormalProp$h(a, prop, b[prop]);
87
+ if (__hasOwnProp$k.call(b, prop))
88
+ __defNormalProp$j(a, prop, b[prop]);
89
+ if (__getOwnPropSymbols$k)
90
+ for (var prop of __getOwnPropSymbols$k(b)) {
91
+ if (__propIsEnum$k.call(b, prop))
92
+ __defNormalProp$j(a, prop, b[prop]);
102
93
  }
103
94
  return a;
104
95
  };
105
- function forEachSceneObjectInState(state, callback) {
106
- for (const propValue of Object.values(state)) {
107
- if (propValue instanceof SceneObjectBase) {
108
- callback(propValue);
109
- }
110
- if (Array.isArray(propValue)) {
111
- for (const child of propValue) {
112
- if (child instanceof SceneObjectBase) {
113
- callback(child);
114
- }
115
- }
116
- }
117
- }
118
- }
119
96
  function cloneSceneObject(sceneObject, withState) {
120
- const clonedState = __spreadValues$h({}, sceneObject.state);
97
+ const clonedState = __spreadValues$j({}, sceneObject.state);
121
98
  for (const key in clonedState) {
122
99
  const propValue = clonedState[key];
123
100
  if (propValue instanceof SceneObjectBase) {
@@ -139,19 +116,19 @@ function cloneSceneObject(sceneObject, withState) {
139
116
  return new sceneObject.constructor(clonedState);
140
117
  }
141
118
 
142
- var __defProp$g = Object.defineProperty;
143
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
144
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
145
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
146
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
147
- var __spreadValues$g = (a, b) => {
119
+ var __defProp$i = Object.defineProperty;
120
+ var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
121
+ var __hasOwnProp$j = Object.prototype.hasOwnProperty;
122
+ var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
123
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
124
+ var __spreadValues$i = (a, b) => {
148
125
  for (var prop in b || (b = {}))
149
- if (__hasOwnProp$h.call(b, prop))
150
- __defNormalProp$g(a, prop, b[prop]);
151
- if (__getOwnPropSymbols$h)
152
- for (var prop of __getOwnPropSymbols$h(b)) {
153
- if (__propIsEnum$h.call(b, prop))
154
- __defNormalProp$g(a, prop, b[prop]);
126
+ if (__hasOwnProp$j.call(b, prop))
127
+ __defNormalProp$i(a, prop, b[prop]);
128
+ if (__getOwnPropSymbols$j)
129
+ for (var prop of __getOwnPropSymbols$j(b)) {
130
+ if (__propIsEnum$j.call(b, prop))
131
+ __defNormalProp$i(a, prop, b[prop]);
155
132
  }
156
133
  return a;
157
134
  };
@@ -162,11 +139,12 @@ class SceneObjectBase {
162
139
  this._activationHandlers = [];
163
140
  this._deactivationHandlers = [];
164
141
  this._subs = new rxjs.Subscription();
142
+ this._refCount = 0;
165
143
  if (!state.key) {
166
144
  state.key = uuid.v4();
167
145
  }
168
146
  this._state = Object.freeze(state);
169
- this.setParent();
147
+ this._setParent();
170
148
  }
171
149
  get state() {
172
150
  return this._state;
@@ -186,8 +164,8 @@ class SceneObjectBase {
186
164
  get Component() {
187
165
  return SceneComponentWrapper;
188
166
  }
189
- setParent() {
190
- forEachSceneObjectInState(this._state, (child) => child._parent = this);
167
+ _setParent() {
168
+ this.forEachChild((child) => child._parent = this);
191
169
  }
192
170
  subscribeToState(handler) {
193
171
  return this._events.subscribe(SceneObjectStateChangedEvent, (event) => {
@@ -201,9 +179,9 @@ class SceneObjectBase {
201
179
  }
202
180
  setState(update) {
203
181
  const prevState = this._state;
204
- const newState = __spreadValues$g(__spreadValues$g({}, this._state), update);
182
+ const newState = __spreadValues$i(__spreadValues$i({}, this._state), update);
205
183
  this._state = Object.freeze(newState);
206
- this.setParent();
184
+ this._setParent();
207
185
  this.publishEvent(
208
186
  new SceneObjectStateChangedEvent({
209
187
  prevState,
@@ -223,17 +201,17 @@ class SceneObjectBase {
223
201
  getRoot() {
224
202
  return !this._parent ? this : this._parent.getRoot();
225
203
  }
226
- activate() {
204
+ _internalActivate() {
227
205
  this._isActive = true;
228
206
  const { $data, $variables, $timeRange } = this.state;
229
207
  if ($timeRange && !$timeRange.isActive) {
230
- $timeRange.activate();
208
+ this._deactivationHandlers.push($timeRange.activate());
231
209
  }
232
210
  if ($variables && !$variables.isActive) {
233
- $variables.activate();
211
+ this._deactivationHandlers.push($variables.activate());
234
212
  }
235
213
  if ($data && !$data.isActive) {
236
- $data.activate();
214
+ this._deactivationHandlers.push($data.activate());
237
215
  }
238
216
  this._activationHandlers.forEach((handler) => {
239
217
  const result = handler();
@@ -242,18 +220,27 @@ class SceneObjectBase {
242
220
  }
243
221
  });
244
222
  }
245
- deactivate() {
246
- this._isActive = false;
247
- const { $data, $variables, $timeRange } = this.state;
248
- if ($timeRange && $timeRange.isActive) {
249
- $timeRange.deactivate();
250
- }
251
- if ($data && $data.isActive) {
252
- $data.deactivate();
253
- }
254
- if ($variables && $variables.isActive) {
255
- $variables.deactivate();
223
+ activate() {
224
+ if (!this.isActive) {
225
+ this._internalActivate();
256
226
  }
227
+ this._refCount++;
228
+ let called = false;
229
+ return () => {
230
+ this._refCount--;
231
+ if (called) {
232
+ const msg = `SceneObject cancelation handler returned by activate() called a second time`;
233
+ console.error(msg, this);
234
+ throw new Error(msg);
235
+ }
236
+ called = true;
237
+ if (this._refCount === 0) {
238
+ this._internalDeactivate();
239
+ }
240
+ };
241
+ }
242
+ _internalDeactivate() {
243
+ this._isActive = false;
257
244
  this._deactivationHandlers.forEach((handler) => handler());
258
245
  this._deactivationHandlers = [];
259
246
  this._events.removeAllListeners();
@@ -272,6 +259,20 @@ class SceneObjectBase {
272
259
  addActivationHandler(handler) {
273
260
  this._activationHandlers.push(handler);
274
261
  }
262
+ forEachChild(callback) {
263
+ for (const propValue of Object.values(this.state)) {
264
+ if (propValue instanceof SceneObjectBase) {
265
+ callback(propValue);
266
+ }
267
+ if (Array.isArray(propValue)) {
268
+ for (const child of propValue) {
269
+ if (child instanceof SceneObjectBase) {
270
+ callback(child);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
275
276
  }
276
277
  function useSceneObjectState(model) {
277
278
  const forceUpdate = ui.useForceUpdate();
@@ -282,8 +283,34 @@ function useSceneObjectState(model) {
282
283
  return model.state;
283
284
  }
284
285
 
286
+ var __defProp$h = Object.defineProperty;
287
+ var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
288
+ var __hasOwnProp$i = Object.prototype.hasOwnProperty;
289
+ var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
290
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
291
+ var __spreadValues$h = (a, b) => {
292
+ for (var prop in b || (b = {}))
293
+ if (__hasOwnProp$i.call(b, prop))
294
+ __defNormalProp$h(a, prop, b[prop]);
295
+ if (__getOwnPropSymbols$i)
296
+ for (var prop of __getOwnPropSymbols$i(b)) {
297
+ if (__propIsEnum$i.call(b, prop))
298
+ __defNormalProp$h(a, prop, b[prop]);
299
+ }
300
+ return a;
301
+ };
285
302
  class SceneDataNode extends SceneObjectBase {
303
+ constructor(state) {
304
+ super(__spreadValues$h({
305
+ data: emptyPanelData
306
+ }, state));
307
+ }
286
308
  }
309
+ const emptyPanelData = {
310
+ state: schema.LoadingState.Done,
311
+ series: [],
312
+ timeRange: data.getDefaultTimeRange()
313
+ };
287
314
 
288
315
  class SceneObjectUrlSyncConfig {
289
316
  constructor(_sceneObject, _options) {
@@ -301,19 +328,19 @@ class SceneObjectUrlSyncConfig {
301
328
  }
302
329
  }
303
330
 
304
- var __defProp$f = Object.defineProperty;
305
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
306
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
307
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
308
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
309
- var __spreadValues$f = (a, b) => {
331
+ var __defProp$g = Object.defineProperty;
332
+ var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
333
+ var __hasOwnProp$h = Object.prototype.hasOwnProperty;
334
+ var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
335
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
336
+ var __spreadValues$g = (a, b) => {
310
337
  for (var prop in b || (b = {}))
311
- if (__hasOwnProp$g.call(b, prop))
312
- __defNormalProp$f(a, prop, b[prop]);
313
- if (__getOwnPropSymbols$g)
314
- for (var prop of __getOwnPropSymbols$g(b)) {
315
- if (__propIsEnum$g.call(b, prop))
316
- __defNormalProp$f(a, prop, b[prop]);
338
+ if (__hasOwnProp$h.call(b, prop))
339
+ __defNormalProp$g(a, prop, b[prop]);
340
+ if (__getOwnPropSymbols$h)
341
+ for (var prop of __getOwnPropSymbols$h(b)) {
342
+ if (__propIsEnum$h.call(b, prop))
343
+ __defNormalProp$g(a, prop, b[prop]);
317
344
  }
318
345
  return a;
319
346
  };
@@ -324,7 +351,7 @@ class SceneTimeRange extends SceneObjectBase {
324
351
  const to = (_b = state.to) != null ? _b : "now";
325
352
  const timeZone = (_c = state.timeZone) != null ? _c : data.getTimeZone();
326
353
  const value = evaluateTimeRange(from, to, timeZone);
327
- super(__spreadValues$f({ from, to, timeZone, value }, state));
354
+ super(__spreadValues$g({ from, to, timeZone, value }, state));
328
355
  this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to"] });
329
356
  this.onTimeRangeChange = (timeRange) => {
330
357
  const update = {};
@@ -404,13 +431,7 @@ function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth) {
404
431
  };
405
432
  }
406
433
 
407
- const EmptyDataNode = new SceneDataNode({
408
- data: {
409
- state: data.LoadingState.Done,
410
- series: [],
411
- timeRange: data.getDefaultTimeRange()
412
- }
413
- });
434
+ const EmptyDataNode = new SceneDataNode();
414
435
  const DefaultTimeRange = new SceneTimeRange();
415
436
  class EmptyVariableSetImpl extends SceneObjectBase {
416
437
  constructor() {
@@ -840,9 +861,66 @@ function collectAllVariables(sceneObject, record = {}) {
840
861
  return record;
841
862
  }
842
863
 
864
+ class DataValueMacro {
865
+ constructor(name, sceneObject, _match, _scopedVars) {
866
+ this._match = _match;
867
+ this._scopedVars = _scopedVars;
868
+ this.state = { name, type: "url_variable" };
869
+ }
870
+ getValue(fieldPath) {
871
+ var _a, _b;
872
+ const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
873
+ if (!dataContext) {
874
+ return this._match;
875
+ }
876
+ const { frame, rowIndex, field, calculatedValue } = dataContext.value;
877
+ if (calculatedValue) {
878
+ switch (fieldPath) {
879
+ case "numeric":
880
+ return calculatedValue.numeric;
881
+ case "raw":
882
+ return calculatedValue.numeric;
883
+ case "time":
884
+ return "";
885
+ case "text":
886
+ default:
887
+ return data.formattedValueToString(calculatedValue);
888
+ }
889
+ }
890
+ if (!rowIndex) {
891
+ return this._match;
892
+ }
893
+ if (fieldPath === "time") {
894
+ const timeField = frame.fields.find((f) => f.type === data.FieldType.time);
895
+ return timeField ? timeField.values.get(rowIndex) : void 0;
896
+ }
897
+ if (!field) {
898
+ return this._match;
899
+ }
900
+ const value = field.values.get(rowIndex);
901
+ if (fieldPath === "raw") {
902
+ return value;
903
+ }
904
+ const displayProcessor = (_b = field.display) != null ? _b : fallbackDisplayProcessor;
905
+ const result = displayProcessor(value);
906
+ switch (fieldPath) {
907
+ case "numeric":
908
+ return result.numeric;
909
+ case "text":
910
+ default:
911
+ return data.formattedValueToString(result);
912
+ }
913
+ }
914
+ getValueText() {
915
+ return "";
916
+ }
917
+ }
918
+ const fallbackDisplayProcessor = data.getDisplayProcessor();
919
+
843
920
  const macrosIndex = {
844
921
  [data.DataLinkBuiltInVars.includeVars]: AllVariablesMacro,
845
- [data.DataLinkBuiltInVars.keepTime]: UrlTimeRangeMacro
922
+ [data.DataLinkBuiltInVars.keepTime]: UrlTimeRangeMacro,
923
+ ["__value"]: DataValueMacro
846
924
  };
847
925
 
848
926
  function sceneInterpolator(sceneObject, target, scopedVars, format) {
@@ -853,22 +931,26 @@ function sceneInterpolator(sceneObject, target, scopedVars, format) {
853
931
  return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
854
932
  const variableName = var1 || var2 || var3;
855
933
  const fmt = fmt2 || fmt3 || format;
856
- const variable = lookupFormatVariable(variableName, scopedVars, sceneObject);
934
+ const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
857
935
  if (!variable) {
858
936
  return match;
859
937
  }
860
938
  return formatValue(variable, variable.getValue(fieldPath), fmt);
861
939
  });
862
940
  }
863
- function lookupFormatVariable(name, scopedVars, sceneObject) {
864
- if (macrosIndex[name]) {
865
- return new macrosIndex[name](name, sceneObject);
941
+ function lookupFormatVariable(name, match, scopedVars, sceneObject) {
942
+ const scopedVar = scopedVars == null ? void 0 : scopedVars[name];
943
+ if (scopedVar) {
944
+ return getSceneVariableForScopedVar(name, scopedVar);
866
945
  }
867
- if (scopedVars && scopedVars[name]) {
868
- return getSceneVariableForScopedVar(name, scopedVars[name]);
869
- } else {
870
- return lookupVariable(name, sceneObject);
946
+ const variable = lookupVariable(name, sceneObject);
947
+ if (variable) {
948
+ return variable;
871
949
  }
950
+ if (macrosIndex[name]) {
951
+ return new macrosIndex[name](name, sceneObject, match, scopedVars);
952
+ }
953
+ return null;
872
954
  }
873
955
  function formatValue(variable, value, formatNameOrFn) {
874
956
  if (value === null || value === void 0) {
@@ -1152,22 +1234,23 @@ class SceneQueryRunner extends SceneObjectBase {
1152
1234
  statePaths: ["queries", "datasource"],
1153
1235
  onVariableUpdatesCompleted: (variables, dependencyChanged) => this.onVariableUpdatesCompleted(variables, dependencyChanged)
1154
1236
  });
1155
- this._onActivate = () => {
1156
- const timeRange = sceneGraph.getTimeRange(this);
1157
- this._subs.add(
1158
- timeRange.subscribeToState((timeRange2) => {
1159
- this.runWithTimeRange(timeRange2.value);
1160
- })
1161
- );
1162
- if (this.shouldRunQueriesOnActivate()) {
1163
- this.runQueries();
1164
- }
1165
- };
1166
1237
  this.onDataReceived = (data$1) => {
1167
1238
  const preProcessedData = data.preProcessPanelData(data$1, this.state.data);
1168
1239
  this.setState({ data: preProcessedData });
1169
1240
  };
1170
- this.addActivationHandler(this._onActivate);
1241
+ this.addActivationHandler(() => this._onActivate());
1242
+ }
1243
+ _onActivate() {
1244
+ const timeRange = sceneGraph.getTimeRange(this);
1245
+ this._subs.add(
1246
+ timeRange.subscribeToState((timeRange2) => {
1247
+ this.runWithTimeRange(timeRange2.value);
1248
+ })
1249
+ );
1250
+ if (this.shouldRunQueriesOnActivate()) {
1251
+ this.runQueries();
1252
+ }
1253
+ return () => this._onDeactivate();
1171
1254
  }
1172
1255
  onVariableUpdatesCompleted(_variablesThatHaveChanged, dependencyChanged) {
1173
1256
  if (this.state.isWaitingForVariables && this.shouldRunQueriesOnActivate()) {
@@ -1194,8 +1277,7 @@ class SceneQueryRunner extends SceneObjectBase {
1194
1277
  }
1195
1278
  return true;
1196
1279
  }
1197
- deactivate() {
1198
- super.deactivate();
1280
+ _onDeactivate() {
1199
1281
  if (this._querySub) {
1200
1282
  this._querySub.unsubscribe();
1201
1283
  this._querySub = void 0;
@@ -1295,25 +1377,25 @@ function findFirstDatasource(targets) {
1295
1377
  return void 0;
1296
1378
  }
1297
1379
 
1298
- var __defProp$e = Object.defineProperty;
1299
- var __defProps$6 = Object.defineProperties;
1300
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1301
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
1302
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
1303
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
1304
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1305
- var __spreadValues$e = (a, b) => {
1380
+ var __defProp$f = Object.defineProperty;
1381
+ var __defProps$8 = Object.defineProperties;
1382
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1383
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
1384
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
1385
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
1386
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1387
+ var __spreadValues$f = (a, b) => {
1306
1388
  for (var prop in b || (b = {}))
1307
- if (__hasOwnProp$f.call(b, prop))
1308
- __defNormalProp$e(a, prop, b[prop]);
1309
- if (__getOwnPropSymbols$f)
1310
- for (var prop of __getOwnPropSymbols$f(b)) {
1311
- if (__propIsEnum$f.call(b, prop))
1312
- __defNormalProp$e(a, prop, b[prop]);
1389
+ if (__hasOwnProp$g.call(b, prop))
1390
+ __defNormalProp$f(a, prop, b[prop]);
1391
+ if (__getOwnPropSymbols$g)
1392
+ for (var prop of __getOwnPropSymbols$g(b)) {
1393
+ if (__propIsEnum$g.call(b, prop))
1394
+ __defNormalProp$f(a, prop, b[prop]);
1313
1395
  }
1314
1396
  return a;
1315
1397
  };
1316
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
1398
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1317
1399
  class SceneDataTransformer extends SceneObjectBase {
1318
1400
  constructor(state) {
1319
1401
  super(state);
@@ -1370,7 +1452,7 @@ class SceneDataTransformer extends SceneObjectBase {
1370
1452
  return sceneGraph.interpolate(this, value, (_a = data$1.request) == null ? void 0 : _a.scopedVars);
1371
1453
  }
1372
1454
  };
1373
- this._transformSub = data.transformDataFrame(transformations, data$1.series, ctx).pipe(rxjs.map((series) => __spreadProps$6(__spreadValues$e({}, data$1), { series }))).subscribe((data2) => this.setState({ data: data2 }));
1455
+ this._transformSub = data.transformDataFrame(transformations, data$1.series, ctx).pipe(rxjs.map((series) => __spreadProps$8(__spreadValues$f({}, data$1), { series }))).subscribe((data2) => this.setState({ data: data2 }));
1374
1456
  }
1375
1457
  }
1376
1458
 
@@ -1455,16 +1537,16 @@ class SceneVariableSet extends SceneObjectBase {
1455
1537
  this._variableValueRecorder = new VariableValueRecorder();
1456
1538
  this._onActivate = () => {
1457
1539
  this._subs.add(
1458
- this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this.handleVariableValueChanged(event.payload))
1540
+ this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this._handleVariableValueChanged(event.payload))
1459
1541
  );
1460
- this._subs.add(this.subscribeToState(this.handleStateChanged));
1461
- this.checkForVariablesThatChangedWhileInactive();
1542
+ this._subs.add(this.subscribeToState(this._onStateChanged));
1543
+ this._checkForVariablesThatChangedWhileInactive();
1462
1544
  for (const variable of this.state.variables) {
1463
- if (this.variableNeedsUpdate(variable)) {
1545
+ if (this._variableNeedsUpdate(variable)) {
1464
1546
  this._variablesToUpdate.add(variable);
1465
1547
  }
1466
1548
  }
1467
- this.updateNextBatch();
1549
+ this._updateNextBatch();
1468
1550
  return this._onDeactivate;
1469
1551
  };
1470
1552
  this._onDeactivate = () => {
@@ -1480,7 +1562,7 @@ class SceneVariableSet extends SceneObjectBase {
1480
1562
  this._variablesToUpdate.clear();
1481
1563
  this._updating.clear();
1482
1564
  };
1483
- this.handleStateChanged = (newState, oldState) => {
1565
+ this._onStateChanged = (newState, oldState) => {
1484
1566
  const variablesToUpdateCountStart = this._variablesToUpdate.size;
1485
1567
  for (const variable of oldState.variables) {
1486
1568
  if (!newState.variables.includes(variable)) {
@@ -1494,13 +1576,13 @@ class SceneVariableSet extends SceneObjectBase {
1494
1576
  }
1495
1577
  for (const variable of newState.variables) {
1496
1578
  if (!oldState.variables.includes(variable)) {
1497
- if (this.variableNeedsUpdate(variable)) {
1579
+ if (this._variableNeedsUpdate(variable)) {
1498
1580
  this._variablesToUpdate.add(variable);
1499
1581
  }
1500
1582
  }
1501
1583
  }
1502
1584
  if (variablesToUpdateCountStart === 0 && this._variablesToUpdate.size > 0) {
1503
- this.updateNextBatch();
1585
+ this._updateNextBatch();
1504
1586
  }
1505
1587
  };
1506
1588
  this.addActivationHandler(this._onActivate);
@@ -1508,18 +1590,18 @@ class SceneVariableSet extends SceneObjectBase {
1508
1590
  getByName(name) {
1509
1591
  return this.state.variables.find((x) => x.state.name === name);
1510
1592
  }
1511
- checkForVariablesThatChangedWhileInactive() {
1593
+ _checkForVariablesThatChangedWhileInactive() {
1512
1594
  if (!this._variableValueRecorder.hasValues()) {
1513
1595
  return;
1514
1596
  }
1515
1597
  for (const variable of this.state.variables) {
1516
1598
  if (this._variableValueRecorder.hasValueChanged(variable)) {
1517
1599
  writeVariableTraceLog(variable, "Changed while in-active");
1518
- this.addDependentVariablesToUpdateQueue(variable);
1600
+ this._addDependentVariablesToUpdateQueue(variable);
1519
1601
  }
1520
1602
  }
1521
1603
  }
1522
- variableNeedsUpdate(variable) {
1604
+ _variableNeedsUpdate(variable) {
1523
1605
  if (!variable.validateAndUpdate) {
1524
1606
  return false;
1525
1607
  }
@@ -1529,9 +1611,9 @@ class SceneVariableSet extends SceneObjectBase {
1529
1611
  }
1530
1612
  return true;
1531
1613
  }
1532
- updateNextBatch() {
1614
+ _updateNextBatch() {
1533
1615
  if (this._variablesToUpdate.size === 0) {
1534
- this.notifyDependentSceneObjects();
1616
+ this._notifyDependentSceneObjects();
1535
1617
  return;
1536
1618
  }
1537
1619
  for (const variable of this._variablesToUpdate) {
@@ -1541,7 +1623,7 @@ class SceneVariableSet extends SceneObjectBase {
1541
1623
  if (this._updating.has(variable)) {
1542
1624
  continue;
1543
1625
  }
1544
- if (this.hasDependendencyInUpdateQueue(variable)) {
1626
+ if (this._hasDependendencyInUpdateQueue(variable)) {
1545
1627
  continue;
1546
1628
  }
1547
1629
  const variableToUpdate = {
@@ -1550,21 +1632,21 @@ class SceneVariableSet extends SceneObjectBase {
1550
1632
  this._updating.set(variable, variableToUpdate);
1551
1633
  writeVariableTraceLog(variable, "updateAndValidate started");
1552
1634
  variableToUpdate.subscription = variable.validateAndUpdate().subscribe({
1553
- next: () => this.validateAndUpdateCompleted(variable),
1554
- error: (err) => this.handleVariableError(variable, err)
1635
+ next: () => this._validateAndUpdateCompleted(variable),
1636
+ error: (err) => this._handleVariableError(variable, err)
1555
1637
  });
1556
1638
  }
1557
1639
  }
1558
- validateAndUpdateCompleted(variable) {
1640
+ _validateAndUpdateCompleted(variable) {
1559
1641
  var _a;
1560
1642
  const update = this._updating.get(variable);
1561
1643
  (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
1562
1644
  this._updating.delete(variable);
1563
1645
  this._variablesToUpdate.delete(variable);
1564
1646
  writeVariableTraceLog(variable, "updateAndValidate completed");
1565
- this.updateNextBatch();
1647
+ this._updateNextBatch();
1566
1648
  }
1567
- handleVariableError(variable, err) {
1649
+ _handleVariableError(variable, err) {
1568
1650
  var _a;
1569
1651
  const update = this._updating.get(variable);
1570
1652
  (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
@@ -1573,7 +1655,7 @@ class SceneVariableSet extends SceneObjectBase {
1573
1655
  variable.setState({ loading: false, error: err });
1574
1656
  writeVariableTraceLog(variable, "updateAndValidate error", err);
1575
1657
  }
1576
- hasDependendencyInUpdateQueue(variable) {
1658
+ _hasDependendencyInUpdateQueue(variable) {
1577
1659
  var _a;
1578
1660
  if (!variable.variableDependency) {
1579
1661
  return false;
@@ -1585,15 +1667,15 @@ class SceneVariableSet extends SceneObjectBase {
1585
1667
  }
1586
1668
  return false;
1587
1669
  }
1588
- handleVariableValueChanged(variableThatChanged) {
1670
+ _handleVariableValueChanged(variableThatChanged) {
1589
1671
  this._variablesThatHaveChanged.add(variableThatChanged);
1590
1672
  if (this._updating.has(variableThatChanged)) {
1591
1673
  return;
1592
1674
  }
1593
- this.addDependentVariablesToUpdateQueue(variableThatChanged);
1594
- this.updateNextBatch();
1675
+ this._addDependentVariablesToUpdateQueue(variableThatChanged);
1676
+ this._updateNextBatch();
1595
1677
  }
1596
- addDependentVariablesToUpdateQueue(variableThatChanged) {
1678
+ _addDependentVariablesToUpdateQueue(variableThatChanged) {
1597
1679
  for (const otherVariable of this.state.variables) {
1598
1680
  if (otherVariable.variableDependency) {
1599
1681
  if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
@@ -1603,14 +1685,14 @@ class SceneVariableSet extends SceneObjectBase {
1603
1685
  }
1604
1686
  }
1605
1687
  }
1606
- notifyDependentSceneObjects() {
1688
+ _notifyDependentSceneObjects() {
1607
1689
  if (!this.parent) {
1608
1690
  return;
1609
1691
  }
1610
- this.traverseSceneAndNotify(this.parent);
1692
+ this._traverseSceneAndNotify(this.parent);
1611
1693
  this._variablesThatHaveChanged.clear();
1612
1694
  }
1613
- traverseSceneAndNotify(sceneObject) {
1695
+ _traverseSceneAndNotify(sceneObject) {
1614
1696
  if (this === sceneObject) {
1615
1697
  return;
1616
1698
  }
@@ -1620,7 +1702,7 @@ class SceneVariableSet extends SceneObjectBase {
1620
1702
  if (sceneObject.variableDependency) {
1621
1703
  sceneObject.variableDependency.variableUpdatesCompleted(this._variablesThatHaveChanged);
1622
1704
  }
1623
- forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));
1705
+ sceneObject.forEachChild((child) => this._traverseSceneAndNotify(child));
1624
1706
  }
1625
1707
  isVariableLoadingOrWaitingToUpdate(variable) {
1626
1708
  if (!this.isActive) {
@@ -1633,28 +1715,28 @@ function writeVariableTraceLog(variable, message, err) {
1633
1715
  writeSceneLog("SceneVariableSet", `Variable[${variable.state.name}]: ${message}`, err);
1634
1716
  }
1635
1717
 
1636
- var __defProp$d = Object.defineProperty;
1637
- var __defProps$5 = Object.defineProperties;
1638
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
1639
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
1640
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
1641
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
1642
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1643
- var __spreadValues$d = (a, b) => {
1718
+ var __defProp$e = Object.defineProperty;
1719
+ var __defProps$7 = Object.defineProperties;
1720
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1721
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
1722
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
1723
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
1724
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1725
+ var __spreadValues$e = (a, b) => {
1644
1726
  for (var prop in b || (b = {}))
1645
- if (__hasOwnProp$e.call(b, prop))
1646
- __defNormalProp$d(a, prop, b[prop]);
1647
- if (__getOwnPropSymbols$e)
1648
- for (var prop of __getOwnPropSymbols$e(b)) {
1649
- if (__propIsEnum$e.call(b, prop))
1650
- __defNormalProp$d(a, prop, b[prop]);
1727
+ if (__hasOwnProp$f.call(b, prop))
1728
+ __defNormalProp$e(a, prop, b[prop]);
1729
+ if (__getOwnPropSymbols$f)
1730
+ for (var prop of __getOwnPropSymbols$f(b)) {
1731
+ if (__propIsEnum$f.call(b, prop))
1732
+ __defNormalProp$e(a, prop, b[prop]);
1651
1733
  }
1652
1734
  return a;
1653
1735
  };
1654
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
1736
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1655
1737
  class ConstantVariable extends SceneObjectBase {
1656
1738
  constructor(initialState) {
1657
- super(__spreadProps$5(__spreadValues$d({
1739
+ super(__spreadProps$7(__spreadValues$e({
1658
1740
  type: "constant",
1659
1741
  value: "",
1660
1742
  name: ""
@@ -1903,25 +1985,25 @@ class CustomAllValue {
1903
1985
  }
1904
1986
  }
1905
1987
 
1906
- var __defProp$c = Object.defineProperty;
1907
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
1908
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
1909
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
1910
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1911
- var __spreadValues$c = (a, b) => {
1988
+ var __defProp$d = Object.defineProperty;
1989
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
1990
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
1991
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
1992
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1993
+ var __spreadValues$d = (a, b) => {
1912
1994
  for (var prop in b || (b = {}))
1913
- if (__hasOwnProp$d.call(b, prop))
1914
- __defNormalProp$c(a, prop, b[prop]);
1915
- if (__getOwnPropSymbols$d)
1916
- for (var prop of __getOwnPropSymbols$d(b)) {
1917
- if (__propIsEnum$d.call(b, prop))
1918
- __defNormalProp$c(a, prop, b[prop]);
1995
+ if (__hasOwnProp$e.call(b, prop))
1996
+ __defNormalProp$d(a, prop, b[prop]);
1997
+ if (__getOwnPropSymbols$e)
1998
+ for (var prop of __getOwnPropSymbols$e(b)) {
1999
+ if (__propIsEnum$e.call(b, prop))
2000
+ __defNormalProp$d(a, prop, b[prop]);
1919
2001
  }
1920
2002
  return a;
1921
2003
  };
1922
2004
  class CustomVariable extends MultiValueVariable {
1923
2005
  constructor(initialState) {
1924
- super(__spreadValues$c({
2006
+ super(__spreadValues$d({
1925
2007
  type: "custom",
1926
2008
  query: "",
1927
2009
  value: "",
@@ -1954,25 +2036,25 @@ CustomVariable.Component = ({ model }) => {
1954
2036
  return renderSelectForVariable(model);
1955
2037
  };
1956
2038
 
1957
- var __defProp$b = Object.defineProperty;
1958
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
1959
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
1960
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
1961
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1962
- var __spreadValues$b = (a, b) => {
2039
+ var __defProp$c = Object.defineProperty;
2040
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
2041
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
2042
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
2043
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2044
+ var __spreadValues$c = (a, b) => {
1963
2045
  for (var prop in b || (b = {}))
1964
- if (__hasOwnProp$c.call(b, prop))
1965
- __defNormalProp$b(a, prop, b[prop]);
1966
- if (__getOwnPropSymbols$c)
1967
- for (var prop of __getOwnPropSymbols$c(b)) {
1968
- if (__propIsEnum$c.call(b, prop))
1969
- __defNormalProp$b(a, prop, b[prop]);
2046
+ if (__hasOwnProp$d.call(b, prop))
2047
+ __defNormalProp$c(a, prop, b[prop]);
2048
+ if (__getOwnPropSymbols$d)
2049
+ for (var prop of __getOwnPropSymbols$d(b)) {
2050
+ if (__propIsEnum$d.call(b, prop))
2051
+ __defNormalProp$c(a, prop, b[prop]);
1970
2052
  }
1971
2053
  return a;
1972
2054
  };
1973
2055
  class DataSourceVariable extends MultiValueVariable {
1974
2056
  constructor(initialState) {
1975
- super(__spreadValues$b({
2057
+ super(__spreadValues$c({
1976
2058
  type: "datasource",
1977
2059
  value: "",
1978
2060
  text: "",
@@ -2060,25 +2142,25 @@ const hasCustomVariableSupport = (datasource) => {
2060
2142
  return "query" in variableSupport && "editor" in variableSupport && Boolean(variableSupport.query) && Boolean(variableSupport.editor);
2061
2143
  };
2062
2144
 
2063
- var __defProp$a = Object.defineProperty;
2064
- var __defProps$4 = Object.defineProperties;
2065
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
2066
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
2067
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
2068
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
2069
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2070
- var __spreadValues$a = (a, b) => {
2145
+ var __defProp$b = Object.defineProperty;
2146
+ var __defProps$6 = Object.defineProperties;
2147
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
2148
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
2149
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
2150
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
2151
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2152
+ var __spreadValues$b = (a, b) => {
2071
2153
  for (var prop in b || (b = {}))
2072
- if (__hasOwnProp$b.call(b, prop))
2073
- __defNormalProp$a(a, prop, b[prop]);
2074
- if (__getOwnPropSymbols$b)
2075
- for (var prop of __getOwnPropSymbols$b(b)) {
2076
- if (__propIsEnum$b.call(b, prop))
2077
- __defNormalProp$a(a, prop, b[prop]);
2154
+ if (__hasOwnProp$c.call(b, prop))
2155
+ __defNormalProp$b(a, prop, b[prop]);
2156
+ if (__getOwnPropSymbols$c)
2157
+ for (var prop of __getOwnPropSymbols$c(b)) {
2158
+ if (__propIsEnum$c.call(b, prop))
2159
+ __defNormalProp$b(a, prop, b[prop]);
2078
2160
  }
2079
2161
  return a;
2080
2162
  };
2081
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
2163
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
2082
2164
  class StandardQueryRunner {
2083
2165
  constructor(datasource, _runRequest = runtime.getRunRequest()) {
2084
2166
  this.datasource = datasource;
@@ -2115,7 +2197,7 @@ class LegacyQueryRunner {
2115
2197
  return getEmptyMetricFindValueObservable();
2116
2198
  }
2117
2199
  return rxjs.from(
2118
- this.datasource.metricFindQuery(variable.state.query, __spreadProps$4(__spreadValues$a({}, request), {
2200
+ this.datasource.metricFindQuery(variable.state.query, __spreadProps$6(__spreadValues$b({}, request), {
2119
2201
  variable: {
2120
2202
  name: variable.state.name,
2121
2203
  type: variable.state.type
@@ -2346,25 +2428,25 @@ function areMetricFindValues(data$1) {
2346
2428
  return false;
2347
2429
  }
2348
2430
 
2349
- var __defProp$9 = Object.defineProperty;
2350
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
2351
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
2352
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
2353
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2354
- var __spreadValues$9 = (a, b) => {
2431
+ var __defProp$a = Object.defineProperty;
2432
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
2433
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
2434
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
2435
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2436
+ var __spreadValues$a = (a, b) => {
2355
2437
  for (var prop in b || (b = {}))
2356
- if (__hasOwnProp$a.call(b, prop))
2357
- __defNormalProp$9(a, prop, b[prop]);
2358
- if (__getOwnPropSymbols$a)
2359
- for (var prop of __getOwnPropSymbols$a(b)) {
2360
- if (__propIsEnum$a.call(b, prop))
2361
- __defNormalProp$9(a, prop, b[prop]);
2438
+ if (__hasOwnProp$b.call(b, prop))
2439
+ __defNormalProp$a(a, prop, b[prop]);
2440
+ if (__getOwnPropSymbols$b)
2441
+ for (var prop of __getOwnPropSymbols$b(b)) {
2442
+ if (__propIsEnum$b.call(b, prop))
2443
+ __defNormalProp$a(a, prop, b[prop]);
2362
2444
  }
2363
2445
  return a;
2364
2446
  };
2365
2447
  class QueryVariable extends MultiValueVariable {
2366
2448
  constructor(initialState) {
2367
- super(__spreadValues$9({
2449
+ super(__spreadValues$a({
2368
2450
  type: "query",
2369
2451
  name: "",
2370
2452
  value: "",
@@ -2379,23 +2461,22 @@ class QueryVariable extends MultiValueVariable {
2379
2461
  this._variableDependency = new VariableDependencyConfig(this, {
2380
2462
  statePaths: ["regex", "query", "datasource"]
2381
2463
  });
2382
- this._onActivate = () => {
2383
- const timeRange = sceneGraph.getTimeRange(this);
2384
- if (this.state.refresh === data.VariableRefresh.onTimeRangeChanged) {
2385
- this._subs.add(
2386
- timeRange.subscribeToState(() => {
2387
- this.updateSubscription = this.validateAndUpdate().subscribe();
2388
- })
2389
- );
2390
- }
2391
- };
2392
- this.addActivationHandler(this._onActivate);
2464
+ this.addActivationHandler(() => this._onActivate());
2393
2465
  }
2394
- deactivate() {
2395
- super.deactivate();
2396
- if (this.updateSubscription) {
2397
- this.updateSubscription.unsubscribe();
2466
+ _onActivate() {
2467
+ const timeRange = sceneGraph.getTimeRange(this);
2468
+ if (this.state.refresh === data.VariableRefresh.onTimeRangeChanged) {
2469
+ this._subs.add(
2470
+ timeRange.subscribeToState(() => {
2471
+ this.updateSubscription = this.validateAndUpdate().subscribe();
2472
+ })
2473
+ );
2398
2474
  }
2475
+ return () => {
2476
+ if (this.updateSubscription) {
2477
+ this.updateSubscription.unsubscribe();
2478
+ }
2479
+ };
2399
2480
  }
2400
2481
  getValueOptions(args) {
2401
2482
  if (this.state.query === "" || !this.state.datasource) {
@@ -2514,25 +2595,25 @@ function queryMetricTree(query) {
2514
2595
  return queryTree(children, query.split("."), 0);
2515
2596
  }
2516
2597
 
2517
- var __defProp$8 = Object.defineProperty;
2518
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
2519
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
2520
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
2521
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2522
- var __spreadValues$8 = (a, b) => {
2598
+ var __defProp$9 = Object.defineProperty;
2599
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
2600
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
2601
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
2602
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2603
+ var __spreadValues$9 = (a, b) => {
2523
2604
  for (var prop in b || (b = {}))
2524
- if (__hasOwnProp$9.call(b, prop))
2525
- __defNormalProp$8(a, prop, b[prop]);
2526
- if (__getOwnPropSymbols$9)
2527
- for (var prop of __getOwnPropSymbols$9(b)) {
2528
- if (__propIsEnum$9.call(b, prop))
2529
- __defNormalProp$8(a, prop, b[prop]);
2605
+ if (__hasOwnProp$a.call(b, prop))
2606
+ __defNormalProp$9(a, prop, b[prop]);
2607
+ if (__getOwnPropSymbols$a)
2608
+ for (var prop of __getOwnPropSymbols$a(b)) {
2609
+ if (__propIsEnum$a.call(b, prop))
2610
+ __defNormalProp$9(a, prop, b[prop]);
2530
2611
  }
2531
2612
  return a;
2532
2613
  };
2533
2614
  class TestVariable extends MultiValueVariable {
2534
2615
  constructor(initialState) {
2535
- super(__spreadValues$8({
2616
+ super(__spreadValues$9({
2536
2617
  type: "custom",
2537
2618
  name: "Test",
2538
2619
  value: "Value",
@@ -2611,25 +2692,25 @@ function VariableValueInput({ model }) {
2611
2692
  });
2612
2693
  }
2613
2694
 
2614
- var __defProp$7 = Object.defineProperty;
2615
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
2616
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
2617
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
2618
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2619
- var __spreadValues$7 = (a, b) => {
2695
+ var __defProp$8 = Object.defineProperty;
2696
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
2697
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
2698
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
2699
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2700
+ var __spreadValues$8 = (a, b) => {
2620
2701
  for (var prop in b || (b = {}))
2621
- if (__hasOwnProp$8.call(b, prop))
2622
- __defNormalProp$7(a, prop, b[prop]);
2623
- if (__getOwnPropSymbols$8)
2624
- for (var prop of __getOwnPropSymbols$8(b)) {
2625
- if (__propIsEnum$8.call(b, prop))
2626
- __defNormalProp$7(a, prop, b[prop]);
2702
+ if (__hasOwnProp$9.call(b, prop))
2703
+ __defNormalProp$8(a, prop, b[prop]);
2704
+ if (__getOwnPropSymbols$9)
2705
+ for (var prop of __getOwnPropSymbols$9(b)) {
2706
+ if (__propIsEnum$9.call(b, prop))
2707
+ __defNormalProp$8(a, prop, b[prop]);
2627
2708
  }
2628
2709
  return a;
2629
2710
  };
2630
2711
  class TextBoxVariable extends SceneObjectBase {
2631
2712
  constructor(initialState) {
2632
- super(__spreadValues$7({
2713
+ super(__spreadValues$8({
2633
2714
  type: "textbox",
2634
2715
  value: "",
2635
2716
  name: ""
@@ -2668,12 +2749,12 @@ class UrlSyncManager {
2668
2749
  constructor(sceneRoot) {
2669
2750
  this.sceneRoot = sceneRoot;
2670
2751
  this.urlKeyMapper = new UniqueUrlKeyMapper();
2671
- this.onLocationUpdate = (location) => {
2752
+ this._onLocationUpdate = (location) => {
2672
2753
  const urlParams = new URLSearchParams(location.search);
2673
2754
  this.urlKeyMapper.rebuldIndex(this.sceneRoot);
2674
- this.syncSceneStateFromUrl(this.sceneRoot, urlParams);
2755
+ this._syncSceneStateFromUrl(this.sceneRoot, urlParams);
2675
2756
  };
2676
- this.onStateChanged = ({ payload }) => {
2757
+ this._onStateChanged = ({ payload }) => {
2677
2758
  const changedObject = payload.changedObject;
2678
2759
  if (changedObject.urlSync) {
2679
2760
  const newUrlState = changedObject.urlSync.getUrlState();
@@ -2695,8 +2776,8 @@ class UrlSyncManager {
2695
2776
  }
2696
2777
  initSync() {
2697
2778
  this.sceneRoot.addActivationHandler(() => {
2698
- const stateChangeSub = this.sceneRoot.subscribeToEvent(SceneObjectStateChangedEvent, this.onStateChanged);
2699
- const locationListenerUnsub = runtime.locationService.getHistory().listen(this.onLocationUpdate);
2779
+ const stateChangeSub = this.sceneRoot.subscribeToEvent(SceneObjectStateChangedEvent, this._onStateChanged);
2780
+ const locationListenerUnsub = runtime.locationService.getHistory().listen(this._onLocationUpdate);
2700
2781
  return () => {
2701
2782
  stateChangeSub.unsubscribe();
2702
2783
  locationListenerUnsub();
@@ -2704,9 +2785,9 @@ class UrlSyncManager {
2704
2785
  });
2705
2786
  const urlParams = runtime.locationService.getSearch();
2706
2787
  this.urlKeyMapper.rebuldIndex(this.sceneRoot);
2707
- this.syncSceneStateFromUrl(this.sceneRoot, urlParams);
2788
+ this._syncSceneStateFromUrl(this.sceneRoot, urlParams);
2708
2789
  }
2709
- syncSceneStateFromUrl(sceneObject, urlParams) {
2790
+ _syncSceneStateFromUrl(sceneObject, urlParams) {
2710
2791
  if (sceneObject.urlSync) {
2711
2792
  const urlState = {};
2712
2793
  const currentState = sceneObject.urlSync.getUrlState();
@@ -2731,7 +2812,7 @@ class UrlSyncManager {
2731
2812
  sceneObject.urlSync.updateFromUrl(urlState);
2732
2813
  }
2733
2814
  }
2734
- forEachSceneObjectInState(sceneObject.state, (obj) => this.syncSceneStateFromUrl(obj, urlParams));
2815
+ sceneObject.forEachChild((child) => this._syncSceneStateFromUrl(child, urlParams));
2735
2816
  }
2736
2817
  }
2737
2818
  class UniqueUrlKeyMapper {
@@ -2765,7 +2846,7 @@ class UniqueUrlKeyMapper {
2765
2846
  }
2766
2847
  }
2767
2848
  }
2768
- forEachSceneObjectInState(sceneObject.state, (obj) => this.buildIndex(obj, depth + 1));
2849
+ sceneObject.forEachChild((child) => this.buildIndex(child, depth + 1));
2769
2850
  }
2770
2851
  }
2771
2852
  function isUrlValueEqual(currentUrlValue, newUrlValue) {
@@ -2829,24 +2910,23 @@ function getStyles$1(theme) {
2829
2910
  };
2830
2911
  }
2831
2912
 
2832
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
2833
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
2834
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
2913
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
2914
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
2915
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
2835
2916
  var __objRest = (source, exclude) => {
2836
2917
  var target = {};
2837
2918
  for (var prop in source)
2838
- if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
2919
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
2839
2920
  target[prop] = source[prop];
2840
- if (source != null && __getOwnPropSymbols$7)
2841
- for (var prop of __getOwnPropSymbols$7(source)) {
2842
- if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
2921
+ if (source != null && __getOwnPropSymbols$8)
2922
+ for (var prop of __getOwnPropSymbols$8(source)) {
2923
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
2843
2924
  target[prop] = source[prop];
2844
2925
  }
2845
2926
  return target;
2846
2927
  };
2847
2928
  function VizPanelRenderer({ model }) {
2848
2929
  var _b;
2849
- const theme = ui.useTheme2();
2850
2930
  const _a = model.useState(), {
2851
2931
  title,
2852
2932
  description,
@@ -2876,10 +2956,10 @@ function VizPanelRenderer({ model }) {
2876
2956
  const isDraggable = parentLayout.isDraggable() && ((_b = state.isDraggable) != null ? _b : true);
2877
2957
  const dragClass = isDraggable && parentLayout.getDragClass ? parentLayout.getDragClass() : "";
2878
2958
  const dragClassCancel = isDraggable && parentLayout.getDragClassCancel ? parentLayout.getDragClassCancel() : "";
2959
+ const rawData = sceneGraph.getData(model).useState();
2960
+ const dataWithFieldConfig = model.applyFieldConfig(rawData.data);
2879
2961
  const titleInterpolated = model.interpolate(title, void 0, "text");
2880
2962
  const timeZone = sceneGraph.getTimeRange(model).state.timeZone;
2881
- const { data: data$1 } = sceneGraph.getData(model).useState();
2882
- const dataWithOverrides = data.useFieldOverrides(plugin, fieldConfig, data$1, timeZone, theme, model.interpolate);
2883
2963
  if (pluginLoadError) {
2884
2964
  return /* @__PURE__ */ React__default["default"].createElement("div", null, "Failed to load plugin: ", pluginLoadError);
2885
2965
  }
@@ -2905,14 +2985,15 @@ function VizPanelRenderer({ model }) {
2905
2985
  model: menu
2906
2986
  });
2907
2987
  }
2988
+ const data$1 = dataWithFieldConfig;
2908
2989
  return /* @__PURE__ */ React__default["default"].createElement("div", {
2909
2990
  ref,
2910
2991
  style: { position: "absolute", width: "100%", height: "100%" }
2911
- }, /* @__PURE__ */ React__default["default"].createElement(ui.PanelChrome, {
2992
+ }, width > 0 && height > 0 && /* @__PURE__ */ React__default["default"].createElement(ui.PanelChrome, {
2912
2993
  title: titleInterpolated,
2913
2994
  description: description ? () => model.interpolate(description) : "",
2914
- loadingState: dataWithOverrides == null ? void 0 : dataWithOverrides.state,
2915
- statusMessage: (dataWithOverrides == null ? void 0 : dataWithOverrides.error) ? dataWithOverrides.error.message : "",
2995
+ loadingState: data$1.state,
2996
+ statusMessage: getChromeStatusMessage(data$1, pluginLoadError),
2916
2997
  width,
2917
2998
  height,
2918
2999
  displayMode,
@@ -2921,15 +3002,17 @@ function VizPanelRenderer({ model }) {
2921
3002
  dragClass,
2922
3003
  dragClassCancel,
2923
3004
  menu: panelMenu
2924
- }, (innerWidth, innerHeight) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, !dataWithOverrides && /* @__PURE__ */ React__default["default"].createElement("div", null, "No data..."), dataWithOverrides && /* @__PURE__ */ React__default["default"].createElement(ui.ErrorBoundaryAlert, {
3005
+ }, (innerWidth, innerHeight) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(ui.ErrorBoundaryAlert, {
2925
3006
  dependencies: [plugin, data$1]
2926
3007
  }, /* @__PURE__ */ React__default["default"].createElement(data.PluginContextProvider, {
2927
3008
  meta: plugin.meta
3009
+ }, /* @__PURE__ */ React__default["default"].createElement(ui.PanelContextProvider, {
3010
+ value: model.getPanelContext()
2928
3011
  }, /* @__PURE__ */ React__default["default"].createElement(PanelComponent, {
2929
3012
  id: 1,
2930
- data: dataWithOverrides,
3013
+ data: data$1,
2931
3014
  title,
2932
- timeRange: dataWithOverrides.timeRange,
3015
+ timeRange: data$1.timeRange,
2933
3016
  timeZone,
2934
3017
  options,
2935
3018
  fieldConfig,
@@ -2942,11 +3025,177 @@ function VizPanelRenderer({ model }) {
2942
3025
  onFieldConfigChange: model.onFieldConfigChange,
2943
3026
  onChangeTimeRange: model.onChangeTimeRange,
2944
3027
  eventBus: runtime.getAppEvents()
2945
- }))))));
3028
+ })))))));
3029
+ }
3030
+ function getChromeStatusMessage(data, pluginLoadingError) {
3031
+ if (pluginLoadingError) {
3032
+ return pluginLoadingError;
3033
+ }
3034
+ return data.error ? data.error.message : void 0;
3035
+ }
3036
+
3037
+ var __defProp$7 = Object.defineProperty;
3038
+ var __defProps$5 = Object.defineProperties;
3039
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
3040
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
3041
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
3042
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
3043
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3044
+ var __spreadValues$7 = (a, b) => {
3045
+ for (var prop in b || (b = {}))
3046
+ if (__hasOwnProp$7.call(b, prop))
3047
+ __defNormalProp$7(a, prop, b[prop]);
3048
+ if (__getOwnPropSymbols$7)
3049
+ for (var prop of __getOwnPropSymbols$7(b)) {
3050
+ if (__propIsEnum$7.call(b, prop))
3051
+ __defNormalProp$7(a, prop, b[prop]);
3052
+ }
3053
+ return a;
3054
+ };
3055
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
3056
+ const displayOverrideRef = "hideSeriesFrom";
3057
+ const isHideSeriesOverride = data.isSystemOverrideWithRef(displayOverrideRef);
3058
+ function seriesVisibilityConfigFactory(label, mode, fieldConfig, data) {
3059
+ const { overrides } = fieldConfig;
3060
+ const displayName = label;
3061
+ const currentIndex = overrides.findIndex(isHideSeriesOverride);
3062
+ if (currentIndex < 0) {
3063
+ if (mode === ui.SeriesVisibilityChangeMode.ToggleSelection) {
3064
+ const override3 = createOverride$1([displayName, ...getNamesOfHiddenFields(overrides, data)]);
3065
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3066
+ overrides: [...fieldConfig.overrides, override3]
3067
+ });
3068
+ }
3069
+ const displayNames = getDisplayNames(data, displayName);
3070
+ const override2 = createOverride$1(displayNames);
3071
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3072
+ overrides: [...fieldConfig.overrides, override2]
3073
+ });
3074
+ }
3075
+ const overridesCopy = Array.from(overrides);
3076
+ const [current] = overridesCopy.splice(currentIndex, 1);
3077
+ if (mode === ui.SeriesVisibilityChangeMode.ToggleSelection) {
3078
+ let existing = getExistingDisplayNames(current);
3079
+ const nameOfHiddenFields = getNamesOfHiddenFields(overridesCopy, data);
3080
+ if (nameOfHiddenFields.length > 0) {
3081
+ existing = existing.filter((el) => nameOfHiddenFields.indexOf(el) < 0);
3082
+ }
3083
+ if (existing[0] === displayName && existing.length === 1) {
3084
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3085
+ overrides: overridesCopy
3086
+ });
3087
+ }
3088
+ const override2 = createOverride$1([displayName, ...nameOfHiddenFields]);
3089
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3090
+ overrides: [...overridesCopy, override2]
3091
+ });
3092
+ }
3093
+ const override = createExtendedOverride(current, displayName);
3094
+ if (allFieldsAreExcluded(override, data)) {
3095
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3096
+ overrides: overridesCopy
3097
+ });
3098
+ }
3099
+ return __spreadProps$5(__spreadValues$7({}, fieldConfig), {
3100
+ overrides: [...overridesCopy, override]
3101
+ });
3102
+ }
3103
+ function createOverride$1(names, mode = data.ByNamesMatcherMode.exclude, property) {
3104
+ property = property != null ? property : {
3105
+ id: "custom.hideFrom",
3106
+ value: {
3107
+ viz: true,
3108
+ legend: false,
3109
+ tooltip: false
3110
+ }
3111
+ };
3112
+ return {
3113
+ __systemRef: displayOverrideRef,
3114
+ matcher: {
3115
+ id: data.FieldMatcherID.byNames,
3116
+ options: {
3117
+ mode,
3118
+ names,
3119
+ prefix: mode === data.ByNamesMatcherMode.exclude ? "All except:" : void 0,
3120
+ readOnly: true
3121
+ }
3122
+ },
3123
+ properties: [
3124
+ __spreadProps$5(__spreadValues$7({}, property), {
3125
+ value: {
3126
+ viz: true,
3127
+ legend: false,
3128
+ tooltip: false
3129
+ }
3130
+ })
3131
+ ]
3132
+ };
2946
3133
  }
2947
- VizPanelRenderer.displayName = "ScenePanelRenderer";
3134
+ const createExtendedOverride = (current, displayName, mode = data.ByNamesMatcherMode.exclude) => {
3135
+ const property = current.properties.find((p) => p.id === "custom.hideFrom");
3136
+ const existing = getExistingDisplayNames(current);
3137
+ const index = existing.findIndex((name) => name === displayName);
3138
+ if (index < 0) {
3139
+ existing.push(displayName);
3140
+ } else {
3141
+ existing.splice(index, 1);
3142
+ }
3143
+ return createOverride$1(existing, mode, property);
3144
+ };
3145
+ const getExistingDisplayNames = (rule) => {
3146
+ var _a;
3147
+ const names = (_a = rule.matcher.options) == null ? void 0 : _a.names;
3148
+ if (!Array.isArray(names)) {
3149
+ return [];
3150
+ }
3151
+ return [...names];
3152
+ };
3153
+ const allFieldsAreExcluded = (override, data) => {
3154
+ return getExistingDisplayNames(override).length === getDisplayNames(data).length;
3155
+ };
3156
+ const getDisplayNames = (data$1, excludeName) => {
3157
+ const unique = /* @__PURE__ */ new Set();
3158
+ for (const frame of data$1) {
3159
+ for (const field of frame.fields) {
3160
+ if (field.type !== data.FieldType.number) {
3161
+ continue;
3162
+ }
3163
+ const name = data.getFieldDisplayName(field, frame, data$1);
3164
+ if (name === excludeName) {
3165
+ continue;
3166
+ }
3167
+ unique.add(name);
3168
+ }
3169
+ }
3170
+ return Array.from(unique);
3171
+ };
3172
+ const getNamesOfHiddenFields = (overrides, data$1) => {
3173
+ var _a;
3174
+ let names = [];
3175
+ for (const override of overrides) {
3176
+ const property = override.properties.find((p) => p.id === "custom.hideFrom");
3177
+ if (property !== void 0 && ((_a = property.value) == null ? void 0 : _a.legend) === true) {
3178
+ const info = data.fieldMatchers.get(override.matcher.id);
3179
+ const matcher = info.get(override.matcher.options);
3180
+ for (const frame of data$1) {
3181
+ for (const field of frame.fields) {
3182
+ if (field.type !== data.FieldType.number) {
3183
+ continue;
3184
+ }
3185
+ const name = data.getFieldDisplayName(field, frame, data$1);
3186
+ if (matcher(field, frame, data$1)) {
3187
+ names.push(name);
3188
+ }
3189
+ }
3190
+ }
3191
+ }
3192
+ }
3193
+ return names;
3194
+ };
2948
3195
 
2949
3196
  var __defProp$6 = Object.defineProperty;
3197
+ var __defProps$4 = Object.defineProperties;
3198
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
2950
3199
  var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
2951
3200
  var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
2952
3201
  var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
@@ -2962,9 +3211,78 @@ var __spreadValues$6 = (a, b) => {
2962
3211
  }
2963
3212
  return a;
2964
3213
  };
3214
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3215
+ const changeSeriesColorConfigFactory = (label, color, fieldConfig) => {
3216
+ const { overrides } = fieldConfig;
3217
+ const currentIndex = fieldConfig.overrides.findIndex((override) => {
3218
+ return override.matcher.id === data.FieldMatcherID.byName && override.matcher.options === label;
3219
+ });
3220
+ if (currentIndex < 0) {
3221
+ return __spreadProps$4(__spreadValues$6({}, fieldConfig), {
3222
+ overrides: [...fieldConfig.overrides, createOverride(label, color)]
3223
+ });
3224
+ }
3225
+ const overridesCopy = Array.from(overrides);
3226
+ const existing = overridesCopy[currentIndex];
3227
+ const propertyIndex = existing.properties.findIndex((p) => p.id === "color");
3228
+ if (propertyIndex < 0) {
3229
+ overridesCopy[currentIndex] = __spreadProps$4(__spreadValues$6({}, existing), {
3230
+ properties: [...existing.properties, createProperty(color)]
3231
+ });
3232
+ return __spreadProps$4(__spreadValues$6({}, fieldConfig), {
3233
+ overrides: overridesCopy
3234
+ });
3235
+ }
3236
+ const propertiesCopy = Array.from(existing.properties);
3237
+ propertiesCopy[propertyIndex] = createProperty(color);
3238
+ overridesCopy[currentIndex] = __spreadProps$4(__spreadValues$6({}, existing), {
3239
+ properties: propertiesCopy
3240
+ });
3241
+ return __spreadProps$4(__spreadValues$6({}, fieldConfig), {
3242
+ overrides: overridesCopy
3243
+ });
3244
+ };
3245
+ const createOverride = (label, color) => {
3246
+ return {
3247
+ matcher: {
3248
+ id: data.FieldMatcherID.byName,
3249
+ options: label
3250
+ },
3251
+ properties: [createProperty(color)]
3252
+ };
3253
+ };
3254
+ const createProperty = (color) => {
3255
+ return {
3256
+ id: "color",
3257
+ value: {
3258
+ mode: data.FieldColorModeId.Fixed,
3259
+ fixedColor: color
3260
+ }
3261
+ };
3262
+ };
3263
+
3264
+ var __defProp$5 = Object.defineProperty;
3265
+ var __defProps$3 = Object.defineProperties;
3266
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
3267
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
3268
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
3269
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
3270
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3271
+ var __spreadValues$5 = (a, b) => {
3272
+ for (var prop in b || (b = {}))
3273
+ if (__hasOwnProp$5.call(b, prop))
3274
+ __defNormalProp$5(a, prop, b[prop]);
3275
+ if (__getOwnPropSymbols$5)
3276
+ for (var prop of __getOwnPropSymbols$5(b)) {
3277
+ if (__propIsEnum$5.call(b, prop))
3278
+ __defNormalProp$5(a, prop, b[prop]);
3279
+ }
3280
+ return a;
3281
+ };
3282
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
2965
3283
  class VizPanel extends SceneObjectBase {
2966
3284
  constructor(state) {
2967
- super(__spreadValues$6({
3285
+ super(__spreadValues$5({
2968
3286
  options: {},
2969
3287
  fieldConfig: { defaults: {}, overrides: [] },
2970
3288
  title: "Title",
@@ -2973,6 +3291,7 @@ class VizPanel extends SceneObjectBase {
2973
3291
  this._variableDependency = new VariableDependencyConfig(this, {
2974
3292
  statePaths: ["title", "options", "fieldConfig"]
2975
3293
  });
3294
+ this._structureRev = 0;
2976
3295
  this.onChangeTimeRange = (timeRange) => {
2977
3296
  const sceneTimeRange = sceneGraph.getTimeRange(this);
2978
3297
  sceneTimeRange.onTimeRangeChange({
@@ -2993,23 +3312,74 @@ class VizPanel extends SceneObjectBase {
2993
3312
  this.interpolate = (value, scoped, format) => {
2994
3313
  return sceneGraph.interpolate(this, value, scoped, format);
2995
3314
  };
3315
+ this._onSeriesColorChange = (label, color) => {
3316
+ this.onFieldConfigChange(changeSeriesColorConfigFactory(label, color, this.state.fieldConfig));
3317
+ };
3318
+ this._onSeriesVisibilityChange = (label, mode) => {
3319
+ if (!this._dataWithFieldConfig) {
3320
+ return;
3321
+ }
3322
+ this.onFieldConfigChange(
3323
+ seriesVisibilityConfigFactory(label, mode, this.state.fieldConfig, this._dataWithFieldConfig.series)
3324
+ );
3325
+ };
3326
+ this._onInstanceStateChange = (state) => {
3327
+ this.setState({ pluginInstanceState: state });
3328
+ };
3329
+ this._onToggleLegendSort = (sortKey) => {
3330
+ const legendOptions = this.state.options.legend;
3331
+ if (!legendOptions) {
3332
+ return;
3333
+ }
3334
+ let sortDesc = legendOptions.sortDesc;
3335
+ let sortBy = legendOptions.sortBy;
3336
+ if (sortKey !== sortBy) {
3337
+ sortDesc = void 0;
3338
+ }
3339
+ if (sortDesc === false) {
3340
+ sortBy = void 0;
3341
+ sortDesc = void 0;
3342
+ } else {
3343
+ sortDesc = !sortDesc;
3344
+ sortBy = sortKey;
3345
+ }
3346
+ this.onOptionsChange(__spreadProps$3(__spreadValues$5({}, this.state.options), {
3347
+ legend: __spreadProps$3(__spreadValues$5({}, legendOptions), { sortBy, sortDesc })
3348
+ }));
3349
+ };
3350
+ this._panelContext = {
3351
+ eventBus: runtime.getAppEvents(),
3352
+ app: data.CoreApp.Unknown,
3353
+ sync: () => data.DashboardCursorSync.Off,
3354
+ onSeriesColorChange: this._onSeriesColorChange,
3355
+ onToggleSeriesVisibility: this._onSeriesVisibilityChange,
3356
+ onToggleLegendSort: this._onToggleLegendSort,
3357
+ onInstanceStateChange: this._onInstanceStateChange
3358
+ };
3359
+ this.addActivationHandler(() => {
3360
+ this._onActivate();
3361
+ });
2996
3362
  }
2997
- activate() {
2998
- super.activate();
3363
+ _onActivate() {
3364
+ if (!this._plugin) {
3365
+ this._loadPlugin();
3366
+ }
3367
+ }
3368
+ _loadPlugin() {
2999
3369
  const { getPanelPluginFromCache, importPanelPlugin } = runtime.getPluginImportUtils();
3000
3370
  const plugin = getPanelPluginFromCache(this.state.pluginId);
3001
3371
  if (plugin) {
3002
- this.pluginLoaded(plugin);
3372
+ this._pluginLoaded(plugin);
3003
3373
  } else {
3004
- importPanelPlugin(this.state.pluginId).then((result) => this.pluginLoaded(result)).catch((err) => {
3374
+ importPanelPlugin(this.state.pluginId).then((result) => this._pluginLoaded(result)).catch((err) => {
3005
3375
  this.setState({ pluginLoadError: err.message });
3006
3376
  });
3007
3377
  }
3008
3378
  }
3009
- pluginLoaded(plugin) {
3379
+ _pluginLoaded(plugin) {
3010
3380
  const { options, fieldConfig, title, pluginId, pluginVersion } = this.state;
3011
3381
  const panel = { title, options, fieldConfig, id: 1, type: pluginId, pluginVersion };
3012
- const currentVersion = this.getPluginVersion(plugin);
3382
+ const currentVersion = this._getPluginVersion(plugin);
3013
3383
  if (plugin.onPanelMigration) {
3014
3384
  if (currentVersion !== this.state.pluginVersion) {
3015
3385
  panel.options = plugin.onPanelMigration(panel);
@@ -3028,12 +3398,40 @@ class VizPanel extends SceneObjectBase {
3028
3398
  pluginVersion: currentVersion
3029
3399
  });
3030
3400
  }
3031
- getPluginVersion(plugin) {
3401
+ _getPluginVersion(plugin) {
3032
3402
  return plugin && plugin.meta.info.version ? plugin.meta.info.version : runtime.config.buildInfo.version;
3033
3403
  }
3034
3404
  getPlugin() {
3035
3405
  return this._plugin;
3036
3406
  }
3407
+ getPanelContext() {
3408
+ return this._panelContext;
3409
+ }
3410
+ applyFieldConfig(rawData) {
3411
+ var _a, _b;
3412
+ const plugin = this._plugin;
3413
+ if (!plugin || plugin.meta.skipDataQuery || !rawData) {
3414
+ return emptyPanelData;
3415
+ }
3416
+ const fieldConfigRegistry = plugin.fieldConfigRegistry;
3417
+ const prevFrames = (_a = this._prevData) == null ? void 0 : _a.series;
3418
+ const newFrames = rawData == null ? void 0 : rawData.series;
3419
+ if (rawData.structureRev == null && newFrames && prevFrames && !data.compareArrayValues(newFrames, prevFrames, data.compareDataFrameStructures)) {
3420
+ this._structureRev++;
3421
+ }
3422
+ this._dataWithFieldConfig = __spreadProps$3(__spreadValues$5({}, rawData), {
3423
+ structureRev: this._structureRev,
3424
+ series: data.applyFieldOverrides({
3425
+ data: newFrames,
3426
+ fieldConfig: this.state.fieldConfig,
3427
+ fieldConfigRegistry,
3428
+ replaceVariables: this.interpolate,
3429
+ theme: runtime.config.theme2,
3430
+ timeZone: (_b = rawData.request) == null ? void 0 : _b.timezone
3431
+ })
3432
+ });
3433
+ return this._dataWithFieldConfig;
3434
+ }
3037
3435
  }
3038
3436
  VizPanel.Component = VizPanelRenderer;
3039
3437
 
@@ -3073,43 +3471,16 @@ function VizPanelMenuRenderer({ model }) {
3073
3471
  return /* @__PURE__ */ React__default["default"].createElement(ui.Menu, null, renderItems(items));
3074
3472
  }
3075
3473
 
3076
- var __defProp$5 = Object.defineProperty;
3077
- var __defProps$3 = Object.defineProperties;
3078
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
3079
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
3080
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
3081
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
3082
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3083
- var __spreadValues$5 = (a, b) => {
3084
- for (var prop in b || (b = {}))
3085
- if (__hasOwnProp$5.call(b, prop))
3086
- __defNormalProp$5(a, prop, b[prop]);
3087
- if (__getOwnPropSymbols$5)
3088
- for (var prop of __getOwnPropSymbols$5(b)) {
3089
- if (__propIsEnum$5.call(b, prop))
3090
- __defNormalProp$5(a, prop, b[prop]);
3091
- }
3092
- return a;
3093
- };
3094
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
3095
3474
  class NestedScene extends SceneObjectBase {
3096
3475
  constructor() {
3097
3476
  super(...arguments);
3098
3477
  this.onToggle = () => {
3099
3478
  this.setState({
3100
- isCollapsed: !this.state.isCollapsed,
3101
- placement: __spreadProps$3(__spreadValues$5({}, this.state.placement), {
3102
- ySizing: this.state.isCollapsed ? "fill" : "content"
3103
- })
3479
+ isCollapsed: !this.state.isCollapsed
3104
3480
  });
3105
3481
  };
3106
3482
  this.onRemove = () => {
3107
3483
  const parent = this.parent;
3108
- if ("children" in parent.state) {
3109
- parent.setState({
3110
- children: parent.state.children.filter((x) => x !== this)
3111
- });
3112
- }
3113
3484
  if (isSceneLayoutItem(parent)) {
3114
3485
  parent.setState({
3115
3486
  body: void 0
@@ -3197,7 +3568,6 @@ class SceneCanvasText extends SceneObjectBase {
3197
3568
  this._variableDependency = new VariableDependencyConfig(this, { statePaths: ["text"] });
3198
3569
  }
3199
3570
  }
3200
- SceneCanvasText.Editor = Editor;
3201
3571
  SceneCanvasText.Component = ({ model }) => {
3202
3572
  const { text, fontSize = 20, align = "left", key } = model.useState();
3203
3573
  const style = {
@@ -3213,16 +3583,6 @@ SceneCanvasText.Component = ({ model }) => {
3213
3583
  "data-testid": key
3214
3584
  }, sceneGraph.interpolate(model, text));
3215
3585
  };
3216
- function Editor({ model }) {
3217
- const { fontSize } = model.useState();
3218
- return /* @__PURE__ */ React__default["default"].createElement(ui.Field, {
3219
- label: "Font size"
3220
- }, /* @__PURE__ */ React__default["default"].createElement(ui.Input, {
3221
- type: "number",
3222
- defaultValue: fontSize,
3223
- onBlur: (evt) => model.setState({ fontSize: parseInt(evt.currentTarget.value, 10) })
3224
- }));
3225
- }
3226
3586
 
3227
3587
  class SceneToolbarButton extends SceneObjectBase {
3228
3588
  }