@grafana/scenes 0.10.0 → 0.11.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.
- package/CHANGELOG.md +16 -2
- package/dist/esm/variables/macros/index.js +5 -2
- package/dist/esm/variables/macros/index.js.map +1 -1
- package/dist/esm/variables/macros/timeMacros.js +15 -2
- package/dist/esm/variables/macros/timeMacros.js.map +1 -1
- package/dist/esm/variables/macros/urlMacros.js +54 -0
- package/dist/esm/variables/macros/urlMacros.js.map +1 -0
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# v0.11.0 (Tue May 23 2023)
|
|
2
|
+
|
|
3
|
+
#### 🚀 Enhancement
|
|
4
|
+
|
|
5
|
+
- Macros: Url macro [#199](https://github.com/grafana/scenes/pull/199) ([@torkelo](https://github.com/torkelo) [@dprokop](https://github.com/dprokop))
|
|
6
|
+
- Macros: Add __timezone macro [#200](https://github.com/grafana/scenes/pull/200) ([@dprokop](https://github.com/dprokop))
|
|
7
|
+
|
|
8
|
+
#### Authors: 2
|
|
9
|
+
|
|
10
|
+
- Dominik Prokop ([@dprokop](https://github.com/dprokop))
|
|
11
|
+
- Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
1
15
|
# v0.10.0 (Tue May 23 2023)
|
|
2
16
|
|
|
3
17
|
#### 🚀 Enhancement
|
|
@@ -73,7 +87,7 @@
|
|
|
73
87
|
|
|
74
88
|
You can now use multiple time zones in Scene. `SceneTimeRange` and `SceneTimePicker` respect time zone settings. Additionally, a new object was added, `SceneTimeZoneOverride`. It can be used to override the time zone provided by a time range object higher in the scene hierarchy. Objects within `SceneTimeZoneOverride` scope will use the closest `SceneTimeRange` range, but a locally specified time zone.
|
|
75
89
|
|
|
76
|
-
Example:
|
|
90
|
+
Example:
|
|
77
91
|
|
|
78
92
|
```ts
|
|
79
93
|
const scene = new EmbeddedScene({
|
|
@@ -85,7 +99,7 @@ const scene = new EmbeddedScene({
|
|
|
85
99
|
...
|
|
86
100
|
}),
|
|
87
101
|
// Will use global time range and locally specified time zone
|
|
88
|
-
new VizPanel({
|
|
102
|
+
new VizPanel({
|
|
89
103
|
$timeRange: new SceneTimeZoneOverride({ timeZone: 'America/New_York' }),
|
|
90
104
|
$data: new SceneQueryRunner({ ... }),
|
|
91
105
|
...
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DataLinkBuiltInVars } from '@grafana/data';
|
|
2
|
-
import { UrlTimeRangeMacro, TimeFromAndToMacro } from './timeMacros.js';
|
|
2
|
+
import { UrlTimeRangeMacro, TimeFromAndToMacro, TimezoneMacro } from './timeMacros.js';
|
|
3
3
|
import { AllVariablesMacro } from './AllVariablesMacro.js';
|
|
4
4
|
import { ValueMacro, DataMacro, SeriesMacro, FieldMacro } from './dataMacros.js';
|
|
5
|
+
import { UrlMacro } from './urlMacros.js';
|
|
5
6
|
|
|
6
7
|
const macrosIndex = {
|
|
7
8
|
[DataLinkBuiltInVars.includeVars]: AllVariablesMacro,
|
|
@@ -10,8 +11,10 @@ const macrosIndex = {
|
|
|
10
11
|
["__data"]: DataMacro,
|
|
11
12
|
["__series"]: SeriesMacro,
|
|
12
13
|
["__field"]: FieldMacro,
|
|
14
|
+
["__url"]: UrlMacro,
|
|
13
15
|
["__from"]: TimeFromAndToMacro,
|
|
14
|
-
["__to"]: TimeFromAndToMacro
|
|
16
|
+
["__to"]: TimeFromAndToMacro,
|
|
17
|
+
["__timezone"]: TimezoneMacro
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
export { macrosIndex };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { TimeFromAndToMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\n\nexport const macrosIndex: Record<string, MacroVariableConstructor> = {\n [DataLinkBuiltInVars.includeVars]: AllVariablesMacro,\n [DataLinkBuiltInVars.keepTime]: UrlTimeRangeMacro,\n ['__value']: ValueMacro,\n ['__data']: DataMacro,\n ['__series']: SeriesMacro,\n ['__field']: FieldMacro,\n ['__from']: TimeFromAndToMacro,\n ['__to']: TimeFromAndToMacro,\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\nimport { UrlMacro } from './urlMacros';\n\nexport const macrosIndex: Record<string, MacroVariableConstructor> = {\n [DataLinkBuiltInVars.includeVars]: AllVariablesMacro,\n [DataLinkBuiltInVars.keepTime]: UrlTimeRangeMacro,\n ['__value']: ValueMacro,\n ['__data']: DataMacro,\n ['__series']: SeriesMacro,\n ['__field']: FieldMacro,\n ['__url']: UrlMacro,\n ['__from']: TimeFromAndToMacro,\n ['__to']: TimeFromAndToMacro,\n ['__timezone']: TimezoneMacro,\n};\n"],"names":[],"mappings":";;;;;;AAOO,MAAM,WAAwD,GAAA;AAAA,EACnE,CAAC,oBAAoB,WAAc,GAAA,iBAAA;AAAA,EACnC,CAAC,oBAAoB,QAAW,GAAA,iBAAA;AAAA,EAChC,CAAC,SAAY,GAAA,UAAA;AAAA,EACb,CAAC,QAAW,GAAA,SAAA;AAAA,EACZ,CAAC,UAAa,GAAA,WAAA;AAAA,EACd,CAAC,SAAY,GAAA,UAAA;AAAA,EACb,CAAC,OAAU,GAAA,QAAA;AAAA,EACX,CAAC,QAAW,GAAA,kBAAA;AAAA,EACZ,CAAC,MAAS,GAAA,kBAAA;AAAA,EACV,CAAC,YAAe,GAAA,aAAA;AAClB;;;;"}
|
|
@@ -4,7 +4,7 @@ import { SkipFormattingValue } from './types.js';
|
|
|
4
4
|
|
|
5
5
|
class UrlTimeRangeMacro {
|
|
6
6
|
constructor(name, sceneObject) {
|
|
7
|
-
this.state = { name, type: "
|
|
7
|
+
this.state = { name, type: "url_variable" };
|
|
8
8
|
this._sceneObject = sceneObject;
|
|
9
9
|
}
|
|
10
10
|
getValue() {
|
|
@@ -39,6 +39,19 @@ class TimeFromAndToMacro {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
class TimezoneMacro {
|
|
43
|
+
constructor(name, sceneObject) {
|
|
44
|
+
this.state = { name, type: "time_macro" };
|
|
45
|
+
this._sceneObject = sceneObject;
|
|
46
|
+
}
|
|
47
|
+
getValue() {
|
|
48
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
49
|
+
return timeRange.getTimeZone();
|
|
50
|
+
}
|
|
51
|
+
getValueText() {
|
|
52
|
+
return this.getValue();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
42
55
|
|
|
43
|
-
export { TimeFromAndToMacro, UrlTimeRangeMacro };
|
|
56
|
+
export { TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro };
|
|
44
57
|
//# sourceMappingURL=timeMacros.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeMacros.js","sources":["../../../../src/variables/macros/timeMacros.ts"],"sourcesContent":["import { dateTimeFormat, urlUtil } from '@grafana/data';\nimport { getTimeRange } from '../../core/sceneGraph/getTimeRange';\nimport { SceneObject } from '../../core/types';\nimport { FormatVariable } from '../interpolation/formatRegistry';\nimport { SkipFormattingValue } from './types';\n\n/**\n * Handles expressions like $__url_time_range.\n */\nexport class UrlTimeRangeMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: '
|
|
1
|
+
{"version":3,"file":"timeMacros.js","sources":["../../../../src/variables/macros/timeMacros.ts"],"sourcesContent":["import { dateTimeFormat, urlUtil } from '@grafana/data';\nimport { getTimeRange } from '../../core/sceneGraph/getTimeRange';\nimport { SceneObject } from '../../core/types';\nimport { FormatVariable } from '../interpolation/formatRegistry';\nimport { SkipFormattingValue } from './types';\n\n/**\n * Handles expressions like $__url_time_range.\n */\nexport class UrlTimeRangeMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'url_variable' };\n this._sceneObject = sceneObject;\n }\n\n public getValue(): SkipFormattingValue {\n const timeRange = getTimeRange(this._sceneObject);\n const urlState = timeRange.urlSync?.getUrlState();\n return new SkipFormattingValue(urlUtil.toUrlParams(urlState));\n }\n\n public getValueText?(): string {\n return '';\n }\n}\n\n/**\n * Handles expressions like $__from and $__to.\n */\nexport class TimeFromAndToMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return timeRange.state.value.from.valueOf();\n } else {\n return timeRange.state.value.to.valueOf();\n }\n }\n\n public getValueText?(): string {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });\n } else {\n return dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });\n }\n }\n}\n\n/**\n * Handles $__timezone expression.\n */\nexport class TimezoneMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n return timeRange.getTimeZone();\n }\n\n public getValueText?(): string {\n return this.getValue();\n }\n}\n"],"names":[],"mappings":";;;;AASO,MAAM,iBAA4C,CAAA;AAAA,EAIhD,WAAA,CAAY,MAAc,WAA0B,EAAA;AACzD,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,IAAY,EAAA,IAAA,EAAM,cAAe,EAAA,CAAA;AAChD,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AAAA,GACtB;AAAA,EAEO,QAAgC,GAAA;AAlBzC,IAAA,IAAA,EAAA,CAAA;AAmBI,IAAM,MAAA,SAAA,GAAY,YAAa,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AAChD,IAAM,MAAA,QAAA,GAAA,CAAW,EAAU,GAAA,SAAA,CAAA,OAAA,KAAV,IAAmB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,WAAA,EAAA,CAAA;AACpC,IAAA,OAAO,IAAI,mBAAA,CAAoB,OAAQ,CAAA,WAAA,CAAY,QAAQ,CAAC,CAAA,CAAA;AAAA,GAC9D;AAAA,EAEO,YAAwB,GAAA;AAC7B,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AACF,CAAA;AAKO,MAAM,kBAA6C,CAAA;AAAA,EAIjD,WAAA,CAAY,MAAc,WAA0B,EAAA;AACzD,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,IAAY,EAAA,IAAA,EAAM,YAAa,EAAA,CAAA;AAC9C,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AAAA,GACtB;AAAA,EAEO,QAAW,GAAA;AAChB,IAAM,MAAA,SAAA,GAAY,YAAa,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AAChD,IAAI,IAAA,IAAA,CAAK,KAAM,CAAA,IAAA,KAAS,QAAU,EAAA;AAChC,MAAA,OAAO,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UrlMacro {
|
|
4
|
+
constructor(name, _) {
|
|
5
|
+
this.state = { name, type: "url_macro" };
|
|
6
|
+
}
|
|
7
|
+
getValue(fieldPath) {
|
|
8
|
+
const location = locationService.getLocation();
|
|
9
|
+
switch (fieldPath != null ? fieldPath : "") {
|
|
10
|
+
case "params":
|
|
11
|
+
return new UrlStateFormatter(location.search);
|
|
12
|
+
case "path":
|
|
13
|
+
return location.pathname;
|
|
14
|
+
case "":
|
|
15
|
+
default:
|
|
16
|
+
return location.pathname + location.search;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getValueText() {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class UrlStateFormatter {
|
|
24
|
+
constructor(_urlQueryParams) {
|
|
25
|
+
this._urlQueryParams = _urlQueryParams;
|
|
26
|
+
}
|
|
27
|
+
formatter(options) {
|
|
28
|
+
if (!options) {
|
|
29
|
+
return this._urlQueryParams;
|
|
30
|
+
}
|
|
31
|
+
const params = options.split(":");
|
|
32
|
+
if (params[0] === "exclude" && params.length > 1) {
|
|
33
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
34
|
+
for (const param of params[1].split(",")) {
|
|
35
|
+
allParams.delete(param);
|
|
36
|
+
}
|
|
37
|
+
return `?${allParams}`;
|
|
38
|
+
}
|
|
39
|
+
if (params[0] === "include" && params.length > 1) {
|
|
40
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
41
|
+
const includeOnly = params[1].split(",");
|
|
42
|
+
for (const param of allParams.keys()) {
|
|
43
|
+
if (!includeOnly.includes(param)) {
|
|
44
|
+
allParams.delete(param);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return `?${allParams}`;
|
|
48
|
+
}
|
|
49
|
+
return this._urlQueryParams;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { UrlMacro };
|
|
54
|
+
//# sourceMappingURL=urlMacros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlMacros.js","sources":["../../../../src/variables/macros/urlMacros.ts"],"sourcesContent":["import { locationService } from '@grafana/runtime';\nimport { SceneObject } from '../../core/types';\nimport { FormatVariable } from '../interpolation/formatRegistry';\nimport { CustomVariableValue } from '../types';\n\nexport class UrlMacro implements FormatVariable {\n public state: { name: string; type: string };\n\n public constructor(name: string, _: SceneObject) {\n this.state = { name: name, type: 'url_macro' };\n }\n\n public getValue(fieldPath?: string) {\n const location = locationService.getLocation();\n\n switch (fieldPath ?? '') {\n case 'params':\n return new UrlStateFormatter(location.search);\n case 'path':\n return location.pathname;\n case '':\n default:\n return location.pathname + location.search;\n }\n }\n\n public getValueText?(): string {\n return '';\n }\n}\n\nclass UrlStateFormatter implements CustomVariableValue {\n public constructor(private _urlQueryParams: string) {}\n\n public formatter(options: string): string {\n if (!options) {\n return this._urlQueryParams;\n }\n\n const params = options.split(':');\n if (params[0] === 'exclude' && params.length > 1) {\n const allParams = new URLSearchParams(this._urlQueryParams);\n for (const param of params[1].split(',')) {\n allParams.delete(param);\n }\n\n return `?${allParams}`;\n }\n\n if (params[0] === 'include' && params.length > 1) {\n const allParams = new URLSearchParams(this._urlQueryParams);\n const includeOnly = params[1].split(',');\n\n for (const param of allParams.keys()) {\n if (!includeOnly.includes(param)) {\n allParams.delete(param);\n }\n }\n\n return `?${allParams}`;\n }\n\n return this._urlQueryParams;\n }\n}\n"],"names":[],"mappings":";;AAKO,MAAM,QAAmC,CAAA;AAAA,EAGvC,WAAA,CAAY,MAAc,CAAgB,EAAA;AAC/C,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,IAAY,EAAA,IAAA,EAAM,WAAY,EAAA,CAAA;AAAA,GAC/C;AAAA,EAEO,SAAS,SAAoB,EAAA;AAClC,IAAM,MAAA,QAAA,GAAW,gBAAgB,WAAY,EAAA,CAAA;AAE7C,IAAA,QAAQ,SAAa,IAAA,IAAA,GAAA,SAAA,GAAA,EAAA;AAAA,MACd,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A;AAC1D,MAAA,MAAM,WAAc,GAAA,MAAA,CAAO,CAAG,CAAA,CAAA,KAAA,CAAM,GAAG,CAAA,CAAA;AAEvC,MAAW,KAAA,MAAA,KAAA,IAAS,SAAU,CAAA,IAAA,EAAQ,EAAA;AACpC,QAAA,IAAI,CAAC,WAAA,CAAY,QAAS,CAAA,KAAK,CAAG,EAAA;AAChC,UAAA,SAAA,CAAU,OAAO,KAAK,CAAA,CAAA;AAAA,SACxB;AAAA,OACF;AAEA,MAAA,OAAO,CAAI,CAAA,EAAA,SAAA,CAAA,CAAA,CAAA;AAAA,KACb;AAEA,IAAA,OAAO,IAAK,CAAA,eAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -977,7 +977,7 @@ class SkipFormattingValue {
|
|
|
977
977
|
|
|
978
978
|
class UrlTimeRangeMacro {
|
|
979
979
|
constructor(name, sceneObject) {
|
|
980
|
-
this.state = { name, type: "
|
|
980
|
+
this.state = { name, type: "url_variable" };
|
|
981
981
|
this._sceneObject = sceneObject;
|
|
982
982
|
}
|
|
983
983
|
getValue() {
|
|
@@ -1012,6 +1012,19 @@ class TimeFromAndToMacro {
|
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
1014
|
}
|
|
1015
|
+
class TimezoneMacro {
|
|
1016
|
+
constructor(name, sceneObject) {
|
|
1017
|
+
this.state = { name, type: "time_macro" };
|
|
1018
|
+
this._sceneObject = sceneObject;
|
|
1019
|
+
}
|
|
1020
|
+
getValue() {
|
|
1021
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
1022
|
+
return timeRange.getTimeZone();
|
|
1023
|
+
}
|
|
1024
|
+
getValueText() {
|
|
1025
|
+
return this.getValue();
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1015
1028
|
|
|
1016
1029
|
class AllVariablesMacro {
|
|
1017
1030
|
constructor(name, sceneObject) {
|
|
@@ -1232,6 +1245,56 @@ class FieldMacro {
|
|
|
1232
1245
|
}
|
|
1233
1246
|
}
|
|
1234
1247
|
|
|
1248
|
+
class UrlMacro {
|
|
1249
|
+
constructor(name, _) {
|
|
1250
|
+
this.state = { name, type: "url_macro" };
|
|
1251
|
+
}
|
|
1252
|
+
getValue(fieldPath) {
|
|
1253
|
+
const location = runtime.locationService.getLocation();
|
|
1254
|
+
switch (fieldPath != null ? fieldPath : "") {
|
|
1255
|
+
case "params":
|
|
1256
|
+
return new UrlStateFormatter(location.search);
|
|
1257
|
+
case "path":
|
|
1258
|
+
return location.pathname;
|
|
1259
|
+
case "":
|
|
1260
|
+
default:
|
|
1261
|
+
return location.pathname + location.search;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
getValueText() {
|
|
1265
|
+
return "";
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
class UrlStateFormatter {
|
|
1269
|
+
constructor(_urlQueryParams) {
|
|
1270
|
+
this._urlQueryParams = _urlQueryParams;
|
|
1271
|
+
}
|
|
1272
|
+
formatter(options) {
|
|
1273
|
+
if (!options) {
|
|
1274
|
+
return this._urlQueryParams;
|
|
1275
|
+
}
|
|
1276
|
+
const params = options.split(":");
|
|
1277
|
+
if (params[0] === "exclude" && params.length > 1) {
|
|
1278
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
1279
|
+
for (const param of params[1].split(",")) {
|
|
1280
|
+
allParams.delete(param);
|
|
1281
|
+
}
|
|
1282
|
+
return `?${allParams}`;
|
|
1283
|
+
}
|
|
1284
|
+
if (params[0] === "include" && params.length > 1) {
|
|
1285
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
1286
|
+
const includeOnly = params[1].split(",");
|
|
1287
|
+
for (const param of allParams.keys()) {
|
|
1288
|
+
if (!includeOnly.includes(param)) {
|
|
1289
|
+
allParams.delete(param);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return `?${allParams}`;
|
|
1293
|
+
}
|
|
1294
|
+
return this._urlQueryParams;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1235
1298
|
const macrosIndex = {
|
|
1236
1299
|
[data.DataLinkBuiltInVars.includeVars]: AllVariablesMacro,
|
|
1237
1300
|
[data.DataLinkBuiltInVars.keepTime]: UrlTimeRangeMacro,
|
|
@@ -1239,8 +1302,10 @@ const macrosIndex = {
|
|
|
1239
1302
|
["__data"]: DataMacro,
|
|
1240
1303
|
["__series"]: SeriesMacro,
|
|
1241
1304
|
["__field"]: FieldMacro,
|
|
1305
|
+
["__url"]: UrlMacro,
|
|
1242
1306
|
["__from"]: TimeFromAndToMacro,
|
|
1243
|
-
["__to"]: TimeFromAndToMacro
|
|
1307
|
+
["__to"]: TimeFromAndToMacro,
|
|
1308
|
+
["__timezone"]: TimezoneMacro
|
|
1244
1309
|
};
|
|
1245
1310
|
|
|
1246
1311
|
function sceneInterpolator(sceneObject, target, scopedVars, format) {
|