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,48 +1,51 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import { FORMULA_COLUMN_TYPES_MAP, isNumber, TableUtils, Views } from 'dtable-store';
|
|
3
2
|
import { isArrayCellValue } from '../../utils/common-utils';
|
|
4
3
|
import { getCellValue, getFormattedLabel } from '../../utils/row-utils';
|
|
5
4
|
import StatUtils from '../../utils/stat-utils';
|
|
6
5
|
import { PIE_CHART_COLORS } from '../../constants';
|
|
7
6
|
function calculateResult(chart, value, username, userId) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const {
|
|
8
|
+
table_id,
|
|
9
|
+
view_id,
|
|
10
|
+
name_column,
|
|
11
|
+
completed_column,
|
|
12
|
+
target_column,
|
|
13
|
+
group_column,
|
|
14
|
+
date_granularity,
|
|
15
|
+
geolocation_granularity
|
|
16
|
+
} = chart;
|
|
17
|
+
const table = TableUtils.getTableById(value.tables, table_id);
|
|
18
|
+
const view = table && Views.getViewById(table.views, view_id);
|
|
18
19
|
if (!view) {
|
|
19
20
|
return [];
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const nameColumn = TableUtils.getTableColumnByKey(table, name_column);
|
|
22
23
|
if (!nameColumn) return [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const statRows = Views.getViewRows(view, table, value, username, userId);
|
|
25
|
+
const formulaRows = Views.getTableFormulaResults(table, statRows, value);
|
|
26
|
+
const groupColumn = TableUtils.getTableColumnByKey(table, group_column);
|
|
27
|
+
const isColumnDataAsAnArray = isArrayCellValue(nameColumn);
|
|
28
|
+
const isGroupChart = !!groupColumn;
|
|
29
|
+
let result = [];
|
|
29
30
|
if (!isGroupChart) {
|
|
30
|
-
|
|
31
|
-
statRows.forEach(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const memo = new Map();
|
|
32
|
+
statRows.forEach(row => {
|
|
33
|
+
let {
|
|
34
|
+
_id: rowId
|
|
35
|
+
} = row;
|
|
36
|
+
let formulaRow = formulaRows[rowId] || {};
|
|
37
|
+
const name = row[nameColumn.key];
|
|
35
38
|
if (name || Number.isFinite(name)) {
|
|
36
|
-
|
|
39
|
+
let label = StatUtils.getGroupLabel(name, formulaRow, nameColumn, '', '', value);
|
|
37
40
|
if (isColumnDataAsAnArray) {
|
|
38
41
|
label = label[0];
|
|
39
42
|
}
|
|
40
43
|
label = getFormattedLabel(nameColumn, label, value.collaborators);
|
|
41
44
|
if (!memo.get(label)) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const completedColumn = TableUtils.getTableColumnByKey(table, completed_column);
|
|
46
|
+
const targetColumn = TableUtils.getTableColumnByKey(table, target_column);
|
|
47
|
+
let currentValue = getCellValue(row, formulaRow, completedColumn);
|
|
48
|
+
let targetValue = getCellValue(row, formulaRow, targetColumn);
|
|
46
49
|
currentValue = isNumber(currentValue) ? currentValue : 0;
|
|
47
50
|
targetValue = isNumber(targetValue) ? targetValue : 0;
|
|
48
51
|
if (currentValue >= targetValue) {
|
|
@@ -73,18 +76,20 @@ function calculateResult(chart, value, username, userId) {
|
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
} else {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
statRows.forEach(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const memo = new Map();
|
|
80
|
+
const colorMap = {};
|
|
81
|
+
let colorIndex = 0;
|
|
82
|
+
let isFormulaType = FORMULA_COLUMN_TYPES_MAP[groupColumn.type];
|
|
83
|
+
const isGroupColumnDataAsAnArray = isArrayCellValue(groupColumn);
|
|
84
|
+
statRows.forEach(row => {
|
|
85
|
+
let {
|
|
86
|
+
_id: rowId
|
|
87
|
+
} = row;
|
|
88
|
+
let formulaRow = formulaRows[rowId] || {};
|
|
89
|
+
const name = row[nameColumn.key],
|
|
85
90
|
groupLabelName = !isFormulaType ? row[groupColumn.key] : formulaRow[rowId][groupColumn.key];
|
|
86
91
|
if ((name || Number.isFinite(name)) && (groupLabelName || Number.isFinite(groupLabelName))) {
|
|
87
|
-
|
|
92
|
+
let label = StatUtils.getGroupLabel(name, formulaRow, nameColumn, '', '', value),
|
|
88
93
|
groupLabel = StatUtils.getGroupLabel(groupLabelName, formulaRow, groupColumn, date_granularity, geolocation_granularity, value);
|
|
89
94
|
if (isColumnDataAsAnArray) {
|
|
90
95
|
label = label[0];
|
|
@@ -94,18 +99,18 @@ function calculateResult(chart, value, username, userId) {
|
|
|
94
99
|
}
|
|
95
100
|
label = getFormattedLabel(nameColumn, label, value.collaborators);
|
|
96
101
|
groupLabel = getFormattedLabel(groupColumn, groupLabel, value.collaborators);
|
|
97
|
-
|
|
102
|
+
let color = colorMap[groupLabel];
|
|
98
103
|
if (!color) {
|
|
99
104
|
color = PIE_CHART_COLORS[colorIndex % 12];
|
|
100
105
|
colorMap[groupLabel] = color;
|
|
101
106
|
colorIndex++;
|
|
102
107
|
}
|
|
103
|
-
|
|
108
|
+
let cache = memo.get(label);
|
|
104
109
|
if (groupLabel && (!cache || !cache[groupLabel])) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
const completedColumn = TableUtils.getTableColumnByKey(table, completed_column);
|
|
111
|
+
const targetColumn = TableUtils.getTableColumnByKey(table, target_column);
|
|
112
|
+
let currentValue = getCellValue(row, formulaRow, completedColumn);
|
|
113
|
+
let targetValue = getCellValue(row, formulaRow, targetColumn);
|
|
109
114
|
currentValue = isNumber(currentValue) ? currentValue : 0;
|
|
110
115
|
targetValue = isNumber(targetValue) ? targetValue : 0;
|
|
111
116
|
if (currentValue >= targetValue) {
|
|
@@ -113,7 +118,7 @@ function calculateResult(chart, value, username, userId) {
|
|
|
113
118
|
name: label,
|
|
114
119
|
group_label: groupLabel,
|
|
115
120
|
value: currentValue,
|
|
116
|
-
color
|
|
121
|
+
color,
|
|
117
122
|
type: 'completed',
|
|
118
123
|
current_value: currentValue,
|
|
119
124
|
target_value: targetValue
|
|
@@ -123,7 +128,7 @@ function calculateResult(chart, value, username, userId) {
|
|
|
123
128
|
name: label,
|
|
124
129
|
group_label: groupLabel,
|
|
125
130
|
value: currentValue,
|
|
126
|
-
color
|
|
131
|
+
color,
|
|
127
132
|
type: 'completed',
|
|
128
133
|
current_value: currentValue,
|
|
129
134
|
target_value: targetValue
|
|
@@ -131,7 +136,7 @@ function calculateResult(chart, value, username, userId) {
|
|
|
131
136
|
name: label,
|
|
132
137
|
group_label: groupLabel,
|
|
133
138
|
value: targetValue - currentValue,
|
|
134
|
-
color
|
|
139
|
+
color,
|
|
135
140
|
type: 'uncompleted',
|
|
136
141
|
current_value: currentValue,
|
|
137
142
|
target_value: targetValue
|
|
@@ -139,9 +144,11 @@ function calculateResult(chart, value, username, userId) {
|
|
|
139
144
|
}
|
|
140
145
|
if (cache) {
|
|
141
146
|
cache[groupLabel] = 1;
|
|
142
|
-
|
|
147
|
+
memo.set(label, cache);
|
|
143
148
|
} else {
|
|
144
|
-
|
|
149
|
+
memo.set(label, {
|
|
150
|
+
[groupLabel]: 1
|
|
151
|
+
});
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
}
|
|
@@ -2,37 +2,39 @@ import { isNumber, isNumericColumn, TableUtils, Views } from 'dtable-store';
|
|
|
2
2
|
import { getSummaryResult } from '../../utils/common-utils';
|
|
3
3
|
import { getCellValue } from '../../utils/row-utils';
|
|
4
4
|
function calculateResult(chart, value, username, userId) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const {
|
|
6
|
+
table_id,
|
|
7
|
+
view_id,
|
|
8
|
+
target_value_column,
|
|
9
|
+
target_value_column_summary_method,
|
|
10
|
+
total_value_column,
|
|
11
|
+
total_value_column_summary_method
|
|
12
|
+
} = chart;
|
|
13
|
+
const selectedTable = TableUtils.getTableById(value.tables, table_id);
|
|
14
|
+
const selectedView = selectedTable && Views.getViewById(selectedTable.views, view_id);
|
|
15
|
+
const selectedColumn1 = TableUtils.getTableColumnByKey(selectedTable, target_value_column);
|
|
16
|
+
const selectedColumn2 = TableUtils.getTableColumnByKey(selectedTable, total_value_column);
|
|
17
|
+
const statRows = Views.getViewRows(selectedView, selectedTable, value, username, userId);
|
|
16
18
|
if (statRows.length === 0) {
|
|
17
19
|
return 0;
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
statRows.forEach(
|
|
27
|
-
|
|
21
|
+
const isNumericColumn1 = selectedColumn1 && isNumericColumn(selectedColumn1);
|
|
22
|
+
const isNumericColumn2 = selectedColumn2 && isNumericColumn(selectedColumn2);
|
|
23
|
+
const formulaRows = isNumericColumn1 || isNumericColumn2 ? Views.getTableFormulaResults(selectedTable, statRows, value) : {};
|
|
24
|
+
let result1;
|
|
25
|
+
let result2;
|
|
26
|
+
let numberList1 = [];
|
|
27
|
+
let numberList2 = [];
|
|
28
|
+
statRows.forEach(row => {
|
|
29
|
+
const formulaRow = formulaRows[row._id];
|
|
28
30
|
if (isNumericColumn1) {
|
|
29
|
-
|
|
31
|
+
const cellValue1 = getCellValue(row, formulaRow, selectedColumn1);
|
|
30
32
|
if (isNumber(cellValue1)) {
|
|
31
33
|
numberList1.push(cellValue1);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
if (isNumericColumn2) {
|
|
35
|
-
|
|
37
|
+
const cellValue2 = getCellValue(row, formulaRow, selectedColumn2);
|
|
36
38
|
if (isNumber(cellValue2)) {
|
|
37
39
|
numberList2.push(cellValue2);
|
|
38
40
|
}
|
|
@@ -5,38 +5,40 @@ import { getCellValue } from '../../utils/row-utils';
|
|
|
5
5
|
import { SUMMARY_TYPE } from '../../constants';
|
|
6
6
|
import StatUtils from '../../utils/stat-utils';
|
|
7
7
|
function calculateStatItem(chart, dtableValue, username, userId) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
const {
|
|
9
|
+
table_id,
|
|
10
|
+
view_id,
|
|
11
|
+
column,
|
|
12
|
+
summary_type,
|
|
13
|
+
summary_column,
|
|
14
|
+
summary_method,
|
|
15
|
+
group_column
|
|
16
|
+
} = chart;
|
|
17
|
+
const table = TableUtils.getTableById(dtableValue.tables, table_id);
|
|
18
|
+
const view = table && Views.getViewById(table.views, view_id);
|
|
19
|
+
const columnItem = TableUtils.getTableColumnByKey(table, column);
|
|
20
|
+
const rows = Views.getViewRows(view, table, dtableValue, username, userId);
|
|
21
|
+
const formulaRows = Views.getTableFormulaResults(table, rows, dtableValue);
|
|
22
|
+
const groupColumn = TableUtils.getTableColumnByKey(table, group_column);
|
|
23
|
+
const numericColumn = summary_column && TableUtils.getTableColumnByKey(table, summary_column);
|
|
24
|
+
const groupItems = getGroupItems(rows, groupColumn);
|
|
23
25
|
if (groupColumn.length === 0) return;
|
|
24
|
-
|
|
25
|
-
groupItems.forEach(
|
|
26
|
+
let result = {};
|
|
27
|
+
groupItems.forEach(groupValue => {
|
|
26
28
|
result[groupValue] = {};
|
|
27
29
|
});
|
|
28
30
|
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
29
|
-
groupItems.forEach(
|
|
30
|
-
rows.forEach(
|
|
31
|
-
|
|
31
|
+
groupItems.forEach(groupItem => {
|
|
32
|
+
rows.forEach(row => {
|
|
33
|
+
let value = getClientCellValueDisplayString(row, columnItem.type, columnItem.key, {
|
|
32
34
|
collaborators: dtableValue.collaborators,
|
|
33
35
|
data: columnItem.data,
|
|
34
|
-
formulaRows
|
|
36
|
+
formulaRows
|
|
35
37
|
});
|
|
36
38
|
if (!value && value !== 0 || value.length === 0) value = null;
|
|
37
|
-
|
|
39
|
+
const groupValue = row[groupColumn.key];
|
|
38
40
|
if (groupItems.includes(groupValue)) {
|
|
39
|
-
|
|
41
|
+
const count = result[groupItem][value];
|
|
40
42
|
if (groupItem === groupValue) {
|
|
41
43
|
if (count === undefined) {
|
|
42
44
|
result[groupItem][value] = 1;
|
|
@@ -52,19 +54,19 @@ function calculateStatItem(chart, dtableValue, username, userId) {
|
|
|
52
54
|
});
|
|
53
55
|
});
|
|
54
56
|
} else {
|
|
55
|
-
groupItems.forEach(
|
|
56
|
-
rows.forEach(
|
|
57
|
-
|
|
57
|
+
groupItems.forEach(groupItem => {
|
|
58
|
+
rows.forEach(row => {
|
|
59
|
+
let value = getClientCellValueDisplayString(row, columnItem.type, columnItem.key, {
|
|
58
60
|
collaborators: dtableValue.collaborators,
|
|
59
61
|
data: columnItem.data,
|
|
60
|
-
formulaRows
|
|
62
|
+
formulaRows
|
|
61
63
|
});
|
|
62
64
|
if (!value && value !== 0 || value.length === 0) value = null;
|
|
63
|
-
|
|
65
|
+
const groupValue = row[groupColumn.key];
|
|
64
66
|
if (groupItems.includes(groupValue)) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const list = result[groupItem][value];
|
|
68
|
+
const formulaRow = formulaRows[row._id];
|
|
69
|
+
let cellValue = getCellValue(row, formulaRow, numericColumn);
|
|
68
70
|
cellValue = isNumber(cellValue) ? cellValue : 0;
|
|
69
71
|
if (groupItem === groupValue) {
|
|
70
72
|
if (!list) {
|
|
@@ -81,41 +83,39 @@ function calculateStatItem(chart, dtableValue, username, userId) {
|
|
|
81
83
|
});
|
|
82
84
|
});
|
|
83
85
|
if (numericColumn) {
|
|
84
|
-
|
|
86
|
+
const data = numericColumn.data || {};
|
|
85
87
|
result = summaryResult(result, summary_method, data.precision);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
return normalizeResult(result, groupColumn, numericColumn, summary_type, summary_method);
|
|
89
91
|
}
|
|
90
92
|
function summaryResult(result, summaryMethod, precision) {
|
|
91
|
-
|
|
92
|
-
Object.keys(result).forEach(
|
|
93
|
+
const newResult = {};
|
|
94
|
+
Object.keys(result).forEach(groupId => {
|
|
93
95
|
newResult[groupId] = {};
|
|
94
|
-
Object.keys(result[groupId]).forEach(
|
|
95
|
-
|
|
96
|
+
Object.keys(result[groupId]).forEach(key => {
|
|
97
|
+
const currentValue = result[groupId][key];
|
|
96
98
|
newResult[groupId][key] = getSummaryResult(currentValue, summaryMethod, precision);
|
|
97
99
|
});
|
|
98
100
|
});
|
|
99
101
|
return newResult;
|
|
100
102
|
}
|
|
101
103
|
function normalizeResult(result, groupColumn, summaryColumn, summaryType, summaryMethod) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
Object.keys(result).forEach(
|
|
105
|
-
|
|
106
|
-
return option.id === groupId;
|
|
107
|
-
});
|
|
104
|
+
const data = [];
|
|
105
|
+
const colorSet = [];
|
|
106
|
+
Object.keys(result).forEach((groupId, index) => {
|
|
107
|
+
const groupItem = groupColumn.data.options.find(option => option.id === groupId);
|
|
108
108
|
if (!groupItem) return;
|
|
109
109
|
colorSet[index] = groupItem.color;
|
|
110
|
-
Object.keys(result[groupId]).forEach(
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
Object.keys(result[groupId]).forEach(name => {
|
|
111
|
+
const value = result[groupId][name];
|
|
112
|
+
let formattedValue = value;
|
|
113
113
|
if (summaryType === SUMMARY_TYPE.ADVANCED) {
|
|
114
114
|
formattedValue = StatUtils.getFormattedValue(value, summaryColumn, summaryMethod);
|
|
115
115
|
}
|
|
116
116
|
data.push({
|
|
117
|
-
name
|
|
118
|
-
value
|
|
117
|
+
name,
|
|
118
|
+
value,
|
|
119
119
|
formatted_value: formattedValue,
|
|
120
120
|
group_name: groupItem.name,
|
|
121
121
|
color: groupItem.color
|
|
@@ -123,14 +123,14 @@ function normalizeResult(result, groupColumn, summaryColumn, summaryType, summar
|
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
return {
|
|
126
|
-
data
|
|
127
|
-
colorSet
|
|
126
|
+
data,
|
|
127
|
+
colorSet
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
function getGroupItems(rows, groupColumn) {
|
|
131
|
-
|
|
132
|
-
for (
|
|
133
|
-
|
|
131
|
+
const items = [];
|
|
132
|
+
for (let index = 0; index < rows.length; index++) {
|
|
133
|
+
const value = rows[index][groupColumn.key];
|
|
134
134
|
if (value && !items.includes(value)) {
|
|
135
135
|
items.push(value);
|
|
136
136
|
if (items.length === 2) break;
|