@datarailsshared/dr_renderer 1.2.315-dragons → 1.2.316-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 +1 -1
- package/src/dr_pivottable.js +1 -1
- package/src/highcharts_renderer.js +158 -123
- package/src/pivottable.js +17 -4
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
@@ -198,7 +198,7 @@ let initDRPivotTable = function($, window, document) {
|
|
198
198
|
let flatRowKey = rowKey.join(delim);
|
199
199
|
let flatColKey = colKey.join(delim);
|
200
200
|
|
201
|
-
if (this.keysLength === rowKey.length + colKey.length) {
|
201
|
+
if (this.keysLength === rowKey.length + colKey.length && !this.isKeysSortingDoneOnBackendSide) {
|
202
202
|
if (!this.rowKeys.some(rKey => rKey.join(delim) === flatRowKey)) {
|
203
203
|
this.rowKeys.push(rowKey);
|
204
204
|
}
|
@@ -1507,6 +1507,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1507
1507
|
const chart_series = [];
|
1508
1508
|
const row_n_keys = pivotData.getRowKeys();
|
1509
1509
|
const col_n_keys = pivotData.getColKeys();
|
1510
|
+
const rows_by_cols = pivotData.rowKeysByCols;
|
1510
1511
|
|
1511
1512
|
let resultObject = {
|
1512
1513
|
data: [],
|
@@ -1535,7 +1536,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
1535
1536
|
});
|
1536
1537
|
|
1537
1538
|
if (col_index !== col_n_keys.length - 1) {
|
1538
|
-
|
1539
|
+
|
1540
|
+
const rowKeys = rows_by_cols ? rows_by_cols[col_index] : row_n_keys;
|
1541
|
+
lodash.forEach(rowKeys, function (row_n_value) {
|
1539
1542
|
const agg = pivotData.getAggregator(row_n_value, col_n_value);
|
1540
1543
|
let val = agg.value();
|
1541
1544
|
|
@@ -4711,17 +4714,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4711
4714
|
opts.rendererOptions.onlyOptions = true;
|
4712
4715
|
}
|
4713
4716
|
|
4714
|
-
|
4715
|
-
lodash.
|
4716
|
-
|
4717
|
-
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
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
|
+
}
|
4725
4730
|
}
|
4726
4731
|
|
4727
4732
|
result = opts.renderer(pivotData, opts.rendererOptions);
|
@@ -4775,6 +4780,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
4775
4780
|
rows: lodash.map(pivotOptions.legendArray, 'name'),
|
4776
4781
|
rendererOptions: widget.options,
|
4777
4782
|
dateValuesDictionary: pivotOptions ? pivotOptions.dateValuesDictionary : null,
|
4783
|
+
keysObject: pivotOptions ? pivotOptions.keysObject : null,
|
4778
4784
|
};
|
4779
4785
|
|
4780
4786
|
if (!subopts.rendererOptions) {
|
@@ -8643,6 +8649,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8643
8649
|
};
|
8644
8650
|
|
8645
8651
|
highchartsRenderer.getWidgetDataSorters = function (res, widget, defaultDateFormat) {
|
8652
|
+
let sorters;
|
8653
|
+
|
8646
8654
|
if ($.pivotUtilities && !$.pivotUtilities.additionalFieldsList) {
|
8647
8655
|
$.pivotUtilities.additionalFieldsList = [
|
8648
8656
|
{key: 'DR_Average', name: 'DR_Average'},
|
@@ -8650,32 +8658,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8650
8658
|
];
|
8651
8659
|
}
|
8652
8660
|
|
8653
|
-
|
8661
|
+
let datesFields = [];
|
8654
8662
|
datesFields = lodash.filter(widget.rows, element => element.type == 'Date');
|
8655
8663
|
datesFields = datesFields.concat(lodash.filter(widget.cols, element => element.type == 'Date'));
|
8656
|
-
|
8657
|
-
const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
|
8658
|
-
if (isCustomSorting) {
|
8659
|
-
lodash.forEach(datesFields, function (field) {
|
8660
|
-
const fieldToSort = lodash.find(
|
8661
|
-
widget.options.sortingFields, element => element.id === field.id && lodash.get(element, 'sorting.sort_by') === 'field_items'
|
8662
|
-
);
|
8663
|
-
field.sorting = fieldToSort ? fieldToSort.sorting : field.sorting;
|
8664
|
-
});
|
8665
|
-
}
|
8666
|
-
|
8667
8664
|
datesFields = lodash.map(datesFields, function (row) {
|
8668
8665
|
return { "format": highchartsRenderer.getDateFieldFormat(widget, row), "name": row.name, "type": row.type, "values": [], "sorting": row.sorting } //'MMM - yyyy' format
|
8669
8666
|
});
|
8670
8667
|
|
8671
|
-
var data = res;
|
8672
|
-
|
8673
8668
|
lodash.forEach(datesFields, function (row) {
|
8674
8669
|
row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
|
8675
8670
|
});
|
8676
8671
|
|
8677
8672
|
if (datesFields.length > 0) {
|
8678
|
-
lodash.forEach(
|
8673
|
+
lodash.forEach(res, function (element) {
|
8679
8674
|
for (var i in datesFields) {
|
8680
8675
|
if (element.hasOwnProperty(datesFields[i].name)) {
|
8681
8676
|
datesFields[i].values.push(element[datesFields[i].name]);
|
@@ -8693,120 +8688,144 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8693
8688
|
}
|
8694
8689
|
}
|
8695
8690
|
});
|
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
|
+
})
|
8696
8703
|
}
|
8697
|
-
lodash.forEach(datesFields, function (row) {
|
8698
|
-
row.values = lodash.uniq(row.values);
|
8699
8704
|
|
8700
|
-
|
8701
|
-
|
8702
|
-
|
8703
|
-
|
8704
|
-
|
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();
|
8705
8731
|
}
|
8706
|
-
|
8707
|
-
if (
|
8708
|
-
row.values.
|
8732
|
+
|
8733
|
+
if (row.sorting && row.sorting.type == "largestToSmallest") {
|
8734
|
+
row.values = lodash.reverse(row.values);
|
8709
8735
|
}
|
8710
|
-
|
8711
|
-
row.values = row.values
|
8712
|
-
|
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
|
+
});
|
8713
8742
|
|
8714
|
-
|
8715
|
-
|
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
|
+
});
|
8716
8768
|
}
|
8717
|
-
delete row.sorting;
|
8718
|
-
row.values = lodash.map(row.values, function (val) {
|
8719
|
-
return highchartsRenderer.returnRawDataValue(row.type, val, row.format, row.name, row.val_not_convert) + "";
|
8720
|
-
})
|
8721
|
-
|
8722
|
-
});
|
8723
8769
|
|
8724
|
-
/* date string */
|
8725
|
-
var rowsAndCols = [];
|
8726
|
-
rowsAndCols = widget.rows.concat(widget.cols);
|
8727
|
-
|
8728
|
-
if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
|
8729
|
-
|
8730
|
-
// if it is breakdown widget - redefine sorting according to breakdown_options
|
8731
|
-
// TODO: remove this when BE sort will be implemented
|
8732
|
-
lodash.forEach(rowsAndCols, function (field) {
|
8733
|
-
const waterfallFieldType = field.id === widget.cols[0].id ? 'totals' : 'breakdown';
|
8734
|
-
field.sorting = {
|
8735
|
-
type: 'CustomOrder',
|
8736
|
-
values: lodash.map(
|
8737
|
-
widget.options.breakdown_options.values[waterfallFieldType],
|
8738
|
-
value => value.key
|
8739
|
-
),
|
8740
|
-
};
|
8741
|
-
});
|
8742
|
-
} else if (isCustomSorting) {
|
8743
8770
|
lodash.forEach(rowsAndCols, function (field) {
|
8744
|
-
|
8745
|
-
|
8746
|
-
|
8747
|
-
|
8748
|
-
|
8749
|
-
|
8750
|
-
|
8751
|
-
|
8752
|
-
|
8753
|
-
|
8754
|
-
|
8755
|
-
|
8756
|
-
|
8757
|
-
|
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) {
|
8758
8786
|
datesFields.push({
|
8759
8787
|
"format": field.format,
|
8760
8788
|
"name": field.name,
|
8761
8789
|
"type": field.type,
|
8762
|
-
"values":
|
8763
|
-
"sorting": field.sorting,
|
8790
|
+
"values": field.sorting.values
|
8764
8791
|
});
|
8765
8792
|
}
|
8766
|
-
}
|
8767
|
-
datesFields.push({
|
8768
|
-
"format": field.format,
|
8769
|
-
"name": field.name,
|
8770
|
-
"type": field.type,
|
8771
|
-
"values": field.sorting.values
|
8772
|
-
});
|
8773
|
-
}
|
8774
|
-
});
|
8775
|
-
|
8776
|
-
if (widget.vals && widget.vals.length > 1) {
|
8777
|
-
datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
|
8778
|
-
}
|
8793
|
+
});
|
8779
8794
|
|
8780
|
-
|
8781
|
-
|
8782
|
-
// TODO: Remove. sortingValues looks like lagacy which is not in use neither in webclient nor in renderer
|
8783
|
-
if (widget.options && widget.options.sortingValues) {
|
8784
|
-
var field = lodash.find(datesFields, {name: widget.options.sortingValues.field});
|
8785
|
-
if (field) {
|
8786
|
-
field.values = widget.options.sortingValues.values;
|
8787
|
-
field.sorting = null;
|
8788
|
-
} else {
|
8789
|
-
datesFields.push({
|
8790
|
-
name: widget.options.sortingValues.field,
|
8791
|
-
values: widget.options.sortingValues.values
|
8792
|
-
});
|
8795
|
+
if (widget.vals && widget.vals.length > 1) {
|
8796
|
+
datesFields.push({name: "DR_Values", values: lodash.map(widget.vals, 'name')});
|
8793
8797
|
}
|
8794
|
-
|
8795
|
-
|
8796
|
-
|
8797
|
-
|
8798
|
-
if (
|
8799
|
-
|
8800
|
-
|
8801
|
-
|
8802
|
-
|
8803
|
-
return $.pivotUtilities.largeToSmallSortByAbsolute;
|
8804
|
-
|
8805
|
-
return $.pivotUtilities.largeToSmallSort;
|
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});
|
8804
|
+
if (field) {
|
8805
|
+
field.values = widget.options.sortingValues.values;
|
8806
|
+
field.sorting = null;
|
8806
8807
|
} else {
|
8807
|
-
|
8808
|
+
datesFields.push({
|
8809
|
+
name: widget.options.sortingValues.field,
|
8810
|
+
values: widget.options.sortingValues.values
|
8811
|
+
});
|
8808
8812
|
}
|
8809
|
-
|
8813
|
+
}
|
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
|
+
};
|
8828
|
+
}
|
8810
8829
|
|
8811
8830
|
return sorters;
|
8812
8831
|
};
|
@@ -8826,6 +8845,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8826
8845
|
|
8827
8846
|
//highchartsRenderer.getGraphOptions(scope.data, override_values, res, scope.dataModel.templatesWithOutData, scope.openDrillDownList, drillDownFunction)
|
8828
8847
|
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
|
+
|
8829
8854
|
let res = highchartsRenderer.updateSelectedOverrideValues(widget_obj, override_values, row_data);
|
8830
8855
|
res = highchartsRenderer.convertUniqueDateValues(widget_obj, templates, res);
|
8831
8856
|
|
@@ -8837,6 +8862,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8837
8862
|
|
8838
8863
|
let pivot = {};
|
8839
8864
|
|
8865
|
+
if (highchartsRenderer.isSortingOnBackendEnabled()) {
|
8866
|
+
pivot.keysObject = keysObject;
|
8867
|
+
}
|
8868
|
+
|
8840
8869
|
let templateNoData = lodash.find(templates, {id: widget_obj.template_id});
|
8841
8870
|
if (templateNoData) {
|
8842
8871
|
|
@@ -8873,6 +8902,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
8873
8902
|
subopts.onlyOptions = true;
|
8874
8903
|
}
|
8875
8904
|
|
8905
|
+
subopts.keysObject = keysObject;
|
8906
|
+
|
8876
8907
|
let hc_options = highchartsRenderer.rhPivotView(res, subopts, is_table, widget_obj);
|
8877
8908
|
|
8878
8909
|
return hc_options;
|
@@ -9200,6 +9231,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9200
9231
|
}
|
9201
9232
|
}
|
9202
9233
|
|
9234
|
+
highchartsRenderer.isSortingOnBackendEnabled = function() {
|
9235
|
+
return lodash.includes(lodash.get(document, 'ReportHippo.user.features'), 'enable_server_widget_data_sorting');
|
9236
|
+
}
|
9237
|
+
|
9203
9238
|
return highchartsRenderer;
|
9204
9239
|
};
|
9205
9240
|
|
package/src/pivottable.js
CHANGED
@@ -686,8 +686,17 @@ let initPivotTable = function($, window, document) {
|
|
686
686
|
});
|
687
687
|
this.tree = {};
|
688
688
|
this.insights = [];
|
689
|
-
|
690
|
-
this.
|
689
|
+
|
690
|
+
this.isKeysSortingDoneOnBackendSide = opts.keysObject && typeof opts.keysObject === 'object';
|
691
|
+
if (this.isKeysSortingDoneOnBackendSide) {
|
692
|
+
this.rowKeys = opts.keysObject.row_keys;
|
693
|
+
this.colKeys = opts.keysObject.col_keys;
|
694
|
+
// TODO: add also for breakdown sort object when BE story is ready.
|
695
|
+
} else {
|
696
|
+
this.rowKeys = [];
|
697
|
+
this.colKeys = [];
|
698
|
+
}
|
699
|
+
|
691
700
|
this.rowTotals = {};
|
692
701
|
this.colTotals = {};
|
693
702
|
this.allTotal = this.aggregator(this, [], []);
|
@@ -852,12 +861,16 @@ let initPivotTable = function($, window, document) {
|
|
852
861
|
};
|
853
862
|
|
854
863
|
PivotData.prototype.getColKeys = function() {
|
855
|
-
this.
|
864
|
+
if (!this.isKeysSortingDoneOnBackendSide) {
|
865
|
+
this.sortKeys();
|
866
|
+
}
|
856
867
|
return this.colKeys;
|
857
868
|
};
|
858
869
|
|
859
870
|
PivotData.prototype.getRowKeys = function() {
|
860
|
-
this.
|
871
|
+
if (!this.isKeysSortingDoneOnBackendSide) {
|
872
|
+
this.sortKeys();
|
873
|
+
}
|
861
874
|
return this.rowKeys;
|
862
875
|
};
|
863
876
|
|