@datarailsshared/dr_renderer 1.2.430 → 1.2.432

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.430",
3
+ "version": "1.2.432",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1026,9 +1026,49 @@ var DataFormatterImpl = function () {
1026
1026
 
1027
1027
  return result;
1028
1028
  }
1029
+ }, {
1030
+ key: 'formatValue',
1031
+ value: function formatValue(data_type, number_format, value, override_values_format) {
1032
+ if (!number_format) {
1033
+ number_format = 'General';
1034
+ }
1035
+
1036
+ if (Number.isNaN(value)) {
1037
+ return { value: "#Error" };
1038
+ }
1039
+
1040
+ if (data_type === 'n' && value != null) {
1041
+ if (override_values_format) {
1042
+ number_format = override_values_format;
1043
+ }
1044
+
1045
+ if (number_format.indexOf('[kilo]') >= 0) {
1046
+ value = value / 1000;
1047
+ number_format = number_format.replace('[kilo]', '');
1048
+ } else if (number_format.indexOf('[mega]') >= 0) {
1049
+ value = value / 1000000;
1050
+ number_format = number_format.replace('[mega]', '');
1051
+ } else if (number_format.indexOf('[kilomega]') >= 0) {
1052
+ number_format = number_format.replace('[kilomega]', '');
1053
+ }
1054
+
1055
+ return this.format(value, 'Number', number_format);
1056
+ } else if (data_type === 'd') {
1057
+ number_format = number_format.split(';')[0];
1058
+ let d;
1059
+ if (value instanceof Date || typeof value === 'string') {
1060
+ d = new Date(value);
1061
+ } else {
1062
+ d = new Date(value * 1000);
1063
+ }
1064
+ return this.format(d.toString(), 'DateTime', number_format);
1065
+ } else {
1066
+ return value;
1067
+ }
1068
+ }
1029
1069
  }]);
1030
1070
 
1031
1071
  return DataFormatterImpl;
1032
1072
  }();
1033
1073
 
1034
- module.exports = new DataFormatterImpl();
1074
+ module.exports = new DataFormatterImpl();
@@ -153,6 +153,7 @@ const FEATURES = {
153
153
  MULTIPLE_DIMENSION_TAGS: 'multiple_dimension_tags',
154
154
  USE_NEW_SCENARIO_TAG: 'use_new_scenario_tag',
155
155
  ENABLE_SERVER_WIDGET_DATA_SORTING: 'enable_server_widget_data_sorting',
156
+ CLIENT_WIDGET_SORTING_KEYS_MERGE: 'client_widget_sorting_keys_merge',
156
157
  }
157
158
 
158
159
  const TICKS_COUNT = 5;
@@ -207,6 +208,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
207
208
  disableAnimation = document.ReportHippo.user.organization && document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.disable_animation
208
209
  highchartsRenderer.enabledNewWidgetValueFormatting = highchartsRenderer.hasFeature(FEATURES.ENABLE_NEW_WIDGET_VALUE_FORMATTING);
209
210
  highchartsRenderer.isSortingOnBackendEnabled = highchartsRenderer.hasFeature(FEATURES.ENABLE_SERVER_WIDGET_DATA_SORTING);
211
+ highchartsRenderer.CLIENT_WIDGET_SORTING_KEYS_MERGE = highchartsRenderer.hasFeature(FEATURES.CLIENT_WIDGET_SORTING_KEYS_MERGE);
210
212
  }
211
213
 
212
214
  // fix issue of use tootip.stickOnContact with tooltip.outside , source: https://github.com/highcharts/highcharts/pull/15960
@@ -3742,52 +3744,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3742
3744
  }
3743
3745
 
3744
3746
  highchartsRenderer.formatValue = function (data_type, number_format, value, widget_values_format) {
3745
- if (!number_format)
3746
- number_format = 'General';
3747
- if (Number.isNaN(value)) {
3748
- return {value: "#Error"};
3749
- }
3750
- if (data_type == 'n' && value != null) {
3751
-
3752
- if (widget_values_format)
3753
- number_format = widget_values_format;
3754
- var sumbol = '';
3755
-
3756
- if (number_format.indexOf('[kilo]') >= 0) {
3757
- sumbol = 'k';
3758
- value = value / 1000;
3759
- number_format = number_format.replace('[kilo]', '');
3760
- } else if (number_format.indexOf('[mega]') >= 0) {
3761
- sumbol = 'M';
3762
- value = value / 1000000;
3763
- number_format = number_format.replace('[mega]', '');
3764
- } else if (number_format.indexOf('[kilomega]') >= 0) {
3765
- var sumbol = '';
3766
- /*if(Math.abs(value) > 999){
3767
- sumbol = 'k';
3768
- value = value / 1000;
3769
- }
3770
- if(Math.abs(value) > 999){
3771
- sumbol = 'M';
3772
- value = value / 1000;
3773
- }*/
3774
-
3775
- number_format = number_format.replace('[kilomega]', '');
3776
- }
3777
-
3778
- return DataFormatter.format(value, "Number", number_format);
3779
- } else if (data_type == 'd') {
3780
- number_format = number_format.split(';')[0];
3781
- var d;
3782
- if (value instanceof Date || typeof value === 'string') {
3783
- d = new Date(value);
3784
- } else {
3785
- d = new Date(value * 1000);
3786
- }
3787
- return DataFormatter.format(d.toString(), "DateTime", number_format);
3788
- } else {
3789
- return value;
3790
- }
3747
+ return DataFormatter.formatValue(data_type, number_format, value, widget_values_format);
3791
3748
  };
3792
3749
 
3793
3750
  highchartsRenderer.getCalculatedValueFormat = function(calculatedFormats, rowKey, colKey) {
@@ -9723,7 +9680,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9723
9680
  return res;
9724
9681
  }
9725
9682
 
9726
- // TODO: move this logic to BE (the problem it is solving that BE returns several sorting objects for more than 1 field in Values)
9727
9683
  highchartsRenderer.getAggregatedSortingObjects = function(res) {
9728
9684
  let sortingObjectToReturn = null;
9729
9685
 
@@ -9732,7 +9688,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9732
9688
  if (!sortingObjectToReturn) {
9733
9689
  sortingObjectToReturn = lodash.clone(dataRow);
9734
9690
  } else {
9735
- sortingObjectToReturn.row_keys = lodash.concat(sortingObjectToReturn.row_keys, dataRow.row_keys || []);
9691
+ if (highchartsRenderer.CLIENT_WIDGET_SORTING_KEYS_MERGE) {
9692
+ const concatUniqueKeys = (keysA, keysB) => {
9693
+ if (!Array.isArray(keysB) || !keysB.length) return keysA;
9694
+ return lodash.chain(keysA).concat(keysB).uniqWith(lodash.isEqual).value();
9695
+ }
9696
+ sortingObjectToReturn.row_keys = concatUniqueKeys(sortingObjectToReturn.row_keys, dataRow.row_keys);
9697
+ sortingObjectToReturn.col_keys = concatUniqueKeys(sortingObjectToReturn.col_keys, dataRow.col_keys);
9698
+ } else {
9699
+ sortingObjectToReturn.row_keys = lodash.concat(sortingObjectToReturn.row_keys, dataRow.row_keys || []);
9700
+ }
9701
+
9736
9702
  }
9737
9703
  dataRow.isSortingObject = true;
9738
9704
  }
@@ -5257,8 +5257,41 @@ describe('highcharts_renderer', () => {
5257
5257
  });
5258
5258
  });
5259
5259
 
5260
- it('should get sort object and remove from data rows (several object encounters - for more than one Values field)', () => {
5260
+ it('should get sort object and remove from data rows (several object encounters - for more than one Values field) with merge cols and rows under FF', () => {
5261
+ highchartsRenderer.CLIENT_WIDGET_SORTING_KEYS_MERGE = true;
5262
+ const expectedObj = {
5263
+ col_keys: [['colKey1'], ['colKey2'], ['colKey3'], ['colKey4'], ['colKey5']],
5264
+ row_keys: [['rowKey1'], ['rowKey2'], ['rowKey1', 'rowKey2'], ['rowKey3']],
5265
+ };
5266
+ const rowData = [
5267
+ { someField1: 'someValue1' },
5268
+ { col_keys: [['colKey1'], ['colKey2']], row_keys: [['rowKey1']] },
5269
+ { someField2: 'someValue2' },
5270
+ { col_keys: [['colKey1'], ['colKey3'], ['colKey4'], ['colKey5']], row_keys: [['rowKey2']] },
5271
+ { someField3: 'someValue3' },
5272
+ { col_keys: [], row_keys: [['rowKey1', 'rowKey2']] },
5273
+ { someField4: 'someValue4' },
5274
+ { col_keys: [], row_keys: [['rowKey1', 'rowKey2']] },
5275
+ { someField4: 'someValue5' },
5276
+ { col_keys: [], row_keys: [] },
5277
+ { someField4: 'someValue6' },
5278
+ { col_keys: [['colKey5']], row_keys: [['rowKey3']] },
5279
+ ];
5280
+
5281
+ const sortObj = highchartsRenderer.getAggregatedSortingObjects(rowData);
5261
5282
 
5283
+ expect(rowData).toEqual([
5284
+ { someField1: 'someValue1' },
5285
+ { someField2: 'someValue2' },
5286
+ { someField3: 'someValue3' },
5287
+ { someField4: 'someValue4' },
5288
+ { someField4: 'someValue5' },
5289
+ { someField4: 'someValue6' },
5290
+ ]);
5291
+ expect(sortObj).toEqual(expectedObj);
5292
+ });
5293
+
5294
+ it('should get sort object and remove from data rows (several object encounters - for more than one Values field)', () => {
5262
5295
  const expectedObj = { col_keys: ['colKey1', 'colKey2'], row_keys: ['rowKey1', 'rowKey2'] };
5263
5296
  const rowData = [
5264
5297
  { someField1: 'someValue1' },