dtable-statistic 4.3.3 → 4.3.4
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 +3 -10
- package/es/calculator/base-calculator.js +12 -20
- package/es/calculator/basic-chart-calculator.js +65 -72
- package/es/calculator/combination-calculator.js +57 -64
- package/es/calculator/compare-bar-calculator.js +26 -33
- package/es/calculator/completeness-calculator.js +30 -37
- package/es/calculator/copy-value.js +1 -7
- package/es/calculator/dashboard-calculator.js +13 -20
- package/es/calculator/heat-map-calculator.js +18 -25
- package/es/calculator/horizontal-bar-calculator.js +8 -15
- package/es/calculator/index.js +35 -42
- package/es/calculator/map-calculator.js +22 -29
- package/es/calculator/mirror-calculator.js +20 -27
- package/es/calculator/number-card-calculator.js +10 -17
- package/es/calculator/pivot-table-calculator.js +58 -65
- package/es/calculator/scatter-calculator.js +14 -21
- package/es/calculator/thread-manager.js +1 -7
- package/es/calculator/trend-calculator.js +22 -29
- package/es/calculator/workers/basic-chart-calculator-worker.js +76 -83
- package/es/calculator/workers/calculator.worker.js +30 -33
- package/es/calculator/workers/card-calculator-worker.js +13 -19
- package/es/calculator/workers/combination-calculator-worker.js +46 -53
- package/es/calculator/workers/compare-bar-chart-calculator-worker.js +22 -29
- package/es/calculator/workers/completeness-calculator-worker.js +34 -41
- package/es/calculator/workers/dashboard-calculator-worker.js +18 -24
- package/es/calculator/workers/mirror-calculator-worker.js +22 -29
- package/es/calculator/workers/pivot-table-calculator-worker.js +77 -84
- package/es/calculator/workers/scatter-calculator-worker.js +20 -27
- package/es/calculator/workers/trend-calculator-worker.js +27 -34
- package/es/calculator/world-map-calculator.js +17 -24
- package/es/components/common-add-tool.js +5 -12
- package/es/components/dialog/chart-addition-edit-dialog.js +12 -20
- package/es/components/dialog/chart-addition-widgets/chart-selector.js +101 -108
- package/es/components/dialog/color-theme-dialog.js +15 -22
- package/es/components/dialog/delete-confirmation-dialog.js +11 -18
- package/es/components/dialog/enlarged-chart-dialog.js +20 -28
- package/es/components/dialog/new-table-dialog.js +16 -23
- package/es/components/dialog/new-view-dialog.js +14 -21
- package/es/components/dialog/rename-view-dialog.js +14 -22
- package/es/components/dialog/statistic-record-dialog/index.js +37 -45
- package/es/components/dialog/statistic-types-dialog/index.js +14 -22
- package/es/components/dialog/table-select-dialog.js +15 -23
- package/es/components/dropdown-menu/statistic-dropdown-menu.js +41 -49
- package/es/components/dtable-popover.js +12 -19
- package/es/components/dtable-search-input.js +13 -21
- package/es/components/dtable-select.js +15 -21
- package/es/components/icon.js +4 -11
- package/es/components/index.js +11 -76
- package/es/components/loading.js +3 -10
- package/es/components/modal-portal.js +5 -12
- package/es/components/popover/color-rules/color-rule.js +25 -33
- package/es/components/popover/color-rules/index.js +6 -14
- package/es/components/popover/color-rules/rule-filters/filter.js +27 -34
- package/es/components/popover/color-rules/rule-filters/index.js +17 -25
- package/es/components/popover/color-rules/rule-filters/number-input.js +9 -17
- package/es/components/popover/color-rules-popover.js +24 -32
- package/es/components/popover/color-selector-popover.js +10 -17
- package/es/components/seatable-radio/index.js +9 -16
- package/es/components/select/index.js +2 -9
- package/es/components/select/option-group.js +19 -27
- package/es/components/select/option.js +6 -14
- package/es/components/select/select.js +17 -25
- package/es/components/toast/alert.js +24 -31
- package/es/components/toast/index.js +3 -10
- package/es/components/toast/toast.js +12 -20
- package/es/components/toast/toastManager.js +9 -17
- package/es/components/toast/toaster.js +6 -14
- package/es/constants/color-rules.js +6 -12
- package/es/constants/dtable-select-style.js +4 -9
- package/es/constants/event-types.js +4 -10
- package/es/constants/index.js +67 -96
- package/es/constants/key-codes.js +0 -2
- package/es/constants/map.js +2 -8
- package/es/constants/model.js +20 -26
- package/es/constants/regions.js +3 -8
- package/es/constants/zIndexes.js +1 -7
- package/es/custom-g2.js +208 -236
- package/es/dashboard.js +50 -58
- package/es/desktop-dashboard.js +47 -55
- package/es/index.js +3 -6
- package/es/locale/index.js +10 -13
- package/es/locale/lang/de.js +1 -7
- package/es/locale/lang/en.js +1 -7
- package/es/locale/lang/fr.js +1 -7
- package/es/locale/lang/zh_CN.js +1 -7
- package/es/mobile-dashboard.js +38 -46
- package/es/model/bar-group.js +11 -19
- package/es/model/bar.js +10 -18
- package/es/model/base-model.js +2 -9
- package/es/model/basic-number-card.js +8 -16
- package/es/model/collaborators.js +2 -9
- package/es/model/combination.js +12 -20
- package/es/model/compare-bar.js +16 -24
- package/es/model/completeness-group.js +8 -16
- package/es/model/completeness.js +5 -13
- package/es/model/custom-bar.js +6 -14
- package/es/model/dashboard.js +6 -14
- package/es/model/generic-model.js +133 -141
- package/es/model/heat-map.js +11 -19
- package/es/model/horizontal-bar-group.js +10 -18
- package/es/model/horizontal-bar.js +10 -18
- package/es/model/index.js +53 -185
- package/es/model/map.js +15 -23
- package/es/model/mirror.js +13 -21
- package/es/model/pie.js +10 -18
- package/es/model/ring.js +11 -19
- package/es/model/scatter.js +6 -14
- package/es/model/statistic-dashboard.js +2 -9
- package/es/model/table.js +10 -18
- package/es/model/trend.js +12 -20
- package/es/model/world-map.js +13 -21
- package/es/service/chart-service.js +7 -14
- package/es/service/dashboard-service.js +34 -41
- package/es/service/map-json.js +8 -14
- package/es/stat-editor/chart-name-editor.js +8 -15
- package/es/stat-editor/index.js +16 -24
- package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +21 -29
- package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +49 -57
- package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +23 -31
- package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +4 -11
- package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +19 -27
- package/es/stat-editor/stat-settings/advance-chart-settings/index.js +43 -51
- package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +23 -31
- package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +23 -31
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +37 -45
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +19 -27
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +26 -34
- package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +47 -55
- package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +22 -30
- package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +18 -26
- package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +27 -35
- package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +24 -32
- package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +33 -41
- package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +22 -30
- package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +27 -26
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +46 -54
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +23 -31
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +26 -34
- package/es/stat-editor/stat-settings/basic-chart-settings/index.js +77 -85
- package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +21 -29
- package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +73 -81
- package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +16 -24
- package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +19 -27
- package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +18 -26
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +49 -57
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +17 -25
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +47 -55
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +11 -19
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +45 -53
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +9 -17
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +20 -28
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +30 -38
- package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +50 -58
- package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +17 -25
- package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +47 -55
- package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +11 -19
- package/es/stat-editor/stat-settings/color-setting/color-picker.js +12 -19
- package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +62 -70
- package/es/stat-editor/stat-settings/map/map-level.js +13 -20
- package/es/stat-editor/stat-settings/map/map-province-city.js +20 -27
- package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +11 -19
- package/es/stat-editor/stat-settings/public-setting/base-settings.js +20 -28
- package/es/stat-editor/stat-settings/public-setting/calender.js +22 -29
- package/es/stat-editor/stat-settings/public-setting/column-settings.js +6 -13
- package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +9 -16
- package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +13 -21
- package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +8 -15
- package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +11 -19
- package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +27 -35
- package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +8 -15
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +18 -26
- package/es/stat-list/chart-preview.js +20 -28
- package/es/stat-list/index.js +27 -35
- package/es/stat-view/area-chart.js +43 -50
- package/es/stat-view/bar-chart.js +47 -54
- package/es/stat-view/base-chart.js +24 -32
- package/es/stat-view/basic-number-card.js +19 -26
- package/es/stat-view/combination-chart.js +49 -56
- package/es/stat-view/compare-chart.js +39 -46
- package/es/stat-view/completeness-chart.js +28 -35
- package/es/stat-view/custom-bar.js +31 -38
- package/es/stat-view/dashboard-chart.js +15 -22
- package/es/stat-view/heat-map.js +43 -50
- package/es/stat-view/horizontal-bar-chart.js +51 -58
- package/es/stat-view/index.js +73 -80
- package/es/stat-view/line-chart.js +39 -46
- package/es/stat-view/map.js +33 -40
- package/es/stat-view/mirror.js +21 -28
- package/es/stat-view/pie-chart.js +29 -36
- package/es/stat-view/pivot-table/index.js +32 -39
- package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +31 -39
- package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +29 -37
- package/es/stat-view/pivot-table/pivot-table-display-name.js +46 -54
- package/es/stat-view/pivot-table/two-dimension-table.js +62 -70
- package/es/stat-view/ring-chart.js +38 -45
- package/es/stat-view/scatter-chart.js +30 -37
- package/es/stat-view/treemap-chart.js +37 -44
- package/es/stat-view/trend-chart.js +32 -39
- package/es/stat-view/world-map.js +33 -40
- package/es/tabs/index.js +32 -40
- package/es/tabs/tab.js +26 -34
- package/es/utils/basic-chart-utils.js +2 -9
- package/es/utils/cell-format.js +14 -22
- package/es/utils/cell-value.js +7 -14
- package/es/utils/collaborator.js +4 -13
- package/es/utils/color-utils.js +18 -29
- package/es/utils/column-utils.js +18 -29
- package/es/utils/column.js +4 -11
- package/es/utils/common-utils.js +41 -65
- package/es/utils/date-format.js +2 -8
- package/es/utils/export-table-utils.js +82 -91
- package/es/utils/index.js +11 -100
- package/es/utils/map.js +26 -36
- package/es/utils/model.js +6 -14
- package/es/utils/object.js +6 -15
- package/es/utils/pivot-table.js +16 -23
- package/es/utils/row-utils.js +23 -33
- package/es/utils/search.js +21 -29
- package/es/utils/sql-utils.js +65 -75
- package/es/utils/stat-utils.js +60 -66
- package/es/utils/trend-utils.js +32 -40
- package/package.json +1 -1
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _dtableStore = require("dtable-store");
|
|
9
|
-
var _utils = require("../../utils");
|
|
10
|
-
var _commonUtils = require("../../utils/common-utils");
|
|
11
|
-
var _rowUtils = require("../../utils/row-utils");
|
|
12
|
-
var _constants = require("../../constants");
|
|
13
|
-
var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
|
|
1
|
+
import { isNumber, TableUtils, Views } from 'dtable-store';
|
|
2
|
+
import { getClientCellValueDisplayString } from '../../utils';
|
|
3
|
+
import { getSummaryResult } from '../../utils/common-utils';
|
|
4
|
+
import { getCellValue } from '../../utils/row-utils';
|
|
5
|
+
import { SUMMARY_TYPE } from '../../constants';
|
|
6
|
+
import StatUtils from '../../utils/stat-utils';
|
|
14
7
|
function calculateStatItem(chart, dtableValue, username, userId) {
|
|
15
8
|
const {
|
|
16
9
|
table_id,
|
|
@@ -21,23 +14,23 @@ function calculateStatItem(chart, dtableValue, username, userId) {
|
|
|
21
14
|
summary_method,
|
|
22
15
|
group_column
|
|
23
16
|
} = chart;
|
|
24
|
-
const table =
|
|
25
|
-
const view = table &&
|
|
26
|
-
const columnItem =
|
|
27
|
-
const rows =
|
|
28
|
-
const formulaRows =
|
|
29
|
-
const groupColumn =
|
|
30
|
-
const numericColumn = summary_column &&
|
|
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);
|
|
31
24
|
const groupItems = getGroupItems(rows, groupColumn);
|
|
32
25
|
if (groupColumn.length === 0) return;
|
|
33
26
|
let result = {};
|
|
34
27
|
groupItems.forEach(groupValue => {
|
|
35
28
|
result[groupValue] = {};
|
|
36
29
|
});
|
|
37
|
-
if (summary_type ===
|
|
30
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
38
31
|
groupItems.forEach(groupItem => {
|
|
39
32
|
rows.forEach(row => {
|
|
40
|
-
let value =
|
|
33
|
+
let value = getClientCellValueDisplayString(row, columnItem.type, columnItem.key, {
|
|
41
34
|
collaborators: dtableValue.collaborators,
|
|
42
35
|
data: columnItem.data,
|
|
43
36
|
formulaRows
|
|
@@ -63,7 +56,7 @@ function calculateStatItem(chart, dtableValue, username, userId) {
|
|
|
63
56
|
} else {
|
|
64
57
|
groupItems.forEach(groupItem => {
|
|
65
58
|
rows.forEach(row => {
|
|
66
|
-
let value =
|
|
59
|
+
let value = getClientCellValueDisplayString(row, columnItem.type, columnItem.key, {
|
|
67
60
|
collaborators: dtableValue.collaborators,
|
|
68
61
|
data: columnItem.data,
|
|
69
62
|
formulaRows
|
|
@@ -73,8 +66,8 @@ function calculateStatItem(chart, dtableValue, username, userId) {
|
|
|
73
66
|
if (groupItems.includes(groupValue)) {
|
|
74
67
|
const list = result[groupItem][value];
|
|
75
68
|
const formulaRow = formulaRows[row._id];
|
|
76
|
-
let cellValue =
|
|
77
|
-
cellValue =
|
|
69
|
+
let cellValue = getCellValue(row, formulaRow, numericColumn);
|
|
70
|
+
cellValue = isNumber(cellValue) ? cellValue : 0;
|
|
78
71
|
if (groupItem === groupValue) {
|
|
79
72
|
if (!list) {
|
|
80
73
|
result[groupItem][value] = [cellValue];
|
|
@@ -102,7 +95,7 @@ function summaryResult(result, summaryMethod, precision) {
|
|
|
102
95
|
newResult[groupId] = {};
|
|
103
96
|
Object.keys(result[groupId]).forEach(key => {
|
|
104
97
|
const currentValue = result[groupId][key];
|
|
105
|
-
newResult[groupId][key] =
|
|
98
|
+
newResult[groupId][key] = getSummaryResult(currentValue, summaryMethod, precision);
|
|
106
99
|
});
|
|
107
100
|
});
|
|
108
101
|
return newResult;
|
|
@@ -117,8 +110,8 @@ function normalizeResult(result, groupColumn, summaryColumn, summaryType, summar
|
|
|
117
110
|
Object.keys(result[groupId]).forEach(name => {
|
|
118
111
|
const value = result[groupId][name];
|
|
119
112
|
let formattedValue = value;
|
|
120
|
-
if (summaryType ===
|
|
121
|
-
formattedValue =
|
|
113
|
+
if (summaryType === SUMMARY_TYPE.ADVANCED) {
|
|
114
|
+
formattedValue = StatUtils.getFormattedValue(value, summaryColumn, summaryMethod);
|
|
122
115
|
}
|
|
123
116
|
data.push({
|
|
124
117
|
name,
|
|
@@ -145,4 +138,4 @@ function getGroupItems(rows, groupColumn) {
|
|
|
145
138
|
}
|
|
146
139
|
return items;
|
|
147
140
|
}
|
|
148
|
-
|
|
141
|
+
export default calculateStatItem;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.default = calculateStatItem;
|
|
8
|
-
var _dtableStore = require("dtable-store");
|
|
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, username, userId) {
|
|
1
|
+
import { FORMULA_COLUMN_TYPES_MAP, isNumber, TableUtils, Views, isDateColumn, isNumericColumn } from 'dtable-store';
|
|
2
|
+
import { SUMMARY_METHOD_MAP, SUMMARY_TYPE } from '../../constants';
|
|
3
|
+
import { isArrayCellValue } from '../../utils/common-utils';
|
|
4
|
+
import { getFormattedLabel, isValidRow } from '../../utils/row-utils';
|
|
5
|
+
import StatUtils from '../../utils/stat-utils';
|
|
6
|
+
export default function calculateStatItem(chart, value, username, userId) {
|
|
14
7
|
const {
|
|
15
8
|
groupby_column_key,
|
|
16
9
|
column_groupby_column_key
|
|
@@ -36,21 +29,21 @@ function calculateOneDimensionTable(chart, value, username, userId) {
|
|
|
36
29
|
groupby_geolocation_granularity,
|
|
37
30
|
summary_columns_option
|
|
38
31
|
} = chart;
|
|
39
|
-
const table =
|
|
40
|
-
const view = table &&
|
|
41
|
-
const column =
|
|
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);
|
|
42
35
|
if (!column) return {};
|
|
43
|
-
const isColumnDataAsAnArray =
|
|
44
|
-
const statRows =
|
|
45
|
-
const formulaRows =
|
|
36
|
+
const isColumnDataAsAnArray = isArrayCellValue(column);
|
|
37
|
+
const statRows = Views.getViewRows(view, table, value, username, userId);
|
|
38
|
+
const formulaRows = Views.getTableFormulaResults(table, statRows, value);
|
|
46
39
|
let pivot_rows = [];
|
|
47
40
|
statRows.forEach(row => {
|
|
48
41
|
const {
|
|
49
42
|
_id: rowId
|
|
50
43
|
} = row;
|
|
51
44
|
const formulaRow = formulaRows[rowId];
|
|
52
|
-
if (
|
|
53
|
-
const name =
|
|
45
|
+
if (isValidRow(row, formulaRow, column, include_empty)) {
|
|
46
|
+
const name = StatUtils.getGroupLabel(row[column.key], formulaRow, column, groupby_date_granularity, groupby_geolocation_granularity, value);
|
|
54
47
|
let pivotRowIndex;
|
|
55
48
|
if (isColumnDataAsAnArray) {
|
|
56
49
|
if (name.length === 0 && include_empty) {
|
|
@@ -74,7 +67,7 @@ function calculateOneDimensionTable(chart, value, username, userId) {
|
|
|
74
67
|
const statisticColumnKeys = [summary_column_key, ...summary_columns_option_keys];
|
|
75
68
|
const validStatisticColumnKeys = statisticColumnKeys;
|
|
76
69
|
let statisticColumns = validStatisticColumnKeys.map(key => {
|
|
77
|
-
const column =
|
|
70
|
+
const column = TableUtils.getTableColumnByKey(table, key);
|
|
78
71
|
return column ? {
|
|
79
72
|
...column
|
|
80
73
|
} : null;
|
|
@@ -90,16 +83,16 @@ function calculateOneDimensionTable(chart, value, username, userId) {
|
|
|
90
83
|
const {
|
|
91
84
|
pivot_columns_total
|
|
92
85
|
} = getOneDimensionTotal(statisticColumns, summary_type, formulaRows, pivot_rows);
|
|
93
|
-
|
|
94
|
-
const pivot_columns = summary_type ===
|
|
86
|
+
StatUtils.sortStatistics(pivot_rows, column, 'name');
|
|
87
|
+
const pivot_columns = summary_type === SUMMARY_TYPE.COUNT ? [] : statisticColumns.map(column => {
|
|
95
88
|
return {
|
|
96
89
|
key: column.key,
|
|
97
90
|
method: column.method
|
|
98
91
|
};
|
|
99
|
-
}).filter(item =>
|
|
92
|
+
}).filter(item => TableUtils.getTableColumnByKey(table, item.key));
|
|
100
93
|
pivot_rows.forEach(row => {
|
|
101
94
|
row.original_name = row.name;
|
|
102
|
-
row.name =
|
|
95
|
+
row.name = getFormattedLabel(column, row.name, value.collaborators);
|
|
103
96
|
});
|
|
104
97
|
return {
|
|
105
98
|
pivot_columns_total,
|
|
@@ -128,7 +121,7 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
128
121
|
let dateColumnsTotalArr = {};
|
|
129
122
|
if (Array.isArray(columns) && columns.length > 0) {
|
|
130
123
|
columns.forEach(column => {
|
|
131
|
-
if (column &&
|
|
124
|
+
if (column && isDateColumn(column)) {
|
|
132
125
|
dateColumnsTotalArr[column.key] = [];
|
|
133
126
|
}
|
|
134
127
|
});
|
|
@@ -141,7 +134,7 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
141
134
|
...item
|
|
142
135
|
};
|
|
143
136
|
let totalMap = {};
|
|
144
|
-
if (summary_type ===
|
|
137
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
145
138
|
totalMap['total'] = rows.length;
|
|
146
139
|
pivot_columns_total.total = (pivot_columns_total['total'] || 0) + rows.length;
|
|
147
140
|
} else {
|
|
@@ -153,8 +146,8 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
153
146
|
method
|
|
154
147
|
} = summaryColumn;
|
|
155
148
|
const total = getTotal(summaryColumn, summary_type, method, rows, formula_rows);
|
|
156
|
-
if (summaryColumn &&
|
|
157
|
-
if (method ===
|
|
149
|
+
if (summaryColumn && isDateColumn(summaryColumn)) {
|
|
150
|
+
if (method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
158
151
|
totalMap['total'] = total;
|
|
159
152
|
} else {
|
|
160
153
|
totalMap['total'] = total === 0 ? 0 : total.date;
|
|
@@ -162,11 +155,11 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
162
155
|
dateColumnsTotalArr[key].push(total);
|
|
163
156
|
}
|
|
164
157
|
}
|
|
165
|
-
if (method ===
|
|
166
|
-
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key],
|
|
167
|
-
} else if (method ===
|
|
168
|
-
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key],
|
|
169
|
-
} else if (method ===
|
|
158
|
+
if (method === SUMMARY_METHOD_MAP.Max) {
|
|
159
|
+
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], SUMMARY_METHOD_MAP.Max).date;
|
|
160
|
+
} else if (method === SUMMARY_METHOD_MAP.Min) {
|
|
161
|
+
pivot_columns_total['total'] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], SUMMARY_METHOD_MAP.Min).date;
|
|
162
|
+
} else if (method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
170
163
|
const pivotColumnTotal = (pivot_columns_total['total'] ? pivot_columns_total['total'] - 0 : 0) + total;
|
|
171
164
|
pivot_columns_total['total'] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
172
165
|
}
|
|
@@ -184,8 +177,8 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
184
177
|
} = column;
|
|
185
178
|
const totalKey = key + method;
|
|
186
179
|
const total = getTotal(column, summary_type, method, rows, formula_rows);
|
|
187
|
-
if (column &&
|
|
188
|
-
if (method ===
|
|
180
|
+
if (column && isDateColumn(column)) {
|
|
181
|
+
if (method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
189
182
|
totalMap[totalKey] = total;
|
|
190
183
|
} else {
|
|
191
184
|
totalMap[totalKey] = total === 0 ? 0 : total.date;
|
|
@@ -193,11 +186,11 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
193
186
|
dateColumnsTotalArr[key].push(total);
|
|
194
187
|
}
|
|
195
188
|
}
|
|
196
|
-
if (method ===
|
|
197
|
-
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key],
|
|
198
|
-
} else if (method ===
|
|
199
|
-
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key],
|
|
200
|
-
} else if (method ===
|
|
189
|
+
if (method === SUMMARY_METHOD_MAP.Max) {
|
|
190
|
+
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], SUMMARY_METHOD_MAP.Max).date;
|
|
191
|
+
} else if (method === SUMMARY_METHOD_MAP.Min) {
|
|
192
|
+
pivot_columns_total[totalKey] = dateColumnsTotalArr[key].length === 0 ? 0 : getDateMaxOrMinTotal(dateColumnsTotalArr[key], SUMMARY_METHOD_MAP.Min).date;
|
|
193
|
+
} else if (method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
201
194
|
const pivotColumnTotal = (pivot_columns_total[totalKey] ? pivot_columns_total[totalKey] - 0 : 0) + total;
|
|
202
195
|
pivot_columns_total[totalKey] = Number.parseFloat(pivotColumnTotal.toFixed(8));
|
|
203
196
|
}
|
|
@@ -234,24 +227,24 @@ function calculateTwoDimensionTable(chart, value, username, userId) {
|
|
|
234
227
|
column_groupby_geolocation_granularity,
|
|
235
228
|
summary_columns_option
|
|
236
229
|
} = chart;
|
|
237
|
-
const table =
|
|
238
|
-
const view = table &&
|
|
230
|
+
const table = TableUtils.getTableById(value.tables, table_id);
|
|
231
|
+
const view = table && Views.getViewById(table.views, view_id);
|
|
239
232
|
if (!view) return;
|
|
240
|
-
const groupbyColumn =
|
|
233
|
+
const groupbyColumn = TableUtils.getTableColumnByKey(table, groupby_column_key);
|
|
241
234
|
if (!groupbyColumn) return;
|
|
242
|
-
const isGroupbyColumnDataAsAnArray =
|
|
243
|
-
const rowGroupbyColumn =
|
|
235
|
+
const isGroupbyColumnDataAsAnArray = isArrayCellValue(groupbyColumn);
|
|
236
|
+
const rowGroupbyColumn = TableUtils.getTableColumnByKey(table, column_groupby_column_key);
|
|
244
237
|
if (!rowGroupbyColumn) {
|
|
245
238
|
return calculateOneDimensionTable(chart, value);
|
|
246
239
|
}
|
|
247
|
-
const isRowGroupbyColumnDataAsAnArray =
|
|
248
|
-
const summaryColumn =
|
|
249
|
-
const statRows =
|
|
250
|
-
const formulaRows =
|
|
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);
|
|
251
244
|
const pivot_summary_multiple_columns = [];
|
|
252
245
|
summary_columns_option.forEach(item => {
|
|
253
|
-
const column =
|
|
254
|
-
if (column &&
|
|
246
|
+
const column = TableUtils.getTableColumnByKey(table, item.key);
|
|
247
|
+
if (column && isNumericColumn(column)) {
|
|
255
248
|
pivot_summary_multiple_columns.push({
|
|
256
249
|
key: item.key,
|
|
257
250
|
type: column.type,
|
|
@@ -282,12 +275,12 @@ function calculateTwoDimensionTable(chart, value, username, userId) {
|
|
|
282
275
|
_id: rowId
|
|
283
276
|
} = row;
|
|
284
277
|
const formulaRow = formulaRows[rowId];
|
|
285
|
-
const cellValueForColumn =
|
|
286
|
-
if (
|
|
278
|
+
const cellValueForColumn = StatUtils.getGroupLabel(row[rowGroupbyColumn.key], formulaRow, rowGroupbyColumn, column_groupby_date_granularity, column_groupby_geolocation_granularity, value);
|
|
279
|
+
if (isValidRow(row, formulaRow, rowGroupbyColumn, include_empty)) {
|
|
287
280
|
updateTwoDimensionColumns(value, pivot_columns, rowGroupbyColumn, row, formulaRow, include_empty, column_groupby_date_granularity, column_groupby_geolocation_granularity, isRowGroupbyColumnDataAsAnArray);
|
|
288
281
|
}
|
|
289
|
-
if (
|
|
290
|
-
const name =
|
|
282
|
+
if (isValidRow(row, formulaRow, groupbyColumn, include_empty)) {
|
|
283
|
+
const name = StatUtils.getGroupLabel(row[groupbyColumn.key], formulaRow, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, value);
|
|
291
284
|
let pivotRowIndex;
|
|
292
285
|
if (isGroupbyColumnDataAsAnArray) {
|
|
293
286
|
if (name.length === 0 && include_empty) {
|
|
@@ -311,18 +304,18 @@ function calculateTwoDimensionTable(chart, value, username, userId) {
|
|
|
311
304
|
pivot_columns_total,
|
|
312
305
|
pivot_table_total
|
|
313
306
|
} = getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formulaRows, pivot_rows, pivot_columns);
|
|
314
|
-
|
|
315
|
-
|
|
307
|
+
StatUtils.sortStatistics(pivot_rows, groupbyColumn, 'name');
|
|
308
|
+
StatUtils.sortStatistics(pivot_columns, rowGroupbyColumn, 'key');
|
|
316
309
|
|
|
317
310
|
// format shown label(name)
|
|
318
311
|
const map = {};
|
|
319
312
|
pivot_columns.forEach(column => {
|
|
320
|
-
const name =
|
|
313
|
+
const name = getFormattedLabel(rowGroupbyColumn, column.key, value.collaborators);
|
|
321
314
|
map[column.key] = name;
|
|
322
315
|
column.key = name;
|
|
323
316
|
});
|
|
324
317
|
pivot_rows.forEach(row => {
|
|
325
|
-
row.name =
|
|
318
|
+
row.name = getFormattedLabel(groupbyColumn, row.name, value.collaborators);
|
|
326
319
|
const cells = {};
|
|
327
320
|
Object.keys(row.cells).forEach(key => {
|
|
328
321
|
cells[map[key]] = row.cells[key];
|
|
@@ -343,7 +336,7 @@ function calculateTwoDimensionTable(chart, value, username, userId) {
|
|
|
343
336
|
};
|
|
344
337
|
}
|
|
345
338
|
function updateTwoDimensionColumns(value, pivot_columns, column, row, formulaRow, isIncludeEmpty, dateGranularity, geolocationGranularity, isRowGroupbyColumnDataAsAnArray) {
|
|
346
|
-
let key =
|
|
339
|
+
let key = StatUtils.getGroupLabel(row[column.key], formulaRow, column, dateGranularity, geolocationGranularity, value);
|
|
347
340
|
let pivotColumnIndex;
|
|
348
341
|
if (isRowGroupbyColumnDataAsAnArray) {
|
|
349
342
|
if (key.length === 0 && isIncludeEmpty) {
|
|
@@ -420,7 +413,7 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
|
|
|
420
413
|
}
|
|
421
414
|
}
|
|
422
415
|
function isSameName(prevName, currName) {
|
|
423
|
-
if (
|
|
416
|
+
if (isNumber(prevName) && isNumber(currName)) {
|
|
424
417
|
return prevName === currName;
|
|
425
418
|
}
|
|
426
419
|
if (!prevName && !currName) {
|
|
@@ -443,7 +436,7 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
|
|
|
443
436
|
let {
|
|
444
437
|
type: summary_column_type
|
|
445
438
|
} = summaryColumn || {};
|
|
446
|
-
const isSummaryDateColumn = summaryColumn &&
|
|
439
|
+
const isSummaryDateColumn = summaryColumn && isDateColumn(summaryColumn);
|
|
447
440
|
let date_summary_column_format = isSummaryDateColumn ? summaryColumn.data.format : '';
|
|
448
441
|
Array.isArray(pivot_rows) && pivot_rows.forEach(pivotRow => {
|
|
449
442
|
let {
|
|
@@ -482,8 +475,8 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
|
|
|
482
475
|
pivot_table_total += total;
|
|
483
476
|
}
|
|
484
477
|
});
|
|
485
|
-
if (summaryColumn &&
|
|
486
|
-
if (summary_method ===
|
|
478
|
+
if (summaryColumn && isDateColumn(summaryColumn)) {
|
|
479
|
+
if (summary_method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
487
480
|
pivot_columns_total = Number.parseFloat(pivot_table_total.toFixed(8));
|
|
488
481
|
} else {
|
|
489
482
|
pivot_columns_total = showTwoDimensionDateColumnsAndRowsTotal(dateColumnsTotalArr, pivot_rows, date_summary_column_format, pivot_columns, summary_method);
|
|
@@ -508,15 +501,15 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
508
501
|
const summary_column_type = summary_column ? summary_column.type : '';
|
|
509
502
|
const rowsLength = rows.length;
|
|
510
503
|
let total;
|
|
511
|
-
if (summary_type ===
|
|
504
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
512
505
|
total = rowsLength;
|
|
513
|
-
} else if (summary_type ===
|
|
514
|
-
if (summary_method ===
|
|
506
|
+
} else if (summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
507
|
+
if (summary_method === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
515
508
|
total = 0;
|
|
516
509
|
let existMap = {};
|
|
517
510
|
rows.forEach(row => {
|
|
518
511
|
let num;
|
|
519
|
-
if (
|
|
512
|
+
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
520
513
|
const formulaRow = formula_rows[row._id] || {};
|
|
521
514
|
num = formulaRow[summary_column_key];
|
|
522
515
|
num = Array.isArray(num) ? num[0] : num;
|
|
@@ -537,14 +530,14 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
537
530
|
});
|
|
538
531
|
return total;
|
|
539
532
|
}
|
|
540
|
-
if (summary_column &&
|
|
533
|
+
if (summary_column && isDateColumn(summary_column)) {
|
|
541
534
|
if (rowsLength === 0) return;
|
|
542
535
|
let dateArr = [];
|
|
543
536
|
rows.forEach(r => {
|
|
544
537
|
let formatDate = {};
|
|
545
538
|
let formatDateData;
|
|
546
539
|
let value = r[summary_column_key];
|
|
547
|
-
if (
|
|
540
|
+
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
548
541
|
let formulaRow = formula_rows[r._id] || {};
|
|
549
542
|
value = formulaRow[summary_column_key];
|
|
550
543
|
}
|
|
@@ -561,21 +554,21 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
561
554
|
formatDate.value = Date.parse(formatDateData);
|
|
562
555
|
dateArr.push(formatDate);
|
|
563
556
|
});
|
|
564
|
-
if (summary_method ===
|
|
565
|
-
total = getDateMaxOrMinTotal(dateArr,
|
|
566
|
-
} else if (summary_method ===
|
|
567
|
-
total = getDateMaxOrMinTotal(dateArr,
|
|
557
|
+
if (summary_method === SUMMARY_METHOD_MAP.Max) {
|
|
558
|
+
total = getDateMaxOrMinTotal(dateArr, SUMMARY_METHOD_MAP.Max);
|
|
559
|
+
} else if (summary_method === SUMMARY_METHOD_MAP.Min) {
|
|
560
|
+
total = getDateMaxOrMinTotal(dateArr, SUMMARY_METHOD_MAP.Min);
|
|
568
561
|
}
|
|
569
562
|
} else {
|
|
570
563
|
switch (summary_method) {
|
|
571
|
-
case
|
|
572
|
-
case
|
|
564
|
+
case SUMMARY_METHOD_MAP.Sum:
|
|
565
|
+
case SUMMARY_METHOD_MAP.Mean:
|
|
573
566
|
{
|
|
574
567
|
let sum = 0;
|
|
575
568
|
let validNumbersCount = 0;
|
|
576
569
|
rows.forEach(r => {
|
|
577
570
|
let num;
|
|
578
|
-
if (
|
|
571
|
+
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
579
572
|
let formulaRow = formula_rows[r._id] || {};
|
|
580
573
|
if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
|
|
581
574
|
num = formulaRow[summary_column_key][0];
|
|
@@ -585,7 +578,7 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
585
578
|
} else {
|
|
586
579
|
num = r[summary_column_key];
|
|
587
580
|
}
|
|
588
|
-
if (
|
|
581
|
+
if (isNumber(num)) {
|
|
589
582
|
validNumbersCount++;
|
|
590
583
|
sum += num;
|
|
591
584
|
}
|
|
@@ -597,13 +590,13 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
597
590
|
}
|
|
598
591
|
break;
|
|
599
592
|
}
|
|
600
|
-
case
|
|
601
|
-
case
|
|
593
|
+
case SUMMARY_METHOD_MAP.Max:
|
|
594
|
+
case SUMMARY_METHOD_MAP.Min:
|
|
602
595
|
{
|
|
603
596
|
if (rowsLength > 0) {
|
|
604
597
|
let result = rows.reduce((current, next) => {
|
|
605
598
|
let currentValue, nextValue;
|
|
606
|
-
if (
|
|
599
|
+
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
607
600
|
let currentFormulaRow = formula_rows[current._id] || {};
|
|
608
601
|
let nextFormulaRow = formula_rows[next._id] || {};
|
|
609
602
|
currentValue = currentFormulaRow[summary_column_key];
|
|
@@ -622,7 +615,7 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
622
615
|
return isNextGreater ? next : current;
|
|
623
616
|
}
|
|
624
617
|
});
|
|
625
|
-
if (
|
|
618
|
+
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
626
619
|
let formulaRow = formula_rows[result._id];
|
|
627
620
|
if (formulaRow) {
|
|
628
621
|
if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _dtableStore = require("dtable-store");
|
|
9
|
-
var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
|
|
10
|
-
var _commonUtils = require("../../utils/common-utils");
|
|
11
|
-
var _rowUtils = require("../../utils/row-utils");
|
|
12
|
-
var _constants = require("../../constants");
|
|
1
|
+
import { isNumber, TableUtils, Views } from 'dtable-store';
|
|
2
|
+
import StatUtils from '../../utils/stat-utils';
|
|
3
|
+
import { isArrayCellValue } from '../../utils/common-utils';
|
|
4
|
+
import { getCellValue, getFormattedLabel } from '../../utils/row-utils';
|
|
5
|
+
import { DATE_GRANULARITY } from '../../constants';
|
|
13
6
|
function calculateResult(chart, value, username, userId) {
|
|
14
7
|
const {
|
|
15
8
|
table_id,
|
|
@@ -18,26 +11,26 @@ function calculateResult(chart, value, username, userId) {
|
|
|
18
11
|
y_axis_column,
|
|
19
12
|
group_column
|
|
20
13
|
} = chart;
|
|
21
|
-
const table =
|
|
22
|
-
const view = table &&
|
|
14
|
+
const table = TableUtils.getTableById(value.tables, table_id);
|
|
15
|
+
const view = table && Views.getViewById(table.views, view_id);
|
|
23
16
|
if (!view) {
|
|
24
17
|
return [];
|
|
25
18
|
}
|
|
26
|
-
const selectedXAxisColumn =
|
|
27
|
-
const selectedYAxisColumn =
|
|
28
|
-
const selectedGroupColumn =
|
|
29
|
-
const statRows =
|
|
30
|
-
const formulaRows =
|
|
19
|
+
const selectedXAxisColumn = TableUtils.getTableColumnByKey(table, x_axis_column);
|
|
20
|
+
const selectedYAxisColumn = TableUtils.getTableColumnByKey(table, y_axis_column);
|
|
21
|
+
const selectedGroupColumn = TableUtils.getTableColumnByKey(table, group_column);
|
|
22
|
+
const statRows = Views.getViewRows(view, table, value, username, userId);
|
|
23
|
+
const formulaRows = Views.getTableFormulaResults(table, statRows, value);
|
|
31
24
|
const data = [];
|
|
32
25
|
statRows.forEach(row => {
|
|
33
26
|
const {
|
|
34
27
|
_id: rowId
|
|
35
28
|
} = row;
|
|
36
29
|
const formulaRow = formulaRows[rowId] || {};
|
|
37
|
-
let x_axis =
|
|
38
|
-
let y_axis =
|
|
39
|
-
x_axis =
|
|
40
|
-
y_axis =
|
|
30
|
+
let x_axis = getCellValue(row, formulaRow, selectedXAxisColumn);
|
|
31
|
+
let y_axis = getCellValue(row, formulaRow, selectedYAxisColumn);
|
|
32
|
+
x_axis = isNumber(x_axis) ? x_axis : 0;
|
|
33
|
+
y_axis = isNumber(y_axis) ? y_axis : 0;
|
|
41
34
|
const name = getColumnValue(row, formulaRow, selectedGroupColumn, value);
|
|
42
35
|
const nameIndex = data.findIndex(r => r.name === name && r.x_axis === x_axis && r.y_axis === y_axis);
|
|
43
36
|
const dataItem = {
|
|
@@ -66,11 +59,11 @@ function updateBasicChartRows(results, index, name, dataItem, row) {
|
|
|
66
59
|
}
|
|
67
60
|
function getColumnValue(data, formulaRow, column, dtableValue) {
|
|
68
61
|
const tempValue = data[column.key];
|
|
69
|
-
let value =
|
|
70
|
-
if (
|
|
62
|
+
let value = StatUtils.getGroupLabel(tempValue, formulaRow, column, DATE_GRANULARITY.DAY, '', dtableValue);
|
|
63
|
+
if (isArrayCellValue(column)) {
|
|
71
64
|
value = value[0];
|
|
72
65
|
}
|
|
73
|
-
value =
|
|
66
|
+
value = getFormattedLabel(column, value, dtableValue.collaborators);
|
|
74
67
|
return value;
|
|
75
68
|
}
|
|
76
|
-
|
|
69
|
+
export default calculateResult;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _dtableStore = require("dtable-store");
|
|
11
|
-
var _constants = require("../../constants");
|
|
12
|
-
var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
|
|
13
|
-
var _rowUtils = require("../../utils/row-utils");
|
|
14
|
-
var _commonUtils = require("../../utils/common-utils");
|
|
15
|
-
var _trendUtils = require("../../utils/trend-utils");
|
|
16
|
-
_dayjs.default.extend(_quarterOfYear.default);
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
3
|
+
import { FORMULA_COLUMN_TYPES_MAP, isNumber, TableUtils, Views } from 'dtable-store';
|
|
4
|
+
import { SUMMARY_TYPE } from '../../constants';
|
|
5
|
+
import StatUtils from '../../utils/stat-utils';
|
|
6
|
+
import { getCellValue } from '../../utils/row-utils';
|
|
7
|
+
import { getSummaryResult } from '../../utils/common-utils';
|
|
8
|
+
import { getCompareDate, summaryDurationResult } from '../../utils/trend-utils';
|
|
9
|
+
dayjs.extend(quarterOfYear);
|
|
17
10
|
function calculateStatItem(chart, value, username, userId) {
|
|
18
11
|
const {
|
|
19
12
|
table_id,
|
|
@@ -24,16 +17,16 @@ function calculateStatItem(chart, value, username, userId) {
|
|
|
24
17
|
summary_type,
|
|
25
18
|
summary_method
|
|
26
19
|
} = chart;
|
|
27
|
-
const selectedTable =
|
|
28
|
-
const selectedView = selectedTable &&
|
|
29
|
-
const selectedColumn =
|
|
20
|
+
const selectedTable = TableUtils.getTableById(value.tables, table_id);
|
|
21
|
+
const selectedView = selectedTable && Views.getViewById(selectedTable.views, view_id);
|
|
22
|
+
const selectedColumn = TableUtils.getTableColumnByKey(selectedTable, date_column);
|
|
30
23
|
const resultMap = new Map();
|
|
31
24
|
let formulaRows = {};
|
|
32
|
-
const rows =
|
|
33
|
-
const numericColumn =
|
|
34
|
-
if (summary_type ===
|
|
35
|
-
if (
|
|
36
|
-
formulaRows =
|
|
25
|
+
const rows = Views.getViewRows(selectedView, selectedTable, value, username, userId);
|
|
26
|
+
const numericColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column);
|
|
27
|
+
if (summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
28
|
+
if (FORMULA_COLUMN_TYPES_MAP[numericColumn.type]) {
|
|
29
|
+
formulaRows = Views.getTableFormulaResults(selectedTable, rows, value);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
32
|
let granularity = date_granularity;
|
|
@@ -42,16 +35,16 @@ function calculateStatItem(chart, value, username, userId) {
|
|
|
42
35
|
}
|
|
43
36
|
rows.forEach(row => {
|
|
44
37
|
const dateValue = row[selectedColumn.key];
|
|
45
|
-
const label =
|
|
38
|
+
const label = StatUtils.getGroupLabel(dateValue, {}, selectedColumn, granularity, '', value);
|
|
46
39
|
if (dateValue) {
|
|
47
|
-
if (summary_type ===
|
|
40
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
48
41
|
const currentCount = resultMap.get(label) || 0;
|
|
49
42
|
resultMap.set(label, currentCount + 1);
|
|
50
43
|
} else {
|
|
51
44
|
const formulaRow = formulaRows[row._id];
|
|
52
|
-
const numericValue =
|
|
45
|
+
const numericValue = getCellValue(row, formulaRow, numericColumn);
|
|
53
46
|
const currentList = resultMap.get(label) || [];
|
|
54
|
-
if (
|
|
47
|
+
if (isNumber(numericValue)) {
|
|
55
48
|
currentList.push(numericValue);
|
|
56
49
|
}
|
|
57
50
|
resultMap.set(label, currentList);
|
|
@@ -63,22 +56,22 @@ function calculateStatItem(chart, value, username, userId) {
|
|
|
63
56
|
const {
|
|
64
57
|
compareValue: value1,
|
|
65
58
|
comparedValue: value2
|
|
66
|
-
} =
|
|
59
|
+
} = summaryDurationResult(resultMap, date_granularity, summary_type, summary_column, false);
|
|
67
60
|
currentValues = value1;
|
|
68
61
|
previousValues = value2;
|
|
69
62
|
} else {
|
|
70
63
|
const {
|
|
71
64
|
compareDate,
|
|
72
65
|
comparedDate
|
|
73
|
-
} =
|
|
66
|
+
} = getCompareDate(date_granularity);
|
|
74
67
|
currentValues = resultMap.get(compareDate);
|
|
75
68
|
previousValues = resultMap.get(comparedDate);
|
|
76
|
-
if (summary_type ===
|
|
69
|
+
if (summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
77
70
|
if (currentValues) {
|
|
78
|
-
currentValues =
|
|
71
|
+
currentValues = getSummaryResult(currentValues, summary_method);
|
|
79
72
|
}
|
|
80
73
|
if (previousValues) {
|
|
81
|
-
previousValues =
|
|
74
|
+
previousValues = getSummaryResult(previousValues, summary_method);
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
}
|
|
@@ -101,4 +94,4 @@ function calculateStatItem(chart, value, username, userId) {
|
|
|
101
94
|
type: currentValues > previousValues ? 'up' : 'down'
|
|
102
95
|
};
|
|
103
96
|
}
|
|
104
|
-
|
|
97
|
+
export default calculateStatItem;
|