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