@datarailsshared/dr_renderer 1.2.323-dragons → 1.2.325

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.
@@ -139,6 +139,11 @@ const CHART_AXIS_DEFAULT_LABEL = 'Axis (Category)';
139
139
 
140
140
  const CHART_LEGEND_DEFAULT_LABEL = 'Legend (Series)';
141
141
 
142
+ const FEATURES = {
143
+ ENABLE_NEW_WIDGET_VALUE_FORMATTING: 'enable_new_widget_value_formatting',
144
+ ENABLE_SERVER_TOTALS_CALCULATION: 'enable_server_totals_calculation',
145
+ }
146
+
142
147
  let getHighchartsRenderer = function ($, document, Highcharts, default_colors, highchartsRenderer,
143
148
  DataFormatter, lodash, moment_lib, isNewAngular) {
144
149
 
@@ -166,10 +171,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
166
171
  lodash.assign(highchartsRenderer, HIGHCHARTS_CONSTANTS);
167
172
 
168
173
  highchartsRenderer.useTotalsCalculation = false;
174
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
169
175
  let disableAnimation = false;
170
176
  if (document.ReportHippo && document.ReportHippo && document.ReportHippo.user) {
171
- highchartsRenderer.useTotalsCalculation = lodash.includes(document.ReportHippo.user.features, 'enable_server_totals_calculation');
177
+ highchartsRenderer.useTotalsCalculation = lodash.includes(document.ReportHippo.user.features, FEATURES.ENABLE_SERVER_TOTALS_CALCULATION);
172
178
  disableAnimation = document.ReportHippo.user.organization && document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.disable_animation
179
+ highchartsRenderer.enabledNewWidgetValueFormatting = lodash.includes(document.ReportHippo.user.features, FEATURES.ENABLE_NEW_WIDGET_VALUE_FORMATTING);
173
180
  }
174
181
 
175
182
  // fix issue of use tootip.stickOnContact with tooltip.outside , source: https://github.com/highcharts/highcharts/pull/15960
@@ -628,7 +635,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
628
635
  // do nothing
629
636
  }
630
637
  }
631
- return $.pivotUtilities.getFormattedNumber(value, null, opts);
638
+ return $.pivotUtilities.getFormattedNumber(value, null, opts).replace(/\u00A0/g, " ");
632
639
  };
633
640
  return func;
634
641
  };
@@ -1150,7 +1157,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1150
1157
  ob.name = row_n_value.join(highchartsRenderer.delimer)
1151
1158
  .replace(highchartsRenderer.DR_OTHERS_KEY, othersName);
1152
1159
  }
1153
-
1154
1160
  lodash.forEach(col_n_keys, function (col_n_value, index) {
1155
1161
  var agg = pivotData.getAggregator(row_n_value, col_n_value);
1156
1162
  var val = agg.value();
@@ -1392,7 +1398,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1392
1398
  if (opts.trendLine) {
1393
1399
  const a = ((ySum * squareXSum) - (xSum * xySum)) / ((n * squareXSum) - (xSum * xSum));
1394
1400
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
1395
-
1396
1401
  const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
1397
1402
  trendSeries.className = 'trendSeries';
1398
1403
  trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
@@ -1403,7 +1408,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1403
1408
  if (colors && colors[i]) {
1404
1409
  trendSeries.color = colors[i];
1405
1410
  }
1406
-
1407
1411
  trendSerieses.push(trendSeries);
1408
1412
  }
1409
1413
  i++;
@@ -1420,7 +1424,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1420
1424
  }
1421
1425
 
1422
1426
  let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
1423
-
1424
1427
  if (opts.comboOptions && lodash.includes(chartType,'combo') && !lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
1425
1428
  chart_series.forEach((series, seriesIndex) => {
1426
1429
  const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
@@ -1507,7 +1510,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1507
1510
  const chart_series = [];
1508
1511
  const row_n_keys = pivotData.getRowKeys();
1509
1512
  const col_n_keys = pivotData.getColKeys();
1510
- const rows_by_cols = pivotData.rowKeysByCols;
1511
1513
 
1512
1514
  let resultObject = {
1513
1515
  data: [],
@@ -1536,9 +1538,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1536
1538
  });
1537
1539
 
1538
1540
  if (col_index !== col_n_keys.length - 1) {
1539
-
1540
- const rowKeys = rows_by_cols ? rows_by_cols[col_index] : row_n_keys;
1541
- lodash.forEach(rowKeys, function (row_n_value) {
1541
+ lodash.forEach(row_n_keys, function (row_n_value) {
1542
1542
  const agg = pivotData.getAggregator(row_n_value, col_n_value);
1543
1543
  let val = agg.value();
1544
1544
 
@@ -3890,6 +3890,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3890
3890
 
3891
3891
  highchartsRenderer.rhPivotCount = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
3892
3892
  var attr = arg[0];
3893
+ // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
3894
+ // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
3895
+ // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
3896
+ const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
3897
+
3893
3898
  return function (data, rowKey, colKey) {
3894
3899
  return {
3895
3900
  sum: 0,
@@ -3901,6 +3906,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3901
3906
  calculated_formats: calculated_info.formats,
3902
3907
  isChangeable: false,
3903
3908
  push: function (record) {
3909
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
3910
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
3911
+ }
3912
+
3904
3913
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
3905
3914
  this.data_types = this.data_types.concat(record['data_types']);
3906
3915
  this.data_types = lodash.uniq(this.data_types);
@@ -3945,7 +3954,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3945
3954
  number_format = 'General';
3946
3955
  }
3947
3956
 
3948
- if (this.widget_values_format) {
3957
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
3958
+ number_format = this.widget_values_format;
3959
+ }
3960
+
3961
+ if (isCustomValuesFormat) {
3949
3962
  number_format = this.widget_values_format;
3950
3963
  }
3951
3964
 
@@ -4033,6 +4046,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4033
4046
 
4034
4047
  highchartsRenderer.rhPivotAggregatorSum = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4035
4048
  var attr = arg[0];
4049
+ // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4050
+ // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4051
+ // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4052
+ const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4053
+
4036
4054
  return function (data, rowKey, colKey) {
4037
4055
  return {
4038
4056
  sum: 0,
@@ -4053,7 +4071,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4053
4071
  }
4054
4072
  }
4055
4073
  var val = parseFloat(record[attr]);
4074
+
4056
4075
  if (!isNaN(val)) {
4076
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4077
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4078
+ }
4057
4079
 
4058
4080
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4059
4081
  this.data_types = this.data_types.concat(record['data_types']);
@@ -4100,13 +4122,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4100
4122
  number_format = 'General';
4101
4123
  }
4102
4124
 
4103
- if (this.widget_values_format) {
4125
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4104
4126
  number_format = this.widget_values_format;
4105
4127
  }
4106
4128
 
4129
+ if (isCustomValuesFormat) {
4130
+ number_format = this.widget_values_format;
4131
+ }
4107
4132
  number_format = highchartsRenderer.getCalculatedValueFormat(this.calculated_formats, rowKey, colKey) || number_format;
4108
-
4109
4133
  var formated_value = highchartsRenderer.formatValue('n', number_format, x)
4134
+
4110
4135
  if (formated_value && formated_value.hasOwnProperty('value') && formated_value.value != null) {
4111
4136
  return formated_value.value;
4112
4137
  } else {
@@ -4121,6 +4146,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4121
4146
 
4122
4147
  highchartsRenderer.rhPivotAggregatorMin = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4123
4148
  var attr = arg[0];
4149
+ // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4150
+ // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4151
+ // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4152
+ const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4153
+
4124
4154
  return function (data, rowKey, colKey) {
4125
4155
  return {
4126
4156
  val: null,
@@ -4144,6 +4174,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4144
4174
  var ref, x;
4145
4175
  x = parseFloat(record[attr]);
4146
4176
  if (!isNaN(x)) {
4177
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4178
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4179
+ }
4180
+
4147
4181
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4148
4182
  this.data_types = this.data_types.concat(record['data_types']);
4149
4183
  this.data_types = lodash.uniq(this.data_types);
@@ -4186,7 +4220,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4186
4220
  number_format = 'General';
4187
4221
  }
4188
4222
 
4189
- if (this.widget_values_format) {
4223
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4224
+ number_format = this.widget_values_format;
4225
+ }
4226
+
4227
+ if (isCustomValuesFormat) {
4190
4228
  number_format = this.widget_values_format;
4191
4229
  }
4192
4230
 
@@ -4207,6 +4245,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4207
4245
 
4208
4246
  highchartsRenderer.rhPivotAggregatorMax = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4209
4247
  var attr = arg[0];
4248
+ // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4249
+ // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4250
+ // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4251
+ const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4252
+
4210
4253
  return function (data, rowKey, colKey) {
4211
4254
  return {
4212
4255
  val: null,
@@ -4230,6 +4273,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4230
4273
  var ref, x;
4231
4274
  x = parseFloat(record[attr]);
4232
4275
  if (!isNaN(x)) {
4276
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4277
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4278
+ }
4279
+
4233
4280
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4234
4281
  this.data_types = this.data_types.concat(record['data_types']);
4235
4282
  this.data_types = lodash.uniq(this.data_types);
@@ -4273,7 +4320,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4273
4320
  number_format = 'General';
4274
4321
  }
4275
4322
 
4276
- if (this.widget_values_format) {
4323
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4324
+ number_format = this.widget_values_format;
4325
+ }
4326
+
4327
+ if (isCustomValuesFormat) {
4277
4328
  number_format = this.widget_values_format;
4278
4329
  }
4279
4330
 
@@ -4294,6 +4345,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4294
4345
 
4295
4346
  highchartsRenderer.rhPivotAggregatorAverage = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4296
4347
  var attr = arg[0];
4348
+ // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4349
+ // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4350
+ // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4351
+ const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4352
+
4297
4353
  return function (data, rowKey, colKey) {
4298
4354
  return {
4299
4355
  sum: 0,
@@ -4318,6 +4374,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4318
4374
  var ref, x;
4319
4375
  x = parseFloat(record[attr]);
4320
4376
  if (!isNaN(x)) {
4377
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4378
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4379
+ }
4380
+
4321
4381
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4322
4382
  this.data_types = this.data_types.concat(record['data_types']);
4323
4383
  this.data_types = lodash.uniq(this.data_types);
@@ -4367,7 +4427,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4367
4427
  number_format = 'General';
4368
4428
  }
4369
4429
 
4370
- if (this.widget_values_format) {
4430
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4431
+ number_format = this.widget_values_format;
4432
+ }
4433
+
4434
+ if (isCustomValuesFormat) {
4371
4435
  number_format = this.widget_values_format;
4372
4436
  }
4373
4437
 
@@ -4714,18 +4778,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4714
4778
  opts.rendererOptions.onlyOptions = true;
4715
4779
  }
4716
4780
 
4717
- if (!highchartsRenderer.isSortingOnBackendEnabled()) {
4718
- const sortByValueSettings = lodash.filter(
4719
- lodash.get(widget, 'options.sortingFields', []),
4720
- sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
4721
- );
4722
-
4723
- if (sortByValueSettings.length) {
4724
- pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
4725
- let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
4726
- opts.sorters = new_sorting_function;
4727
- optsFiltered.sorters = new_sorting_function;
4728
- pivotData.sorters = new_sorting_function;
4781
+ const sortByValueSettings = lodash.filter(
4782
+ lodash.get(widget, 'options.sortingFields', []),
4783
+ sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
4784
+ );
4785
+
4786
+ if (sortByValueSettings.length) {
4787
+ pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
4788
+ let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
4789
+ opts.sorters = new_sorting_function;
4790
+ optsFiltered.sorters = new_sorting_function;
4791
+ pivotData.sorters = new_sorting_function;
4792
+
4793
+ if (lodash.isObject(lodash.get(widget, 'pivot'))) {
4794
+ widget.pivot.sorters = new_sorting_function;
4729
4795
  }
4730
4796
  }
4731
4797
 
@@ -4740,6 +4806,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4740
4806
  result = {};
4741
4807
  }
4742
4808
  }
4809
+
4810
+ if (lodash.isObject(lodash.get(widget, 'pivot'))) {
4811
+ widget.pivot.sortByValueAttrs = pivotData.sortByValueAttrs;
4812
+ }
4743
4813
  } catch (_error) {
4744
4814
  e = _error;
4745
4815
  if (typeof console !== "undefined" && console !== null) {
@@ -4776,11 +4846,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4776
4846
  }
4777
4847
  var subopts = {
4778
4848
  sorters: pivotOptions ? pivotOptions.sorters : null,
4849
+ sortByValueAttrs: pivotOptions ? pivotOptions.sortByValueAttrs : null,
4779
4850
  cols: lodash.map(pivotOptions.axisArray, 'name'),
4780
4851
  rows: lodash.map(pivotOptions.legendArray, 'name'),
4781
4852
  rendererOptions: widget.options,
4782
4853
  dateValuesDictionary: pivotOptions ? pivotOptions.dateValuesDictionary : null,
4783
- keysObject: pivotOptions ? pivotOptions.keysObject : null,
4784
4854
  };
4785
4855
 
4786
4856
  if (!subopts.rendererOptions) {
@@ -5594,21 +5664,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5594
5664
 
5595
5665
  lodash.forEach(functionOptions.filters, function (filterObj) {
5596
5666
  fieldOb = lodash.find(fields, {id: filterObj.field});
5597
- if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype == 'list') {
5667
+ if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype === 'list') {
5598
5668
  filterObj.values = filterObj.values.val
5599
- } else if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype != 'list') {
5669
+ } else if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype !== 'list') {
5600
5670
  fieldOb.values = filterObj.values;
5601
5671
  } else if (fieldOb && filterObj.values && filterObj.values.type === 'advanced') {
5602
5672
  fieldOb.values = filterObj.values;
5603
5673
  }
5604
5674
 
5605
5675
  if (fieldOb && filterObj.values && filterObj.values instanceof Array) {
5606
- if (filterObj.is_excluded == true) {
5676
+ if (filterObj.is_excluded) {
5607
5677
  fieldOb.excludes = filterObj.values;
5608
5678
  } else {
5609
5679
  fieldOb.includes = filterObj.values;
5610
5680
  }
5611
- //includes[fieldOb.name] = highchartsRenderer.getOnlyIncludedOfField(fieldOb);
5612
5681
  }
5613
5682
  if (filterObj.show_in_graph && fieldOb) {
5614
5683
  fieldOb.show_in_graph = filterObj.show_in_graph
@@ -5774,7 +5843,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5774
5843
  widgetOptions.pivot.legendArray = legendFields;
5775
5844
  widgetOptions.pivot.valuesArray = valuesFields;
5776
5845
  widgetOptions.pivot.filtersArray = filterFields;
5777
- //widgetOptions.pivot.filter = filterFn;
5778
5846
  widgetOptions.pivot.filterIncludes = includes;
5779
5847
  widgetOptions.pivot.chartType = widgetOptions.chart_type;
5780
5848
  widgetOptions.pivot.chartOptions = widgetOptions.options;
@@ -8649,8 +8717,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8649
8717
  };
8650
8718
 
8651
8719
  highchartsRenderer.getWidgetDataSorters = function (res, widget, defaultDateFormat) {
8652
- let sorters;
8653
-
8654
8720
  if ($.pivotUtilities && !$.pivotUtilities.additionalFieldsList) {
8655
8721
  $.pivotUtilities.additionalFieldsList = [
8656
8722
  {key: 'DR_Average', name: 'DR_Average'},
@@ -8658,20 +8724,32 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8658
8724
  ];
8659
8725
  }
8660
8726
 
8661
- let datesFields = [];
8727
+ var datesFields = [];
8662
8728
  datesFields = lodash.filter(widget.rows, element => element.type == 'Date');
8663
8729
  datesFields = datesFields.concat(lodash.filter(widget.cols, element => element.type == 'Date'));
8730
+
8731
+ const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8732
+ if (isCustomSorting) {
8733
+ lodash.forEach(datesFields, function (field) {
8734
+ const fieldToSort = lodash.find(
8735
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8736
+ );
8737
+ field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8738
+ });
8739
+ }
8740
+
8664
8741
  datesFields = lodash.map(datesFields, function (row) {
8665
8742
  return { "format": highchartsRenderer.getDateFieldFormat(widget, row), "name": row.name, "type": row.type, "values": [], "sorting": row.sorting } //'MMM - yyyy' format
8666
8743
  });
8667
8744
 
8745
+ var data = res;
8746
+
8668
8747
  lodash.forEach(datesFields, function (row) {
8669
8748
  row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
8670
8749
  });
8671
8750
 
8672
8751
  if (datesFields.length > 0) {
8673
- const invertedDateStringMap = {};
8674
- lodash.forEach(res, function (element) {
8752
+ lodash.forEach(data, function (element) {
8675
8753
  for (var i in datesFields) {
8676
8754
  if (element.hasOwnProperty(datesFields[i].name)) {
8677
8755
  datesFields[i].values.push(element[datesFields[i].name]);
@@ -8684,156 +8762,125 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8684
8762
  widget.pivot.dateValuesDictionary = {}
8685
8763
  }
8686
8764
  widget.pivot.dateValuesDictionary[dateStringValue] = element[datesFields[i].name];
8687
- invertedDateStringMap[element[datesFields[i].name]] = dateStringValue;
8688
8765
  }
8689
8766
  element[datesFields[i].name] = dateStringValue;
8690
8767
  }
8691
8768
  }
8692
8769
  });
8693
-
8694
- if (highchartsRenderer.isSortingOnBackendEnabled()) {
8695
- lodash.forEach(['col_keys', 'row_keys'], (keysListName, index) => {
8696
- const widgetFields = index ? widget.rows : widget.cols;
8697
- const uniqueFormattedKeysList = [];
8698
- lodash.forEach(widget.pivot.keysObject[keysListName], subKeysList => {
8699
- lodash.forEach(subKeysList, (key, index) => {
8700
- if (widgetFields[index].type === 'Date') {
8701
- subKeysList[index] = invertedDateStringMap[key] || key;
8702
- }
8703
- });
8704
- if (!lodash.find(uniqueFormattedKeysList, formattedSubKeys => lodash.isEqual(formattedSubKeys, subKeysList))) {
8705
- uniqueFormattedKeysList.push(subKeysList);
8706
- }
8707
- });
8708
- widget.pivot.keysObject[keysListName] = uniqueFormattedKeysList;
8709
- });
8710
- }
8711
8770
  }
8771
+ lodash.forEach(datesFields, function (row) {
8772
+ row.values = lodash.uniq(row.values);
8712
8773
 
8713
- if (!highchartsRenderer.isSortingOnBackendEnabled()) {
8714
- const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8715
- if (isCustomSorting) {
8716
- lodash.forEach(datesFields, function (field) {
8717
- const fieldToSort = lodash.find(
8718
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8719
- );
8720
- field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8721
- });
8722
- }
8723
-
8724
- lodash.forEach(datesFields, function (row) {
8725
- row.values = lodash.uniq(row.values);
8726
-
8727
- const isTimestampDateField = row.type === 'Date' && lodash.some(row.values, value => typeof value ==='number');
8728
- if (isTimestampDateField) {
8729
- const nullValueIndex = row.values.indexOf(NULL_VALUE);
8730
- if (~nullValueIndex) {
8731
- row.values.splice(nullValueIndex, 1);
8732
- }
8733
- row.values = row.values.sort((a, b) => a - b);
8734
- if (~nullValueIndex) {
8735
- row.values.push(NULL_VALUE);
8736
- }
8737
- } else {
8738
- row.values = row.values.sort();
8774
+ const isTimestampDateField = row.type === 'Date' && lodash.some(row.values, value => typeof value ==='number');
8775
+ if (isTimestampDateField) {
8776
+ const nullValueIndex = row.values.indexOf(NULL_VALUE);
8777
+ if (~nullValueIndex) {
8778
+ row.values.splice(nullValueIndex, 1);
8739
8779
  }
8740
-
8741
- if (row.sorting && row.sorting.type == "largestToSmallest") {
8742
- row.values = lodash.reverse(row.values);
8780
+ row.values = row.values.sort((a, b) => a - b);
8781
+ if (~nullValueIndex) {
8782
+ row.values.push(NULL_VALUE);
8743
8783
  }
8744
- delete row.sorting;
8745
- row.values = lodash.map(row.values, function (val) {
8746
- return highchartsRenderer.returnRawDataValue(row.type, val, row.format, row.name, row.val_not_convert) + "";
8747
- })
8748
-
8749
- });
8784
+ } else {
8785
+ row.values = row.values.sort();
8786
+ }
8750
8787
 
8751
- /* date string */
8752
- var rowsAndCols = [];
8753
- rowsAndCols = widget.rows.concat(widget.cols);
8754
-
8755
- if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8756
-
8757
- // if it is breakdown widget - redefine sorting according to breakdown_options
8758
- // TODO: remove this when BE sort will be implemented
8759
- lodash.forEach(rowsAndCols, function (field) {
8760
- const waterfallFieldType = field.id === widget.cols[0].id ? 'totals' : 'breakdown';
8761
- field.sorting = {
8762
- type: 'CustomOrder',
8763
- values: lodash.map(
8764
- widget.options.breakdown_options.values[waterfallFieldType],
8765
- value => value.key
8766
- ),
8767
- };
8768
- });
8769
- } else if (isCustomSorting) {
8770
- lodash.forEach(rowsAndCols, function (field) {
8771
- const fieldToSort = lodash.find(
8772
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8773
- );
8774
- field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8775
- });
8788
+ if (row.sorting && row.sorting.type == "largestToSmallest") {
8789
+ row.values = lodash.reverse(row.values);
8776
8790
  }
8791
+ delete row.sorting;
8792
+ row.values = lodash.map(row.values, function (val) {
8793
+ return highchartsRenderer.returnRawDataValue(row.type, val, row.format, row.name, row.val_not_convert) + "";
8794
+ })
8795
+
8796
+ });
8797
+
8798
+ /* date string */
8799
+ var rowsAndCols = [];
8800
+ rowsAndCols = widget.rows.concat(widget.cols);
8777
8801
 
8802
+ if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8803
+
8804
+ // if it is breakdown widget - redefine sorting according to breakdown_options
8805
+ // TODO: remove this when BE sort will be implemented
8778
8806
  lodash.forEach(rowsAndCols, function (field) {
8779
- if (field.sorting && (field.sorting.type == "DateString" || field.sorting.type == "largestToSmallest")) {
8780
- var find_field = lodash.find(datesFields, {name: field.name});
8781
- if (find_field) {
8782
- if (find_field.type != 'Date')
8783
- find_field.sorting = field.sorting;
8784
- } else {
8785
- datesFields.push({
8786
- "format": field.format,
8787
- "name": field.name,
8788
- "type": field.type,
8789
- "values": [],
8790
- "sorting": field.sorting,
8791
- });
8792
- }
8793
- } else if (field.sorting && field.sorting.type == "CustomOrder" && field.sorting.values) {
8807
+ const waterfallFieldType = field.id === widget.cols[0].id ? 'totals' : 'breakdown';
8808
+ field.sorting = {
8809
+ type: 'CustomOrder',
8810
+ values: lodash.map(
8811
+ widget.options.breakdown_options.values[waterfallFieldType],
8812
+ value => value.key
8813
+ ),
8814
+ };
8815
+ });
8816
+ } else if (isCustomSorting) {
8817
+ lodash.forEach(rowsAndCols, function (field) {
8818
+ const fieldToSort = lodash.find(
8819
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8820
+ );
8821
+ field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8822
+ });
8823
+ }
8824
+
8825
+ lodash.forEach(rowsAndCols, function (field) {
8826
+ if (field.sorting && (field.sorting.type == "DateString" || field.sorting.type == "largestToSmallest")) {
8827
+ var find_field = lodash.find(datesFields, {name: field.name});
8828
+ if (find_field) {
8829
+ if (find_field.type != 'Date')
8830
+ find_field.sorting = field.sorting;
8831
+ } else {
8794
8832
  datesFields.push({
8795
8833
  "format": field.format,
8796
8834
  "name": field.name,
8797
8835
  "type": field.type,
8798
- "values": field.sorting.values
8836
+ "values": [],
8837
+ "sorting": field.sorting,
8799
8838
  });
8800
8839
  }
8801
- });
8840
+ } else if (field.sorting && field.sorting.type == "CustomOrder" && field.sorting.values) {
8841
+ datesFields.push({
8842
+ "format": field.format,
8843
+ "name": field.name,
8844
+ "type": field.type,
8845
+ "values": field.sorting.values
8846
+ });
8847
+ }
8848
+ });
8802
8849
 
8803
- if (widget.vals && widget.vals.length > 1) {
8804
- datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
8850
+ if (widget.vals && widget.vals.length > 1) {
8851
+ datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
8852
+ }
8853
+
8854
+ /****** END *******/
8855
+
8856
+ // TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
8857
+ if (widget.options && widget.options.sortingValues) {
8858
+ var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8859
+ if (field) {
8860
+ field.values = widget.options.sortingValues.values;
8861
+ field.sorting = null;
8862
+ } else {
8863
+ datesFields.push({
8864
+ name: widget.options.sortingValues.field,
8865
+ values: widget.options.sortingValues.values
8866
+ });
8805
8867
  }
8806
-
8807
- /****** END *******/
8808
-
8809
- // TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
8810
- if (widget.options && widget.options.sortingValues) {
8811
- var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8812
- if (field) {
8813
- field.values = widget.options.sortingValues.values;
8814
- field.sorting = null;
8868
+ }
8869
+
8870
+ let sorters = function (attr) {
8871
+ var field = lodash.find(datesFields, {name: attr});
8872
+ if (field)
8873
+ if (field.sorting && field.sorting.type == "DateString") {
8874
+ return $.pivotUtilities.sortDateStrings(field.sorting.month_order);
8875
+ } else if (field.sorting && field.sorting.type == "largestToSmallest") {
8876
+ if (field.sorting.is_absolute)
8877
+ return $.pivotUtilities.largeToSmallSortByAbsolute;
8878
+
8879
+ return $.pivotUtilities.largeToSmallSort;
8815
8880
  } else {
8816
- datesFields.push({
8817
- name: widget.options.sortingValues.field,
8818
- values: widget.options.sortingValues.values
8819
- });
8881
+ return $.pivotUtilities.sortAs(field.values);
8820
8882
  }
8821
- }
8822
- sorters = function (attr) {
8823
- var field = lodash.find(datesFields, {name: attr});
8824
- if (field)
8825
- if (field.sorting && field.sorting.type == "DateString") {
8826
- return $.pivotUtilities.sortDateStrings(field.sorting.month_order);
8827
- } else if (field.sorting && field.sorting.type == "largestToSmallest") {
8828
- if (field.sorting.is_absolute)
8829
- return $.pivotUtilities.largeToSmallSortByAbsolute;
8830
-
8831
- return $.pivotUtilities.largeToSmallSort;
8832
- } else {
8833
- return $.pivotUtilities.sortAs(field.values);
8834
- }
8835
- };
8836
- }
8883
+ };
8837
8884
 
8838
8885
  return sorters;
8839
8886
  };
@@ -8853,12 +8900,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8853
8900
 
8854
8901
  //highchartsRenderer.getGraphOptions(scope.data, override_values, res, scope.dataModel.templatesWithOutData, scope.openDrillDownList, drillDownFunction)
8855
8902
  highchartsRenderer.getGraphOptions = function (widget_obj, override_values, row_data, templates, openDrillDownListFunction, drillDownFunction) {
8856
-
8857
- let keysObject;
8858
- if (highchartsRenderer.isSortingOnBackendEnabled()) {
8859
- keysObject = row_data.pop();
8860
- }
8861
-
8862
8903
  let res = highchartsRenderer.updateSelectedOverrideValues(widget_obj, override_values, row_data);
8863
8904
  res = highchartsRenderer.convertUniqueDateValues(widget_obj, templates, res);
8864
8905
 
@@ -8870,10 +8911,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8870
8911
 
8871
8912
  let pivot = {};
8872
8913
 
8873
- if (highchartsRenderer.isSortingOnBackendEnabled()) {
8874
- pivot.keysObject = keysObject;
8875
- }
8876
-
8877
8914
  let templateNoData = lodash.find(templates, {id: widget_obj.template_id});
8878
8915
  if (templateNoData) {
8879
8916
 
@@ -8910,8 +8947,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8910
8947
  subopts.onlyOptions = true;
8911
8948
  }
8912
8949
 
8913
- subopts.keysObject = keysObject;
8914
-
8915
8950
  let hc_options = highchartsRenderer.rhPivotView(res, subopts, is_table, widget_obj);
8916
8951
 
8917
8952
  return hc_options;
@@ -9239,8 +9274,31 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9239
9274
  }
9240
9275
  }
9241
9276
 
9242
- highchartsRenderer.isSortingOnBackendEnabled = function() {
9243
- return lodash.includes(lodash.get(document, 'ReportHippo.user.features'), 'enable_server_widget_data_sorting');
9277
+ highchartsRenderer.checkFormats = function(render_options, widget_values_format) {
9278
+ let isSecondaryAxis = false;
9279
+ let formats = [];
9280
+ if (render_options && render_options.comboOptions && render_options.comboOptions.seriesOptions) {
9281
+ isSecondaryAxis = lodash.some(render_options.comboOptions.seriesOptions, series => series.secondaryAxis);
9282
+ formats = lodash.map(render_options.comboOptions.seriesOptions, series => series.format);
9283
+ }
9284
+ const isCustomFormat = !lodash.includes(formats, widget_values_format);
9285
+
9286
+ return { isSecondaryAxis, isCustomFormat }
9287
+ }
9288
+
9289
+ highchartsRenderer.getRecordFormats = function(render_options, recordName) {
9290
+ let formats = [];
9291
+ if (render_options && render_options.comboOptions && render_options.comboOptions.seriesOptions) {
9292
+ formats = render_options.comboOptions.seriesOptions
9293
+ .filter(series => series.series === recordName)
9294
+ .map(series => series.format);
9295
+ }
9296
+ return formats;
9297
+ }
9298
+
9299
+ highchartsRenderer.isCustomValuesFormat = function (render_options, widget_values_format) {
9300
+ const { isSecondaryAxis, isCustomFormat } = highchartsRenderer.checkFormats(render_options, widget_values_format);
9301
+ return highchartsRenderer.enabledNewWidgetValueFormatting && (isCustomFormat || !isSecondaryAxis);
9244
9302
  }
9245
9303
 
9246
9304
  return highchartsRenderer;