@datarailsshared/dr_renderer 1.2.379 → 1.2.382

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.379",
3
+ "version": "1.2.382",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -6017,16 +6017,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6017
6017
  ];
6018
6018
 
6019
6019
  highchartsRenderer.getDefaultValueForChart = function (type, existing_options) {
6020
- var chartOpt;
6021
- if (type == highchartsRenderer.richTextSubType.type) {
6022
- chartOpt = highchartsRenderer.richTextSubType;
6023
- } else {
6024
- chartOpt = highchartsRenderer.getChartOptionsBySubType(type);
6025
- }
6026
- var valToReturn = {};
6020
+ const chartOpt = type === highchartsRenderer.richTextSubType.type
6021
+ ? highchartsRenderer.richTextSubType
6022
+ : highchartsRenderer.getChartOptionsBySubType(type);
6023
+
6024
+ let valToReturn = {};
6027
6025
  if (chartOpt) {
6028
- lodash.forEach(chartOpt.suboptions, function (suboption) {
6029
- valToReturn[suboption.category_type] = highchartsRenderer.getDefaultValueForSubOptions(suboption.category_type, existing_options);
6026
+ lodash.forEach(chartOpt.suboptions, (suboption) => {
6027
+ valToReturn[suboption.category_type] = highchartsRenderer.getDefaultValueForSubOptions(suboption, existing_options);
6030
6028
  });
6031
6029
  }
6032
6030
 
@@ -6107,10 +6105,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6107
6105
  return key
6108
6106
  };
6109
6107
 
6110
- highchartsRenderer.getDefaultValueForSubOptions = function (type, existing_options) {
6111
- var valToReturn = {};
6112
- var option = highchartsRenderer.suboptions[type] || lodash.find(highchartsRenderer.suboptions, suboption => suboption.category_type === type);
6108
+ highchartsRenderer.getDefaultValueForSubOptions = function (option, existing_options) {
6109
+ const valToReturn = {};
6110
+
6113
6111
  if (option) {
6112
+ const type = option.category_type;
6114
6113
  lodash.forEach(option.elements, function (elem) {
6115
6114
  if (existing_options && lodash.has(existing_options, type + '.' + elem.value_name)) {
6116
6115
  valToReturn[elem.value_name] = lodash.get(existing_options, type + '.' + elem.value_name);
@@ -3436,17 +3436,19 @@ describe('highcharts_renderer', () => {
3436
3436
  highchartsRenderer.suboptions = tempSubOptions;
3437
3437
  });
3438
3438
 
3439
- it('should return an empty object if option type is not found', () => {
3440
- const type = 'invalid_type';
3439
+ it('should return an empty object if passed suboption is falsy', () => {
3441
3440
  const existing_options = {};
3442
- const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3443
- expect(result).toEqual({});
3441
+ const result1 = highchartsRenderer.getDefaultValueForSubOptions(null, existing_options);
3442
+ expect(result1).toEqual({});
3443
+
3444
+ const result2 = highchartsRenderer.getDefaultValueForSubOptions(undefined, existing_options);
3445
+ expect(result2).toEqual({});
3444
3446
  });
3445
3447
 
3446
3448
  it('should return default values for all elements in suboption', () => {
3447
- const type = 'type1';
3449
+ const suboption = suboptions.option1;
3448
3450
  const existing_options = {};
3449
- const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3451
+ const result = highchartsRenderer.getDefaultValueForSubOptions(suboption, existing_options);
3450
3452
  expect(result).toEqual({
3451
3453
  value1: 'default1',
3452
3454
  value2: 42,
@@ -3454,14 +3456,14 @@ describe('highcharts_renderer', () => {
3454
3456
  });
3455
3457
 
3456
3458
  it('should use existing options if available', () => {
3457
- const type = 'type1';
3459
+ const suboption = suboptions.option1;
3458
3460
  const existing_options = {
3459
3461
  type1: {
3460
3462
  value1: 'existing1',
3461
3463
  value2: 99,
3462
3464
  },
3463
3465
  };
3464
- const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3466
+ const result = highchartsRenderer.getDefaultValueForSubOptions(suboption, existing_options);
3465
3467
  expect(result).toEqual({
3466
3468
  value1: 'existing1',
3467
3469
  value2: 99,
@@ -3469,16 +3471,16 @@ describe('highcharts_renderer', () => {
3469
3471
  });
3470
3472
 
3471
3473
  it('should ignore elements with type "devider"', () => {
3472
- const type = 'type1';
3474
+ const suboption = suboptions.option1;
3473
3475
  const existing_options = {};
3474
- const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3476
+ const result = highchartsRenderer.getDefaultValueForSubOptions(suboption, existing_options);
3475
3477
  expect(result).not.toHaveProperty('value3');
3476
3478
  });
3477
3479
 
3478
3480
  it('should clone default value if it is an object', () => {
3479
- const type = 'type3';
3481
+ const suboption = suboptions.option3;
3480
3482
  const existing_options = {};
3481
- const result = highchartsRenderer.getDefaultValueForSubOptions(type, existing_options);
3483
+ const result = highchartsRenderer.getDefaultValueForSubOptions(suboption, existing_options);
3482
3484
  expect(result.value1).toEqual(suboptions.option3.elements[0].default_value);
3483
3485
  expect(result.value1).not.toBe(suboptions.option3.elements[0].default_value);
3484
3486
  });