@datarailsshared/dr_renderer 1.2.310-dragons → 1.2.312
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/highcharts_renderer.js +34 -23
- package/tests/highcharts_renderer.test.js +654 -0
package/package.json
CHANGED
@@ -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;
|
@@ -5019,7 +5016,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
5019
5016
|
};
|
5020
5017
|
|
5021
5018
|
highchartsRenderer.isSystemField = function (field) {
|
5022
|
-
|
5019
|
+
const features = lodash.get(document, 'ReportHippo.user.features', []);
|
5020
|
+
const dynamicSystemFields = [];
|
5021
|
+
|
5022
|
+
const areMultipleAndScenarioTags = lodash.includes(features, 'multiple_dimension_tags')
|
5023
|
+
&& lodash.includes(features, 'use_new_scenario_tag');
|
5024
|
+
|
5025
|
+
if (areMultipleAndScenarioTags) {
|
5026
|
+
dynamicSystemFields.push('Scenario', 'Budget Cycle');
|
5027
|
+
}
|
5028
|
+
|
5029
|
+
const regexDelimer = '|';
|
5030
|
+
const dynamicSystemFieldsRegex = dynamicSystemFields.length ? dynamicSystemFields.join(regexDelimer) + regexDelimer : '';
|
5031
|
+
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
5032
|
|
5024
5033
|
return (field.category && field.category.includes("")) || regex.test(field.name)
|
5025
5034
|
};
|
@@ -9095,17 +9104,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9095
9104
|
|
9096
9105
|
// if it is not total value - then add it as rowData data row and sum it up
|
9097
9106
|
// else - add total with calculated sum as new rowData data row (totals do not initially exist in BE response)
|
9098
|
-
if (value.trend !== 'total') {
|
9107
|
+
if (value && value.trend !== 'total') {
|
9099
9108
|
const rowIndex = lodash.findIndex(rowData, (responseRow) =>
|
9100
9109
|
lodash.every(categoryFields, (field, fieldKey) => responseRow[field.name] === value.key[fieldKey])
|
9101
9110
|
);
|
9102
|
-
|
9103
|
-
|
9104
|
-
|
9111
|
+
if (rowIndex >= 0) {
|
9112
|
+
modifiedRowData.push(rowData[rowIndex]);
|
9113
|
+
sum += rowData[rowIndex][valueField.name];
|
9114
|
+
rowData.splice(rowIndex, 1);
|
9115
|
+
}
|
9105
9116
|
} else {
|
9106
9117
|
const totalRow = {};
|
9107
9118
|
lodash.forEach(categoryFields, (field, fieldKey) => {
|
9108
|
-
totalRow[field.name] = value.key[fieldKey];
|
9119
|
+
totalRow[field.name] = value && value.key && value.key[fieldKey];
|
9109
9120
|
});
|
9110
9121
|
totalRow[valueField.name] = sum;
|
9111
9122
|
modifiedRowData.push(totalRow);
|
@@ -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)')
|