autoql-fe-utils 1.0.0 → 1.0.2
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/dist/index.d.ts +387 -1
- package/dist/index.global.js +5784 -1283
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2409 -956
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2348 -956
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -174,16 +174,16 @@ var isListQuery = (columns) => {
|
|
|
174
174
|
|
|
175
175
|
// src/dayjsWithPlugins.ts
|
|
176
176
|
import dayjs from "dayjs";
|
|
177
|
-
import advancedFormat from "dayjs/plugin/advancedFormat";
|
|
178
|
-
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
179
|
-
import utc from "dayjs/plugin/utc";
|
|
180
|
-
import timezone from "dayjs/plugin/timezone";
|
|
181
|
-
import isBetween from "dayjs/plugin/isBetween";
|
|
182
|
-
import weekOfYear from "dayjs/plugin/weekOfYear";
|
|
183
|
-
import quarterOfYear from "dayjs/plugin/quarterOfYear";
|
|
184
|
-
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
185
|
-
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
|
186
|
-
import isToday from "dayjs/plugin/isToday";
|
|
177
|
+
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
178
|
+
import localizedFormat from "dayjs/plugin/localizedFormat.js";
|
|
179
|
+
import utc from "dayjs/plugin/utc.js";
|
|
180
|
+
import timezone from "dayjs/plugin/timezone.js";
|
|
181
|
+
import isBetween from "dayjs/plugin/isBetween.js";
|
|
182
|
+
import weekOfYear from "dayjs/plugin/weekOfYear.js";
|
|
183
|
+
import quarterOfYear from "dayjs/plugin/quarterOfYear.js";
|
|
184
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
185
|
+
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
|
|
186
|
+
import isToday from "dayjs/plugin/isToday.js";
|
|
187
187
|
dayjs.extend(utc);
|
|
188
188
|
dayjs.extend(isToday);
|
|
189
189
|
dayjs.extend(timezone);
|
|
@@ -224,7 +224,7 @@ var isNumber = (str) => {
|
|
|
224
224
|
return /^\d+$/.test(str);
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
// src/Constants/
|
|
227
|
+
// src/Constants/visualizationConstants.ts
|
|
228
228
|
var TABLE_TYPES = [
|
|
229
229
|
"pivot_table",
|
|
230
230
|
"pivot_column",
|
|
@@ -336,1093 +336,1413 @@ var AGG_TYPES = [
|
|
|
336
336
|
var MAX_LEGEND_LABELS = 22;
|
|
337
337
|
var MIN_HISTOGRAM_SAMPLE = 20;
|
|
338
338
|
|
|
339
|
-
// src/
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
PrecisionTypes2["HOUR"] = "HOUR";
|
|
354
|
-
PrecisionTypes2["MINUTE"] = "MINUTE";
|
|
355
|
-
return PrecisionTypes2;
|
|
356
|
-
})(PrecisionTypes || {});
|
|
357
|
-
var NumberColumnTypes = /* @__PURE__ */ ((NumberColumnTypes2) => {
|
|
358
|
-
NumberColumnTypes2["CURRENCY"] = "DOLLAR_AMT";
|
|
359
|
-
NumberColumnTypes2["QUANTITY"] = "QUANTITY";
|
|
360
|
-
NumberColumnTypes2["RATIO"] = "RATIO";
|
|
361
|
-
NumberColumnTypes2["PERCENT"] = "PERCENT";
|
|
362
|
-
return NumberColumnTypes2;
|
|
363
|
-
})(NumberColumnTypes || {});
|
|
364
|
-
var NumberColumnTypeDisplayNames = /* @__PURE__ */ ((NumberColumnTypeDisplayNames2) => {
|
|
365
|
-
NumberColumnTypeDisplayNames2["DOLLAR_AMT"] = "Currency";
|
|
366
|
-
NumberColumnTypeDisplayNames2["QUANTITY"] = "Quantity";
|
|
367
|
-
NumberColumnTypeDisplayNames2["RATIO"] = "Ratio";
|
|
368
|
-
NumberColumnTypeDisplayNames2["PERCENT"] = "Percent";
|
|
369
|
-
return NumberColumnTypeDisplayNames2;
|
|
370
|
-
})(NumberColumnTypeDisplayNames || {});
|
|
371
|
-
|
|
372
|
-
// src/Constants/defaults.ts
|
|
373
|
-
var authenticationDefault = {
|
|
374
|
-
token: void 0,
|
|
375
|
-
apiKey: void 0,
|
|
376
|
-
domain: void 0,
|
|
377
|
-
dprKey: void 0,
|
|
378
|
-
dprDomain: void 0
|
|
379
|
-
};
|
|
380
|
-
var dataFormattingDefault = {
|
|
381
|
-
timestampFormat: "ISO8601" /* iso8601 */,
|
|
382
|
-
currencyCode: "USD",
|
|
383
|
-
languageCode: "en-US",
|
|
384
|
-
currencyDecimals: 2,
|
|
385
|
-
quantityDecimals: 2,
|
|
386
|
-
ratioDecimals: 4,
|
|
387
|
-
comparisonDisplay: "PERCENT",
|
|
388
|
-
monthYearFormat: "MMMM YYYY",
|
|
389
|
-
dayMonthYearFormat: "ll"
|
|
390
|
-
};
|
|
391
|
-
var autoQLConfigDefault = {
|
|
392
|
-
debug: false,
|
|
393
|
-
test: false,
|
|
394
|
-
enableAutocomplete: true,
|
|
395
|
-
enableQueryInterpretation: true,
|
|
396
|
-
enableQueryValidation: true,
|
|
397
|
-
enableQuerySuggestions: true,
|
|
398
|
-
enableColumnVisibilityManager: true,
|
|
399
|
-
enableDrilldowns: true,
|
|
400
|
-
enableNotifications: false,
|
|
401
|
-
enableCSVDownload: true,
|
|
402
|
-
enableReportProblem: true
|
|
403
|
-
};
|
|
404
|
-
var dataConfigDefault = {
|
|
405
|
-
stringColumnIndices: [],
|
|
406
|
-
numberColumnIndices: [],
|
|
407
|
-
stringColumnIndex: 0,
|
|
408
|
-
legendColumnIndex: void 0,
|
|
409
|
-
numberColumnIndex: 1
|
|
410
|
-
};
|
|
411
|
-
var getAuthentication = (prop = {}) => {
|
|
412
|
-
return {
|
|
413
|
-
...authenticationDefault,
|
|
414
|
-
...prop
|
|
415
|
-
};
|
|
416
|
-
};
|
|
417
|
-
var getDataFormatting = (prop = {}) => {
|
|
418
|
-
return {
|
|
419
|
-
...dataFormattingDefault,
|
|
420
|
-
...prop
|
|
421
|
-
};
|
|
339
|
+
// src/HelperFns/arrayHelpers.ts
|
|
340
|
+
import isEqual from "lodash.isequal";
|
|
341
|
+
var invertArray = (array) => {
|
|
342
|
+
const numRows = array.length;
|
|
343
|
+
const numColumns = array[0].length;
|
|
344
|
+
const invertedArray = [];
|
|
345
|
+
for (let i = 0; i < numColumns; i++) {
|
|
346
|
+
invertedArray[i] = [];
|
|
347
|
+
for (let j = 0; j < numRows; j++) {
|
|
348
|
+
if (array[j][i])
|
|
349
|
+
invertedArray[i][j] = array[j][i];
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return invertedArray;
|
|
422
353
|
};
|
|
423
|
-
var
|
|
424
|
-
return
|
|
425
|
-
...autoQLConfigDefault,
|
|
426
|
-
...prop
|
|
427
|
-
};
|
|
354
|
+
var functionsEqual = (a, b) => {
|
|
355
|
+
return (a == null ? void 0 : a.toString()) == (b == null ? void 0 : b.toString());
|
|
428
356
|
};
|
|
429
|
-
var
|
|
430
|
-
return
|
|
431
|
-
...dataConfigDefault,
|
|
432
|
-
...prop
|
|
433
|
-
};
|
|
357
|
+
var isObject = (obj) => {
|
|
358
|
+
return typeof obj === "object" && !Array.isArray(obj) && obj !== null && obj !== void 0;
|
|
434
359
|
};
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return void 0;
|
|
360
|
+
var deepEqual = (objA, objB) => {
|
|
361
|
+
const lodashIsEqual = isEqual(objA, objB);
|
|
362
|
+
if (lodashIsEqual) {
|
|
363
|
+
return true;
|
|
440
364
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
case "MINUTE": {
|
|
456
|
-
const dayjsTime = dayjsWithPlugins_default.utc(value, "THH:mm:ss.SSSZ").utc();
|
|
457
|
-
if (dayjsTime.isValid()) {
|
|
458
|
-
formattedValue = dayjsTime.format("h:mmA");
|
|
459
|
-
}
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
case "MONTH": {
|
|
463
|
-
formattedValue = value;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
default: {
|
|
467
|
-
formattedValue = value;
|
|
468
|
-
break;
|
|
365
|
+
const objAIsObject = isObject(objA);
|
|
366
|
+
const objBIsObject = isObject(objB);
|
|
367
|
+
if (!objAIsObject || !objBIsObject) {
|
|
368
|
+
return lodashIsEqual;
|
|
369
|
+
}
|
|
370
|
+
const keysA = Object.keys(objA);
|
|
371
|
+
const keysB = Object.keys(objB);
|
|
372
|
+
if (keysA.length !== keysB.length) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
376
|
+
if (typeof objA[keysA[i]] === "function" && typeof objB[keysA[i]] === "function") {
|
|
377
|
+
if (!functionsEqual(objA[keysA[i]], objB[keysA[i]])) {
|
|
378
|
+
return false;
|
|
469
379
|
}
|
|
380
|
+
} else if (!Object.hasOwnProperty.call(objB, keysA[i]) || !isEqual(objA[keysA[i]], objB[keysA[i]])) {
|
|
381
|
+
return false;
|
|
470
382
|
}
|
|
471
|
-
return formattedValue;
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error(error);
|
|
474
|
-
return value;
|
|
475
383
|
}
|
|
384
|
+
return true;
|
|
476
385
|
};
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if ((
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const dayJSObj = dayjsWithPlugins_default.utc(value).utc();
|
|
495
|
-
if (!dayJSObj.isValid()) {
|
|
496
|
-
return value;
|
|
497
|
-
}
|
|
498
|
-
let date = value;
|
|
499
|
-
if (day) {
|
|
500
|
-
date = dayJSObj.format(dayMonthYearFormat);
|
|
501
|
-
} else if (month) {
|
|
502
|
-
date = dayJSObj.format(monthYearFormat);
|
|
503
|
-
} else if (week) {
|
|
504
|
-
} else if (year) {
|
|
505
|
-
date = year;
|
|
386
|
+
var difference = (objA, objB) => {
|
|
387
|
+
const diff = [];
|
|
388
|
+
Object.keys(Object.assign({}, objA, objB)).forEach((key) => {
|
|
389
|
+
if (typeof objA[key] === "function" && typeof objB[key] === "function") {
|
|
390
|
+
if (!functionsEqual(objA[key], objB[key])) {
|
|
391
|
+
diff.push({
|
|
392
|
+
key,
|
|
393
|
+
objA: objA[key],
|
|
394
|
+
objB: objB[key]
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
} else if (!Object.is(objA[key], objB[key])) {
|
|
398
|
+
diff.push({
|
|
399
|
+
key,
|
|
400
|
+
objA: objA[key],
|
|
401
|
+
objB: objB[key]
|
|
402
|
+
});
|
|
506
403
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
return value;
|
|
404
|
+
});
|
|
405
|
+
return diff;
|
|
510
406
|
};
|
|
511
|
-
var
|
|
512
|
-
|
|
513
|
-
|
|
407
|
+
var rotateArray = (array, n) => {
|
|
408
|
+
const rotated = [...array];
|
|
409
|
+
n = n % array.length;
|
|
410
|
+
if (n < 0)
|
|
411
|
+
n = array.length + n;
|
|
412
|
+
for (let i = 0; i < n; i++) {
|
|
413
|
+
rotated.unshift(rotated.pop());
|
|
514
414
|
}
|
|
515
|
-
return
|
|
415
|
+
return rotated;
|
|
516
416
|
};
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
return element;
|
|
520
|
-
}
|
|
521
|
-
if (column.precision) {
|
|
522
|
-
return formatStringDateWithPrecision(element, column);
|
|
523
|
-
}
|
|
524
|
-
return formatStringDate(element, config);
|
|
417
|
+
var onlyUnique = (value, index, self) => {
|
|
418
|
+
return self.indexOf(value) === index;
|
|
525
419
|
};
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
420
|
+
var makeEmptyArray = (w, h, value = "") => {
|
|
421
|
+
var arr = [];
|
|
422
|
+
for (let i = 0; i < h; i++) {
|
|
423
|
+
arr[i] = [];
|
|
424
|
+
for (let j = 0; j < w; j++) {
|
|
425
|
+
arr[i][j] = value;
|
|
426
|
+
}
|
|
532
427
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
428
|
+
return arr;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/HelperFns/displayTypeHelpers.ts
|
|
432
|
+
var isChartType = (type) => CHART_TYPES.includes(type);
|
|
433
|
+
var isTableType = (type) => TABLE_TYPES.includes(type);
|
|
434
|
+
var isDisplayTypeValid = (response, displayType, dataLength, pivotDataLength, columns, isDataLimited) => {
|
|
435
|
+
var _a, _b;
|
|
436
|
+
const supportedDisplayTypes = getSupportedDisplayTypes({
|
|
437
|
+
response,
|
|
438
|
+
columns: columns ?? ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.columns),
|
|
439
|
+
dataLength,
|
|
440
|
+
pivotDataLength,
|
|
441
|
+
isDataLimited
|
|
442
|
+
});
|
|
443
|
+
const isValid = displayType && supportedDisplayTypes.includes(displayType);
|
|
444
|
+
return isValid;
|
|
445
|
+
};
|
|
446
|
+
var shouldPlotMultiSeries = (columns) => {
|
|
447
|
+
if (isAggregation(columns)) {
|
|
448
|
+
return false;
|
|
538
449
|
}
|
|
539
|
-
|
|
450
|
+
const multiSeriesIndex = columns.findIndex((col) => col.multi_series === true);
|
|
451
|
+
return multiSeriesIndex >= 0;
|
|
452
|
+
};
|
|
453
|
+
var supportsPieChart = (columns, chartData) => {
|
|
454
|
+
if (shouldPlotMultiSeries(columns)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
if (chartData) {
|
|
458
|
+
return chartData.length < 7;
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
};
|
|
462
|
+
var supports2DCharts = (columns, dataLength) => {
|
|
463
|
+
if (dataLength <= 1) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
const { amountOfNumberColumns, amountOfStringColumns } = getColumnTypeAmounts(columns);
|
|
467
|
+
return amountOfNumberColumns > 0 && amountOfStringColumns > 0;
|
|
468
|
+
};
|
|
469
|
+
var supportsRegularPivotTable = (columns, dataLength, data) => {
|
|
470
|
+
var _a, _b;
|
|
471
|
+
if (dataLength <= 1) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
const groupbyColumns = getGroupableColumns(columns);
|
|
475
|
+
const hasTwoGroupables = (groupbyColumns == null ? void 0 : groupbyColumns.length) === 2;
|
|
476
|
+
if (!hasTwoGroupables) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
const visibleColumns = getVisibleColumns(columns);
|
|
480
|
+
const groupbyColumn1 = columns[groupbyColumns[0]];
|
|
481
|
+
const groupbyColumn2 = columns[groupbyColumns[1]];
|
|
482
|
+
if (!groupbyColumn1.is_visible || !groupbyColumn2.is_visible || !((visibleColumns == null ? void 0 : visibleColumns.length) >= 3)) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
const column1Data = (data == null ? void 0 : data.map((row) => {
|
|
486
|
+
return row[groupbyColumns[0]];
|
|
487
|
+
})) ?? [];
|
|
488
|
+
const column2Data = (data == null ? void 0 : data.map((row) => {
|
|
489
|
+
return row[groupbyColumns[1]];
|
|
490
|
+
})) ?? [];
|
|
491
|
+
const uniqueData1Length = ((_a = column1Data == null ? void 0 : column1Data.filter(onlyUnique)) == null ? void 0 : _a.length) ?? 0;
|
|
492
|
+
const uniqueData2Length = ((_b = column2Data == null ? void 0 : column2Data.filter(onlyUnique)) == null ? void 0 : _b.length) ?? 0;
|
|
493
|
+
if (uniqueData1Length > MAX_LEGEND_LABELS && uniqueData2Length > MAX_LEGEND_LABELS) {
|
|
494
|
+
console.debug(
|
|
495
|
+
`Info: Pivot table will not be supported since there are too many unique fields. The calculated dimensions would be: ${uniqueData1Length} x ${uniqueData2Length}`
|
|
496
|
+
);
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
return true;
|
|
500
|
+
};
|
|
501
|
+
var supportsDatePivotTable = (columns) => {
|
|
502
|
+
var _a;
|
|
503
|
+
const dateColumnIndex = columns.findIndex((col) => col.type === "DATE" || col.type === "DATE_STRING");
|
|
504
|
+
const dateColumn = columns[dateColumnIndex];
|
|
505
|
+
return dateColumn && ((_a = dateColumn == null ? void 0 : dateColumn.display_name) == null ? void 0 : _a.toLowerCase().includes("month")) && (columns == null ? void 0 : columns.length) === 2;
|
|
506
|
+
};
|
|
507
|
+
var isSingleValueResponse = (response) => {
|
|
508
|
+
var _a, _b, _c, _d, _e, _f;
|
|
509
|
+
if (!response) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
const rows = (_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.rows;
|
|
513
|
+
const columns = (_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.data) == null ? void 0 : _d.columns;
|
|
514
|
+
const referenceID = (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.reference_id;
|
|
515
|
+
const hasNoData = rows && !(rows == null ? void 0 : rows.length);
|
|
516
|
+
const hasOneColumn = (columns == null ? void 0 : columns.length) === 1;
|
|
517
|
+
if (hasNoData && hasOneColumn && referenceID === "1.1.211") {
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
const oneRowAndColumn = (rows == null ? void 0 : rows.length) === 1 && ((_f = rows[0]) == null ? void 0 : _f.length) === 1;
|
|
521
|
+
if (oneRowAndColumn) {
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
};
|
|
526
|
+
var getSupportedDisplayTypes = ({
|
|
527
|
+
response,
|
|
528
|
+
columns,
|
|
529
|
+
dataLength,
|
|
530
|
+
pivotDataLength,
|
|
531
|
+
isDataLimited
|
|
532
|
+
} = {}) => {
|
|
533
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
540
534
|
try {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
535
|
+
if (!((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.display_type)) {
|
|
536
|
+
return [];
|
|
537
|
+
}
|
|
538
|
+
const displayType = response.data.data.display_type;
|
|
539
|
+
if (displayType === "suggestion" || displayType === "help" || displayType === "html") {
|
|
540
|
+
return [displayType];
|
|
541
|
+
}
|
|
542
|
+
const rows = ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.data) == null ? void 0 : _d.rows) ?? [];
|
|
543
|
+
const allColumns = columns || ((_f = (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.data) == null ? void 0 : _f.columns);
|
|
544
|
+
const visibleColumns = getVisibleColumns(allColumns);
|
|
545
|
+
if (!(visibleColumns == null ? void 0 : visibleColumns.length)) {
|
|
546
|
+
return ["text"];
|
|
547
|
+
}
|
|
548
|
+
if (isSingleValueResponse(response)) {
|
|
549
|
+
return ["single-value"];
|
|
550
|
+
}
|
|
551
|
+
if (!(rows == null ? void 0 : rows.length)) {
|
|
552
|
+
return ["table"];
|
|
553
|
+
}
|
|
554
|
+
const maxRowsForPieChart = 10;
|
|
555
|
+
const numRows = dataLength ?? rows.length;
|
|
556
|
+
let pivotDataHasLength = true;
|
|
557
|
+
const pivotDataLengthProvided = pivotDataLength !== void 0 && pivotDataLength !== null;
|
|
558
|
+
if (pivotDataLengthProvided) {
|
|
559
|
+
pivotDataHasLength = !!pivotDataLength;
|
|
560
|
+
}
|
|
561
|
+
if (supportsRegularPivotTable(visibleColumns, numRows, (_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.data) == null ? void 0 : _h.rows)) {
|
|
562
|
+
const supportedDisplayTypes = ["table"];
|
|
563
|
+
if (!isDataLimited) {
|
|
564
|
+
supportedDisplayTypes.push("pivot_table");
|
|
552
565
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
566
|
+
if (
|
|
567
|
+
// Comment out for now so chart row count doesnt change display type
|
|
568
|
+
// numRows <= maxRowsForPivot &&
|
|
569
|
+
pivotDataHasLength
|
|
570
|
+
) {
|
|
571
|
+
supportedDisplayTypes.push("stacked_column", "stacked_bar", "column", "bar", "bubble", "heatmap");
|
|
572
|
+
if (hasDateColumn(visibleColumns)) {
|
|
573
|
+
supportedDisplayTypes.push("stacked_line", "line");
|
|
574
|
+
}
|
|
556
575
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
576
|
+
return supportedDisplayTypes;
|
|
577
|
+
} else if (supports2DCharts(visibleColumns, numRows)) {
|
|
578
|
+
const supportedDisplayTypes = ["table", "column", "bar"];
|
|
579
|
+
if (numRows > MIN_HISTOGRAM_SAMPLE) {
|
|
580
|
+
supportedDisplayTypes.push("histogram");
|
|
562
581
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
break;
|
|
582
|
+
if (hasDateColumn(visibleColumns)) {
|
|
583
|
+
supportedDisplayTypes.push("line");
|
|
566
584
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
break;
|
|
585
|
+
if (numRows > 1 && numRows <= maxRowsForPieChart) {
|
|
586
|
+
supportedDisplayTypes.push("pie");
|
|
570
587
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
588
|
+
const { amountOfNumberColumns } = getColumnTypeAmounts(visibleColumns);
|
|
589
|
+
if (amountOfNumberColumns > 1) {
|
|
590
|
+
supportedDisplayTypes.push("column_line");
|
|
591
|
+
supportedDisplayTypes.push("scatterplot");
|
|
574
592
|
}
|
|
575
|
-
|
|
576
|
-
|
|
593
|
+
if (!isDataLimited && supportsDatePivotTable(visibleColumns)) {
|
|
594
|
+
const dateColumnIndex = visibleColumns.findIndex((col) => col.type === "DATE" || col.type === "DATE_STRING");
|
|
595
|
+
const dateColumn = visibleColumns[dateColumnIndex];
|
|
596
|
+
const data = (_j = (_i = response == null ? void 0 : response.data) == null ? void 0 : _i.data) == null ? void 0 : _j.rows;
|
|
597
|
+
const uniqueYears = [];
|
|
598
|
+
data.forEach((row) => {
|
|
599
|
+
const year = formatElement({
|
|
600
|
+
element: row[dateColumnIndex],
|
|
601
|
+
column: dateColumn,
|
|
602
|
+
config: getDataFormatting({ monthYearFormat: "YYYY", dayMonthYearFormat: "YYYY" })
|
|
603
|
+
});
|
|
604
|
+
if (!uniqueYears.includes(year)) {
|
|
605
|
+
uniqueYears.push(year);
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
if (uniqueYears.length > 1) {
|
|
609
|
+
supportedDisplayTypes.push("pivot_table");
|
|
610
|
+
}
|
|
577
611
|
}
|
|
612
|
+
return supportedDisplayTypes;
|
|
578
613
|
}
|
|
579
|
-
return
|
|
614
|
+
return ["table"];
|
|
580
615
|
} catch (error) {
|
|
581
616
|
console.error(error);
|
|
617
|
+
return ["table"];
|
|
582
618
|
}
|
|
583
619
|
};
|
|
584
|
-
var
|
|
585
|
-
|
|
586
|
-
|
|
620
|
+
var getFirstChartDisplayType = (supportedDisplayTypes, fallback) => {
|
|
621
|
+
const chartType = supportedDisplayTypes.find((displayType) => isChartType(displayType));
|
|
622
|
+
if (chartType) {
|
|
623
|
+
return chartType;
|
|
587
624
|
}
|
|
588
|
-
|
|
589
|
-
|
|
625
|
+
return fallback;
|
|
626
|
+
};
|
|
627
|
+
var getDefaultDisplayType = (response, defaultToChart, columns, dataLength, pivotDataLength, preferredDisplayType, isDataLimited = false) => {
|
|
628
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
629
|
+
const supportedDisplayTypes = getSupportedDisplayTypes({
|
|
630
|
+
response,
|
|
631
|
+
columns: columns ?? ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.columns),
|
|
632
|
+
dataLength,
|
|
633
|
+
pivotDataLength,
|
|
634
|
+
isDataLimited
|
|
635
|
+
});
|
|
636
|
+
if (preferredDisplayType && supportedDisplayTypes.includes(preferredDisplayType)) {
|
|
637
|
+
return preferredDisplayType;
|
|
590
638
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const monthYear = monthYearFormat;
|
|
595
|
-
const dayMonthYear = dayMonthYearFormat;
|
|
596
|
-
const title = col.title;
|
|
597
|
-
let dayJSObj;
|
|
598
|
-
if (isNaN(parseFloat(value))) {
|
|
599
|
-
dayJSObj = dayjsWithPlugins_default.utc(value).utc();
|
|
600
|
-
} else {
|
|
601
|
-
dayJSObj = dayjsWithPlugins_default.unix(value).utc();
|
|
602
|
-
}
|
|
603
|
-
if (!dayJSObj.isValid()) {
|
|
604
|
-
return value;
|
|
605
|
-
}
|
|
606
|
-
let date = dayJSObj.format(dayMonthYear);
|
|
607
|
-
if (isNaN(parseFloat(value))) {
|
|
608
|
-
if (title && title.toLowerCase().includes("year")) {
|
|
609
|
-
date = dayJSObj.format(year);
|
|
610
|
-
} else if (title && title.toLowerCase().includes("month")) {
|
|
611
|
-
date = dayJSObj.format(monthYear);
|
|
612
|
-
}
|
|
613
|
-
date = dayJSObj.format(dayMonthYear);
|
|
614
|
-
} else if (title && title.toLowerCase().includes("year")) {
|
|
615
|
-
date = dayJSObj.format(year);
|
|
616
|
-
} else if (title && title.toLowerCase().includes("month")) {
|
|
617
|
-
date = dayJSObj.format(monthYear);
|
|
618
|
-
}
|
|
619
|
-
return date;
|
|
620
|
-
} catch (error) {
|
|
621
|
-
console.error(error);
|
|
622
|
-
return value;
|
|
639
|
+
const responseDisplayType = (_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.data) == null ? void 0 : _d.display_type;
|
|
640
|
+
if (supportedDisplayTypes.includes(preferredDisplayType)) {
|
|
641
|
+
return preferredDisplayType;
|
|
623
642
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
let dowStyle = col.dow_style;
|
|
627
|
-
if (!dowStyle) {
|
|
628
|
-
dowStyle = "NUM_1_MON";
|
|
643
|
+
if (responseDisplayType === "suggestion" || responseDisplayType === "help" || responseDisplayType === "html") {
|
|
644
|
+
return responseDisplayType;
|
|
629
645
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
switch (dowStyle) {
|
|
633
|
-
case "NUM_1_MON": {
|
|
634
|
-
const weekdays = WEEKDAY_NAMES_MON;
|
|
635
|
-
const index = weekdayNumber - 1;
|
|
636
|
-
if (index >= 0) {
|
|
637
|
-
formattedValue = weekdays[index];
|
|
638
|
-
} else {
|
|
639
|
-
console.warn(`dow style is NUM_1_MON but the value could not be converted to a number: ${value}`);
|
|
640
|
-
}
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
643
|
-
case "NUM_1_SUN": {
|
|
644
|
-
const weekdays = WEEKDAY_NAMES_SUN;
|
|
645
|
-
const index = weekdayNumber - 1;
|
|
646
|
-
if (index >= 0) {
|
|
647
|
-
formattedValue = weekdays[index];
|
|
648
|
-
} else {
|
|
649
|
-
console.warn(`dow style is NUM_1_SUN but the value could not be converted to a number: ${value}`);
|
|
650
|
-
}
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
case "NUM_0_MON": {
|
|
654
|
-
const weekdays = WEEKDAY_NAMES_MON;
|
|
655
|
-
if (weekdayNumber >= 0) {
|
|
656
|
-
formattedValue = weekdays[weekdayNumber];
|
|
657
|
-
} else {
|
|
658
|
-
console.warn(`dow style is NUM_0_MON but the value could not be converted to a number: ${value}`);
|
|
659
|
-
}
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
case "NUM_0_SUN": {
|
|
663
|
-
const weekdays = WEEKDAY_NAMES_SUN;
|
|
664
|
-
if (weekdayNumber >= 0) {
|
|
665
|
-
formattedValue = weekdays[weekdayNumber];
|
|
666
|
-
} else {
|
|
667
|
-
console.warn(`dow style is NUM_0_SUN but the value could not be converted to a number: ${value}`);
|
|
668
|
-
}
|
|
669
|
-
break;
|
|
670
|
-
}
|
|
671
|
-
case "ALPHA_MON":
|
|
672
|
-
case "ALPHA_SUN": {
|
|
673
|
-
const weekday = WEEKDAY_NAMES_MON.find((weekday2) => weekday2.toLowerCase().includes(value.trim().toLowerCase()));
|
|
674
|
-
if (weekday) {
|
|
675
|
-
formattedValue = weekday;
|
|
676
|
-
} else {
|
|
677
|
-
console.warn(`dow style is ALPHA but the value could not be matched to a weekday name: ${value}`);
|
|
678
|
-
}
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
default: {
|
|
682
|
-
console.warn(`could not format dow value. dow_style was not recognized: ${col.dow_style}`);
|
|
683
|
-
break;
|
|
684
|
-
}
|
|
646
|
+
if (supportedDisplayTypes.length === 1) {
|
|
647
|
+
return supportedDisplayTypes[0];
|
|
685
648
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
const aDateYear = a.substring(0, 4);
|
|
691
|
-
const bDateYear = b.substring(0, 4);
|
|
692
|
-
if (aDateYear !== bDateYear) {
|
|
693
|
-
return aDateYear - bDateYear;
|
|
694
|
-
} else {
|
|
695
|
-
const aDateWeek = a.substring(6, 8);
|
|
696
|
-
const bDateWeek = b.substring(6, 8);
|
|
697
|
-
return aDateWeek - bDateWeek;
|
|
698
|
-
}
|
|
699
|
-
} else if (WEEKDAY_NAMES_MON.includes(a.trim())) {
|
|
700
|
-
const aDayIndex = WEEKDAY_NAMES_MON.findIndex((d) => d.toLowerCase().includes(a.trim().toLowerCase()));
|
|
701
|
-
const bDayIndex = WEEKDAY_NAMES_MON.findIndex((d) => d.toLowerCase().includes(b.trim().toLowerCase()));
|
|
702
|
-
let sortValue = a - b;
|
|
703
|
-
if (aDayIndex >= 0 && bDayIndex >= 0) {
|
|
704
|
-
sortValue = aDayIndex - bDayIndex;
|
|
705
|
-
}
|
|
706
|
-
return sortValue;
|
|
707
|
-
} else if (MONTH_NAMES.includes(a.trim())) {
|
|
708
|
-
const aMonthIndex = MONTH_NAMES.findIndex((m) => m === a.trim());
|
|
709
|
-
const bMonthIndex = MONTH_NAMES.findIndex((m) => m === b.trim());
|
|
710
|
-
if (aMonthIndex >= 0 && bMonthIndex >= 0) {
|
|
711
|
-
return bMonthIndex - aMonthIndex;
|
|
649
|
+
if (supportedDisplayTypes.includes("pivot_table")) {
|
|
650
|
+
let displayType = "pivot_table";
|
|
651
|
+
if (defaultToChart) {
|
|
652
|
+
displayType = isAggregation((_f = (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.data) == null ? void 0 : _f.columns) ? getFirstChartDisplayType(supportedDisplayTypes, "pivot_table") : "pivot_table";
|
|
712
653
|
}
|
|
713
|
-
return
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
if (aYear === bYear) {
|
|
720
|
-
return aSeasonIndex - bSeasonIndex;
|
|
654
|
+
return displayType;
|
|
655
|
+
}
|
|
656
|
+
if (!responseDisplayType && hasData(response) || responseDisplayType === "data") {
|
|
657
|
+
let displayType = "table";
|
|
658
|
+
if (defaultToChart) {
|
|
659
|
+
displayType = isAggregation((_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.data) == null ? void 0 : _h.columns) ? getFirstChartDisplayType(supportedDisplayTypes, "table") : "table";
|
|
721
660
|
}
|
|
722
|
-
return
|
|
661
|
+
return displayType;
|
|
723
662
|
}
|
|
724
|
-
return
|
|
663
|
+
return "text";
|
|
725
664
|
};
|
|
726
|
-
var
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
const aTrimmed = a.trim();
|
|
731
|
-
const bTrimmed = b.trim();
|
|
732
|
-
switch (col.precision) {
|
|
733
|
-
case "DOW": {
|
|
734
|
-
const dowStyle = col.dow_style ?? "ALPHA_MON";
|
|
735
|
-
let aIndex = WEEKDAY_NAMES_MON.findIndex((dow) => dow.toLowerCase().includes(aTrimmed.toLowerCase()));
|
|
736
|
-
let bIndex = WEEKDAY_NAMES_MON.findIndex((dow) => dow.toLowerCase().includes(bTrimmed.toLowerCase()));
|
|
737
|
-
if (dowStyle === "ALPHA_SUN") {
|
|
738
|
-
aIndex = WEEKDAY_NAMES_SUN.findIndex((dow) => dow.toLowerCase().includes(aTrimmed.toLowerCase()));
|
|
739
|
-
bIndex = WEEKDAY_NAMES_SUN.findIndex((dow) => dow.toLowerCase().includes(bTrimmed.toLowerCase()));
|
|
740
|
-
}
|
|
741
|
-
return aIndex - bIndex;
|
|
742
|
-
}
|
|
743
|
-
case "HOUR":
|
|
744
|
-
case "MINUTE": {
|
|
745
|
-
const aDayjsTime = dayjsWithPlugins_default.utc(aTrimmed, "THH:mm:ss.SSSZ").utc();
|
|
746
|
-
const bDayjsTime = dayjsWithPlugins_default.utc(bTrimmed, "THH:mm:ss.SSSZ").utc();
|
|
747
|
-
return aDayjsTime.unix() - bDayjsTime.unix();
|
|
748
|
-
}
|
|
749
|
-
case "MONTH": {
|
|
750
|
-
MONTH_NAMES;
|
|
751
|
-
const aMonthIndex = MONTH_NAMES.findIndex((m) => m.toLowerCase() === aTrimmed.toLowerCase());
|
|
752
|
-
const bMonthIndex = MONTH_NAMES.findIndex((m) => m.toLowerCase() === bTrimmed.toLowerCase());
|
|
753
|
-
return aMonthIndex - bMonthIndex;
|
|
754
|
-
}
|
|
755
|
-
default: {
|
|
756
|
-
return dateStringSortFnWithoutPrecision(aTrimmed, bTrimmed);
|
|
757
|
-
}
|
|
665
|
+
var hasData = (response) => {
|
|
666
|
+
var _a, _b, _c;
|
|
667
|
+
if (!response) {
|
|
668
|
+
return false;
|
|
758
669
|
}
|
|
670
|
+
return (_c = (_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.rows) == null ? void 0 : _c.length;
|
|
759
671
|
};
|
|
760
|
-
|
|
672
|
+
|
|
673
|
+
// src/HelperFns/dataAlertHelpers.ts
|
|
674
|
+
var getDayLocalStartDate = ({ timeObj, timezone: timezone2, daysToAdd = 0 }) => {
|
|
761
675
|
try {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
} else if (a && !b || !col) {
|
|
767
|
-
return -1;
|
|
768
|
-
}
|
|
769
|
-
let aDate = Number(a);
|
|
770
|
-
let bDate = Number(b);
|
|
771
|
-
let sortValue = aDate - bDate;
|
|
772
|
-
if (isNaN(aDate) || isNaN(bDate)) {
|
|
773
|
-
if (col.type === "DATE_STRING") {
|
|
774
|
-
sortValue = dateStringSortFn(a, b, col);
|
|
775
|
-
} else {
|
|
776
|
-
sortValue = dayjsWithPlugins_default.utc(a).unix() - dayjsWithPlugins_default.utc(b).unix();
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
if (isTable && col.precision === "DOW") {
|
|
780
|
-
sortValue = -1 * sortValue;
|
|
676
|
+
const now = dayjsWithPlugins_default().tz(timezone2);
|
|
677
|
+
let nextCycle = now.startOf("minute").set("hour", timeObj.hour24).set("minute", timeObj.minute);
|
|
678
|
+
if (nextCycle.valueOf() < now.valueOf()) {
|
|
679
|
+
nextCycle = nextCycle.add(1, "day");
|
|
781
680
|
}
|
|
782
|
-
|
|
681
|
+
const nextCycleFormatted = nextCycle.add(daysToAdd, "days").format("YYYY-MM-DD[T]HH:mm:00");
|
|
682
|
+
return nextCycleFormatted;
|
|
783
683
|
} catch (error) {
|
|
784
684
|
console.error(error);
|
|
785
|
-
return
|
|
685
|
+
return;
|
|
786
686
|
}
|
|
787
687
|
};
|
|
788
|
-
var
|
|
688
|
+
var getWeekLocalStartDate = ({ weekDay, timeObj, timezone: timezone2 }) => {
|
|
789
689
|
try {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
let multiplier = sortDirection === "desc" ? -1 : 1;
|
|
797
|
-
const sortedData = [...data].sort(
|
|
798
|
-
(a, b) => multiplier * dateSortFn(a[dateColumnIndex], b[dateColumnIndex], dateColumn, isTable)
|
|
799
|
-
);
|
|
800
|
-
return sortedData;
|
|
690
|
+
const now = dayjsWithPlugins_default().tz(timezone2);
|
|
691
|
+
const weekdayNumber = WEEKDAY_NAMES_SUN.findIndex((day) => weekDay.toLowerCase() === day.toLowerCase());
|
|
692
|
+
const nextWeekday = now.day(weekdayNumber).startOf("minute");
|
|
693
|
+
const nextWeekdayWithTime = nextWeekday.hour(timeObj.hour24).minute(timeObj.minute);
|
|
694
|
+
if (nextWeekdayWithTime.valueOf() < now.valueOf()) {
|
|
695
|
+
return nextWeekdayWithTime.add(1, "week").format("YYYY-MM-DD[T]HH:mm:00");
|
|
801
696
|
}
|
|
697
|
+
return nextWeekdayWithTime.format("YYYY-MM-DD[T]HH:mm:00");
|
|
802
698
|
} catch (error) {
|
|
803
699
|
console.error(error);
|
|
700
|
+
return;
|
|
804
701
|
}
|
|
805
|
-
return data;
|
|
806
702
|
};
|
|
807
|
-
var
|
|
808
|
-
element,
|
|
809
|
-
column,
|
|
810
|
-
config = dataFormattingDefault,
|
|
811
|
-
htmlElement,
|
|
812
|
-
isChart = false
|
|
813
|
-
}) => {
|
|
703
|
+
var getMonthLocalStartDate = ({ monthDay, timeObj, timezone: timezone2 }) => {
|
|
814
704
|
try {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
705
|
+
const now = dayjsWithPlugins_default().tz(timezone2);
|
|
706
|
+
let nextMonthStr;
|
|
707
|
+
if (monthDay === "LAST") {
|
|
708
|
+
nextMonthStr = now.endOf("month").startOf("day").format("ll HH:mm");
|
|
709
|
+
} else if (monthDay === "FIRST") {
|
|
710
|
+
nextMonthStr = now.add(1, "month").startOf("month").format("ll HH:mm");
|
|
820
711
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
case "DOLLAR_AMT": {
|
|
827
|
-
const elementNumber = parseFloat(`${element}`);
|
|
828
|
-
if (!isNaN(elementNumber)) {
|
|
829
|
-
const currency = currencyCode || "USD";
|
|
830
|
-
const validatedCurrencyDecimals = currencyDecimals || currencyDecimals === 0 ? currencyDecimals : void 0;
|
|
831
|
-
try {
|
|
832
|
-
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
833
|
-
style: "currency",
|
|
834
|
-
currency: `${currency}`,
|
|
835
|
-
minimumFractionDigits: validatedCurrencyDecimals,
|
|
836
|
-
maximumFractionDigits: validatedCurrencyDecimals
|
|
837
|
-
}).format(elementNumber);
|
|
838
|
-
} catch (error) {
|
|
839
|
-
console.error(error);
|
|
840
|
-
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
841
|
-
style: "currency",
|
|
842
|
-
currency: "USD",
|
|
843
|
-
minimumFractionDigits: validatedCurrencyDecimals,
|
|
844
|
-
maximumFractionDigits: validatedCurrencyDecimals
|
|
845
|
-
}).format(elementNumber);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
break;
|
|
849
|
-
}
|
|
850
|
-
case "QUANTITY": {
|
|
851
|
-
const validatedQuantityDecimals = !isNaN(quantityDecimals) ? quantityDecimals : 2;
|
|
852
|
-
const elementNumber = parseFloat(`${element}`);
|
|
853
|
-
if (!isNaN(elementNumber)) {
|
|
854
|
-
const numDecimals = elementNumber % 1 !== 0 ? validatedQuantityDecimals : 0;
|
|
855
|
-
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
856
|
-
minimumFractionDigits: numDecimals,
|
|
857
|
-
maximumFractionDigits: numDecimals
|
|
858
|
-
}).format(elementNumber);
|
|
859
|
-
}
|
|
860
|
-
break;
|
|
861
|
-
}
|
|
862
|
-
case "DATE": {
|
|
863
|
-
formattedElement = formatDateType(element, column, config);
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
case "DATE_STRING": {
|
|
867
|
-
formattedElement = formatDateStringType(element, column, config);
|
|
868
|
-
break;
|
|
869
|
-
}
|
|
870
|
-
case "RATIO": {
|
|
871
|
-
const numDecimals = !isNaN(ratioDecimals) ? ratioDecimals : 4;
|
|
872
|
-
const elementNumber = parseFloat(`${element}`);
|
|
873
|
-
if (!isNaN(elementNumber)) {
|
|
874
|
-
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
875
|
-
minimumFractionDigits: numDecimals,
|
|
876
|
-
maximumFractionDigits: numDecimals
|
|
877
|
-
}).format(elementNumber);
|
|
878
|
-
}
|
|
879
|
-
break;
|
|
880
|
-
}
|
|
881
|
-
case "PERCENT": {
|
|
882
|
-
const elementNumber = parseFloat(`${element}`);
|
|
883
|
-
if (!isNaN(elementNumber)) {
|
|
884
|
-
const p = elementNumber / 100;
|
|
885
|
-
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
886
|
-
style: "percent",
|
|
887
|
-
minimumFractionDigits: 2,
|
|
888
|
-
maximumFractionDigits: 2
|
|
889
|
-
}).format(p);
|
|
890
|
-
if (htmlElement) {
|
|
891
|
-
if (elementNumber < 0) {
|
|
892
|
-
htmlElement.classList.add("comparison-value-negative");
|
|
893
|
-
} else if (elementNumber > 0) {
|
|
894
|
-
htmlElement.classList.add("comparison-value-positive");
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
break;
|
|
899
|
-
}
|
|
900
|
-
default: {
|
|
901
|
-
break;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
return formattedElement;
|
|
712
|
+
const nextMonth = dayjsWithPlugins_default.tz(nextMonthStr, timezone2);
|
|
713
|
+
const nextMonthWithTime = nextMonth.hour(timeObj.hour24).minute(timeObj.minute);
|
|
714
|
+
return nextMonthWithTime.format("YYYY-MM-DD[T]HH:mm:00");
|
|
906
715
|
} catch (error) {
|
|
907
716
|
console.error(error);
|
|
908
|
-
return
|
|
717
|
+
return;
|
|
909
718
|
}
|
|
910
719
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
720
|
+
|
|
721
|
+
// src/Constants/dataAlertConstants.ts
|
|
722
|
+
var CUSTOM_TYPE = "CUSTOM";
|
|
723
|
+
var PROJECT_TYPE = "PROJECT";
|
|
724
|
+
var PERIODIC_TYPE = "PERIODIC";
|
|
725
|
+
var CONTINUOUS_TYPE = "CONTINUOUS";
|
|
726
|
+
var SCHEDULED_TYPE = "SCHEDULED";
|
|
727
|
+
var COMPARE_TYPE = "COMPARE";
|
|
728
|
+
var EXISTS_TYPE = "EXISTS";
|
|
729
|
+
var NUMBER_TERM_TYPE = "CONSTANT";
|
|
730
|
+
var QUERY_TERM_TYPE = "QUERY";
|
|
731
|
+
var GROUP_TERM_TYPE = "GROUP";
|
|
732
|
+
var DEFAULT_EVALUATION_FREQUENCY = 5;
|
|
733
|
+
var DATA_ALERT_STATUSES = {
|
|
734
|
+
ACTIVE: "ACTIVE",
|
|
735
|
+
// currently running
|
|
736
|
+
RETRY: "RETRY",
|
|
737
|
+
// currently being retried because of an error, no action required yet
|
|
738
|
+
WAITING: "WAITING",
|
|
739
|
+
// active but triggered already and waiting for the reset period to end
|
|
740
|
+
INACTIVE: "INACTIVE",
|
|
741
|
+
// either not running OR it is a prototype (can not be run)
|
|
742
|
+
EVALUATION_ERROR: "EVALUATION_ERROR",
|
|
743
|
+
// expression evaluation resulted in an error
|
|
744
|
+
DATA_RETURN_ERROR: "DATA_RETURN_ERROR",
|
|
745
|
+
// expression evaluation was successful, but data return query failed
|
|
746
|
+
GENERAL_ERROR: "GENERAL_ERROR"
|
|
747
|
+
// every thing else that doesnt fall into a category above
|
|
748
|
+
};
|
|
749
|
+
var DATA_ALERT_ENABLED_STATUSES = [
|
|
750
|
+
DATA_ALERT_STATUSES.ACTIVE,
|
|
751
|
+
DATA_ALERT_STATUSES.RETRY,
|
|
752
|
+
DATA_ALERT_STATUSES.WAITING
|
|
753
|
+
];
|
|
754
|
+
var DATA_ALERT_OPERATORS = {
|
|
755
|
+
GREATER_THAN: {
|
|
756
|
+
displayName: `
|
|
757
|
+
<span>
|
|
758
|
+
Is <strong>greater</strong> than
|
|
759
|
+
</span>
|
|
760
|
+
`,
|
|
761
|
+
symbol: ">",
|
|
762
|
+
conditionText: "exceeds",
|
|
763
|
+
conditionTextPast: "exceeded"
|
|
764
|
+
},
|
|
765
|
+
GREATER_THAN_EQUAL_TO: {
|
|
766
|
+
displayName: `
|
|
767
|
+
<span>
|
|
768
|
+
Is <strong>greater</strong> than <strong>or equal</strong> to
|
|
769
|
+
</span>
|
|
770
|
+
`,
|
|
771
|
+
symbol: ">=",
|
|
772
|
+
conditionText: "is equal to or exceeds",
|
|
773
|
+
conditionTextPast: "was equal to or exceeded"
|
|
774
|
+
},
|
|
775
|
+
LESS_THAN: {
|
|
776
|
+
displayName: `
|
|
777
|
+
<span>
|
|
778
|
+
Is <strong>less</strong> than
|
|
779
|
+
</span>
|
|
780
|
+
`,
|
|
781
|
+
symbol: "<",
|
|
782
|
+
conditionText: "falls below",
|
|
783
|
+
conditionTextPast: "fell below"
|
|
784
|
+
},
|
|
785
|
+
LESS_THAN_EQUAL_TO: {
|
|
786
|
+
displayName: `
|
|
787
|
+
<span>
|
|
788
|
+
Is <strong>less</strong> than <strong>or equal</strong> to
|
|
789
|
+
</span>
|
|
790
|
+
`,
|
|
791
|
+
symbol: "<=",
|
|
792
|
+
conditionText: "is equal to or falls below",
|
|
793
|
+
conditionTextPast: "was equal to or fell below"
|
|
794
|
+
},
|
|
795
|
+
EQUAL_TO: {
|
|
796
|
+
displayName: `
|
|
797
|
+
<span>
|
|
798
|
+
Is <strong>equal</strong> to
|
|
799
|
+
</span>
|
|
800
|
+
`,
|
|
801
|
+
symbol: "=",
|
|
802
|
+
conditionText: "equals",
|
|
803
|
+
conditionTextPast: "was equal to"
|
|
804
|
+
}
|
|
805
|
+
/* Not using this for now. Uncomment to enable later if desired
|
|
806
|
+
NOT_EQUAL_TO: {
|
|
807
|
+
displayName: (
|
|
808
|
+
<span>
|
|
809
|
+
Is <strong>not equal</strong> to
|
|
810
|
+
</span>
|
|
811
|
+
),
|
|
812
|
+
symbol: '!=',
|
|
813
|
+
conditionText: 'does not equal',
|
|
814
|
+
conditionTextPast: 'was not equal to',
|
|
815
|
+
}, */
|
|
816
|
+
/* These are additions term condition values
|
|
817
|
+
They can be used to create more complex condition groups
|
|
818
|
+
EXISTS: {},
|
|
819
|
+
NOT_EXISTS: {},
|
|
820
|
+
AND: {},
|
|
821
|
+
OR: {},
|
|
822
|
+
TERMINATOR: {} */
|
|
823
|
+
};
|
|
824
|
+
var DATA_ALERT_CONDITION_TYPES = {
|
|
825
|
+
[COMPARE_TYPE]: {
|
|
826
|
+
displayName: "When a specific condition is met"
|
|
827
|
+
},
|
|
828
|
+
[EXISTS_TYPE]: {
|
|
829
|
+
displayName: "If new data is detected"
|
|
931
830
|
}
|
|
932
|
-
return { minimumFractionDigits, maximumFractionDigits, notation };
|
|
933
831
|
};
|
|
934
|
-
var
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
832
|
+
var DATA_ALERT_FREQUENCY_TYPE_OPTIONS = {
|
|
833
|
+
[SCHEDULED_TYPE]: {
|
|
834
|
+
label: "at the following times:",
|
|
835
|
+
listLabel: "at the following times"
|
|
836
|
+
},
|
|
837
|
+
[CONTINUOUS_TYPE]: {
|
|
838
|
+
label: "right away.",
|
|
839
|
+
listLabel: "right away"
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
var SCHEDULE_INTERVAL_OPTIONS = {
|
|
843
|
+
DAY: {
|
|
844
|
+
displayName: `
|
|
845
|
+
<span>
|
|
846
|
+
Every <strong>day</strong>
|
|
847
|
+
</span>
|
|
848
|
+
`,
|
|
849
|
+
getLocalStartDate: getDayLocalStartDate
|
|
850
|
+
},
|
|
851
|
+
WEEK: {
|
|
852
|
+
displayName: `
|
|
853
|
+
<span>
|
|
854
|
+
Every <strong>week</strong>
|
|
855
|
+
</span>
|
|
856
|
+
`,
|
|
857
|
+
getLocalStartDate: getWeekLocalStartDate
|
|
858
|
+
},
|
|
859
|
+
MONTH: {
|
|
860
|
+
displayName: `
|
|
861
|
+
<span>
|
|
862
|
+
Every <strong>month</strong>
|
|
863
|
+
</span>
|
|
864
|
+
`,
|
|
865
|
+
getLocalStartDate: getMonthLocalStartDate
|
|
866
|
+
}
|
|
867
|
+
// Not supporting for now
|
|
868
|
+
// YEAR: {
|
|
869
|
+
// displayName: (
|
|
870
|
+
// <span>
|
|
871
|
+
// Every <strong>year</strong>
|
|
872
|
+
// </span>
|
|
873
|
+
// ),
|
|
874
|
+
// displayText: 'Scheduled yearly',
|
|
875
|
+
// },
|
|
876
|
+
};
|
|
877
|
+
var SCHEDULE_FREQUENCY_OPTIONS = {
|
|
878
|
+
DAY: {
|
|
879
|
+
displayText: "Scheduled daily"
|
|
880
|
+
},
|
|
881
|
+
WEEK: {
|
|
882
|
+
displayText: "Scheduled weekly"
|
|
883
|
+
},
|
|
884
|
+
MONTH: {
|
|
885
|
+
displayText: "Scheduled for the 1st of every month"
|
|
886
|
+
},
|
|
887
|
+
MONTH_LAST_DAY: {
|
|
888
|
+
displayText: "Scheduled for the end of every month"
|
|
889
|
+
},
|
|
890
|
+
YEAR: {
|
|
891
|
+
displayText: "Scheduled yearly"
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
var RESET_PERIOD_OPTIONS = {
|
|
895
|
+
DAY: {
|
|
896
|
+
displayName: `
|
|
897
|
+
<span>
|
|
898
|
+
At most <strong>once a day</strong>
|
|
899
|
+
</span>
|
|
900
|
+
`,
|
|
901
|
+
displayText: "At most once a day"
|
|
902
|
+
},
|
|
903
|
+
WEEK: {
|
|
904
|
+
displayName: `
|
|
905
|
+
<span>
|
|
906
|
+
At most <strong>once a week</strong>
|
|
907
|
+
</span>
|
|
908
|
+
`,
|
|
909
|
+
displayText: "At most once a week"
|
|
910
|
+
},
|
|
911
|
+
MONTH: {
|
|
912
|
+
displayName: `
|
|
913
|
+
<span>
|
|
914
|
+
At most <strong>once a month</strong>
|
|
915
|
+
</span>
|
|
916
|
+
`,
|
|
917
|
+
displayText: "At most once a month"
|
|
918
|
+
},
|
|
919
|
+
// Not supporting for now
|
|
920
|
+
// YEAR: {
|
|
921
|
+
// displayName: (
|
|
922
|
+
// <span>
|
|
923
|
+
// At most <strong>once a year</strong>
|
|
924
|
+
// </span>
|
|
925
|
+
// ),
|
|
926
|
+
// displayText: 'At most once a year'
|
|
927
|
+
// },
|
|
928
|
+
NONE: {
|
|
929
|
+
displayName: `
|
|
930
|
+
<span>
|
|
931
|
+
<strong>Every time</strong> new data is detected
|
|
932
|
+
</span>
|
|
933
|
+
`,
|
|
934
|
+
displayText: "Continuous"
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
var MONTH_DAY_SELECT_OPTIONS = {
|
|
938
|
+
FIRST: `
|
|
939
|
+
<span>
|
|
940
|
+
on the <strong>first day</strong>
|
|
941
|
+
</span>
|
|
942
|
+
`,
|
|
943
|
+
LAST: `
|
|
944
|
+
<span>
|
|
945
|
+
on the <strong>last day</strong>
|
|
946
|
+
</span>
|
|
947
|
+
`
|
|
948
|
+
};
|
|
949
|
+
var EVALUATION_FREQUENCY_OPTIONS = {
|
|
950
|
+
1: {
|
|
951
|
+
value: 1,
|
|
952
|
+
label: "1 min"
|
|
953
|
+
},
|
|
954
|
+
2: {
|
|
955
|
+
value: 2,
|
|
956
|
+
label: "2 mins"
|
|
957
|
+
},
|
|
958
|
+
3: {
|
|
959
|
+
value: 3,
|
|
960
|
+
label: "3 mins"
|
|
961
|
+
},
|
|
962
|
+
5: {
|
|
963
|
+
value: 5,
|
|
964
|
+
label: "5 mins",
|
|
965
|
+
listLabel: `
|
|
966
|
+
<span>
|
|
967
|
+
5 mins <em>(Recommended)</em>
|
|
968
|
+
</span>
|
|
969
|
+
`
|
|
970
|
+
},
|
|
971
|
+
10: {
|
|
972
|
+
value: 10,
|
|
973
|
+
label: "10 mins"
|
|
974
|
+
},
|
|
975
|
+
30: {
|
|
976
|
+
value: 30,
|
|
977
|
+
label: "30 mins"
|
|
978
|
+
},
|
|
979
|
+
60: {
|
|
980
|
+
value: 60,
|
|
981
|
+
label: "60 mins"
|
|
947
982
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
// src/Constants/queryConstants.ts
|
|
986
|
+
var DEFAULT_SOURCE = "widgets";
|
|
987
|
+
|
|
988
|
+
// src/Constants/enums.ts
|
|
989
|
+
var TimestampFormats = /* @__PURE__ */ ((TimestampFormats2) => {
|
|
990
|
+
TimestampFormats2["epoch"] = "EPOCH";
|
|
991
|
+
TimestampFormats2["iso8601"] = "ISO8601";
|
|
992
|
+
return TimestampFormats2;
|
|
993
|
+
})(TimestampFormats || {});
|
|
994
|
+
var PrecisionTypes = /* @__PURE__ */ ((PrecisionTypes2) => {
|
|
995
|
+
PrecisionTypes2["DAY"] = "DAY";
|
|
996
|
+
PrecisionTypes2["MONTH"] = "MONTH";
|
|
997
|
+
PrecisionTypes2["YEAR"] = "YEAR";
|
|
998
|
+
PrecisionTypes2["WEEK"] = "WEEK";
|
|
999
|
+
PrecisionTypes2["QUARTER"] = "QUARTER";
|
|
1000
|
+
PrecisionTypes2["DATE_HOUR"] = "DATE_HOUR";
|
|
1001
|
+
PrecisionTypes2["DATE_MINUTE"] = "DATE_MINUTE";
|
|
1002
|
+
PrecisionTypes2["HOUR"] = "HOUR";
|
|
1003
|
+
PrecisionTypes2["MINUTE"] = "MINUTE";
|
|
1004
|
+
return PrecisionTypes2;
|
|
1005
|
+
})(PrecisionTypes || {});
|
|
1006
|
+
var NumberColumnTypes = /* @__PURE__ */ ((NumberColumnTypes2) => {
|
|
1007
|
+
NumberColumnTypes2["CURRENCY"] = "DOLLAR_AMT";
|
|
1008
|
+
NumberColumnTypes2["QUANTITY"] = "QUANTITY";
|
|
1009
|
+
NumberColumnTypes2["RATIO"] = "RATIO";
|
|
1010
|
+
NumberColumnTypes2["PERCENT"] = "PERCENT";
|
|
1011
|
+
return NumberColumnTypes2;
|
|
1012
|
+
})(NumberColumnTypes || {});
|
|
1013
|
+
var NumberColumnTypeDisplayNames = /* @__PURE__ */ ((NumberColumnTypeDisplayNames2) => {
|
|
1014
|
+
NumberColumnTypeDisplayNames2["DOLLAR_AMT"] = "Currency";
|
|
1015
|
+
NumberColumnTypeDisplayNames2["QUANTITY"] = "Quantity";
|
|
1016
|
+
NumberColumnTypeDisplayNames2["RATIO"] = "Ratio";
|
|
1017
|
+
NumberColumnTypeDisplayNames2["PERCENT"] = "Percent";
|
|
1018
|
+
return NumberColumnTypeDisplayNames2;
|
|
1019
|
+
})(NumberColumnTypeDisplayNames || {});
|
|
1020
|
+
var DataExplorerTypes = /* @__PURE__ */ ((DataExplorerTypes2) => {
|
|
1021
|
+
DataExplorerTypes2["SUBJECT_TYPE"] = "subject";
|
|
1022
|
+
DataExplorerTypes2["VL_TYPE"] = "VL";
|
|
1023
|
+
return DataExplorerTypes2;
|
|
1024
|
+
})(DataExplorerTypes || {});
|
|
1025
|
+
|
|
1026
|
+
// src/Constants/defaults.ts
|
|
1027
|
+
var authenticationDefault = {
|
|
1028
|
+
token: void 0,
|
|
1029
|
+
apiKey: void 0,
|
|
1030
|
+
domain: void 0,
|
|
1031
|
+
dprKey: void 0,
|
|
1032
|
+
dprDomain: void 0
|
|
1033
|
+
};
|
|
1034
|
+
var dataFormattingDefault = {
|
|
1035
|
+
timestampFormat: "ISO8601" /* iso8601 */,
|
|
1036
|
+
currencyCode: "USD",
|
|
1037
|
+
languageCode: "en-US",
|
|
1038
|
+
currencyDecimals: 2,
|
|
1039
|
+
quantityDecimals: 2,
|
|
1040
|
+
ratioDecimals: 4,
|
|
1041
|
+
comparisonDisplay: "PERCENT",
|
|
1042
|
+
monthYearFormat: "MMMM YYYY",
|
|
1043
|
+
dayMonthYearFormat: "ll"
|
|
1044
|
+
};
|
|
1045
|
+
var autoQLConfigDefault = {
|
|
1046
|
+
debug: false,
|
|
1047
|
+
test: false,
|
|
1048
|
+
enableAutocomplete: true,
|
|
1049
|
+
enableQueryInterpretation: true,
|
|
1050
|
+
enableQueryValidation: true,
|
|
1051
|
+
enableQuerySuggestions: true,
|
|
1052
|
+
enableColumnVisibilityManager: true,
|
|
1053
|
+
enableDrilldowns: true,
|
|
1054
|
+
enableNotifications: false,
|
|
1055
|
+
enableCSVDownload: true,
|
|
1056
|
+
enableReportProblem: true
|
|
1057
|
+
};
|
|
1058
|
+
var dataConfigDefault = {
|
|
1059
|
+
stringColumnIndices: [],
|
|
1060
|
+
numberColumnIndices: [],
|
|
1061
|
+
stringColumnIndex: 0,
|
|
1062
|
+
legendColumnIndex: void 0,
|
|
1063
|
+
numberColumnIndex: 1
|
|
1064
|
+
};
|
|
1065
|
+
var getAuthentication = (prop = {}) => {
|
|
1066
|
+
return {
|
|
1067
|
+
...authenticationDefault,
|
|
1068
|
+
...prop
|
|
1069
|
+
};
|
|
1070
|
+
};
|
|
1071
|
+
var getDataFormatting = (prop = {}) => {
|
|
1072
|
+
return {
|
|
1073
|
+
...dataFormattingDefault,
|
|
1074
|
+
...prop
|
|
1075
|
+
};
|
|
1076
|
+
};
|
|
1077
|
+
var getAutoQLConfig = (prop = {}) => {
|
|
1078
|
+
return {
|
|
1079
|
+
...autoQLConfigDefault,
|
|
1080
|
+
...prop
|
|
1081
|
+
};
|
|
1082
|
+
};
|
|
1083
|
+
var getDataConfig = (prop = {}) => {
|
|
1084
|
+
return {
|
|
1085
|
+
...dataConfigDefault,
|
|
1086
|
+
...prop
|
|
1087
|
+
};
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
// src/HelperFns/dataFormattingHelpers.ts
|
|
1091
|
+
var formatStringDateWithPrecision = (value, col) => {
|
|
1092
|
+
if (!value) {
|
|
1093
|
+
return void 0;
|
|
953
1094
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
column: column ?? (scale == null ? void 0 : scale.column),
|
|
960
|
-
config: dataFormatting,
|
|
961
|
-
isChart: true
|
|
962
|
-
});
|
|
963
|
-
} else {
|
|
964
|
-
switch (type) {
|
|
965
|
-
case "STRING": {
|
|
1095
|
+
let formattedValue = value;
|
|
1096
|
+
try {
|
|
1097
|
+
switch (col.precision) {
|
|
1098
|
+
case "DOW": {
|
|
1099
|
+
formattedValue = formatDOW(value, col);
|
|
966
1100
|
break;
|
|
967
1101
|
}
|
|
968
|
-
case "
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
const currencyConfig = {
|
|
973
|
-
style,
|
|
974
|
-
minimumFractionDigits,
|
|
975
|
-
maximumFractionDigits,
|
|
976
|
-
notation
|
|
977
|
-
};
|
|
978
|
-
try {
|
|
979
|
-
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
980
|
-
...currencyConfig,
|
|
981
|
-
currency
|
|
982
|
-
}).format(d);
|
|
983
|
-
} catch (error) {
|
|
984
|
-
console.error(error);
|
|
985
|
-
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
986
|
-
...currencyConfig,
|
|
987
|
-
currency: "USD"
|
|
988
|
-
}).format(d);
|
|
989
|
-
}
|
|
1102
|
+
case "HOUR": {
|
|
1103
|
+
const dayjsTime = dayjsWithPlugins_default.utc(value, "THH:mm:ss.SSSZ").utc();
|
|
1104
|
+
if (dayjsTime.isValid()) {
|
|
1105
|
+
formattedValue = dayjsTime.format("h:00A");
|
|
990
1106
|
}
|
|
991
1107
|
break;
|
|
992
1108
|
}
|
|
993
|
-
case "
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
maximumFractionDigits,
|
|
998
|
-
notation
|
|
999
|
-
}).format(d);
|
|
1109
|
+
case "MINUTE": {
|
|
1110
|
+
const dayjsTime = dayjsWithPlugins_default.utc(value, "THH:mm:ss.SSSZ").utc();
|
|
1111
|
+
if (dayjsTime.isValid()) {
|
|
1112
|
+
formattedValue = dayjsTime.format("h:mmA");
|
|
1000
1113
|
}
|
|
1001
1114
|
break;
|
|
1002
1115
|
}
|
|
1003
|
-
case "
|
|
1004
|
-
|
|
1005
|
-
break;
|
|
1006
|
-
}
|
|
1007
|
-
case "DATE_STRING": {
|
|
1008
|
-
formattedLabel = formatDateStringType(d, col, config);
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
case "PERCENT": {
|
|
1012
|
-
if (Number(d) || Number(d) === 0) {
|
|
1013
|
-
const p = Number(d) / 100;
|
|
1014
|
-
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
1015
|
-
style: "percent",
|
|
1016
|
-
minimumFractionDigits: 1,
|
|
1017
|
-
maximumFractionDigits: 1
|
|
1018
|
-
}).format(p);
|
|
1019
|
-
}
|
|
1116
|
+
case "MONTH": {
|
|
1117
|
+
formattedValue = value;
|
|
1020
1118
|
break;
|
|
1021
1119
|
}
|
|
1022
1120
|
default: {
|
|
1121
|
+
formattedValue = value;
|
|
1023
1122
|
break;
|
|
1024
1123
|
}
|
|
1025
1124
|
}
|
|
1125
|
+
return formattedValue;
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
console.error(error);
|
|
1128
|
+
return value;
|
|
1026
1129
|
}
|
|
1027
|
-
const fullWidthLabel = formattedLabel;
|
|
1028
|
-
if (typeof formattedLabel === "string" && maxLabelWidth && formattedLabel.length > maxLabelWidth) {
|
|
1029
|
-
formattedLabel = `${formattedLabel.substring(0, maxLabelWidth)}...`;
|
|
1030
|
-
}
|
|
1031
|
-
return { fullWidthLabel, formattedLabel };
|
|
1032
1130
|
};
|
|
1033
|
-
var
|
|
1131
|
+
var formatStringDate = (value, config = dataFormattingDefault) => {
|
|
1034
1132
|
var _a;
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
const formattedParts = new Intl.NumberFormat(languageCode, {
|
|
1038
|
-
style: "currency",
|
|
1039
|
-
currency: currencyCode
|
|
1040
|
-
}).formatToParts(0);
|
|
1041
|
-
const symbol = (_a = formattedParts.find((part) => (part == null ? void 0 : part.type) === "currency")) == null ? void 0 : _a.value;
|
|
1042
|
-
return symbol;
|
|
1043
|
-
} catch (error) {
|
|
1044
|
-
console.error(error);
|
|
1045
|
-
return;
|
|
1133
|
+
if (!value) {
|
|
1134
|
+
return void 0;
|
|
1046
1135
|
}
|
|
1136
|
+
if (value && typeof value === "string") {
|
|
1137
|
+
const dateArray = value.split("-");
|
|
1138
|
+
const year = dateArray == null ? void 0 : dateArray[0];
|
|
1139
|
+
const day = dateArray == null ? void 0 : dateArray[2];
|
|
1140
|
+
let month;
|
|
1141
|
+
let week;
|
|
1142
|
+
if ((_a = dateArray == null ? void 0 : dateArray[1]) == null ? void 0 : _a.includes("W")) {
|
|
1143
|
+
week = dateArray == null ? void 0 : dateArray[1];
|
|
1144
|
+
} else {
|
|
1145
|
+
month = dateArray == null ? void 0 : dateArray[1];
|
|
1146
|
+
}
|
|
1147
|
+
const { monthYearFormat, dayMonthYearFormat } = getDataFormatting(config);
|
|
1148
|
+
const dayJSObj = dayjsWithPlugins_default.utc(value).utc();
|
|
1149
|
+
if (!dayJSObj.isValid()) {
|
|
1150
|
+
return value;
|
|
1151
|
+
}
|
|
1152
|
+
let date = value;
|
|
1153
|
+
if (day) {
|
|
1154
|
+
date = dayJSObj.format(dayMonthYearFormat);
|
|
1155
|
+
} else if (month) {
|
|
1156
|
+
date = dayJSObj.format(monthYearFormat);
|
|
1157
|
+
} else if (week) {
|
|
1158
|
+
} else if (year) {
|
|
1159
|
+
date = year;
|
|
1160
|
+
}
|
|
1161
|
+
return date;
|
|
1162
|
+
}
|
|
1163
|
+
return value;
|
|
1047
1164
|
};
|
|
1048
|
-
var
|
|
1165
|
+
var formatDateType = (element, column, config = dataFormattingDefault) => {
|
|
1166
|
+
if (isNumber(element)) {
|
|
1167
|
+
return formatEpochDate(element, column, config);
|
|
1168
|
+
}
|
|
1169
|
+
return formatISODateWithPrecision(element, column, config);
|
|
1170
|
+
};
|
|
1171
|
+
var formatDateStringType = (element, column, config = dataFormattingDefault) => {
|
|
1172
|
+
if (!column) {
|
|
1173
|
+
return element;
|
|
1174
|
+
}
|
|
1175
|
+
if (column.precision) {
|
|
1176
|
+
return formatStringDateWithPrecision(element, column);
|
|
1177
|
+
}
|
|
1178
|
+
return formatStringDate(element, config);
|
|
1179
|
+
};
|
|
1180
|
+
var formatISODateWithPrecision = (value, col, config = dataFormattingDefault) => {
|
|
1049
1181
|
if (!value) {
|
|
1050
1182
|
return void 0;
|
|
1051
1183
|
}
|
|
1184
|
+
if (!col) {
|
|
1185
|
+
return value;
|
|
1186
|
+
}
|
|
1187
|
+
const precision = col.precision;
|
|
1188
|
+
const { dayMonthYearFormat, monthYearFormat } = getDataFormatting(config);
|
|
1189
|
+
const dateDayJS = dayjsWithPlugins_default.utc(value).utc();
|
|
1190
|
+
if (!dateDayJS.isValid()) {
|
|
1191
|
+
return value;
|
|
1192
|
+
}
|
|
1193
|
+
let date = dateDayJS.format(dayMonthYearFormat);
|
|
1052
1194
|
try {
|
|
1053
|
-
switch (
|
|
1054
|
-
case "
|
|
1055
|
-
|
|
1195
|
+
switch (precision) {
|
|
1196
|
+
case "DAY" /* DAY */: {
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
case "WEEK" /* WEEK */: {
|
|
1200
|
+
const dateJSStart = dateDayJS.startOf("week").format("MMM D");
|
|
1201
|
+
const dateJSEnd = dateDayJS.endOf("week").format("MMM D");
|
|
1202
|
+
const week = dateDayJS.week();
|
|
1203
|
+
const year = dateDayJS.format("YYYY");
|
|
1204
|
+
date = `${dateJSStart} - ${dateJSEnd}, ${year} (Week ${week})`;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
case "MONTH" /* MONTH */: {
|
|
1208
|
+
date = dateDayJS.format(monthYearFormat);
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
case "QUARTER" /* QUARTER */: {
|
|
1212
|
+
const quarter = dateDayJS.quarter();
|
|
1213
|
+
const year = dateDayJS.format("YYYY");
|
|
1214
|
+
date = `${year}-Q${quarter}`;
|
|
1215
|
+
break;
|
|
1056
1216
|
}
|
|
1057
|
-
case "
|
|
1058
|
-
|
|
1059
|
-
|
|
1217
|
+
case "YEAR" /* YEAR */: {
|
|
1218
|
+
date = dateDayJS.format("YYYY");
|
|
1219
|
+
break;
|
|
1060
1220
|
}
|
|
1061
|
-
case "
|
|
1062
|
-
|
|
1221
|
+
case "DATE_HOUR" /* DATE_HOUR */: {
|
|
1222
|
+
date = dateDayJS.format(`${dayMonthYearFormat} h:00A`);
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
case "DATE_MINUTE" /* DATE_MINUTE */: {
|
|
1226
|
+
date = dateDayJS.format(`${dayMonthYearFormat} h:mmA`);
|
|
1227
|
+
break;
|
|
1063
1228
|
}
|
|
1064
1229
|
default: {
|
|
1065
|
-
|
|
1230
|
+
break;
|
|
1066
1231
|
}
|
|
1067
1232
|
}
|
|
1233
|
+
return date;
|
|
1068
1234
|
} catch (error) {
|
|
1069
1235
|
console.error(error);
|
|
1070
|
-
return void 0;
|
|
1071
1236
|
}
|
|
1072
1237
|
};
|
|
1073
|
-
var
|
|
1074
|
-
if (
|
|
1075
|
-
return
|
|
1238
|
+
var formatEpochDate = (value, col, config = dataFormattingDefault) => {
|
|
1239
|
+
if (!value) {
|
|
1240
|
+
return void 0;
|
|
1076
1241
|
}
|
|
1077
|
-
if (
|
|
1078
|
-
return
|
|
1242
|
+
if (!col) {
|
|
1243
|
+
return value;
|
|
1079
1244
|
}
|
|
1080
|
-
|
|
1081
|
-
};
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1245
|
+
try {
|
|
1246
|
+
const { monthYearFormat, dayMonthYearFormat } = getDataFormatting(config);
|
|
1247
|
+
const year = "YYYY";
|
|
1248
|
+
const monthYear = monthYearFormat;
|
|
1249
|
+
const dayMonthYear = dayMonthYearFormat;
|
|
1250
|
+
const title = col.title;
|
|
1251
|
+
let dayJSObj;
|
|
1252
|
+
if (isNaN(parseFloat(value))) {
|
|
1253
|
+
dayJSObj = dayjsWithPlugins_default.utc(value).utc();
|
|
1254
|
+
} else {
|
|
1255
|
+
dayJSObj = dayjsWithPlugins_default.unix(value).utc();
|
|
1088
1256
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
invertedArray[i][j] = array[j][i];
|
|
1257
|
+
if (!dayJSObj.isValid()) {
|
|
1258
|
+
return value;
|
|
1259
|
+
}
|
|
1260
|
+
let date = dayJSObj.format(dayMonthYear);
|
|
1261
|
+
if (isNaN(parseFloat(value))) {
|
|
1262
|
+
if (title && title.toLowerCase().includes("year")) {
|
|
1263
|
+
date = dayJSObj.format(year);
|
|
1264
|
+
} else if (title && title.toLowerCase().includes("month")) {
|
|
1265
|
+
date = dayJSObj.format(monthYear);
|
|
1266
|
+
}
|
|
1267
|
+
date = dayJSObj.format(dayMonthYear);
|
|
1268
|
+
} else if (title && title.toLowerCase().includes("year")) {
|
|
1269
|
+
date = dayJSObj.format(year);
|
|
1270
|
+
} else if (title && title.toLowerCase().includes("month")) {
|
|
1271
|
+
date = dayJSObj.format(monthYear);
|
|
1105
1272
|
}
|
|
1273
|
+
return date;
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
console.error(error);
|
|
1276
|
+
return value;
|
|
1106
1277
|
}
|
|
1107
|
-
return invertedArray;
|
|
1108
|
-
};
|
|
1109
|
-
var functionsEqual = (a, b) => {
|
|
1110
|
-
return (a == null ? void 0 : a.toString()) == (b == null ? void 0 : b.toString());
|
|
1111
|
-
};
|
|
1112
|
-
var isObject = (obj) => {
|
|
1113
|
-
return typeof obj === "object" && !Array.isArray(obj) && obj !== null && obj !== void 0;
|
|
1114
1278
|
};
|
|
1115
|
-
var
|
|
1116
|
-
|
|
1117
|
-
if (
|
|
1118
|
-
|
|
1119
|
-
}
|
|
1120
|
-
const objAIsObject = isObject(objA);
|
|
1121
|
-
const objBIsObject = isObject(objB);
|
|
1122
|
-
if (!objAIsObject || !objBIsObject) {
|
|
1123
|
-
return lodashIsEqual;
|
|
1124
|
-
}
|
|
1125
|
-
const keysA = Object.keys(objA);
|
|
1126
|
-
const keysB = Object.keys(objB);
|
|
1127
|
-
if (keysA.length !== keysB.length) {
|
|
1128
|
-
return false;
|
|
1279
|
+
var formatDOW = (value, col) => {
|
|
1280
|
+
let dowStyle = col.dow_style;
|
|
1281
|
+
if (!dowStyle) {
|
|
1282
|
+
dowStyle = "NUM_1_MON";
|
|
1129
1283
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1284
|
+
let formattedValue = value;
|
|
1285
|
+
let weekdayNumber = Number(value);
|
|
1286
|
+
switch (dowStyle) {
|
|
1287
|
+
case "NUM_1_MON": {
|
|
1288
|
+
const weekdays = WEEKDAY_NAMES_MON;
|
|
1289
|
+
const index = weekdayNumber - 1;
|
|
1290
|
+
if (index >= 0) {
|
|
1291
|
+
formattedValue = weekdays[index];
|
|
1292
|
+
} else {
|
|
1293
|
+
console.warn(`dow style is NUM_1_MON but the value could not be converted to a number: ${value}`);
|
|
1134
1294
|
}
|
|
1135
|
-
|
|
1136
|
-
return false;
|
|
1295
|
+
break;
|
|
1137
1296
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
if (!functionsEqual(objA[key], objB[key])) {
|
|
1146
|
-
diff.push({
|
|
1147
|
-
key,
|
|
1148
|
-
objA: objA[key],
|
|
1149
|
-
objB: objB[key]
|
|
1150
|
-
});
|
|
1297
|
+
case "NUM_1_SUN": {
|
|
1298
|
+
const weekdays = WEEKDAY_NAMES_SUN;
|
|
1299
|
+
const index = weekdayNumber - 1;
|
|
1300
|
+
if (index >= 0) {
|
|
1301
|
+
formattedValue = weekdays[index];
|
|
1302
|
+
} else {
|
|
1303
|
+
console.warn(`dow style is NUM_1_SUN but the value could not be converted to a number: ${value}`);
|
|
1151
1304
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
case "NUM_0_MON": {
|
|
1308
|
+
const weekdays = WEEKDAY_NAMES_MON;
|
|
1309
|
+
if (weekdayNumber >= 0) {
|
|
1310
|
+
formattedValue = weekdays[weekdayNumber];
|
|
1311
|
+
} else {
|
|
1312
|
+
console.warn(`dow style is NUM_0_MON but the value could not be converted to a number: ${value}`);
|
|
1313
|
+
}
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
case "NUM_0_SUN": {
|
|
1317
|
+
const weekdays = WEEKDAY_NAMES_SUN;
|
|
1318
|
+
if (weekdayNumber >= 0) {
|
|
1319
|
+
formattedValue = weekdays[weekdayNumber];
|
|
1320
|
+
} else {
|
|
1321
|
+
console.warn(`dow style is NUM_0_SUN but the value could not be converted to a number: ${value}`);
|
|
1322
|
+
}
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
case "ALPHA_MON":
|
|
1326
|
+
case "ALPHA_SUN": {
|
|
1327
|
+
const weekday = WEEKDAY_NAMES_MON.find((weekday2) => weekday2.toLowerCase().includes(value.trim().toLowerCase()));
|
|
1328
|
+
if (weekday) {
|
|
1329
|
+
formattedValue = weekday;
|
|
1330
|
+
} else {
|
|
1331
|
+
console.warn(`dow style is ALPHA but the value could not be matched to a weekday name: ${value}`);
|
|
1332
|
+
}
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
default: {
|
|
1336
|
+
console.warn(`could not format dow value. dow_style was not recognized: ${col.dow_style}`);
|
|
1337
|
+
break;
|
|
1158
1338
|
}
|
|
1159
|
-
});
|
|
1160
|
-
return diff;
|
|
1161
|
-
};
|
|
1162
|
-
var rotateArray = (array, n) => {
|
|
1163
|
-
const rotated = [...array];
|
|
1164
|
-
n = n % array.length;
|
|
1165
|
-
if (n < 0)
|
|
1166
|
-
n = array.length + n;
|
|
1167
|
-
for (let i = 0; i < n; i++) {
|
|
1168
|
-
rotated.unshift(rotated.pop());
|
|
1169
1339
|
}
|
|
1170
|
-
return
|
|
1340
|
+
return formattedValue;
|
|
1171
1341
|
};
|
|
1172
|
-
var
|
|
1173
|
-
|
|
1342
|
+
var dateStringSortFnWithoutPrecision = (a, b) => {
|
|
1343
|
+
if (a.includes("-W")) {
|
|
1344
|
+
const aDateYear = a.substring(0, 4);
|
|
1345
|
+
const bDateYear = b.substring(0, 4);
|
|
1346
|
+
if (aDateYear !== bDateYear) {
|
|
1347
|
+
return aDateYear - bDateYear;
|
|
1348
|
+
} else {
|
|
1349
|
+
const aDateWeek = a.substring(6, 8);
|
|
1350
|
+
const bDateWeek = b.substring(6, 8);
|
|
1351
|
+
return aDateWeek - bDateWeek;
|
|
1352
|
+
}
|
|
1353
|
+
} else if (WEEKDAY_NAMES_MON.includes(a.trim())) {
|
|
1354
|
+
const aDayIndex = WEEKDAY_NAMES_MON.findIndex((d) => d.toLowerCase().includes(a.trim().toLowerCase()));
|
|
1355
|
+
const bDayIndex = WEEKDAY_NAMES_MON.findIndex((d) => d.toLowerCase().includes(b.trim().toLowerCase()));
|
|
1356
|
+
let sortValue = a - b;
|
|
1357
|
+
if (aDayIndex >= 0 && bDayIndex >= 0) {
|
|
1358
|
+
sortValue = aDayIndex - bDayIndex;
|
|
1359
|
+
}
|
|
1360
|
+
return sortValue;
|
|
1361
|
+
} else if (MONTH_NAMES.includes(a.trim())) {
|
|
1362
|
+
const aMonthIndex = MONTH_NAMES.findIndex((m) => m === a.trim());
|
|
1363
|
+
const bMonthIndex = MONTH_NAMES.findIndex((m) => m === b.trim());
|
|
1364
|
+
if (aMonthIndex >= 0 && bMonthIndex >= 0) {
|
|
1365
|
+
return bMonthIndex - aMonthIndex;
|
|
1366
|
+
}
|
|
1367
|
+
return a - b;
|
|
1368
|
+
} else if (SEASON_NAMES.includes(a.substr(0, 2))) {
|
|
1369
|
+
const aSeasonIndex = SEASON_NAMES.findIndex((s) => s === a.substr(0, 2));
|
|
1370
|
+
const bSeasonIndex = SEASON_NAMES.findIndex((s) => s === b.substr(0, 2));
|
|
1371
|
+
const aYear = Number(a.substr(2));
|
|
1372
|
+
const bYear = Number(b.substr(2));
|
|
1373
|
+
if (aYear === bYear) {
|
|
1374
|
+
return aSeasonIndex - bSeasonIndex;
|
|
1375
|
+
}
|
|
1376
|
+
return aYear - bYear;
|
|
1377
|
+
}
|
|
1378
|
+
return a - b;
|
|
1174
1379
|
};
|
|
1175
|
-
var
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1380
|
+
var dateStringSortFn = (a, b, col) => {
|
|
1381
|
+
if (typeof a !== "string" || typeof b !== "string" || !col) {
|
|
1382
|
+
return a - b;
|
|
1383
|
+
}
|
|
1384
|
+
const aTrimmed = a.trim();
|
|
1385
|
+
const bTrimmed = b.trim();
|
|
1386
|
+
switch (col.precision) {
|
|
1387
|
+
case "DOW": {
|
|
1388
|
+
const dowStyle = col.dow_style ?? "ALPHA_MON";
|
|
1389
|
+
let aIndex = WEEKDAY_NAMES_MON.findIndex((dow) => dow.toLowerCase().includes(aTrimmed.toLowerCase()));
|
|
1390
|
+
let bIndex = WEEKDAY_NAMES_MON.findIndex((dow) => dow.toLowerCase().includes(bTrimmed.toLowerCase()));
|
|
1391
|
+
if (dowStyle === "ALPHA_SUN") {
|
|
1392
|
+
aIndex = WEEKDAY_NAMES_SUN.findIndex((dow) => dow.toLowerCase().includes(aTrimmed.toLowerCase()));
|
|
1393
|
+
bIndex = WEEKDAY_NAMES_SUN.findIndex((dow) => dow.toLowerCase().includes(bTrimmed.toLowerCase()));
|
|
1394
|
+
}
|
|
1395
|
+
return aIndex - bIndex;
|
|
1396
|
+
}
|
|
1397
|
+
case "HOUR":
|
|
1398
|
+
case "MINUTE": {
|
|
1399
|
+
const aDayjsTime = dayjsWithPlugins_default.utc(aTrimmed, "THH:mm:ss.SSSZ").utc();
|
|
1400
|
+
const bDayjsTime = dayjsWithPlugins_default.utc(bTrimmed, "THH:mm:ss.SSSZ").utc();
|
|
1401
|
+
return aDayjsTime.unix() - bDayjsTime.unix();
|
|
1402
|
+
}
|
|
1403
|
+
case "MONTH": {
|
|
1404
|
+
MONTH_NAMES;
|
|
1405
|
+
const aMonthIndex = MONTH_NAMES.findIndex((m) => m.toLowerCase() === aTrimmed.toLowerCase());
|
|
1406
|
+
const bMonthIndex = MONTH_NAMES.findIndex((m) => m.toLowerCase() === bTrimmed.toLowerCase());
|
|
1407
|
+
return aMonthIndex - bMonthIndex;
|
|
1408
|
+
}
|
|
1409
|
+
default: {
|
|
1410
|
+
return dateStringSortFnWithoutPrecision(aTrimmed, bTrimmed);
|
|
1181
1411
|
}
|
|
1182
1412
|
}
|
|
1183
|
-
return arr;
|
|
1184
|
-
};
|
|
1185
|
-
|
|
1186
|
-
// src/HelperFns/displayTypeHelpers.ts
|
|
1187
|
-
var isChartType = (type) => CHART_TYPES.includes(type);
|
|
1188
|
-
var isTableType = (type) => TABLE_TYPES.includes(type);
|
|
1189
|
-
var isDisplayTypeValid = (response, displayType, dataLength, pivotDataLength, columns, isDataLimited) => {
|
|
1190
|
-
var _a, _b;
|
|
1191
|
-
const supportedDisplayTypes = getSupportedDisplayTypes({
|
|
1192
|
-
response,
|
|
1193
|
-
columns: columns ?? ((_b = (_a = response == null ? void 0 : response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.columns),
|
|
1194
|
-
dataLength,
|
|
1195
|
-
pivotDataLength,
|
|
1196
|
-
isDataLimited
|
|
1197
|
-
});
|
|
1198
|
-
const isValid = displayType && supportedDisplayTypes.includes(displayType);
|
|
1199
|
-
return isValid;
|
|
1200
1413
|
};
|
|
1201
|
-
var
|
|
1202
|
-
|
|
1203
|
-
|
|
1414
|
+
var dateSortFn = (a, b, col, isTable) => {
|
|
1415
|
+
try {
|
|
1416
|
+
if (!a && !b) {
|
|
1417
|
+
return 0;
|
|
1418
|
+
} else if (!a && b) {
|
|
1419
|
+
return 1;
|
|
1420
|
+
} else if (a && !b || !col) {
|
|
1421
|
+
return -1;
|
|
1422
|
+
}
|
|
1423
|
+
let aDate = Number(a);
|
|
1424
|
+
let bDate = Number(b);
|
|
1425
|
+
let sortValue = aDate - bDate;
|
|
1426
|
+
if (isNaN(aDate) || isNaN(bDate)) {
|
|
1427
|
+
if (col.type === "DATE_STRING") {
|
|
1428
|
+
sortValue = dateStringSortFn(a, b, col);
|
|
1429
|
+
} else {
|
|
1430
|
+
sortValue = dayjsWithPlugins_default.utc(a).unix() - dayjsWithPlugins_default.utc(b).unix();
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (isTable && col.precision === "DOW") {
|
|
1434
|
+
sortValue = -1 * sortValue;
|
|
1435
|
+
}
|
|
1436
|
+
return sortValue;
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
console.error(error);
|
|
1439
|
+
return -1;
|
|
1204
1440
|
}
|
|
1205
|
-
const multiSeriesIndex = columns.findIndex((col) => col.multi_series === true);
|
|
1206
|
-
return multiSeriesIndex >= 0;
|
|
1207
1441
|
};
|
|
1208
|
-
var
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1442
|
+
var sortDataByDate = (data, tableColumns, sortDirection = "desc", isTable) => {
|
|
1443
|
+
try {
|
|
1444
|
+
if (!data || typeof data !== "object") {
|
|
1445
|
+
throw new Error("Could not sort data by date - no data supplied");
|
|
1446
|
+
}
|
|
1447
|
+
const dateColumnIndex = getDateColumnIndex(tableColumns);
|
|
1448
|
+
const dateColumn = tableColumns[dateColumnIndex];
|
|
1449
|
+
if (dateColumnIndex >= 0) {
|
|
1450
|
+
let multiplier = sortDirection === "desc" ? -1 : 1;
|
|
1451
|
+
const sortedData = [...data].sort(
|
|
1452
|
+
(a, b) => multiplier * dateSortFn(a[dateColumnIndex], b[dateColumnIndex], dateColumn, isTable)
|
|
1453
|
+
);
|
|
1454
|
+
return sortedData;
|
|
1455
|
+
}
|
|
1456
|
+
} catch (error) {
|
|
1457
|
+
console.error(error);
|
|
1214
1458
|
}
|
|
1215
|
-
return
|
|
1459
|
+
return data;
|
|
1216
1460
|
};
|
|
1217
|
-
var
|
|
1218
|
-
|
|
1219
|
-
|
|
1461
|
+
var formatElement = ({
|
|
1462
|
+
element,
|
|
1463
|
+
column,
|
|
1464
|
+
config = dataFormattingDefault,
|
|
1465
|
+
htmlElement,
|
|
1466
|
+
isChart = false
|
|
1467
|
+
}) => {
|
|
1468
|
+
try {
|
|
1469
|
+
let formattedElement = element;
|
|
1470
|
+
const { currencyCode, languageCode, currencyDecimals, quantityDecimals, ratioDecimals } = getDataFormatting(config);
|
|
1471
|
+
let type = column == null ? void 0 : column.type;
|
|
1472
|
+
if (isChart && ["count", "deviation", "variance"].includes(column == null ? void 0 : column.aggType)) {
|
|
1473
|
+
type = "QUANTITY";
|
|
1474
|
+
}
|
|
1475
|
+
if (column) {
|
|
1476
|
+
switch (type) {
|
|
1477
|
+
case "STRING": {
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
case "DOLLAR_AMT": {
|
|
1481
|
+
const elementNumber = parseFloat(`${element}`);
|
|
1482
|
+
if (!isNaN(elementNumber)) {
|
|
1483
|
+
const currency = currencyCode || "USD";
|
|
1484
|
+
const validatedCurrencyDecimals = currencyDecimals || currencyDecimals === 0 ? currencyDecimals : void 0;
|
|
1485
|
+
try {
|
|
1486
|
+
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
1487
|
+
style: "currency",
|
|
1488
|
+
currency: `${currency}`,
|
|
1489
|
+
minimumFractionDigits: validatedCurrencyDecimals,
|
|
1490
|
+
maximumFractionDigits: validatedCurrencyDecimals
|
|
1491
|
+
}).format(elementNumber);
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
console.error(error);
|
|
1494
|
+
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
1495
|
+
style: "currency",
|
|
1496
|
+
currency: "USD",
|
|
1497
|
+
minimumFractionDigits: validatedCurrencyDecimals,
|
|
1498
|
+
maximumFractionDigits: validatedCurrencyDecimals
|
|
1499
|
+
}).format(elementNumber);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
break;
|
|
1503
|
+
}
|
|
1504
|
+
case "QUANTITY": {
|
|
1505
|
+
const validatedQuantityDecimals = !isNaN(quantityDecimals) ? quantityDecimals : 2;
|
|
1506
|
+
const elementNumber = parseFloat(`${element}`);
|
|
1507
|
+
if (!isNaN(elementNumber)) {
|
|
1508
|
+
const numDecimals = elementNumber % 1 !== 0 ? validatedQuantityDecimals : 0;
|
|
1509
|
+
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
1510
|
+
minimumFractionDigits: numDecimals,
|
|
1511
|
+
maximumFractionDigits: numDecimals
|
|
1512
|
+
}).format(elementNumber);
|
|
1513
|
+
}
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
case "DATE": {
|
|
1517
|
+
formattedElement = formatDateType(element, column, config);
|
|
1518
|
+
break;
|
|
1519
|
+
}
|
|
1520
|
+
case "DATE_STRING": {
|
|
1521
|
+
formattedElement = formatDateStringType(element, column, config);
|
|
1522
|
+
break;
|
|
1523
|
+
}
|
|
1524
|
+
case "RATIO": {
|
|
1525
|
+
const numDecimals = !isNaN(ratioDecimals) ? ratioDecimals : 4;
|
|
1526
|
+
const elementNumber = parseFloat(`${element}`);
|
|
1527
|
+
if (!isNaN(elementNumber)) {
|
|
1528
|
+
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
1529
|
+
minimumFractionDigits: numDecimals,
|
|
1530
|
+
maximumFractionDigits: numDecimals
|
|
1531
|
+
}).format(elementNumber);
|
|
1532
|
+
}
|
|
1533
|
+
break;
|
|
1534
|
+
}
|
|
1535
|
+
case "PERCENT": {
|
|
1536
|
+
const elementNumber = parseFloat(`${element}`);
|
|
1537
|
+
if (!isNaN(elementNumber)) {
|
|
1538
|
+
const p = elementNumber / 100;
|
|
1539
|
+
formattedElement = new Intl.NumberFormat(languageCode, {
|
|
1540
|
+
style: "percent",
|
|
1541
|
+
minimumFractionDigits: 2,
|
|
1542
|
+
maximumFractionDigits: 2
|
|
1543
|
+
}).format(p);
|
|
1544
|
+
if (htmlElement) {
|
|
1545
|
+
if (elementNumber < 0) {
|
|
1546
|
+
htmlElement.classList.add("comparison-value-negative");
|
|
1547
|
+
} else if (elementNumber > 0) {
|
|
1548
|
+
htmlElement.classList.add("comparison-value-positive");
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
default: {
|
|
1555
|
+
break;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
return formattedElement;
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
console.error(error);
|
|
1562
|
+
return element;
|
|
1220
1563
|
}
|
|
1221
|
-
const { amountOfNumberColumns, amountOfStringColumns } = getColumnTypeAmounts(columns);
|
|
1222
|
-
return amountOfNumberColumns > 0 && amountOfStringColumns > 0;
|
|
1223
1564
|
};
|
|
1224
|
-
var
|
|
1565
|
+
var getNumberFormatConfig = (d, scale) => {
|
|
1225
1566
|
var _a, _b;
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
const
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
return row[groupbyColumns[1]];
|
|
1245
|
-
})) ?? [];
|
|
1246
|
-
const uniqueData1Length = ((_a = column1Data == null ? void 0 : column1Data.filter(onlyUnique)) == null ? void 0 : _a.length) ?? 0;
|
|
1247
|
-
const uniqueData2Length = ((_b = column2Data == null ? void 0 : column2Data.filter(onlyUnique)) == null ? void 0 : _b.length) ?? 0;
|
|
1248
|
-
if (uniqueData1Length > MAX_LEGEND_LABELS && uniqueData2Length > MAX_LEGEND_LABELS) {
|
|
1249
|
-
console.debug(
|
|
1250
|
-
`Info: Pivot table will not be supported since there are too many unique fields. The calculated dimensions would be: ${uniqueData1Length} x ${uniqueData2Length}`
|
|
1251
|
-
);
|
|
1252
|
-
return false;
|
|
1567
|
+
let minimumFractionDigits = 0;
|
|
1568
|
+
let maximumFractionDigits = 0;
|
|
1569
|
+
let notation;
|
|
1570
|
+
const domainRange = ((_a = scale == null ? void 0 : scale.domain()) == null ? void 0 : _a[1]) - ((_b = scale == null ? void 0 : scale.domain()) == null ? void 0 : _b[0]);
|
|
1571
|
+
const smallDomain = domainRange && domainRange < 10;
|
|
1572
|
+
const absValue = Math.abs(d);
|
|
1573
|
+
if (smallDomain) {
|
|
1574
|
+
minimumFractionDigits = 2;
|
|
1575
|
+
maximumFractionDigits = 2;
|
|
1576
|
+
} else if (absValue >= 1e3) {
|
|
1577
|
+
notation = "compact";
|
|
1578
|
+
if (absValue > 1e9) {
|
|
1579
|
+
maximumFractionDigits = 3;
|
|
1580
|
+
} else if (absValue > 1e6) {
|
|
1581
|
+
maximumFractionDigits = 2;
|
|
1582
|
+
} else if (absValue > 1e3) {
|
|
1583
|
+
maximumFractionDigits = 1;
|
|
1584
|
+
}
|
|
1253
1585
|
}
|
|
1254
|
-
return
|
|
1255
|
-
};
|
|
1256
|
-
var supportsDatePivotTable = (columns) => {
|
|
1257
|
-
var _a;
|
|
1258
|
-
const dateColumnIndex = columns.findIndex((col) => col.type === "DATE" || col.type === "DATE_STRING");
|
|
1259
|
-
const dateColumn = columns[dateColumnIndex];
|
|
1260
|
-
return dateColumn && ((_a = dateColumn == null ? void 0 : dateColumn.display_name) == null ? void 0 : _a.toLowerCase().includes("month")) && (columns == null ? void 0 : columns.length) === 2;
|
|
1586
|
+
return { minimumFractionDigits, maximumFractionDigits, notation };
|
|
1261
1587
|
};
|
|
1262
|
-
var
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1588
|
+
var formatChartLabel = ({ d, scale, column, dataFormatting, maxLabelWidth }) => {
|
|
1589
|
+
if (d === null) {
|
|
1590
|
+
return {
|
|
1591
|
+
fullWidthLabel: "Untitled Category",
|
|
1592
|
+
formattedLabel: "Untitled Category"
|
|
1593
|
+
};
|
|
1266
1594
|
}
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
return true;
|
|
1595
|
+
const col = column ?? (scale == null ? void 0 : scale.column);
|
|
1596
|
+
if (!col || !col.type) {
|
|
1597
|
+
return {
|
|
1598
|
+
fullWidthLabel: d,
|
|
1599
|
+
formattedLabel: d
|
|
1600
|
+
};
|
|
1274
1601
|
}
|
|
1275
|
-
const
|
|
1276
|
-
|
|
1277
|
-
|
|
1602
|
+
const config = (scale == null ? void 0 : scale.dataFormatting) ?? dataFormatting;
|
|
1603
|
+
const { currencyCode, languageCode } = config;
|
|
1604
|
+
let type = col.type;
|
|
1605
|
+
if ((scale == null ? void 0 : scale.units) === "none") {
|
|
1606
|
+
type = "QUANTITY";
|
|
1278
1607
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
}
|
|
1293
|
-
const displayType = response.data.data.display_type;
|
|
1294
|
-
if (displayType === "suggestion" || displayType === "help" || displayType === "html") {
|
|
1295
|
-
return [displayType];
|
|
1296
|
-
}
|
|
1297
|
-
const rows = ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.data) == null ? void 0 : _d.rows) ?? [];
|
|
1298
|
-
const allColumns = columns || ((_f = (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.data) == null ? void 0 : _f.columns);
|
|
1299
|
-
const visibleColumns = getVisibleColumns(allColumns);
|
|
1300
|
-
if (!(visibleColumns == null ? void 0 : visibleColumns.length)) {
|
|
1301
|
-
return ["text"];
|
|
1302
|
-
}
|
|
1303
|
-
if (isSingleValueResponse(response)) {
|
|
1304
|
-
return ["single-value"];
|
|
1305
|
-
}
|
|
1306
|
-
if (!(rows == null ? void 0 : rows.length)) {
|
|
1307
|
-
return ["table"];
|
|
1308
|
-
}
|
|
1309
|
-
const maxRowsForPieChart = 10;
|
|
1310
|
-
const numRows = dataLength ?? rows.length;
|
|
1311
|
-
let pivotDataHasLength = true;
|
|
1312
|
-
const pivotDataLengthProvided = pivotDataLength !== void 0 && pivotDataLength !== null;
|
|
1313
|
-
if (pivotDataLengthProvided) {
|
|
1314
|
-
pivotDataHasLength = !!pivotDataLength;
|
|
1315
|
-
}
|
|
1316
|
-
if (supportsRegularPivotTable(visibleColumns, numRows, (_h = (_g = response == null ? void 0 : response.data) == null ? void 0 : _g.data) == null ? void 0 : _h.rows)) {
|
|
1317
|
-
const supportedDisplayTypes = ["table"];
|
|
1318
|
-
if (!isDataLimited) {
|
|
1319
|
-
supportedDisplayTypes.push("pivot_table");
|
|
1608
|
+
const { minimumFractionDigits, maximumFractionDigits, notation } = getNumberFormatConfig(d, scale);
|
|
1609
|
+
let formattedLabel = d;
|
|
1610
|
+
if (scale == null ? void 0 : scale.showLabelDecimals) {
|
|
1611
|
+
formattedLabel = formatElement({
|
|
1612
|
+
element: d,
|
|
1613
|
+
column: column ?? (scale == null ? void 0 : scale.column),
|
|
1614
|
+
config: dataFormatting,
|
|
1615
|
+
isChart: true
|
|
1616
|
+
});
|
|
1617
|
+
} else {
|
|
1618
|
+
switch (type) {
|
|
1619
|
+
case "STRING": {
|
|
1620
|
+
break;
|
|
1320
1621
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1622
|
+
case "DOLLAR_AMT": {
|
|
1623
|
+
if (Number(d) || Number(d) === 0) {
|
|
1624
|
+
const style = "currency";
|
|
1625
|
+
const currency = currencyCode || "USD";
|
|
1626
|
+
const currencyConfig = {
|
|
1627
|
+
style,
|
|
1628
|
+
minimumFractionDigits,
|
|
1629
|
+
maximumFractionDigits,
|
|
1630
|
+
notation
|
|
1631
|
+
};
|
|
1632
|
+
try {
|
|
1633
|
+
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
1634
|
+
...currencyConfig,
|
|
1635
|
+
currency
|
|
1636
|
+
}).format(d);
|
|
1637
|
+
} catch (error) {
|
|
1638
|
+
console.error(error);
|
|
1639
|
+
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
1640
|
+
...currencyConfig,
|
|
1641
|
+
currency: "USD"
|
|
1642
|
+
}).format(d);
|
|
1643
|
+
}
|
|
1329
1644
|
}
|
|
1645
|
+
break;
|
|
1330
1646
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1647
|
+
case "QUANTITY": {
|
|
1648
|
+
if (!isNaN(parseFloat(d))) {
|
|
1649
|
+
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
1650
|
+
minimumFractionDigits,
|
|
1651
|
+
maximumFractionDigits,
|
|
1652
|
+
notation
|
|
1653
|
+
}).format(d);
|
|
1654
|
+
}
|
|
1655
|
+
break;
|
|
1339
1656
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1657
|
+
case "DATE": {
|
|
1658
|
+
formattedLabel = formatDateType(d, col, config);
|
|
1659
|
+
break;
|
|
1342
1660
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
supportedDisplayTypes.push("scatterplot");
|
|
1661
|
+
case "DATE_STRING": {
|
|
1662
|
+
formattedLabel = formatDateStringType(d, col, config);
|
|
1663
|
+
break;
|
|
1347
1664
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
column: dateColumn,
|
|
1357
|
-
config: getDataFormatting({ monthYearFormat: "YYYY", dayMonthYearFormat: "YYYY" })
|
|
1358
|
-
});
|
|
1359
|
-
if (!uniqueYears.includes(year)) {
|
|
1360
|
-
uniqueYears.push(year);
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1363
|
-
if (uniqueYears.length > 1) {
|
|
1364
|
-
supportedDisplayTypes.push("pivot_table");
|
|
1665
|
+
case "PERCENT": {
|
|
1666
|
+
if (Number(d) || Number(d) === 0) {
|
|
1667
|
+
const p = Number(d) / 100;
|
|
1668
|
+
formattedLabel = new Intl.NumberFormat(languageCode, {
|
|
1669
|
+
style: "percent",
|
|
1670
|
+
minimumFractionDigits: 1,
|
|
1671
|
+
maximumFractionDigits: 1
|
|
1672
|
+
}).format(p);
|
|
1365
1673
|
}
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
default: {
|
|
1677
|
+
break;
|
|
1366
1678
|
}
|
|
1367
|
-
return supportedDisplayTypes;
|
|
1368
1679
|
}
|
|
1369
|
-
return ["table"];
|
|
1370
|
-
} catch (error) {
|
|
1371
|
-
console.error(error);
|
|
1372
|
-
return ["table"];
|
|
1373
1680
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
if (chartType) {
|
|
1378
|
-
return chartType;
|
|
1681
|
+
const fullWidthLabel = formattedLabel;
|
|
1682
|
+
if (typeof formattedLabel === "string" && maxLabelWidth && formattedLabel.length > maxLabelWidth) {
|
|
1683
|
+
formattedLabel = `${formattedLabel.substring(0, maxLabelWidth)}...`;
|
|
1379
1684
|
}
|
|
1380
|
-
return
|
|
1685
|
+
return { fullWidthLabel, formattedLabel };
|
|
1381
1686
|
};
|
|
1382
|
-
var
|
|
1383
|
-
var _a
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
if (supportedDisplayTypes.includes(preferredDisplayType)) {
|
|
1396
|
-
return preferredDisplayType;
|
|
1397
|
-
}
|
|
1398
|
-
if (responseDisplayType === "suggestion" || responseDisplayType === "help" || responseDisplayType === "html") {
|
|
1399
|
-
return responseDisplayType;
|
|
1687
|
+
var getCurrencySymbol = (dataFormatting = dataFormattingDefault) => {
|
|
1688
|
+
var _a;
|
|
1689
|
+
try {
|
|
1690
|
+
const { currencyCode, languageCode } = getDataFormatting(dataFormatting);
|
|
1691
|
+
const formattedParts = new Intl.NumberFormat(languageCode, {
|
|
1692
|
+
style: "currency",
|
|
1693
|
+
currency: currencyCode
|
|
1694
|
+
}).formatToParts(0);
|
|
1695
|
+
const symbol = (_a = formattedParts.find((part) => (part == null ? void 0 : part.type) === "currency")) == null ? void 0 : _a.value;
|
|
1696
|
+
return symbol;
|
|
1697
|
+
} catch (error) {
|
|
1698
|
+
console.error(error);
|
|
1699
|
+
return;
|
|
1400
1700
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1701
|
+
};
|
|
1702
|
+
var getDayjsObjForStringType = (value, col) => {
|
|
1703
|
+
if (!value) {
|
|
1704
|
+
return void 0;
|
|
1403
1705
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1706
|
+
try {
|
|
1707
|
+
switch (col.precision) {
|
|
1708
|
+
case "DOW": {
|
|
1709
|
+
return void 0;
|
|
1710
|
+
}
|
|
1711
|
+
case "HOUR":
|
|
1712
|
+
case "MINUTE": {
|
|
1713
|
+
return dayjsWithPlugins_default.utc(value, "THH:mm:ss.SSSZ").utc();
|
|
1714
|
+
}
|
|
1715
|
+
case "MONTH": {
|
|
1716
|
+
return void 0;
|
|
1717
|
+
}
|
|
1718
|
+
default: {
|
|
1719
|
+
return void 0;
|
|
1720
|
+
}
|
|
1408
1721
|
}
|
|
1409
|
-
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
console.error(error);
|
|
1724
|
+
return void 0;
|
|
1410
1725
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1726
|
+
};
|
|
1727
|
+
var getDayJSObj = ({ value, column }) => {
|
|
1728
|
+
if (column.type === "DATE_STRING") {
|
|
1729
|
+
return getDayjsObjForStringType(value, column);
|
|
1730
|
+
}
|
|
1731
|
+
if (isNumber(value)) {
|
|
1732
|
+
return dayjsWithPlugins_default.unix(value).utc();
|
|
1417
1733
|
}
|
|
1418
|
-
return
|
|
1734
|
+
return dayjsWithPlugins_default.utc(value).utc();
|
|
1419
1735
|
};
|
|
1420
|
-
var
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1736
|
+
var getEpochFromDate = (date, precision, precisionFrame) => {
|
|
1737
|
+
if (date == null ? void 0 : date.getTime) {
|
|
1738
|
+
if (precision && precisionFrame === "start") {
|
|
1739
|
+
return dayjsWithPlugins_default(date).utc().startOf(precision).valueOf();
|
|
1740
|
+
} else if (precision && precisionFrame === "end") {
|
|
1741
|
+
return dayjsWithPlugins_default(date).utc().endOf(precision).valueOf();
|
|
1742
|
+
}
|
|
1743
|
+
return date.getTime();
|
|
1424
1744
|
}
|
|
1425
|
-
return
|
|
1745
|
+
return;
|
|
1426
1746
|
};
|
|
1427
1747
|
|
|
1428
1748
|
// src/HelperFns/domHelpers.ts
|
|
@@ -1617,38 +1937,1082 @@ var mergeSources = (source, newSource) => {
|
|
|
1617
1937
|
}
|
|
1618
1938
|
return finalSource;
|
|
1619
1939
|
};
|
|
1940
|
+
|
|
1941
|
+
// src/Charts/chartHelpers.ts
|
|
1942
|
+
import { max, min } from "d3-array";
|
|
1943
|
+
import _isEqual from "lodash.isequal";
|
|
1944
|
+
import { scaleLinear, scaleBand, scaleTime } from "d3-scale";
|
|
1945
|
+
import { select } from "d3-selection";
|
|
1946
|
+
var DEFAULT_INNER_PADDING = 0.2;
|
|
1947
|
+
var DEFAULT_OUTER_PADDING = 0.5;
|
|
1948
|
+
var dataStructureChanged = (props, prevProps) => {
|
|
1949
|
+
var _a, _b;
|
|
1950
|
+
return ((_a = props.data) == null ? void 0 : _a.length) !== ((_b = prevProps.data) == null ? void 0 : _b.length) || props.stringColumnIndex !== prevProps.stringColumnIndex || props.numberColumnIndex !== prevProps.numberColumnIndex || !_isEqual(props.legendColumn, prevProps.legendColumn) || !_isEqual(props.columns, prevProps.columns) || !_isEqual(props.numberColumnIndices, prevProps.numberColumnIndices) || !_isEqual(props.stringColumnIndices, prevProps.stringColumnIndices) || props.type === "pie" && !_isEqual(props.data, prevProps.data);
|
|
1951
|
+
};
|
|
1952
|
+
var onlySeriesVisibilityChanged = (props, prevProps) => {
|
|
1953
|
+
if (_isEqual(props.columns, prevProps.columns)) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
const columnsFiltered = props.columns.map((col) => {
|
|
1957
|
+
return {
|
|
1958
|
+
...col,
|
|
1959
|
+
isSeriesHidden: void 0
|
|
1960
|
+
};
|
|
1961
|
+
});
|
|
1962
|
+
const prevColumnsFiltered = prevProps.columns.map((col) => {
|
|
1963
|
+
return {
|
|
1964
|
+
...col,
|
|
1965
|
+
isSeriesHidden: void 0
|
|
1966
|
+
};
|
|
1967
|
+
});
|
|
1968
|
+
return deepEqual(columnsFiltered, prevColumnsFiltered);
|
|
1969
|
+
};
|
|
1970
|
+
var scaleZero = (scale) => {
|
|
1971
|
+
const domain = scale == null ? void 0 : scale.domain();
|
|
1972
|
+
const domainLength = domain == null ? void 0 : domain.length;
|
|
1973
|
+
if (!domainLength) {
|
|
1974
|
+
return (scale == null ? void 0 : scale(0)) || 0;
|
|
1975
|
+
}
|
|
1976
|
+
const min2 = domain[0];
|
|
1977
|
+
const max2 = domain[(domain == null ? void 0 : domain.length) - 1];
|
|
1978
|
+
if (min2 > 0 && max2 > 0) {
|
|
1979
|
+
return scale(min2);
|
|
1980
|
+
}
|
|
1981
|
+
if (min2 < 0 && max2 < 0) {
|
|
1982
|
+
return scale(max2);
|
|
1983
|
+
}
|
|
1984
|
+
return scale(0);
|
|
1985
|
+
};
|
|
1986
|
+
var getKey = (rowIndex, cellIndex, extraIndex = 0) => {
|
|
1987
|
+
return `${rowIndex}-${cellIndex}-${extraIndex}`;
|
|
1988
|
+
};
|
|
1989
|
+
var shouldLabelsRotate = (axisElement) => {
|
|
1990
|
+
let prevBBox;
|
|
1991
|
+
let didOverlap = false;
|
|
1992
|
+
const padding = 10;
|
|
1993
|
+
select(axisElement).selectAll("g.tick text").each(function() {
|
|
1994
|
+
if (!didOverlap) {
|
|
1995
|
+
const textBoundingRect = select(this).node().getBoundingClientRect();
|
|
1996
|
+
if (prevBBox) {
|
|
1997
|
+
if (textBoundingRect.x < prevBBox.x + prevBBox.width + padding) {
|
|
1998
|
+
didOverlap = true;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
prevBBox = textBoundingRect;
|
|
2002
|
+
}
|
|
2003
|
+
});
|
|
2004
|
+
return didOverlap;
|
|
2005
|
+
};
|
|
2006
|
+
var getTooltipContent = ({
|
|
2007
|
+
row,
|
|
2008
|
+
columns,
|
|
2009
|
+
colIndex,
|
|
2010
|
+
colIndex2,
|
|
2011
|
+
legendColumn,
|
|
2012
|
+
dataFormatting,
|
|
2013
|
+
aggregated = true
|
|
2014
|
+
}) => {
|
|
2015
|
+
var _a;
|
|
2016
|
+
let tooltipElement = null;
|
|
2017
|
+
try {
|
|
2018
|
+
let tooltipLine1 = "";
|
|
2019
|
+
let tooltipLine2 = "";
|
|
2020
|
+
let tooltipLine3 = "";
|
|
2021
|
+
const column1 = columns[colIndex];
|
|
2022
|
+
const column2 = columns[colIndex2];
|
|
2023
|
+
if (!!legendColumn && !!(column1 == null ? void 0 : column1.origColumn)) {
|
|
2024
|
+
tooltipLine1 = `<div><strong>${legendColumn.tooltipTitle ?? legendColumn.title}:</strong> ${column1.tooltipTitle ?? column1.title}</div>`;
|
|
2025
|
+
}
|
|
2026
|
+
if (column1) {
|
|
2027
|
+
let column1Title = column1.origColumn ? column1.origColumn.tooltipTitle ?? column1.origColumn.title : column1.tooltipTitle ?? column1.title;
|
|
2028
|
+
if (aggregated) {
|
|
2029
|
+
const aggTypeDisplayName = (_a = AGG_TYPES.find((agg) => agg.value === column1.aggType)) == null ? void 0 : _a.displayName;
|
|
2030
|
+
if (aggTypeDisplayName) {
|
|
2031
|
+
column1Title = `${column1Title} (${aggTypeDisplayName})`;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
const column1Value = formatElement({
|
|
2035
|
+
element: row[colIndex] || 0,
|
|
2036
|
+
column: columns[colIndex],
|
|
2037
|
+
config: dataFormatting,
|
|
2038
|
+
isChart: true
|
|
2039
|
+
});
|
|
2040
|
+
tooltipLine2 = `<div><strong>${column1Title}:</strong> ${column1Value}</div>`;
|
|
2041
|
+
}
|
|
2042
|
+
if (column2) {
|
|
2043
|
+
const stringTitle = column2.tooltipTitle ?? column2.title;
|
|
2044
|
+
const stringValue = formatElement({
|
|
2045
|
+
element: row[colIndex2],
|
|
2046
|
+
column: column2,
|
|
2047
|
+
config: dataFormatting,
|
|
2048
|
+
isChart: true
|
|
2049
|
+
});
|
|
2050
|
+
tooltipLine3 = `<div><strong>${stringTitle}:</strong> ${stringValue}</div>`;
|
|
2051
|
+
}
|
|
2052
|
+
tooltipElement = `<div>
|
|
2053
|
+
${tooltipLine1}
|
|
2054
|
+
${tooltipLine2}
|
|
2055
|
+
${tooltipLine3}
|
|
2056
|
+
</div>`;
|
|
2057
|
+
return tooltipElement;
|
|
2058
|
+
} catch (error) {
|
|
2059
|
+
console.error(error);
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
var getLegendLabelsForMultiSeries = (columns, colorScale, numberColumnIndices = []) => {
|
|
2064
|
+
try {
|
|
2065
|
+
if (!(numberColumnIndices == null ? void 0 : numberColumnIndices.length)) {
|
|
2066
|
+
return [];
|
|
2067
|
+
}
|
|
2068
|
+
const numberColumns = numberColumnIndices.map((index) => columns[index]);
|
|
2069
|
+
if (!(numberColumns == null ? void 0 : numberColumns.length)) {
|
|
2070
|
+
return [];
|
|
2071
|
+
}
|
|
2072
|
+
const allAggTypesSame = numberColumns.every((col) => col.aggType === numberColumns[0].aggType);
|
|
2073
|
+
const legendLabels = numberColumnIndices.map((columnIndex, i) => {
|
|
2074
|
+
var _a;
|
|
2075
|
+
const column = columns[columnIndex];
|
|
2076
|
+
let label = column.title;
|
|
2077
|
+
if (!allAggTypesSame) {
|
|
2078
|
+
const aggTypeDisplayName = (_a = AGG_TYPES.find((agg) => agg.value === (column == null ? void 0 : column.aggType))) == null ? void 0 : _a.displayName;
|
|
2079
|
+
if (aggTypeDisplayName) {
|
|
2080
|
+
label = `${label} (${aggTypeDisplayName})`;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
return {
|
|
2084
|
+
label,
|
|
2085
|
+
color: colorScale(columnIndex),
|
|
2086
|
+
hidden: column.isSeriesHidden,
|
|
2087
|
+
columnIndex,
|
|
2088
|
+
column
|
|
2089
|
+
};
|
|
2090
|
+
});
|
|
2091
|
+
return legendLabels;
|
|
2092
|
+
} catch (error) {
|
|
2093
|
+
console.error(error);
|
|
2094
|
+
return [];
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
var getNumberOfSeries = (data) => {
|
|
2098
|
+
try {
|
|
2099
|
+
const numSeries = data[0].cells.length;
|
|
2100
|
+
return numSeries;
|
|
2101
|
+
} catch (error) {
|
|
2102
|
+
console.error(error);
|
|
2103
|
+
return 1;
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
var convertToNumber = (value) => {
|
|
2107
|
+
try {
|
|
2108
|
+
const number = Number(value);
|
|
2109
|
+
if (isNaN(number)) {
|
|
2110
|
+
return 0;
|
|
2111
|
+
}
|
|
2112
|
+
return number;
|
|
2113
|
+
} catch (error) {
|
|
2114
|
+
console.error(error);
|
|
2115
|
+
return 0;
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
var calculateMinAndMaxSums = (data, stringColumnIndex, numberColumnIndices, isScaled) => {
|
|
2119
|
+
const positiveSumsObject = {};
|
|
2120
|
+
const negativeSumsObject = {};
|
|
2121
|
+
data.forEach((row) => {
|
|
2122
|
+
const label = row[stringColumnIndex];
|
|
2123
|
+
numberColumnIndices.forEach((colIndex) => {
|
|
2124
|
+
const rawValue = row[colIndex];
|
|
2125
|
+
let value = Number(rawValue);
|
|
2126
|
+
if (isNaN(value)) {
|
|
2127
|
+
value = 0;
|
|
2128
|
+
}
|
|
2129
|
+
if (value >= 0) {
|
|
2130
|
+
if (positiveSumsObject[label]) {
|
|
2131
|
+
positiveSumsObject[label] += value;
|
|
2132
|
+
} else {
|
|
2133
|
+
positiveSumsObject[label] = value;
|
|
2134
|
+
}
|
|
2135
|
+
} else if (value < 0) {
|
|
2136
|
+
if (negativeSumsObject[label]) {
|
|
2137
|
+
negativeSumsObject[label] -= value;
|
|
2138
|
+
} else {
|
|
2139
|
+
negativeSumsObject[label] = value;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
});
|
|
2144
|
+
let maxValue = getMaxValueFromKeyValueObj(positiveSumsObject);
|
|
2145
|
+
let minValue = getMinValueFromKeyValueObj(negativeSumsObject);
|
|
2146
|
+
const scaleRatio = maxValue / minValue;
|
|
2147
|
+
const disableChartScale = !isScaled || maxValue > 0 && minValue < 0 || scaleRatio > 1e3;
|
|
2148
|
+
if (disableChartScale) {
|
|
2149
|
+
if (maxValue > 0 && minValue > 0) {
|
|
2150
|
+
minValue = 0;
|
|
2151
|
+
} else if (maxValue < 0 && minValue < 0) {
|
|
2152
|
+
maxValue = 0;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return {
|
|
2156
|
+
maxValue,
|
|
2157
|
+
minValue
|
|
2158
|
+
};
|
|
2159
|
+
};
|
|
2160
|
+
var getObjSize = (obj) => {
|
|
2161
|
+
if (typeof obj !== "object") {
|
|
2162
|
+
return void 0;
|
|
2163
|
+
}
|
|
2164
|
+
return Object.keys(obj).length;
|
|
2165
|
+
};
|
|
2166
|
+
var getMaxValueFromKeyValueObj = (obj) => {
|
|
2167
|
+
const size = getObjSize(obj);
|
|
2168
|
+
let maxValue = 0;
|
|
2169
|
+
if (size === 1) {
|
|
2170
|
+
maxValue = obj[Object.keys(obj)[0]];
|
|
2171
|
+
} else if (size > 1) {
|
|
2172
|
+
const numberValues = [...Object.values(obj)].map((value) => Number(value)).filter((value) => {
|
|
2173
|
+
return !isNaN(value);
|
|
2174
|
+
});
|
|
2175
|
+
maxValue = Math.max(...numberValues);
|
|
2176
|
+
}
|
|
2177
|
+
return maxValue;
|
|
2178
|
+
};
|
|
2179
|
+
var getMinValueFromKeyValueObj = (obj) => {
|
|
2180
|
+
const size = getObjSize(obj);
|
|
2181
|
+
let minValue = 0;
|
|
2182
|
+
if (size === 1) {
|
|
2183
|
+
minValue = obj[Object.keys(obj)[0]];
|
|
2184
|
+
} else if (size > 1) {
|
|
2185
|
+
const numberValues = [...Object.values(obj)].map((value) => Number(value)).filter((value) => {
|
|
2186
|
+
return !isNaN(value);
|
|
2187
|
+
});
|
|
2188
|
+
minValue = Math.min(...numberValues);
|
|
2189
|
+
}
|
|
2190
|
+
return minValue;
|
|
2191
|
+
};
|
|
2192
|
+
var getMinAndMaxValues = (data, numberColumnIndices, isScaled, sum, stringColumnIndex) => {
|
|
2193
|
+
if (sum) {
|
|
2194
|
+
return calculateMinAndMaxSums(data, stringColumnIndex, numberColumnIndices, isScaled);
|
|
2195
|
+
}
|
|
2196
|
+
try {
|
|
2197
|
+
const maxValuesFromArrays = [];
|
|
2198
|
+
const minValuesFromArrays = [];
|
|
2199
|
+
numberColumnIndices.forEach((colIndex, i) => {
|
|
2200
|
+
maxValuesFromArrays.push(max(data, (d) => convertToNumber(d[colIndex])));
|
|
2201
|
+
minValuesFromArrays.push(min(data, (d) => convertToNumber(d[colIndex])));
|
|
2202
|
+
});
|
|
2203
|
+
let maxValue = max(maxValuesFromArrays);
|
|
2204
|
+
let minValue = min(minValuesFromArrays);
|
|
2205
|
+
if (maxValue === minValue) {
|
|
2206
|
+
if (minValue > 0) {
|
|
2207
|
+
minValue = 0;
|
|
2208
|
+
} else if (maxValue < 0) {
|
|
2209
|
+
maxValue = 0;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
const scaleRatio = maxValue / minValue;
|
|
2213
|
+
const disableChartScale = !isScaled || maxValue > 0 && minValue < 0 || scaleRatio > 1e3;
|
|
2214
|
+
if (disableChartScale) {
|
|
2215
|
+
if (maxValue > 0 && minValue > 0) {
|
|
2216
|
+
minValue = 0;
|
|
2217
|
+
} else if (maxValue < 0 && minValue < 0) {
|
|
2218
|
+
maxValue = 0;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
return {
|
|
2222
|
+
minValue,
|
|
2223
|
+
maxValue
|
|
2224
|
+
};
|
|
2225
|
+
} catch (error) {
|
|
2226
|
+
console.error(error);
|
|
2227
|
+
return { minValue: 0, maxValue: 0 };
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
var getLegendLocation = (seriesArray, displayType, preferredLocation = "right") => {
|
|
2231
|
+
const bottom = "bottom";
|
|
2232
|
+
if (displayType === "column_line") {
|
|
2233
|
+
return bottom;
|
|
2234
|
+
}
|
|
2235
|
+
const displayTypesWithoutLegends = ["pie", "heatmap", "bubble", "scatterplot", "histogram"];
|
|
2236
|
+
if ((seriesArray == null ? void 0 : seriesArray.length) < 2 || displayTypesWithoutLegends.includes(displayType)) {
|
|
2237
|
+
return void 0;
|
|
2238
|
+
} else if (displayType === "stacked_column" || displayType === "stacked_bar" || displayType === "stacked_line") {
|
|
2239
|
+
return preferredLocation;
|
|
2240
|
+
} else if ((seriesArray == null ? void 0 : seriesArray.length) > 2) {
|
|
2241
|
+
return preferredLocation;
|
|
2242
|
+
} else if ((seriesArray == null ? void 0 : seriesArray.length) > 1) {
|
|
2243
|
+
return preferredLocation;
|
|
2244
|
+
}
|
|
2245
|
+
return void 0;
|
|
2246
|
+
};
|
|
2247
|
+
var getRangeForAxis = ({ axis, height, width }) => {
|
|
2248
|
+
let rangeStart;
|
|
2249
|
+
let rangeEnd;
|
|
2250
|
+
if (axis === "x") {
|
|
2251
|
+
rangeStart = 0;
|
|
2252
|
+
rangeEnd = rangeStart + width;
|
|
2253
|
+
if (rangeEnd < rangeStart) {
|
|
2254
|
+
rangeEnd = rangeStart;
|
|
2255
|
+
}
|
|
2256
|
+
} else if (axis === "y") {
|
|
2257
|
+
rangeEnd = 0;
|
|
2258
|
+
rangeStart = height;
|
|
2259
|
+
if (rangeStart < rangeEnd) {
|
|
2260
|
+
rangeStart = rangeEnd;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
return [rangeStart, rangeEnd];
|
|
2264
|
+
};
|
|
2265
|
+
var getTimeScale = ({
|
|
2266
|
+
data,
|
|
2267
|
+
columns,
|
|
2268
|
+
columnIndex,
|
|
2269
|
+
axis,
|
|
2270
|
+
domain,
|
|
2271
|
+
dataFormatting = dataFormattingDefault,
|
|
2272
|
+
outerPadding = DEFAULT_OUTER_PADDING,
|
|
2273
|
+
innerPadding = DEFAULT_INNER_PADDING,
|
|
2274
|
+
height,
|
|
2275
|
+
width,
|
|
2276
|
+
stringColumnIndices,
|
|
2277
|
+
changeColumnIndices,
|
|
2278
|
+
enableAxisDropdown,
|
|
2279
|
+
changeStringColumnIndex
|
|
2280
|
+
}) => {
|
|
2281
|
+
var _a;
|
|
2282
|
+
let error = false;
|
|
2283
|
+
const config = getDataFormatting(dataFormatting);
|
|
2284
|
+
const dateArray = data.map((d) => {
|
|
2285
|
+
const dayjsObj = getDayJSObj({
|
|
2286
|
+
value: d[columnIndex],
|
|
2287
|
+
column: columns[columnIndex]
|
|
2288
|
+
});
|
|
2289
|
+
if (dayjsObj == null ? void 0 : dayjsObj.isValid()) {
|
|
2290
|
+
return DateUTC(dayjsObj.valueOf());
|
|
2291
|
+
}
|
|
2292
|
+
error = true;
|
|
2293
|
+
return;
|
|
2294
|
+
});
|
|
2295
|
+
if (error) {
|
|
2296
|
+
return getBandScale({
|
|
2297
|
+
columnIndex,
|
|
2298
|
+
axis,
|
|
2299
|
+
domain,
|
|
2300
|
+
data,
|
|
2301
|
+
outerPadding,
|
|
2302
|
+
innerPadding,
|
|
2303
|
+
columns,
|
|
2304
|
+
stringColumnIndices,
|
|
2305
|
+
changeColumnIndices,
|
|
2306
|
+
enableAxisDropdown,
|
|
2307
|
+
changeStringColumnIndex,
|
|
2308
|
+
dataFormatting: config,
|
|
2309
|
+
height,
|
|
2310
|
+
width
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
const range = getRangeForAxis({ axis, height, width });
|
|
2314
|
+
const minDate = min(dateArray);
|
|
2315
|
+
const maxDate = max(dateArray);
|
|
2316
|
+
const scaleDomain = domain ?? [minDate, maxDate];
|
|
2317
|
+
const axisColumns = stringColumnIndices == null ? void 0 : stringColumnIndices.map((index) => columns[index]);
|
|
2318
|
+
const scale = scaleTime().domain(scaleDomain).range(range);
|
|
2319
|
+
scale.type = "TIME";
|
|
2320
|
+
scale.minValue = minDate;
|
|
2321
|
+
scale.maxValue = maxDate;
|
|
2322
|
+
scale.dataFormatting = config;
|
|
2323
|
+
scale.column = columns[columnIndex];
|
|
2324
|
+
scale.title = (_a = scale.column) == null ? void 0 : _a.display_name;
|
|
2325
|
+
scale.fields = axisColumns;
|
|
2326
|
+
scale.hasDropdown = enableAxisDropdown && (stringColumnIndices == null ? void 0 : stringColumnIndices.length) > 1;
|
|
2327
|
+
scale.tickLabels = getTickValues({ scale, innerPadding, outerPadding });
|
|
2328
|
+
scale.tickSize = 0;
|
|
2329
|
+
scale.getValue = (value) => {
|
|
2330
|
+
return scale(getDayJSObj({ value, column: scale.column }).toDate());
|
|
2331
|
+
};
|
|
2332
|
+
return scale;
|
|
2333
|
+
};
|
|
2334
|
+
var getBandScale = ({
|
|
2335
|
+
data,
|
|
2336
|
+
columns,
|
|
2337
|
+
columnIndex,
|
|
2338
|
+
axis,
|
|
2339
|
+
domain,
|
|
2340
|
+
dataFormatting = dataFormattingDefault,
|
|
2341
|
+
outerPadding = DEFAULT_OUTER_PADDING,
|
|
2342
|
+
innerPadding = DEFAULT_INNER_PADDING,
|
|
2343
|
+
height,
|
|
2344
|
+
width,
|
|
2345
|
+
stringColumnIndices,
|
|
2346
|
+
changeColumnIndices,
|
|
2347
|
+
enableAxisDropdown,
|
|
2348
|
+
changeStringColumnIndex
|
|
2349
|
+
}) => {
|
|
2350
|
+
var _a;
|
|
2351
|
+
const range = getRangeForAxis({ axis, height, width });
|
|
2352
|
+
const scaleDomain = domain ?? data.map((d) => d[columnIndex]);
|
|
2353
|
+
const axisColumns = stringColumnIndices == null ? void 0 : stringColumnIndices.map((index) => columns[index]);
|
|
2354
|
+
const scale = scaleBand().domain(scaleDomain).range(range).paddingInner(innerPadding).paddingOuter(outerPadding);
|
|
2355
|
+
scale.type = "BAND";
|
|
2356
|
+
scale.dataFormatting = getDataFormatting(dataFormatting);
|
|
2357
|
+
scale.column = columns[columnIndex];
|
|
2358
|
+
scale.title = (_a = scale.column) == null ? void 0 : _a.display_name;
|
|
2359
|
+
scale.fields = axisColumns;
|
|
2360
|
+
scale.tickSize = scale.bandwidth();
|
|
2361
|
+
scale.hasDropdown = enableAxisDropdown && (stringColumnIndices == null ? void 0 : stringColumnIndices.length) > 1;
|
|
2362
|
+
scale.getValue = (value) => {
|
|
2363
|
+
return scale(value);
|
|
2364
|
+
};
|
|
2365
|
+
scale.changeColumnIndices = changeColumnIndices ?? changeStringColumnIndex;
|
|
2366
|
+
scale.tickLabels = getTickValues({ scale, initialTicks: scaleDomain, innerPadding, outerPadding });
|
|
2367
|
+
return scale;
|
|
2368
|
+
};
|
|
2369
|
+
var getUnitsForColumn = (column, useAgg = true) => {
|
|
2370
|
+
var _a;
|
|
2371
|
+
if (!column) {
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
let aggUnit;
|
|
2375
|
+
if (useAgg && column.aggType) {
|
|
2376
|
+
aggUnit = (_a = AGG_TYPES.find((aggType) => aggType.value === column.aggType)) == null ? void 0 : _a.unit;
|
|
2377
|
+
}
|
|
2378
|
+
switch (aggUnit) {
|
|
2379
|
+
case "none": {
|
|
2380
|
+
return "none";
|
|
2381
|
+
}
|
|
2382
|
+
case "inherit": {
|
|
2383
|
+
break;
|
|
2384
|
+
}
|
|
2385
|
+
default: {
|
|
2386
|
+
break;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
if (column.type === "DOLLAR_AMT" /* CURRENCY */) {
|
|
2390
|
+
return "currency";
|
|
2391
|
+
} else if (column.type === "QUANTITY" /* QUANTITY */) {
|
|
2392
|
+
return "none";
|
|
2393
|
+
} else if (column.type === "RATIO" /* RATIO */) {
|
|
2394
|
+
return "none";
|
|
2395
|
+
} else if (column.type === "PERCENT" /* PERCENT */) {
|
|
2396
|
+
return "percent";
|
|
2397
|
+
}
|
|
2398
|
+
};
|
|
2399
|
+
var getUnitSymbol = ({
|
|
2400
|
+
column,
|
|
2401
|
+
dataFormatting = dataFormattingDefault
|
|
2402
|
+
}) => {
|
|
2403
|
+
const units = getUnitsForColumn(column, false);
|
|
2404
|
+
let unitSymbol = "";
|
|
2405
|
+
if (units === "currency") {
|
|
2406
|
+
const config = getDataFormatting(dataFormatting);
|
|
2407
|
+
const currencySymbol = getCurrencySymbol(config);
|
|
2408
|
+
if (currencySymbol) {
|
|
2409
|
+
unitSymbol = currencySymbol;
|
|
2410
|
+
}
|
|
2411
|
+
} else if (units === "percent") {
|
|
2412
|
+
unitSymbol = "%";
|
|
2413
|
+
}
|
|
2414
|
+
return unitSymbol;
|
|
2415
|
+
};
|
|
2416
|
+
var getLinearAxisTitle = ({
|
|
2417
|
+
numberColumns,
|
|
2418
|
+
aggregated = false
|
|
2419
|
+
}) => {
|
|
2420
|
+
var _a;
|
|
2421
|
+
let title = "Amount";
|
|
2422
|
+
try {
|
|
2423
|
+
if (!(numberColumns == null ? void 0 : numberColumns.length)) {
|
|
2424
|
+
return void 0;
|
|
2425
|
+
}
|
|
2426
|
+
if (numberColumns.length === 1) {
|
|
2427
|
+
return numberColumns[0].display_name;
|
|
2428
|
+
}
|
|
2429
|
+
const allTitlesEqual = !numberColumns.find((col) => {
|
|
2430
|
+
return col.display_name !== numberColumns[0].display_name;
|
|
2431
|
+
});
|
|
2432
|
+
if (allTitlesEqual) {
|
|
2433
|
+
title = numberColumns[0].display_name;
|
|
2434
|
+
}
|
|
2435
|
+
if (aggregated) {
|
|
2436
|
+
const aggTypeArray = numberColumns.map((col) => col.aggType);
|
|
2437
|
+
const allAggTypesEqual = !aggTypeArray.find((agg) => agg !== aggTypeArray[0]);
|
|
2438
|
+
if (allAggTypesEqual) {
|
|
2439
|
+
const aggName = (_a = AGG_TYPES.find((agg) => agg.value === aggTypeArray[0])) == null ? void 0 : _a.displayName;
|
|
2440
|
+
if (aggName) {
|
|
2441
|
+
title = `${title} (${aggName})`;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return title;
|
|
2446
|
+
} catch (error) {
|
|
2447
|
+
console.error(error);
|
|
2448
|
+
return title;
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
var getNumberAxisUnits = (numberColumns) => {
|
|
2452
|
+
const unitsArray = numberColumns.map((col) => {
|
|
2453
|
+
return getUnitsForColumn(col);
|
|
2454
|
+
});
|
|
2455
|
+
const allUnitsEqual = !unitsArray.find((unit) => unit !== unitsArray[0]);
|
|
2456
|
+
if (allUnitsEqual) {
|
|
2457
|
+
return unitsArray[0];
|
|
2458
|
+
}
|
|
2459
|
+
return "none";
|
|
2460
|
+
};
|
|
2461
|
+
var getBinLinearScale = ({
|
|
2462
|
+
columns,
|
|
2463
|
+
columnIndex,
|
|
2464
|
+
axis,
|
|
2465
|
+
buckets,
|
|
2466
|
+
bins,
|
|
2467
|
+
changeColumnIndices,
|
|
2468
|
+
enableAxisDropdown,
|
|
2469
|
+
innerHeight,
|
|
2470
|
+
innerWidth,
|
|
2471
|
+
height,
|
|
2472
|
+
width,
|
|
2473
|
+
dataFormatting = dataFormattingDefault,
|
|
2474
|
+
changeNumberColumnIndices
|
|
2475
|
+
}) => {
|
|
2476
|
+
var _a;
|
|
2477
|
+
const { amountOfNumberColumns } = getColumnTypeAmounts(columns);
|
|
2478
|
+
const domain = [bins[0], bins[bins.length - 1]];
|
|
2479
|
+
const range = getRangeForAxis({ axis, height, width });
|
|
2480
|
+
const scale = scaleLinear().domain(domain).range(range);
|
|
2481
|
+
scale.type = "BIN";
|
|
2482
|
+
scale.minValue = domain[0];
|
|
2483
|
+
scale.maxValue = domain[1];
|
|
2484
|
+
scale.column = columns[columnIndex];
|
|
2485
|
+
scale.fields = [columnIndex];
|
|
2486
|
+
scale.columnIndex = columnIndex;
|
|
2487
|
+
scale.dataFormatting = {
|
|
2488
|
+
...getDataFormatting(dataFormatting),
|
|
2489
|
+
isBinScale: true
|
|
2490
|
+
};
|
|
2491
|
+
scale.hasDropdown = enableAxisDropdown && amountOfNumberColumns > 1;
|
|
2492
|
+
scale.stacked = false;
|
|
2493
|
+
scale.units = getUnitsForColumn(columns[columnIndex], false);
|
|
2494
|
+
scale.title = (_a = columns[columnIndex]) == null ? void 0 : _a.display_name;
|
|
2495
|
+
scale.tickSize = (axis === "x" ? innerWidth : innerHeight) / buckets.length;
|
|
2496
|
+
scale.isScaled = false;
|
|
2497
|
+
scale.aggregated = false;
|
|
2498
|
+
scale.changeColumnIndices = changeColumnIndices ?? changeNumberColumnIndices;
|
|
2499
|
+
scale.getValue = (value) => {
|
|
2500
|
+
return scale(value);
|
|
2501
|
+
};
|
|
2502
|
+
scale.tickLabels = getTickValues({
|
|
2503
|
+
initialTicks: bins,
|
|
2504
|
+
scale
|
|
2505
|
+
});
|
|
2506
|
+
return scale;
|
|
2507
|
+
};
|
|
2508
|
+
var getHistogramScale = ({
|
|
2509
|
+
axis,
|
|
2510
|
+
buckets,
|
|
2511
|
+
columnIndex,
|
|
2512
|
+
height,
|
|
2513
|
+
width,
|
|
2514
|
+
minValue,
|
|
2515
|
+
maxValue,
|
|
2516
|
+
tickValues,
|
|
2517
|
+
numTicks,
|
|
2518
|
+
stacked,
|
|
2519
|
+
isScaled,
|
|
2520
|
+
columns,
|
|
2521
|
+
columnIndices,
|
|
2522
|
+
changeColumnIndices,
|
|
2523
|
+
dataFormatting,
|
|
2524
|
+
changeNumberColumnIndices,
|
|
2525
|
+
enableAxisDropdown,
|
|
2526
|
+
aggregated
|
|
2527
|
+
}) => {
|
|
2528
|
+
const maxBins = max(buckets, (d) => d.length);
|
|
2529
|
+
const range = getRangeForAxis({ axis, height, width });
|
|
2530
|
+
const domain = [0, maxBins];
|
|
2531
|
+
const units = "none";
|
|
2532
|
+
const allowMultipleSeries = false;
|
|
2533
|
+
const hasDropdown = false;
|
|
2534
|
+
const disableAutoScale = true;
|
|
2535
|
+
const title = "Count";
|
|
2536
|
+
return getLinearScale({
|
|
2537
|
+
units,
|
|
2538
|
+
domain,
|
|
2539
|
+
range,
|
|
2540
|
+
columnIndex,
|
|
2541
|
+
allowMultipleSeries,
|
|
2542
|
+
hasDropdown,
|
|
2543
|
+
axis,
|
|
2544
|
+
title,
|
|
2545
|
+
disableAutoScale,
|
|
2546
|
+
minValue,
|
|
2547
|
+
maxValue,
|
|
2548
|
+
tickValues,
|
|
2549
|
+
numTicks,
|
|
2550
|
+
stacked,
|
|
2551
|
+
isScaled,
|
|
2552
|
+
columns,
|
|
2553
|
+
columnIndices,
|
|
2554
|
+
changeColumnIndices,
|
|
2555
|
+
dataFormatting,
|
|
2556
|
+
changeNumberColumnIndices,
|
|
2557
|
+
enableAxisDropdown,
|
|
2558
|
+
height,
|
|
2559
|
+
width,
|
|
2560
|
+
aggregated
|
|
2561
|
+
});
|
|
2562
|
+
};
|
|
2563
|
+
var getLinearScale = ({
|
|
2564
|
+
minValue,
|
|
2565
|
+
maxValue,
|
|
2566
|
+
axis,
|
|
2567
|
+
range,
|
|
2568
|
+
domain,
|
|
2569
|
+
tickValues,
|
|
2570
|
+
numTicks,
|
|
2571
|
+
stacked,
|
|
2572
|
+
isScaled,
|
|
2573
|
+
columns,
|
|
2574
|
+
units,
|
|
2575
|
+
title,
|
|
2576
|
+
columnIndex,
|
|
2577
|
+
columnIndices,
|
|
2578
|
+
hasDropdown,
|
|
2579
|
+
allowMultipleSeries = true,
|
|
2580
|
+
changeColumnIndices,
|
|
2581
|
+
disableAutoScale = false,
|
|
2582
|
+
dataFormatting = dataFormattingDefault,
|
|
2583
|
+
changeNumberColumnIndices,
|
|
2584
|
+
enableAxisDropdown,
|
|
2585
|
+
height,
|
|
2586
|
+
width,
|
|
2587
|
+
aggregated
|
|
2588
|
+
}) => {
|
|
2589
|
+
let domainFinal = domain;
|
|
2590
|
+
if (!domain) {
|
|
2591
|
+
let min2 = minValue ?? (tickValues == null ? void 0 : tickValues[0]);
|
|
2592
|
+
let max2 = maxValue ?? (tickValues == null ? void 0 : tickValues[(tickValues == null ? void 0 : tickValues.length) - 1]);
|
|
2593
|
+
if (isNaN(min2)) {
|
|
2594
|
+
min2 = 0;
|
|
2595
|
+
}
|
|
2596
|
+
if (isNaN(max2)) {
|
|
2597
|
+
max2 = min2;
|
|
2598
|
+
}
|
|
2599
|
+
domainFinal = [min2, max2];
|
|
2600
|
+
}
|
|
2601
|
+
const config = getDataFormatting(dataFormatting);
|
|
2602
|
+
const colIndices = columnIndices ?? [columnIndex];
|
|
2603
|
+
const scaleRange = range ?? getRangeForAxis({ axis, height, width });
|
|
2604
|
+
const axisColumns = (colIndices == null ? void 0 : colIndices.map((index) => columns == null ? void 0 : columns[index])) ?? [];
|
|
2605
|
+
console.log({ axisColumns });
|
|
2606
|
+
const axisTitle = title ?? getLinearAxisTitle({
|
|
2607
|
+
numberColumns: axisColumns,
|
|
2608
|
+
aggregated
|
|
2609
|
+
});
|
|
2610
|
+
const scale = scaleLinear().domain(domainFinal).range(scaleRange);
|
|
2611
|
+
scale.disableAutoScale = disableAutoScale;
|
|
2612
|
+
scale.minValue = domainFinal[0];
|
|
2613
|
+
scale.maxValue = domainFinal[1];
|
|
2614
|
+
scale.columnIndex = columnIndex;
|
|
2615
|
+
scale.column = columns == null ? void 0 : columns[columnIndex];
|
|
2616
|
+
scale.fields = axisColumns;
|
|
2617
|
+
scale.dataFormatting = config;
|
|
2618
|
+
scale.hasDropdown = hasDropdown ?? enableAxisDropdown;
|
|
2619
|
+
scale.stacked = !!stacked;
|
|
2620
|
+
scale.type = "LINEAR";
|
|
2621
|
+
scale.units = units ?? getNumberAxisUnits(axisColumns);
|
|
2622
|
+
scale.title = axisTitle;
|
|
2623
|
+
scale.tickSize = 0;
|
|
2624
|
+
scale.isScaled = isScaled;
|
|
2625
|
+
scale.aggregated = aggregated;
|
|
2626
|
+
scale.allowMultipleSeries = allowMultipleSeries;
|
|
2627
|
+
scale.changeColumnIndices = changeColumnIndices ?? changeNumberColumnIndices;
|
|
2628
|
+
scale.getValue = (value) => {
|
|
2629
|
+
return scale(value);
|
|
2630
|
+
};
|
|
2631
|
+
scale.tickLabels = tickValues ?? getTickValues({
|
|
2632
|
+
scale,
|
|
2633
|
+
numTicks
|
|
2634
|
+
});
|
|
2635
|
+
return scale;
|
|
2636
|
+
};
|
|
2637
|
+
var getLinearScales = ({
|
|
2638
|
+
data,
|
|
2639
|
+
columnIndices1 = [],
|
|
2640
|
+
columnIndices2 = [],
|
|
2641
|
+
axis,
|
|
2642
|
+
stacked,
|
|
2643
|
+
isScaled,
|
|
2644
|
+
columns,
|
|
2645
|
+
hasDropdown,
|
|
2646
|
+
allowMultipleSeries,
|
|
2647
|
+
changeColumnIndices,
|
|
2648
|
+
disableAutoScale,
|
|
2649
|
+
dataFormatting,
|
|
2650
|
+
changeNumberColumnIndices,
|
|
2651
|
+
enableAxisDropdown,
|
|
2652
|
+
stringColumnIndex,
|
|
2653
|
+
height,
|
|
2654
|
+
width,
|
|
2655
|
+
aggregated
|
|
2656
|
+
}) => {
|
|
2657
|
+
var _a;
|
|
2658
|
+
const commonParams = {
|
|
2659
|
+
stacked,
|
|
2660
|
+
isScaled,
|
|
2661
|
+
axis,
|
|
2662
|
+
columns,
|
|
2663
|
+
hasDropdown,
|
|
2664
|
+
allowMultipleSeries,
|
|
2665
|
+
changeColumnIndices,
|
|
2666
|
+
disableAutoScale,
|
|
2667
|
+
dataFormatting,
|
|
2668
|
+
changeNumberColumnIndices,
|
|
2669
|
+
stringColumnIndex,
|
|
2670
|
+
enableAxisDropdown,
|
|
2671
|
+
height,
|
|
2672
|
+
width,
|
|
2673
|
+
aggregated
|
|
2674
|
+
};
|
|
2675
|
+
const minMax = getMinAndMaxValues(data, columnIndices1, isScaled, stacked, stringColumnIndex);
|
|
2676
|
+
const minValue = minMax.minValue;
|
|
2677
|
+
const maxValue = minMax.maxValue;
|
|
2678
|
+
const tempScale1 = getLinearScale({
|
|
2679
|
+
minValue,
|
|
2680
|
+
maxValue,
|
|
2681
|
+
columnIndex: columnIndices1[0],
|
|
2682
|
+
columnIndices: columnIndices1,
|
|
2683
|
+
...commonParams
|
|
2684
|
+
});
|
|
2685
|
+
if (!(columnIndices2 == null ? void 0 : columnIndices2.length)) {
|
|
2686
|
+
return {
|
|
2687
|
+
scale: tempScale1
|
|
2688
|
+
};
|
|
2689
|
+
}
|
|
2690
|
+
const minMax2 = getMinAndMaxValues(data, columnIndices2, isScaled, stacked, stringColumnIndex);
|
|
2691
|
+
const minValue2 = minMax2.minValue;
|
|
2692
|
+
const maxValue2 = minMax2.maxValue;
|
|
2693
|
+
const tempScale2 = getLinearScale({
|
|
2694
|
+
minValue: minValue2,
|
|
2695
|
+
maxValue: maxValue2,
|
|
2696
|
+
range: tempScale1.range(),
|
|
2697
|
+
numTicks: ((_a = tempScale1.tickLabels) == null ? void 0 : _a.length) ?? void 0,
|
|
2698
|
+
columnIndex: columnIndices2[0],
|
|
2699
|
+
columnIndices: columnIndices2,
|
|
2700
|
+
...commonParams
|
|
2701
|
+
});
|
|
2702
|
+
const tickValues1 = tempScale1.tickLabels || [];
|
|
2703
|
+
const tickValues2 = tempScale2.tickLabels || [];
|
|
2704
|
+
const numTickValues1 = tickValues1.length;
|
|
2705
|
+
const numTickValues2 = tickValues2.length;
|
|
2706
|
+
const newTickValues1 = [...tickValues1];
|
|
2707
|
+
const newTickValues2 = [...tickValues2];
|
|
2708
|
+
if (numTickValues1 === numTickValues2) {
|
|
2709
|
+
} else if (numTickValues2 < numTickValues1) {
|
|
2710
|
+
const difference2 = numTickValues1 - numTickValues2;
|
|
2711
|
+
const interval = tickValues2[1] - tickValues2[0];
|
|
2712
|
+
const maxTickValue = tickValues2[numTickValues2 - 1];
|
|
2713
|
+
for (let i = 0; i < difference2; i++) {
|
|
2714
|
+
const nextTickValue = maxTickValue + i * interval;
|
|
2715
|
+
newTickValues2.push(nextTickValue);
|
|
2716
|
+
}
|
|
2717
|
+
} else if (numTickValues2 > numTickValues1) {
|
|
2718
|
+
const difference2 = numTickValues2 - numTickValues1;
|
|
2719
|
+
const interval = tickValues1[1] - tickValues1[0];
|
|
2720
|
+
const maxTickValue = tickValues1[numTickValues1 - 1];
|
|
2721
|
+
for (let i = 1; i <= difference2; i++) {
|
|
2722
|
+
const nextTickValue = maxTickValue + i * interval;
|
|
2723
|
+
newTickValues1.push(nextTickValue);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
const scale = getLinearScale({
|
|
2727
|
+
tickValues: newTickValues1,
|
|
2728
|
+
columnIndex: columnIndices1[0],
|
|
2729
|
+
columnIndices: columnIndices1,
|
|
2730
|
+
...commonParams
|
|
2731
|
+
});
|
|
2732
|
+
const scale2 = getLinearScale({
|
|
2733
|
+
range: scale.range(),
|
|
2734
|
+
tickValues: newTickValues2,
|
|
2735
|
+
columnIndex: columnIndices2[0],
|
|
2736
|
+
columnIndices: columnIndices2,
|
|
2737
|
+
...commonParams
|
|
2738
|
+
});
|
|
2739
|
+
scale.secondScale = scale2;
|
|
2740
|
+
scale2.secondScale = scale;
|
|
2741
|
+
return { scale, scale2 };
|
|
2742
|
+
};
|
|
2743
|
+
var doesElementOverflowContainer = (element, container) => {
|
|
2744
|
+
const elementBBox = element.getBBox();
|
|
2745
|
+
const containerBBox = container.getBBox();
|
|
2746
|
+
if (elementBBox.y < containerBBox.y) {
|
|
2747
|
+
return true;
|
|
2748
|
+
}
|
|
2749
|
+
if (elementBBox.y + elementBBox.height < containerBBox.y + containerBBox.height) {
|
|
2750
|
+
return true;
|
|
2751
|
+
}
|
|
2752
|
+
if (elementBBox.x < containerBBox.x) {
|
|
2753
|
+
return true;
|
|
2754
|
+
}
|
|
2755
|
+
if (elementBBox.x + elementBBox.width < containerBBox.x + containerBBox.width) {
|
|
2756
|
+
return true;
|
|
2757
|
+
}
|
|
2758
|
+
return false;
|
|
2759
|
+
};
|
|
2760
|
+
var DateUTC = (d) => {
|
|
2761
|
+
const date = new Date(d);
|
|
2762
|
+
date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1e3);
|
|
2763
|
+
return date;
|
|
2764
|
+
};
|
|
2765
|
+
var getNiceDateTickValues = ({ tickValues, scale }) => {
|
|
2766
|
+
var _a;
|
|
2767
|
+
try {
|
|
2768
|
+
if ((tickValues == null ? void 0 : tickValues.length) < 2) {
|
|
2769
|
+
return tickValues;
|
|
2770
|
+
}
|
|
2771
|
+
const { minValue, maxValue } = scale;
|
|
2772
|
+
if (minValue === void 0 || maxValue === void 0) {
|
|
2773
|
+
throw new Error("Tried to make nice labels but max/min values were not provided");
|
|
2774
|
+
}
|
|
2775
|
+
const minSeconds = getEpochFromDate(minValue);
|
|
2776
|
+
const maxSeconds = getEpochFromDate(maxValue);
|
|
2777
|
+
if (!minSeconds || !maxSeconds) {
|
|
2778
|
+
throw new Error("Tried to make nice labels but could not convert min and max dates to epoch");
|
|
2779
|
+
}
|
|
2780
|
+
const newTickValues = [...tickValues];
|
|
2781
|
+
const tickRange = getEpochFromDate(tickValues[1]) - getEpochFromDate(tickValues[0]);
|
|
2782
|
+
const dayjsPrecision = DAYJS_PRECISION_FORMATS[(_a = scale == null ? void 0 : scale.column) == null ? void 0 : _a.precision];
|
|
2783
|
+
const minTickValue = getEpochFromDate(tickValues[0], dayjsPrecision, "start");
|
|
2784
|
+
const maxTickValue = getEpochFromDate(tickValues[tickValues.length - 1], dayjsPrecision, "end");
|
|
2785
|
+
if (!tickRange || isNaN(minTickValue) || isNaN(maxTickValue)) {
|
|
2786
|
+
throw new Error("Tried to make nice labels but could not convert tick values to epoch");
|
|
2787
|
+
}
|
|
2788
|
+
let newMinTickValue = minTickValue;
|
|
2789
|
+
let newMaxTickValue = maxTickValue;
|
|
2790
|
+
if (minSeconds < minTickValue) {
|
|
2791
|
+
newMinTickValue = minTickValue - tickRange;
|
|
2792
|
+
newTickValues.unshift(DateUTC(newMinTickValue));
|
|
2793
|
+
}
|
|
2794
|
+
if (maxSeconds > maxTickValue) {
|
|
2795
|
+
newMaxTickValue = maxTickValue + tickRange;
|
|
2796
|
+
newTickValues.push(DateUTC(newMaxTickValue));
|
|
2797
|
+
}
|
|
2798
|
+
scale.domain([DateUTC(newTickValues[0]), DateUTC(newTickValues[newTickValues.length - 1])]);
|
|
2799
|
+
return newTickValues;
|
|
2800
|
+
} catch (error) {
|
|
2801
|
+
console.error(error);
|
|
2802
|
+
return tickValues;
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
var getNiceTickValues = ({ tickValues, scale }) => {
|
|
2806
|
+
const { minValue, maxValue } = scale;
|
|
2807
|
+
if (minValue === void 0 || maxValue === void 0) {
|
|
2808
|
+
console.warn("Tried to make nice labels but max/min values were not provided");
|
|
2809
|
+
return tickValues;
|
|
2810
|
+
} else if ((tickValues == null ? void 0 : tickValues.length) === 1) {
|
|
2811
|
+
return tickValues;
|
|
2812
|
+
}
|
|
2813
|
+
const newTickValues = [...tickValues];
|
|
2814
|
+
try {
|
|
2815
|
+
const minTickValue = tickValues[0];
|
|
2816
|
+
const maxTickValue = tickValues[tickValues.length - 1];
|
|
2817
|
+
const tickRange = Math.abs(tickValues[1] - tickValues[0]);
|
|
2818
|
+
let newMinTickValue = minTickValue;
|
|
2819
|
+
let newMaxTickValue = maxTickValue;
|
|
2820
|
+
if (minValue < minTickValue) {
|
|
2821
|
+
newMinTickValue = minTickValue - tickRange;
|
|
2822
|
+
newTickValues.unshift(newMinTickValue);
|
|
2823
|
+
}
|
|
2824
|
+
if (maxValue > maxTickValue) {
|
|
2825
|
+
newMaxTickValue = maxTickValue + tickRange;
|
|
2826
|
+
newTickValues.push(newMaxTickValue);
|
|
2827
|
+
}
|
|
2828
|
+
scale.domain([newTickValues[0], newTickValues[newTickValues.length - 1]]);
|
|
2829
|
+
} catch (error) {
|
|
2830
|
+
console.error(error);
|
|
2831
|
+
}
|
|
2832
|
+
return newTickValues;
|
|
2833
|
+
};
|
|
2834
|
+
var getTickSizeFromNumTicks = ({
|
|
2835
|
+
scale,
|
|
2836
|
+
numTicks,
|
|
2837
|
+
innerPadding = DEFAULT_INNER_PADDING,
|
|
2838
|
+
outerPadding = DEFAULT_OUTER_PADDING
|
|
2839
|
+
}) => {
|
|
2840
|
+
var _a, _b;
|
|
2841
|
+
const fontSize = 12;
|
|
2842
|
+
const rangeStart = ((_a = scale == null ? void 0 : scale.range()) == null ? void 0 : _a[1]) ?? 0;
|
|
2843
|
+
const rangeEnd = ((_b = scale == null ? void 0 : scale.range()) == null ? void 0 : _b[0]) ?? 0;
|
|
2844
|
+
const fullSize = Math.abs(rangeEnd - rangeStart) + fontSize;
|
|
2845
|
+
if (scale.type !== "BAND") {
|
|
2846
|
+
const tickSize = fullSize / numTicks;
|
|
2847
|
+
return tickSize;
|
|
2848
|
+
}
|
|
2849
|
+
const tickSizeWithoutPadding = fullSize / (2 * outerPadding + numTicks + (numTicks + 1) * innerPadding);
|
|
2850
|
+
const tickSizeWithInnerPadding = tickSizeWithoutPadding + innerPadding * tickSizeWithoutPadding;
|
|
2851
|
+
return tickSizeWithInnerPadding;
|
|
2852
|
+
};
|
|
2853
|
+
var getTickValues = ({
|
|
2854
|
+
scale,
|
|
2855
|
+
initialTicks,
|
|
2856
|
+
numTicks,
|
|
2857
|
+
innerPadding = DEFAULT_INNER_PADDING,
|
|
2858
|
+
outerPadding = DEFAULT_OUTER_PADDING
|
|
2859
|
+
}) => {
|
|
2860
|
+
var _a, _b;
|
|
2861
|
+
try {
|
|
2862
|
+
let tickValues = scale.tickLabels;
|
|
2863
|
+
if (initialTicks) {
|
|
2864
|
+
tickValues = [...initialTicks];
|
|
2865
|
+
} else if (typeof (scale == null ? void 0 : scale.ticks) === "function") {
|
|
2866
|
+
tickValues = scale.ticks(numTicks);
|
|
2867
|
+
}
|
|
2868
|
+
const tickSize = getTickSizeFromNumTicks({ scale, numTicks: tickValues == null ? void 0 : tickValues.length, innerPadding, outerPadding });
|
|
2869
|
+
if (!tickValues) {
|
|
2870
|
+
console.error("Unable to set tick labels for scale. tickValues is undefined");
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
const fontSize = 12;
|
|
2874
|
+
const minimumTickSize = 20;
|
|
2875
|
+
const fullSize = (Math.abs(((_a = scale == null ? void 0 : scale.range()) == null ? void 0 : _a[1]) - ((_b = scale == null ? void 0 : scale.range()) == null ? void 0 : _b[0])) ?? 1) + fontSize;
|
|
2876
|
+
const interval = Math.ceil(tickValues.length * minimumTickSize / fullSize);
|
|
2877
|
+
let newTickValues = [...tickValues];
|
|
2878
|
+
if (tickSize < minimumTickSize) {
|
|
2879
|
+
newTickValues = [];
|
|
2880
|
+
tickValues.forEach((label, index) => {
|
|
2881
|
+
if (index % interval === 0) {
|
|
2882
|
+
newTickValues.push(label);
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
if ((scale == null ? void 0 : scale.type) === "LINEAR" || (scale == null ? void 0 : scale.type) === "BIN") {
|
|
2887
|
+
return getNiceTickValues({
|
|
2888
|
+
tickValues: newTickValues,
|
|
2889
|
+
scale
|
|
2890
|
+
});
|
|
2891
|
+
} else if ((scale == null ? void 0 : scale.type) === "TIME") {
|
|
2892
|
+
return getNiceDateTickValues({
|
|
2893
|
+
tickValues: newTickValues,
|
|
2894
|
+
scale
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
return newTickValues;
|
|
2898
|
+
} catch (error) {
|
|
2899
|
+
console.error(error);
|
|
2900
|
+
}
|
|
2901
|
+
return initialTicks || [];
|
|
2902
|
+
};
|
|
2903
|
+
var mergeBboxes = (boundingBoxes) => {
|
|
2904
|
+
const filteredBBoxes = boundingBoxes.filter((bbox) => !!bbox);
|
|
2905
|
+
if (!(filteredBBoxes == null ? void 0 : filteredBBoxes.length)) {
|
|
2906
|
+
return void 0;
|
|
2907
|
+
}
|
|
2908
|
+
try {
|
|
2909
|
+
let minLeft;
|
|
2910
|
+
let maxBottom;
|
|
2911
|
+
let maxRight;
|
|
2912
|
+
let minTop;
|
|
2913
|
+
filteredBBoxes.forEach(
|
|
2914
|
+
({
|
|
2915
|
+
left,
|
|
2916
|
+
bottom,
|
|
2917
|
+
right,
|
|
2918
|
+
top
|
|
2919
|
+
} = { left: void 0, bottom: void 0, right: void 0, top: void 0 }) => {
|
|
2920
|
+
if (isNaN(left) || isNaN(bottom) || isNaN(right) || isNaN(top)) {
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
const width = right - left;
|
|
2924
|
+
const height = bottom - top;
|
|
2925
|
+
if (width <= 0 && height <= 0) {
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2928
|
+
if (minLeft === void 0 || left < minLeft)
|
|
2929
|
+
minLeft = left;
|
|
2930
|
+
if (maxBottom === void 0 || bottom > maxBottom)
|
|
2931
|
+
maxBottom = bottom;
|
|
2932
|
+
if (maxRight === void 0 || right > maxRight)
|
|
2933
|
+
maxRight = right;
|
|
2934
|
+
if (minTop === void 0 || top < minTop)
|
|
2935
|
+
minTop = top;
|
|
2936
|
+
}
|
|
2937
|
+
);
|
|
2938
|
+
return { x: minLeft, y: minTop, height: Math.abs(maxBottom - minTop), width: Math.abs(maxRight - minLeft) };
|
|
2939
|
+
} catch (error) {
|
|
2940
|
+
console.error(error);
|
|
2941
|
+
return void 0;
|
|
2942
|
+
}
|
|
2943
|
+
};
|
|
2944
|
+
|
|
2945
|
+
// src/errorMessages.ts
|
|
2946
|
+
var GENERAL_ERROR = "Uh oh, Our system is experiencing an unexpected error. We're aware of this issue and are working to fix it as soon as possible.";
|
|
2947
|
+
var GENERAL_QUERY_ERROR = "Internal Service Error: Our system is experiencing an unexpected error. We're aware of this issue and are working to fix it as soon as possible.";
|
|
2948
|
+
var GENERAL_HTML_ERROR = "Internal Service Error: Our system is experiencing an unexpected error. We're aware of this issue and are working to fix it as soon as possible.";
|
|
2949
|
+
var UNAUTHENTICATED_ERROR = "Uh oh.. It looks like you don't have access to this resource. Please double check that all required authentication fields are correct.";
|
|
2950
|
+
var REQUEST_CANCELLED_ERROR = "Request cancelled";
|
|
1620
2951
|
export {
|
|
1621
2952
|
AGG_TYPES,
|
|
1622
2953
|
CHART_TYPES,
|
|
2954
|
+
COMPARE_TYPE,
|
|
2955
|
+
CONTINUOUS_TYPE,
|
|
2956
|
+
CUSTOM_TYPE,
|
|
2957
|
+
DATA_ALERT_CONDITION_TYPES,
|
|
2958
|
+
DATA_ALERT_ENABLED_STATUSES,
|
|
2959
|
+
DATA_ALERT_FREQUENCY_TYPE_OPTIONS,
|
|
2960
|
+
DATA_ALERT_OPERATORS,
|
|
2961
|
+
DATA_ALERT_STATUSES,
|
|
1623
2962
|
DATE_ONLY_CHART_TYPES,
|
|
1624
2963
|
DAYJS_PRECISION_FORMATS,
|
|
1625
2964
|
DEFAULT_AGG_TYPE,
|
|
1626
2965
|
DEFAULT_DATA_PAGE_SIZE,
|
|
2966
|
+
DEFAULT_EVALUATION_FREQUENCY,
|
|
2967
|
+
DEFAULT_SOURCE,
|
|
1627
2968
|
DOUBLE_AXIS_CHART_TYPES,
|
|
1628
2969
|
DOW_STYLES,
|
|
2970
|
+
DataExplorerTypes,
|
|
2971
|
+
DateUTC,
|
|
2972
|
+
EVALUATION_FREQUENCY_OPTIONS,
|
|
2973
|
+
EXISTS_TYPE,
|
|
2974
|
+
GENERAL_ERROR,
|
|
2975
|
+
GENERAL_HTML_ERROR,
|
|
2976
|
+
GENERAL_QUERY_ERROR,
|
|
2977
|
+
GROUP_TERM_TYPE,
|
|
1629
2978
|
MAX_DATA_PAGE_SIZE,
|
|
1630
2979
|
MAX_LEGEND_LABELS,
|
|
1631
2980
|
MIN_HISTOGRAM_SAMPLE,
|
|
2981
|
+
MONTH_DAY_SELECT_OPTIONS,
|
|
1632
2982
|
MONTH_NAMES,
|
|
2983
|
+
NUMBER_TERM_TYPE,
|
|
1633
2984
|
NumberColumnTypeDisplayNames,
|
|
1634
2985
|
NumberColumnTypes,
|
|
2986
|
+
PERIODIC_TYPE,
|
|
2987
|
+
PROJECT_TYPE,
|
|
1635
2988
|
PrecisionTypes,
|
|
2989
|
+
QUERY_TERM_TYPE,
|
|
2990
|
+
REQUEST_CANCELLED_ERROR,
|
|
2991
|
+
RESET_PERIOD_OPTIONS,
|
|
2992
|
+
SCHEDULED_TYPE,
|
|
2993
|
+
SCHEDULE_FREQUENCY_OPTIONS,
|
|
2994
|
+
SCHEDULE_INTERVAL_OPTIONS,
|
|
1636
2995
|
SEASON_NAMES,
|
|
1637
2996
|
TABLE_TYPES,
|
|
1638
2997
|
TimestampFormats,
|
|
2998
|
+
UNAUTHENTICATED_ERROR,
|
|
1639
2999
|
WEEKDAY_NAMES_MON,
|
|
1640
3000
|
WEEKDAY_NAMES_SUN,
|
|
1641
3001
|
animateInputText,
|
|
1642
3002
|
authenticationDefault,
|
|
1643
3003
|
autoQLConfigDefault,
|
|
3004
|
+
calculateMinAndMaxSums,
|
|
1644
3005
|
capitalizeFirstChar,
|
|
3006
|
+
convertToNumber,
|
|
1645
3007
|
currentEventLoopEnd,
|
|
1646
3008
|
dataConfigDefault,
|
|
1647
3009
|
dataFormattingDefault,
|
|
3010
|
+
dataStructureChanged,
|
|
1648
3011
|
dateSortFn,
|
|
1649
3012
|
dateStringSortFn,
|
|
1650
3013
|
deepEqual,
|
|
1651
3014
|
difference,
|
|
3015
|
+
doesElementOverflowContainer,
|
|
1652
3016
|
formatChartLabel,
|
|
1653
3017
|
formatDateStringType,
|
|
1654
3018
|
formatDateType,
|
|
@@ -1661,6 +3025,8 @@ export {
|
|
|
1661
3025
|
getAuthentication,
|
|
1662
3026
|
getAutoQLConfig,
|
|
1663
3027
|
getBBoxFromRef,
|
|
3028
|
+
getBandScale,
|
|
3029
|
+
getBinLinearScale,
|
|
1664
3030
|
getColumnTypeAmounts,
|
|
1665
3031
|
getCurrencySymbol,
|
|
1666
3032
|
getDataConfig,
|
|
@@ -1675,14 +3041,36 @@ export {
|
|
|
1675
3041
|
getGroupBysFromPivotTable,
|
|
1676
3042
|
getGroupBysFromTable,
|
|
1677
3043
|
getGroupableColumns,
|
|
3044
|
+
getHistogramScale,
|
|
3045
|
+
getKey,
|
|
1678
3046
|
getKeyByValue,
|
|
3047
|
+
getLegendLabelsForMultiSeries,
|
|
3048
|
+
getLegendLocation,
|
|
3049
|
+
getLinearAxisTitle,
|
|
3050
|
+
getLinearScale,
|
|
3051
|
+
getLinearScales,
|
|
3052
|
+
getMaxValueFromKeyValueObj,
|
|
3053
|
+
getMinAndMaxValues,
|
|
3054
|
+
getMinValueFromKeyValueObj,
|
|
3055
|
+
getNiceDateTickValues,
|
|
3056
|
+
getNiceTickValues,
|
|
3057
|
+
getNumberAxisUnits,
|
|
1679
3058
|
getNumberFormatConfig,
|
|
1680
3059
|
getNumberOfGroupables,
|
|
3060
|
+
getNumberOfSeries,
|
|
3061
|
+
getObjSize,
|
|
1681
3062
|
getPadding,
|
|
1682
3063
|
getQueryParams,
|
|
3064
|
+
getRangeForAxis,
|
|
1683
3065
|
getSVGBase64,
|
|
1684
3066
|
getStringFromSource,
|
|
1685
3067
|
getSupportedDisplayTypes,
|
|
3068
|
+
getTickSizeFromNumTicks,
|
|
3069
|
+
getTickValues,
|
|
3070
|
+
getTimeScale,
|
|
3071
|
+
getTooltipContent,
|
|
3072
|
+
getUnitSymbol,
|
|
3073
|
+
getUnitsForColumn,
|
|
1686
3074
|
getVisibleColumns,
|
|
1687
3075
|
handleTooltipBoundaryCollision,
|
|
1688
3076
|
hasData,
|
|
@@ -1702,12 +3090,16 @@ export {
|
|
|
1702
3090
|
isSingleValueResponse,
|
|
1703
3091
|
isTableType,
|
|
1704
3092
|
makeEmptyArray,
|
|
3093
|
+
mergeBboxes,
|
|
1705
3094
|
mergeSources,
|
|
1706
3095
|
nameValueObject,
|
|
3096
|
+
onlySeriesVisibilityChanged,
|
|
1707
3097
|
onlyUnique,
|
|
1708
3098
|
removeFromDOM,
|
|
1709
3099
|
rotateArray,
|
|
3100
|
+
scaleZero,
|
|
1710
3101
|
setCaretPosition,
|
|
3102
|
+
shouldLabelsRotate,
|
|
1711
3103
|
shouldPlotMultiSeries,
|
|
1712
3104
|
sortDataByDate,
|
|
1713
3105
|
supports2DCharts,
|