@datarailsshared/dr_renderer 1.2.317-rocket → 1.2.318-rocket
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 +165 -80
- package/src/pivottable.js +0 -1
- package/tests/highcharts_renderer.test.js +0 -642
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
|
}
|
@@ -1460,7 +1460,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1460
1460
|
totalSeries.color = colors[i];
|
1461
1461
|
}
|
1462
1462
|
|
1463
|
-
if (!lodash.isEmpty(pivotData.colTotals)) {
|
1464
1463
|
col_n_keys.forEach(columnKey => {
|
1465
1464
|
let key = columnKey;
|
1466
1465
|
let totalKey = columnKey;
|
@@ -1471,18 +1470,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1471
1470
|
const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
|
1472
1471
|
totalSeries.data.push({name: lodash.unescape(key), y: value});
|
1473
1472
|
});
|
1474
|
-
} else {
|
1475
|
-
lodash.forEach(row_n_keys, (rowKey, index) => {
|
1476
|
-
let key = rowKey;
|
1477
|
-
let totalKey = rowKey;
|
1478
|
-
if (lodash.isArray(rowKey)) {
|
1479
|
-
key = col_n_keys[index];
|
1480
|
-
totalKey = totalKey.join(highchartsRenderer.delimer);
|
1481
|
-
}
|
1482
|
-
const value = pivotData.rowTotals[totalKey] ? pivotData.rowTotals[totalKey].value() : 0;
|
1483
|
-
totalSeries.data.push({name: lodash.unescape(key), y: value});
|
1484
|
-
});
|
1485
|
-
}
|
1486
1473
|
|
1487
1474
|
chart_series.push(totalSeries);
|
1488
1475
|
}
|
@@ -4421,42 +4408,72 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4421
4408
|
return ret_str;
|
4422
4409
|
};
|
4423
4410
|
|
4424
|
-
highchartsRenderer.
|
4425
|
-
let
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
let valueForComparison;
|
4431
|
-
if (sortingOptions.sort_by === 'variance') {
|
4432
|
-
const varianceConfig = widget.options.chartOptions.delta_column;
|
4433
|
-
const data = pivotData.input;
|
4434
|
-
const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
|
4435
|
-
const varianceRowsForCurrentKey = lodash.filter(data, row =>
|
4436
|
-
row[varianceField.name] === varianceConfig.name
|
4437
|
-
&& lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
|
4438
|
-
);
|
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;
|
4439
4417
|
|
4440
|
-
valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
|
4441
|
-
} else {
|
4442
|
-
let getAggregatorParams = [firstArray, secondArray];
|
4443
4418
|
|
4444
|
-
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4448
|
-
|
4419
|
+
if (!colAttrs || colAttrs.length == 0) {
|
4420
|
+
return null;
|
4421
|
+
}
|
4422
|
+
|
4423
|
+
let values_names_arr = [];
|
4424
|
+
let keysArray = sortingOptions.field ? rowKeys : colKeys;
|
4449
4425
|
|
4450
|
-
|
4451
|
-
|
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);
|
4430
|
+
|
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);
|
4452
4435
|
}
|
4436
|
+
values_names_arr.push({name: val[0], value: value_subtotal});
|
4453
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
|
+
};
|
4451
|
+
|
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);
|
4454
4470
|
|
4455
|
-
if (
|
4456
|
-
|
4457
|
-
|
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);
|
4458
4475
|
}
|
4459
|
-
values_names_arr.push({name:
|
4476
|
+
values_names_arr.push({name: val[0], value: value_subtotal});
|
4460
4477
|
}
|
4461
4478
|
});
|
4462
4479
|
|
@@ -4468,33 +4485,36 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4468
4485
|
values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
|
4469
4486
|
|
4470
4487
|
// map only names
|
4471
|
-
|
4488
|
+
let attr_sorted_values = lodash.map(values_names_arr, 'name');
|
4489
|
+
return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
|
4472
4490
|
};
|
4473
4491
|
|
4474
|
-
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
|
+
|
4475
4501
|
let old_sorters_function = opts.sorters;
|
4476
4502
|
if (!old_sorters_function) {
|
4477
4503
|
old_sorters_function = function () {
|
4478
4504
|
};
|
4479
4505
|
}
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
sortingOptions.sorting,
|
4489
|
-
pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
|
4490
|
-
pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
|
4491
|
-
fieldIndex,
|
4492
|
-
widget
|
4493
|
-
);
|
4494
|
-
return $.pivotUtilities.sortAs(orderedNamesList);
|
4495
|
-
} else {
|
4496
|
-
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
|
+
}
|
4497
4514
|
}
|
4515
|
+
return new_sorters_function;
|
4516
|
+
} else {
|
4517
|
+
return old_sorters_function;
|
4498
4518
|
}
|
4499
4519
|
};
|
4500
4520
|
|
@@ -4698,7 +4718,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4698
4718
|
result = null;
|
4699
4719
|
try {
|
4700
4720
|
pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
|
4701
|
-
pivotData.sortByValueAttrs = [];
|
4702
4721
|
try {
|
4703
4722
|
if (options && options.onlyOptions) {
|
4704
4723
|
if (!opts.rendererOptions) {
|
@@ -4706,15 +4725,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4706
4725
|
}
|
4707
4726
|
opts.rendererOptions.onlyOptions = true;
|
4708
4727
|
}
|
4709
|
-
|
4710
|
-
|
4711
|
-
|
4712
|
-
sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
|
4713
|
-
);
|
4714
|
-
|
4715
|
-
if (sortByValueSettings.length) {
|
4716
|
-
pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
|
4717
|
-
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);
|
4718
4731
|
opts.sorters = new_sorting_function;
|
4719
4732
|
optsFiltered.sorters = new_sorting_function;
|
4720
4733
|
pivotData.sorters = new_sorting_function;
|
@@ -7071,6 +7084,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7071
7084
|
value_name: 'is_percentage',
|
7072
7085
|
default_value: false,
|
7073
7086
|
hidden: true,
|
7087
|
+
}, {
|
7088
|
+
element_type: 'checkbox',
|
7089
|
+
element_label: 'Sort by variance',
|
7090
|
+
value_name: 'sort_by_variance',
|
7091
|
+
default_value: false,
|
7092
|
+
hidden: true
|
7093
|
+
}, {
|
7094
|
+
element_type: 'checkbox',
|
7095
|
+
element_label: 'Sort by absolute variance',
|
7096
|
+
value_name: 'sort_by_absolute_variance',
|
7097
|
+
default_value: false,
|
7098
|
+
hidden: true
|
7074
7099
|
}]
|
7075
7100
|
},
|
7076
7101
|
'delta_column_for_drill_down': {
|
@@ -7137,6 +7162,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7137
7162
|
value_name: 'is_percentage',
|
7138
7163
|
default_value: false,
|
7139
7164
|
hidden: true,
|
7165
|
+
}, {
|
7166
|
+
element_type: 'checkbox',
|
7167
|
+
element_label: 'Sort by variance',
|
7168
|
+
value_name: 'sort_by_variance',
|
7169
|
+
default_value: false,
|
7170
|
+
hidden: true
|
7171
|
+
}, {
|
7172
|
+
element_type: 'checkbox',
|
7173
|
+
element_label: 'Sort by absolute variance',
|
7174
|
+
value_name: 'sort_by_absolute_variance',
|
7175
|
+
default_value: false,
|
7176
|
+
hidden: true
|
7140
7177
|
}, {
|
7141
7178
|
element_type: 'checkbox',
|
7142
7179
|
element_label: 'Filter zero values',
|
@@ -8653,9 +8690,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8653
8690
|
const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
|
8654
8691
|
if (isCustomSorting) {
|
8655
8692
|
lodash.forEach(datesFields, function (field) {
|
8656
|
-
const fieldToSort = lodash.find(
|
8657
|
-
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8658
|
-
);
|
8693
|
+
const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
|
8659
8694
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8660
8695
|
});
|
8661
8696
|
}
|
@@ -8737,9 +8772,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8737
8772
|
});
|
8738
8773
|
} else if (isCustomSorting) {
|
8739
8774
|
lodash.forEach(rowsAndCols, function (field) {
|
8740
|
-
const fieldToSort = lodash.find(
|
8741
|
-
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8742
|
-
);
|
8775
|
+
const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
|
8743
8776
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8744
8777
|
});
|
8745
8778
|
}
|
@@ -8774,9 +8807,61 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8774
8807
|
}
|
8775
8808
|
|
8776
8809
|
/****** END *******/
|
8777
|
-
|
8778
|
-
|
8779
|
-
|
8810
|
+
|
8811
|
+
if (lodash.has(widget, "options.chartOptions.delta_column") &&
|
8812
|
+
widget.options.chartOptions.delta_column.field != '' &&
|
8813
|
+
(widget.options.chartOptions.delta_column.sort_by_variance ||
|
8814
|
+
widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
|
8815
|
+
widget.rows.length > 0 &&
|
8816
|
+
widget.cols.length > 0 &&
|
8817
|
+
widget.vals.length
|
8818
|
+
) {
|
8819
|
+
let variance_config = widget.options.chartOptions.delta_column;
|
8820
|
+
let val_field = widget.vals[0];
|
8821
|
+
let field_for_sorting = null;
|
8822
|
+
let field_with_variant = null;
|
8823
|
+
if (variance_config.field == "series") {
|
8824
|
+
field_for_sorting = widget.cols[0];
|
8825
|
+
field_with_variant = widget.rows[0];
|
8826
|
+
} else if (variance_config.field == "category") {
|
8827
|
+
field_for_sorting = widget.rows[0];
|
8828
|
+
field_with_variant = widget.cols[0];
|
8829
|
+
}
|
8830
|
+
|
8831
|
+
let data_sorted = lodash.filter(data, function (data_row) {
|
8832
|
+
return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
|
8833
|
+
});
|
8834
|
+
|
8835
|
+
const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
|
8836
|
+
|
8837
|
+
if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
|
8838
|
+
data_sorted = lodash.sortBy(data_sorted, function (o) {
|
8839
|
+
if (sorting_variance === 'desc') {
|
8840
|
+
return Math.abs(o[val_field.name]) * -1;
|
8841
|
+
}
|
8842
|
+
|
8843
|
+
return Math.abs(o[val_field.name]) * 1;
|
8844
|
+
});
|
8845
|
+
} else {
|
8846
|
+
data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
|
8847
|
+
}
|
8848
|
+
|
8849
|
+
let values_for_sort = lodash.map(data_sorted, function (data_row) {
|
8850
|
+
return data_row[field_for_sorting.name];
|
8851
|
+
});
|
8852
|
+
|
8853
|
+
values_for_sort = lodash.uniq(values_for_sort);
|
8854
|
+
|
8855
|
+
if (values_for_sort.length > 0) {
|
8856
|
+
let field = lodash.find(datesFields, {name: field_for_sorting.name});
|
8857
|
+
if (field) {
|
8858
|
+
field.values = values_for_sort;
|
8859
|
+
field.sorting = null;
|
8860
|
+
} else {
|
8861
|
+
datesFields.push({name: field_for_sorting.name, values: values_for_sort});
|
8862
|
+
}
|
8863
|
+
}
|
8864
|
+
} else if (widget.options && widget.options.sortingValues) {
|
8780
8865
|
var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
|
8781
8866
|
if (field) {
|
8782
8867
|
field.values = widget.options.sortingValues.values;
|
package/src/pivottable.js
CHANGED
@@ -1323,264 +1323,6 @@ describe('highcharts_renderer', () => {
|
|
1323
1323
|
});
|
1324
1324
|
});
|
1325
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
|
-
|
1584
1326
|
describe('function aggregators', () => {
|
1585
1327
|
const aggregatorsIds = ['SUM', 'COUNT', 'COUNT_UNIQUE', 'UNIQUE_VALUES', 'AVG', 'MIN', 'MAX'];
|
1586
1328
|
|
@@ -2711,390 +2453,6 @@ describe('highcharts_renderer', () => {
|
|
2711
2453
|
});
|
2712
2454
|
});
|
2713
2455
|
|
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
|
-
|
3098
2456
|
describe('function getChartAxisLabel', () => {
|
3099
2457
|
it('should return default value', () => {
|
3100
2458
|
expect(highchartsRenderer.getChartAxisLabel('invalidType')).toBe('Axis (Category)')
|