@datarailsshared/dr_renderer 1.2.416 → 1.2.417
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/highcharts_renderer.js +36 -17
- package/tests/highcharts_renderer.test.js +168 -2
package/package.json
CHANGED
@@ -859,7 +859,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
859
859
|
|
860
860
|
/* model renderers */
|
861
861
|
|
862
|
-
highchartsRenderer.tableCSVExportRenderer = function (pivotData) {
|
862
|
+
highchartsRenderer.tableCSVExportRenderer = function (pivotData, chartOptions) {
|
863
863
|
var aggregator, colAttrs, colKey, colKeys, i, j, rowAttrs, rowKey, rowKeys, tempAr,
|
864
864
|
totalAggregator, val;
|
865
865
|
|
@@ -867,11 +867,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
867
867
|
var forExport = [];
|
868
868
|
|
869
869
|
const TOTAL_CELL = 'Totals';
|
870
|
+
|
870
871
|
colAttrs = pivotData.colAttrs;
|
871
872
|
rowAttrs = pivotData.rowAttrs;
|
872
873
|
rowKeys = pivotData.getRowKeys();
|
873
874
|
colKeys = pivotData.getColKeys();
|
874
875
|
|
876
|
+
let isDisplayingColTotals = lodash.get(chartOptions, 'table_options.show_column_total') && colKeys.length;
|
877
|
+
let isDisplayingRowTotals = lodash.get(chartOptions, 'table_options.show_row_total') && rowKeys.length;
|
878
|
+
|
875
879
|
for (j in colAttrs) {
|
876
880
|
if (!hasProp.call(colAttrs, j)) continue;
|
877
881
|
tempAr = [];
|
@@ -888,7 +892,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
888
892
|
tempAr = tempAr.concat(lodash.map(colKeys, function (row) {
|
889
893
|
return row[j];
|
890
894
|
}));
|
891
|
-
|
895
|
+
|
896
|
+
if (isDisplayingRowTotals) {
|
897
|
+
tempAr.push(TOTAL_CELL);
|
898
|
+
}
|
899
|
+
|
892
900
|
forExport.push(tempAr);
|
893
901
|
}
|
894
902
|
|
@@ -911,31 +919,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
911
919
|
val = aggregator.value();
|
912
920
|
tempAr.push(val);
|
913
921
|
}
|
914
|
-
|
915
|
-
|
916
|
-
|
922
|
+
|
923
|
+
if (isDisplayingRowTotals) {
|
924
|
+
totalAggregator = pivotData.getAggregator(rowKey, []);
|
925
|
+
val = totalAggregator.value();
|
926
|
+
tempAr.push(val);
|
927
|
+
}
|
928
|
+
|
917
929
|
forExport.push(tempAr);
|
918
930
|
}
|
919
931
|
|
920
932
|
tempAr = [];
|
921
933
|
|
922
|
-
|
923
|
-
|
924
|
-
|
934
|
+
if (isDisplayingColTotals) {
|
935
|
+
for (j in rowAttrs) {
|
936
|
+
if (!hasProp.call(rowAttrs, j)) continue;
|
937
|
+
tempAr.push(TOTAL_CELL)
|
938
|
+
}
|
939
|
+
|
940
|
+
for (j in colKeys) {
|
941
|
+
if (!hasProp.call(colKeys, j)) continue;
|
942
|
+
colKey = colKeys[j];
|
943
|
+
aggregator = pivotData.getAggregator([], colKey);
|
944
|
+
val = aggregator.value();
|
945
|
+
tempAr.push(val);
|
946
|
+
}
|
925
947
|
}
|
926
948
|
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
aggregator = pivotData.getAggregator([], colKey);
|
931
|
-
val = aggregator.value();
|
949
|
+
if (isDisplayingColTotals && isDisplayingRowTotals) {
|
950
|
+
totalAggregator = pivotData.getAggregator([], []);
|
951
|
+
val = totalAggregator.value();
|
932
952
|
tempAr.push(val);
|
933
953
|
}
|
934
954
|
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
forExport.push(tempAr);
|
955
|
+
if (tempAr.length) {
|
956
|
+
forExport.push(tempAr);
|
957
|
+
}
|
939
958
|
|
940
959
|
return forExport;
|
941
960
|
};
|
@@ -5962,7 +5962,15 @@ describe('highcharts_renderer', () => {
|
|
5962
5962
|
|
5963
5963
|
describe('Function tableCSVExportRenderer', () => {
|
5964
5964
|
window._ = lodash;
|
5965
|
-
|
5965
|
+
|
5966
|
+
it('should create csv json object representation based on pivot data (only cols)', () => {
|
5967
|
+
const chartOptions = {
|
5968
|
+
table_options: {
|
5969
|
+
show_column_total: true,
|
5970
|
+
show_row_total: true,
|
5971
|
+
},
|
5972
|
+
};
|
5973
|
+
|
5966
5974
|
const inputs = [
|
5967
5975
|
{
|
5968
5976
|
"Date": 1653955200,
|
@@ -6026,7 +6034,7 @@ describe('highcharts_renderer', () => {
|
|
6026
6034
|
},
|
6027
6035
|
};
|
6028
6036
|
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
6029
|
-
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData);
|
6037
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
6030
6038
|
expect(csvJson).toEqual(
|
6031
6039
|
[
|
6032
6040
|
[ 1651363200, 1652400000, 1653177600, 1653955200, 'Totals' ],
|
@@ -6037,6 +6045,164 @@ describe('highcharts_renderer', () => {
|
|
6037
6045
|
]
|
6038
6046
|
);
|
6039
6047
|
});
|
6048
|
+
|
6049
|
+
describe('cases for both col and row present', () => {
|
6050
|
+
const inputs = [
|
6051
|
+
{
|
6052
|
+
"Date": 1653955200,
|
6053
|
+
"Type": 'Food',
|
6054
|
+
"Amount": 2849521.69
|
6055
|
+
},
|
6056
|
+
{
|
6057
|
+
"Date": 1653955200,
|
6058
|
+
"Type": 'Technology',
|
6059
|
+
"Amount": 321123
|
6060
|
+
},
|
6061
|
+
{
|
6062
|
+
"Date": 1653177600,
|
6063
|
+
"Type": 'Food',
|
6064
|
+
"Amount": 3141257.27
|
6065
|
+
},
|
6066
|
+
{
|
6067
|
+
"Date": 1653177600,
|
6068
|
+
"Type": 'Technology',
|
6069
|
+
"Amount": 4321
|
6070
|
+
},
|
6071
|
+
{
|
6072
|
+
"Date": 1653955200,
|
6073
|
+
"Amount": 123
|
6074
|
+
},
|
6075
|
+
{
|
6076
|
+
"Type": 'Technology',
|
6077
|
+
"Amount": 1
|
6078
|
+
},
|
6079
|
+
{
|
6080
|
+
"Type": 'Food',
|
6081
|
+
"Amount": 2
|
6082
|
+
},
|
6083
|
+
{
|
6084
|
+
"Date": 1653177600,
|
6085
|
+
"Amount": 321
|
6086
|
+
},
|
6087
|
+
{
|
6088
|
+
"Amount": 9834311.05
|
6089
|
+
},
|
6090
|
+
{
|
6091
|
+
"col_keys": [
|
6092
|
+
[
|
6093
|
+
1651363200
|
6094
|
+
],
|
6095
|
+
[
|
6096
|
+
1653177600
|
6097
|
+
],
|
6098
|
+
],
|
6099
|
+
"row_keys": [
|
6100
|
+
[
|
6101
|
+
'Food'
|
6102
|
+
],
|
6103
|
+
[
|
6104
|
+
'Technology'
|
6105
|
+
]
|
6106
|
+
]
|
6107
|
+
}
|
6108
|
+
];
|
6109
|
+
const subOptions = {
|
6110
|
+
"sorters": () => null,
|
6111
|
+
"sortByValueAttrs": [],
|
6112
|
+
"cols": ["Date"],
|
6113
|
+
"rows": ["Type"],
|
6114
|
+
"colFormats": [
|
6115
|
+
{
|
6116
|
+
"type": "Date",
|
6117
|
+
"name": "Date",
|
6118
|
+
"val_not_convert": []
|
6119
|
+
},
|
6120
|
+
],
|
6121
|
+
"rowFormats": [
|
6122
|
+
{
|
6123
|
+
"type": "Text",
|
6124
|
+
"name": "Type",
|
6125
|
+
"val_not_convert": []
|
6126
|
+
},
|
6127
|
+
],
|
6128
|
+
"rendererOptions": {
|
6129
|
+
},
|
6130
|
+
};
|
6131
|
+
|
6132
|
+
it('should create csv json object representation based on pivot data, with totals', () => {
|
6133
|
+
const chartOptions = {
|
6134
|
+
table_options: {
|
6135
|
+
show_column_total: true,
|
6136
|
+
show_row_total: true,
|
6137
|
+
},
|
6138
|
+
};
|
6139
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
6140
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
6141
|
+
expect(csvJson).toEqual(
|
6142
|
+
[
|
6143
|
+
["Date", 1653177600, 1653955200, "Totals"],
|
6144
|
+
["Type"],
|
6145
|
+
["Food", 1, 1, 1],
|
6146
|
+
["Technology", 1, 1, 1],
|
6147
|
+
["Totals", 1, 1, 2]
|
6148
|
+
]
|
6149
|
+
);
|
6150
|
+
});
|
6151
|
+
|
6152
|
+
it('should create csv json object representation based on pivot data, without col totals', () => {
|
6153
|
+
const chartOptions = {
|
6154
|
+
table_options: {
|
6155
|
+
show_column_total: false,
|
6156
|
+
show_row_total: true,
|
6157
|
+
},
|
6158
|
+
};
|
6159
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
6160
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
6161
|
+
expect(csvJson).toEqual([
|
6162
|
+
["Date", 1653177600, 1653955200, "Totals"],
|
6163
|
+
["Type"],
|
6164
|
+
["Food", 1, 1, 1],
|
6165
|
+
["Technology", 1, 1, 1]
|
6166
|
+
]);
|
6167
|
+
});
|
6168
|
+
|
6169
|
+
it('should create csv json object representation based on pivot data, without row totals', () => {
|
6170
|
+
const chartOptions = {
|
6171
|
+
table_options: {
|
6172
|
+
show_column_total: true,
|
6173
|
+
show_row_total: false,
|
6174
|
+
},
|
6175
|
+
};
|
6176
|
+
|
6177
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
6178
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
6179
|
+
expect(csvJson).toEqual([
|
6180
|
+
["Date", 1653177600, 1653955200],
|
6181
|
+
["Type"],
|
6182
|
+
["Food", 1, 1],
|
6183
|
+
["Technology", 1, 1],
|
6184
|
+
["Totals", 1, 1]
|
6185
|
+
]);
|
6186
|
+
});
|
6187
|
+
|
6188
|
+
it('should create csv json object representation based on pivot data, without col and row totals', () => {
|
6189
|
+
const chartOptions = {
|
6190
|
+
table_options: {
|
6191
|
+
show_column_total: false,
|
6192
|
+
show_row_total: false,
|
6193
|
+
},
|
6194
|
+
};
|
6195
|
+
|
6196
|
+
const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
|
6197
|
+
const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
|
6198
|
+
expect(csvJson).toEqual([
|
6199
|
+
["Date", 1653177600, 1653955200],
|
6200
|
+
["Type"],
|
6201
|
+
["Food", 1, 1],
|
6202
|
+
["Technology", 1, 1],
|
6203
|
+
]);
|
6204
|
+
});
|
6205
|
+
});
|
6040
6206
|
});
|
6041
6207
|
|
6042
6208
|
describe("Function returnRawDataValue", () => {
|