@datarailsshared/dr_renderer 1.2.302-dragons → 1.2.304

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.302-dragons",
3
+ "version": "1.2.304",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -91,7 +91,6 @@ let initDRPivotTable = function($, window, document) {
91
91
 
92
92
  DRPivotData.prototype.arrSort = function(attrs) {
93
93
  var a, sortersArr;
94
- const sortByValueAttrs = this.sortByValueAttrs;
95
94
  sortersArr = (function() {
96
95
  var l, len1, results;
97
96
  results = [];
@@ -101,16 +100,11 @@ let initDRPivotTable = function($, window, document) {
101
100
  }
102
101
  return results;
103
102
  }).call(this);
104
-
105
103
  return function(a, b) {
106
104
  var comparison, i, sorter;
107
105
  for (i in sortersArr) {
108
106
  sorter = sortersArr[i];
109
- if (sortByValueAttrs.indexOf(attrs[parseInt(i)]) !== -1) {
110
- comparison = sorter(a.slice(0, parseInt(i) + 1).join(','), b.slice(0, parseInt(i) + 1).join(','));
111
- } else {
112
- comparison = sorter(a[i], b[i]);
113
- }
107
+ comparison = sorter(a[i], b[i]);
114
108
  if (comparison !== 0) {
115
109
  return comparison;
116
110
  }
@@ -81,11 +81,6 @@ const HIGHCHARTS_CONSTANTS = {
81
81
  MAX_SELECTED_ITEMS_CHARECHTERS_IN_LABEL: 50,
82
82
  }
83
83
 
84
- const SUBOPTIONS_FONT_SIZE_VALUES = (new Array(19).fill(null).map(function (item, index) {
85
- const fontValue = index + 6;
86
- return { label: fontValue, value: fontValue }
87
- }));
88
-
89
84
  const SUBOPTIONS_FONTS = [
90
85
  'Arial',
91
86
  'Arial Black',
@@ -694,7 +689,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
694
689
  setTimeout(() => {
695
690
  var aggr = highchartsRenderer.defaultFormatterToTooltip(pivotData, opts);
696
691
  const formatted_value_to_return = aggr.bind(this)();
697
- opts.insightsTooltipFunc({...this, formatted_value_to_return, ...insight});
692
+ opts.insightsTooltipFunc(lodash.merge(lodash.cloneDeep(this), { formatted_value_to_return }, insight));
698
693
  });
699
694
  }
700
695
  }
@@ -1155,7 +1150,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1155
1150
  ob.name = row_n_value.join(highchartsRenderer.delimer)
1156
1151
  .replace(highchartsRenderer.DR_OTHERS_KEY, othersName);
1157
1152
  }
1158
-
1159
1153
  lodash.forEach(col_n_keys, function (col_n_value, index) {
1160
1154
  var agg = pivotData.getAggregator(row_n_value, col_n_value);
1161
1155
  var val = agg.value();
@@ -1397,7 +1391,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1397
1391
  if (opts.trendLine) {
1398
1392
  const a = ((ySum * squareXSum) - (xSum * xySum)) / ((n * squareXSum) - (xSum * xSum));
1399
1393
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
1400
-
1401
1394
  const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
1402
1395
  trendSeries.className = 'trendSeries';
1403
1396
  trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
@@ -1408,7 +1401,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1408
1401
  if (colors && colors[i]) {
1409
1402
  trendSeries.color = colors[i];
1410
1403
  }
1411
-
1412
1404
  trendSerieses.push(trendSeries);
1413
1405
  }
1414
1406
  i++;
@@ -1425,7 +1417,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1425
1417
  }
1426
1418
 
1427
1419
  let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
1428
-
1429
1420
  if (opts.comboOptions && lodash.includes(chartType,'combo') && !lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
1430
1421
  chart_series.forEach((series, seriesIndex) => {
1431
1422
  const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
@@ -4397,42 +4388,72 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4397
4388
  return ret_str;
4398
4389
  };
4399
4390
 
4400
- highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex, widget) {
4401
- let values_names_arr = [];
4402
- lodash.forEach(keysArray, function (val) {
4403
- const firstArray = [];
4404
- const secondArray = val.slice(0, fieldIndex + 1);
4405
-
4406
- let valueForComparison;
4407
- if (sortingOptions.sort_by === 'variance') {
4408
- const varianceConfig = widget.options.chartOptions.delta_column;
4409
- const data = pivotData.input;
4410
- const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
4411
- const varianceRowsForCurrentKey = lodash.filter(data, row =>
4412
- row[varianceField.name] === varianceConfig.name
4413
- && lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
4414
- );
4391
+ highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
4392
+ let rowAttrs, rowKeys, colKeys, colAttrs;
4393
+ rowAttrs = pivotData.rowAttrs;
4394
+ rowKeys = pivotData.rowKeys;
4395
+ colKeys = pivotData.colKeys;
4396
+ colAttrs = pivotData.colAttrs;
4415
4397
 
4416
- valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
4417
- } else {
4418
- let getAggregatorParams = [firstArray, secondArray];
4419
4398
 
4420
- if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4421
- getAggregatorParams = lodash.reverse(getAggregatorParams);
4422
- }
4423
-
4424
- let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4399
+ if (!colAttrs || colAttrs.length == 0) {
4400
+ return null;
4401
+ }
4402
+
4403
+ let values_names_arr = [];
4404
+ let keysArray = sortingOptions.field ? rowKeys : colKeys;
4425
4405
 
4426
- if (aggregator_subtotal) {
4427
- valueForComparison = aggregator_subtotal.value();
4406
+ lodash.forEach(keysArray, function (val) {
4407
+ let firstArray = sortingOptions.field ? [val[0]] : [];
4408
+ let secondArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4409
+ let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4410
+
4411
+ if (aggregator_subtotal) {
4412
+ let value_subtotal = aggregator_subtotal.value();
4413
+ if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4414
+ value_subtotal = Math.abs(value_subtotal);
4428
4415
  }
4416
+ values_names_arr.push({name: val[0], value: value_subtotal});
4429
4417
  }
4418
+ });
4430
4419
 
4431
- if (typeof valueForComparison !== 'undefined') {
4432
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(valueForComparison))) {
4433
- valueForComparison = Math.abs(valueForComparison);
4420
+ // ORDERING
4421
+ let sorting_vector = ['asc'];
4422
+ if (sortingOptions && sortingOptions.type == 'largestToSmallest') {
4423
+ sorting_vector = ['desc'];
4424
+ }
4425
+ values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4426
+
4427
+ // map only names
4428
+ let attr_sorted_values = lodash.map(values_names_arr, 'name');
4429
+ return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
4430
+ };
4431
+
4432
+ highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
4433
+ let rowAttrs, rowKeys, colKeys, colAttrs;
4434
+ rowAttrs = pivotData.rowAttrs;
4435
+ rowKeys = pivotData.rowKeys;
4436
+ colKeys = pivotData.colKeys;
4437
+ colAttrs = pivotData.colAttrs;
4438
+
4439
+ if (!rowAttrs || rowAttrs.length == 0) {
4440
+ return null;
4441
+ }
4442
+
4443
+ let values_names_arr = [];
4444
+ let keysArray = sortingOptions.field ? colKeys : rowKeys;
4445
+
4446
+ lodash.forEach(keysArray, function (val) {
4447
+ let firstArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4448
+ let secondArray = sortingOptions.field ? [val[0]] : [];
4449
+ let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4450
+
4451
+ if (aggregator_subtotal) {
4452
+ let value_subtotal = aggregator_subtotal.value();
4453
+ if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4454
+ value_subtotal = Math.abs(value_subtotal);
4434
4455
  }
4435
- values_names_arr.push({name: secondArray.join(','), value: valueForComparison});
4456
+ values_names_arr.push({name: val[0], value: value_subtotal});
4436
4457
  }
4437
4458
  });
4438
4459
 
@@ -4444,33 +4465,36 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4444
4465
  values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4445
4466
 
4446
4467
  // map only names
4447
- return lodash.map(values_names_arr, 'name');
4468
+ let attr_sorted_values = lodash.map(values_names_arr, 'name');
4469
+ return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
4448
4470
  };
4449
4471
 
4450
- highchartsRenderer.generateSortingFunctionByValues = function (sortByValueSettings, pivotData, opts, widget) {
4472
+ highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
4473
+ let new_map;
4474
+ let axis = highchartsRenderer.getAxis(sortingOptions.axis, opts);
4475
+ if (axis == 'col_total') {
4476
+ new_map = highchartsRenderer.getNewAttrSortingForCol(pivotData, sortingOptions);
4477
+ } else if (axis == 'row_total') {
4478
+ new_map = highchartsRenderer.getNewAttrSortingForRow(pivotData, sortingOptions);
4479
+ }
4480
+
4451
4481
  let old_sorters_function = opts.sorters;
4452
4482
  if (!old_sorters_function) {
4453
4483
  old_sorters_function = function () {
4454
4484
  };
4455
4485
  }
4456
- return function (attr) {
4457
- const sortingOptions = lodash.find(sortByValueSettings, fieldSorting => fieldSorting.name === attr);
4458
- if (sortingOptions) {
4459
- const axis = highchartsRenderer.getAxis(_.includes(pivotData.colAttrs, attr) ? 'col_total' : 'row_total', opts);
4460
- const isColumnSort = axis === 'col_total';
4461
- const fieldIndex = lodash.findIndex(isColumnSort ? pivotData.colAttrs : pivotData.rowAttrs, name => name === attr);
4462
- const orderedNamesList = highchartsRenderer.getSortingByValueOrderList(
4463
- pivotData,
4464
- sortingOptions.sorting,
4465
- pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
4466
- pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
4467
- fieldIndex,
4468
- widget
4469
- );
4470
- return $.pivotUtilities.sortAs(orderedNamesList);
4471
- } else {
4472
- return old_sorters_function(attr);
4486
+ if (new_map) {
4487
+ var sortAs = $.pivotUtilities.sortAs;
4488
+ let new_sorters_function = function (attr) {
4489
+ if (new_map.name == attr) {
4490
+ return $.pivotUtilities.sortAs(new_map.values);
4491
+ } else {
4492
+ return old_sorters_function(attr);
4493
+ }
4473
4494
  }
4495
+ return new_sorters_function;
4496
+ } else {
4497
+ return old_sorters_function;
4474
4498
  }
4475
4499
  };
4476
4500
 
@@ -4674,7 +4698,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4674
4698
  result = null;
4675
4699
  try {
4676
4700
  pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
4677
- pivotData.sortByValueAttrs = [];
4678
4701
  try {
4679
4702
  if (options && options.onlyOptions) {
4680
4703
  if (!opts.rendererOptions) {
@@ -4682,15 +4705,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4682
4705
  }
4683
4706
  opts.rendererOptions.onlyOptions = true;
4684
4707
  }
4685
-
4686
- const sortByValueSettings = lodash.filter(
4687
- lodash.get(widget, 'options.sortingFields', []),
4688
- sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
4689
- );
4690
-
4691
- if (sortByValueSettings.length) {
4692
- pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
4693
- let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
4708
+ var totalFilters = lodash.get(opts, 'rendererOptions.total_value_options', null);
4709
+ if (totalFilters && totalFilters.sorting_options) {
4710
+ let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(totalFilters.sorting_options, pivotData, opts);
4694
4711
  opts.sorters = new_sorting_function;
4695
4712
  optsFiltered.sorters = new_sorting_function;
4696
4713
  pivotData.sorters = new_sorting_function;
@@ -4955,7 +4972,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4955
4972
  const fiscalYearMonthsModifier = highchartsRenderer.getFiscalYearMonthModifier();
4956
4973
 
4957
4974
  let date = moment_lib(tryParse).utcOffset(0);
4958
- if (['quarter', 'year'].includes(timeframe)) {
4975
+ if (lodash.includes(['quarter', 'year'], timeframe)) {
4959
4976
  date = date.subtract(fiscalYearMonthsModifier, 'M');
4960
4977
  }
4961
4978
 
@@ -5993,6 +6010,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5993
6010
 
5994
6011
  highchartsRenderer.widgetPlaceholders = lodash.assign({}, $.pivotUtilities.errorHandling.placeholders);
5995
6012
 
6013
+ const suboptionsFontSizeValues = (lodash.map(lodash.fill(new Array(19), null), function (item, index) {
6014
+ const fontValue = index + 6;
6015
+ return { label: fontValue, value: fontValue }
6016
+ }));
6017
+
5996
6018
  highchartsRenderer.suboptions = {
5997
6019
  'widget_library': {
5998
6020
  is_hidden: true,
@@ -6154,7 +6176,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6154
6176
  element_type: 'select',
6155
6177
  value_name: 'columns_font_size',
6156
6178
  element_label: 'Font size',
6157
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6179
+ element_options: suboptionsFontSizeValues,
6158
6180
  default_value: '10'
6159
6181
  },
6160
6182
  {
@@ -6183,7 +6205,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6183
6205
  element_type: 'select',
6184
6206
  value_name: 'rows_font_size',
6185
6207
  element_label: 'Font size',
6186
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6208
+ element_options: suboptionsFontSizeValues,
6187
6209
  default_value: '10'
6188
6210
  },
6189
6211
  {
@@ -6212,7 +6234,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6212
6234
  element_type: 'select',
6213
6235
  value_name: 'values_font_size',
6214
6236
  element_label: 'Font size',
6215
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6237
+ element_options: suboptionsFontSizeValues,
6216
6238
  default_value: '10'
6217
6239
  },
6218
6240
  {
@@ -6241,7 +6263,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6241
6263
  element_type: 'select',
6242
6264
  value_name: 'totals_font_size',
6243
6265
  element_label: 'Font size',
6244
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6266
+ element_options: suboptionsFontSizeValues,
6245
6267
  default_value: '10'
6246
6268
  },
6247
6269
  {
@@ -6517,7 +6539,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6517
6539
  element_type: 'select',
6518
6540
  value_name: 'font_size',
6519
6541
  element_label: 'Font size',
6520
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6542
+ element_options: suboptionsFontSizeValues,
6521
6543
  default_value: LABEL_DEFAULT_SETTINGS.FONT_SIZE,
6522
6544
  },
6523
6545
  {
@@ -6595,7 +6617,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6595
6617
  element_type: 'select',
6596
6618
  value_name: 'font_size',
6597
6619
  element_label: 'Font size',
6598
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6620
+ element_options: suboptionsFontSizeValues,
6599
6621
  default_value: LABEL_DEFAULT_SETTINGS.FONT_SIZE,
6600
6622
  },
6601
6623
  {
@@ -6672,7 +6694,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6672
6694
  element_type: 'select',
6673
6695
  value_name: 'font_size',
6674
6696
  element_label: 'Font size',
6675
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6697
+ element_options: suboptionsFontSizeValues,
6676
6698
  default_value: LABEL_DEFAULT_SETTINGS.FONT_SIZE,
6677
6699
  },
6678
6700
  {
@@ -6841,7 +6863,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6841
6863
  element_type: 'select',
6842
6864
  value_name: 'font_size',
6843
6865
  element_label: 'Font size',
6844
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6866
+ element_options: suboptionsFontSizeValues,
6845
6867
  default_value: TOOLTIP_DEFAULT_SETTINGS.FONT_SIZE,
6846
6868
  },
6847
6869
  {
@@ -6931,7 +6953,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6931
6953
  element_type: 'select',
6932
6954
  value_name: 'font_size',
6933
6955
  element_label: 'Font size',
6934
- element_options: SUBOPTIONS_FONT_SIZE_VALUES,
6956
+ element_options: suboptionsFontSizeValues,
6935
6957
  default_value: TOOLTIP_DEFAULT_SETTINGS.FONT_SIZE,
6936
6958
  },
6937
6959
  {
@@ -7036,6 +7058,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7036
7058
  value_name: 'is_percentage',
7037
7059
  default_value: false,
7038
7060
  hidden: true,
7061
+ }, {
7062
+ element_type: 'checkbox',
7063
+ element_label: 'Sort by variance',
7064
+ value_name: 'sort_by_variance',
7065
+ default_value: false,
7066
+ hidden: true
7067
+ }, {
7068
+ element_type: 'checkbox',
7069
+ element_label: 'Sort by absolute variance',
7070
+ value_name: 'sort_by_absolute_variance',
7071
+ default_value: false,
7072
+ hidden: true
7039
7073
  }]
7040
7074
  },
7041
7075
  'delta_column_for_drill_down': {
@@ -7102,6 +7136,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7102
7136
  value_name: 'is_percentage',
7103
7137
  default_value: false,
7104
7138
  hidden: true,
7139
+ }, {
7140
+ element_type: 'checkbox',
7141
+ element_label: 'Sort by variance',
7142
+ value_name: 'sort_by_variance',
7143
+ default_value: false,
7144
+ hidden: true
7145
+ }, {
7146
+ element_type: 'checkbox',
7147
+ element_label: 'Sort by absolute variance',
7148
+ value_name: 'sort_by_absolute_variance',
7149
+ default_value: false,
7150
+ hidden: true
7105
7151
  }, {
7106
7152
  element_type: 'checkbox',
7107
7153
  element_label: 'Filter zero values',
@@ -8618,9 +8664,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8618
8664
  const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8619
8665
  if (isCustomSorting) {
8620
8666
  lodash.forEach(datesFields, function (field) {
8621
- const fieldToSort = lodash.find(
8622
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8623
- );
8667
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8624
8668
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8625
8669
  });
8626
8670
  }
@@ -8702,9 +8746,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8702
8746
  });
8703
8747
  } else if (isCustomSorting) {
8704
8748
  lodash.forEach(rowsAndCols, function (field) {
8705
- const fieldToSort = lodash.find(
8706
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8707
- );
8749
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8708
8750
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8709
8751
  });
8710
8752
  }
@@ -8739,9 +8781,61 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8739
8781
  }
8740
8782
 
8741
8783
  /****** END *******/
8742
-
8743
- // TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
8744
- if (widget.options && widget.options.sortingValues) {
8784
+
8785
+ if (lodash.has(widget, "options.chartOptions.delta_column") &&
8786
+ widget.options.chartOptions.delta_column.field != '' &&
8787
+ (widget.options.chartOptions.delta_column.sort_by_variance ||
8788
+ widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
8789
+ widget.rows.length > 0 &&
8790
+ widget.cols.length > 0 &&
8791
+ widget.vals.length
8792
+ ) {
8793
+ let variance_config = widget.options.chartOptions.delta_column;
8794
+ let val_field = widget.vals[0];
8795
+ let field_for_sorting = null;
8796
+ let field_with_variant = null;
8797
+ if (variance_config.field == "series") {
8798
+ field_for_sorting = widget.cols[0];
8799
+ field_with_variant = widget.rows[0];
8800
+ } else if (variance_config.field == "category") {
8801
+ field_for_sorting = widget.rows[0];
8802
+ field_with_variant = widget.cols[0];
8803
+ }
8804
+
8805
+ let data_sorted = lodash.filter(data, function (data_row) {
8806
+ return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
8807
+ });
8808
+
8809
+ const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
8810
+
8811
+ if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
8812
+ data_sorted = lodash.sortBy(data_sorted, function (o) {
8813
+ if (sorting_variance === 'desc') {
8814
+ return Math.abs(o[val_field.name]) * -1;
8815
+ }
8816
+
8817
+ return Math.abs(o[val_field.name]) * 1;
8818
+ });
8819
+ } else {
8820
+ data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
8821
+ }
8822
+
8823
+ let values_for_sort = lodash.map(data_sorted, function (data_row) {
8824
+ return data_row[field_for_sorting.name];
8825
+ });
8826
+
8827
+ values_for_sort = lodash.uniq(values_for_sort);
8828
+
8829
+ if (values_for_sort.length > 0) {
8830
+ let field = lodash.find(datesFields, {name: field_for_sorting.name});
8831
+ if (field) {
8832
+ field.values = values_for_sort;
8833
+ field.sorting = null;
8834
+ } else {
8835
+ datesFields.push({name: field_for_sorting.name, values: values_for_sort});
8836
+ }
8837
+ }
8838
+ } else if (widget.options && widget.options.sortingValues) {
8745
8839
  var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8746
8840
  if (field) {
8747
8841
  field.values = widget.options.sortingValues.values;