@datarailsshared/dr_renderer 1.2.318-rocket → 1.2.320

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.318-rocket",
3
+ "version": "1.2.320",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -91,6 +91,7 @@ let initDRPivotTable = function($, window, document) {
91
91
 
92
92
  DRPivotData.prototype.arrSort = function(attrs) {
93
93
  var a, sortersArr;
94
+ const sortByValueAttrs = this.sortByValueAttrs;
94
95
  sortersArr = (function() {
95
96
  var l, len1, results;
96
97
  results = [];
@@ -100,11 +101,21 @@ let initDRPivotTable = function($, window, document) {
100
101
  }
101
102
  return results;
102
103
  }).call(this);
104
+
103
105
  return function(a, b) {
104
106
  var comparison, i, sorter;
105
107
  for (i in sortersArr) {
106
- sorter = sortersArr[i];
107
- comparison = sorter(a[i], b[i]);
108
+ const index = parseInt(i);
109
+ sorter = sortersArr[index];
110
+ if (sortByValueAttrs.indexOf(attrs[index]) !== -1) {
111
+
112
+ // For case current Field attrs[index] is sorted by value we are concatenating values passed to sorter function
113
+ // Concatenation is done from first field in a block (first axis or first series) until current field index.
114
+ // Cause for this case sorting will be as list of these concatenated strings (which is prepared in getSortingByValueOrderList)
115
+ comparison = sorter(a.slice(0, index + 1).join(','), b.slice(0, index + 1).join(','));
116
+ } else {
117
+ comparison = sorter(a[index], b[index]);
118
+ }
108
119
  if (comparison !== 0) {
109
120
  return comparison;
110
121
  }
@@ -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
  };
@@ -1460,6 +1467,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1460
1467
  totalSeries.color = colors[i];
1461
1468
  }
1462
1469
 
1470
+ if (!lodash.isEmpty(pivotData.colTotals)) {
1463
1471
  col_n_keys.forEach(columnKey => {
1464
1472
  let key = columnKey;
1465
1473
  let totalKey = columnKey;
@@ -1470,6 +1478,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1470
1478
  const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
1471
1479
  totalSeries.data.push({name: lodash.unescape(key), y: value});
1472
1480
  });
1481
+ } else {
1482
+ lodash.forEach(row_n_keys, (rowKey, index) => {
1483
+ let key = rowKey;
1484
+ let totalKey = rowKey;
1485
+ if (lodash.isArray(rowKey)) {
1486
+ key = col_n_keys[index];
1487
+ totalKey = totalKey.join(highchartsRenderer.delimer);
1488
+ }
1489
+ const value = pivotData.rowTotals[totalKey] ? pivotData.rowTotals[totalKey].value() : 0;
1490
+ totalSeries.data.push({name: lodash.unescape(key), y: value});
1491
+ });
1492
+ }
1473
1493
 
1474
1494
  chart_series.push(totalSeries);
1475
1495
  }
@@ -3870,6 +3890,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3870
3890
 
3871
3891
  highchartsRenderer.rhPivotCount = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
3872
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
+
3873
3898
  return function (data, rowKey, colKey) {
3874
3899
  return {
3875
3900
  sum: 0,
@@ -3881,6 +3906,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3881
3906
  calculated_formats: calculated_info.formats,
3882
3907
  isChangeable: false,
3883
3908
  push: function (record) {
3909
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
3910
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
3911
+ }
3912
+
3884
3913
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
3885
3914
  this.data_types = this.data_types.concat(record['data_types']);
3886
3915
  this.data_types = lodash.uniq(this.data_types);
@@ -3925,7 +3954,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3925
3954
  number_format = 'General';
3926
3955
  }
3927
3956
 
3928
- 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) {
3929
3962
  number_format = this.widget_values_format;
3930
3963
  }
3931
3964
 
@@ -4013,6 +4046,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4013
4046
 
4014
4047
  highchartsRenderer.rhPivotAggregatorSum = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4015
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
+
4016
4054
  return function (data, rowKey, colKey) {
4017
4055
  return {
4018
4056
  sum: 0,
@@ -4033,7 +4071,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4033
4071
  }
4034
4072
  }
4035
4073
  var val = parseFloat(record[attr]);
4074
+
4036
4075
  if (!isNaN(val)) {
4076
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4077
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4078
+ }
4037
4079
 
4038
4080
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4039
4081
  this.data_types = this.data_types.concat(record['data_types']);
@@ -4080,13 +4122,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4080
4122
  number_format = 'General';
4081
4123
  }
4082
4124
 
4083
- if (this.widget_values_format) {
4125
+ if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4084
4126
  number_format = this.widget_values_format;
4085
4127
  }
4086
4128
 
4129
+ if (isCustomValuesFormat) {
4130
+ number_format = this.widget_values_format;
4131
+ }
4087
4132
  number_format = highchartsRenderer.getCalculatedValueFormat(this.calculated_formats, rowKey, colKey) || number_format;
4088
-
4089
4133
  var formated_value = highchartsRenderer.formatValue('n', number_format, x)
4134
+
4090
4135
  if (formated_value && formated_value.hasOwnProperty('value') && formated_value.value != null) {
4091
4136
  return formated_value.value;
4092
4137
  } else {
@@ -4101,6 +4146,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4101
4146
 
4102
4147
  highchartsRenderer.rhPivotAggregatorMin = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4103
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
+
4104
4154
  return function (data, rowKey, colKey) {
4105
4155
  return {
4106
4156
  val: null,
@@ -4124,6 +4174,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4124
4174
  var ref, x;
4125
4175
  x = parseFloat(record[attr]);
4126
4176
  if (!isNaN(x)) {
4177
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4178
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4179
+ }
4180
+
4127
4181
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4128
4182
  this.data_types = this.data_types.concat(record['data_types']);
4129
4183
  this.data_types = lodash.uniq(this.data_types);
@@ -4166,7 +4220,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4166
4220
  number_format = 'General';
4167
4221
  }
4168
4222
 
4169
- 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) {
4170
4228
  number_format = this.widget_values_format;
4171
4229
  }
4172
4230
 
@@ -4187,6 +4245,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4187
4245
 
4188
4246
  highchartsRenderer.rhPivotAggregatorMax = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4189
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
+
4190
4253
  return function (data, rowKey, colKey) {
4191
4254
  return {
4192
4255
  val: null,
@@ -4210,6 +4273,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4210
4273
  var ref, x;
4211
4274
  x = parseFloat(record[attr]);
4212
4275
  if (!isNaN(x)) {
4276
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4277
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4278
+ }
4279
+
4213
4280
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4214
4281
  this.data_types = this.data_types.concat(record['data_types']);
4215
4282
  this.data_types = lodash.uniq(this.data_types);
@@ -4253,7 +4320,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4253
4320
  number_format = 'General';
4254
4321
  }
4255
4322
 
4256
- 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) {
4257
4328
  number_format = this.widget_values_format;
4258
4329
  }
4259
4330
 
@@ -4274,6 +4345,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4274
4345
 
4275
4346
  highchartsRenderer.rhPivotAggregatorAverage = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4276
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
+
4277
4353
  return function (data, rowKey, colKey) {
4278
4354
  return {
4279
4355
  sum: 0,
@@ -4298,6 +4374,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4298
4374
  var ref, x;
4299
4375
  x = parseFloat(record[attr]);
4300
4376
  if (!isNaN(x)) {
4377
+ if (highchartsRenderer.enabledNewWidgetValueFormatting) {
4378
+ record.formats = highchartsRenderer.getRecordFormats(render_options, record['DR_Values']);
4379
+ }
4380
+
4301
4381
  if (record.hasOwnProperty('data_types') && $.isArray(record['data_types'])) {
4302
4382
  this.data_types = this.data_types.concat(record['data_types']);
4303
4383
  this.data_types = lodash.uniq(this.data_types);
@@ -4347,7 +4427,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4347
4427
  number_format = 'General';
4348
4428
  }
4349
4429
 
4350
- 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) {
4351
4435
  number_format = this.widget_values_format;
4352
4436
  }
4353
4437
 
@@ -4408,72 +4492,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4408
4492
  return ret_str;
4409
4493
  };
4410
4494
 
4411
- highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
4412
- let rowAttrs, rowKeys, colKeys, colAttrs;
4413
- rowAttrs = pivotData.rowAttrs;
4414
- rowKeys = pivotData.rowKeys;
4415
- colKeys = pivotData.colKeys;
4416
- colAttrs = pivotData.colAttrs;
4417
-
4418
-
4419
- if (!colAttrs || colAttrs.length == 0) {
4420
- return null;
4421
- }
4422
-
4495
+ highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex, widget) {
4423
4496
  let values_names_arr = [];
4424
- let keysArray = sortingOptions.field ? rowKeys : colKeys;
4425
-
4426
4497
  lodash.forEach(keysArray, function (val) {
4427
- let firstArray = sortingOptions.field ? [val[0]] : [];
4428
- let secondArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4429
- let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4430
-
4431
- if (aggregator_subtotal) {
4432
- let value_subtotal = aggregator_subtotal.value();
4433
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4434
- value_subtotal = Math.abs(value_subtotal);
4435
- }
4436
- values_names_arr.push({name: val[0], value: value_subtotal});
4437
- }
4438
- });
4439
-
4440
- // ORDERING
4441
- let sorting_vector = ['asc'];
4442
- if (sortingOptions && sortingOptions.type == 'largestToSmallest') {
4443
- sorting_vector = ['desc'];
4444
- }
4445
- values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4446
-
4447
- // map only names
4448
- let attr_sorted_values = lodash.map(values_names_arr, 'name');
4449
- return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
4450
- };
4451
-
4452
- highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
4453
- let rowAttrs, rowKeys, colKeys, colAttrs;
4454
- rowAttrs = pivotData.rowAttrs;
4455
- rowKeys = pivotData.rowKeys;
4456
- colKeys = pivotData.colKeys;
4457
- colAttrs = pivotData.colAttrs;
4498
+ const firstArray = [];
4499
+ const secondArray = val.slice(0, fieldIndex + 1);
4500
+
4501
+ let valueForComparison;
4502
+ if (sortingOptions.sort_by === 'variance') {
4503
+ const varianceConfig = widget.options.chartOptions.delta_column;
4504
+ const data = pivotData.input;
4505
+ const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
4506
+ const varianceRowsForCurrentKey = lodash.filter(data, row =>
4507
+ row[varianceField.name] === varianceConfig.name
4508
+ && lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
4509
+ );
4458
4510
 
4459
- if (!rowAttrs || rowAttrs.length == 0) {
4460
- return null;
4461
- }
4511
+ valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
4512
+ } else {
4513
+ let getAggregatorParams = [firstArray, secondArray];
4462
4514
 
4463
- let values_names_arr = [];
4464
- let keysArray = sortingOptions.field ? colKeys : rowKeys;
4515
+ if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4516
+ getAggregatorParams = lodash.reverse(getAggregatorParams);
4517
+ }
4518
+
4519
+ let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4465
4520
 
4466
- lodash.forEach(keysArray, function (val) {
4467
- let firstArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4468
- let secondArray = sortingOptions.field ? [val[0]] : [];
4469
- let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4521
+ if (aggregator_subtotal) {
4522
+ valueForComparison = aggregator_subtotal.value();
4523
+ }
4524
+ }
4470
4525
 
4471
- if (aggregator_subtotal) {
4472
- let value_subtotal = aggregator_subtotal.value();
4473
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4474
- value_subtotal = Math.abs(value_subtotal);
4526
+ if (!lodash.isNil(valueForComparison)) {
4527
+ if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(valueForComparison))) {
4528
+ valueForComparison = Math.abs(valueForComparison);
4475
4529
  }
4476
- values_names_arr.push({name: val[0], value: value_subtotal});
4530
+ values_names_arr.push({name: secondArray.join(','), value: valueForComparison});
4477
4531
  }
4478
4532
  });
4479
4533
 
@@ -4485,36 +4539,33 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4485
4539
  values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4486
4540
 
4487
4541
  // map only names
4488
- let attr_sorted_values = lodash.map(values_names_arr, 'name');
4489
- return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
4542
+ return lodash.map(values_names_arr, 'name');
4490
4543
  };
4491
4544
 
4492
- highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
4493
- let new_map;
4494
- let axis = highchartsRenderer.getAxis(sortingOptions.axis, opts);
4495
- if (axis == 'col_total') {
4496
- new_map = highchartsRenderer.getNewAttrSortingForCol(pivotData, sortingOptions);
4497
- } else if (axis == 'row_total') {
4498
- new_map = highchartsRenderer.getNewAttrSortingForRow(pivotData, sortingOptions);
4499
- }
4500
-
4545
+ highchartsRenderer.generateSortingFunctionByValues = function (sortByValueSettings, pivotData, opts, widget) {
4501
4546
  let old_sorters_function = opts.sorters;
4502
4547
  if (!old_sorters_function) {
4503
4548
  old_sorters_function = function () {
4504
4549
  };
4505
4550
  }
4506
- if (new_map) {
4507
- var sortAs = $.pivotUtilities.sortAs;
4508
- let new_sorters_function = function (attr) {
4509
- if (new_map.name == attr) {
4510
- return $.pivotUtilities.sortAs(new_map.values);
4511
- } else {
4512
- return old_sorters_function(attr);
4513
- }
4551
+ return function (attr) {
4552
+ const sortingOptions = lodash.find(sortByValueSettings, fieldSorting => fieldSorting.name === attr);
4553
+ if (sortingOptions) {
4554
+ const axis = highchartsRenderer.getAxis(_.includes(pivotData.colAttrs, attr) ? 'col_total' : 'row_total', opts);
4555
+ const isColumnSort = axis === 'col_total';
4556
+ const fieldIndex = lodash.findIndex(isColumnSort ? pivotData.colAttrs : pivotData.rowAttrs, name => name === attr);
4557
+ const orderedNamesList = highchartsRenderer.getSortingByValueOrderList(
4558
+ pivotData,
4559
+ sortingOptions.sorting,
4560
+ pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
4561
+ pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
4562
+ fieldIndex,
4563
+ widget
4564
+ );
4565
+ return $.pivotUtilities.sortAs(orderedNamesList);
4566
+ } else {
4567
+ return old_sorters_function(attr);
4514
4568
  }
4515
- return new_sorters_function;
4516
- } else {
4517
- return old_sorters_function;
4518
4569
  }
4519
4570
  };
4520
4571
 
@@ -4718,6 +4769,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4718
4769
  result = null;
4719
4770
  try {
4720
4771
  pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
4772
+ pivotData.sortByValueAttrs = [];
4721
4773
  try {
4722
4774
  if (options && options.onlyOptions) {
4723
4775
  if (!opts.rendererOptions) {
@@ -4725,9 +4777,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4725
4777
  }
4726
4778
  opts.rendererOptions.onlyOptions = true;
4727
4779
  }
4728
- var totalFilters = lodash.get(opts, 'rendererOptions.total_value_options', null);
4729
- if (totalFilters && totalFilters.sorting_options) {
4730
- let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(totalFilters.sorting_options, pivotData, opts);
4780
+
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);
4731
4789
  opts.sorters = new_sorting_function;
4732
4790
  optsFiltered.sorters = new_sorting_function;
4733
4791
  pivotData.sorters = new_sorting_function;
@@ -7084,18 +7142,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7084
7142
  value_name: 'is_percentage',
7085
7143
  default_value: false,
7086
7144
  hidden: true,
7087
- }, {
7088
- element_type: 'checkbox',
7089
- element_label: 'Sort by variance',
7090
- value_name: 'sort_by_variance',
7091
- default_value: false,
7092
- hidden: true
7093
- }, {
7094
- element_type: 'checkbox',
7095
- element_label: 'Sort by absolute variance',
7096
- value_name: 'sort_by_absolute_variance',
7097
- default_value: false,
7098
- hidden: true
7099
7145
  }]
7100
7146
  },
7101
7147
  'delta_column_for_drill_down': {
@@ -7162,18 +7208,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7162
7208
  value_name: 'is_percentage',
7163
7209
  default_value: false,
7164
7210
  hidden: true,
7165
- }, {
7166
- element_type: 'checkbox',
7167
- element_label: 'Sort by variance',
7168
- value_name: 'sort_by_variance',
7169
- default_value: false,
7170
- hidden: true
7171
- }, {
7172
- element_type: 'checkbox',
7173
- element_label: 'Sort by absolute variance',
7174
- value_name: 'sort_by_absolute_variance',
7175
- default_value: false,
7176
- hidden: true
7177
7211
  }, {
7178
7212
  element_type: 'checkbox',
7179
7213
  element_label: 'Filter zero values',
@@ -8690,7 +8724,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8690
8724
  const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8691
8725
  if (isCustomSorting) {
8692
8726
  lodash.forEach(datesFields, function (field) {
8693
- const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8727
+ const fieldToSort = lodash.find(
8728
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8729
+ );
8694
8730
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8695
8731
  });
8696
8732
  }
@@ -8772,7 +8808,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8772
8808
  });
8773
8809
  } else if (isCustomSorting) {
8774
8810
  lodash.forEach(rowsAndCols, function (field) {
8775
- const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8811
+ const fieldToSort = lodash.find(
8812
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8813
+ );
8776
8814
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8777
8815
  });
8778
8816
  }
@@ -8807,61 +8845,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8807
8845
  }
8808
8846
 
8809
8847
  /****** END *******/
8810
-
8811
- if (lodash.has(widget, "options.chartOptions.delta_column") &&
8812
- widget.options.chartOptions.delta_column.field != '' &&
8813
- (widget.options.chartOptions.delta_column.sort_by_variance ||
8814
- widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
8815
- widget.rows.length > 0 &&
8816
- widget.cols.length > 0 &&
8817
- widget.vals.length
8818
- ) {
8819
- let variance_config = widget.options.chartOptions.delta_column;
8820
- let val_field = widget.vals[0];
8821
- let field_for_sorting = null;
8822
- let field_with_variant = null;
8823
- if (variance_config.field == "series") {
8824
- field_for_sorting = widget.cols[0];
8825
- field_with_variant = widget.rows[0];
8826
- } else if (variance_config.field == "category") {
8827
- field_for_sorting = widget.rows[0];
8828
- field_with_variant = widget.cols[0];
8829
- }
8830
-
8831
- let data_sorted = lodash.filter(data, function (data_row) {
8832
- return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
8833
- });
8834
-
8835
- const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
8836
-
8837
- if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
8838
- data_sorted = lodash.sortBy(data_sorted, function (o) {
8839
- if (sorting_variance === 'desc') {
8840
- return Math.abs(o[val_field.name]) * -1;
8841
- }
8842
-
8843
- return Math.abs(o[val_field.name]) * 1;
8844
- });
8845
- } else {
8846
- data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
8847
- }
8848
-
8849
- let values_for_sort = lodash.map(data_sorted, function (data_row) {
8850
- return data_row[field_for_sorting.name];
8851
- });
8852
-
8853
- values_for_sort = lodash.uniq(values_for_sort);
8854
-
8855
- if (values_for_sort.length > 0) {
8856
- let field = lodash.find(datesFields, {name: field_for_sorting.name});
8857
- if (field) {
8858
- field.values = values_for_sort;
8859
- field.sorting = null;
8860
- } else {
8861
- datesFields.push({name: field_for_sorting.name, values: values_for_sort});
8862
- }
8863
- }
8864
- } else if (widget.options && widget.options.sortingValues) {
8848
+
8849
+ // TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
8850
+ if (widget.options && widget.options.sortingValues) {
8865
8851
  var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8866
8852
  if (field) {
8867
8853
  field.values = widget.options.sortingValues.values;
@@ -9281,6 +9267,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9281
9267
  }
9282
9268
  }
9283
9269
 
9270
+ highchartsRenderer.checkFormats = function(render_options, widget_values_format) {
9271
+ const isSecondaryAxis = lodash.some(render_options.comboOptions?.seriesOptions, series => series?.secondaryAxis);
9272
+ const formats = lodash.map(render_options.comboOptions?.seriesOptions, series => series.format);
9273
+ const isCustomFormat = !lodash.includes(formats, widget_values_format);
9274
+
9275
+ return { isSecondaryAxis, isCustomFormat }
9276
+ }
9277
+
9278
+ highchartsRenderer.getRecordFormats = function(render_options, recordName) {
9279
+ return render_options?.comboOptions?.seriesOptions
9280
+ .filter(series => series.series === recordName)
9281
+ .map(series => series.format);
9282
+ }
9283
+
9284
+ highchartsRenderer.isCustomValuesFormat = function (render_options, widget_values_format) {
9285
+ const { isSecondaryAxis, isCustomFormat } = highchartsRenderer.checkFormats(render_options, widget_values_format);
9286
+ return highchartsRenderer.enabledNewWidgetValueFormatting && (isCustomFormat || !isSecondaryAxis);
9287
+ }
9288
+
9284
9289
  return highchartsRenderer;
9285
9290
  };
9286
9291
 
package/src/pivottable.js CHANGED
@@ -577,6 +577,7 @@ let initPivotTable = function($, window, document) {
577
577
  l_mapping = {};
578
578
  for (i in order) {
579
579
  x = order[i];
580
+ if (order[i] === null) x = '[null]';
580
581
  mapping[x] = i;
581
582
  if (typeof x === "string") {
582
583
  l_mapping[x.toLowerCase()] = i;