@datarailsshared/dr_renderer 1.2.311 → 1.2.313
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 +1 -1
- package/src/dr_pivottable.js +13 -2
- package/src/highcharts_renderer.js +80 -165
- package/src/pivottable.js +1 -0
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
@@ -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
|
-
|
107
|
-
|
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
|
}
|
@@ -1460,6 +1460,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1460
1460
|
totalSeries.color = colors[i];
|
1461
1461
|
}
|
1462
1462
|
|
1463
|
+
if (!lodash.isEmpty(pivotData.colTotals)) {
|
1463
1464
|
col_n_keys.forEach(columnKey => {
|
1464
1465
|
let key = columnKey;
|
1465
1466
|
let totalKey = columnKey;
|
@@ -1470,6 +1471,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1470
1471
|
const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
|
1471
1472
|
totalSeries.data.push({name: lodash.unescape(key), y: value});
|
1472
1473
|
});
|
1474
|
+
} else {
|
1475
|
+
lodash.forEach(row_n_keys, (rowKey, index) => {
|
1476
|
+
let key = rowKey;
|
1477
|
+
let totalKey = rowKey;
|
1478
|
+
if (lodash.isArray(rowKey)) {
|
1479
|
+
key = col_n_keys[index];
|
1480
|
+
totalKey = totalKey.join(highchartsRenderer.delimer);
|
1481
|
+
}
|
1482
|
+
const value = pivotData.rowTotals[totalKey] ? pivotData.rowTotals[totalKey].value() : 0;
|
1483
|
+
totalSeries.data.push({name: lodash.unescape(key), y: value});
|
1484
|
+
});
|
1485
|
+
}
|
1473
1486
|
|
1474
1487
|
chart_series.push(totalSeries);
|
1475
1488
|
}
|
@@ -4408,72 +4421,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4408
4421
|
return ret_str;
|
4409
4422
|
};
|
4410
4423
|
|
4411
|
-
highchartsRenderer.
|
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
|
-
|
4424
|
+
highchartsRenderer.getSortingByValueOrderList = function (pivotData, sortingOptions, keysArray, attrs, fieldIndex, widget) {
|
4423
4425
|
let values_names_arr = [];
|
4424
|
-
let keysArray = sortingOptions.field ? rowKeys : colKeys;
|
4425
|
-
|
4426
4426
|
lodash.forEach(keysArray, function (val) {
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
if (
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
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;
|
4427
|
+
const firstArray = [];
|
4428
|
+
const secondArray = val.slice(0, fieldIndex + 1);
|
4429
|
+
|
4430
|
+
let valueForComparison;
|
4431
|
+
if (sortingOptions.sort_by === 'variance') {
|
4432
|
+
const varianceConfig = widget.options.chartOptions.delta_column;
|
4433
|
+
const data = pivotData.input;
|
4434
|
+
const varianceField = varianceConfig.field === 'category' ? widget.cols[0] : widget.rows[0];
|
4435
|
+
const varianceRowsForCurrentKey = lodash.filter(data, row =>
|
4436
|
+
row[varianceField.name] === varianceConfig.name
|
4437
|
+
&& lodash.every(secondArray, (item, index) => row[attrs[index]] === item)
|
4438
|
+
);
|
4458
4439
|
|
4459
|
-
|
4460
|
-
|
4461
|
-
|
4440
|
+
valueForComparison = lodash.reduce(varianceRowsForCurrentKey, (a, d) => a + d[widget.vals[0].name], 0);
|
4441
|
+
} else {
|
4442
|
+
let getAggregatorParams = [firstArray, secondArray];
|
4462
4443
|
|
4463
|
-
|
4464
|
-
|
4444
|
+
if (lodash.includes(pivotData.rowAttrs, attrs[fieldIndex])) {
|
4445
|
+
getAggregatorParams = lodash.reverse(getAggregatorParams);
|
4446
|
+
}
|
4447
|
+
|
4448
|
+
let aggregator_subtotal = pivotData.getAggregator(...getAggregatorParams);
|
4465
4449
|
|
4466
|
-
|
4467
|
-
|
4468
|
-
|
4469
|
-
|
4450
|
+
if (aggregator_subtotal) {
|
4451
|
+
valueForComparison = aggregator_subtotal.value();
|
4452
|
+
}
|
4453
|
+
}
|
4470
4454
|
|
4471
|
-
if (
|
4472
|
-
|
4473
|
-
|
4474
|
-
value_subtotal = Math.abs(value_subtotal);
|
4455
|
+
if (!lodash.isNil(valueForComparison)) {
|
4456
|
+
if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(valueForComparison))) {
|
4457
|
+
valueForComparison = Math.abs(valueForComparison);
|
4475
4458
|
}
|
4476
|
-
values_names_arr.push({name:
|
4459
|
+
values_names_arr.push({name: secondArray.join(','), value: valueForComparison});
|
4477
4460
|
}
|
4478
4461
|
});
|
4479
4462
|
|
@@ -4485,36 +4468,33 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4485
4468
|
values_names_arr = lodash.orderBy(values_names_arr, ['value'], sorting_vector);
|
4486
4469
|
|
4487
4470
|
// map only names
|
4488
|
-
|
4489
|
-
return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
|
4471
|
+
return lodash.map(values_names_arr, 'name');
|
4490
4472
|
};
|
4491
4473
|
|
4492
|
-
highchartsRenderer.generateSortingFunctionByValues = function (
|
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
|
-
|
4474
|
+
highchartsRenderer.generateSortingFunctionByValues = function (sortByValueSettings, pivotData, opts, widget) {
|
4501
4475
|
let old_sorters_function = opts.sorters;
|
4502
4476
|
if (!old_sorters_function) {
|
4503
4477
|
old_sorters_function = function () {
|
4504
4478
|
};
|
4505
4479
|
}
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
4509
|
-
|
4510
|
-
|
4511
|
-
|
4512
|
-
|
4513
|
-
|
4480
|
+
return function (attr) {
|
4481
|
+
const sortingOptions = lodash.find(sortByValueSettings, fieldSorting => fieldSorting.name === attr);
|
4482
|
+
if (sortingOptions) {
|
4483
|
+
const axis = highchartsRenderer.getAxis(_.includes(pivotData.colAttrs, attr) ? 'col_total' : 'row_total', opts);
|
4484
|
+
const isColumnSort = axis === 'col_total';
|
4485
|
+
const fieldIndex = lodash.findIndex(isColumnSort ? pivotData.colAttrs : pivotData.rowAttrs, name => name === attr);
|
4486
|
+
const orderedNamesList = highchartsRenderer.getSortingByValueOrderList(
|
4487
|
+
pivotData,
|
4488
|
+
sortingOptions.sorting,
|
4489
|
+
pivotData[isColumnSort ? 'colKeys' : 'rowKeys'],
|
4490
|
+
pivotData[isColumnSort ? 'colAttrs' : 'rowAttrs'],
|
4491
|
+
fieldIndex,
|
4492
|
+
widget
|
4493
|
+
);
|
4494
|
+
return $.pivotUtilities.sortAs(orderedNamesList);
|
4495
|
+
} else {
|
4496
|
+
return old_sorters_function(attr);
|
4514
4497
|
}
|
4515
|
-
return new_sorters_function;
|
4516
|
-
} else {
|
4517
|
-
return old_sorters_function;
|
4518
4498
|
}
|
4519
4499
|
};
|
4520
4500
|
|
@@ -4718,6 +4698,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4718
4698
|
result = null;
|
4719
4699
|
try {
|
4720
4700
|
pivotData = $.pivotUtilities.getPivotDataModel(rowData, opts);
|
4701
|
+
pivotData.sortByValueAttrs = [];
|
4721
4702
|
try {
|
4722
4703
|
if (options && options.onlyOptions) {
|
4723
4704
|
if (!opts.rendererOptions) {
|
@@ -4725,9 +4706,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4725
4706
|
}
|
4726
4707
|
opts.rendererOptions.onlyOptions = true;
|
4727
4708
|
}
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4709
|
+
|
4710
|
+
const sortByValueSettings = lodash.filter(
|
4711
|
+
lodash.get(widget, 'options.sortingFields', []),
|
4712
|
+
sortingField => lodash.includes(['field_values', 'variance'], lodash.get(sortingField, 'sorting.sort_by'))
|
4713
|
+
);
|
4714
|
+
|
4715
|
+
if (sortByValueSettings.length) {
|
4716
|
+
pivotData.sortByValueAttrs = lodash.map(sortByValueSettings, fieldSorting => fieldSorting.name);
|
4717
|
+
let new_sorting_function = highchartsRenderer.generateSortingFunctionByValues(sortByValueSettings, pivotData, opts, widget);
|
4731
4718
|
opts.sorters = new_sorting_function;
|
4732
4719
|
optsFiltered.sorters = new_sorting_function;
|
4733
4720
|
pivotData.sorters = new_sorting_function;
|
@@ -7090,18 +7077,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7090
7077
|
value_name: 'is_percentage',
|
7091
7078
|
default_value: false,
|
7092
7079
|
hidden: true,
|
7093
|
-
}, {
|
7094
|
-
element_type: 'checkbox',
|
7095
|
-
element_label: 'Sort by variance',
|
7096
|
-
value_name: 'sort_by_variance',
|
7097
|
-
default_value: false,
|
7098
|
-
hidden: true
|
7099
|
-
}, {
|
7100
|
-
element_type: 'checkbox',
|
7101
|
-
element_label: 'Sort by absolute variance',
|
7102
|
-
value_name: 'sort_by_absolute_variance',
|
7103
|
-
default_value: false,
|
7104
|
-
hidden: true
|
7105
7080
|
}]
|
7106
7081
|
},
|
7107
7082
|
'delta_column_for_drill_down': {
|
@@ -7168,18 +7143,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
7168
7143
|
value_name: 'is_percentage',
|
7169
7144
|
default_value: false,
|
7170
7145
|
hidden: true,
|
7171
|
-
}, {
|
7172
|
-
element_type: 'checkbox',
|
7173
|
-
element_label: 'Sort by variance',
|
7174
|
-
value_name: 'sort_by_variance',
|
7175
|
-
default_value: false,
|
7176
|
-
hidden: true
|
7177
|
-
}, {
|
7178
|
-
element_type: 'checkbox',
|
7179
|
-
element_label: 'Sort by absolute variance',
|
7180
|
-
value_name: 'sort_by_absolute_variance',
|
7181
|
-
default_value: false,
|
7182
|
-
hidden: true
|
7183
7146
|
}, {
|
7184
7147
|
element_type: 'checkbox',
|
7185
7148
|
element_label: 'Filter zero values',
|
@@ -8696,7 +8659,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8696
8659
|
const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
|
8697
8660
|
if (isCustomSorting) {
|
8698
8661
|
lodash.forEach(datesFields, function (field) {
|
8699
|
-
const fieldToSort = lodash.find(
|
8662
|
+
const fieldToSort = lodash.find(
|
8663
|
+
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8664
|
+
);
|
8700
8665
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8701
8666
|
});
|
8702
8667
|
}
|
@@ -8778,7 +8743,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8778
8743
|
});
|
8779
8744
|
} else if (isCustomSorting) {
|
8780
8745
|
lodash.forEach(rowsAndCols, function (field) {
|
8781
|
-
const fieldToSort = lodash.find(
|
8746
|
+
const fieldToSort = lodash.find(
|
8747
|
+
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8748
|
+
);
|
8782
8749
|
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8783
8750
|
});
|
8784
8751
|
}
|
@@ -8813,61 +8780,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8813
8780
|
}
|
8814
8781
|
|
8815
8782
|
/****** END *******/
|
8816
|
-
|
8817
|
-
|
8818
|
-
|
8819
|
-
(widget.options.chartOptions.delta_column.sort_by_variance ||
|
8820
|
-
widget.options.chartOptions.delta_column.sort_by_absolute_variance) &&
|
8821
|
-
widget.rows.length > 0 &&
|
8822
|
-
widget.cols.length > 0 &&
|
8823
|
-
widget.vals.length
|
8824
|
-
) {
|
8825
|
-
let variance_config = widget.options.chartOptions.delta_column;
|
8826
|
-
let val_field = widget.vals[0];
|
8827
|
-
let field_for_sorting = null;
|
8828
|
-
let field_with_variant = null;
|
8829
|
-
if (variance_config.field == "series") {
|
8830
|
-
field_for_sorting = widget.cols[0];
|
8831
|
-
field_with_variant = widget.rows[0];
|
8832
|
-
} else if (variance_config.field == "category") {
|
8833
|
-
field_for_sorting = widget.rows[0];
|
8834
|
-
field_with_variant = widget.cols[0];
|
8835
|
-
}
|
8836
|
-
|
8837
|
-
let data_sorted = lodash.filter(data, function (data_row) {
|
8838
|
-
return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
|
8839
|
-
});
|
8840
|
-
|
8841
|
-
const sorting_variance = widget.options.total_value_options && widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
|
8842
|
-
|
8843
|
-
if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
|
8844
|
-
data_sorted = lodash.sortBy(data_sorted, function (o) {
|
8845
|
-
if (sorting_variance === 'desc') {
|
8846
|
-
return Math.abs(o[val_field.name]) * -1;
|
8847
|
-
}
|
8848
|
-
|
8849
|
-
return Math.abs(o[val_field.name]) * 1;
|
8850
|
-
});
|
8851
|
-
} else {
|
8852
|
-
data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
|
8853
|
-
}
|
8854
|
-
|
8855
|
-
let values_for_sort = lodash.map(data_sorted, function (data_row) {
|
8856
|
-
return data_row[field_for_sorting.name];
|
8857
|
-
});
|
8858
|
-
|
8859
|
-
values_for_sort = lodash.uniq(values_for_sort);
|
8860
|
-
|
8861
|
-
if (values_for_sort.length > 0) {
|
8862
|
-
let field = lodash.find(datesFields, {name: field_for_sorting.name});
|
8863
|
-
if (field) {
|
8864
|
-
field.values = values_for_sort;
|
8865
|
-
field.sorting = null;
|
8866
|
-
} else {
|
8867
|
-
datesFields.push({name: field_for_sorting.name, values: values_for_sort});
|
8868
|
-
}
|
8869
|
-
}
|
8870
|
-
} else if (widget.options && widget.options.sortingValues) {
|
8783
|
+
|
8784
|
+
// TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
|
8785
|
+
if (widget.options && widget.options.sortingValues) {
|
8871
8786
|
var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
|
8872
8787
|
if (field) {
|
8873
8788
|
field.values = widget.options.sortingValues.values;
|
package/src/pivottable.js
CHANGED