@datarailsshared/dr_renderer 1.2.316-dragons → 1.2.318-rocket

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.
@@ -1150,7 +1150,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1150
1150
  ob.name = row_n_value.join(highchartsRenderer.delimer)
1151
1151
  .replace(highchartsRenderer.DR_OTHERS_KEY, othersName);
1152
1152
  }
1153
-
1154
1153
  lodash.forEach(col_n_keys, function (col_n_value, index) {
1155
1154
  var agg = pivotData.getAggregator(row_n_value, col_n_value);
1156
1155
  var val = agg.value();
@@ -1392,7 +1391,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1392
1391
  if (opts.trendLine) {
1393
1392
  const a = ((ySum * squareXSum) - (xSum * xySum)) / ((n * squareXSum) - (xSum * xSum));
1394
1393
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
1395
-
1396
1394
  const trendSeries = lodash.clone(chart_series[chart_series.length - 1]);
1397
1395
  trendSeries.className = 'trendSeries';
1398
1396
  trendSeries.name = highchartsRenderer.getTrendSeriesName(trendSeries);
@@ -1403,7 +1401,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1403
1401
  if (colors && colors[i]) {
1404
1402
  trendSeries.color = colors[i];
1405
1403
  }
1406
-
1407
1404
  trendSerieses.push(trendSeries);
1408
1405
  }
1409
1406
  i++;
@@ -1420,7 +1417,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1420
1417
  }
1421
1418
 
1422
1419
  let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
1423
-
1424
1420
  if (opts.comboOptions && lodash.includes(chartType,'combo') && !lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
1425
1421
  chart_series.forEach((series, seriesIndex) => {
1426
1422
  const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
@@ -1464,7 +1460,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1464
1460
  totalSeries.color = colors[i];
1465
1461
  }
1466
1462
 
1467
- if (!lodash.isEmpty(pivotData.colTotals)) {
1468
1463
  col_n_keys.forEach(columnKey => {
1469
1464
  let key = columnKey;
1470
1465
  let totalKey = columnKey;
@@ -1475,18 +1470,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1475
1470
  const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
1476
1471
  totalSeries.data.push({name: lodash.unescape(key), y: value});
1477
1472
  });
1478
- } else {
1479
- lodash.forEach(row_n_keys, (rowKey, index) => {
1480
- let key = rowKey;
1481
- let totalKey = rowKey;
1482
- if (lodash.isArray(rowKey)) {
1483
- key = col_n_keys[index];
1484
- totalKey = totalKey.join(highchartsRenderer.delimer);
1485
- }
1486
- const value = pivotData.rowTotals[totalKey] ? pivotData.rowTotals[totalKey].value() : 0;
1487
- totalSeries.data.push({name: lodash.unescape(key), y: value});
1488
- });
1489
- }
1490
1473
 
1491
1474
  chart_series.push(totalSeries);
1492
1475
  }
@@ -1507,7 +1490,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1507
1490
  const chart_series = [];
1508
1491
  const row_n_keys = pivotData.getRowKeys();
1509
1492
  const col_n_keys = pivotData.getColKeys();
1510
- const rows_by_cols = pivotData.rowKeysByCols;
1511
1493
 
1512
1494
  let resultObject = {
1513
1495
  data: [],
@@ -1536,9 +1518,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1536
1518
  });
1537
1519
 
1538
1520
  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) {
1521
+ lodash.forEach(row_n_keys, function (row_n_value) {
1542
1522
  const agg = pivotData.getAggregator(row_n_value, col_n_value);
1543
1523
  let val = agg.value();
1544
1524
 
@@ -4428,42 +4408,72 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4428
4408
  return ret_str;
4429
4409
  };
4430
4410
 
4431
- highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex, widget) {
4432
- let values_names_arr = [];
4433
- lodash.forEach(keysArray, function (val) {
4434
- const firstArray = [];
4435
- const secondArray = val.slice(0, fieldIndex + 1);
4436
-
4437
- let valueForComparison;
4438
- if (sortingOptions.sort_by === 'variance') {
4439
- const varianceConfig = widget.options.chartOptions.delta_column;
4440
- const data = pivotData.input;
4441
- const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
4442
- const varianceRowsForCurrentKey = lodash.filter(data, row =>
4443
- row[varianceField.name] === varianceConfig.name
4444
- && lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
4445
- );
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;
4446
4417
 
4447
- valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
4448
- } else {
4449
- let getAggregatorParams = [firstArray, secondArray];
4450
4418
 
4451
- if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4452
- getAggregatorParams = lodash.reverse(getAggregatorParams);
4453
- }
4454
-
4455
- let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4419
+ if (!colAttrs || colAttrs.length == 0) {
4420
+ return null;
4421
+ }
4422
+
4423
+ let values_names_arr = [];
4424
+ let keysArray = sortingOptions.field ? rowKeys : colKeys;
4425
+
4426
+ 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);
4456
4430
 
4457
- if (aggregator_subtotal) {
4458
- valueForComparison = aggregator_subtotal.value();
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);
4459
4435
  }
4436
+ values_names_arr.push({name: val[0], value: value_subtotal});
4460
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);
4461
4446
 
4462
- if (!lodash.isNil(valueForComparison)) {
4463
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(valueForComparison))) {
4464
- valueForComparison = Math.abs(valueForComparison);
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;
4458
+
4459
+ if (!rowAttrs || rowAttrs.length == 0) {
4460
+ return null;
4461
+ }
4462
+
4463
+ let values_names_arr = [];
4464
+ let keysArray = sortingOptions.field ? colKeys : rowKeys;
4465
+
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);
4470
+
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);
4465
4475
  }
4466
- values_names_arr.push({name: secondArray.join(','), value: valueForComparison});
4476
+ values_names_arr.push({name: val[0], value: value_subtotal});
4467
4477
  }
4468
4478
  });
4469
4479
 
@@ -4475,33 +4485,36 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4475
4485
  values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4476
4486
 
4477
4487
  // map only names
4478
- return lodash.map(values_names_arr, 'name');
4488
+ let attr_sorted_values = lodash.map(values_names_arr, 'name');
4489
+ return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
4479
4490
  };
4480
4491
 
4481
- highchartsRenderer.generateSortingFunctionByValues = function (sortByValueSettings, pivotData, opts, widget) {
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
+
4482
4501
  let old_sorters_function = opts.sorters;
4483
4502
  if (!old_sorters_function) {
4484
4503
  old_sorters_function = function () {
4485
4504
  };
4486
4505
  }
4487
- return function (attr) {
4488
- const sortingOptions = lodash.find(sortByValueSettings, fieldSorting => fieldSorting.name === attr);
4489
- if (sortingOptions) {
4490
- const axis = highchartsRenderer.getAxis(_.includes(pivotData.colAttrs, attr) ? 'col_total' : 'row_total', opts);
4491
- const isColumnSort = axis === 'col_total';
4492
- const fieldIndex = lodash.findIndex(isColumnSort ? pivotData.colAttrs : pivotData.rowAttrs, name => name === attr);
4493
- const orderedNamesList = highchartsRenderer.getSortingByValueOrderList(
4494
- pivotData,
4495
- sortingOptions.sorting,
4496
- pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
4497
- pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
4498
- fieldIndex,
4499
- widget
4500
- );
4501
- return $.pivotUtilities.sortAs(orderedNamesList);
4502
- } else {
4503
- return old_sorters_function(attr);
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
+ }
4504
4514
  }
4515
+ return new_sorters_function;
4516
+ } else {
4517
+ return old_sorters_function;
4505
4518
  }
4506
4519
  };
4507
4520
 
@@ -4705,7 +4718,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4705
4718
  result = null;
4706
4719
  try {
4707
4720
  pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
4708
- pivotData.sortByValueAttrs = [];
4709
4721
  try {
4710
4722
  if (options && options.onlyOptions) {
4711
4723
  if (!opts.rendererOptions) {
@@ -4713,20 +4725,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4713
4725
  }
4714
4726
  opts.rendererOptions.onlyOptions = true;
4715
4727
  }
4716
-
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;
4729
- }
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);
4731
+ opts.sorters = new_sorting_function;
4732
+ optsFiltered.sorters = new_sorting_function;
4733
+ pivotData.sorters = new_sorting_function;
4730
4734
  }
4731
4735
 
4732
4736
  result = opts.renderer(pivotData, opts.rendererOptions);
@@ -4780,7 +4784,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4780
4784
  rows: lodash.map(pivotOptions.legendArray, 'name'),
4781
4785
  rendererOptions: widget.options,
4782
4786
  dateValuesDictionary: pivotOptions ? pivotOptions.dateValuesDictionary : null,
4783
- keysObject: pivotOptions ? pivotOptions.keysObject : null,
4784
4787
  };
4785
4788
 
4786
4789
  if (!subopts.rendererOptions) {
@@ -7081,6 +7084,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7081
7084
  value_name: 'is_percentage',
7082
7085
  default_value: false,
7083
7086
  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
7084
7099
  }]
7085
7100
  },
7086
7101
  'delta_column_for_drill_down': {
@@ -7147,6 +7162,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7147
7162
  value_name: 'is_percentage',
7148
7163
  default_value: false,
7149
7164
  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
7150
7177
  }, {
7151
7178
  element_type: 'checkbox',
7152
7179
  element_label: 'Filter zero values',
@@ -8649,8 +8676,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8649
8676
  };
8650
8677
 
8651
8678
  highchartsRenderer.getWidgetDataSorters = function (res, widget, defaultDateFormat) {
8652
- let sorters;
8653
-
8654
8679
  if ($.pivotUtilities && !$.pivotUtilities.additionalFieldsList) {
8655
8680
  $.pivotUtilities.additionalFieldsList = [
8656
8681
  {key: 'DR_Average', name: 'DR_Average'},
@@ -8658,19 +8683,30 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8658
8683
  ];
8659
8684
  }
8660
8685
 
8661
- let datesFields = [];
8686
+ var datesFields = [];
8662
8687
  datesFields = lodash.filter(widget.rows, element => element.type == 'Date');
8663
8688
  datesFields = datesFields.concat(lodash.filter(widget.cols, element => element.type == 'Date'));
8689
+
8690
+ const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8691
+ if (isCustomSorting) {
8692
+ lodash.forEach(datesFields, function (field) {
8693
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8694
+ field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8695
+ });
8696
+ }
8697
+
8664
8698
  datesFields = lodash.map(datesFields, function (row) {
8665
8699
  return { "format": highchartsRenderer.getDateFieldFormat(widget, row), "name": row.name, "type": row.type, "values": [], "sorting": row.sorting } //'MMM - yyyy' format
8666
8700
  });
8667
8701
 
8702
+ var data = res;
8703
+
8668
8704
  lodash.forEach(datesFields, function (row) {
8669
8705
  row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
8670
8706
  });
8671
8707
 
8672
8708
  if (datesFields.length > 0) {
8673
- lodash.forEach(res, function (element) {
8709
+ lodash.forEach(data, function (element) {
8674
8710
  for (var i in datesFields) {
8675
8711
  if (element.hasOwnProperty(datesFields[i].name)) {
8676
8712
  datesFields[i].values.push(element[datesFields[i].name]);
@@ -8688,145 +8724,171 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8688
8724
  }
8689
8725
  }
8690
8726
  });
8691
-
8692
- const invertedDateStringMap = lodash.invert(widget.pivot.dateValuesDictionary);
8693
- lodash.forEach([widget.pivot.keysObject.col_keys, widget.pivot.keysObject.row_keys], (widgetKeyLists, index) => {
8694
- const widgetFields = index ? widget.rows : widget.cols;
8695
- lodash.forEach(widgetKeyLists, keysList => {
8696
- lodash.forEach(keysList, (key, index) => {
8697
- if (widgetFields[index].type === 'Date') {
8698
- keysList[index] = invertedDateStringMap[key] || key;
8699
- }
8700
- });
8701
- });
8702
- })
8703
8727
  }
8728
+ lodash.forEach(datesFields, function (row) {
8729
+ row.values = lodash.uniq(row.values);
8704
8730
 
8705
- if (!highchartsRenderer.isSortingOnBackendEnabled()) {
8706
- const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8707
- if (isCustomSorting) {
8708
- lodash.forEach(datesFields, function (field) {
8709
- const fieldToSort = lodash.find(
8710
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8711
- );
8712
- field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8713
- });
8714
- }
8715
-
8716
- lodash.forEach(datesFields, function (row) {
8717
- row.values = lodash.uniq(row.values);
8718
-
8719
- const isTimestampDateField = row.type === 'Date' && lodash.some(row.values, value => typeof value ==='number');
8720
- if (isTimestampDateField) {
8721
- const nullValueIndex = row.values.indexOf(NULL_VALUE);
8722
- if (~nullValueIndex) {
8723
- row.values.splice(nullValueIndex, 1);
8724
- }
8725
- row.values = row.values.sort((a, b) => a - b);
8726
- if (~nullValueIndex) {
8727
- row.values.push(NULL_VALUE);
8728
- }
8729
- } else {
8730
- row.values = row.values.sort();
8731
+ const isTimestampDateField = row.type === 'Date' && lodash.some(row.values, value => typeof value ==='number');
8732
+ if (isTimestampDateField) {
8733
+ const nullValueIndex = row.values.indexOf(NULL_VALUE);
8734
+ if (~nullValueIndex) {
8735
+ row.values.splice(nullValueIndex, 1);
8731
8736
  }
8732
-
8733
- if (row.sorting && row.sorting.type == "largestToSmallest") {
8734
- row.values = lodash.reverse(row.values);
8737
+ row.values = row.values.sort((a, b) => a - b);
8738
+ if (~nullValueIndex) {
8739
+ row.values.push(NULL_VALUE);
8735
8740
  }
8736
- delete row.sorting;
8737
- row.values = lodash.map(row.values, function (val) {
8738
- return highchartsRenderer.returnRawDataValue(row.type, val, row.format, row.name, row.val_not_convert) + "";
8739
- })
8740
-
8741
- });
8741
+ } else {
8742
+ row.values = row.values.sort();
8743
+ }
8742
8744
 
8743
- /* date string */
8744
- var rowsAndCols = [];
8745
- rowsAndCols = widget.rows.concat(widget.cols);
8746
-
8747
- if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8748
-
8749
- // if it is breakdown widget - redefine sorting according to breakdown_options
8750
- // TODO: remove this when BE sort will be implemented
8751
- lodash.forEach(rowsAndCols, function (field) {
8752
- const waterfallFieldType = field.id === widget.cols[0].id ? 'totals' : 'breakdown';
8753
- field.sorting = {
8754
- type: 'CustomOrder',
8755
- values: lodash.map(
8756
- widget.options.breakdown_options.values[waterfallFieldType],
8757
- value => value.key
8758
- ),
8759
- };
8760
- });
8761
- } else if (isCustomSorting) {
8762
- lodash.forEach(rowsAndCols, function (field) {
8763
- const fieldToSort = lodash.find(
8764
- widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8765
- );
8766
- field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8767
- });
8745
+ if (row.sorting && row.sorting.type == "largestToSmallest") {
8746
+ row.values = lodash.reverse(row.values);
8768
8747
  }
8748
+ delete row.sorting;
8749
+ row.values = lodash.map(row.values, function (val) {
8750
+ return highchartsRenderer.returnRawDataValue(row.type, val, row.format, row.name, row.val_not_convert) + "";
8751
+ })
8752
+
8753
+ });
8754
+
8755
+ /* date string */
8756
+ var rowsAndCols = [];
8757
+ rowsAndCols = widget.rows.concat(widget.cols);
8758
+
8759
+ if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8769
8760
 
8761
+ // if it is breakdown widget - redefine sorting according to breakdown_options
8762
+ // TODO: remove this when BE sort will be implemented
8770
8763
  lodash.forEach(rowsAndCols, function (field) {
8771
- if (field.sorting && (field.sorting.type == "DateString" || field.sorting.type == "largestToSmallest")) {
8772
- var find_field = lodash.find(datesFields, {name: field.name});
8773
- if (find_field) {
8774
- if (find_field.type != 'Date')
8775
- find_field.sorting = field.sorting;
8776
- } else {
8777
- datesFields.push({
8778
- "format": field.format,
8779
- "name": field.name,
8780
- "type": field.type,
8781
- "values": [],
8782
- "sorting": field.sorting,
8783
- });
8784
- }
8785
- } else if (field.sorting && field.sorting.type == "CustomOrder" && field.sorting.values) {
8764
+ const waterfallFieldType = field.id === widget.cols[0].id ? 'totals' : 'breakdown';
8765
+ field.sorting = {
8766
+ type: 'CustomOrder',
8767
+ values: lodash.map(
8768
+ widget.options.breakdown_options.values[waterfallFieldType],
8769
+ value => value.key
8770
+ ),
8771
+ };
8772
+ });
8773
+ } else if (isCustomSorting) {
8774
+ lodash.forEach(rowsAndCols, function (field) {
8775
+ const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8776
+ field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8777
+ });
8778
+ }
8779
+
8780
+ lodash.forEach(rowsAndCols, function (field) {
8781
+ if (field.sorting && (field.sorting.type == "DateString" || field.sorting.type == "largestToSmallest")) {
8782
+ var find_field = lodash.find(datesFields, {name: field.name});
8783
+ if (find_field) {
8784
+ if (find_field.type != 'Date')
8785
+ find_field.sorting = field.sorting;
8786
+ } else {
8786
8787
  datesFields.push({
8787
8788
  "format": field.format,
8788
8789
  "name": field.name,
8789
8790
  "type": field.type,
8790
- "values": field.sorting.values
8791
+ "values": [],
8792
+ "sorting": field.sorting,
8791
8793
  });
8792
8794
  }
8795
+ } else if (field.sorting && field.sorting.type == "CustomOrder" && field.sorting.values) {
8796
+ datesFields.push({
8797
+ "format": field.format,
8798
+ "name": field.name,
8799
+ "type": field.type,
8800
+ "values": field.sorting.values
8801
+ });
8802
+ }
8803
+ });
8804
+
8805
+ if (widget.vals && widget.vals.length > 1) {
8806
+ datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
8807
+ }
8808
+
8809
+ /****** 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;
8793
8833
  });
8794
8834
 
8795
- if (widget.vals && widget.vals.length > 1) {
8796
- datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
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]);
8797
8847
  }
8798
-
8799
- /****** END *******/
8800
-
8801
- // TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
8802
- if (widget.options && widget.options.sortingValues) {
8803
- var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
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});
8804
8857
  if (field) {
8805
- field.values = widget.options.sortingValues.values;
8858
+ field.values = values_for_sort;
8806
8859
  field.sorting = null;
8807
8860
  } else {
8808
- datesFields.push({
8809
- name: widget.options.sortingValues.field,
8810
- values: widget.options.sortingValues.values
8811
- });
8861
+ datesFields.push({name: field_for_sorting.name, values: values_for_sort});
8812
8862
  }
8813
8863
  }
8814
- sorters = function (attr) {
8815
- var field = lodash.find(datesFields, {name: attr});
8816
- if (field)
8817
- if (field.sorting && field.sorting.type == "DateString") {
8818
- return $.pivotUtilities.sortDateStrings(field.sorting.month_order);
8819
- } else if (field.sorting && field.sorting.type == "largestToSmallest") {
8820
- if (field.sorting.is_absolute)
8821
- return $.pivotUtilities.largeToSmallSortByAbsolute;
8822
-
8823
- return $.pivotUtilities.largeToSmallSort;
8824
- } else {
8825
- return $.pivotUtilities.sortAs(field.values);
8826
- }
8827
- };
8864
+ } else if (widget.options && widget.options.sortingValues) {
8865
+ var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8866
+ if (field) {
8867
+ field.values = widget.options.sortingValues.values;
8868
+ field.sorting = null;
8869
+ } else {
8870
+ datesFields.push({
8871
+ name: widget.options.sortingValues.field,
8872
+ values: widget.options.sortingValues.values
8873
+ });
8874
+ }
8828
8875
  }
8829
8876
 
8877
+ let sorters = function (attr) {
8878
+ var field = lodash.find(datesFields, {name: attr});
8879
+ if (field)
8880
+ if (field.sorting && field.sorting.type == "DateString") {
8881
+ return $.pivotUtilities.sortDateStrings(field.sorting.month_order);
8882
+ } else if (field.sorting && field.sorting.type == "largestToSmallest") {
8883
+ if (field.sorting.is_absolute)
8884
+ return $.pivotUtilities.largeToSmallSortByAbsolute;
8885
+
8886
+ return $.pivotUtilities.largeToSmallSort;
8887
+ } else {
8888
+ return $.pivotUtilities.sortAs(field.values);
8889
+ }
8890
+ };
8891
+
8830
8892
  return sorters;
8831
8893
  };
8832
8894
 
@@ -8845,12 +8907,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8845
8907
 
8846
8908
  //highchartsRenderer.getGraphOptions(scope.data, override_values, res, scope.dataModel.templatesWithOutData, scope.openDrillDownList, drillDownFunction)
8847
8909
  highchartsRenderer.getGraphOptions = function (widget_obj, override_values, row_data, templates, openDrillDownListFunction, drillDownFunction) {
8848
-
8849
- let keysObject;
8850
- if (highchartsRenderer.isSortingOnBackendEnabled()) {
8851
- keysObject = row_data.pop();
8852
- }
8853
-
8854
8910
  let res = highchartsRenderer.updateSelectedOverrideValues(widget_obj, override_values, row_data);
8855
8911
  res = highchartsRenderer.convertUniqueDateValues(widget_obj, templates, res);
8856
8912
 
@@ -8862,10 +8918,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8862
8918
 
8863
8919
  let pivot = {};
8864
8920
 
8865
- if (highchartsRenderer.isSortingOnBackendEnabled()) {
8866
- pivot.keysObject = keysObject;
8867
- }
8868
-
8869
8921
  let templateNoData = lodash.find(templates, {id: widget_obj.template_id});
8870
8922
  if (templateNoData) {
8871
8923
 
@@ -8902,8 +8954,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8902
8954
  subopts.onlyOptions = true;
8903
8955
  }
8904
8956
 
8905
- subopts.keysObject = keysObject;
8906
-
8907
8957
  let hc_options = highchartsRenderer.rhPivotView(res, subopts, is_table, widget_obj);
8908
8958
 
8909
8959
  return hc_options;
@@ -9231,10 +9281,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9231
9281
  }
9232
9282
  }
9233
9283
 
9234
- highchartsRenderer.isSortingOnBackendEnabled = function() {
9235
- return lodash.includes(lodash.get(document, 'ReportHippo.user.features'), 'enable_server_widget_data_sorting');
9236
- }
9237
-
9238
9284
  return highchartsRenderer;
9239
9285
  };
9240
9286