@datarailsshared/dr_renderer 1.2.403 → 1.2.406

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.403",
3
+ "version": "1.2.406",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -174,108 +174,56 @@ let initDRPivotTable = function($, window, document) {
174
174
  return keys.join(delim);
175
175
  }
176
176
 
177
- DRPivotData.prototype.processRecord = function(record, useTotalsCalculation) {
178
- if (useTotalsCalculation) {
179
- if (!this.notFirst) {
180
- this.keysLength = _.filter(_.keys(record), key => !_.includes(['data_types', 'formats', 'values_formats'], key)).length - 1;
181
- this.notFirst = true;
182
- }
183
- let getRowAggregator = (function(_this) {
184
- return function(key) {
185
- return _this.aggregator(_this, key, []);
186
- };
187
- })(this);
188
- let getColAggregator = (function(_this) {
189
- return function(key) {
190
- return _this.aggregator(_this, [], key);
191
- };
192
- })(this);
193
-
194
- const rowKey = this.getAttrsKeys(record, this.rowAttrs);
195
- const colKey = this.getAttrsKeys(record, this.colAttrs);
196
-
197
- let flatRowKey = rowKey.join(delim);
198
- let flatColKey = colKey.join(delim);
199
-
200
- if (this.keysLength === rowKey.length + colKey.length) {
201
- if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.rowKeys, flatRowKey)) {
202
- this.rowKeys.push(rowKey);
203
- }
204
- if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.colKeys, flatColKey)) {
205
- this.colKeys.push(colKey);
206
- }
207
- }
208
-
209
- if (!colKey.length && !rowKey.length) {
210
- this.allTotal.push(record);
211
- } else if (!colKey.length && rowKey.length) {
212
- if (!this.rowTotals[flatRowKey]) {
213
- this.rowTotals[flatRowKey] = getRowAggregator(rowKey.slice());
214
- this.rowTotals[flatRowKey].push(record);
215
- }
216
- } else if (!rowKey.length && colKey.length) {
217
- if (!this.colTotals[flatColKey]) {
218
- this.colTotals[flatColKey] = getColAggregator(colKey.slice());
219
- this.colTotals[flatColKey].push(record);
220
- }
221
- } else {
222
- if (!this.tree[flatRowKey]) {
223
- this.tree[flatRowKey] = {};
224
- }
225
- this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
226
- this.tree[flatRowKey][flatColKey].push(record);
227
- }
228
-
229
- return;
230
- }
231
-
232
- var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
233
- rowKey = [];
234
- colKey = [];
235
- const recordValues = _.values(record);
236
- const containsAverage = _.includes(recordValues, 'DR_Average');
237
- const containsOthers = _.includes(recordValues, 'DR_Others');
238
- if (!containsAverage && !containsOthers) {
239
- this.allTotal.push(record);
177
+ DRPivotData.prototype.processRecord = function(record) {
178
+ if (!this.notFirst) {
179
+ this.keysLength = _.filter(_.keys(record), key => !_.includes(['data_types', 'formats', 'values_formats'], key)).length - 1;
180
+ this.notFirst = true;
240
181
  }
241
- rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, containsAverage, containsOthers, (function(_this) {
182
+ let getRowAggregator = (function(_this) {
242
183
  return function(key) {
243
184
  return _this.aggregator(_this, key, []);
244
185
  };
245
- })(this));
246
- colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, containsAverage, containsOthers, (function(_this) {
186
+ })(this);
187
+ let getColAggregator = (function(_this) {
247
188
  return function(key) {
248
189
  return _this.aggregator(_this, [], key);
249
190
  };
250
- })(this));
191
+ })(this);
251
192
 
252
- m = rowKey.length - 1;
253
- n = colKey.length - 1;
254
- if (m < 0 || n < 0) {
255
- return;
193
+ const rowKey = this.getAttrsKeys(record, this.rowAttrs);
194
+ const colKey = this.getAttrsKeys(record, this.colAttrs);
195
+
196
+ let flatRowKey = rowKey.join(delim);
197
+ let flatColKey = colKey.join(delim);
198
+
199
+ if (this.keysLength === rowKey.length + colKey.length) {
200
+ if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.rowKeys, flatRowKey)) {
201
+ this.rowKeys.push(rowKey);
202
+ }
203
+ if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.colKeys, flatColKey)) {
204
+ this.colKeys.push(colKey);
205
+ }
256
206
  }
257
- results = [];
258
- for (i = k = 0, ref = m; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
259
- fRowKey = rowKey.slice(0, i + 1);
260
- flatRowKey = fRowKey.join(delim);
207
+
208
+ if (!colKey.length && !rowKey.length) {
209
+ this.allTotal.push(record);
210
+ } else if (!colKey.length && rowKey.length) {
211
+ if (!this.rowTotals[flatRowKey]) {
212
+ this.rowTotals[flatRowKey] = getRowAggregator(rowKey.slice());
213
+ this.rowTotals[flatRowKey].push(record);
214
+ }
215
+ } else if (!rowKey.length && colKey.length) {
216
+ if (!this.colTotals[flatColKey]) {
217
+ this.colTotals[flatColKey] = getColAggregator(colKey.slice());
218
+ this.colTotals[flatColKey].push(record);
219
+ }
220
+ } else {
261
221
  if (!this.tree[flatRowKey]) {
262
222
  this.tree[flatRowKey] = {};
263
223
  }
264
- results.push((function() {
265
- var l, ref1, results1;
266
- results1 = [];
267
- for (j = l = 0, ref1 = n; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
268
- fColKey = colKey.slice(0, j + 1);
269
- flatColKey = fColKey.join(delim);
270
- if (!this.tree[flatRowKey][flatColKey]) {
271
- this.tree[flatRowKey][flatColKey] = this.aggregator(this, fRowKey, fColKey);
272
- }
273
- results1.push(this.tree[flatRowKey][flatColKey].push(record));
274
- }
275
- return results1;
276
- }).call(this));
224
+ this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
225
+ this.tree[flatRowKey][flatColKey].push(record);
277
226
  }
278
- return results;
279
227
  };
280
228
 
281
229
  DRPivotData.prototype.getAggregator = function(rowKey, colKey) {
@@ -149,7 +149,6 @@ const CHART_LEGEND_DEFAULT_LABEL = 'Legend (Series)';
149
149
 
150
150
  const FEATURES = {
151
151
  ENABLE_NEW_WIDGET_VALUE_FORMATTING: 'enable_new_widget_value_formatting',
152
- ENABLE_SERVER_TOTALS_CALCULATION: 'enable_server_totals_calculation',
153
152
  FORMAT_AXIS: 'use_default_table_format_for_axis',
154
153
  FORMAT_DATES_AS_OTHER_AXIS_TYPES: 'format_dates_as_other_axis_types',
155
154
  MULTIPLE_DIMENSION_TAGS: 'multiple_dimension_tags',
@@ -198,7 +197,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
198
197
  }
199
198
  lodash.assign(highchartsRenderer, HIGHCHARTS_CONSTANTS);
200
199
 
201
- highchartsRenderer.useTotalsCalculation = false;
202
200
  highchartsRenderer.enabledNewWidgetValueFormatting = false;
203
201
  let disableAnimation = false;
204
202
 
@@ -207,7 +205,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
207
205
  }
208
206
 
209
207
  if (!!lodash.get(document, 'ReportHippo.user')) {
210
- highchartsRenderer.useTotalsCalculation = highchartsRenderer.hasFeature(FEATURES.ENABLE_SERVER_TOTALS_CALCULATION);
211
208
  disableAnimation = document.ReportHippo.user.organization && document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.disable_animation
212
209
  highchartsRenderer.enabledNewWidgetValueFormatting = highchartsRenderer.hasFeature(FEATURES.ENABLE_NEW_WIDGET_VALUE_FORMATTING);
213
210
  highchartsRenderer.isSortingOnBackendEnabled = highchartsRenderer.hasFeature(FEATURES.ENABLE_SERVER_WIDGET_DATA_SORTING);
@@ -863,19 +860,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
863
860
 
864
861
  /* model renderers */
865
862
 
866
- highchartsRenderer.tableCSVExportRenderer = function (pivotData, opts) {
867
- var aggregator, colAttrs, colKey, colKeys, defaults, i, j, rowAttrs, rowKey, rowKeys, tempAr,
863
+ highchartsRenderer.tableCSVExportRenderer = function (pivotData) {
864
+ var aggregator, colAttrs, colKey, colKeys, i, j, rowAttrs, rowKey, rowKeys, tempAr,
868
865
  totalAggregator, val;
869
866
 
870
867
  var hasProp = {}.hasOwnProperty;
871
868
  var forExport = [];
872
869
 
873
- defaults = {
874
- localeStrings: {
875
- totals: "Totals"
876
- }
877
- };
878
- opts = $.extend(defaults, opts);
870
+ const TOTAL_CELL = 'Totals';
879
871
  colAttrs = pivotData.colAttrs;
880
872
  rowAttrs = pivotData.rowAttrs;
881
873
  rowKeys = pivotData.getRowKeys();
@@ -897,7 +889,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
897
889
  tempAr = tempAr.concat(lodash.map(colKeys, function (row) {
898
890
  return row[j];
899
891
  }));
900
- tempAr.push(opts.localeStrings.totals);
892
+ tempAr.push(TOTAL_CELL);
901
893
  forExport.push(tempAr);
902
894
  }
903
895
 
@@ -930,7 +922,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
930
922
 
931
923
  for (j in rowAttrs) {
932
924
  if (!hasProp.call(rowAttrs, j)) continue;
933
- tempAr.push(opts.localeStrings.totals)
925
+ tempAr.push(TOTAL_CELL)
934
926
  }
935
927
 
936
928
  for (j in colKeys) {
@@ -949,10 +941,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
949
941
  return forExport;
950
942
  };
951
943
 
952
- highchartsRenderer.getNoDataResult = function (rendererOptions, to_match) {
944
+ highchartsRenderer.getNoDataResult = function (to_match) {
953
945
  var temp_result = $('<div class="noData-box"></div>');
954
946
  var resultsArr = [];
955
- var subTitle;
956
947
 
957
948
  if (to_match) {
958
949
  resultsArr.push(highchartsRenderer.getWidgetPlaceholder(highchartsRenderer.widgetPlaceholders.tooMuchData));
@@ -1070,11 +1061,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1070
1061
  }
1071
1062
 
1072
1063
  if (!seriesDataLength && !chartOptions.onlyText) {
1073
- result = highchartsRenderer.getNoDataResult(chartOptions);
1064
+ result = highchartsRenderer.getNoDataResult();
1074
1065
  opts.error_has_occurred = true;
1075
1066
  opts.error_params = highchartsRenderer.widgetPlaceholders.nodata;
1076
1067
  } else if (!chartOptions.onlyText && chartOptions.series && toMatch) {
1077
- result = highchartsRenderer.getNoDataResult(chartOptions, toMatch);
1068
+ result = highchartsRenderer.getNoDataResult(toMatch);
1078
1069
  opts.error_has_occurred = true;
1079
1070
  opts.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
1080
1071
  } else {
@@ -3922,10 +3913,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3922
3913
  this.ignoreValue = true;
3923
3914
  }
3924
3915
 
3925
- if (highchartsRenderer.useTotalsCalculation && !isNaN(parseFloat(record[attr]))) {
3916
+ if (!isNaN(parseFloat(record[attr]))) {
3926
3917
  return this.sum = parseFloat(record[attr]);
3927
- } else if (!isNaN(parseFloat(record[attr]))) {
3928
- return this.sum += parseFloat(record[attr]);
3929
3918
  }
3930
3919
  },
3931
3920
  value: function () {
@@ -4080,11 +4069,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4080
4069
  this.ignoreValue = true;
4081
4070
  }
4082
4071
 
4083
- if (highchartsRenderer.useTotalsCalculation) {
4084
- return this.sum = val;
4085
- } else {
4086
- return this.sum += val;
4087
- }
4072
+ return this.sum = val;
4088
4073
  } else {
4089
4074
  return this.sum = NaN;
4090
4075
  }
@@ -4172,11 +4157,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4172
4157
  if (highchartsRenderer.ignoreIfCalculatedValue(data, rowKey, colKey, record, calculated_info.associated_fields, render_options, is_graph)) {
4173
4158
  this.ignoreValue = true;
4174
4159
  }
4175
- if (highchartsRenderer.useTotalsCalculation) {
4176
- return this.val = x;
4177
- } else {
4178
- return this.val = Math.min(x, (ref = this.val) != null ? ref : x);
4179
- }
4160
+
4161
+ return this.val = x;
4180
4162
  }
4181
4163
  },
4182
4164
  value: function () {
@@ -4263,11 +4245,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4263
4245
  this.ignoreValue = true;
4264
4246
  }
4265
4247
 
4266
- if (highchartsRenderer.useTotalsCalculation) {
4267
- return this.val = x;
4268
- } else {
4269
- return this.val = Math.max(x, (ref = this.val) != null ? ref : x);
4270
- }
4248
+ return this.val = x;
4271
4249
  }
4272
4250
  },
4273
4251
  value: function () {
@@ -4355,12 +4333,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4355
4333
  this.ignoreValue = true;
4356
4334
  }
4357
4335
 
4358
-
4359
- if (highchartsRenderer.useTotalsCalculation) {
4360
- this.sum = parseFloat(x);
4361
- } else {
4362
- this.sum += parseFloat(x);
4363
- }
4336
+ this.sum = parseFloat(x);
4364
4337
 
4365
4338
  return this.len++;
4366
4339
  }
@@ -4369,10 +4342,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4369
4342
  if (this.ignoreValue) {
4370
4343
  return null;
4371
4344
  }
4372
- if (highchartsRenderer.useTotalsCalculation) {
4373
- return this.sum;
4374
- }
4375
- return this.sum / this.len;
4345
+ return this.sum;
4376
4346
  },
4377
4347
  format: function (x, only_formats) {
4378
4348
  if (x == null || x == undefined)
@@ -4669,7 +4639,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4669
4639
  class: uniqueCategories.length < minCategories ? 'waterfall-nodata' : 'waterfall-too-much-data',
4670
4640
  }
4671
4641
 
4672
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4642
+ return highchartsRenderer.getNoDataResult(true);
4673
4643
  }
4674
4644
  }
4675
4645
 
@@ -4680,7 +4650,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4680
4650
 
4681
4651
  options.error_has_occurred = true;
4682
4652
  options.error_params = highchartsRenderer.widgetPlaceholders.nodata;
4683
- return highchartsRenderer.getNoDataResult(options.rendererOptions);
4653
+ return highchartsRenderer.getNoDataResult();
4684
4654
  }
4685
4655
 
4686
4656
  if (rowData.length > highchartsRenderer.MAX_ROWS_FOR_SHOW_RESULTS) {
@@ -4690,7 +4660,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4690
4660
 
4691
4661
  options.error_has_occurred = true;
4692
4662
  options.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
4693
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4663
+ return highchartsRenderer.getNoDataResult(true);
4694
4664
  }
4695
4665
 
4696
4666
  var tmp = $.pivotUtilities.aggregatorTemplates;
@@ -4839,7 +4809,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4839
4809
  class: uniqueCategories.length < minCategories ? 'waterfall-nodata' : 'waterfall-too-much-data',
4840
4810
  }
4841
4811
 
4842
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4812
+ return highchartsRenderer.getNoDataResult(true);
4843
4813
  }
4844
4814
  }
4845
4815
 
@@ -4850,7 +4820,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4850
4820
 
4851
4821
  options.error_has_occurred = true;
4852
4822
  options.error_params = highchartsRenderer.widgetPlaceholders.nodata;
4853
- return highchartsRenderer.getNoDataResult(options.rendererOptions);
4823
+ return highchartsRenderer.getNoDataResult();
4854
4824
  }
4855
4825
 
4856
4826
  if (rowData.length > highchartsRenderer.MAX_ROWS_FOR_SHOW_RESULTS) {
@@ -4860,7 +4830,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4860
4830
 
4861
4831
  options.error_has_occurred = true;
4862
4832
  options.error_params = highchartsRenderer.widgetPlaceholders.tooMuchData;
4863
- return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4833
+ return highchartsRenderer.getNoDataResult(true);
4864
4834
  }
4865
4835
 
4866
4836
  var tmp = $.pivotUtilities.aggregatorTemplates;
@@ -8962,20 +8932,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8962
8932
  return res;
8963
8933
  };
8964
8934
 
8965
- highchartsRenderer.setNewFieldNames = function (res) {
8966
- if (highchartsRenderer.useTotalsCalculation) {
8967
- return res;
8968
- }
8969
-
8970
- if (res && res[0] && res[0]['DR_Values']) {
8971
- lodash.forEach(res, function (item) {
8972
- item['DR_Values'] = highchartsRenderer.getFieldName(item['DR_Values']);
8973
- });
8974
- }
8975
-
8976
- return res;
8977
- };
8978
-
8979
8935
  highchartsRenderer.replaceSortingKeysWithMappedValues = function(keys, invertedDateStringMap, widgetFields) {
8980
8936
  if (!keys || !invertedDateStringMap) {
8981
8937
  return;
@@ -9236,8 +9192,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9236
9192
  let res = highchartsRenderer.updateSelectedOverrideValues(widget_obj, override_values, row_data);
9237
9193
  res = highchartsRenderer.convertUniqueDateValues(widget_obj, templates, res);
9238
9194
 
9239
- res = highchartsRenderer.setNewFieldNames(res);
9240
-
9241
9195
  if (widget_obj.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH) {
9242
9196
  res = highchartsRenderer.addTotalsToWalkthroughRowData(widget_obj, res);
9243
9197
  }
@@ -9764,8 +9718,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9764
9718
  // TODO: remove it when fixed on BE side
9765
9719
  highchartsRenderer.fixIncompatibleCalculatedValuesTotals = function(widget, res) {
9766
9720
 
9767
- // if it is FE side calculation or empty response - just return unmodified
9768
- if (!highchartsRenderer.useTotalsCalculation || !lodash.get(res, 'length')) return res;
9721
+ // if it is empty response - just return unmodified
9722
+ if (!lodash.get(res, 'length')) return res;
9769
9723
 
9770
9724
  const calculatedValuesInValsCount = lodash.filter(
9771
9725
  widget.calculated_values, calcVal => lodash.some(widget.vals, { field: calcVal.field })
package/src/pivottable.js CHANGED
@@ -22,10 +22,7 @@ let initPivotTable = function($, window, document) {
22
22
  }
23
23
  return x1 + x2;
24
24
  };
25
- let useTotalsCalculation = false;
26
- if (document.ReportHippo && document.ReportHippo && document.ReportHippo.user) {
27
- useTotalsCalculation = _.includes(document.ReportHippo.user.features, 'enable_server_totals_calculation');
28
- }
25
+
29
26
  numberFormat = function(opts) {
30
27
  var defaults;
31
28
  defaults = {
@@ -715,7 +712,7 @@ let initPivotTable = function($, window, document) {
715
712
  PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
716
713
  return function(record) {
717
714
  if (_this.filter(record)) {
718
- return _this.processRecord(record, useTotalsCalculation);
715
+ return _this.processRecord(record);
719
716
  }
720
717
  };
721
718
  })(this));
@@ -1969,15 +1969,7 @@ describe('highcharts_renderer', () => {
1969
1969
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
1970
1970
  });
1971
1971
 
1972
- it('Value should be a sum of records when server calculation disabled', () => {
1973
- highchartsRenderer.useTotalsCalculation = false;
1974
- aggregatorObject.push({Profit: 10});
1975
- aggregatorObject.push({Profit: 20});
1976
- expect(aggregatorObject.sum).toEqual(30);
1977
- });
1978
-
1979
- it('Value should be a last record value when server calculation enabled', () => {
1980
- highchartsRenderer.useTotalsCalculation = true;
1972
+ it('Value should be a last record value', () => {
1981
1973
  aggregatorObject.push({Profit: 10});
1982
1974
  aggregatorObject.push({Profit: 20});
1983
1975
  expect(aggregatorObject.sum).toEqual(20);
@@ -2178,15 +2170,7 @@ describe('highcharts_renderer', () => {
2178
2170
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2179
2171
  });
2180
2172
 
2181
- it('Value should be a sum of records when server calculation disabled', () => {
2182
- highchartsRenderer.useTotalsCalculation = false;
2183
- aggregatorObject.push({Profit: 10});
2184
- aggregatorObject.push({Profit: 20});
2185
- expect(aggregatorObject.sum).toEqual(30);
2186
- });
2187
-
2188
- it('Value should be a last record value when server calculation enabled', () => {
2189
- highchartsRenderer.useTotalsCalculation = true;
2173
+ it('Value should be a last record value', () => {
2190
2174
  aggregatorObject.push({Profit: 10});
2191
2175
  aggregatorObject.push({Profit: 20});
2192
2176
  expect(aggregatorObject.sum).toEqual(20);
@@ -2379,13 +2363,6 @@ describe('highcharts_renderer', () => {
2379
2363
  expect(aggregatorObject.formated_values).toEqual(['$123.12', 456.456, 789.789]);
2380
2364
  });
2381
2365
 
2382
- // it('Value should be a sum of records when server calculation disabled', () => {
2383
- // highchartsRenderer.useTotalsCalculation = false;
2384
- // aggregatorObject.push({Profit: 10});
2385
- // aggregatorObject.push({Profit: 20});
2386
- // expect(aggregatorObject.sum).toEqual(30);
2387
- // });
2388
-
2389
2366
  it('Value must be ignored if calculated totals disabled', () => {
2390
2367
  const options = {
2391
2368
  chartOptions: {
@@ -2541,16 +2518,7 @@ describe('highcharts_renderer', () => {
2541
2518
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2542
2519
  });
2543
2520
 
2544
- it('Value should be a sum of records when server calculation disabled', () => {
2545
- highchartsRenderer.useTotalsCalculation = false;
2546
- aggregatorObject.push({Profit: 10});
2547
- aggregatorObject.push({Profit: 20});
2548
- expect(aggregatorObject.sum).toEqual(30);
2549
- expect(aggregatorObject.len).toEqual(2);
2550
- });
2551
-
2552
- it('Value should be a last record value when server calculation enabled', () => {
2553
- highchartsRenderer.useTotalsCalculation = true;
2521
+ it('Value should be a last record value', () => {
2554
2522
  aggregatorObject.push({Profit: 20});
2555
2523
  aggregatorObject.push({Profit: 10});
2556
2524
  expect(aggregatorObject.sum).toEqual(10);
@@ -2615,17 +2583,10 @@ describe('highcharts_renderer', () => {
2615
2583
  expect(aggregatorObject.value()).toBe(null);
2616
2584
  });
2617
2585
 
2618
- it('Should return sum if server calculation enabled', () => {
2619
- highchartsRenderer.useTotalsCalculation = true;
2586
+ it('Should return sum', () => {
2620
2587
  aggregatorObject.ignoreValue = false;
2621
2588
  expect(aggregatorObject.value()).toBe(20);
2622
2589
  });
2623
-
2624
- it('Should return average if server calculation disabled', () => {
2625
- highchartsRenderer.useTotalsCalculation = false;
2626
- aggregatorObject.ignoreValue = false;
2627
- expect(aggregatorObject.value()).toBe(5);
2628
- });
2629
2590
  });
2630
2591
 
2631
2592
  describe('Format method', () => {
@@ -2761,15 +2722,7 @@ describe('highcharts_renderer', () => {
2761
2722
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2762
2723
  });
2763
2724
 
2764
- it('Value should be a min of records when server calculation disabled', () => {
2765
- highchartsRenderer.useTotalsCalculation = false;
2766
- aggregatorObject.push({Profit: 10});
2767
- aggregatorObject.push({Profit: 20});
2768
- expect(aggregatorObject.val).toEqual(10);
2769
- });
2770
-
2771
- it('Value should be a last record value when server calculation enabled', () => {
2772
- highchartsRenderer.useTotalsCalculation = true;
2725
+ it('Value should be a last record value', () => {
2773
2726
  aggregatorObject.push({Profit: 10});
2774
2727
  aggregatorObject.push({Profit: 20});
2775
2728
  expect(aggregatorObject.val).toEqual(20);
@@ -2971,15 +2924,7 @@ describe('highcharts_renderer', () => {
2971
2924
  expect(aggregatorObject.formats).toEqual(['####', '#,###']);
2972
2925
  });
2973
2926
 
2974
- it('Value should be a min of records when server calculation disabled', () => {
2975
- highchartsRenderer.useTotalsCalculation = false;
2976
- aggregatorObject.push({Profit: 20});
2977
- aggregatorObject.push({Profit: 10});
2978
- expect(aggregatorObject.val).toEqual(20);
2979
- });
2980
-
2981
- it('Value should be a last record value when server calculation enabled', () => {
2982
- highchartsRenderer.useTotalsCalculation = true;
2927
+ it('Value should be a last record value', () => {
2983
2928
  aggregatorObject.push({Profit: 20});
2984
2929
  aggregatorObject.push({Profit: 10});
2985
2930
  expect(aggregatorObject.val).toEqual(10);
@@ -4473,44 +4418,6 @@ describe('highcharts_renderer', () => {
4473
4418
  });
4474
4419
  });
4475
4420
 
4476
- describe('function setNewFieldNames', () => {
4477
- beforeEach(() => {
4478
- highchartsRenderer.useTotalsCalculation = false;
4479
- });
4480
-
4481
- it('should return the input if useTotalsCalculation is true', () => {
4482
- const res = [{ DR_Values: 'value1' }, { DR_Values: 'value2' }];
4483
- highchartsRenderer.useTotalsCalculation = true;
4484
- const result = highchartsRenderer.setNewFieldNames(res);
4485
-
4486
- expect(result).toEqual(res);
4487
- });
4488
-
4489
- it('should update DR_Values field names', () => {
4490
- const res = [{ DR_Values: 'DR_Values' }, { DR_Values: 'value2' }];
4491
- const expected = [{ DR_Values: 'Values' }, { DR_Values: 'value2' }];
4492
- const result = highchartsRenderer.setNewFieldNames(res);
4493
-
4494
- expect(result).toEqual(expected);
4495
- });
4496
-
4497
- it('should handle empty input', () => {
4498
- const res = null;
4499
- const expected = null;
4500
- const result = highchartsRenderer.setNewFieldNames(res);
4501
-
4502
- expect(result).toEqual(expected);
4503
- });
4504
-
4505
- it('should handle empty DR_Values array in input', () => {
4506
- const res = [{}];
4507
- const expected = [{ DR_Values: undefined }];
4508
- const result = highchartsRenderer.setNewFieldNames(res);
4509
-
4510
- expect(result).toEqual(expected);
4511
- });
4512
- });
4513
-
4514
4421
  describe('function getOptionsForLegends', () => {
4515
4422
  const rowAttrsLength = 1;
4516
4423
  let additionOptions;
@@ -6244,6 +6151,85 @@ describe('highcharts_renderer', () => {
6244
6151
  });
6245
6152
  });
6246
6153
 
6154
+ describe('Function tableCSVExportRenderer', () => {
6155
+ window._ = lodash;
6156
+ it('should create csv json object representation based on pivot data', () => {
6157
+ const inputs = [
6158
+ {
6159
+ "Date": 1653955200,
6160
+ "Amount": 2849521.69
6161
+ },
6162
+ {
6163
+ "Date": 1653177600,
6164
+ "Amount": 3141257.27
6165
+ },
6166
+ {
6167
+ "Date": 1652400000,
6168
+ "Amount": 1700691.7000000002
6169
+ },
6170
+ {
6171
+ "Date": 1651363200,
6172
+ "Amount": 2142840.39
6173
+ },
6174
+ {
6175
+ "Amount": 9834311.05
6176
+ },
6177
+ {
6178
+ "col_keys": [
6179
+ [
6180
+ 1651363200
6181
+ ],
6182
+ [
6183
+ 1652400000
6184
+ ],
6185
+ [
6186
+ 1653177600
6187
+ ],
6188
+ [
6189
+ 1653955200
6190
+ ]
6191
+ ],
6192
+ "row_keys": []
6193
+ }
6194
+ ];
6195
+ const subOptions = {
6196
+ "sorters": () => null,
6197
+ "sortByValueAttrs": [],
6198
+ "cols": [
6199
+ "Date",
6200
+ "Payment Date"
6201
+ ],
6202
+ "rows": [],
6203
+ "colFormats": [
6204
+ {
6205
+ "type": "Date",
6206
+ "name": "Date",
6207
+ "val_not_convert": []
6208
+ },
6209
+ {
6210
+ "type": "Date",
6211
+ "name": "Payment Date",
6212
+ "val_not_convert": []
6213
+ }
6214
+ ],
6215
+ "rowFormats": [],
6216
+ "rendererOptions": {
6217
+ },
6218
+ };
6219
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6220
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData);
6221
+ expect(csvJson).toEqual(
6222
+ [
6223
+ [ 1651363200, 1652400000, 1653177600, 1653955200, 'Totals' ],
6224
+ [ undefined, undefined, undefined, undefined, 'Totals' ],
6225
+ [],
6226
+ [ 1, 1, 1, 1, 2 ],
6227
+ [ 1, 1, 1, 1, 2 ]
6228
+ ]
6229
+ );
6230
+ });
6231
+ });
6232
+
6247
6233
  describe("Function returnRawDataValue", () => {
6248
6234
  const testCases = [{
6249
6235
  name: "Date",
@@ -7427,4 +7413,42 @@ describe('highcharts_renderer', () => {
7427
7413
  ]);
7428
7414
  })
7429
7415
  });
7416
+
7417
+ describe('Function getNoDataResult', () => {
7418
+ const container = $('<div class="noData-box"></div>');
7419
+
7420
+ it('should return no data html', () => {
7421
+ const placeholderMeta = highchartsRenderer.widgetPlaceholders.nodata;
7422
+ const expected = container.clone().html(highchartsRenderer.getWidgetPlaceholder(placeholderMeta));
7423
+ expect(highchartsRenderer.getNoDataResult()).toEqual(expected);
7424
+ });
7425
+
7426
+ it('should return too much data html', () => {
7427
+ const placeholderMeta = highchartsRenderer.widgetPlaceholders.tooMuchData;
7428
+ const expected = container.clone().html(highchartsRenderer.getWidgetPlaceholder(placeholderMeta));
7429
+ expect(highchartsRenderer.getNoDataResult(true)).toEqual(expected);
7430
+ });
7431
+
7432
+ });
7433
+
7434
+ describe('Function getWidgetPlaceholder', () => {
7435
+ const titleSelector = '.noData-title';
7436
+ const imageSelector = '.noData-image';
7437
+ const textSelector = '.noData-text';
7438
+
7439
+ it('should return default placeholder when no data is provided', () => {
7440
+ const placeholder = highchartsRenderer.getWidgetPlaceholder();
7441
+ const defaultPlaceholder = '<div class="noData"><i class="noData-image"></i> no data</div>';
7442
+ expect(placeholder[0].outerHTML).toEqual(defaultPlaceholder);
7443
+ });
7444
+
7445
+ it('should return placeholder html when data is provided', () => {
7446
+ Object.entries(highchartsRenderer.widgetPlaceholders).forEach(([, value]) => {
7447
+ const placeholder = highchartsRenderer.getWidgetPlaceholder(value)[0];
7448
+ expect(placeholder.querySelector(titleSelector).innerHTML).toEqual(value.title);
7449
+ expect(placeholder.querySelector(imageSelector).classList.contains(value.class)).toBeTruthy();
7450
+ expect(placeholder.querySelector(textSelector).innerHTML).toEqual(value.text);
7451
+ });
7452
+ });
7453
+ })
7430
7454
  });