dtable-statistic 5.0.0 → 5.0.1
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/es/assets/css/dashboard.css +1 -0
- package/es/assets/css/dialog.css +35 -0
- package/es/components/dialog/chart-edit-dialog.js +93 -0
- package/es/components/dialog/enlarged-chart-dialog.js +8 -13
- package/es/components/dialog/statistic-record-dialog/index.js +27 -35
- package/es/components/dialog/table-select-dialog.js +3 -3
- package/es/components/dropdown-menu/statistic-dropdown-menu.js +2 -2
- package/es/constants/index.js +3 -499
- package/es/dashboard.js +9 -87
- package/es/desktop-dashboard.js +51 -32
- package/es/index.js +56 -1
- package/es/mobile-dashboard.js +8 -16
- package/es/model/conver-statItem.js +124 -0
- package/es/service/chart-service.js +8 -27
- package/es/service/dashboard-service.js +25 -29
- package/es/stat-list/chart-preview.js +19 -20
- package/es/stat-list/index.js +17 -23
- package/es/stat-view/index.js +47 -156
- package/es/tabs/tab.js +18 -15
- package/es/utils/common-utils.js +2 -352
- package/es/utils/export-table-utils.js +0 -69
- package/es/utils/index.js +12 -89
- package/package.json +6 -9
- package/es/assets/css/color-picker.css +0 -53
- package/es/assets/css/color-rules-popover.css +0 -144
- package/es/assets/css/slider.css +0 -77
- package/es/assets/css/statistic-chart.module.css +0 -11
- package/es/assets/css/statistic-custom-title.module.css +0 -3
- package/es/assets/css/statistic-custom.module.css +0 -4
- package/es/assets/css/statistic-numeric-column-item.module.css +0 -43
- package/es/assets/css/statistic-time-picker.module.css +0 -21
- package/es/calculator/base-calculator.js +0 -80
- package/es/calculator/basic-chart-calculator.js +0 -349
- package/es/calculator/combination-calculator.js +0 -246
- package/es/calculator/compare-bar-calculator.js +0 -197
- package/es/calculator/completeness-calculator.js +0 -215
- package/es/calculator/copy-value.js +0 -53
- package/es/calculator/dashboard-calculator.js +0 -70
- package/es/calculator/heat-map-calculator.js +0 -148
- package/es/calculator/horizontal-bar-calculator.js +0 -67
- package/es/calculator/index.js +0 -81
- package/es/calculator/map-calculator.js +0 -103
- package/es/calculator/mirror-calculator.js +0 -146
- package/es/calculator/number-card-calculator.js +0 -60
- package/es/calculator/pivot-table-calculator.js +0 -821
- package/es/calculator/scatter-calculator.js +0 -75
- package/es/calculator/thread-manager.js +0 -57
- package/es/calculator/trend-calculator.js +0 -113
- package/es/calculator/workers/basic-chart-calculator-worker.js +0 -495
- package/es/calculator/workers/calculator.worker.js +0 -44
- package/es/calculator/workers/card-calculator-worker.js +0 -40
- package/es/calculator/workers/combination-calculator-worker.js +0 -276
- package/es/calculator/workers/compare-bar-chart-calculator-worker.js +0 -150
- package/es/calculator/workers/completeness-calculator-worker.js +0 -208
- package/es/calculator/workers/dashboard-calculator-worker.js +0 -68
- package/es/calculator/workers/mirror-calculator-worker.js +0 -152
- package/es/calculator/workers/pivot-table-calculator-worker.js +0 -718
- package/es/calculator/workers/scatter-calculator-worker.js +0 -80
- package/es/calculator/workers/trend-calculator-worker.js +0 -108
- package/es/calculator/world-map-calculator.js +0 -124
- package/es/components/dialog/chart-addition-edit-dialog.js +0 -90
- package/es/components/dialog/chart-addition-widgets/chart-selector.js +0 -259
- package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +0 -83
- package/es/components/dialog/statistic-types-dialog/index.css +0 -14
- package/es/components/dialog/statistic-types-dialog/index.js +0 -62
- package/es/components/popover/color-rules/color-rule.js +0 -183
- package/es/components/popover/color-rules/index.js +0 -87
- package/es/components/popover/color-rules/rule-filters/filter.js +0 -221
- package/es/components/popover/color-rules/rule-filters/index.css +0 -210
- package/es/components/popover/color-rules/rule-filters/index.js +0 -97
- package/es/components/popover/color-rules/rule-filters/number-input.js +0 -78
- package/es/components/popover/color-rules-popover.js +0 -218
- package/es/components/popover/color-selector-popover.js +0 -83
- package/es/constants/color-rules.js +0 -17
- package/es/constants/map.js +0 -13
- package/es/constants/model.js +0 -26
- package/es/constants/regions.js +0 -2111
- package/es/constants/zIndexes.js +0 -7
- package/es/custom-g2.js +0 -644
- package/es/model/bar-group.js +0 -58
- package/es/model/bar.js +0 -47
- package/es/model/base-model.js +0 -18
- package/es/model/basic-number-card.js +0 -25
- package/es/model/combination.js +0 -48
- package/es/model/compare-bar.js +0 -56
- package/es/model/completeness-group.js +0 -31
- package/es/model/completeness.js +0 -25
- package/es/model/custom-bar.js +0 -25
- package/es/model/dashboard.js +0 -20
- package/es/model/generic-model.js +0 -222
- package/es/model/heat-map.js +0 -33
- package/es/model/horizontal-bar-group.js +0 -55
- package/es/model/horizontal-bar.js +0 -47
- package/es/model/index.js +0 -187
- package/es/model/map.js +0 -38
- package/es/model/mirror.js +0 -33
- package/es/model/pie.js +0 -38
- package/es/model/ring.js +0 -40
- package/es/model/scatter.js +0 -22
- package/es/model/table.js +0 -32
- package/es/model/trend.js +0 -32
- package/es/model/world-map.js +0 -34
- package/es/service/map-json.js +0 -140
- package/es/stat-editor/chart-name-editor.js +0 -68
- package/es/stat-editor/index.js +0 -75
- package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +0 -153
- package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +0 -422
- package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +0 -203
- package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +0 -23
- package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +0 -104
- package/es/stat-editor/stat-settings/advance-chart-settings/index.js +0 -334
- package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +0 -119
- package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +0 -132
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +0 -240
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +0 -89
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +0 -138
- package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +0 -331
- package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +0 -143
- package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +0 -109
- package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +0 -153
- package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +0 -144
- package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +0 -214
- package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +0 -121
- package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +0 -172
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +0 -366
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +0 -142
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +0 -150
- package/es/stat-editor/stat-settings/basic-chart-settings/index.js +0 -473
- package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +0 -182
- package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +0 -564
- package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +0 -112
- package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +0 -87
- package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +0 -187
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +0 -300
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +0 -113
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +0 -289
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +0 -58
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +0 -359
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +0 -48
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +0 -121
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +0 -143
- package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +0 -269
- package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +0 -104
- package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +0 -366
- package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +0 -55
- package/es/stat-editor/stat-settings/color-setting/color-picker.js +0 -130
- package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +0 -374
- package/es/stat-editor/stat-settings/map/map-level.js +0 -72
- package/es/stat-editor/stat-settings/map/map-province-city.js +0 -151
- package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +0 -108
- package/es/stat-editor/stat-settings/public-setting/base-settings.js +0 -154
- package/es/stat-editor/stat-settings/public-setting/calender.js +0 -125
- package/es/stat-editor/stat-settings/public-setting/column-settings.js +0 -24
- package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +0 -62
- package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +0 -61
- package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +0 -35
- package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +0 -60
- package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +0 -123
- package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +0 -33
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.css +0 -29
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +0 -82
- package/es/stat-view/area-chart.js +0 -551
- package/es/stat-view/bar-chart.js +0 -582
- package/es/stat-view/base-chart.js +0 -132
- package/es/stat-view/basic-number-card.js +0 -201
- package/es/stat-view/combination-chart.js +0 -546
- package/es/stat-view/compare-chart.js +0 -483
- package/es/stat-view/completeness-chart.js +0 -390
- package/es/stat-view/custom-bar.js +0 -418
- package/es/stat-view/dashboard-chart.js +0 -266
- package/es/stat-view/heat-map.js +0 -463
- package/es/stat-view/horizontal-bar-chart.js +0 -562
- package/es/stat-view/line-chart.js +0 -518
- package/es/stat-view/map.js +0 -448
- package/es/stat-view/mirror.js +0 -275
- package/es/stat-view/pie-chart.js +0 -290
- package/es/stat-view/pivot-table/index.js +0 -196
- package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +0 -156
- package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +0 -176
- package/es/stat-view/pivot-table/pivot-table-display-name.js +0 -215
- package/es/stat-view/pivot-table/statistic-pivot-table.module.css +0 -132
- package/es/stat-view/pivot-table/two-dimension-table.js +0 -384
- package/es/stat-view/ring-chart.js +0 -392
- package/es/stat-view/scatter-chart.js +0 -306
- package/es/stat-view/treemap-chart.js +0 -253
- package/es/stat-view/trend-chart.js +0 -249
- package/es/stat-view/world-map.js +0 -431
- package/es/utils/basic-chart-utils.js +0 -29
- package/es/utils/cell-format.js +0 -115
- package/es/utils/collaborator.js +0 -50
- package/es/utils/color-utils.js +0 -134
- package/es/utils/column-utils.js +0 -110
- package/es/utils/column.js +0 -20
- package/es/utils/date-format.js +0 -71
- package/es/utils/map.js +0 -114
- package/es/utils/model.js +0 -19
- package/es/utils/row-utils.js +0 -134
- package/es/utils/search.js +0 -73
- package/es/utils/sql-utils.js +0 -359
- package/es/utils/stat-utils.js +0 -351
- package/es/utils/trend-utils.js +0 -135
|
@@ -1,718 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = calculateStatItem;
|
|
8
|
-
var _dtableUtils = require("dtable-utils");
|
|
9
|
-
var _constants = require("../../constants");
|
|
10
|
-
var _commonUtils = require("../../utils/common-utils");
|
|
11
|
-
var _rowUtils = require("../../utils/row-utils");
|
|
12
|
-
var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
|
|
13
|
-
function calculateStatItem(chart, value, _ref) {
|
|
14
|
-
let {
|
|
15
|
-
getViewRows,
|
|
16
|
-
getTableFormulaResults
|
|
17
|
-
} = _ref;
|
|
18
|
-
const {
|
|
19
|
-
groupby_column_key,
|
|
20
|
-
column_groupby_column_key
|
|
21
|
-
} = chart;
|
|
22
|
-
if (!groupby_column_key) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
if (!column_groupby_column_key) {
|
|
26
|
-
return calculateOneDimensionTable(chart, value, {
|
|
27
|
-
getViewRows,
|
|
28
|
-
getTableFormulaResults
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return calculateTwoDimensionTable(chart, value, {
|
|
32
|
-
getViewRows,
|
|
33
|
-
getTableFormulaResults
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async function calculateOneDimensionTable(chart, value, _ref2) {
|
|
37
|
-
let {
|
|
38
|
-
getViewRows,
|
|
39
|
-
getTableFormulaResults
|
|
40
|
-
} = _ref2;
|
|
41
|
-
const {
|
|
42
|
-
table_id,
|
|
43
|
-
view_id,
|
|
44
|
-
summary_type,
|
|
45
|
-
summary_method,
|
|
46
|
-
summary_column_key,
|
|
47
|
-
groupby_column_key,
|
|
48
|
-
groupby_include_empty_cells: include_empty,
|
|
49
|
-
groupby_date_granularity,
|
|
50
|
-
groupby_geolocation_granularity,
|
|
51
|
-
summary_columns_option
|
|
52
|
-
} = chart;
|
|
53
|
-
const table = (0, _dtableUtils.getTableById)(value.tables, table_id);
|
|
54
|
-
const view = table && (0, _dtableUtils.getViewById)(table.views, view_id);
|
|
55
|
-
const column = (0, _dtableUtils.getTableColumnByKey)(table, groupby_column_key);
|
|
56
|
-
if (!column) return {};
|
|
57
|
-
const isColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(column);
|
|
58
|
-
const statRows = await getViewRows(view, table);
|
|
59
|
-
const formulaRows = await getTableFormulaResults(table, statRows);
|
|
60
|
-
let pivot_rows = [];
|
|
61
|
-
statRows.forEach(row => {
|
|
62
|
-
const {
|
|
63
|
-
_id: rowId
|
|
64
|
-
} = row;
|
|
65
|
-
const formulaRow = formulaRows[rowId];
|
|
66
|
-
if ((0, _rowUtils.isValidRow)(row, formulaRow, column, include_empty)) {
|
|
67
|
-
const name = _statUtils.default.getGroupLabel(row[column.key], formulaRow, column, groupby_date_granularity, groupby_geolocation_granularity, value);
|
|
68
|
-
let pivotRowIndex;
|
|
69
|
-
if (isColumnDataAsAnArray) {
|
|
70
|
-
if (name.length === 0 && include_empty) {
|
|
71
|
-
let pivotRowIndex = pivot_rows.findIndex(r => !r.name);
|
|
72
|
-
updateOneDimensionRows(pivot_rows, pivotRowIndex, null, row);
|
|
73
|
-
} else {
|
|
74
|
-
name.forEach(n => {
|
|
75
|
-
pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
76
|
-
updateOneDimensionRows(pivot_rows, pivotRowIndex, n, row);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
pivotRowIndex = pivot_rows.findIndex(pivotRow => {
|
|
81
|
-
return isSameName(pivotRow.name, name);
|
|
82
|
-
});
|
|
83
|
-
updateOneDimensionRows(pivot_rows, pivotRowIndex, name, row);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const summary_columns_option_keys = Array.isArray(summary_columns_option) ? summary_columns_option.map(option => option.key) : [];
|
|
88
|
-
const statisticColumnKeys = [summary_column_key, ...summary_columns_option_keys];
|
|
89
|
-
const validStatisticColumnKeys = statisticColumnKeys;
|
|
90
|
-
let statisticColumns = validStatisticColumnKeys.map(key => {
|
|
91
|
-
const column = (0, _dtableUtils.getTableColumnByKey)(table, key);
|
|
92
|
-
return column ? {
|
|
93
|
-
...column
|
|
94
|
-
} : null;
|
|
95
|
-
}).filter(Boolean);
|
|
96
|
-
if (statisticColumns.length > 0) {
|
|
97
|
-
statisticColumns[0].method = summary_method;
|
|
98
|
-
}
|
|
99
|
-
Array.isArray(summary_columns_option) && summary_columns_option.forEach((option, index) => {
|
|
100
|
-
if (statisticColumns[index + 1]) {
|
|
101
|
-
statisticColumns[index + 1].method = option.method;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const {
|
|
105
|
-
pivot_columns_total
|
|
106
|
-
} = getOneDimensionTotal(statisticColumns, summary_type, formulaRows, pivot_rows);
|
|
107
|
-
_statUtils.default.sortStatistics(pivot_rows, column, 'name');
|
|
108
|
-
const pivot_columns = summary_type === _constants.SUMMARY_TYPE.COUNT ? [] : statisticColumns.map(column => {
|
|
109
|
-
return {
|
|
110
|
-
key: column.key,
|
|
111
|
-
method: column.method
|
|
112
|
-
};
|
|
113
|
-
}).filter(item => (0, _dtableUtils.getTableColumnByKey)(table, item.key));
|
|
114
|
-
pivot_rows.forEach(row => {
|
|
115
|
-
row.original_name = row.name;
|
|
116
|
-
row.name = (0, _rowUtils.getFormattedLabel)(column, row.name, value.collaborators);
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
pivot_columns_total,
|
|
120
|
-
pivot_rows,
|
|
121
|
-
pivot_columns,
|
|
122
|
-
formulaRows
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function updateOneDimensionRows(pivot_rows, index, name, row) {
|
|
126
|
-
if (index > -1) {
|
|
127
|
-
let updatedPivotRow = pivot_rows[index];
|
|
128
|
-
updatedPivotRow.rows.push(row);
|
|
129
|
-
pivot_rows[index] = updatedPivotRow;
|
|
130
|
-
} else {
|
|
131
|
-
const updatedPivotRow = {
|
|
132
|
-
name,
|
|
133
|
-
original_name: name,
|
|
134
|
-
rows: [row]
|
|
135
|
-
};
|
|
136
|
-
pivot_rows.push(updatedPivotRow);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
140
|
-
let statResult = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
141
|
-
let pivot_columns_total = {};
|
|
142
|
-
let dateColumnsTotalArr = {};
|
|
143
|
-
if (Array.isArray(columns) && columns.length > 0) {
|
|
144
|
-
columns.forEach(column => {
|
|
145
|
-
if (column && (0, _dtableUtils.isDateColumn)(column)) {
|
|
146
|
-
dateColumnsTotalArr[column.key] = [];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
Array.isArray(statResult) && statResult.forEach((item, index) => {
|
|
151
|
-
const {
|
|
152
|
-
rows
|
|
153
|
-
} = item;
|
|
154
|
-
let updated = {
|
|
155
|
-
...item
|
|
156
|
-
};
|
|
157
|
-
let totalMap = {};
|
|
158
|
-
if (summary_type === _constants.SUMMARY_TYPE.COUNT) {
|
|
159
|
-
totalMap['total'] = rows.length;
|
|
160
|
-
pivot_columns_total.total = (pivot_columns_total['total'] || 0) + rows.length;
|
|
161
|
-
} else {
|
|
162
|
-
if (Array.isArray(columns)) {
|
|
163
|
-
if (columns.length === 1) {
|
|
164
|
-
const summaryColumn = columns[0];
|
|
165
|
-
const {
|
|
166
|
-
key,
|
|
167
|
-
method
|
|
168
|
-
} = summaryColumn;
|
|
169
|
-
const total = getTotal(summaryColumn, summary_type, method, rows, formula_rows);
|
|
170
|
-
if (summaryColumn && (0, _dtableUtils.isDateColumn)(summaryColumn)) {
|
|
171
|
-
if (method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
172
|
-
totalMap['total'] = total;
|
|
173
|
-
} else {
|
|
174
|
-
totalMap['total'] = total === 0 ? 0 : total.date;
|
|
175
|
-
if (total !== 0) {
|
|
176
|
-
dateColumnsTotalArr[key].push(total);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (method === _constants.SUMMARY_METHOD_MAP.Max) {
|
|
180
|
-
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], _constants.SUMMARY_METHOD_MAP.Max).date;
|
|
181
|
-
} else if (method === _constants.SUMMARY_METHOD_MAP.Min) {
|
|
182
|
-
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], _constants.SUMMARY_METHOD_MAP.Min).date;
|
|
183
|
-
} else if (method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
184
|
-
const pivotColumnTotal = (pivot_columns_total['total'] ? pivot_columns_total['total'] - 0 : 0) + total;
|
|
185
|
-
pivot_columns_total['total'] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
const validTotal = total ? total - 0 : 0;
|
|
189
|
-
totalMap['total'] = validTotal;
|
|
190
|
-
const pivotColumnTotal = (pivot_columns_total['total'] ? pivot_columns_total['total'] - 0 : 0) + validTotal;
|
|
191
|
-
pivot_columns_total['total'] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
columns.forEach(column => {
|
|
195
|
-
const {
|
|
196
|
-
key,
|
|
197
|
-
method
|
|
198
|
-
} = column;
|
|
199
|
-
const totalKey = key + method;
|
|
200
|
-
const total = getTotal(column, summary_type, method, rows, formula_rows);
|
|
201
|
-
if (column && (0, _dtableUtils.isDateColumn)(column)) {
|
|
202
|
-
if (method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
203
|
-
totalMap[totalKey] = total;
|
|
204
|
-
} else {
|
|
205
|
-
totalMap[totalKey] = total === 0 ? 0 : total.date;
|
|
206
|
-
if (total !== 0) {
|
|
207
|
-
dateColumnsTotalArr[key].push(total);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (method === _constants.SUMMARY_METHOD_MAP.Max) {
|
|
211
|
-
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], _constants.SUMMARY_METHOD_MAP.Max).date;
|
|
212
|
-
} else if (method === _constants.SUMMARY_METHOD_MAP.Min) {
|
|
213
|
-
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], _constants.SUMMARY_METHOD_MAP.Min).date;
|
|
214
|
-
} else if (method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
215
|
-
const pivotColumnTotal = (pivot_columns_total[totalKey] ? pivot_columns_total[totalKey] - 0 : 0) + total;
|
|
216
|
-
pivot_columns_total[totalKey] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
const validTotal = total ? total - 0 : 0;
|
|
220
|
-
totalMap[totalKey] = validTotal;
|
|
221
|
-
const pivotColumnTotal = (pivot_columns_total[totalKey] ? pivot_columns_total[totalKey] - 0 : 0) + validTotal;
|
|
222
|
-
pivot_columns_total[totalKey] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
updated.total = totalMap;
|
|
229
|
-
statResult[index] = updated;
|
|
230
|
-
});
|
|
231
|
-
return {
|
|
232
|
-
pivot_columns_total
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
async function calculateTwoDimensionTable(chart, value, _ref3) {
|
|
236
|
-
let {
|
|
237
|
-
getViewRows,
|
|
238
|
-
getTableFormulaResults
|
|
239
|
-
} = _ref3;
|
|
240
|
-
const {
|
|
241
|
-
table_id,
|
|
242
|
-
view_id,
|
|
243
|
-
summary_type,
|
|
244
|
-
summary_method,
|
|
245
|
-
summary_column_key,
|
|
246
|
-
groupby_column_key,
|
|
247
|
-
groupby_include_empty_cells: include_empty,
|
|
248
|
-
groupby_date_granularity,
|
|
249
|
-
groupby_geolocation_granularity,
|
|
250
|
-
column_groupby_column_key,
|
|
251
|
-
column_groupby_date_granularity,
|
|
252
|
-
column_groupby_geolocation_granularity,
|
|
253
|
-
summary_columns_option
|
|
254
|
-
} = chart;
|
|
255
|
-
const table = (0, _dtableUtils.getTableById)(value.tables, table_id);
|
|
256
|
-
const view = table && (0, _dtableUtils.getViewById)(table.views, view_id);
|
|
257
|
-
if (!view) return;
|
|
258
|
-
const groupbyColumn = (0, _dtableUtils.getTableColumnByKey)(table, groupby_column_key);
|
|
259
|
-
if (!groupbyColumn) return;
|
|
260
|
-
const isGroupbyColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(groupbyColumn);
|
|
261
|
-
const rowGroupbyColumn = (0, _dtableUtils.getTableColumnByKey)(table, column_groupby_column_key);
|
|
262
|
-
if (!rowGroupbyColumn) {
|
|
263
|
-
return calculateOneDimensionTable(chart, value);
|
|
264
|
-
}
|
|
265
|
-
const isRowGroupbyColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(rowGroupbyColumn);
|
|
266
|
-
const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key);
|
|
267
|
-
const statRows = await getViewRows(view, table);
|
|
268
|
-
const formulaRows = await getTableFormulaResults(table, statRows);
|
|
269
|
-
const pivot_summary_multiple_columns = [];
|
|
270
|
-
summary_columns_option.forEach(item => {
|
|
271
|
-
const column = (0, _dtableUtils.getTableColumnByKey)(table, item.key);
|
|
272
|
-
if (column && (0, _dtableUtils.isNumericColumn)(column)) {
|
|
273
|
-
pivot_summary_multiple_columns.push({
|
|
274
|
-
key: item.key,
|
|
275
|
-
type: column.type,
|
|
276
|
-
data: column.data,
|
|
277
|
-
method: item.method,
|
|
278
|
-
column_name: column.name
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
// [{key: null}, {key: cell_value}, {key: cell_value}, ...]
|
|
284
|
-
let pivot_columns = [];
|
|
285
|
-
|
|
286
|
-
// [
|
|
287
|
-
// {
|
|
288
|
-
// name: '',
|
|
289
|
-
// cells: {
|
|
290
|
-
// [key1]: {rows: [], total: ''},
|
|
291
|
-
// [key2]: {rows: [], total: ''},
|
|
292
|
-
// [key3]: {rows: [], total: ''},
|
|
293
|
-
// }
|
|
294
|
-
// },
|
|
295
|
-
// ...
|
|
296
|
-
// ]
|
|
297
|
-
let pivot_rows = [];
|
|
298
|
-
statRows.forEach(row => {
|
|
299
|
-
const {
|
|
300
|
-
_id: rowId
|
|
301
|
-
} = row;
|
|
302
|
-
const formulaRow = formulaRows[rowId];
|
|
303
|
-
const cellValueForColumn = _statUtils.default.getGroupLabel(row[rowGroupbyColumn.key], formulaRow, rowGroupbyColumn, column_groupby_date_granularity, column_groupby_geolocation_granularity, value);
|
|
304
|
-
if ((0, _rowUtils.isValidRow)(row, formulaRow, rowGroupbyColumn, include_empty)) {
|
|
305
|
-
updateTwoDimensionColumns(value, pivot_columns, rowGroupbyColumn, row, formulaRow, include_empty, column_groupby_date_granularity, column_groupby_geolocation_granularity, isRowGroupbyColumnDataAsAnArray);
|
|
306
|
-
}
|
|
307
|
-
if ((0, _rowUtils.isValidRow)(row, formulaRow, groupbyColumn, include_empty)) {
|
|
308
|
-
const name = _statUtils.default.getGroupLabel(row[groupbyColumn.key], formulaRow, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, value);
|
|
309
|
-
let pivotRowIndex;
|
|
310
|
-
if (isGroupbyColumnDataAsAnArray) {
|
|
311
|
-
if (name.length === 0 && include_empty) {
|
|
312
|
-
let pivotRowIndex = pivot_rows.findIndex(r => !r.name);
|
|
313
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, null, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
314
|
-
} else {
|
|
315
|
-
name.forEach(n => {
|
|
316
|
-
pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
317
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
pivotRowIndex = pivot_rows.findIndex(pivotRow => {
|
|
322
|
-
return isSameName(pivotRow.name, name);
|
|
323
|
-
});
|
|
324
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, name, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
let {
|
|
329
|
-
pivot_columns_total,
|
|
330
|
-
pivot_table_total
|
|
331
|
-
} = getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formulaRows, pivot_rows, pivot_columns);
|
|
332
|
-
_statUtils.default.sortStatistics(pivot_rows, groupbyColumn, 'name');
|
|
333
|
-
_statUtils.default.sortStatistics(pivot_columns, rowGroupbyColumn, 'key');
|
|
334
|
-
|
|
335
|
-
// format shown label(name)
|
|
336
|
-
const map = {};
|
|
337
|
-
pivot_columns.forEach(column => {
|
|
338
|
-
const name = (0, _rowUtils.getFormattedLabel)(rowGroupbyColumn, column.key, value.collaborators);
|
|
339
|
-
map[column.key] = name;
|
|
340
|
-
column.key = name;
|
|
341
|
-
});
|
|
342
|
-
pivot_rows.forEach(row => {
|
|
343
|
-
row.name = (0, _rowUtils.getFormattedLabel)(groupbyColumn, row.name, value.collaborators);
|
|
344
|
-
const cells = {};
|
|
345
|
-
Object.keys(row.cells).forEach(key => {
|
|
346
|
-
cells[map[key]] = row.cells[key];
|
|
347
|
-
});
|
|
348
|
-
row.cells = cells;
|
|
349
|
-
});
|
|
350
|
-
const new_pivot_columns_total = {};
|
|
351
|
-
Object.keys(pivot_columns_total).forEach(key => {
|
|
352
|
-
new_pivot_columns_total[map[key]] = pivot_columns_total[key];
|
|
353
|
-
});
|
|
354
|
-
return {
|
|
355
|
-
pivot_rows,
|
|
356
|
-
pivot_columns,
|
|
357
|
-
pivot_columns_total: new_pivot_columns_total,
|
|
358
|
-
pivot_table_total,
|
|
359
|
-
pivot_summary_multiple_columns,
|
|
360
|
-
formulaRows
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function updateTwoDimensionColumns(value, pivot_columns, column, row, formulaRow, isIncludeEmpty, dateGranularity, geolocationGranularity, isRowGroupbyColumnDataAsAnArray) {
|
|
364
|
-
let key = _statUtils.default.getGroupLabel(row[column.key], formulaRow, column, dateGranularity, geolocationGranularity, value);
|
|
365
|
-
let pivotColumnIndex;
|
|
366
|
-
if (isRowGroupbyColumnDataAsAnArray) {
|
|
367
|
-
if (key.length === 0 && isIncludeEmpty) {
|
|
368
|
-
pivotColumnIndex = pivot_columns.findIndex(r => !r.key);
|
|
369
|
-
if (pivotColumnIndex < 0) {
|
|
370
|
-
pivot_columns.unshift({
|
|
371
|
-
key: null,
|
|
372
|
-
original_key: null
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
} else {
|
|
376
|
-
key.forEach(k => {
|
|
377
|
-
pivotColumnIndex = pivot_columns.findIndex(r => r.key === k);
|
|
378
|
-
if (pivotColumnIndex < 0) {
|
|
379
|
-
pivot_columns.push({
|
|
380
|
-
key: k,
|
|
381
|
-
original_key: k
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
} else {
|
|
387
|
-
pivotColumnIndex = pivot_columns.findIndex(r => {
|
|
388
|
-
let resKey = r.key;
|
|
389
|
-
return resKey === null && key === null || resKey === undefined && key === undefined || resKey === 0 && key === 0 || resKey === key;
|
|
390
|
-
});
|
|
391
|
-
if (pivotColumnIndex < 0) {
|
|
392
|
-
pivot_columns.push({
|
|
393
|
-
key,
|
|
394
|
-
original_key: key
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isColumnDataAsAnArray, cellValue) {
|
|
400
|
-
if (index > -1) {
|
|
401
|
-
let updatedPivotRow = pivot_rows[index];
|
|
402
|
-
let {
|
|
403
|
-
cells
|
|
404
|
-
} = updatedPivotRow;
|
|
405
|
-
pivot_columns.forEach(c => {
|
|
406
|
-
let {
|
|
407
|
-
key
|
|
408
|
-
} = c;
|
|
409
|
-
if (isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
410
|
-
if (cells[key]) {
|
|
411
|
-
cells[key].rows.push(row);
|
|
412
|
-
} else {
|
|
413
|
-
cells[key] = {
|
|
414
|
-
rows: [row]
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
updatedPivotRow.cells = cells;
|
|
420
|
-
pivot_rows[index] = updatedPivotRow;
|
|
421
|
-
} else {
|
|
422
|
-
let cells = {};
|
|
423
|
-
pivot_columns.forEach(c => {
|
|
424
|
-
let {
|
|
425
|
-
key
|
|
426
|
-
} = c;
|
|
427
|
-
if (isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
428
|
-
cells[key] = {
|
|
429
|
-
rows: [row]
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
pivot_rows.push({
|
|
434
|
-
name,
|
|
435
|
-
original_name: name,
|
|
436
|
-
cells
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function isSameName(prevName, currName) {
|
|
441
|
-
if ((0, _dtableUtils.isNumber)(prevName) && (0, _dtableUtils.isNumber)(currName)) {
|
|
442
|
-
return prevName === currName;
|
|
443
|
-
}
|
|
444
|
-
if (!prevName && !currName) {
|
|
445
|
-
return prevName === null && currName === null || prevName === undefined && currName === undefined || isNaN(prevName) && isNaN(currName);
|
|
446
|
-
}
|
|
447
|
-
return prevName === currName;
|
|
448
|
-
}
|
|
449
|
-
function isSameGroup(isColumnDataAsAnArray, source, target) {
|
|
450
|
-
if (isColumnDataAsAnArray) {
|
|
451
|
-
return (!source || source.length === 0) && !target || source && source.includes(target);
|
|
452
|
-
}
|
|
453
|
-
return source === null && target === null || source === undefined && target === undefined || source === target;
|
|
454
|
-
}
|
|
455
|
-
function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formula_rows) {
|
|
456
|
-
let pivot_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
457
|
-
let pivot_columns = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
458
|
-
let pivot_columns_total = {};
|
|
459
|
-
let pivot_table_total = 0;
|
|
460
|
-
let dateColumnsTotalArr = [];
|
|
461
|
-
let {
|
|
462
|
-
type: summary_column_type
|
|
463
|
-
} = summaryColumn || {};
|
|
464
|
-
const isSummaryDateColumn = summaryColumn && (0, _dtableUtils.isDateColumn)(summaryColumn);
|
|
465
|
-
let date_summary_column_format = isSummaryDateColumn ? summaryColumn.data.format : '';
|
|
466
|
-
Array.isArray(pivot_rows) && pivot_rows.forEach(pivotRow => {
|
|
467
|
-
let {
|
|
468
|
-
cells
|
|
469
|
-
} = pivotRow;
|
|
470
|
-
let total = 0;
|
|
471
|
-
Array.isArray(pivot_columns) && pivot_columns.forEach(pivotColumn => {
|
|
472
|
-
const {
|
|
473
|
-
key
|
|
474
|
-
} = pivotColumn;
|
|
475
|
-
if (cells[key]) {
|
|
476
|
-
let {
|
|
477
|
-
rows
|
|
478
|
-
} = cells[key];
|
|
479
|
-
let subTotal = getTotal(summaryColumn, summary_type, summary_method, rows, formula_rows);
|
|
480
|
-
if (isSummaryDateColumn) {
|
|
481
|
-
if (subTotal === 0) {
|
|
482
|
-
cells[key].total = 0;
|
|
483
|
-
} else {
|
|
484
|
-
subTotal.key = key;
|
|
485
|
-
subTotal.name = pivotRow.name;
|
|
486
|
-
dateColumnsTotalArr.push(subTotal);
|
|
487
|
-
cells[key].total = subTotal.date;
|
|
488
|
-
}
|
|
489
|
-
} else {
|
|
490
|
-
cells[key].total = subTotal;
|
|
491
|
-
total += subTotal ? subTotal - 0 : 0;
|
|
492
|
-
let columnTotal = pivot_columns_total[key] ? pivot_columns_total[key] : 0;
|
|
493
|
-
columnTotal += subTotal ? subTotal - 0 : 0;
|
|
494
|
-
pivot_columns_total[key] = columnTotal;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
if (summary_column_type !== 'date') {
|
|
499
|
-
pivotRow.total = Number.parseFloat(total.toFixed(8));
|
|
500
|
-
pivot_table_total += total;
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
if (summaryColumn && (0, _dtableUtils.isDateColumn)(summaryColumn)) {
|
|
504
|
-
if (summary_method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
505
|
-
pivot_columns_total = Number.parseFloat(pivot_table_total.toFixed(8));
|
|
506
|
-
} else {
|
|
507
|
-
pivot_columns_total = showTwoDimensionDateColumnsAndRowsTotal(dateColumnsTotalArr, pivot_rows, date_summary_column_format, pivot_columns, summary_method);
|
|
508
|
-
}
|
|
509
|
-
if (summary_method === 'Max') {
|
|
510
|
-
pivot_table_total = dateColumnsTotalArr.length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr, 'Max').date;
|
|
511
|
-
} else if (summary_method === 'Min') {
|
|
512
|
-
pivot_table_total = dateColumnsTotalArr.length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr, 'Min').date;
|
|
513
|
-
}
|
|
514
|
-
} else {
|
|
515
|
-
pivot_table_total = Number.parseFloat(pivot_table_total.toFixed(8));
|
|
516
|
-
}
|
|
517
|
-
return {
|
|
518
|
-
pivot_columns_total,
|
|
519
|
-
pivot_table_total
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
function getTotal(summary_column, summary_type, summary_method) {
|
|
523
|
-
let rows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
524
|
-
let formula_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
525
|
-
const summary_column_key = summary_column ? summary_column.key : '';
|
|
526
|
-
const summary_column_type = summary_column ? summary_column.type : '';
|
|
527
|
-
const rowsLength = rows.length;
|
|
528
|
-
let total;
|
|
529
|
-
if (summary_type === _constants.SUMMARY_TYPE.COUNT) {
|
|
530
|
-
total = rowsLength;
|
|
531
|
-
} else if (summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
532
|
-
if (summary_method === _constants.SUMMARY_METHOD_MAP.Distinct_values) {
|
|
533
|
-
total = 0;
|
|
534
|
-
let existMap = {};
|
|
535
|
-
rows.forEach(row => {
|
|
536
|
-
let num;
|
|
537
|
-
if (_dtableUtils.FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
538
|
-
const formulaRow = formula_rows[row._id] || {};
|
|
539
|
-
num = formulaRow[summary_column_key];
|
|
540
|
-
num = Array.isArray(num) ? num[0] : num;
|
|
541
|
-
} else {
|
|
542
|
-
num = row[summary_column_key];
|
|
543
|
-
}
|
|
544
|
-
if (!num) {
|
|
545
|
-
if (num === 0) {
|
|
546
|
-
num = '0';
|
|
547
|
-
} else {
|
|
548
|
-
num = !!num;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
if (!existMap[num]) {
|
|
552
|
-
existMap[num] = true;
|
|
553
|
-
total++;
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
return total;
|
|
557
|
-
}
|
|
558
|
-
if (summary_column && (0, _dtableUtils.isDateColumn)(summary_column)) {
|
|
559
|
-
if (rowsLength === 0) return;
|
|
560
|
-
let dateArr = [];
|
|
561
|
-
rows.forEach(r => {
|
|
562
|
-
let formatDate = {};
|
|
563
|
-
let formatDateData;
|
|
564
|
-
let value = r[summary_column_key];
|
|
565
|
-
if (_dtableUtils.FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
566
|
-
let formulaRow = formula_rows[r._id] || {};
|
|
567
|
-
value = formulaRow[summary_column_key];
|
|
568
|
-
}
|
|
569
|
-
if (!value) return;
|
|
570
|
-
if (value.indexOf('T') != -1) {
|
|
571
|
-
const index = value.indexOf('T');
|
|
572
|
-
const targetStr = value.substring(0, index);
|
|
573
|
-
formatDateData = targetStr.replace(/-/g, '/');
|
|
574
|
-
formatDate.date = targetStr;
|
|
575
|
-
} else {
|
|
576
|
-
formatDateData = value.replace(/-/g, '/');
|
|
577
|
-
formatDate.date = value;
|
|
578
|
-
}
|
|
579
|
-
formatDate.value = Date.parse(formatDateData);
|
|
580
|
-
dateArr.push(formatDate);
|
|
581
|
-
});
|
|
582
|
-
if (summary_method === _constants.SUMMARY_METHOD_MAP.Max) {
|
|
583
|
-
total = getDateMaxOrMinTotal(dateArr, _constants.SUMMARY_METHOD_MAP.Max);
|
|
584
|
-
} else if (summary_method === _constants.SUMMARY_METHOD_MAP.Min) {
|
|
585
|
-
total = getDateMaxOrMinTotal(dateArr, _constants.SUMMARY_METHOD_MAP.Min);
|
|
586
|
-
}
|
|
587
|
-
} else {
|
|
588
|
-
switch (summary_method) {
|
|
589
|
-
case _constants.SUMMARY_METHOD_MAP.Sum:
|
|
590
|
-
case _constants.SUMMARY_METHOD_MAP.Mean:
|
|
591
|
-
{
|
|
592
|
-
let sum = 0;
|
|
593
|
-
let validNumbersCount = 0;
|
|
594
|
-
rows.forEach(r => {
|
|
595
|
-
let num;
|
|
596
|
-
if (_dtableUtils.FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
597
|
-
let formulaRow = formula_rows[r._id] || {};
|
|
598
|
-
if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
|
|
599
|
-
num = formulaRow[summary_column_key][0];
|
|
600
|
-
} else {
|
|
601
|
-
num = formulaRow[summary_column_key];
|
|
602
|
-
}
|
|
603
|
-
} else {
|
|
604
|
-
num = r[summary_column_key];
|
|
605
|
-
}
|
|
606
|
-
if ((0, _dtableUtils.isNumber)(num)) {
|
|
607
|
-
validNumbersCount++;
|
|
608
|
-
sum += num;
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
if (summary_method === 'Sum') {
|
|
612
|
-
total = Number.parseFloat(sum.toFixed(8));
|
|
613
|
-
} else if (summary_method === 'Mean') {
|
|
614
|
-
total = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
|
|
615
|
-
}
|
|
616
|
-
break;
|
|
617
|
-
}
|
|
618
|
-
case _constants.SUMMARY_METHOD_MAP.Max:
|
|
619
|
-
case _constants.SUMMARY_METHOD_MAP.Min:
|
|
620
|
-
{
|
|
621
|
-
if (rowsLength > 0) {
|
|
622
|
-
let result = rows.reduce((current, next) => {
|
|
623
|
-
let currentValue, nextValue;
|
|
624
|
-
if (_dtableUtils.FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
625
|
-
let currentFormulaRow = formula_rows[current._id] || {};
|
|
626
|
-
let nextFormulaRow = formula_rows[next._id] || {};
|
|
627
|
-
currentValue = currentFormulaRow[summary_column_key];
|
|
628
|
-
nextValue = nextFormulaRow[summary_column_key];
|
|
629
|
-
} else {
|
|
630
|
-
currentValue = current[summary_column_key];
|
|
631
|
-
nextValue = next[summary_column_key];
|
|
632
|
-
}
|
|
633
|
-
if (!nextValue && nextValue !== 0) {
|
|
634
|
-
return current;
|
|
635
|
-
}
|
|
636
|
-
let isNextGreater = currentValue < nextValue;
|
|
637
|
-
if (summary_method === 'Min') {
|
|
638
|
-
return isNextGreater ? current : next;
|
|
639
|
-
} else {
|
|
640
|
-
return isNextGreater ? next : current;
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
if (_dtableUtils.FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
644
|
-
let formulaRow = formula_rows[result._id];
|
|
645
|
-
if (formulaRow) {
|
|
646
|
-
if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
|
|
647
|
-
total = formulaRow[summary_column_key][0];
|
|
648
|
-
} else {
|
|
649
|
-
total = formulaRow[summary_column_key];
|
|
650
|
-
}
|
|
651
|
-
} else {
|
|
652
|
-
total = null;
|
|
653
|
-
}
|
|
654
|
-
} else {
|
|
655
|
-
total = result[summary_column_key];
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
default:
|
|
661
|
-
{
|
|
662
|
-
break;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
// formula_rows result can be '#VALUE!'
|
|
668
|
-
if (total === '#VALUE!') {
|
|
669
|
-
total = 0;
|
|
670
|
-
}
|
|
671
|
-
return total || 0;
|
|
672
|
-
}
|
|
673
|
-
function showTwoDimensionDateColumnsAndRowsTotal(dateArr, pivot_rows, summary_column_format, pivot_columns, summary_method) {
|
|
674
|
-
let pivot_columns_total = {};
|
|
675
|
-
Array.isArray(pivot_columns) && pivot_columns.forEach(pivotColumn => {
|
|
676
|
-
const {
|
|
677
|
-
key
|
|
678
|
-
} = pivotColumn;
|
|
679
|
-
let dateColumnTotal = [];
|
|
680
|
-
dateArr.forEach(item => {
|
|
681
|
-
if (item.key === key) {
|
|
682
|
-
dateColumnTotal.push(item);
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
if (summary_method === 'Max') {
|
|
686
|
-
pivot_columns_total[key] = dateColumnTotal.length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnTotal, 'Max').date;
|
|
687
|
-
} else if (summary_method === 'Min') {
|
|
688
|
-
pivot_columns_total[key] = dateColumnTotal.length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnTotal, 'Min').date;
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
Array.isArray(pivot_rows) && pivot_rows.forEach(pivotRow => {
|
|
692
|
-
let dateRowTotal = [];
|
|
693
|
-
dateArr.forEach(item => {
|
|
694
|
-
if (item.name === pivotRow.name) {
|
|
695
|
-
dateRowTotal.push(item);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
if (summary_method === 'Max') {
|
|
699
|
-
pivotRow.total = dateRowTotal.length === 0 ? 0 : getDateMaxOrMinTotal(dateRowTotal, 'Max').date;
|
|
700
|
-
} else if (summary_method === 'Min') {
|
|
701
|
-
pivotRow.total = dateRowTotal.length === 0 ? 0 : getDateMaxOrMinTotal(dateRowTotal, 'Min').date;
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
return pivot_columns_total;
|
|
705
|
-
}
|
|
706
|
-
function getDateMaxOrMinTotal(dateArr, type) {
|
|
707
|
-
if (dateArr.length === 0) return;
|
|
708
|
-
const list = dateArr.map(item => item.value);
|
|
709
|
-
let dateValue = 0;
|
|
710
|
-
let dateIndex = 0;
|
|
711
|
-
if (type === 'Max') {
|
|
712
|
-
dateValue = Math.max(...list);
|
|
713
|
-
} else if (type === 'Min') {
|
|
714
|
-
dateValue = Math.min(...list);
|
|
715
|
-
}
|
|
716
|
-
dateIndex = list.indexOf(dateValue);
|
|
717
|
-
return dateArr[dateIndex];
|
|
718
|
-
}
|