UNPKG

5.01 kBJavaScriptView Raw
1import { a as __extends, _ as __assign } from './tslib.es6-863e3717.js';
2import { U as Utils } from './Utils-5f9f1f09.js';
3import 'd3';
4import 'moment-timezone';
5import { C as ChartDataOptions } from './ChartDataOptions-a1b69faa.js';
6
7var TsqExpression = /** @class */ (function (_super) {
8 __extends(TsqExpression, _super);
9 function TsqExpression(instanceObject, variableObject, searchSpan, colorOrOptionsObject, alias, contextMenu) {
10 var _this = this;
11 // This constructor should be called with the following parameters:
12 // new TsqExpression(instanceObject, variableObject, searchSpan, optionsObject)
13 // where the optionsObject should contain properties for color, alias, and contextMenu.
14 //
15 // However, to maintain backwards compatibility with older code, the constructor still
16 // accepts the older set of parameters:
17 // new TsqExpression(instanceObject, variableObject, searchSpan, color, alias, contextMenu)
18 // Here we differentiate between both and call the parent class's constructor as appropriate.
19 var optionsObject = (typeof (colorOrOptionsObject) === 'object' && !!colorOrOptionsObject)
20 ? __assign(__assign({}, colorOrOptionsObject), { searchSpan: searchSpan, measureTypes: Object.keys(variableObject) }) : {
21 color: colorOrOptionsObject,
22 searchSpan: searchSpan,
23 measureTypes: Object.keys(variableObject),
24 alias: alias,
25 contextMenu: contextMenu
26 };
27 _this = _super.call(this, optionsObject) || this;
28 _this.instanceObject = instanceObject;
29 _this.variableObject = variableObject;
30 return _this;
31 }
32 TsqExpression.prototype.toTsq = function (roundFromTo, getEvents, getSeries) {
33 if (roundFromTo === void 0) { roundFromTo = false; }
34 if (getEvents === void 0) { getEvents = false; }
35 if (getSeries === void 0) { getSeries = false; }
36 var tsq = {};
37 var shiftMillis = Utils.parseShift(this.timeShift, this.startAt, this.searchSpan);
38 var fromMillis = this.searchSpan.from.valueOf() + shiftMillis;
39 var toMillis = this.searchSpan.to.valueOf() + shiftMillis;
40 if (roundFromTo) {
41 var bucketSizeInMillis = Utils.parseTimeInput(this.searchSpan.bucketSize);
42 var roundedFromMillis = Math.floor((fromMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
43 var roundedToMillis = Math.ceil((toMillis + 62135596800000) / (bucketSizeInMillis)) * (bucketSizeInMillis) - 62135596800000;
44 fromMillis = roundedFromMillis;
45 toMillis = roundedToMillis;
46 }
47 tsq['searchSpan'] = { from: (new Date(fromMillis)).toISOString(), to: (new Date(toMillis)).toISOString() };
48 tsq['timeSeriesId'] = this.instanceObject.timeSeriesId;
49 if (getEvents) {
50 return { getEvents: tsq };
51 }
52 else if (getSeries) {
53 tsq['inlineVariables'] = __assign({}, this.variableObject);
54 tsq['projectedVariables'] = Object.keys(this.variableObject);
55 return { getSeries: tsq };
56 }
57 else {
58 tsq['interval'] = Utils.bucketSizeToTsqInterval(this.searchSpan.bucketSize);
59 tsq['inlineVariables'] = __assign({}, this.variableObject);
60 tsq['projectedVariables'] = Object.keys(this.variableObject);
61 return { aggregateSeries: tsq };
62 }
63 };
64 // This method will create an API query payload for the variable statistics of the first inline variable
65 // of this object, for numeric dataTypes. Categorical types work as expected.
66 TsqExpression.prototype.toStatsTsq = function (fromMillis, toMillis) {
67 var tsq = this.toTsq();
68 var shiftMillis = Utils.parseShift(this.timeShift);
69 fromMillis += shiftMillis;
70 toMillis += shiftMillis;
71 tsq.aggregateSeries['searchSpan'] = { from: (new Date(fromMillis)).toISOString(), to: (new Date(toMillis)).toISOString() };
72 tsq.aggregateSeries['interval'] = 'P1000Y';
73 if (this.dataType === 'numeric') {
74 var inlineVariables_1 = { min: {}, max: {}, avg: {}, stDev: {} };
75 var firstVariable_1 = tsq.aggregateSeries['inlineVariables'][Object.keys(tsq.aggregateSeries['inlineVariables'])[0]];
76 Object.keys(inlineVariables_1).forEach(function (k) {
77 inlineVariables_1[k] = JSON.parse(JSON.stringify(firstVariable_1));
78 inlineVariables_1[k].aggregation.tsx = k + "($value)";
79 delete inlineVariables_1[k]['interpolation'];
80 });
81 tsq.aggregateSeries['inlineVariables'] = inlineVariables_1;
82 tsq.aggregateSeries['projectedVariables'] = Object.keys(inlineVariables_1);
83 }
84 return tsq;
85 };
86 return TsqExpression;
87}(ChartDataOptions));
88
89export default TsqExpression;