@datarailsshared/dr_renderer 1.2.301-dragons → 1.2.302-dragons

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.301-dragons",
3
+ "version": "1.2.302-dragons",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -4397,25 +4397,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4397
4397
  return ret_str;
4398
4398
  };
4399
4399
 
4400
- highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex) {
4400
+ highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex, widget) {
4401
4401
  let values_names_arr = [];
4402
4402
  lodash.forEach(keysArray, function (val) {
4403
4403
  const firstArray = [];
4404
4404
  const secondArray = val.slice(0, fieldIndex + 1);
4405
- let getAggregatorParams = [firstArray, secondArray];
4406
4405
 
4407
- if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4408
- getAggregatorParams = lodash.reverse(getAggregatorParams);
4409
- }
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
+ );
4415
+
4416
+ valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
4417
+ } else {
4418
+ let getAggregatorParams = [firstArray, secondArray];
4419
+
4420
+ if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4421
+ getAggregatorParams = lodash.reverse(getAggregatorParams);
4422
+ }
4423
+
4424
+ let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4410
4425
 
4411
- let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4426
+ if (aggregator_subtotal) {
4427
+ valueForComparison = aggregator_subtotal.value();
4428
+ }
4429
+ }
4412
4430
 
4413
- if (aggregator_subtotal) {
4414
- let value_subtotal = aggregator_subtotal.value();
4415
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4416
- value_subtotal = Math.abs(value_subtotal);
4431
+ if (typeof valueForComparison !== 'undefined') {
4432
+ if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(valueForComparison))) {
4433
+ valueForComparison = Math.abs(valueForComparison);
4417
4434
  }
4418
- values_names_arr.push({name: secondArray.join(','), value: value_subtotal});
4435
+ values_names_arr.push({name: secondArray.join(','), value: valueForComparison});
4419
4436
  }
4420
4437
  });
4421
4438
 
@@ -4447,7 +4464,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4447
4464
  sortingOptions.sorting,
4448
4465
  pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
4449
4466
  pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
4450
- fieldIndex
4467
+ fieldIndex,
4468
+ widget
4451
4469
  );
4452
4470
  return $.pivotUtilities.sortAs(orderedNamesList);
4453
4471
  } else {
@@ -4667,7 +4685,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4667
4685
 
4668
4686
  const sortByValueSettings = lodash.filter(
4669
4687
  lodash.get(widget, 'options.sortingFields', []),
4670
- sortingField => lodash.get(sortingField, 'sorting.sort_by') === 'field_values'
4688
+ sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
4671
4689
  );
4672
4690
 
4673
4691
  if (sortByValueSettings.length) {
@@ -7018,18 +7036,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7018
7036
  value_name: 'is_percentage',
7019
7037
  default_value: false,
7020
7038
  hidden: true,
7021
- }, {
7022
- element_type: 'checkbox',
7023
- element_label: 'Sort by variance',
7024
- value_name: 'sort_by_variance',
7025
- default_value: false,
7026
- hidden: true
7027
- }, {
7028
- element_type: 'checkbox',
7029
- element_label: 'Sort by absolute variance',
7030
- value_name: 'sort_by_absolute_variance',
7031
- default_value: false,
7032
- hidden: true
7033
7039
  }]
7034
7040
  },
7035
7041
  'delta_column_for_drill_down': {
@@ -7096,18 +7102,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7096
7102
  value_name: 'is_percentage',
7097
7103
  default_value: false,
7098
7104
  hidden: true,
7099
- }, {
7100
- element_type: 'checkbox',
7101
- element_label: 'Sort by variance',
7102
- value_name: 'sort_by_variance',
7103
- default_value: false,
7104
- hidden: true
7105
- }, {
7106
- element_type: 'checkbox',
7107
- element_label: 'Sort by absolute variance',
7108
- value_name: 'sort_by_absolute_variance',
7109
- default_value: false,
7110
- hidden: true
7111
7105
  }, {
7112
7106
  element_type: 'checkbox',
7113
7107
  element_label: 'Filter zero values',
@@ -8745,61 +8739,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8745
8739
  }
8746
8740
 
8747
8741
  /****** END *******/
8748
-
8749
- if (lodash.has(widget, "options.chartOptions.delta_column") &&
8750
- widget.options.chartOptions.delta_column.field != '' &&
8751
- (widget.options.chartOptions.delta_column.sort_by_variance ||
8752
- widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
8753
- widget.rows.length > 0 &&
8754
- widget.cols.length > 0 &&
8755
- widget.vals.length
8756
- ) {
8757
- let variance_config = widget.options.chartOptions.delta_column;
8758
- let val_field = widget.vals[0];
8759
- let field_for_sorting = null;
8760
- let field_with_variant = null;
8761
- if (variance_config.field == "series") {
8762
- field_for_sorting = widget.cols[0];
8763
- field_with_variant = widget.rows[0];
8764
- } else if (variance_config.field == "category") {
8765
- field_for_sorting = widget.rows[0];
8766
- field_with_variant = widget.cols[0];
8767
- }
8768
-
8769
- let data_sorted = lodash.filter(data, function (data_row) {
8770
- return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
8771
- });
8772
-
8773
- const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
8774
-
8775
- if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
8776
- data_sorted = lodash.sortBy(data_sorted, function (o) {
8777
- if (sorting_variance === 'desc') {
8778
- return Math.abs(o[val_field.name]) * -1;
8779
- }
8780
-
8781
- return Math.abs(o[val_field.name]) * 1;
8782
- });
8783
- } else {
8784
- data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
8785
- }
8786
-
8787
- let values_for_sort = lodash.map(data_sorted, function (data_row) {
8788
- return data_row[field_for_sorting.name];
8789
- });
8790
-
8791
- values_for_sort = lodash.uniq(values_for_sort);
8792
-
8793
- if (values_for_sort.length > 0) {
8794
- let field = lodash.find(datesFields, {name: field_for_sorting.name});
8795
- if (field) {
8796
- field.values = values_for_sort;
8797
- field.sorting = null;
8798
- } else {
8799
- datesFields.push({name: field_for_sorting.name, values: values_for_sort});
8800
- }
8801
- }
8802
- } else if (widget.options && widget.options.sortingValues) {
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) {
8803
8745
  var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
8804
8746
  if (field) {
8805
8747
  field.values = widget.options.sortingValues.values;