@datarailsshared/dr_renderer 1.2.300-dragons → 1.2.301-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.300-dragons",
3
+ "version": "1.2.301-dragons",
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,16 @@ 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
108
  sorter = sortersArr[i];
107
- comparison = sorter(a[i], b[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
+ }
108
114
  if (comparison !== 0) {
109
115
  return comparison;
110
116
  }
@@ -4397,72 +4397,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4397
4397
  return ret_str;
4398
4398
  };
4399
4399
 
4400
- highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
4401
- let rowAttrs, rowKeys, colKeys, colAttrs;
4402
- rowAttrs = pivotData.rowAttrs;
4403
- rowKeys = pivotData.rowKeys;
4404
- colKeys = pivotData.colKeys;
4405
- colAttrs = pivotData.colAttrs;
4406
-
4407
-
4408
- if (!colAttrs || colAttrs.length == 0) {
4409
- return null;
4410
- }
4411
-
4400
+ highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex) {
4412
4401
  let values_names_arr = [];
4413
- let keysArray = sortingOptions.field ? rowKeys : colKeys;
4414
-
4415
4402
  lodash.forEach(keysArray, function (val) {
4416
- let firstArray = sortingOptions.field ? [val[0]] : [];
4417
- let secondArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4418
- let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4403
+ const firstArray = [];
4404
+ const secondArray = val.slice(0, fieldIndex + 1);
4405
+ let getAggregatorParams = [firstArray, secondArray];
4419
4406
 
4420
- if (aggregator_subtotal) {
4421
- let value_subtotal = aggregator_subtotal.value();
4422
- if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4423
- value_subtotal = Math.abs(value_subtotal);
4424
- }
4425
- values_names_arr.push({name: val[0], value: value_subtotal});
4407
+ if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
4408
+ getAggregatorParams = lodash.reverse(getAggregatorParams);
4426
4409
  }
4427
- });
4428
4410
 
4429
- // ORDERING
4430
- let sorting_vector = ['asc'];
4431
- if (sortingOptions && sortingOptions.type == 'largestToSmallest') {
4432
- sorting_vector = ['desc'];
4433
- }
4434
- values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4435
-
4436
- // map only names
4437
- let attr_sorted_values = lodash.map(values_names_arr, 'name');
4438
- return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
4439
- };
4440
-
4441
- highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
4442
- let rowAttrs, rowKeys, colKeys, colAttrs;
4443
- rowAttrs = pivotData.rowAttrs;
4444
- rowKeys = pivotData.rowKeys;
4445
- colKeys = pivotData.colKeys;
4446
- colAttrs = pivotData.colAttrs;
4447
-
4448
- if (!rowAttrs || rowAttrs.length == 0) {
4449
- return null;
4450
- }
4451
-
4452
- let values_names_arr = [];
4453
- let keysArray = sortingOptions.field ? colKeys : rowKeys;
4454
-
4455
- lodash.forEach(keysArray, function (val) {
4456
- let firstArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
4457
- let secondArray = sortingOptions.field ? [val[0]] : [];
4458
- let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
4411
+ let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
4459
4412
 
4460
4413
  if (aggregator_subtotal) {
4461
4414
  let value_subtotal = aggregator_subtotal.value();
4462
4415
  if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
4463
4416
  value_subtotal = Math.abs(value_subtotal);
4464
4417
  }
4465
- values_names_arr.push({name: val[0], value: value_subtotal});
4418
+ values_names_arr.push({name: secondArray.join(','), value: value_subtotal});
4466
4419
  }
4467
4420
  });
4468
4421
 
@@ -4474,36 +4427,32 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4474
4427
  values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
4475
4428
 
4476
4429
  // map only names
4477
- let attr_sorted_values = lodash.map(values_names_arr, 'name');
4478
- return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
4430
+ return lodash.map(values_names_arr, 'name');
4479
4431
  };
4480
4432
 
4481
- highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
4482
- let new_map;
4483
- let axis = highchartsRenderer.getAxis(sortingOptions.axis, opts);
4484
- if (axis == 'col_total') {
4485
- new_map = highchartsRenderer.getNewAttrSortingForCol(pivotData, sortingOptions);
4486
- } else if (axis == 'row_total') {
4487
- new_map = highchartsRenderer.getNewAttrSortingForRow(pivotData, sortingOptions);
4488
- }
4489
-
4433
+ highchartsRenderer.generateSortingFunctionByValues = function (sortByValueSettings, pivotData, opts, widget) {
4490
4434
  let old_sorters_function = opts.sorters;
4491
4435
  if (!old_sorters_function) {
4492
4436
  old_sorters_function = function () {
4493
4437
  };
4494
4438
  }
4495
- if (new_map) {
4496
- var sortAs = $.pivotUtilities.sortAs;
4497
- let new_sorters_function = function (attr) {
4498
- if (new_map.name == attr) {
4499
- return $.pivotUtilities.sortAs(new_map.values);
4500
- } else {
4501
- return old_sorters_function(attr);
4502
- }
4439
+ return function (attr) {
4440
+ const sortingOptions = lodash.find(sortByValueSettings, fieldSorting => fieldSorting.name === attr);
4441
+ if (sortingOptions) {
4442
+ const axis = highchartsRenderer.getAxis(_.includes(pivotData.colAttrs, attr) ? 'col_total' : 'row_total', opts);
4443
+ const isColumnSort = axis === 'col_total';
4444
+ const fieldIndex = lodash.findIndex(isColumnSort ? pivotData.colAttrs : pivotData.rowAttrs, name => name === attr);
4445
+ const orderedNamesList = highchartsRenderer.getSortingByValueOrderList(
4446
+ pivotData,
4447
+ sortingOptions.sorting,
4448
+ pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
4449
+ pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
4450
+ fieldIndex
4451
+ );
4452
+ return $.pivotUtilities.sortAs(orderedNamesList);
4453
+ } else {
4454
+ return old_sorters_function(attr);
4503
4455
  }
4504
- return new_sorters_function;
4505
- } else {
4506
- return old_sorters_function;
4507
4456
  }
4508
4457
  };
4509
4458
 
@@ -4707,6 +4656,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4707
4656
  result = null;
4708
4657
  try {
4709
4658
  pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
4659
+ pivotData.sortByValueAttrs = [];
4710
4660
  try {
4711
4661
  if (options && options.onlyOptions) {
4712
4662
  if (!opts.rendererOptions) {
@@ -4714,9 +4664,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4714
4664
  }
4715
4665
  opts.rendererOptions.onlyOptions = true;
4716
4666
  }
4717
- var totalFilters = lodash.get(opts, 'rendererOptions.total_value_options', null);
4718
- if (totalFilters && totalFilters.sorting_options) {
4719
- let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(totalFilters.sorting_options, pivotData, opts);
4667
+
4668
+ const sortByValueSettings = lodash.filter(
4669
+ lodash.get(widget, 'options.sortingFields', []),
4670
+ sortingField => lodash.get(sortingField, 'sorting.sort_by') === 'field_values'
4671
+ );
4672
+
4673
+ if (sortByValueSettings.length) {
4674
+ pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
4675
+ let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
4720
4676
  opts.sorters = new_sorting_function;
4721
4677
  optsFiltered.sorters = new_sorting_function;
4722
4678
  pivotData.sorters = new_sorting_function;
@@ -8668,7 +8624,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8668
8624
  const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
8669
8625
  if (isCustomSorting) {
8670
8626
  lodash.forEach(datesFields, function (field) {
8671
- const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8627
+ const fieldToSort = lodash.find(
8628
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8629
+ );
8672
8630
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8673
8631
  });
8674
8632
  }
@@ -8750,7 +8708,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8750
8708
  });
8751
8709
  } else if (isCustomSorting) {
8752
8710
  lodash.forEach(rowsAndCols, function (field) {
8753
- const fieldToSort = lodash.find(widget.options.sortingFields, element => element.id === field.id);
8711
+ const fieldToSort = lodash.find(
8712
+ widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
8713
+ );
8754
8714
  field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
8755
8715
  });
8756
8716
  }