@datarailsshared/dr_renderer 1.2.310-dragons → 1.2.311
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_pivottable.js +2 -13
- package/src/highcharts_renderer.js +199 -90
- package/src/pivottable.js +0 -1
- package/tests/highcharts_renderer.test.js +654 -0
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
@@ -91,7 +91,6 @@ let initDRPivotTable = function($, window, document) {
|
|
91
91
|
|
92
92
|
DRPivotData.prototype.arrSort = function(attrs) {
|
93
93
|
var a, sortersArr;
|
94
|
-
const sortByValueAttrs = this.sortByValueAttrs;
|
95
94
|
sortersArr = (function() {
|
96
95
|
var l, len1, results;
|
97
96
|
results = [];
|
@@ -101,21 +100,11 @@ let initDRPivotTable = function($, window, document) {
|
|
101
100
|
}
|
102
101
|
return results;
|
103
102
|
}).call(this);
|
104
|
-
|
105
103
|
return function(a, b) {
|
106
104
|
var comparison, i, sorter;
|
107
105
|
for (i in sortersArr) {
|
108
|
-
|
109
|
-
|
110
|
-
if (sortByValueAttrs.indexOf(attrs[index]) !== -1) {
|
111
|
-
|
112
|
-
// For case current Field attrs[index] is sorted by value we are concatenating values passed to sorter function
|
113
|
-
// Concatenation is done from first field in a block (first axis or first series) until current field index.
|
114
|
-
// Cause for this case sorting will be as list of these concatenated strings (which is prepared in getSortingByValueOrderList)
|
115
|
-
comparison = sorter(a.slice(0, index + 1).join(','), b.slice(0, index + 1).join(','));
|
116
|
-
} else {
|
117
|
-
comparison = sorter(a[index], b[index]);
|
118
|
-
}
|
106
|
+
sorter = sortersArr[i];
|
107
|
+
comparison = sorter(a[i], b[i]);
|
119
108
|
if (comparison !== 0) {
|
120
109
|
return comparison;
|
121
110
|
}
|
@@ -1150,7 +1150,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1150
1150
|
ob.name = row_n_value.join(highchartsRenderer.delimer)
|
1151
1151
|
.replace(highchartsRenderer.DR_OTHERS_KEY, othersName);
|
1152
1152
|
}
|
1153
|
-
|
1154
1153
|
lodash.forEach(col_n_keys, function (col_n_value, index) {
|
1155
1154
|
var agg = pivotData.getAggregator(row_n_value, col_n_value);
|
1156
1155
|
var val = agg.value();
|
@@ -1392,7 +1391,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1392
1391
|
if (opts.trendLine) {
|
1393
1392
|
const a = ((ySum * squareXSum) - (xSum * xySum)) / ((n * squareXSum) - (xSum * xSum));
|
1394
1393
|
const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
|
1395
|
-
|
1396
1394
|
const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
|
1397
1395
|
trendSeries.className = 'trendSeries';
|
1398
1396
|
trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
|
@@ -1403,7 +1401,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1403
1401
|
if (colors && colors[i]) {
|
1404
1402
|
trendSeries.color = colors[i];
|
1405
1403
|
}
|
1406
|
-
|
1407
1404
|
trendSerieses.push(trendSeries);
|
1408
1405
|
}
|
1409
1406
|
i++;
|
@@ -1420,7 +1417,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1420
1417
|
}
|
1421
1418
|
|
1422
1419
|
let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
|
1423
|
-
|
1424
1420
|
if (opts.comboOptions && lodash.includes(chartType,'combo') && !lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
|
1425
1421
|
chart_series.forEach((series, seriesIndex) => {
|
1426
1422
|
const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
|
@@ -1640,18 +1636,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1640
1636
|
? lodash.get(waterfallOptions, 'colors', {}).increase || baseColor.increase
|
1641
1637
|
: lodash.get(waterfallOptions, 'colors', {}).decrease || baseColor.decrease;
|
1642
1638
|
}
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1639
|
+
if (val !== 0) {
|
1640
|
+
resultObject.data.push({
|
1641
|
+
y: val,
|
1642
|
+
name: lodash.replace(
|
1643
|
+
lodash.unescape(name), highchartsRenderer.DR_OTHERS_KEY, highchartsRenderer.getOthersName(opts)
|
1644
|
+
),
|
1645
|
+
totalIndex: value.trend === 'total' ? index : undefined,
|
1646
|
+
isSum: value.trend === 'total',
|
1647
|
+
isTotal: value.trend === 'total',
|
1648
|
+
color,
|
1649
|
+
colsForTotal: value.trend === 'total' ? keys : null,
|
1650
|
+
});
|
1651
|
+
}
|
1655
1652
|
});
|
1656
1653
|
chart_series.push(resultObject);
|
1657
1654
|
chart_series.push(
|
@@ -2675,7 +2672,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
2675
2672
|
}
|
2676
2673
|
};
|
2677
2674
|
}
|
2678
|
-
|
2675
|
+
|
2679
2676
|
if (lodash.get(chartOptions, 'plotOptions.series.point.events')) {
|
2680
2677
|
chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
|
2681
2678
|
chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
|
@@ -4411,42 +4408,72 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4411
4408
|
return ret_str;
|
4412
4409
|
};
|
4413
4410
|
|
4414
|
-
highchartsRenderer.
|
4415
|
-
let
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
let valueForComparison;
|
4421
|
-
if (sortingOptions.sort_by === 'variance') {
|
4422
|
-
const varianceConfig = widget.options.chartOptions.delta_column;
|
4423
|
-
const data = pivotData.input;
|
4424
|
-
const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
|
4425
|
-
const varianceRowsForCurrentKey = lodash.filter(data, row =>
|
4426
|
-
row[varianceField.name] === varianceConfig.name
|
4427
|
-
&& lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
|
4428
|
-
);
|
4411
|
+
highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
|
4412
|
+
let rowAttrs, rowKeys, colKeys, colAttrs;
|
4413
|
+
rowAttrs = pivotData.rowAttrs;
|
4414
|
+
rowKeys = pivotData.rowKeys;
|
4415
|
+
colKeys = pivotData.colKeys;
|
4416
|
+
colAttrs = pivotData.colAttrs;
|
4429
4417
|
|
4430
|
-
valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
|
4431
|
-
} else {
|
4432
|
-
let getAggregatorParams = [firstArray, secondArray];
|
4433
4418
|
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4419
|
+
if (!colAttrs || colAttrs.length == 0) {
|
4420
|
+
return null;
|
4421
|
+
}
|
4422
|
+
|
4423
|
+
let values_names_arr = [];
|
4424
|
+
let keysArray = sortingOptions.field ? rowKeys : colKeys;
|
4425
|
+
|
4426
|
+
lodash.forEach(keysArray, function (val) {
|
4427
|
+
let firstArray = sortingOptions.field ? [val[0]] : [];
|
4428
|
+
let secondArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
|
4429
|
+
let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
|
4439
4430
|
|
4440
|
-
|
4441
|
-
|
4431
|
+
if (aggregator_subtotal) {
|
4432
|
+
let value_subtotal = aggregator_subtotal.value();
|
4433
|
+
if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
|
4434
|
+
value_subtotal = Math.abs(value_subtotal);
|
4442
4435
|
}
|
4436
|
+
values_names_arr.push({name: val[0], value: value_subtotal});
|
4443
4437
|
}
|
4438
|
+
});
|
4439
|
+
|
4440
|
+
// ORDERING
|
4441
|
+
let sorting_vector = ['asc'];
|
4442
|
+
if (sortingOptions && sortingOptions.type == 'largestToSmallest') {
|
4443
|
+
sorting_vector = ['desc'];
|
4444
|
+
}
|
4445
|
+
values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
|
4446
|
+
|
4447
|
+
// map only names
|
4448
|
+
let attr_sorted_values = lodash.map(values_names_arr, 'name');
|
4449
|
+
return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
|
4450
|
+
};
|
4444
4451
|
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4452
|
+
highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
|
4453
|
+
let rowAttrs, rowKeys, colKeys, colAttrs;
|
4454
|
+
rowAttrs = pivotData.rowAttrs;
|
4455
|
+
rowKeys = pivotData.rowKeys;
|
4456
|
+
colKeys = pivotData.colKeys;
|
4457
|
+
colAttrs = pivotData.colAttrs;
|
4458
|
+
|
4459
|
+
if (!rowAttrs || rowAttrs.length == 0) {
|
4460
|
+
return null;
|
4461
|
+
}
|
4462
|
+
|
4463
|
+
let values_names_arr = [];
|
4464
|
+
let keysArray = sortingOptions.field ? colKeys : rowKeys;
|
4465
|
+
|
4466
|
+
lodash.forEach(keysArray, function (val) {
|
4467
|
+
let firstArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
|
4468
|
+
let secondArray = sortingOptions.field ? [val[0]] : [];
|
4469
|
+
let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
|
4470
|
+
|
4471
|
+
if (aggregator_subtotal) {
|
4472
|
+
let value_subtotal = aggregator_subtotal.value();
|
4473
|
+
if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
|
4474
|
+
value_subtotal = Math.abs(value_subtotal);
|
4448
4475
|
}
|
4449
|
-
values_names_arr.push({name:
|
4476
|
+
values_names_arr.push({name: val[0], value: value_subtotal});
|
4450
4477
|
}
|
4451
4478
|
});
|
4452
4479
|
|
@@ -4458,33 +4485,36 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4458
4485
|
values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
|
4459
4486
|
|
4460
4487
|
// map only names
|
4461
|
-
|
4488
|
+
let attr_sorted_values = lodash.map(values_names_arr, 'name');
|
4489
|
+
return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
|
4462
4490
|
};
|
4463
4491
|
|
4464
|
-
highchartsRenderer.generateSortingFunctionByValues = function (
|
4492
|
+
highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
|
4493
|
+
let new_map;
|
4494
|
+
let axis = highchartsRenderer.getAxis(sortingOptions.axis, opts);
|
4495
|
+
if (axis == 'col_total') {
|
4496
|
+
new_map = highchartsRenderer.getNewAttrSortingForCol(pivotData, sortingOptions);
|
4497
|
+
} else if (axis == 'row_total') {
|
4498
|
+
new_map = highchartsRenderer.getNewAttrSortingForRow(pivotData, sortingOptions);
|
4499
|
+
}
|
4500
|
+
|
4465
4501
|
let old_sorters_function = opts.sorters;
|
4466
4502
|
if (!old_sorters_function) {
|
4467
4503
|
old_sorters_function = function () {
|
4468
4504
|
};
|
4469
4505
|
}
|
4470
|
-
|
4471
|
-
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
sortingOptions.sorting,
|
4479
|
-
pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
|
4480
|
-
pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
|
4481
|
-
fieldIndex,
|
4482
|
-
widget
|
4483
|
-
);
|
4484
|
-
return $.pivotUtilities.sortAs(orderedNamesList);
|
4485
|
-
} else {
|
4486
|
-
return old_sorters_function(attr);
|
4506
|
+
if (new_map) {
|
4507
|
+
var sortAs = $.pivotUtilities.sortAs;
|
4508
|
+
let new_sorters_function = function (attr) {
|
4509
|
+
if (new_map.name == attr) {
|
4510
|
+
return $.pivotUtilities.sortAs(new_map.values);
|
4511
|
+
} else {
|
4512
|
+
return old_sorters_function(attr);
|
4513
|
+
}
|
4487
4514
|
}
|
4515
|
+
return new_sorters_function;
|
4516
|
+
} else {
|
4517
|
+
return old_sorters_function;
|
4488
4518
|
}
|
4489
4519
|
};
|
4490
4520
|
|
@@ -4688,7 +4718,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4688
4718
|
result = null;
|
4689
4719
|
try {
|
4690
4720
|
pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
|
4691
|
-
pivotData.sortByValueAttrs = [];
|
4692
4721
|
try {
|
4693
4722
|
if (options && options.onlyOptions) {
|
4694
4723
|
if (!opts.rendererOptions) {
|
@@ -4696,15 +4725,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4696
4725
|
}
|
4697
4726
|
opts.rendererOptions.onlyOptions = true;
|
4698
4727
|
}
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
|
4703
|
-
);
|
4704
|
-
|
4705
|
-
if (sortByValueSettings.length) {
|
4706
|
-
pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
|
4707
|
-
let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
|
4728
|
+
var totalFilters = lodash.get(opts, 'rendererOptions.total_value_options', null);
|
4729
|
+
if (totalFilters && totalFilters.sorting_options) {
|
4730
|
+
let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(totalFilters.sorting_options, pivotData, opts);
|
4708
4731
|
opts.sorters = new_sorting_function;
|
4709
4732
|
optsFiltered.sorters = new_sorting_function;
|
4710
4733
|
pivotData.sorters = new_sorting_function;
|
@@ -5019,7 +5042,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
5019
5042
|
};
|
5020
5043
|
|
5021
5044
|
highchartsRenderer.isSystemField = function (field) {
|
5022
|
-
|
5045
|
+
const features = lodash.get(document, 'ReportHippo.user.features', []);
|
5046
|
+
const dynamicSystemFields = [];
|
5047
|
+
|
5048
|
+
const areMultipleAndScenarioTags = lodash.includes(features, 'multiple_dimension_tags')
|
5049
|
+
&& lodash.includes(features, 'use_new_scenario_tag');
|
5050
|
+
|
5051
|
+
if (areMultipleAndScenarioTags) {
|
5052
|
+
dynamicSystemFields.push('Scenario', 'Budget Cycle');
|
5053
|
+
}
|
5054
|
+
|
5055
|
+
const regexDelimer = '|';
|
5056
|
+
const dynamicSystemFieldsRegex = dynamicSystemFields.length ? dynamicSystemFields.join(regexDelimer) + regexDelimer : '';
|
5057
|
+
var regex = new RegExp(`^(${dynamicSystemFieldsRegex}Calc_Model_Name|Calc_Model_ID|Parent_Name|Parent_Id|FileBox_ID|FileBox_Name|DataMapper_Name|Doc_ID|Doc_version|Label|Submission_Date|User|table_id|Latest_In_Dim|Tab_name|CP_Name|DT_.+|VT_.+|System_.+)$`, "m");
|
5023
5058
|
|
5024
5059
|
return (field.category && field.category.includes("")) || regex.test(field.name)
|
5025
5060
|
};
|
@@ -7055,6 +7090,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7055
7090
|
value_name: 'is_percentage',
|
7056
7091
|
default_value: false,
|
7057
7092
|
hidden: true,
|
7093
|
+
}, {
|
7094
|
+
element_type: 'checkbox',
|
7095
|
+
element_label: 'Sort by variance',
|
7096
|
+
value_name: 'sort_by_variance',
|
7097
|
+
default_value: false,
|
7098
|
+
hidden: true
|
7099
|
+
}, {
|
7100
|
+
element_type: 'checkbox',
|
7101
|
+
element_label: 'Sort by absolute variance',
|
7102
|
+
value_name: 'sort_by_absolute_variance',
|
7103
|
+
default_value: false,
|
7104
|
+
hidden: true
|
7058
7105
|
}]
|
7059
7106
|
},
|
7060
7107
|
'delta_column_for_drill_down': {
|
@@ -7121,6 +7168,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7121
7168
|
value_name: 'is_percentage',
|
7122
7169
|
default_value: false,
|
7123
7170
|
hidden: true,
|
7171
|
+
}, {
|
7172
|
+
element_type: 'checkbox',
|
7173
|
+
element_label: 'Sort by variance',
|
7174
|
+
value_name: 'sort_by_variance',
|
7175
|
+
default_value: false,
|
7176
|
+
hidden: true
|
7177
|
+
}, {
|
7178
|
+
element_type: 'checkbox',
|
7179
|
+
element_label: 'Sort by absolute variance',
|
7180
|
+
value_name: 'sort_by_absolute_variance',
|
7181
|
+
default_value: false,
|
7182
|
+
hidden: true
|
7124
7183
|
}, {
|
7125
7184
|
element_type: 'checkbox',
|
7126
7185
|
element_label: 'Filter zero values',
|
@@ -8637,9 +8696,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8637
8696
|
const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
|
8638
8697
|
if (isCustomSorting) {
|
8639
8698
|
lodash.forEach(datesFields, function (field) {
|
8640
|
-
const fieldToSort = lodash.find(
|
8641
|
-
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8642
|
-
);
|
8699
|
+
const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
|
8643
8700
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8644
8701
|
});
|
8645
8702
|
}
|
@@ -8721,9 +8778,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8721
8778
|
});
|
8722
8779
|
} else if (isCustomSorting) {
|
8723
8780
|
lodash.forEach(rowsAndCols, function (field) {
|
8724
|
-
const fieldToSort = lodash.find(
|
8725
|
-
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8726
|
-
);
|
8781
|
+
const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
|
8727
8782
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8728
8783
|
});
|
8729
8784
|
}
|
@@ -8758,9 +8813,61 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8758
8813
|
}
|
8759
8814
|
|
8760
8815
|
/****** END *******/
|
8761
|
-
|
8762
|
-
|
8763
|
-
|
8816
|
+
|
8817
|
+
if (lodash.has(widget, "options.chartOptions.delta_column") &&
|
8818
|
+
widget.options.chartOptions.delta_column.field != '' &&
|
8819
|
+
(widget.options.chartOptions.delta_column.sort_by_variance ||
|
8820
|
+
widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
|
8821
|
+
widget.rows.length > 0 &&
|
8822
|
+
widget.cols.length > 0 &&
|
8823
|
+
widget.vals.length
|
8824
|
+
) {
|
8825
|
+
let variance_config = widget.options.chartOptions.delta_column;
|
8826
|
+
let val_field = widget.vals[0];
|
8827
|
+
let field_for_sorting = null;
|
8828
|
+
let field_with_variant = null;
|
8829
|
+
if (variance_config.field == "series") {
|
8830
|
+
field_for_sorting = widget.cols[0];
|
8831
|
+
field_with_variant = widget.rows[0];
|
8832
|
+
} else if (variance_config.field == "category") {
|
8833
|
+
field_for_sorting = widget.rows[0];
|
8834
|
+
field_with_variant = widget.cols[0];
|
8835
|
+
}
|
8836
|
+
|
8837
|
+
let data_sorted = lodash.filter(data, function (data_row) {
|
8838
|
+
return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
|
8839
|
+
});
|
8840
|
+
|
8841
|
+
const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
|
8842
|
+
|
8843
|
+
if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
|
8844
|
+
data_sorted = lodash.sortBy(data_sorted, function (o) {
|
8845
|
+
if (sorting_variance === 'desc') {
|
8846
|
+
return Math.abs(o[val_field.name]) * -1;
|
8847
|
+
}
|
8848
|
+
|
8849
|
+
return Math.abs(o[val_field.name]) * 1;
|
8850
|
+
});
|
8851
|
+
} else {
|
8852
|
+
data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
|
8853
|
+
}
|
8854
|
+
|
8855
|
+
let values_for_sort = lodash.map(data_sorted, function (data_row) {
|
8856
|
+
return data_row[field_for_sorting.name];
|
8857
|
+
});
|
8858
|
+
|
8859
|
+
values_for_sort = lodash.uniq(values_for_sort);
|
8860
|
+
|
8861
|
+
if (values_for_sort.length > 0) {
|
8862
|
+
let field = lodash.find(datesFields, {name: field_for_sorting.name});
|
8863
|
+
if (field) {
|
8864
|
+
field.values = values_for_sort;
|
8865
|
+
field.sorting = null;
|
8866
|
+
} else {
|
8867
|
+
datesFields.push({name: field_for_sorting.name, values: values_for_sort});
|
8868
|
+
}
|
8869
|
+
}
|
8870
|
+
} else if (widget.options && widget.options.sortingValues) {
|
8764
8871
|
var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
|
8765
8872
|
if (field) {
|
8766
8873
|
field.values = widget.options.sortingValues.values;
|
@@ -9095,17 +9202,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9095
9202
|
|
9096
9203
|
// if it is not total value - then add it as rowData data row and sum it up
|
9097
9204
|
// else - add total with calculated sum as new rowData data row (totals do not initially exist in BE response)
|
9098
|
-
if (value.trend !== 'total') {
|
9205
|
+
if (value && value.trend !== 'total') {
|
9099
9206
|
const rowIndex = lodash.findIndex(rowData, (responseRow) =>
|
9100
9207
|
lodash.every(categoryFields, (field, fieldKey) => responseRow[field.name] === value.key[fieldKey])
|
9101
9208
|
);
|
9102
|
-
|
9103
|
-
|
9104
|
-
|
9209
|
+
if (rowIndex >= 0) {
|
9210
|
+
modifiedRowData.push(rowData[rowIndex]);
|
9211
|
+
sum += rowData[rowIndex][valueField.name];
|
9212
|
+
rowData.splice(rowIndex, 1);
|
9213
|
+
}
|
9105
9214
|
} else {
|
9106
9215
|
const totalRow = {};
|
9107
9216
|
lodash.forEach(categoryFields, (field, fieldKey) => {
|
9108
|
-
totalRow[field.name] = value.key[fieldKey];
|
9217
|
+
totalRow[field.name] = value && value.key && value.key[fieldKey];
|
9109
9218
|
});
|
9110
9219
|
totalRow[valueField.name] = sum;
|
9111
9220
|
modifiedRowData.push(totalRow);
|
package/src/pivottable.js
CHANGED
@@ -1154,6 +1154,18 @@ describe('highcharts_renderer', () => {
|
|
1154
1154
|
};
|
1155
1155
|
expect(highchartsRenderer.isSystemField(field)).toBe(false);
|
1156
1156
|
});
|
1157
|
+
|
1158
|
+
describe('dynamic system fields', () => {
|
1159
|
+
it('should count Scenario & Budget Cycle as system field', () => {
|
1160
|
+
lodash.set(document, 'ReportHippo.user.features', ['multiple_dimension_tags', 'use_new_scenario_tag']);
|
1161
|
+
|
1162
|
+
const fieldWithScenario = { name: 'Scenario' };
|
1163
|
+
expect(highchartsRenderer.isSystemField(fieldWithScenario)).toBe(true);
|
1164
|
+
|
1165
|
+
const fieldWithBudgetCycle = { name: 'Budget Cycle' };
|
1166
|
+
expect(highchartsRenderer.isSystemField(fieldWithBudgetCycle)).toBe(true);
|
1167
|
+
});
|
1168
|
+
});
|
1157
1169
|
});
|
1158
1170
|
|
1159
1171
|
describe('function getFieldColorClass', () => {
|
@@ -1311,6 +1323,264 @@ describe('highcharts_renderer', () => {
|
|
1311
1323
|
});
|
1312
1324
|
});
|
1313
1325
|
|
1326
|
+
describe("function updateBackwardCompatibleWidgetOptions", () => {
|
1327
|
+
it("should delete chart 'hideLegends' option if exists and true", () => {
|
1328
|
+
const options = {
|
1329
|
+
chartOptions: {
|
1330
|
+
chart: {
|
1331
|
+
hideLegends: true
|
1332
|
+
}
|
1333
|
+
},
|
1334
|
+
comboOptions: {}
|
1335
|
+
};
|
1336
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1337
|
+
expect(options.chartOptions.legends_position.value).toBe('none');
|
1338
|
+
expect(options.chartOptions.chart.hideLegends).toBe(undefined);
|
1339
|
+
});
|
1340
|
+
|
1341
|
+
it("should move error_policy chart option to advanced chart option", () => {
|
1342
|
+
const error_policy = 'test_policy';
|
1343
|
+
const options = {
|
1344
|
+
chartOptions: {
|
1345
|
+
error_policy: {
|
1346
|
+
error_policy: error_policy
|
1347
|
+
}
|
1348
|
+
},
|
1349
|
+
comboOptions: {}
|
1350
|
+
};
|
1351
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1352
|
+
expect(options.chartOptions.advanced.from_latest).toBe('');
|
1353
|
+
expect(options.chartOptions.advanced.error_policy).toBe(error_policy);
|
1354
|
+
expect(options.chartOptions.error_policy).toBe(undefined);
|
1355
|
+
expect(options.chartOptions.from_version).toBe(undefined);
|
1356
|
+
});
|
1357
|
+
|
1358
|
+
it("should move from_version chart option to advanced chart option", () => {
|
1359
|
+
const from_version = 'from_version';
|
1360
|
+
const options = {
|
1361
|
+
chartOptions: {
|
1362
|
+
from_version: {
|
1363
|
+
value: from_version
|
1364
|
+
}
|
1365
|
+
},
|
1366
|
+
comboOptions: {}
|
1367
|
+
};
|
1368
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1369
|
+
expect(options.chartOptions.advanced.from_latest).toBe(from_version);
|
1370
|
+
expect(options.chartOptions.advanced.error_policy).toBe('None');
|
1371
|
+
expect(options.chartOptions.error_policy).toBe(undefined);
|
1372
|
+
expect(options.chartOptions.from_version).toBe(undefined);
|
1373
|
+
});
|
1374
|
+
|
1375
|
+
it("should remove chart label style option", () => {
|
1376
|
+
const options = {
|
1377
|
+
chartOptions: {
|
1378
|
+
label: {
|
1379
|
+
style: 'color: red;'
|
1380
|
+
}
|
1381
|
+
},
|
1382
|
+
comboOptions: {}
|
1383
|
+
};
|
1384
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1385
|
+
expect(options.chartOptions.label.style).toBe(undefined);
|
1386
|
+
});
|
1387
|
+
|
1388
|
+
it("should remove chart label_pie style option", () => {
|
1389
|
+
const options = {
|
1390
|
+
chartOptions: {
|
1391
|
+
label_pie: {
|
1392
|
+
style: 'color: red;'
|
1393
|
+
}
|
1394
|
+
},
|
1395
|
+
comboOptions: {}
|
1396
|
+
};
|
1397
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'line-chart')
|
1398
|
+
expect(options.chartOptions.label_pie.style).toBe(undefined);
|
1399
|
+
});
|
1400
|
+
|
1401
|
+
it("update pie-chart label options if only_value", () => {
|
1402
|
+
const options = {
|
1403
|
+
chartOptions: {
|
1404
|
+
label: {
|
1405
|
+
only_value: true
|
1406
|
+
}
|
1407
|
+
},
|
1408
|
+
comboOptions: {}
|
1409
|
+
};
|
1410
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
|
1411
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1412
|
+
show_percentage_in_labels: false,
|
1413
|
+
show_value_in_labels: true
|
1414
|
+
});
|
1415
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1416
|
+
});
|
1417
|
+
|
1418
|
+
it("update pie-chart label options if only_percentage", () => {
|
1419
|
+
const options = {
|
1420
|
+
chartOptions: {
|
1421
|
+
label: {
|
1422
|
+
only_percentage: true
|
1423
|
+
}
|
1424
|
+
},
|
1425
|
+
comboOptions: {}
|
1426
|
+
};
|
1427
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart')
|
1428
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1429
|
+
show_percentage_in_labels: true,
|
1430
|
+
show_value_in_labels: false
|
1431
|
+
});
|
1432
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1433
|
+
});
|
1434
|
+
|
1435
|
+
it("update pie-chart label options if show", () => {
|
1436
|
+
const options = {
|
1437
|
+
chartOptions: {
|
1438
|
+
label: {
|
1439
|
+
show: true
|
1440
|
+
}
|
1441
|
+
},
|
1442
|
+
comboOptions: {}
|
1443
|
+
};
|
1444
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, 'pie-chart');
|
1445
|
+
expect(options.chartOptions.label_pie).toEqual({
|
1446
|
+
show: true,
|
1447
|
+
show_percentage_in_labels: true,
|
1448
|
+
show_value_in_labels: true
|
1449
|
+
});
|
1450
|
+
expect(options.chartOptions.label).toBe(undefined);
|
1451
|
+
});
|
1452
|
+
|
1453
|
+
it("should do nothing if pie chart without 'only_percentage/only_value/show'", () => {
|
1454
|
+
const options1 = {
|
1455
|
+
chartOptions: { label: { } }, comboOptions: {}
|
1456
|
+
};
|
1457
|
+
const options2 = {
|
1458
|
+
chartOptions: { }, comboOptions: {}
|
1459
|
+
};
|
1460
|
+
|
1461
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options1, 'pie-chart');
|
1462
|
+
expect(options1).toEqual({
|
1463
|
+
chartOptions: { label_pie: {} }, comboOptions: {}
|
1464
|
+
});
|
1465
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options2, 'pie-chart');
|
1466
|
+
expect(options2).toEqual({
|
1467
|
+
chartOptions: { }, comboOptions: {}
|
1468
|
+
});
|
1469
|
+
});
|
1470
|
+
|
1471
|
+
it("should create comboOptions for different series types", () => {
|
1472
|
+
const options = {
|
1473
|
+
chartOptions: {
|
1474
|
+
delta_column: {
|
1475
|
+
field: 'series',
|
1476
|
+
name: 'TEST_test',
|
1477
|
+
same_yaxis: true,
|
1478
|
+
is_percentage: true,
|
1479
|
+
}
|
1480
|
+
}
|
1481
|
+
};
|
1482
|
+
|
1483
|
+
const seriesTypes = ['line', 'spline', 'area', 'areaspline', 'scatter', 'column', 'default'];
|
1484
|
+
const seriesTypesMap = ['line-chart', 'line-chart-smooth', 'area-chart', 'area-chart-smooth', 'scatter-chart', 'column-chart', 'scatter-chart'];
|
1485
|
+
|
1486
|
+
seriesTypes.forEach((type, index) => {
|
1487
|
+
const currentOptions = lodash.cloneDeep(options);
|
1488
|
+
currentOptions.chartOptions.delta_column.chart = type;
|
1489
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(currentOptions, null);
|
1490
|
+
expect(currentOptions.comboOptions).toEqual({
|
1491
|
+
secondaryAxisSettings: {
|
1492
|
+
name: 'TESTtest',
|
1493
|
+
max: null,
|
1494
|
+
min: null,
|
1495
|
+
is_percentage: true
|
1496
|
+
},
|
1497
|
+
seriesOptions: [{
|
1498
|
+
series: 'TEST_test',
|
1499
|
+
secondaryAxis: false,
|
1500
|
+
chartType: seriesTypesMap[index]
|
1501
|
+
}]
|
1502
|
+
});
|
1503
|
+
});
|
1504
|
+
});
|
1505
|
+
|
1506
|
+
it("should create comboOptions without series options if no delta_column field", () => {
|
1507
|
+
const options = {};
|
1508
|
+
highchartsRenderer.updateBackwardCompatibleWidgetOptions(options, null);
|
1509
|
+
expect(options).toEqual({
|
1510
|
+
comboOptions :{
|
1511
|
+
secondaryAxisSettings: {
|
1512
|
+
name: 'Secondary Axis',
|
1513
|
+
max: null,
|
1514
|
+
min: null,
|
1515
|
+
is_percentage: false,
|
1516
|
+
},
|
1517
|
+
seriesOptions: []
|
1518
|
+
}
|
1519
|
+
});
|
1520
|
+
});
|
1521
|
+
});
|
1522
|
+
|
1523
|
+
describe("function setMissingWidgetOptions", () => {
|
1524
|
+
it("should return do nothing if there are no chartOptions", () => {
|
1525
|
+
const options = { testProp: true };
|
1526
|
+
highchartsRenderer.setMissingWidgetOptions(options, null)
|
1527
|
+
expect(options).toEqual({ testProp: true });
|
1528
|
+
});
|
1529
|
+
|
1530
|
+
it("should merge current chart options with default", () => {
|
1531
|
+
spyOn(highchartsRenderer, 'getDefaultValueForChart').and.returnValue({
|
1532
|
+
array: [1, 3, 5],
|
1533
|
+
newProp: 'defaultNew',
|
1534
|
+
existingProp: 'defaultExist',
|
1535
|
+
obj: {
|
1536
|
+
newProp: 'defaultNew',
|
1537
|
+
existingProp: 'defaultExist',
|
1538
|
+
},
|
1539
|
+
newObj: {
|
1540
|
+
newProp: 'defaultNew',
|
1541
|
+
}
|
1542
|
+
});
|
1543
|
+
const options = {
|
1544
|
+
chartOptions: {
|
1545
|
+
array: [2, 5, 6],
|
1546
|
+
existingProp: 'exist',
|
1547
|
+
obj: {
|
1548
|
+
existingProp: 'exist',
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
};
|
1552
|
+
highchartsRenderer.setMissingWidgetOptions(options, 'line-chart')
|
1553
|
+
expect(options.chartOptions).toEqual({
|
1554
|
+
array: [2, 5, 6],
|
1555
|
+
existingProp: "exist",
|
1556
|
+
newObj: { newProp: "defaultNew" },
|
1557
|
+
newProp: "defaultNew",
|
1558
|
+
obj: {
|
1559
|
+
existingProp: "exist",
|
1560
|
+
newProp: "defaultNew"
|
1561
|
+
}
|
1562
|
+
});
|
1563
|
+
});
|
1564
|
+
});
|
1565
|
+
|
1566
|
+
describe('function getChartOptionsBySubType', () => {
|
1567
|
+
it('returns null for rich_text subtype', () => {
|
1568
|
+
const result = highchartsRenderer.getChartOptionsBySubType('rich_text');
|
1569
|
+
expect(result).toBe(highchartsRenderer.richTextSubType);
|
1570
|
+
});
|
1571
|
+
|
1572
|
+
it('returns chart options for existing subtype', () => {
|
1573
|
+
const result = highchartsRenderer.getChartOptionsBySubType('line-chart');
|
1574
|
+
expect(result.type).toEqual('line-chart');
|
1575
|
+
expect(result.suboptions.length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
|
1576
|
+
});
|
1577
|
+
|
1578
|
+
it('returns null for non-existing subtype', () => {
|
1579
|
+
const result = highchartsRenderer.getChartOptionsBySubType('nonExistingType');
|
1580
|
+
expect(result).toBe(null);
|
1581
|
+
});
|
1582
|
+
});
|
1583
|
+
|
1314
1584
|
describe('function aggregators', () => {
|
1315
1585
|
const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
|
1316
1586
|
|
@@ -2441,6 +2711,390 @@ describe('highcharts_renderer', () => {
|
|
2441
2711
|
});
|
2442
2712
|
});
|
2443
2713
|
|
2714
|
+
describe('function getDefaultValueForChart', () => {
|
2715
|
+
it('should return empty value for rich_text type', () => {
|
2716
|
+
expect(highchartsRenderer.getDefaultValueForChart('rich_text', {})).toEqual({});
|
2717
|
+
});
|
2718
|
+
|
2719
|
+
it('should return default value for line-chart type if existing options are empty', () => {
|
2720
|
+
const res = highchartsRenderer.getDefaultValueForChart('line-chart', {});
|
2721
|
+
expect(Object.keys(res).length).toEqual(highchartsRenderer.chartsData[0].subtypes[0].suboptions.length);
|
2722
|
+
});
|
2723
|
+
});
|
2724
|
+
|
2725
|
+
describe('function getCommonChartOptions', () => {
|
2726
|
+
const TOOLTIP_DEFAULT_OPTIONS = {
|
2727
|
+
borderColor: '#fff',
|
2728
|
+
shadow: {
|
2729
|
+
color: '#9199b4',
|
2730
|
+
width: 10,
|
2731
|
+
opacity: 0.05
|
2732
|
+
},
|
2733
|
+
style: {
|
2734
|
+
fontSize: '12',
|
2735
|
+
fontFamily: 'Poppins',
|
2736
|
+
color: '#545a6b',
|
2737
|
+
},
|
2738
|
+
enabled: true,
|
2739
|
+
};
|
2740
|
+
|
2741
|
+
it('should return empty object if additionalOptions is null or undefined', () => {
|
2742
|
+
expect(highchartsRenderer.getCommonChartOptions(null)).toEqual({});
|
2743
|
+
expect(highchartsRenderer.getCommonChartOptions(undefined)).toEqual({});
|
2744
|
+
});
|
2745
|
+
|
2746
|
+
it('should return empty tooltip if additionalOptions has no tooltips', () => {
|
2747
|
+
const additionalOptions = { };
|
2748
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual({});
|
2749
|
+
});
|
2750
|
+
|
2751
|
+
it('should return tooltip with default options if tooltips.show is not defined', () => {
|
2752
|
+
const additionalOptions = { tooltips: {} };
|
2753
|
+
const expected = { tooltip: TOOLTIP_DEFAULT_OPTIONS };
|
2754
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2755
|
+
});
|
2756
|
+
|
2757
|
+
it('should return tooltip with custom style options', () => {
|
2758
|
+
const additionalOptions = {
|
2759
|
+
tooltips: {
|
2760
|
+
show: true,
|
2761
|
+
font_size: 14,
|
2762
|
+
font_style: 'Arial',
|
2763
|
+
font_color: '#333',
|
2764
|
+
}
|
2765
|
+
};
|
2766
|
+
const expected = {
|
2767
|
+
tooltip: {
|
2768
|
+
borderColor: '#fff',
|
2769
|
+
shadow: {
|
2770
|
+
color: '#9199b4',
|
2771
|
+
width: 10,
|
2772
|
+
opacity: 0.05
|
2773
|
+
},
|
2774
|
+
style: {
|
2775
|
+
fontSize: 14,
|
2776
|
+
fontFamily: 'Arial',
|
2777
|
+
color: '#333',
|
2778
|
+
},
|
2779
|
+
enabled: true,
|
2780
|
+
}
|
2781
|
+
};
|
2782
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2783
|
+
});
|
2784
|
+
|
2785
|
+
it('should return tooltip with custom style options and show set to false', () => {
|
2786
|
+
const additionalOptions = {
|
2787
|
+
tooltips: {
|
2788
|
+
show: false,
|
2789
|
+
font_size: 14,
|
2790
|
+
font_style: 'Arial',
|
2791
|
+
font_color: '#333',
|
2792
|
+
}
|
2793
|
+
};
|
2794
|
+
const expected = {
|
2795
|
+
tooltip: {
|
2796
|
+
borderColor: '#fff',
|
2797
|
+
shadow: {
|
2798
|
+
color: '#9199b4',
|
2799
|
+
width: 10,
|
2800
|
+
opacity: 0.05
|
2801
|
+
},
|
2802
|
+
style: {
|
2803
|
+
fontSize: 14,
|
2804
|
+
fontFamily: 'Arial',
|
2805
|
+
color: '#333',
|
2806
|
+
},
|
2807
|
+
enabled: false,
|
2808
|
+
}
|
2809
|
+
};
|
2810
|
+
expect(highchartsRenderer.getCommonChartOptions(additionalOptions)).toEqual(expected);
|
2811
|
+
});
|
2812
|
+
});
|
2813
|
+
|
2814
|
+
describe('function getDataLabelsStyle', () => {
|
2815
|
+
it('returns default style if additionalOptions is empty', () => {
|
2816
|
+
const additionalOptions = {};
|
2817
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2818
|
+
const expected = defaultStyle;
|
2819
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2820
|
+
expect(actual).toEqual(expected);
|
2821
|
+
});
|
2822
|
+
|
2823
|
+
it('returns default style if additionalOptions does not contain a label option key', () => {
|
2824
|
+
const additionalOptions = { backgroundColor: '#fff' };
|
2825
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2826
|
+
const expected = defaultStyle;
|
2827
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2828
|
+
expect(actual).toEqual(expected);
|
2829
|
+
});
|
2830
|
+
|
2831
|
+
it('returns style merged with defaultStyle if both exist', () => {
|
2832
|
+
const additionalOptions = { label_1: { font_size: '16px' } };
|
2833
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2834
|
+
const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px' };
|
2835
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2836
|
+
expect(actual).toEqual(expected);
|
2837
|
+
});
|
2838
|
+
|
2839
|
+
it('returns style with font size and font family if they exist', () => {
|
2840
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2841
|
+
const defaultStyle = { color: '#333', fontWeight: 'bold' };
|
2842
|
+
const expected = { color: '#333', fontWeight: 'bold', fontSize: '16px', fontFamily: 'Helvetica' };
|
2843
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2844
|
+
expect(actual).toEqual(expected);
|
2845
|
+
});
|
2846
|
+
|
2847
|
+
it('returns style only with font size and font family if defaultStyle has wrong format', () => {
|
2848
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2849
|
+
const defaultStyle = "{ color: '#333', fontWeight: 'bold' }";
|
2850
|
+
const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
|
2851
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2852
|
+
expect(actual).toEqual(expected);
|
2853
|
+
});
|
2854
|
+
|
2855
|
+
it('returns style only with font size and font family if defaultStyle is null', () => {
|
2856
|
+
const additionalOptions = { label_1: { font_size: '16px', font_style: 'Helvetica' } };
|
2857
|
+
const defaultStyle = null;
|
2858
|
+
const expected = { fontSize: '16px', fontFamily: 'Helvetica' };
|
2859
|
+
const actual = highchartsRenderer.getDataLabelsStyle(additionalOptions, defaultStyle);
|
2860
|
+
expect(actual).toEqual(expected);
|
2861
|
+
});
|
2862
|
+
});
|
2863
|
+
|
2864
|
+
describe('function getDataLabelsOptions', () => {
|
2865
|
+
const defaultDataLabels = {
|
2866
|
+
color: "#151a41",
|
2867
|
+
enabled: true,
|
2868
|
+
style: {
|
2869
|
+
fontFamily: "Poppins",
|
2870
|
+
fontSize: "12px",
|
2871
|
+
fontWeight: "bold"
|
2872
|
+
}
|
2873
|
+
};
|
2874
|
+
|
2875
|
+
it('should return chartOptions with default data label options if additionalOptions is not defined', () => {
|
2876
|
+
const chartOptions = {
|
2877
|
+
dataLabels: {
|
2878
|
+
enabled: true,
|
2879
|
+
style: {
|
2880
|
+
fontSize: '12px',
|
2881
|
+
fontWeight: 'bold',
|
2882
|
+
},
|
2883
|
+
},
|
2884
|
+
};
|
2885
|
+
const result = highchartsRenderer.getDataLabelsOptions(undefined, chartOptions);
|
2886
|
+
expect(result).toEqual(chartOptions);
|
2887
|
+
expect(result.dataLabels).toEqual(defaultDataLabels);
|
2888
|
+
});
|
2889
|
+
|
2890
|
+
it('should return chartOptions with merged data label options if additionalOptions does not contain a label key', () => {
|
2891
|
+
const additionalOptions = {
|
2892
|
+
option1: 'value1',
|
2893
|
+
option2: 'value2',
|
2894
|
+
option3: 'value3',
|
2895
|
+
};
|
2896
|
+
const chartOptions = {
|
2897
|
+
dataLabels: {
|
2898
|
+
enabled: true,
|
2899
|
+
style: {
|
2900
|
+
fontSize: '13px',
|
2901
|
+
fontWeight: 'normal',
|
2902
|
+
},
|
2903
|
+
},
|
2904
|
+
};
|
2905
|
+
const expected = {
|
2906
|
+
dataLabels: {
|
2907
|
+
color: "#151a41",
|
2908
|
+
enabled: true,
|
2909
|
+
style: {
|
2910
|
+
fontFamily: "Poppins",
|
2911
|
+
fontSize: "13px",
|
2912
|
+
fontWeight: "normal"
|
2913
|
+
}
|
2914
|
+
}
|
2915
|
+
};
|
2916
|
+
const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
|
2917
|
+
expect(result).toEqual(expected);
|
2918
|
+
});
|
2919
|
+
|
2920
|
+
it('should return chartOptions with merged data label options if additionalOptions contains a label key', () => {
|
2921
|
+
const additionalOptions = {
|
2922
|
+
label_option: {
|
2923
|
+
font_color: 'red',
|
2924
|
+
},
|
2925
|
+
};
|
2926
|
+
const chartOptions = {
|
2927
|
+
dataLabels: {
|
2928
|
+
enabled: true,
|
2929
|
+
style: {
|
2930
|
+
fontSize: '15px',
|
2931
|
+
fontWeight: 'bold',
|
2932
|
+
},
|
2933
|
+
},
|
2934
|
+
};
|
2935
|
+
const expected = {
|
2936
|
+
dataLabels: {
|
2937
|
+
color: "red",
|
2938
|
+
enabled: true,
|
2939
|
+
style: {
|
2940
|
+
fontFamily: "Poppins",
|
2941
|
+
fontSize: "15px",
|
2942
|
+
fontWeight: "bold"
|
2943
|
+
}
|
2944
|
+
}
|
2945
|
+
};
|
2946
|
+
const result = highchartsRenderer.getDataLabelsOptions(additionalOptions, chartOptions);
|
2947
|
+
expect(result).toEqual(expected);
|
2948
|
+
});
|
2949
|
+
});
|
2950
|
+
|
2951
|
+
describe('function getLabelOptionKey', () => {
|
2952
|
+
it('should return null if additionalOptions is not defined', () => {
|
2953
|
+
const result = highchartsRenderer.getLabelOptionKey(undefined);
|
2954
|
+
expect(result).toBeNull();
|
2955
|
+
});
|
2956
|
+
|
2957
|
+
it('should return null if no label key is found in additionalOptions', () => {
|
2958
|
+
const additionalOptions = {
|
2959
|
+
option1: 'value1',
|
2960
|
+
option2: 'value2',
|
2961
|
+
option3: 'value3',
|
2962
|
+
};
|
2963
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2964
|
+
expect(result).toBeNull();
|
2965
|
+
});
|
2966
|
+
|
2967
|
+
it('should return the label key if found in additionalOptions', () => {
|
2968
|
+
const additionalOptions = {
|
2969
|
+
option1: 'value1',
|
2970
|
+
label_option: 'value2',
|
2971
|
+
option3: 'value3',
|
2972
|
+
};
|
2973
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2974
|
+
expect(result).toBe('label_option');
|
2975
|
+
});
|
2976
|
+
|
2977
|
+
it('should return the first label key if multiple label keys are found in additionalOptions', () => {
|
2978
|
+
const additionalOptions = {
|
2979
|
+
label_option1: 'value1',
|
2980
|
+
option1: 'value2',
|
2981
|
+
label_option2: 'value3',
|
2982
|
+
};
|
2983
|
+
const result = highchartsRenderer.getLabelOptionKey(additionalOptions);
|
2984
|
+
expect(result).toBe('label_option1');
|
2985
|
+
});
|
2986
|
+
});
|
2987
|
+
|
2988
|
+
describe('function getDefaultValueForSubOptions', () => {
|
2989
|
+
const suboptions = {
|
2990
|
+
option1: {
|
2991
|
+
category_type: 'type1',
|
2992
|
+
elements: [
|
2993
|
+
{
|
2994
|
+
value_name: 'value1',
|
2995
|
+
element_type: 'text',
|
2996
|
+
default_value: 'default1',
|
2997
|
+
},
|
2998
|
+
{
|
2999
|
+
value_name: 'value2',
|
3000
|
+
element_type: 'number',
|
3001
|
+
default_value: 42,
|
3002
|
+
},
|
3003
|
+
{
|
3004
|
+
value_name: 'value3',
|
3005
|
+
element_type: 'devider',
|
3006
|
+
},
|
3007
|
+
],
|
3008
|
+
},
|
3009
|
+
option2: {
|
3010
|
+
category_type: 'type2',
|
3011
|
+
elements: [
|
3012
|
+
{
|
3013
|
+
value_name: 'value1',
|
3014
|
+
element_type: 'text',
|
3015
|
+
default_value: 'default2',
|
3016
|
+
},
|
3017
|
+
{
|
3018
|
+
value_name: 'value2',
|
3019
|
+
element_type: 'number',
|
3020
|
+
default_value: 23,
|
3021
|
+
},
|
3022
|
+
{
|
3023
|
+
value_name: 'value3',
|
3024
|
+
element_type: 'devider',
|
3025
|
+
},
|
3026
|
+
],
|
3027
|
+
},
|
3028
|
+
option3: {
|
3029
|
+
category_type: 'type3',
|
3030
|
+
elements: [
|
3031
|
+
{
|
3032
|
+
value_name: 'value1',
|
3033
|
+
element_type: 'text',
|
3034
|
+
default_value: { val: 1 },
|
3035
|
+
}
|
3036
|
+
],
|
3037
|
+
},
|
3038
|
+
};
|
3039
|
+
let tempSubOptions = null;
|
3040
|
+
|
3041
|
+
beforeAll(() => {
|
3042
|
+
tempSubOptions = highchartsRenderer.suboptions;
|
3043
|
+
highchartsRenderer.suboptions = suboptions;
|
3044
|
+
});
|
3045
|
+
|
3046
|
+
afterAll(() => {
|
3047
|
+
highchartsRenderer.suboptions = tempSubOptions;
|
3048
|
+
});
|
3049
|
+
|
3050
|
+
it('should return an empty object if option type is not found', () => {
|
3051
|
+
const type = 'invalid_type';
|
3052
|
+
const existing_options = {};
|
3053
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3054
|
+
expect(result).toEqual({});
|
3055
|
+
});
|
3056
|
+
|
3057
|
+
it('should return default values for all elements in suboption', () => {
|
3058
|
+
const type = 'type1';
|
3059
|
+
const existing_options = {};
|
3060
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3061
|
+
expect(result).toEqual({
|
3062
|
+
value1: 'default1',
|
3063
|
+
value2: 42,
|
3064
|
+
});
|
3065
|
+
});
|
3066
|
+
|
3067
|
+
it('should use existing options if available', () => {
|
3068
|
+
const type = 'type1';
|
3069
|
+
const existing_options = {
|
3070
|
+
type1: {
|
3071
|
+
value1: 'existing1',
|
3072
|
+
value2: 99,
|
3073
|
+
},
|
3074
|
+
};
|
3075
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3076
|
+
expect(result).toEqual({
|
3077
|
+
value1: 'existing1',
|
3078
|
+
value2: 99,
|
3079
|
+
});
|
3080
|
+
});
|
3081
|
+
|
3082
|
+
it('should ignore elements with type "devider"', () => {
|
3083
|
+
const type = 'type1';
|
3084
|
+
const existing_options = {};
|
3085
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3086
|
+
expect(result).not.toHaveProperty('value3');
|
3087
|
+
});
|
3088
|
+
|
3089
|
+
it('should clone default value if it is an object', () => {
|
3090
|
+
const type = 'type3';
|
3091
|
+
const existing_options = {};
|
3092
|
+
const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
|
3093
|
+
expect(result.value1).toEqual(suboptions.option3.elements[0].default_value);
|
3094
|
+
expect(result.value1).not.toBe(suboptions.option3.elements[0].default_value);
|
3095
|
+
});
|
3096
|
+
});
|
3097
|
+
|
2444
3098
|
describe('function getChartAxisLabel', () => {
|
2445
3099
|
it('should return default value', () => {
|
2446
3100
|
expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
|