@datarailsshared/dr_renderer 1.5.122 → 1.5.126
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/package.json +1 -1
- package/src/dr-renderer-helpers.js +0 -1
- package/src/highcharts_renderer.js +21 -127
- package/tests/highcharts_renderer.test.js +116 -66
package/package.json
CHANGED
|
@@ -72,7 +72,6 @@ function isShowingEmptyValues(additionOptions) {
|
|
|
72
72
|
const DELIMER = ' , '
|
|
73
73
|
const FEATURES = {
|
|
74
74
|
ENABLE_NEW_WIDGET_VALUE_FORMATTING: 'enable_new_widget_value_formatting',
|
|
75
|
-
FORMAT_DATES_AS_OTHER_AXIS_TYPES: 'format_dates_as_other_axis_types',
|
|
76
75
|
MULTIPLE_DIMENSION_TAGS: 'multiple_dimension_tags',
|
|
77
76
|
USE_NEW_SCENARIO_TAG: 'use_new_scenario_tag',
|
|
78
77
|
ENABLE_GAUGE_DYNAMIC_GOAL: 'enable_gauge_dynamic_goal',
|
|
@@ -297,8 +297,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
297
297
|
let wrappedFormattedValue = highchartsRenderer.getSpanWrapper(formatted_value);
|
|
298
298
|
|
|
299
299
|
const category_text = tooltipOptions.show_x_axis ? `<b>${cols[0] || this.key}</b>` : '';
|
|
300
|
-
const series_text = tooltipOptions.show_data_series
|
|
301
|
-
? `<br/><span style="color: ${this.series.color};">\u200E${this.series.name}</span>: `
|
|
300
|
+
const series_text = tooltipOptions.show_data_series
|
|
301
|
+
? `<br/><span style="color: ${this.series.color};">\u200E${this.series.name}</span>: `
|
|
302
302
|
: '';
|
|
303
303
|
wrappedFormattedValue = tooltipOptions.show_value ? wrappedFormattedValue : '';
|
|
304
304
|
|
|
@@ -1038,7 +1038,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
1038
1038
|
tempAr[temp_len - 1] = highchartsRenderer.getFieldName(colAttrs[j]);
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
-
const formattedColKeys = highchartsRenderer.getFormattedColKeys(pivotData, null
|
|
1041
|
+
const formattedColKeys = highchartsRenderer.getFormattedColKeys(pivotData, null);
|
|
1042
1042
|
tempAr = tempAr.concat(lodash.map(formattedColKeys, function (row) {
|
|
1043
1043
|
return row[j];
|
|
1044
1044
|
}));
|
|
@@ -1057,11 +1057,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
1057
1057
|
}
|
|
1058
1058
|
forExport.push(tempAr);
|
|
1059
1059
|
|
|
1060
|
+
const formattedRowKeys = highchartsRenderer.getFormattedRowKeys(pivotData, null);
|
|
1061
|
+
|
|
1060
1062
|
for (i in rowKeys) {
|
|
1061
1063
|
if (!hasProp.call(rowKeys, i)) continue;
|
|
1062
1064
|
tempAr = [];
|
|
1063
1065
|
rowKey = rowKeys[i];
|
|
1064
|
-
|
|
1066
|
+
const formattedRowKey = formattedRowKeys[i];
|
|
1067
|
+
tempAr = tempAr.concat(formattedRowKey);
|
|
1065
1068
|
for (j in colKeys) {
|
|
1066
1069
|
if (!hasProp.call(colKeys, j)) continue;
|
|
1067
1070
|
colKey = colKeys[j];
|
|
@@ -1790,19 +1793,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
1790
1793
|
resultObject = highchartsRenderer.getDataLabelsOptions(additionOptions, resultObject);
|
|
1791
1794
|
lodash.forEach(waterfallOptions.values.walkthrough, function(value, index) {
|
|
1792
1795
|
|
|
1793
|
-
|
|
1794
|
-
if (value.trend === 'total' || highchartsRenderer.isFormattingDatesAsOtherAxisTypes()) {
|
|
1795
|
-
keys = value.key;
|
|
1796
|
-
} else {
|
|
1797
|
-
lodash.forEach(value.key, (item) => {
|
|
1798
|
-
const findKeyByValue = lodash.find(
|
|
1799
|
-
Object.keys(pivotData.dateValuesDictionary || {}),
|
|
1800
|
-
key => pivotData.dateValuesDictionary[key] === item
|
|
1801
|
-
);
|
|
1802
|
-
keys.push(findKeyByValue ? findKeyByValue : item);
|
|
1803
|
-
})
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1796
|
+
const keys = value.key;
|
|
1806
1797
|
const agg = pivotData.getAggregator([], keys);
|
|
1807
1798
|
|
|
1808
1799
|
if (keys[0] === 'Total') {
|
|
@@ -7472,18 +7463,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7472
7463
|
return {};
|
|
7473
7464
|
};
|
|
7474
7465
|
|
|
7475
|
-
highchartsRenderer.createDateFromString = function (dateString, format) {
|
|
7476
|
-
if (!(format && highchartsRenderer.isDateFormat(dateString, format) || highchartsRenderer.isDate(dateString))) {
|
|
7477
|
-
return null;
|
|
7478
|
-
}
|
|
7479
|
-
const utcDate = format
|
|
7480
|
-
? moment_lib.utc(dateString, format, true)
|
|
7481
|
-
: moment_lib.utc(dateString);
|
|
7482
|
-
return utcDate.startOf('day').unix();
|
|
7483
|
-
}
|
|
7484
|
-
|
|
7485
7466
|
highchartsRenderer.prepareDrillDownFilters = function (r_keys, c_keys, widget) {
|
|
7486
|
-
const isFormattingDatesAsOtherAxisTypes = highchartsRenderer.isFormattingDatesAsOtherAxisTypes();
|
|
7487
7467
|
let row_key = r_keys;
|
|
7488
7468
|
let col_key = c_keys;
|
|
7489
7469
|
if (widget.options &&
|
|
@@ -7504,11 +7484,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7504
7484
|
let label = col_value;
|
|
7505
7485
|
if (widget.cols[0].type === 'Date' && col_value !== NULL_VALUE) {
|
|
7506
7486
|
const format = highchartsRenderer.getDateFieldFormat(widget, widget.cols[0]);
|
|
7507
|
-
let date =
|
|
7487
|
+
let date = +col_value;
|
|
7508
7488
|
colFilter.values.push(date);
|
|
7509
|
-
label =
|
|
7510
|
-
? highchartsRenderer.returnRawDataValue(widget.cols[0].type, +col_value, format, widget.cols[0].name)
|
|
7511
|
-
: col_value;
|
|
7489
|
+
label = highchartsRenderer.returnRawDataValue(widget.cols[0].type, +col_value, format, widget.cols[0].name);
|
|
7512
7490
|
} else {
|
|
7513
7491
|
colFilter.values.push(col_value);
|
|
7514
7492
|
}
|
|
@@ -7537,9 +7515,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7537
7515
|
return;
|
|
7538
7516
|
}
|
|
7539
7517
|
temp.values = datetrange;
|
|
7540
|
-
temp.values.label =
|
|
7541
|
-
? highchartsRenderer.returnRawDataValue(widget.cols[index].type, +col_value, format, widget.cols[index].name)
|
|
7542
|
-
: col_value;
|
|
7518
|
+
temp.values.label = highchartsRenderer.returnRawDataValue(widget.cols[index].type, +col_value, format, widget.cols[index].name);
|
|
7543
7519
|
} else {
|
|
7544
7520
|
temp.values = [col_value];
|
|
7545
7521
|
}
|
|
@@ -7560,9 +7536,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7560
7536
|
return;
|
|
7561
7537
|
}
|
|
7562
7538
|
temp.values = datetrange;
|
|
7563
|
-
temp.values.label =
|
|
7564
|
-
? highchartsRenderer.returnRawDataValue(widget.rows[index].type, +row_value, format, widget.rows[index].name)
|
|
7565
|
-
: row_value;
|
|
7539
|
+
temp.values.label = highchartsRenderer.returnRawDataValue(widget.rows[index].type, +row_value, format, widget.rows[index].name);
|
|
7566
7540
|
} else {
|
|
7567
7541
|
temp.values = [row_value];
|
|
7568
7542
|
}
|
|
@@ -7611,7 +7585,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7611
7585
|
};
|
|
7612
7586
|
|
|
7613
7587
|
highchartsRenderer.prepareDrillDownGraphFilters = function (r_key, c_key, widget) {
|
|
7614
|
-
const isFormattingDatesAsOtherAxisTypes = highchartsRenderer.isFormattingDatesAsOtherAxisTypes();
|
|
7615
7588
|
let rowKey = r_key;
|
|
7616
7589
|
let colKey = c_key;
|
|
7617
7590
|
let widgetOptions = typeof widget.options === 'string' ? JSON.parse(widget.options) : widget.options;
|
|
@@ -7649,12 +7622,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7649
7622
|
let value = colKey[i];
|
|
7650
7623
|
switch (widget.cols[0].type) {
|
|
7651
7624
|
case 'Date':
|
|
7652
|
-
if (value
|
|
7653
|
-
value = highchartsRenderer.createDateFromString(
|
|
7654
|
-
value,
|
|
7655
|
-
highchartsRenderer.getDateFieldFormat(widget, widget.cols[0])
|
|
7656
|
-
);
|
|
7657
|
-
} else if (!isNaN(value)) {
|
|
7625
|
+
if (!isNaN(value)) {
|
|
7658
7626
|
value = +value;
|
|
7659
7627
|
}
|
|
7660
7628
|
break;
|
|
@@ -7768,44 +7736,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7768
7736
|
return res;
|
|
7769
7737
|
};
|
|
7770
7738
|
|
|
7771
|
-
highchartsRenderer.replaceSortingKeysWithMappedValues = function(keys, invertedDateStringMap, widgetFields) {
|
|
7772
|
-
if (!keys || !invertedDateStringMap) {
|
|
7773
|
-
return;
|
|
7774
|
-
}
|
|
7775
|
-
const dateWidgetFields = lodash.filter(widgetFields, obj => obj.type === 'Date');
|
|
7776
|
-
const replaceNestedKeys = (nestedKeys) => {
|
|
7777
|
-
for (let i = 0; i < nestedKeys.length; i++) {
|
|
7778
|
-
if (Array.isArray(nestedKeys[i])) {
|
|
7779
|
-
replaceNestedKeys(nestedKeys[i]);
|
|
7780
|
-
}
|
|
7781
|
-
else if (invertedDateStringMap[nestedKeys[i]] && widgetFields[i] && widgetFields[i].type === 'Date') {
|
|
7782
|
-
const getFormat = (obj) => (lodash.get(obj, 'format') ?? '').toUpperCase();
|
|
7783
|
-
const isSameDateFormats = lodash.every(dateWidgetFields, obj => getFormat(obj) === getFormat(dateWidgetFields[0]));
|
|
7784
|
-
|
|
7785
|
-
if (isSameDateFormats) {
|
|
7786
|
-
nestedKeys[i] = invertedDateStringMap[nestedKeys[i]];
|
|
7787
|
-
continue;
|
|
7788
|
-
}
|
|
7789
|
-
|
|
7790
|
-
// Reformatting dates when "widgetFields" array contains fields with different formats
|
|
7791
|
-
// Fixes the issue - https://datarailsteam.atlassian.net/browse/DR-37813
|
|
7792
|
-
// Will be removed once "format_dates_as_other_axis_types" FF is deleted
|
|
7793
|
-
const format = (widgetFields[i].format ?? "MM/DD/YYYY").toUpperCase();
|
|
7794
|
-
const date = new Date(parseInt(nestedKeys[i]) * 1000);
|
|
7795
|
-
const formattedDateString = moment_lib(date).utcOffset(0).format(format) + "";
|
|
7796
|
-
nestedKeys[i] = formattedDateString;
|
|
7797
|
-
}
|
|
7798
|
-
}
|
|
7799
|
-
};
|
|
7800
|
-
|
|
7801
|
-
for (let i = 0; i < keys.length; i++) {
|
|
7802
|
-
replaceNestedKeys(keys[i]);
|
|
7803
|
-
}
|
|
7804
|
-
}
|
|
7805
|
-
|
|
7806
7739
|
highchartsRenderer.getWidgetDataSorters = function (res, widget, defaultDateFormat) {
|
|
7807
|
-
const isFormattingDatesAsOtherAxisTypes = highchartsRenderer.isFormattingDatesAsOtherAxisTypes();
|
|
7808
|
-
|
|
7809
7740
|
if ($.pivotUtilities && !$.pivotUtilities.additionalFieldsList) {
|
|
7810
7741
|
$.pivotUtilities.additionalFieldsList = [
|
|
7811
7742
|
{key: 'DR_Average', name: 'DR_Average'},
|
|
@@ -7830,7 +7761,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7830
7761
|
|
|
7831
7762
|
datesFields = lodash.map(datesFields, function (row) {
|
|
7832
7763
|
return {
|
|
7833
|
-
"format":
|
|
7764
|
+
"format": null,
|
|
7834
7765
|
"name": row.name,
|
|
7835
7766
|
"type": row.type,
|
|
7836
7767
|
"values": [],
|
|
@@ -7838,44 +7769,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7838
7769
|
} //'MMM - yyyy' format
|
|
7839
7770
|
});
|
|
7840
7771
|
|
|
7841
|
-
if (!isFormattingDatesAsOtherAxisTypes) {
|
|
7842
|
-
lodash.forEach(datesFields, function (row) {
|
|
7843
|
-
row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
|
|
7844
|
-
});
|
|
7845
|
-
}
|
|
7846
|
-
|
|
7847
7772
|
if (datesFields.length > 0) {
|
|
7848
7773
|
widget.pivot.invertedDateStringMap = {};
|
|
7849
7774
|
lodash.forEach(res, function (element) {
|
|
7850
7775
|
for (var i in datesFields) {
|
|
7851
7776
|
if (element.hasOwnProperty(datesFields[i].name)) {
|
|
7852
7777
|
datesFields[i].values.push(element[datesFields[i].name]);
|
|
7853
|
-
|
|
7854
|
-
if (!isFormattingDatesAsOtherAxisTypes) {
|
|
7855
|
-
const dateStringValue = highchartsRenderer.returnRawDataValue(
|
|
7856
|
-
datesFields[i].type, element[datesFields[i].name],
|
|
7857
|
-
defaultDateFormat ? defaultDateFormat : datesFields[i].format,
|
|
7858
|
-
datesFields[i].name, datesFields[i].val_not_convert);
|
|
7859
|
-
if (widget.pivot) {
|
|
7860
|
-
if (!widget.pivot.dateValuesDictionary) {
|
|
7861
|
-
widget.pivot.dateValuesDictionary = {}
|
|
7862
|
-
}
|
|
7863
|
-
widget.pivot.dateValuesDictionary[dateStringValue] = element[datesFields[i].name];
|
|
7864
|
-
widget.pivot.invertedDateStringMap[element[datesFields[i].name]] = dateStringValue;
|
|
7865
|
-
}
|
|
7866
|
-
element[datesFields[i].name] = dateStringValue;
|
|
7867
|
-
}
|
|
7868
7778
|
}
|
|
7869
7779
|
}
|
|
7870
|
-
if (!isFormattingDatesAsOtherAxisTypes) {
|
|
7871
|
-
const keysObject = lodash.get(widget, 'pivot.keysObject');
|
|
7872
|
-
|
|
7873
|
-
lodash.forEach(['col_keys', 'row_keys', 'row_keys_by_cols'], (keysListName) => {
|
|
7874
|
-
const widgetFields = keysListName === 'col_keys' ? widget.cols : widget.rows;
|
|
7875
|
-
highchartsRenderer
|
|
7876
|
-
.replaceSortingKeysWithMappedValues(lodash.get(keysObject, keysListName), widget.pivot.invertedDateStringMap, widgetFields);
|
|
7877
|
-
});
|
|
7878
|
-
}
|
|
7879
7780
|
});
|
|
7880
7781
|
}
|
|
7881
7782
|
};
|
|
@@ -8235,9 +8136,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
8235
8136
|
filter.values = field.type === 'Date' && colKey !== NULL_VALUE
|
|
8236
8137
|
? highchartsRenderer.createDateTypeFromValue(colKey, format)
|
|
8237
8138
|
: [colKey];
|
|
8238
|
-
filter.value_to_show = field.type === 'Date'
|
|
8239
|
-
? highchartsRenderer.returnRawDataValue(field.type, +colKey, format, field.name)
|
|
8240
|
-
: colKey;
|
|
8139
|
+
filter.value_to_show = field.type === 'Date' ? highchartsRenderer.returnRawDataValue(field.type, +colKey, format, field.name) : colKey;
|
|
8241
8140
|
}
|
|
8242
8141
|
}
|
|
8243
8142
|
|
|
@@ -8330,12 +8229,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
8330
8229
|
return pivotData.isFormattingAxisLabels;
|
|
8331
8230
|
}
|
|
8332
8231
|
|
|
8333
|
-
highchartsRenderer.isFormattingDatesAsOtherAxisTypes = function () {
|
|
8334
|
-
return highchartsRenderer.hasFeature(FEATURES.FORMAT_DATES_AS_OTHER_AXIS_TYPES);
|
|
8335
|
-
}
|
|
8336
|
-
|
|
8337
8232
|
// Method for getting formatted kyes for Axis (cols, rows)
|
|
8338
|
-
highchartsRenderer.getFormattedKey = function (initialKey, pivotData, type
|
|
8233
|
+
highchartsRenderer.getFormattedKey = function (initialKey, pivotData, type) {
|
|
8339
8234
|
const isFlatKey = lodash.isString(initialKey) || lodash.isNumber(initialKey);
|
|
8340
8235
|
if (isFlatKey || lodash.isArray(initialKey)) {
|
|
8341
8236
|
let values = isFlatKey ? initialKey.toString().split(highchartsRenderer.delimer) : lodash.cloneDeep(initialKey);
|
|
@@ -8344,10 +8239,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
8344
8239
|
const formatInfo = pivotData[type][key] || {};
|
|
8345
8240
|
const valueToFloat = parseFloat(value);
|
|
8346
8241
|
const isDate = formatInfo.type === 'Date' && (moment_lib(valueToFloat).isValid() || moment_lib(value, formatInfo.format).isValid());
|
|
8347
|
-
const isDateFormatting = isDate && (forceFormatDates || highchartsRenderer.isFormattingDatesAsOtherAxisTypes());
|
|
8348
8242
|
const isNumberFormatting = !isDate && formatInfo.format && highchartsRenderer.isFormattingNumberAxis(pivotData);
|
|
8349
8243
|
|
|
8350
|
-
if (isNumberFormatting ||
|
|
8244
|
+
if (isNumberFormatting || isDate) {
|
|
8351
8245
|
values[key] = highchartsRenderer.returnRawDataValue(
|
|
8352
8246
|
formatInfo.type,
|
|
8353
8247
|
!isNaN(valueToFloat) ? valueToFloat : value,
|
|
@@ -8372,13 +8266,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
8372
8266
|
return highchartsRenderer.getFormattedKey(initialValue, pivotData, 'rowFormats')
|
|
8373
8267
|
}
|
|
8374
8268
|
|
|
8375
|
-
highchartsRenderer.getFormattedKeys = function(pivotData, isCols, keys
|
|
8269
|
+
highchartsRenderer.getFormattedKeys = function(pivotData, isCols, keys) {
|
|
8376
8270
|
keys = keys || (isCols ? pivotData.getColKeys() : pivotData.getRowKeys());
|
|
8377
|
-
return lodash.map(keys, key => highchartsRenderer.getFormattedKey(key, pivotData, isCols ? 'colFormats' : 'rowFormats'
|
|
8271
|
+
return lodash.map(keys, key => highchartsRenderer.getFormattedKey(key, pivotData, isCols ? 'colFormats' : 'rowFormats'));
|
|
8378
8272
|
}
|
|
8379
8273
|
|
|
8380
|
-
highchartsRenderer.getFormattedColKeys = function(pivotData, keys
|
|
8381
|
-
return highchartsRenderer.getFormattedKeys(pivotData, true, keys
|
|
8274
|
+
highchartsRenderer.getFormattedColKeys = function(pivotData, keys) {
|
|
8275
|
+
return highchartsRenderer.getFormattedKeys(pivotData, true, keys);
|
|
8382
8276
|
}
|
|
8383
8277
|
|
|
8384
8278
|
highchartsRenderer.getFormattedRowKeys = function(pivotData, keys) {
|
|
@@ -5088,12 +5088,7 @@ describe('highcharts_renderer', () => {
|
|
|
5088
5088
|
});
|
|
5089
5089
|
|
|
5090
5090
|
describe('formatting Dates', () => {
|
|
5091
|
-
|
|
5092
|
-
lodash.set(document, 'ReportHippo.user.features', []);
|
|
5093
|
-
});
|
|
5094
|
-
|
|
5095
|
-
it('should return formatted multivalue colKey as array (format_dates_as_other_axis_types is ON)', () => {
|
|
5096
|
-
highchartsRenderer.setFeatures(['format_dates_as_other_axis_types']);
|
|
5091
|
+
it('should return formatted multivalue colKey as array', () => {
|
|
5097
5092
|
const initialKey = [1687277052, 1687277052];
|
|
5098
5093
|
const pivotData = {
|
|
5099
5094
|
colFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
|
|
@@ -5104,8 +5099,7 @@ describe('highcharts_renderer', () => {
|
|
|
5104
5099
|
expect(formattedKey).toEqual(['06/20/2023', 'Jun-23']);
|
|
5105
5100
|
});
|
|
5106
5101
|
|
|
5107
|
-
it('should return formatted multivalue rowKey as array
|
|
5108
|
-
highchartsRenderer.setFeatures(['format_dates_as_other_axis_types']);
|
|
5102
|
+
it('should return formatted multivalue rowKey as array', () => {
|
|
5109
5103
|
const initialKey = [1687277052, 1687277052];
|
|
5110
5104
|
const pivotData = {
|
|
5111
5105
|
rowFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
|
|
@@ -5116,32 +5110,7 @@ describe('highcharts_renderer', () => {
|
|
|
5116
5110
|
expect(formattedKey).toEqual(['06/20/2023', 'Jun-23']);
|
|
5117
5111
|
});
|
|
5118
5112
|
|
|
5119
|
-
it('should return NOT formatted multivalue colKey as array (format_dates_as_other_axis_types is OFF)', () => {
|
|
5120
|
-
highchartsRenderer.setFeatures([]);
|
|
5121
|
-
const initialKeyAlreadyFormatted = ['10/10/2020', '10/10/2021'];
|
|
5122
|
-
const pivotData = {
|
|
5123
|
-
colFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
|
|
5124
|
-
isFormattingAxisLabels: true,
|
|
5125
|
-
};
|
|
5126
|
-
const type = 'colFormats';
|
|
5127
|
-
const formattedKey = highchartsRenderer.getFormattedKey(initialKeyAlreadyFormatted, pivotData, type);
|
|
5128
|
-
expect(formattedKey).toEqual(initialKeyAlreadyFormatted);
|
|
5129
|
-
});
|
|
5130
|
-
|
|
5131
|
-
it('should return NOT formatted multivalue rowKey as array (format_dates_as_other_axis_types is OFF)', () => {
|
|
5132
|
-
highchartsRenderer.setFeatures([]);
|
|
5133
|
-
const initialKeyAlreadyFormatted = ['10/10/2020', '10/10/2021'];
|
|
5134
|
-
const pivotData = {
|
|
5135
|
-
rowFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
|
|
5136
|
-
isFormattingAxisLabels: true,
|
|
5137
|
-
};
|
|
5138
|
-
const type = 'rowFormats';
|
|
5139
|
-
const formattedKey = highchartsRenderer.getFormattedKey(initialKeyAlreadyFormatted, pivotData, type);
|
|
5140
|
-
expect(formattedKey).toEqual(initialKeyAlreadyFormatted);
|
|
5141
|
-
});
|
|
5142
|
-
|
|
5143
5113
|
it('should return NOT formatted value when type is Date but value is not a valid moment date', () => {
|
|
5144
|
-
lodash.set(document, 'ReportHippo.user.features', ['format_dates_as_other_axis_types']);
|
|
5145
5114
|
const initialKey = ['Some Text Value', 'Another Text'];
|
|
5146
5115
|
const pivotData = {
|
|
5147
5116
|
colFormats: [{ type: 'Date' }, { type: 'Date' }],
|
|
@@ -5151,28 +5120,6 @@ describe('highcharts_renderer', () => {
|
|
|
5151
5120
|
const formattedKey = highchartsRenderer.getFormattedKey(initialKey, pivotData, type);
|
|
5152
5121
|
expect(formattedKey).toEqual(initialKey);
|
|
5153
5122
|
});
|
|
5154
|
-
|
|
5155
|
-
it('should return formatted value when type is Date and value is a valid moment date (format_dates_as_other_axis_types is OFF)', () => {
|
|
5156
|
-
const initialKey = ['Feb-24', 'Jan-24'];
|
|
5157
|
-
const pivotData = {
|
|
5158
|
-
colFormats: [{ type: 'Date' }, { type: 'Date' }],
|
|
5159
|
-
isFormattingAxisLabels: true,
|
|
5160
|
-
};
|
|
5161
|
-
const type = 'colFormats';
|
|
5162
|
-
const formattedKey = highchartsRenderer.getFormattedKey(initialKey, pivotData, type);
|
|
5163
|
-
expect(formattedKey).toEqual(initialKey);
|
|
5164
|
-
});
|
|
5165
|
-
|
|
5166
|
-
it('should return formatted value when type is Date and value is a valid moment date (with valid format)', () => {
|
|
5167
|
-
const initialKey = ['Q4-20'];
|
|
5168
|
-
const pivotData = {
|
|
5169
|
-
colFormats: [{ format: "[Q]Q-YY", name: "Date", type: "Date" }],
|
|
5170
|
-
isFormattingAxisLabels: true,
|
|
5171
|
-
};
|
|
5172
|
-
const type = 'colFormats';
|
|
5173
|
-
const formattedKey = highchartsRenderer.getFormattedKey(initialKey, pivotData, type);
|
|
5174
|
-
expect(formattedKey).toEqual(initialKey);
|
|
5175
|
-
});
|
|
5176
5123
|
});
|
|
5177
5124
|
});
|
|
5178
5125
|
|
|
@@ -5274,7 +5221,7 @@ describe('highcharts_renderer', () => {
|
|
|
5274
5221
|
|
|
5275
5222
|
it('should getFormattedColKeys call getFormattedKeys for colFormats', () => {
|
|
5276
5223
|
highchartsRenderer.getFormattedColKeys('test1', 'test2');
|
|
5277
|
-
expect(highchartsRenderer.getFormattedKeys).toHaveBeenCalledWith('test1', true, 'test2'
|
|
5224
|
+
expect(highchartsRenderer.getFormattedKeys).toHaveBeenCalledWith('test1', true, 'test2');
|
|
5278
5225
|
});
|
|
5279
5226
|
|
|
5280
5227
|
it('should getFormattedRowKeys call getFormattedKeys for rowFormats', () => {
|
|
@@ -6027,14 +5974,6 @@ describe('highcharts_renderer', () => {
|
|
|
6027
5974
|
describe('Function tableCSVExportRenderer', () => {
|
|
6028
5975
|
window._ = lodash;
|
|
6029
5976
|
|
|
6030
|
-
beforeEach(() => {
|
|
6031
|
-
lodash.set(document, 'ReportHippo.user.features', ['format_dates_as_other_axis_types']);
|
|
6032
|
-
});
|
|
6033
|
-
|
|
6034
|
-
afterEach(() => {
|
|
6035
|
-
lodash.set(document, 'ReportHippo.user.features', []);
|
|
6036
|
-
});
|
|
6037
|
-
|
|
6038
5977
|
it('should create csv json object representation based on pivot data (only cols)', () => {
|
|
6039
5978
|
const chartOptions = {
|
|
6040
5979
|
table_options: {
|
|
@@ -6279,6 +6218,119 @@ describe('highcharts_renderer', () => {
|
|
|
6279
6218
|
]);
|
|
6280
6219
|
});
|
|
6281
6220
|
});
|
|
6221
|
+
|
|
6222
|
+
describe('cases for date in rows (timestamp row keys)', () => {
|
|
6223
|
+
const inputs = [
|
|
6224
|
+
{
|
|
6225
|
+
"Date": 1653955200,
|
|
6226
|
+
"Type": 'Food',
|
|
6227
|
+
"Amount": 2849521.69
|
|
6228
|
+
},
|
|
6229
|
+
{
|
|
6230
|
+
"Date": 1653955200,
|
|
6231
|
+
"Type": 'Technology',
|
|
6232
|
+
"Amount": 321123
|
|
6233
|
+
},
|
|
6234
|
+
{
|
|
6235
|
+
"Date": 1653177600,
|
|
6236
|
+
"Type": 'Food',
|
|
6237
|
+
"Amount": 3141257.27
|
|
6238
|
+
},
|
|
6239
|
+
{
|
|
6240
|
+
"Date": 1653177600,
|
|
6241
|
+
"Type": 'Technology',
|
|
6242
|
+
"Amount": 4321
|
|
6243
|
+
},
|
|
6244
|
+
{
|
|
6245
|
+
"Date": 1653955200,
|
|
6246
|
+
"Amount": 123
|
|
6247
|
+
},
|
|
6248
|
+
{
|
|
6249
|
+
"Type": 'Technology',
|
|
6250
|
+
"Amount": 1
|
|
6251
|
+
},
|
|
6252
|
+
{
|
|
6253
|
+
"Type": 'Food',
|
|
6254
|
+
"Amount": 2
|
|
6255
|
+
},
|
|
6256
|
+
{
|
|
6257
|
+
"Date": 1653177600,
|
|
6258
|
+
"Amount": 321
|
|
6259
|
+
},
|
|
6260
|
+
{
|
|
6261
|
+
"Amount": 9834311.05
|
|
6262
|
+
},
|
|
6263
|
+
{
|
|
6264
|
+
"col_keys": [
|
|
6265
|
+
['Food'],
|
|
6266
|
+
['Technology'],
|
|
6267
|
+
],
|
|
6268
|
+
"row_keys": [
|
|
6269
|
+
[1653177600],
|
|
6270
|
+
[1653955200]
|
|
6271
|
+
]
|
|
6272
|
+
}
|
|
6273
|
+
];
|
|
6274
|
+
const subOptions = {
|
|
6275
|
+
"cols": ["Type"],
|
|
6276
|
+
"rows": ["Date"],
|
|
6277
|
+
"keysObject": {
|
|
6278
|
+
"row_keys": [[1653177600], [1653955200]],
|
|
6279
|
+
"col_keys": [["Food"], ["Technology"]],
|
|
6280
|
+
},
|
|
6281
|
+
"colFormats": [
|
|
6282
|
+
{
|
|
6283
|
+
"type": "Text",
|
|
6284
|
+
"name": "Type",
|
|
6285
|
+
"val_not_convert": []
|
|
6286
|
+
},
|
|
6287
|
+
],
|
|
6288
|
+
"rowFormats": [
|
|
6289
|
+
{
|
|
6290
|
+
"type": "Date",
|
|
6291
|
+
"name": "Date",
|
|
6292
|
+
"val_not_convert": []
|
|
6293
|
+
},
|
|
6294
|
+
],
|
|
6295
|
+
"rendererOptions": {
|
|
6296
|
+
},
|
|
6297
|
+
};
|
|
6298
|
+
|
|
6299
|
+
it('should format timestamp row keys as dates in csv export', () => {
|
|
6300
|
+
const chartOptions = {
|
|
6301
|
+
table_options: {
|
|
6302
|
+
show_column_total: true,
|
|
6303
|
+
show_row_total: true,
|
|
6304
|
+
},
|
|
6305
|
+
};
|
|
6306
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
|
6307
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
|
6308
|
+
expect(csvJson).toEqual([
|
|
6309
|
+
["Type", "Food", "Technology", "Totals"],
|
|
6310
|
+
["Date"],
|
|
6311
|
+
["05/22/2022", 1, 1, 1],
|
|
6312
|
+
["05/31/2022", 1, 1, 1],
|
|
6313
|
+
["Totals", 1, 1, 2]
|
|
6314
|
+
]);
|
|
6315
|
+
});
|
|
6316
|
+
|
|
6317
|
+
it('should format timestamp row keys as dates without totals', () => {
|
|
6318
|
+
const chartOptions = {
|
|
6319
|
+
table_options: {
|
|
6320
|
+
show_column_total: false,
|
|
6321
|
+
show_row_total: false,
|
|
6322
|
+
},
|
|
6323
|
+
};
|
|
6324
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
|
6325
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
|
6326
|
+
expect(csvJson).toEqual([
|
|
6327
|
+
["Type", "Food", "Technology"],
|
|
6328
|
+
["Date"],
|
|
6329
|
+
["05/22/2022", 1, 1],
|
|
6330
|
+
["05/31/2022", 1, 1],
|
|
6331
|
+
]);
|
|
6332
|
+
});
|
|
6333
|
+
});
|
|
6282
6334
|
});
|
|
6283
6335
|
|
|
6284
6336
|
describe("Function returnRawDataValue", () => {
|
|
@@ -8154,7 +8206,6 @@ describe('highcharts_renderer', () => {
|
|
|
8154
8206
|
});
|
|
8155
8207
|
spyOn(highchartsRenderer, 'getFormattedColKey')
|
|
8156
8208
|
.and.callFake((initialName, pivotData) => `formatted(${ initialName })`);
|
|
8157
|
-
spyOn(highchartsRenderer, 'isFormattingDatesAsOtherAxisTypes').and.returnValue(true);
|
|
8158
8209
|
});
|
|
8159
8210
|
|
|
8160
8211
|
it("should create appropriate series for case when only one column field and one total", () => {
|
|
@@ -9215,7 +9266,6 @@ describe('highcharts_renderer', () => {
|
|
|
9215
9266
|
.and.callFake((initialName, pivotData) => `formatted_col(${ initialName })`);
|
|
9216
9267
|
spyOn(highchartsRenderer, 'getFormattedRowKey')
|
|
9217
9268
|
.and.callFake((initialName, pivotData) => `formatted_row(${ initialName })`);
|
|
9218
|
-
spyOn(highchartsRenderer, 'isFormattingDatesAsOtherAxisTypes').and.returnValue(true);
|
|
9219
9269
|
});
|
|
9220
9270
|
|
|
9221
9271
|
it("should create appropriate series for case no breakdown field (one row value - Variance instead)", () => {
|