1 | import { event, format, select, scaleSequential, interpolateCubehelixDefault, hcl, scaleLinear } from 'd3';
|
2 | import moment from 'moment-timezone';
|
3 |
|
4 | var KeyCodes;
|
5 | (function (KeyCodes) {
|
6 | KeyCodes[KeyCodes["Tab"] = 9] = "Tab";
|
7 | KeyCodes[KeyCodes["Esc"] = 27] = "Esc";
|
8 | KeyCodes[KeyCodes["Enter"] = 13] = "Enter";
|
9 | KeyCodes[KeyCodes["Up"] = 38] = "Up";
|
10 | KeyCodes[KeyCodes["Down"] = 40] = "Down";
|
11 | })(KeyCodes || (KeyCodes = {}));
|
12 |
|
13 | var InstancesSort;
|
14 | (function (InstancesSort) {
|
15 | InstancesSort["DisplayName"] = "DisplayName";
|
16 | InstancesSort["Rank"] = "Rank";
|
17 | })(InstancesSort || (InstancesSort = {}));
|
18 | var HierarchiesExpand;
|
19 | (function (HierarchiesExpand) {
|
20 | HierarchiesExpand["UntilChildren"] = "UntilChildren";
|
21 | HierarchiesExpand["OneLevel"] = "OneLevel";
|
22 | })(HierarchiesExpand || (HierarchiesExpand = {}));
|
23 | var HierarchiesSort;
|
24 | (function (HierarchiesSort) {
|
25 | HierarchiesSort["Name"] = "Name";
|
26 | HierarchiesSort["CumulativeInstanceCount"] = "CumulativeInstanceCount";
|
27 | })(HierarchiesSort || (HierarchiesSort = {}));
|
28 | var MetadataPropertyTypes;
|
29 | (function (MetadataPropertyTypes) {
|
30 | MetadataPropertyTypes["Double"] = "Double";
|
31 | MetadataPropertyTypes["String"] = "String";
|
32 | MetadataPropertyTypes["DateTime"] = "DateTime";
|
33 | MetadataPropertyTypes["Long"] = "Long";
|
34 | })(MetadataPropertyTypes || (MetadataPropertyTypes = {}));
|
35 | var ShiftTypes;
|
36 | (function (ShiftTypes) {
|
37 | ShiftTypes["startAt"] = "Start at";
|
38 | ShiftTypes["shifted"] = "shifted";
|
39 | })(ShiftTypes || (ShiftTypes = {}));
|
40 | var InterpolationFunctions;
|
41 | (function (InterpolationFunctions) {
|
42 | InterpolationFunctions["None"] = "";
|
43 | InterpolationFunctions["CurveLinear"] = "curveLinear";
|
44 | InterpolationFunctions["CurveStep"] = "curveStep";
|
45 | InterpolationFunctions["CurveStepBefore"] = "curveStepBefore";
|
46 | InterpolationFunctions["CurveStepAfter"] = "curveStepAfter";
|
47 | InterpolationFunctions["CurveBasis"] = "curveBasis";
|
48 | InterpolationFunctions["CurveCardinal"] = "curveCardinal";
|
49 | InterpolationFunctions["CurveMonotoneX"] = "curveMonotoneX";
|
50 | InterpolationFunctions["CurveCatmullRom"] = "curveCatmullRom";
|
51 | })(InterpolationFunctions || (InterpolationFunctions = {}));
|
52 | var ErrorCodes;
|
53 | (function (ErrorCodes) {
|
54 | ErrorCodes["InvalidInput"] = "InvalidInput";
|
55 | ErrorCodes["PartialSuccess"] = "PartialSuccess";
|
56 | })(ErrorCodes || (ErrorCodes = {}));
|
57 |
|
58 | var YAxisStates;
|
59 | (function (YAxisStates) {
|
60 | YAxisStates["Stacked"] = "stacked";
|
61 | YAxisStates["Shared"] = "shared";
|
62 | YAxisStates["Overlap"] = "overlap";
|
63 | })(YAxisStates || (YAxisStates = {}));
|
64 | var DataTypes;
|
65 | (function (DataTypes) {
|
66 | DataTypes["Numeric"] = "numeric";
|
67 | DataTypes["Categorical"] = "categorical";
|
68 | DataTypes["Events"] = "events";
|
69 | })(DataTypes || (DataTypes = {}));
|
70 | var EventElementTypes;
|
71 | (function (EventElementTypes) {
|
72 | EventElementTypes["Diamond"] = "diamond";
|
73 | EventElementTypes["Teardrop"] = "teardrop";
|
74 | })(EventElementTypes || (EventElementTypes = {}));
|
75 | var TooltipMeasureFormat;
|
76 | (function (TooltipMeasureFormat) {
|
77 | TooltipMeasureFormat["Enveloped"] = "Enveloped";
|
78 | TooltipMeasureFormat["SingleValue"] = "SingleValue";
|
79 | TooltipMeasureFormat["Scatter"] = "Scatter";
|
80 | })(TooltipMeasureFormat || (TooltipMeasureFormat = {}));
|
81 | var valueTypes;
|
82 | (function (valueTypes) {
|
83 | valueTypes["String"] = "String";
|
84 | valueTypes["Double"] = "Double";
|
85 | valueTypes["Long"] = "Long";
|
86 | valueTypes["Dynamic"] = "Dynamic";
|
87 | valueTypes["Boolean"] = "Boolean";
|
88 | valueTypes["DateTime"] = "DateTime";
|
89 | })(valueTypes || (valueTypes = {}));
|
90 |
|
91 | var DefaultHierarchyNavigationOptions = {
|
92 | instancesPageSize: 10,
|
93 | hierarchiesPageSize: 10,
|
94 | isInstancesRecursive: false,
|
95 | isInstancesHighlighted: false,
|
96 | instancesSort: InstancesSort.DisplayName,
|
97 | hierarchiesExpand: HierarchiesExpand.OneLevel,
|
98 | hierarchiesSort: HierarchiesSort.Name
|
99 | };
|
100 | var nullTsidDisplayString = "null";
|
101 | var swimlaneLabelConstants = {
|
102 | leftMarginOffset: 40,
|
103 | swimLaneLabelHeightPadding: 8,
|
104 | labelLeftPadding: 28
|
105 | };
|
106 | var CharactersToEscapeForExactSearchInstance = ['"', '`', '\'', '!', '(', ')', '^', '[', '{', ':', ']', '}', '~', '/', '\\', '@', '#', '$', '%', '&', '*', ';', '=', '.', '_', '-', '<', '>', ',', '?'];
|
107 | var NONNUMERICTOPMARGIN = 8;
|
108 | var LINECHARTTOPPADDING = 16;
|
109 | var GRIDCONTAINERCLASS = 'tsi-gridContainer';
|
110 | var LINECHARTCHARTMARGINS = {
|
111 | top: 40,
|
112 | bottom: 40,
|
113 | left: 70,
|
114 | right: 60
|
115 | };
|
116 | var LINECHARTXOFFSET = 8;
|
117 | var MARKERVALUENUMERICHEIGHT = 20;
|
118 | var VALUEBARHEIGHT = 3;
|
119 | var SERIESLABELWIDTH = 92;
|
120 |
|
121 | var Utils = (function () {
|
122 | function Utils() {
|
123 | }
|
124 | Utils.formatYAxisNumber = function (val) {
|
125 | if (Math.abs(val) < 1000000) {
|
126 | if (Math.abs(val) < .0000001)
|
127 | return format('.2n')(val);
|
128 | else {
|
129 |
|
130 | var formatted = format(',.7r')(val);
|
131 | if (formatted.indexOf('.') != -1) {
|
132 | var lastChar = formatted[formatted.length - 1];
|
133 | while (lastChar == '0') {
|
134 | formatted = formatted.slice(0, -1);
|
135 | lastChar = formatted[formatted.length - 1];
|
136 | }
|
137 | if (lastChar == '.')
|
138 | formatted = formatted.slice(0, -1);
|
139 | }
|
140 | return formatted;
|
141 | }
|
142 | }
|
143 | else if (Math.abs(val) >= 1000000 && Math.abs(val) < 1000000000)
|
144 | return format('.3s')(val);
|
145 | else if (Math.abs(val) >= 1000000000 && Math.abs(val) < 1000000000000)
|
146 | return format('.3s')(val).slice(0, -1) + 'B';
|
147 | return format('.2n')(val);
|
148 | };
|
149 | Utils.getStackStates = function () {
|
150 | return YAxisStates;
|
151 | };
|
152 |
|
153 | Utils.parseTimeInput = function (inputString) {
|
154 | inputString = inputString.toLowerCase();
|
155 | var getNumber = function (inputString, charsFromEnd) {
|
156 | var startAt = inputString.indexOf('pt') !== -1 ? 2 : (inputString.indexOf('p') !== -1 ? 1 : 0);
|
157 | return Number(inputString.slice(startAt, inputString.length - charsFromEnd));
|
158 | };
|
159 | if (inputString.indexOf('ms') == inputString.length - 2) {
|
160 | return getNumber(inputString, 2);
|
161 | }
|
162 | if (inputString.indexOf('s') == inputString.length - 1) {
|
163 | return getNumber(inputString, 1) * 1000;
|
164 | }
|
165 | if (inputString.indexOf('m') == inputString.length - 1) {
|
166 | return getNumber(inputString, 1) * 60 * 1000;
|
167 | }
|
168 | if (inputString.indexOf('h') == inputString.length - 1) {
|
169 | return getNumber(inputString, 1) * 60 * 60 * 1000;
|
170 | }
|
171 | if (inputString.indexOf('d') == inputString.length - 1) {
|
172 | return getNumber(inputString, 1) * 24 * 60 * 60 * 1000;
|
173 | }
|
174 | return -1;
|
175 | };
|
176 | Utils.findClosestTime = function (prevMillis, timeMap) {
|
177 | var minDistance = Infinity;
|
178 | var closestValue = null;
|
179 | Object.keys(timeMap).forEach(function (intervalCenterString) {
|
180 | var intervalCenter = Number(intervalCenterString);
|
181 | if (Math.abs(intervalCenter - prevMillis) < minDistance) {
|
182 | minDistance = Math.abs(intervalCenter - prevMillis);
|
183 | closestValue = intervalCenter;
|
184 | }
|
185 | });
|
186 | return closestValue;
|
187 | };
|
188 | Utils.getValueOfVisible = function (d, visibleMeasure) {
|
189 | if (d.measures) {
|
190 | if (d.measures[visibleMeasure] != null || d.measures[visibleMeasure] != undefined)
|
191 | return d.measures[visibleMeasure];
|
192 | }
|
193 | return null;
|
194 | };
|
195 | Utils.isStartAt = function (startAtString, searchSpan) {
|
196 | if (startAtString === void 0) { startAtString = null; }
|
197 | if (searchSpan === void 0) { searchSpan = null; }
|
198 | return (startAtString !== null && searchSpan !== null && searchSpan.from !== null);
|
199 | };
|
200 | Utils.parseShift = function (shiftString, startAtString, searchSpan) {
|
201 | if (startAtString === void 0) { startAtString = null; }
|
202 | if (searchSpan === void 0) { searchSpan = null; }
|
203 | if (this.isStartAt(startAtString, searchSpan)) {
|
204 | return (new Date(startAtString)).valueOf() - (new Date(searchSpan.from)).valueOf();
|
205 | }
|
206 | if (shiftString === undefined || shiftString === null || shiftString.length === 0) {
|
207 | return 0;
|
208 | }
|
209 | var millis;
|
210 | if (shiftString[0] === '-' || shiftString[0] === '+') {
|
211 | millis = (shiftString[0] === '-' ? -1 : 1) * this.parseTimeInput(shiftString.slice(1, shiftString.length));
|
212 | }
|
213 | else {
|
214 | millis = this.parseTimeInput(shiftString);
|
215 | }
|
216 | return -millis;
|
217 | };
|
218 | Utils.adjustStartMillisToAbsoluteZero = function (fromMillis, bucketSize) {
|
219 | var epochAdjustment = 62135596800000;
|
220 | return Math.floor((fromMillis + epochAdjustment) / bucketSize) * bucketSize - epochAdjustment;
|
221 | };
|
222 | Utils.bucketSizeToTsqInterval = function (bucketSize) {
|
223 | if (!bucketSize) {
|
224 | return null;
|
225 | }
|
226 | var bucketSizeInMillis = Utils.parseTimeInput(bucketSize);
|
227 | var padLeadingZeroes = function (number) {
|
228 | var numberAsString = String(number);
|
229 | if (numberAsString.length < 3)
|
230 | numberAsString = (numberAsString.length === 2 ? '0' : '00') + numberAsString;
|
231 | return numberAsString;
|
232 | };
|
233 | if (bucketSizeInMillis < 1000) {
|
234 | bucketSize = (bucketSize.toLowerCase().indexOf('d') !== -1) ? 'd.' : '.' + padLeadingZeroes(bucketSizeInMillis) + "s";
|
235 | }
|
236 | var prefix = bucketSize.toLowerCase().indexOf('d') !== -1 ? 'P' : 'PT';
|
237 | return (prefix + bucketSize).toUpperCase();
|
238 | };
|
239 | Utils.createEntityKey = function (aggName, aggIndex) {
|
240 | return encodeURIComponent(aggName).split(".").join("_") + "_" + aggIndex;
|
241 | };
|
242 | Utils.getColorForValue = function (chartDataOptions, value) {
|
243 | if (chartDataOptions.valueMapping && (chartDataOptions.valueMapping[value] !== undefined)) {
|
244 | return chartDataOptions.valueMapping[value].color;
|
245 | }
|
246 | return null;
|
247 | };
|
248 | Utils.rollUpContiguous = function (data) {
|
249 | var areEquivalentBuckets = function (d1, d2) {
|
250 | if (!d1.measures || !d2.measures) {
|
251 | return false;
|
252 | }
|
253 | if (Object.keys(d1.measures).length !== Object.keys(d2.measures).length) {
|
254 | return false;
|
255 | }
|
256 | return Object.keys(d1.measures).reduce(function (p, c, i) {
|
257 | return p && (d1.measures[c] === d2.measures[c]);
|
258 | }, true);
|
259 | };
|
260 | return data.filter(function (d, i) {
|
261 | if (i !== 0) {
|
262 | return !areEquivalentBuckets(d, data[i - 1]);
|
263 | }
|
264 | return true;
|
265 | });
|
266 | };
|
267 | Utils.formatOffsetMinutes = function (offset) {
|
268 | return (offset < 0 ? '-' : '+') +
|
269 | Math.floor(offset / 60) + ':' +
|
270 | (offset % 60 < 10 ? '0' : '') + (offset % 60) + '';
|
271 | };
|
272 | Utils.getOffsetMinutes = function (offset, millis) {
|
273 | if (offset == 'Local') {
|
274 | return -moment.tz.zone(moment.tz.guess()).parse(millis);
|
275 | }
|
276 | if (typeof offset == 'string' && isNaN(offset)) {
|
277 | return -moment.tz.zone(offset).parse(millis);
|
278 | }
|
279 | else {
|
280 | return offset;
|
281 | }
|
282 | };
|
283 | Utils.offsetUTC = function (date) {
|
284 | var offsettedDate = new Date(date.valueOf() - date.getTimezoneOffset() * 60 * 1000);
|
285 | return offsettedDate;
|
286 | };
|
287 |
|
288 | Utils.getMinutesToUTC = function (offset, millisInOffset) {
|
289 | if (offset == 'Local') {
|
290 | return moment.tz.zone(moment.tz.guess()).utcOffset(millisInOffset);
|
291 | }
|
292 | if (typeof offset == 'string' && isNaN(offset)) {
|
293 | return moment.tz.zone(offset).utcOffset(millisInOffset);
|
294 | }
|
295 | else {
|
296 | return -offset;
|
297 | }
|
298 | };
|
299 | Utils.addOffsetGuess = function (timezoneName) {
|
300 | var timezone = moment.tz(new Date(), timezoneName.split(' ').join('_'));
|
301 | var formatted = timezone.format('Z');
|
302 | return "UTC" + formatted;
|
303 | };
|
304 | Utils.timezoneAbbreviation = function (timezoneName) {
|
305 | var abbr = moment.tz(new Date(), timezoneName).format('z');
|
306 | if (abbr[0] === '-' || abbr[0] === '+')
|
307 | return '';
|
308 | return abbr;
|
309 | };
|
310 | Utils.createTimezoneAbbreviation = function (offset) {
|
311 | var timezone = Utils.parseTimezoneName(offset);
|
312 | var timezoneAbbreviation = Utils.timezoneAbbreviation(timezone);
|
313 | return (timezoneAbbreviation.length !== 0 ? timezoneAbbreviation : Utils.addOffsetGuess(timezone));
|
314 | };
|
315 | Utils.parseTimezoneName = function (timezoneRaw) {
|
316 | if (!isNaN(timezoneRaw)) {
|
317 | if (timezoneRaw === 0) {
|
318 | return 'UTC';
|
319 | }
|
320 | return '';
|
321 | }
|
322 | if (timezoneRaw == 'Local') {
|
323 | return moment.tz.guess();
|
324 | }
|
325 | return timezoneRaw !== null ? timezoneRaw.split(' ').join('_') : '';
|
326 | };
|
327 | Utils.convertTimezoneToLabel = function (timezone, locdLocal) {
|
328 | if (locdLocal === void 0) { locdLocal = 'Local'; }
|
329 | var timezoneName = this.parseTimezoneName(timezone);
|
330 | var localPrefix = '';
|
331 | var offsetPrefix = '';
|
332 | if (timezone == 'Local') {
|
333 | localPrefix = locdLocal + ' - ';
|
334 | }
|
335 | if (timezone !== 'UTC') {
|
336 | offsetPrefix = ' (' + this.addOffsetGuess(timezoneName) + ')';
|
337 | }
|
338 | var timezoneAbbreviation = this.timezoneAbbreviation(timezoneName);
|
339 | var timezoneSuffix = (timezoneAbbreviation && timezoneAbbreviation.length !== 0 && timezoneAbbreviation !== 'UTC') ? ': ' + timezoneAbbreviation : '';
|
340 | return offsetPrefix + " " + localPrefix + timezoneName.replace(/_/g, ' ') + timezoneSuffix;
|
341 | };
|
342 | Utils.rangeTimeFormat = function (rangeMillis) {
|
343 | var oneSecond = 1000;
|
344 | var oneMinute = 60 * 1000;
|
345 | var oneHour = oneMinute * 60;
|
346 | var oneDay = oneHour * 24;
|
347 | var days = Math.floor(rangeMillis / oneDay);
|
348 | var hours = Math.floor(rangeMillis / oneHour) % 24;
|
349 | var minutes = Math.floor(rangeMillis / oneMinute) % 60;
|
350 | var seconds = Math.floor(rangeMillis / oneSecond) % 60;
|
351 | var millis = Math.floor(rangeMillis % 1000);
|
352 | if (rangeMillis >= oneDay) {
|
353 | return days + "d " + (hours > 0 ? (hours + "h") : "");
|
354 | }
|
355 | else if (rangeMillis >= oneHour) {
|
356 | return hours + "h " + (minutes > 0 ? (minutes + "m") : "");
|
357 | }
|
358 | else if (rangeMillis >= oneMinute) {
|
359 | return minutes + "m " + (seconds > 0 ? (seconds + "s") : "");
|
360 | }
|
361 | else if (rangeMillis >= oneSecond) {
|
362 | return seconds + (millis != 0 ? "." + millis : "") + "s";
|
363 | }
|
364 | return millis + "ms";
|
365 | };
|
366 | Utils.subDateTimeFormat = function (is24HourTime, usesSeconds, usesMillis) {
|
367 | return (is24HourTime ? "HH" : "hh") + ":mm" + (usesSeconds ? (":ss" + (usesMillis ? ".SSS" : "")) : "") + (is24HourTime ? "" : " A");
|
368 | };
|
369 | Utils.timeFormat = function (usesSeconds, usesMillis, offset, is24HourTime, shiftMillis, timeFormat, locale) {
|
370 | var _this = this;
|
371 | if (usesSeconds === void 0) { usesSeconds = false; }
|
372 | if (usesMillis === void 0) { usesMillis = false; }
|
373 | if (offset === void 0) { offset = 0; }
|
374 | if (is24HourTime === void 0) { is24HourTime = true; }
|
375 | if (shiftMillis === void 0) { shiftMillis = null; }
|
376 | if (timeFormat === void 0) { timeFormat = null; }
|
377 | if (locale === void 0) { locale = 'en'; }
|
378 | return function (d) {
|
379 | if (shiftMillis !== 0) {
|
380 | d = new Date(d.valueOf() + shiftMillis);
|
381 | }
|
382 | var stringFormat;
|
383 | if (timeFormat !== null) {
|
384 | stringFormat = timeFormat;
|
385 | }
|
386 | else {
|
387 | stringFormat = "L " + _this.subDateTimeFormat(is24HourTime, usesSeconds, usesMillis);
|
388 | }
|
389 | if (typeof offset == 'string' && isNaN(offset)) {
|
390 | return moment.tz(d, 'UTC').tz(offset === 'Local' ? moment.tz.guess() : offset).locale(locale).format(stringFormat);
|
391 | }
|
392 | else {
|
393 | return moment.tz(d, "UTC").utcOffset(offset).locale(locale).format(stringFormat);
|
394 | }
|
395 | };
|
396 | };
|
397 | Utils.splitTimeLabel = function (text) {
|
398 | var shouldSplit = function (str) {
|
399 | var splitLines = str.split(' ');
|
400 | return !((splitLines.length === 1) || (splitLines.length === 2 && (splitLines[1] === 'AM' || splitLines[1] === 'PM')));
|
401 | };
|
402 | text.each(function () {
|
403 | if (this.children == undefined || this.children.length == 0) {
|
404 | var text = select(this);
|
405 | var lines = text.text().split(" ");
|
406 | var dy = parseFloat(text.attr("dy"));
|
407 | if (shouldSplit(text.text())) {
|
408 | var newFirstLine = lines[0] + (lines.length === 3 ? (' ' + lines[1]) : '');
|
409 | var newSecondLine = lines[lines.length - 1];
|
410 | text.text(null).append("tspan")
|
411 | .attr("x", 0)
|
412 | .attr("y", text.attr("y"))
|
413 | .attr("dy", dy + "em")
|
414 | .text(newFirstLine);
|
415 | text.append("tspan")
|
416 | .attr("x", 0)
|
417 | .attr("y", text.attr("y"))
|
418 | .attr("dy", (dy + dy * 1.4) + "em")
|
419 | .text(newSecondLine);
|
420 | }
|
421 | }
|
422 | });
|
423 | };
|
424 | Utils.getUTCHours = function (d, is24HourTime) {
|
425 | if (is24HourTime === void 0) { is24HourTime = true; }
|
426 | var hours = d.getUTCHours();
|
427 | if (!is24HourTime) {
|
428 | if (hours == 0)
|
429 | hours = 12;
|
430 | if (hours > 12)
|
431 | hours = hours - 12;
|
432 | }
|
433 | return hours;
|
434 | };
|
435 | Utils.UTCTwelveHourFormat = function (d) {
|
436 | var hours = String(this.getUTCHours(d));
|
437 | var minutes = (d.getUTCMinutes() < 10 ? "0" : "") + String(d.getUTCMinutes());
|
438 | var amPm = (d.getUTCHours() < 12) ? "AM" : "PM";
|
439 | return hours + ":" + minutes + " " + amPm;
|
440 | };
|
441 | Utils.getAgVisible = function (displayState, aggI, splitBy) {
|
442 | return (displayState[aggI].visible) ? displayState[aggI].splitBys[splitBy].visible : false;
|
443 | };
|
444 | Utils.getAgVisibleMeasure = function (displayState, aggI, splitBy) {
|
445 | return displayState[aggI].splitBys[splitBy].visibleType;
|
446 | };
|
447 | Utils.createSeriesTypeIcon = function (seriesType, selection) {
|
448 | var g = selection.append("g")
|
449 | .style("position", "absolute");
|
450 | if (seriesType == "event") {
|
451 | g.attr("transform", "translate(7.5,0)")
|
452 | .append("rect")
|
453 | .attr("width", 7)
|
454 | .attr("height", 7)
|
455 | .attr("transform", "rotate(45)");
|
456 | }
|
457 | else if (seriesType == "state") {
|
458 | g.append("rect")
|
459 | .attr("width", 15)
|
460 | .attr("height", 10);
|
461 | }
|
462 | else {
|
463 | g.append("path")
|
464 | .attr("d", "M0 5 Q 4 0, 8 5 T 16 5")
|
465 | .attr("fill", "none");
|
466 | }
|
467 | };
|
468 | Utils.strip = function (text) {
|
469 | var div = document.createElement('div');
|
470 | div.innerHTML = text;
|
471 | var textContent = div.textContent || div.innerText || '';
|
472 | return textContent;
|
473 | };
|
474 | Utils.stripForConcat = function (text) {
|
475 | var specialCharacters = ['"', "'", '?', '<', '>', ';'];
|
476 | specialCharacters.forEach(function (c) { text = text.split(c).join(''); });
|
477 | return text;
|
478 | };
|
479 | Utils.setSeriesLabelSubtitleText = function (subtitle, isInFocus) {
|
480 | if (isInFocus === void 0) { isInFocus = false; }
|
481 | var subtitleDatum = subtitle.data()[0];
|
482 | if (!subtitle.select('.tsi-splitBy').empty()) {
|
483 | var textAfterSplitByExists = subtitleDatum.timeShift !== '' || subtitleDatum.variableAlias;
|
484 | var splitByString = "" + subtitleDatum.splitBy + ((textAfterSplitByExists && !isInFocus) ? ', ' : '');
|
485 | Utils.appendFormattedElementsFromString(subtitle.select('.tsi-splitBy'), splitByString);
|
486 | }
|
487 | if (subtitle.select('.tsi-timeShift')) {
|
488 | subtitle.select('.tsi-timeShift')
|
489 | .text(function (d) {
|
490 | return "" + subtitleDatum.timeShift + ((subtitleDatum.variableAlias && !isInFocus) ? ', ' : '');
|
491 | });
|
492 | }
|
493 | if (subtitle.select('.tsi-variableAlias')) {
|
494 | subtitle.select('.tsi-variableAlias')
|
495 | .text(function (d) { return subtitleDatum.variableAlias; });
|
496 | }
|
497 | };
|
498 | Utils.revertAllSubtitleText = function (markerValues, opacity) {
|
499 | if (opacity === void 0) { opacity = 1; }
|
500 | var self = this;
|
501 | markerValues.classed('tsi-isExpanded', false)
|
502 | .style('opacity', opacity)
|
503 | .each(function () {
|
504 | self.setSeriesLabelSubtitleText(select(this).selectAll('.tsi-tooltipSubtitle'), false);
|
505 | });
|
506 | };
|
507 | Utils.generateColors = function (numColors, includeColors) {
|
508 | if (includeColors === void 0) { includeColors = null; }
|
509 | var defaultColors = ['#008272', '#D869CB', '#FF8C00', '#8FE6D7', '#3195E3', '#F7727E', '#E0349E', '#C8E139', '#60B9AE',
|
510 | '#93CFFB', '#854CC7', '#258225', '#0078D7', '#FF2828', '#FFF100'];
|
511 | var postDefaultColors = scaleSequential(interpolateCubehelixDefault).domain([defaultColors.length - .5, numColors - .5]);
|
512 | var colors = [];
|
513 | var colorsIndex = 0;
|
514 | if (includeColors) {
|
515 | for (var i = 0; i < includeColors.length && colorsIndex < numColors; i++) {
|
516 | var color = includeColors[i];
|
517 | if (colors.indexOf(color) === -1) {
|
518 | colors.push(color);
|
519 | colorsIndex++;
|
520 | }
|
521 | }
|
522 | }
|
523 | for (var i = 0; colorsIndex < numColors; i++) {
|
524 | if (i < defaultColors.length) {
|
525 | if (colors.indexOf(defaultColors[i]) === -1) {
|
526 | colors.push(defaultColors[i]);
|
527 | colorsIndex++;
|
528 | }
|
529 | }
|
530 | else if (colors.indexOf(postDefaultColors(i)) === -1) {
|
531 | colors.push(postDefaultColors(i));
|
532 | colorsIndex++;
|
533 | }
|
534 | }
|
535 | return colors;
|
536 | };
|
537 | Utils.convertFromLocal = function (date) {
|
538 | return new Date(date.valueOf() - date.getTimezoneOffset() * 60 * 1000);
|
539 | };
|
540 | Utils.adjustDateFromTimezoneOffset = function (date) {
|
541 | var dateCopy = new Date(date.valueOf());
|
542 | dateCopy.setTime(dateCopy.getTime() + dateCopy.getTimezoneOffset() * 60 * 1000);
|
543 | return dateCopy;
|
544 | };
|
545 | Utils.offsetFromUTC = function (date, offset) {
|
546 | if (offset === void 0) { offset = 0; }
|
547 | var offsetMinutes = Utils.getOffsetMinutes(offset, date.valueOf());
|
548 | var dateCopy = new Date(date.valueOf() + offsetMinutes * 60 * 1000);
|
549 | return dateCopy;
|
550 | };
|
551 | Utils.offsetToUTC = function (date, offset) {
|
552 | if (offset === void 0) { offset = 0; }
|
553 | var offsetMinutes = Utils.getOffsetMinutes(offset, date.valueOf());
|
554 | var dateCopy = new Date(date.valueOf() - offsetMinutes * 60 * 1000);
|
555 | return dateCopy;
|
556 | };
|
557 | Utils.parseUserInputDateTime = function (timeText, offset) {
|
558 | var dateTimeFormat = "L " + this.subDateTimeFormat(true, true, true);
|
559 | var parsedDate = moment(timeText, dateTimeFormat).toDate();
|
560 | var utcDate = this.offsetToUTC(this.convertFromLocal(parsedDate), offset);
|
561 | return utcDate.valueOf();
|
562 | };
|
563 | Utils.getBrighterColor = function (color) {
|
564 | var hclColor = hcl(color);
|
565 | if (hclColor.l < 80) {
|
566 | return hclColor.brighter().toString();
|
567 | }
|
568 | return hclColor.toString();
|
569 | };
|
570 | Utils.createSplitByColors = function (displayState, aggKey, ignoreIsOnlyAgg) {
|
571 | if (ignoreIsOnlyAgg === void 0) { ignoreIsOnlyAgg = false; }
|
572 | if (Object.keys(displayState[aggKey]["splitBys"]).length == 1)
|
573 | return [displayState[aggKey].color];
|
574 | var isOnlyAgg = Object.keys(displayState).reduce(function (accum, currAgg) {
|
575 | if (currAgg == aggKey)
|
576 | return accum;
|
577 | if (displayState[currAgg]["visible"] == false)
|
578 | return accum && true;
|
579 | return false;
|
580 | }, true);
|
581 | if (isOnlyAgg && !ignoreIsOnlyAgg) {
|
582 | return this.generateColors(Object.keys(displayState[aggKey]["splitBys"]).length);
|
583 | }
|
584 | var aggColor = displayState[aggKey].color;
|
585 | var interpolateColor = scaleLinear().domain([0, Object.keys(displayState[aggKey]["splitBys"]).length])
|
586 | .range([hcl(aggColor).darker(), hcl(aggColor).brighter()]);
|
587 | var colors = [];
|
588 | for (var i = 0; i < Object.keys(displayState[aggKey]["splitBys"]).length; i++) {
|
589 | colors.push(interpolateColor(i));
|
590 | }
|
591 | return colors;
|
592 | };
|
593 | Utils.colorSplitBy = function (displayState, splitByIndex, aggKey, ignoreIsOnlyAgg) {
|
594 | if (ignoreIsOnlyAgg === void 0) { ignoreIsOnlyAgg = false; }
|
595 | if (Object.keys(displayState[aggKey]["splitBys"]).length == 1)
|
596 | return displayState[aggKey].color;
|
597 | var isOnlyAgg = Object.keys(displayState).reduce(function (accum, currAgg) {
|
598 | if (currAgg == aggKey)
|
599 | return accum;
|
600 | if (displayState[currAgg]["visible"] == false)
|
601 | return accum && true;
|
602 | return false;
|
603 | }, true);
|
604 | if (isOnlyAgg && !ignoreIsOnlyAgg) {
|
605 | var splitByColors = this.generateColors(Object.keys(displayState[aggKey]["splitBys"]).length);
|
606 | return splitByColors[splitByIndex];
|
607 | }
|
608 | var aggColor = displayState[aggKey].color;
|
609 | var interpolateColor = scaleLinear().domain([0, Object.keys(displayState[aggKey]["splitBys"]).length])
|
610 | .range([hcl(aggColor).darker(), hcl(aggColor).brighter()]);
|
611 | return interpolateColor(splitByIndex);
|
612 | };
|
613 | Utils.getTheme = function (theme) {
|
614 | return theme ? 'tsi-' + theme : 'tsi-dark';
|
615 | };
|
616 | Utils.clearSelection = function () {
|
617 | var sel = window.getSelection ? window.getSelection() : document.selection;
|
618 | if (sel) {
|
619 | if (sel.removeAllRanges) {
|
620 | sel.removeAllRanges();
|
621 | }
|
622 | else if (sel.empty) {
|
623 | sel.empty();
|
624 | }
|
625 | }
|
626 | };
|
627 | Utils.mark = function (filter, text) {
|
628 | if (filter.length == 0)
|
629 | return text;
|
630 | var regExp = new RegExp(filter, 'gi');
|
631 | return text.replace(regExp, function (m) { return '<mark>' + m + '</mark>'; });
|
632 | };
|
633 | Utils.hash = function (str) {
|
634 | var hash = 5381, i = str.length;
|
635 | while (i) {
|
636 | hash = (hash * 33) ^ str.charCodeAt(--i);
|
637 | }
|
638 | |
639 |
|
640 |
|
641 | return hash >>> 0;
|
642 | };
|
643 | Utils.guid = function () {
|
644 | var s4 = function () {
|
645 | return Math.floor((1 + Math.random()) * 0x10000)
|
646 | .toString(16)
|
647 | .substring(1);
|
648 | };
|
649 | return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
650 | s4() + '-' + s4() + s4() + s4();
|
651 | };
|
652 | Utils.createValueFilter = function (aggregateKey, splitBy) {
|
653 | return function (d, j) {
|
654 | var currAggKey;
|
655 | var currSplitBy;
|
656 | if (d.aggregateKey) {
|
657 | currAggKey = d.aggregateKey;
|
658 | currSplitBy = d.splitBy;
|
659 | }
|
660 | else if (d && d.length) {
|
661 | currAggKey = d[0].aggregateKey;
|
662 | currSplitBy = d[0].splitBy;
|
663 | }
|
664 | else
|
665 | return true;
|
666 | return (currAggKey == aggregateKey && (splitBy == null || splitBy == currSplitBy));
|
667 | };
|
668 | };
|
669 | Utils.downloadCSV = function (csvString, csvName) {
|
670 | if (csvName === void 0) { csvName = "Table"; }
|
671 | var blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' });
|
672 | var blobURL = window.URL.createObjectURL(blob);
|
673 | var link = document.createElement("a");
|
674 | link.setAttribute("href", blobURL);
|
675 | link.setAttribute("download", csvName + ".csv");
|
676 | link.setAttribute("tabindex", "0");
|
677 | link.innerHTML = "";
|
678 | document.body.appendChild(link);
|
679 | link.click();
|
680 | };
|
681 | Utils.sanitizeString = function (str, type) {
|
682 | if (str === null || str === undefined) {
|
683 | return "";
|
684 | }
|
685 | if (type !== valueTypes.Double && type !== valueTypes.Long) {
|
686 | var jsonifiedString = type === valueTypes.Dynamic ? JSON.stringify(str) : String(str);
|
687 | if (jsonifiedString.indexOf(',') !== -1 || jsonifiedString.indexOf('"') !== -1 || jsonifiedString.indexOf('\n') !== -1 || type === valueTypes.Dynamic) {
|
688 | var replacedString = jsonifiedString.replace(/"/g, '""');
|
689 | return '"' + replacedString + '"';
|
690 | }
|
691 | }
|
692 | return str;
|
693 | };
|
694 | Utils.focusOnEllipsisButton = function (renderTarget) {
|
695 | var ellipsisContainer = select(renderTarget).select(".tsi-ellipsisContainerDiv");
|
696 | if (!ellipsisContainer.empty()) {
|
697 | ellipsisContainer.select(".tsi-ellipsisButton").node().focus();
|
698 | }
|
699 | };
|
700 | Utils.createDownloadEllipsisOption = function (csvStringGenerator, action, downloadLabel) {
|
701 | if (action === void 0) { action = function () { }; }
|
702 | if (downloadLabel === void 0) { downloadLabel = "Download as CSV"; }
|
703 | return {
|
704 | iconClass: "download",
|
705 | label: downloadLabel,
|
706 | action: function () {
|
707 | Utils.downloadCSV(csvStringGenerator());
|
708 | action();
|
709 | },
|
710 | description: ""
|
711 | };
|
712 | };
|
713 | Utils.createControlPanel = function (renderTarget, legendWidth, topChartMargin, chartOptions) {
|
714 | select(renderTarget).selectAll(".tsi-chartControlsPanel").remove();
|
715 | var controlPanelWidth = Math.max(1, select(renderTarget).node().clientWidth -
|
716 | (chartOptions.legend == "shown" ? legendWidth : 0));
|
717 | var chartControlsPanel = select(renderTarget).append("div")
|
718 | .attr("class", "tsi-chartControlsPanel")
|
719 | .style("width", controlPanelWidth + "px")
|
720 | .style("top", Math.max((topChartMargin - 32), 0) + "px");
|
721 | return chartControlsPanel;
|
722 | };
|
723 | Utils.escapeQuotesCommasAndNewlines = function (stringToEscape) {
|
724 | var escapedString = "";
|
725 | if (stringToEscape && (stringToEscape.indexOf("\"") != -1 ||
|
726 | stringToEscape.indexOf(",") != -1 ||
|
727 | stringToEscape.indexOf("\n") != -1)) {
|
728 | stringToEscape = stringToEscape.replace(/"/g, "\"\"");
|
729 | escapedString += "\"";
|
730 | escapedString += stringToEscape;
|
731 | escapedString += "\"";
|
732 | return escapedString;
|
733 | }
|
734 | else {
|
735 | return stringToEscape;
|
736 | }
|
737 | };
|
738 | Utils.getNonNumericHeight = function (rawHeight) {
|
739 | return rawHeight + NONNUMERICTOPMARGIN;
|
740 | };
|
741 | Utils.getControlPanelWidth = function (renderTarget, legendWidth, isLegendShown) {
|
742 | return Math.max(1, select(renderTarget).node().clientWidth -
|
743 | (isLegendShown ? legendWidth : 0));
|
744 | };
|
745 | Utils.getValueOrDefault = function (chartOptionsObj, propertyName, defaultValue) {
|
746 | if (defaultValue === void 0) { defaultValue = null; }
|
747 | var propertyValue = chartOptionsObj[propertyName];
|
748 | if (propertyValue == undefined) {
|
749 | if (this[propertyName] == undefined)
|
750 | return defaultValue;
|
751 | return this[propertyName];
|
752 | }
|
753 | return propertyValue;
|
754 | };
|
755 | Utils.safeNotNullOrUndefined = function (valueLambda) {
|
756 | try {
|
757 | var value = valueLambda();
|
758 | return !(value === null || value === undefined);
|
759 | }
|
760 | catch (err) {
|
761 | return false;
|
762 | }
|
763 | };
|
764 | Utils.getAggKeys = function (data) {
|
765 | var aggregateCounterMap = {};
|
766 | return data.map(function (aggregate) {
|
767 | var aggName = Object.keys(aggregate)[0];
|
768 | var aggKey;
|
769 | if (aggregateCounterMap[aggName]) {
|
770 | aggKey = Utils.createEntityKey(aggName, aggregateCounterMap[aggName]);
|
771 | aggregateCounterMap[aggName] += 1;
|
772 | }
|
773 | else {
|
774 | aggKey = Utils.createEntityKey(aggName, 0);
|
775 | aggregateCounterMap[aggName] = 1;
|
776 | }
|
777 | return aggKey;
|
778 | });
|
779 | };
|
780 | Utils.roundToMillis = function (rawTo, bucketSize) {
|
781 | return Math.ceil((rawTo + 62135596800000) / (bucketSize)) * (bucketSize) - 62135596800000;
|
782 | };
|
783 | Utils.mergeSeriesForScatterPlot = function (chartData, scatterMeasures) {
|
784 | var _a;
|
785 | var _this = this;
|
786 | var xMeasure = chartData[scatterMeasures.X_MEASURE], yMeasure = chartData[scatterMeasures.Y_MEASURE], rMeasure = chartData[scatterMeasures.R_MEASURE];
|
787 | var measureNames = Utils.getScatterPlotMeasureNames(chartData, scatterMeasures);
|
788 |
|
789 | var xLabel = xMeasure.additionalFields.Variable.substring(0, 15) + (xMeasure.additionalFields.Variable.length > 15 ? "... vs" : " vs");
|
790 | var yLabel = " " + yMeasure.additionalFields.Variable.substring(0, 15) + (yMeasure.additionalFields.Variable.length > 15 ? "... " : "");
|
791 | var rLabel = (rMeasure != null ? " vs " + rMeasure.additionalFields.Variable.substring(0, 15) + (rMeasure.additionalFields.Variable.length > 15 ? "... " : "") : "");
|
792 | var dataTitle = xLabel + yLabel + rLabel;
|
793 |
|
794 | var scatterData = (_a = {},
|
795 | _a[dataTitle] = {
|
796 | "": {}
|
797 | },
|
798 | _a);
|
799 |
|
800 | var measureTypes = {
|
801 | X_MEASURE_TYPE: 'avg' in xMeasure.measureTypes ? xMeasure.measureTypes['avg'] : xMeasure.measureTypes[0],
|
802 | Y_MEASURE_TYPE: 'avg' in yMeasure.measureTypes ? yMeasure.measureTypes['avg'] : yMeasure.measureTypes[0],
|
803 | R_MEASURE_TYPE: null
|
804 | };
|
805 |
|
806 | var normalizeTimestampKeys = function (query) {
|
807 | var newTS = {};
|
808 | Object.keys(query.data[query.alias][""]).forEach(function (key) {
|
809 | var oldTime = new Date(key).valueOf();
|
810 | var timeShift = query.timeShift != "" ? _this.parseShift(query.timeShift, query.startAt, query.searchSpan) : 0;
|
811 |
|
812 | var bucketShiftInMillis = _this.adjustStartMillisToAbsoluteZero(timeShift, _this.parseShift(query.searchSpan.bucketSize));
|
813 | var normalizedTime = oldTime - bucketShiftInMillis;
|
814 | var timestamp = new Date(normalizedTime).toISOString();
|
815 | newTS[timestamp] = query.data[query.alias][""][key];
|
816 | });
|
817 | return newTS;
|
818 | };
|
819 |
|
820 | xMeasure.data[xMeasure.alias][""] = normalizeTimestampKeys(xMeasure);
|
821 | yMeasure.data[yMeasure.alias][""] = normalizeTimestampKeys(yMeasure);
|
822 | if (rMeasure) {
|
823 | rMeasure.data[rMeasure.alias][""] = normalizeTimestampKeys(rMeasure);
|
824 | measureTypes.R_MEASURE_TYPE = 'avg' in rMeasure.measureTypes ? rMeasure.measureTypes['avg'] : rMeasure.measureTypes[0];
|
825 | }
|
826 |
|
827 | Object.keys(xMeasure.data[xMeasure.alias][""]).forEach(function (key) {
|
828 | if (key in yMeasure.data[yMeasure.alias][""]) {
|
829 | var measures = {};
|
830 | measures[measureNames.X_MEASURE] = xMeasure.data[xMeasure.alias][""][key][measureTypes.X_MEASURE_TYPE];
|
831 | measures[measureNames.Y_MEASURE] = yMeasure.data[yMeasure.alias][""][key][measureTypes.Y_MEASURE_TYPE];
|
832 |
|
833 | if (rMeasure != null && key in rMeasure.data[rMeasure.alias][""]) {
|
834 | measures[measureNames.R_MEASURE] = rMeasure.data[rMeasure.alias][""][key][measureTypes.R_MEASURE_TYPE];
|
835 | }
|
836 |
|
837 | if (xMeasure.data[xMeasure.alias][""][key][measureTypes.X_MEASURE_TYPE] && yMeasure.data[yMeasure.alias][""][key][measureTypes.Y_MEASURE_TYPE]) {
|
838 | if (rMeasure != null) {
|
839 | if (key in rMeasure.data[rMeasure.alias][""] && rMeasure.data[rMeasure.alias][""][key][measureTypes.R_MEASURE_TYPE])
|
840 | scatterData[dataTitle][""][key] = measures;
|
841 | }
|
842 | else {
|
843 | scatterData[dataTitle][""][key] = measures;
|
844 | }
|
845 | }
|
846 | }
|
847 | });
|
848 | return scatterData;
|
849 | };
|
850 | Utils.getScatterPlotMeasureNames = function (chartData, scatterMeasures) {
|
851 | var uniqueNameMap = {};
|
852 | var xMeasureName = chartData[scatterMeasures.X_MEASURE].alias + " " + chartData[scatterMeasures.X_MEASURE].additionalFields.Variable +
|
853 | (chartData[scatterMeasures.X_MEASURE].timeShift == "" ? "" : " " + chartData[scatterMeasures.X_MEASURE].timeShift);
|
854 | uniqueNameMap[xMeasureName] = 1;
|
855 | var yMeasureName = chartData[scatterMeasures.Y_MEASURE].alias + " " + chartData[scatterMeasures.Y_MEASURE].additionalFields.Variable +
|
856 | (chartData[scatterMeasures.Y_MEASURE].timeShift == "" ? "" : " " + chartData[scatterMeasures.Y_MEASURE].timeShift);
|
857 | if (yMeasureName in uniqueNameMap) {
|
858 | var tempName = yMeasureName;
|
859 | yMeasureName += " (" + uniqueNameMap[yMeasureName].toString() + ")";
|
860 | uniqueNameMap[tempName] = uniqueNameMap[tempName] + 1;
|
861 | }
|
862 | else {
|
863 | uniqueNameMap[yMeasureName] = 1;
|
864 | }
|
865 | var rMeasureName = chartData[scatterMeasures.R_MEASURE] ? chartData[scatterMeasures.R_MEASURE].alias + " " + chartData[scatterMeasures.R_MEASURE].additionalFields.Variable +
|
866 | (chartData[scatterMeasures.R_MEASURE].timeShift == "" ? "" : " " + chartData[scatterMeasures.R_MEASURE].timeShift) : null;
|
867 | if (rMeasureName != null) {
|
868 | if (rMeasureName in uniqueNameMap) {
|
869 | rMeasureName += " (" + uniqueNameMap[rMeasureName].toString() + ")";
|
870 | }
|
871 | }
|
872 | return {
|
873 | X_MEASURE: xMeasureName,
|
874 | Y_MEASURE: yMeasureName,
|
875 | R_MEASURE: rMeasureName ? rMeasureName : null
|
876 | };
|
877 | };
|
878 | Utils.getMinWarmTime = function (warmStoreFrom, retentionString) {
|
879 | var minWarmTime = new Date(warmStoreFrom);
|
880 | if (retentionString !== null) {
|
881 | var retentionPeriod = Utils.parseTimeInput(retentionString);
|
882 | minWarmTime = new Date(Math.max(minWarmTime.valueOf(), (Date.now() - retentionPeriod)));
|
883 | }
|
884 | return minWarmTime;
|
885 | };
|
886 | Utils.standardizeTSStrings = function (rawData) {
|
887 | var convertedData = [];
|
888 | rawData.forEach(function (dG, i) {
|
889 | var dGName = Object.keys(dG)[0];
|
890 | var dataGroup = dG[dGName];
|
891 | var convertedDataGroup = {};
|
892 | var dataGroupKeyedObject = {};
|
893 | dataGroupKeyedObject[dGName] = convertedDataGroup;
|
894 | convertedData.push(dataGroupKeyedObject);
|
895 | if (dataGroup) {
|
896 | Object.keys(dataGroup).forEach(function (seriesName) {
|
897 | convertedDataGroup[seriesName] = {};
|
898 | if (dataGroup[seriesName]) {
|
899 | Object.keys(dataGroup[seriesName]).forEach(function (rawTS) {
|
900 | var isoString;
|
901 | try {
|
902 | isoString = (new Date(rawTS)).toISOString();
|
903 | convertedDataGroup[seriesName][isoString] = dataGroup[seriesName][rawTS];
|
904 | }
|
905 | catch (RangeError) {
|
906 | console.log(rawTS + " is not a valid ISO time");
|
907 | }
|
908 | });
|
909 | }
|
910 | });
|
911 | }
|
912 | });
|
913 | return convertedData;
|
914 | };
|
915 |
|
916 |
|
917 | Utils.cullValuesOutOfRange = function (availabilityDistribution, minDateString, maxDateString) {
|
918 | var dateZero = '0000-01-01T00:00:00Z';
|
919 | var minDateValue = new Date(minDateString).valueOf();
|
920 | var maxDateValue = new Date(maxDateString).valueOf();
|
921 | if (new Date(availabilityDistribution.range.from).valueOf() < minDateValue ||
|
922 | new Date(availabilityDistribution.range.to).valueOf() > maxDateValue) {
|
923 | var inRangeValues_1 = {};
|
924 | var outOfRangeValues_1 = {};
|
925 | var highestNotOverMaxString_1 = dateZero;
|
926 | var highestNotOverMaxValue_1 = (new Date(highestNotOverMaxString_1)).valueOf();
|
927 | var lowestAboveMinValue_1 = Infinity;
|
928 | Object.keys(availabilityDistribution.distribution).forEach(function (bucketKey) {
|
929 | var bucketValue = (new Date(bucketKey)).valueOf();
|
930 | if (bucketValue > maxDateValue || bucketValue < minDateValue) {
|
931 | outOfRangeValues_1[bucketKey] = availabilityDistribution.distribution[bucketKey];
|
932 | }
|
933 | else {
|
934 | inRangeValues_1[bucketKey] = availabilityDistribution.distribution[bucketKey];
|
935 | if (bucketValue > highestNotOverMaxValue_1) {
|
936 | highestNotOverMaxValue_1 = bucketValue;
|
937 | highestNotOverMaxString_1 = bucketKey;
|
938 | }
|
939 | if (bucketValue < lowestAboveMinValue_1) {
|
940 | lowestAboveMinValue_1 = bucketValue;
|
941 | }
|
942 | }
|
943 | });
|
944 | var bucketSize = this.parseTimeInput(availabilityDistribution.intervalSize);
|
945 | if (highestNotOverMaxString_1 !== dateZero) {
|
946 | var nowMillis = new Date().valueOf();
|
947 | if (highestNotOverMaxValue_1 < nowMillis && (highestNotOverMaxValue_1 + bucketSize) > nowMillis) {
|
948 |
|
949 |
|
950 | availabilityDistribution.range.to = new Date(nowMillis).toISOString();
|
951 | }
|
952 | else {
|
953 | availabilityDistribution.range.to = new Date(highestNotOverMaxValue_1 + bucketSize).toISOString();
|
954 | }
|
955 | }
|
956 | else {
|
957 | var rangeToValue = (new Date(availabilityDistribution.range.to)).valueOf();
|
958 | if (minDateValue > rangeToValue) {
|
959 | availabilityDistribution.range.to = maxDateString;
|
960 | }
|
961 | else {
|
962 | var toValue = Math.min(maxDateValue + bucketSize, (new Date(availabilityDistribution.range.to)).valueOf());
|
963 | availabilityDistribution.range.to = (new Date(toValue)).toISOString();
|
964 | }
|
965 | }
|
966 | if (lowestAboveMinValue_1 !== Infinity) {
|
967 | availabilityDistribution.range.from = (new Date(lowestAboveMinValue_1)).toISOString();
|
968 | }
|
969 | else {
|
970 | var rangeFromValue = (new Date(availabilityDistribution.range.from)).valueOf();
|
971 | if (maxDateValue < (new Date(availabilityDistribution.range.from)).valueOf()) {
|
972 | availabilityDistribution.range.from = minDateString;
|
973 | }
|
974 | else {
|
975 | var fromValue = Math.max(minDateValue, rangeFromValue);
|
976 | availabilityDistribution.range.from = (new Date(fromValue)).toISOString();
|
977 | }
|
978 | }
|
979 | availabilityDistribution.distribution = inRangeValues_1;
|
980 | return [availabilityDistribution, outOfRangeValues_1];
|
981 | }
|
982 | return [availabilityDistribution, {}];
|
983 | };
|
984 | Utils.mergeAvailabilities = function (warmAvailability, coldAvailability, retentionString) {
|
985 | if (retentionString === void 0) { retentionString = null; }
|
986 | var warmStoreRange = warmAvailability.range;
|
987 | var minWarmTime = this.getMinWarmTime(warmStoreRange.from, retentionString);
|
988 | var warmStoreToMillis = new Date(warmStoreRange.to).valueOf();
|
989 | var coldStoreToMillis = new Date(coldAvailability.range.to).valueOf();
|
990 |
|
991 | var maxWarmTime = new Date(Math.min(warmStoreToMillis, coldStoreToMillis));
|
992 | var mergedAvailability = Object.assign({}, coldAvailability);
|
993 | mergedAvailability.warmStoreRange = [minWarmTime.toISOString(), maxWarmTime.toISOString()];
|
994 | if (retentionString !== null) {
|
995 | mergedAvailability.retentionPeriod = retentionString;
|
996 | }
|
997 | return mergedAvailability;
|
998 | };
|
999 | Utils.languageGuess = function () {
|
1000 | return navigator.languages && navigator.languages[0] ||
|
1001 | navigator.language;
|
1002 | };
|
1003 | Utils.memorySizeOf = function (obj) {
|
1004 | var bytes = 0;
|
1005 | var sizeOf = function (obj) {
|
1006 | if (obj !== null && obj !== undefined) {
|
1007 | switch (typeof obj) {
|
1008 | case 'number':
|
1009 | bytes += 8;
|
1010 | break;
|
1011 | case 'string':
|
1012 | bytes += obj.length * 2;
|
1013 | break;
|
1014 | case 'boolean':
|
1015 | bytes += 4;
|
1016 | break;
|
1017 | case 'object':
|
1018 | var objClass = Object.prototype.toString.call(obj).slice(8, -1);
|
1019 | if (objClass === 'Object' || objClass === 'Array') {
|
1020 | for (var key in obj) {
|
1021 | if (!obj.hasOwnProperty(key)) {
|
1022 | continue;
|
1023 | }
|
1024 | sizeOf(key);
|
1025 | sizeOf(obj[key]);
|
1026 | }
|
1027 | }
|
1028 | else {
|
1029 | bytes += obj.toString().length * 2;
|
1030 | }
|
1031 | break;
|
1032 | }
|
1033 | }
|
1034 | return bytes;
|
1035 | };
|
1036 | return sizeOf(obj);
|
1037 | };
|
1038 | Utils.guidForNullTSID = Utils.guid();
|
1039 | Utils.equalToEventTarget = (function () {
|
1040 | return (this == event.target);
|
1041 | });
|
1042 | Utils.isKeyDownAndNotEnter = function (e) {
|
1043 | if (e && e.type && e.type === 'keydown') {
|
1044 | var key = e.which || e.keyCode;
|
1045 | if (key !== 13) {
|
1046 | return true;
|
1047 | }
|
1048 | else {
|
1049 | e.preventDefault();
|
1050 | }
|
1051 | }
|
1052 | return false;
|
1053 | };
|
1054 | Utils.getInstanceKey = function (instance) {
|
1055 | return Utils.instanceHasEmptyTSID(instance) ? Utils.guid() : instance.timeSeriesId.map(function (id) { return id === null ? Utils.guidForNullTSID : id; }).join();
|
1056 | };
|
1057 | Utils.stripNullGuid = function (str) {
|
1058 | return str.replace(Utils.guidForNullTSID, nullTsidDisplayString);
|
1059 | };
|
1060 | Utils.getTimeSeriesIdString = function (instance) {
|
1061 | return instance.timeSeriesId.map(function (id) { return id === null ? nullTsidDisplayString : id; }).join(', ');
|
1062 | };
|
1063 | Utils.getTimeSeriesIdToDisplay = function (instance, emptyDisplayString) {
|
1064 | return Utils.instanceHasEmptyTSID(instance) ? emptyDisplayString : instance.timeSeriesId.map(function (id) { return id === null ? Utils.guidForNullTSID : id; }).join(', ');
|
1065 | };
|
1066 | Utils.getHighlightedTimeSeriesIdToDisplay = function (instance) {
|
1067 | var _a;
|
1068 | return (_a = instance.highlights) === null || _a === void 0 ? void 0 : _a.timeSeriesId.map(function (id, idx) { return instance.timeSeriesId[idx] === null ? Utils.guidForNullTSID : id; }).join(', ');
|
1069 | };
|
1070 | Utils.instanceHasEmptyTSID = function (instance) {
|
1071 | return !instance.timeSeriesId || instance.timeSeriesId.length === 0;
|
1072 | };
|
1073 |
|
1074 | Utils.appendFormattedElementsFromString = function (targetElem, str, options) {
|
1075 | if (options === void 0) { options = null; }
|
1076 | var data = [];
|
1077 | var splitByNullGuid = function (str) {
|
1078 | var data = [];
|
1079 | var splittedByNull = str.split(Utils.guidForNullTSID);
|
1080 | splittedByNull.forEach(function (s, i) {
|
1081 | if (i === 0) {
|
1082 | if (s) {
|
1083 | data.push({ str: s });
|
1084 | }
|
1085 | }
|
1086 | else {
|
1087 | data.push({ str: nullTsidDisplayString, isNull: true });
|
1088 | if (s) {
|
1089 | data.push({ str: s });
|
1090 | }
|
1091 | }
|
1092 | });
|
1093 | return data;
|
1094 | };
|
1095 | var splitByTag = options && options.splitByTag ? options.splitByTag : 'hit';
|
1096 | var splittedByHit = str.split("<" + splitByTag + ">");
|
1097 | splittedByHit.forEach(function (s, i) {
|
1098 | if (i === 0) {
|
1099 | data = data.concat(splitByNullGuid(s));
|
1100 | }
|
1101 | else {
|
1102 | var splittedByHitClose = s.split("</" + splitByTag + ">");
|
1103 | data.push({ str: splittedByHitClose[0], isHit: true });
|
1104 | data = data.concat(splitByNullGuid(splittedByHitClose[1]));
|
1105 | }
|
1106 | });
|
1107 | var additionalClassName = options && options.additionalClassName ? options.additionalClassName : '';
|
1108 | var children = targetElem.selectAll('.tsi-formattedChildren').data(data);
|
1109 | children.enter()
|
1110 | .append(function (d) {
|
1111 | return d.isHit ? document.createElement('mark')
|
1112 | : options && options.inSvg ? document.createElementNS('http://www.w3.org/2000/svg', 'tspan')
|
1113 | : document.createElement('span');
|
1114 | })
|
1115 | .classed('tsi-formattedChildren', true)
|
1116 | .merge(children)
|
1117 | .classed('tsi-baseMono', function (d) { return d.isNull; })
|
1118 | .classed(additionalClassName, options && options.additionalClassName)
|
1119 | .text(function (d) { return d.str; });
|
1120 | children.exit().remove();
|
1121 | };
|
1122 | Utils.escapedTsidForExactSearch = function (tsid) {
|
1123 | var escapedTsid = tsid || '';
|
1124 | if (tsid) {
|
1125 | CharactersToEscapeForExactSearchInstance.forEach(function (c) {
|
1126 | escapedTsid = escapedTsid.split(c).join('+');
|
1127 | });
|
1128 | }
|
1129 | return escapedTsid;
|
1130 | };
|
1131 | return Utils;
|
1132 | }());
|
1133 |
|
1134 | export { DataTypes as D, ErrorCodes as E, GRIDCONTAINERCLASS as G, HierarchiesExpand as H, InstancesSort as I, KeyCodes as K, LINECHARTTOPPADDING as L, MARKERVALUENUMERICHEIGHT as M, NONNUMERICTOPMARGIN as N, ShiftTypes as S, TooltipMeasureFormat as T, Utils as U, VALUEBARHEIGHT as V, YAxisStates as Y, EventElementTypes as a, LINECHARTXOFFSET as b, SERIESLABELWIDTH as c, LINECHARTCHARTMARGINS as d, HierarchiesSort as e, InterpolationFunctions as f, DefaultHierarchyNavigationOptions as g, swimlaneLabelConstants as s, valueTypes as v };
|