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
package/es/api/dtable-db-api.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
1
|
+
import axios from 'axios';
|
|
9
2
|
class DTableDbAPI {
|
|
10
3
|
constructor() {
|
|
11
4
|
this.req = null;
|
|
@@ -16,7 +9,7 @@ class DTableDbAPI {
|
|
|
16
9
|
accessToken,
|
|
17
10
|
dtableDb
|
|
18
11
|
} = window.dtable;
|
|
19
|
-
this.req =
|
|
12
|
+
this.req = axios.create({
|
|
20
13
|
baseURL: dtableDb,
|
|
21
14
|
headers: {
|
|
22
15
|
'Authorization': 'Token ' + accessToken
|
|
@@ -41,4 +34,4 @@ class DTableDbAPI {
|
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
36
|
const dtableDbAPI = new DTableDbAPI();
|
|
44
|
-
|
|
37
|
+
export default dtableDbAPI;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var ComLink = _interopRequireWildcard(require("comlink"));
|
|
10
|
-
var _dtableStore = require("dtable-store");
|
|
11
|
-
var _dtableDbApi = _interopRequireDefault(require("../api/dtable-db-api"));
|
|
12
|
-
var _calculatorWorker = _interopRequireDefault(require("./workers/calculator.worker.js"));
|
|
13
|
-
var _copyValue = _interopRequireDefault(require("./copy-value"));
|
|
1
|
+
import * as ComLink from 'comlink';
|
|
2
|
+
import { TableUtils, Views } from 'dtable-store';
|
|
3
|
+
import dtableDbAPI from '../api/dtable-db-api';
|
|
4
|
+
import CalculatorWorker from './workers/calculator.worker.js';
|
|
5
|
+
import copyValue from './copy-value';
|
|
14
6
|
class BaseCalculator {
|
|
15
7
|
constructor(_ref) {
|
|
16
8
|
let {
|
|
@@ -43,27 +35,27 @@ class BaseCalculator {
|
|
|
43
35
|
} = chart;
|
|
44
36
|
const table = this.getTableById(table_id);
|
|
45
37
|
const view = this.getViewById(view_id, table);
|
|
46
|
-
return
|
|
38
|
+
return Views.isArchiveView(view);
|
|
47
39
|
}
|
|
48
40
|
getTableById(tableId) {
|
|
49
|
-
return
|
|
41
|
+
return TableUtils.getTableById(this.value.tables, tableId);
|
|
50
42
|
}
|
|
51
43
|
getViewById(viewId, table) {
|
|
52
|
-
return table &&
|
|
44
|
+
return table && Views.getViewById(table.views, viewId);
|
|
53
45
|
}
|
|
54
46
|
async calculateWithWorker(chart) {
|
|
55
47
|
const {
|
|
56
48
|
_id: chartId
|
|
57
49
|
} = chart;
|
|
58
|
-
const calculatorWorker = await this.statisticThreadManager.applyThread(chartId,
|
|
50
|
+
const calculatorWorker = await this.statisticThreadManager.applyThread(chartId, CalculatorWorker);
|
|
59
51
|
const calculateChart = ComLink.wrap(calculatorWorker);
|
|
60
|
-
const newValue = (
|
|
52
|
+
const newValue = copyValue(this.value);
|
|
61
53
|
const result = await calculateChart(chart, newValue, this.username, this.userId);
|
|
62
54
|
this.statisticThreadManager.removeThread(chartId);
|
|
63
55
|
return result;
|
|
64
56
|
}
|
|
65
57
|
async sqlQuery(sql) {
|
|
66
|
-
return
|
|
58
|
+
return dtableDbAPI.sqlQuery(sql);
|
|
67
59
|
}
|
|
68
60
|
}
|
|
69
|
-
|
|
61
|
+
export default BaseCalculator;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _constants = require("../constants");
|
|
11
|
-
var _sqlUtils = require("../utils/sql-utils");
|
|
12
|
-
var _commonUtils = require("../utils/common-utils");
|
|
13
|
-
var _statUtils = _interopRequireDefault(require("../utils/stat-utils"));
|
|
14
|
-
var _columnUtils = require("../utils/column-utils");
|
|
15
|
-
var _rowUtils = require("../utils/row-utils");
|
|
16
|
-
class BasicChartCalculator extends _baseCalculator.default {
|
|
1
|
+
import { CellType, filter2SqlCondition, TableUtils } from 'dtable-store';
|
|
2
|
+
import BaseCalculator from './base-calculator';
|
|
3
|
+
import { DTABLE_DB_SUMMARY_METHOD, STAT_TYPE, SUMMARY_TYPE, TIME_COLUMN_LIST, Y_AXIS_TYPE_PREFIX } from '../constants';
|
|
4
|
+
import { getSqlGroup, getSqlOrder } from '../utils/sql-utils';
|
|
5
|
+
import { formatNumericValue, getSummaryColumnMethod } from '../utils/common-utils';
|
|
6
|
+
import StatUtils from '../utils/stat-utils';
|
|
7
|
+
import { getColorFromSingleSelectColumn } from '../utils/column-utils';
|
|
8
|
+
import { getFormattedLabel } from '../utils/row-utils';
|
|
9
|
+
class BasicChartCalculator extends BaseCalculator {
|
|
17
10
|
constructor(_ref) {
|
|
18
11
|
let {
|
|
19
12
|
value,
|
|
@@ -32,7 +25,7 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
32
25
|
if (!this.validateBaseConfigs(chart)) {
|
|
33
26
|
return false;
|
|
34
27
|
}
|
|
35
|
-
if (chart.type ===
|
|
28
|
+
if (chart.type === STAT_TYPE.CUSTOM_BAR) {
|
|
36
29
|
return this.isValidCustomBar(chart);
|
|
37
30
|
}
|
|
38
31
|
const {
|
|
@@ -44,11 +37,11 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
44
37
|
} = chart;
|
|
45
38
|
const table = this.getTableById(table_id);
|
|
46
39
|
const groupbyColumnKey = groupby_column_key || x_axis_column_key;
|
|
47
|
-
if (!groupbyColumnKey || !
|
|
40
|
+
if (!groupbyColumnKey || !TableUtils.getTableColumnByKey(table, groupbyColumnKey)) {
|
|
48
41
|
return false;
|
|
49
42
|
}
|
|
50
43
|
const summaryColumnKey = summary_column_key || y_axis_column_key;
|
|
51
|
-
if (summaryColumnKey && !
|
|
44
|
+
if (summaryColumnKey && !TableUtils.getTableColumnByKey(table, summaryColumnKey)) {
|
|
52
45
|
return false;
|
|
53
46
|
}
|
|
54
47
|
return true;
|
|
@@ -73,7 +66,7 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
73
66
|
return await this.calculateWithWorker(chart);
|
|
74
67
|
}
|
|
75
68
|
async queryDb(chart) {
|
|
76
|
-
if (chart.type ===
|
|
69
|
+
if (chart.type === STAT_TYPE.CUSTOM_BAR) {
|
|
77
70
|
return this.queryDbFromCustomBar(chart);
|
|
78
71
|
}
|
|
79
72
|
const {
|
|
@@ -84,7 +77,7 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
84
77
|
let groupby_column_key, summary_type, summary_method, summary_column_key, groupby_date_granularity, include_empty, groupby_geolocation_granularity;
|
|
85
78
|
const column_groupby_column_key = chart.column_groupby_column_key;
|
|
86
79
|
const sortType = chart.sort_type;
|
|
87
|
-
if (chart.type ===
|
|
80
|
+
if (chart.type === STAT_TYPE.PIE || chart.type === STAT_TYPE.RING || chart.type === STAT_TYPE.TREEMAP) {
|
|
88
81
|
groupby_column_key = chart.groupby_column_key;
|
|
89
82
|
summary_type = chart.summary_type;
|
|
90
83
|
summary_method = chart.summary_method;
|
|
@@ -107,14 +100,14 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
107
100
|
if (!selectedView) {
|
|
108
101
|
return [];
|
|
109
102
|
}
|
|
110
|
-
const groupbyColumn =
|
|
111
|
-
const sqlCondition =
|
|
103
|
+
const groupbyColumn = TableUtils.getTableColumnByKey(selectedTable, groupby_column_key);
|
|
104
|
+
const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
112
105
|
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
113
|
-
const isTimeColumn =
|
|
106
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
114
107
|
if (isTimeColumn) {
|
|
115
|
-
groupbyName =
|
|
116
|
-
} else if (groupbyColumn.type ===
|
|
117
|
-
groupbyName =
|
|
108
|
+
groupbyName = getSqlGroup(groupby_date_granularity, groupbyColumn);
|
|
109
|
+
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
110
|
+
groupbyName = getSqlGroup(groupby_geolocation_granularity, groupbyColumn);
|
|
118
111
|
}
|
|
119
112
|
let results;
|
|
120
113
|
if (!column_groupby_column_key && !column_groupby_multiple_numeric_column) {
|
|
@@ -123,7 +116,7 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
123
116
|
const {
|
|
124
117
|
column_groupby_numeric_columns
|
|
125
118
|
} = chart;
|
|
126
|
-
const summaryColumn =
|
|
119
|
+
const summaryColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column_key);
|
|
127
120
|
if (!summaryColumn) return [];
|
|
128
121
|
results = await this.getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summaryColumn, summary_method, column_groupby_numeric_columns, sqlCondition, selectedTable, yAxisType);
|
|
129
122
|
} else {
|
|
@@ -133,7 +126,7 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
133
126
|
} = chart;
|
|
134
127
|
results = await this.getGroupbyOneColumnResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summary_column_key, summary_method, column_groupby_column_key, column_groupby_date_granularity, column_groupby_geolocation_granularity, sqlCondition, selectedTable, yAxisType);
|
|
135
128
|
}
|
|
136
|
-
sortType &&
|
|
129
|
+
sortType && StatUtils.sortStatisticData(results, sortType);
|
|
137
130
|
return results;
|
|
138
131
|
}
|
|
139
132
|
async queryDbFromCustomBar(chart) {
|
|
@@ -152,19 +145,19 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
152
145
|
if (!selectedView || !x_axis_column_key || !Array.isArray(y_axises) || y_axises.length === 0) {
|
|
153
146
|
return [];
|
|
154
147
|
}
|
|
155
|
-
const groupbyColumn =
|
|
148
|
+
const groupbyColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
156
149
|
if (!groupbyColumn) {
|
|
157
150
|
return [];
|
|
158
151
|
}
|
|
159
|
-
const sqlCondition =
|
|
160
|
-
const isTimeColumn =
|
|
152
|
+
const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
153
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
161
154
|
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
162
155
|
if (isTimeColumn) {
|
|
163
|
-
groupbyName =
|
|
164
|
-
} else if (groupbyColumn.type ===
|
|
165
|
-
groupbyName =
|
|
156
|
+
groupbyName = getSqlGroup(x_axis_date_granularity, groupbyColumn);
|
|
157
|
+
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
158
|
+
groupbyName = getSqlGroup(x_axis_geolocation_granularity, groupbyColumn);
|
|
166
159
|
}
|
|
167
|
-
const summaryType =
|
|
160
|
+
const summaryType = SUMMARY_TYPE.ADVANCED;
|
|
168
161
|
const yAxisSummaryColumn = null;
|
|
169
162
|
const yAxisSummaryMethod = null;
|
|
170
163
|
let results = [];
|
|
@@ -174,31 +167,31 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
174
167
|
type: yAxisType,
|
|
175
168
|
column_groupby_numeric_columns
|
|
176
169
|
} = stack;
|
|
177
|
-
if (yAxisType ===
|
|
170
|
+
if (yAxisType === STAT_TYPE.BAR_STACK) {
|
|
178
171
|
// just support summary numeric columns.
|
|
179
172
|
if (!Array.isArray(column_groupby_numeric_columns) || column_groupby_numeric_columns.length === 0) {
|
|
180
173
|
continue;
|
|
181
174
|
}
|
|
182
|
-
const yAxisType = "".concat(
|
|
175
|
+
const yAxisType = "".concat(Y_AXIS_TYPE_PREFIX).concat(i);
|
|
183
176
|
const currentResults = await this.getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, x_axis_date_granularity, x_axis_geolocation_granularity, x_axis_include_empty, summaryType, yAxisSummaryColumn, yAxisSummaryMethod, column_groupby_numeric_columns, sqlCondition, selectedTable, yAxisType);
|
|
184
177
|
results = results.concat(currentResults);
|
|
185
178
|
}
|
|
186
179
|
}
|
|
187
|
-
sort_type &&
|
|
180
|
+
sort_type && StatUtils.sortStatisticData(results, sort_type);
|
|
188
181
|
return results;
|
|
189
182
|
}
|
|
190
183
|
async getNoneGroupbyResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, sortType, sqlCondition, table, yAxisType) {
|
|
191
|
-
const isAdvanced = summaryType ===
|
|
184
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
192
185
|
let selectedSummaryColumn;
|
|
193
186
|
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
194
187
|
if (isAdvanced) {
|
|
195
|
-
selectedSummaryColumn =
|
|
188
|
+
selectedSummaryColumn = TableUtils.getTableColumnByKey(table, summaryColumnKey);
|
|
196
189
|
if (!selectedSummaryColumn) return [];
|
|
197
190
|
summaryColumnName = selectedSummaryColumn.name;
|
|
198
191
|
}
|
|
199
|
-
const method = isAdvanced ?
|
|
200
|
-
const summaryColumnMethod =
|
|
201
|
-
const sqlOrder =
|
|
192
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
193
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
194
|
+
const sqlOrder = getSqlOrder(sortType, groupbyName);
|
|
202
195
|
const sqlString = "select ".concat(groupbyName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " ").concat(sqlOrder, " limit 5000");
|
|
203
196
|
const queryResult = await this.sqlQuery(sqlString);
|
|
204
197
|
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
@@ -216,8 +209,8 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
216
209
|
let value = item[valueKey] || 0;
|
|
217
210
|
let formatted_value = value;
|
|
218
211
|
if (isAdvanced) {
|
|
219
|
-
value =
|
|
220
|
-
formatted_value =
|
|
212
|
+
value = formatNumericValue(value, selectedSummaryColumn);
|
|
213
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
221
214
|
}
|
|
222
215
|
newResult.push({
|
|
223
216
|
name: label,
|
|
@@ -230,23 +223,23 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
230
223
|
return newResult;
|
|
231
224
|
}
|
|
232
225
|
async getGroupbyOneColumnResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, columnGroupbyColumnKey, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, sqlCondition, table, yAxisType) {
|
|
233
|
-
const isAdvanced = summaryType ===
|
|
226
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
234
227
|
let selectedSummaryColumn;
|
|
235
228
|
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
236
229
|
if (isAdvanced) {
|
|
237
|
-
selectedSummaryColumn =
|
|
230
|
+
selectedSummaryColumn = TableUtils.getTableColumnByKey(table, summaryColumnKey);
|
|
238
231
|
if (!selectedSummaryColumn) return [];
|
|
239
232
|
summaryColumnName = selectedSummaryColumn.name;
|
|
240
233
|
}
|
|
241
|
-
const columnGroupbyColumn =
|
|
234
|
+
const columnGroupbyColumn = TableUtils.getTableColumnByKey(table, columnGroupbyColumnKey);
|
|
242
235
|
let columnGroupbyColumnName = "`".concat(columnGroupbyColumn.name, "`");
|
|
243
|
-
if (
|
|
244
|
-
columnGroupbyColumnName =
|
|
245
|
-
} else if (columnGroupbyColumn.type ===
|
|
246
|
-
columnGroupbyColumnName =
|
|
236
|
+
if (TIME_COLUMN_LIST.includes(columnGroupbyColumn.type)) {
|
|
237
|
+
columnGroupbyColumnName = getSqlGroup(columnGroupbyDateGranularity, columnGroupbyColumn);
|
|
238
|
+
} else if (columnGroupbyColumn.type === CellType.GEOLOCATION) {
|
|
239
|
+
columnGroupbyColumnName = getSqlGroup(columnGroupbyGeolocationGranularity, columnGroupbyColumn);
|
|
247
240
|
}
|
|
248
|
-
const method = isAdvanced ?
|
|
249
|
-
const summaryColumnMethod =
|
|
241
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
242
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
250
243
|
const sqlString = "select ".concat(groupbyName, ", ").concat(columnGroupbyColumnName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, ", ").concat(columnGroupbyColumnName, " order by ").concat(groupbyName, " limit 5000");
|
|
251
244
|
const queryResult = await this.sqlQuery(sqlString);
|
|
252
245
|
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
@@ -264,13 +257,13 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
264
257
|
let value = item[valueKey] || 0;
|
|
265
258
|
let formatted_value = value;
|
|
266
259
|
if (isAdvanced) {
|
|
267
|
-
value =
|
|
268
|
-
formatted_value =
|
|
260
|
+
value = formatNumericValue(value, selectedSummaryColumn);
|
|
261
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
269
262
|
}
|
|
270
263
|
let color;
|
|
271
|
-
if (columnGroupbyColumn.type ===
|
|
272
|
-
const tempValue =
|
|
273
|
-
color =
|
|
264
|
+
if (columnGroupbyColumn.type === CellType.SINGLE_SELECT) {
|
|
265
|
+
const tempValue = StatUtils.getGroupLabel(item[columnGroupbyColumn.key], item, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, this.value);
|
|
266
|
+
color = getColorFromSingleSelectColumn(columnGroupbyColumn, tempValue);
|
|
274
267
|
}
|
|
275
268
|
const groupLabel = this.getLabel(columnGroupbyColumn, columnGroupbyColumnName, item, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity);
|
|
276
269
|
newResult.push({
|
|
@@ -287,26 +280,26 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
287
280
|
return newResult;
|
|
288
281
|
}
|
|
289
282
|
async getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumn, summaryMethod, columnGroupbyNumericColumns, sqlCondition, table, yAxisType) {
|
|
290
|
-
const isAdvanced = summaryType ===
|
|
283
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
291
284
|
let numericColumns = [];
|
|
292
285
|
let groupColumnNames = [];
|
|
293
286
|
let groupMethods = [];
|
|
294
287
|
let originalMethods = [];
|
|
295
288
|
if (summaryColumn) {
|
|
296
289
|
const summaryColumnName = isAdvanced ? summaryColumn.name : "`".concat(groupbyColumn.name, "`");
|
|
297
|
-
const method = isAdvanced ?
|
|
298
|
-
const summaryColumnMethod =
|
|
290
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
291
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
299
292
|
numericColumns.push(summaryColumn);
|
|
300
293
|
groupColumnNames.push(summaryColumnName);
|
|
301
294
|
groupMethods.push(summaryColumnMethod);
|
|
302
295
|
originalMethods.push(summaryMethod);
|
|
303
296
|
}
|
|
304
297
|
columnGroupbyNumericColumns.forEach(item => {
|
|
305
|
-
const numericColumn =
|
|
298
|
+
const numericColumn = TableUtils.getTableColumnByKey(table, item.column_key);
|
|
306
299
|
const groupColumnName = numericColumn.name;
|
|
307
300
|
numericColumns.push(numericColumn);
|
|
308
301
|
groupColumnNames.push(groupColumnName);
|
|
309
|
-
groupMethods.push(
|
|
302
|
+
groupMethods.push(getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[item.summary_method], groupColumnName));
|
|
310
303
|
originalMethods.push(item.summary_method);
|
|
311
304
|
});
|
|
312
305
|
const sqlString = "select ".concat(groupbyName, ", ").concat(groupMethods.join(','), " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " order by ").concat(groupbyName, " limit 5000");
|
|
@@ -328,8 +321,8 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
328
321
|
let value = item[groupMethods[index]] || 0;
|
|
329
322
|
let formatted_value = value;
|
|
330
323
|
if (isAdvanced) {
|
|
331
|
-
value =
|
|
332
|
-
formatted_value =
|
|
324
|
+
value = formatNumericValue(value, numericColumns[index]);
|
|
325
|
+
formatted_value = StatUtils.getFormattedValue(value, numericColumns[index], originalMethods[index]);
|
|
333
326
|
}
|
|
334
327
|
groupItems.push({
|
|
335
328
|
name: label,
|
|
@@ -345,14 +338,14 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
345
338
|
return newResult;
|
|
346
339
|
}
|
|
347
340
|
getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
348
|
-
const isTimeColumn =
|
|
341
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
349
342
|
let label;
|
|
350
|
-
if (isTimeColumn || groupColumn.type ===
|
|
343
|
+
if (isTimeColumn || groupColumn.type === CellType.GEOLOCATION) {
|
|
351
344
|
label = item[groupName];
|
|
352
345
|
} else {
|
|
353
346
|
const currentGroupLabel = item[groupColumn.key];
|
|
354
|
-
label =
|
|
355
|
-
label =
|
|
347
|
+
label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
348
|
+
label = getFormattedLabel(groupColumn, label, this.value.collaborators);
|
|
356
349
|
}
|
|
357
350
|
return label;
|
|
358
351
|
}
|
|
@@ -360,4 +353,4 @@ class BasicChartCalculator extends _baseCalculator.default {
|
|
|
360
353
|
return !label;
|
|
361
354
|
}
|
|
362
355
|
}
|
|
363
|
-
|
|
356
|
+
export default BasicChartCalculator;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
|
|
10
|
-
var _statUtils = _interopRequireDefault(require("../utils/stat-utils"));
|
|
11
|
-
var _commonUtils = require("../utils/common-utils");
|
|
12
|
-
var _rowUtils = require("../utils/row-utils");
|
|
13
|
-
var _sqlUtils = require("../utils/sql-utils");
|
|
14
|
-
var _constants = require("../constants");
|
|
15
|
-
class CombinationCalculator extends _baseCalculator.default {
|
|
1
|
+
import { CellType, filter2SqlCondition, TableUtils } from 'dtable-store';
|
|
2
|
+
import BaseCalculator from './base-calculator';
|
|
3
|
+
import StatUtils from '../utils/stat-utils';
|
|
4
|
+
import { getSummaryColumnMethod, formatNumericValue } from '../utils/common-utils';
|
|
5
|
+
import { getFormattedLabel } from '../utils/row-utils';
|
|
6
|
+
import { getSqlGroup } from '../utils/sql-utils';
|
|
7
|
+
import { DTABLE_DB_SUMMARY_METHOD, LABEL_COLORS, SUMMARY_TYPE, TIME_COLUMN_LIST } from '../constants';
|
|
8
|
+
class CombinationCalculator extends BaseCalculator {
|
|
16
9
|
constructor(_ref) {
|
|
17
10
|
let {
|
|
18
11
|
value,
|
|
@@ -45,14 +38,14 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
45
38
|
y_axis_left_summary_type
|
|
46
39
|
} = chart;
|
|
47
40
|
const table = this.getTableById(table_id);
|
|
48
|
-
if (x_axis_column_key && !
|
|
41
|
+
if (x_axis_column_key && !TableUtils.getTableColumnByKey(table, x_axis_column_key)) {
|
|
49
42
|
return false;
|
|
50
43
|
}
|
|
51
44
|
if (!y_axis_left_summary_type || !y_axis_right_summary_type) return false;
|
|
52
|
-
if (y_axis_left_summary_type ===
|
|
45
|
+
if (y_axis_left_summary_type === SUMMARY_TYPE.ADVANCED && y_axis_left_summary_method && !TableUtils.getTableColumnByKey(table, y_axis_left_summary_column)) {
|
|
53
46
|
return false;
|
|
54
47
|
}
|
|
55
|
-
if (y_axis_right_summary_type ===
|
|
48
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED && y_axis_right_summary_method && !TableUtils.getTableColumnByKey(table, y_axis_right_summary_column)) {
|
|
56
49
|
return false;
|
|
57
50
|
}
|
|
58
51
|
return true;
|
|
@@ -81,13 +74,13 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
81
74
|
y_axis_left_group_by_numeric_columns
|
|
82
75
|
} = chart;
|
|
83
76
|
const selectedTable = this.getTableById(table_id);
|
|
84
|
-
const selectedColumn =
|
|
77
|
+
const selectedColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
85
78
|
if (!selectedColumn) return [];
|
|
86
79
|
let groupName = "`".concat(selectedColumn.name, "`");
|
|
87
|
-
if (
|
|
88
|
-
groupName =
|
|
89
|
-
} else if (selectedColumn.type ===
|
|
90
|
-
groupName =
|
|
80
|
+
if (TIME_COLUMN_LIST.includes(selectedColumn.type)) {
|
|
81
|
+
groupName = getSqlGroup(groupby_date_granularity, selectedColumn);
|
|
82
|
+
} else if (selectedColumn.type === CellType.GEOLOCATION) {
|
|
83
|
+
groupName = getSqlGroup(groupby_geolocation_granularity, selectedColumn);
|
|
91
84
|
}
|
|
92
85
|
let sqlString = this.getSqlString(chart, groupName);
|
|
93
86
|
const result = await this.sqlQuery(sqlString);
|
|
@@ -100,14 +93,14 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
100
93
|
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
101
94
|
let value1Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
102
95
|
let leftSummaryColumn, rightSummaryColumn;
|
|
103
|
-
if (y_axis_left_summary_type ===
|
|
104
|
-
leftSummaryColumn =
|
|
105
|
-
value1Key =
|
|
96
|
+
if (y_axis_left_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
97
|
+
leftSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_left_summary_column);
|
|
98
|
+
value1Key = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], leftSummaryColumn.name);
|
|
106
99
|
}
|
|
107
100
|
let value2Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
108
|
-
if (y_axis_right_summary_type ===
|
|
109
|
-
rightSummaryColumn =
|
|
110
|
-
value2Key =
|
|
101
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
102
|
+
rightSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_right_summary_column);
|
|
103
|
+
value2Key = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], rightSummaryColumn.name);
|
|
111
104
|
}
|
|
112
105
|
data.forEach(item => {
|
|
113
106
|
let label = this.getLabel(selectedColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity);
|
|
@@ -115,13 +108,13 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
115
108
|
let value2 = item[value2Key] || 0;
|
|
116
109
|
let formattedValueLeft = value1;
|
|
117
110
|
let formattedValueRight = value2;
|
|
118
|
-
if (y_axis_left_summary_type ===
|
|
119
|
-
value1 =
|
|
120
|
-
formattedValueLeft =
|
|
111
|
+
if (y_axis_left_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
112
|
+
value1 = formatNumericValue(value1, leftSummaryColumn);
|
|
113
|
+
formattedValueLeft = StatUtils.getFormattedValue(value1, leftSummaryColumn, y_axis_left_summary_method);
|
|
121
114
|
}
|
|
122
|
-
if (y_axis_right_summary_type ===
|
|
123
|
-
value2 =
|
|
124
|
-
formattedValueRight =
|
|
115
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
116
|
+
value2 = formatNumericValue(value2, rightSummaryColumn);
|
|
117
|
+
formattedValueRight = StatUtils.getFormattedValue(value2, rightSummaryColumn, y_axis_right_summary_method);
|
|
125
118
|
}
|
|
126
119
|
if (!this.isEmptyLabel(label) || x_axis_include_empty) {
|
|
127
120
|
newResult.push({
|
|
@@ -137,14 +130,14 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
137
130
|
} else {
|
|
138
131
|
let rightSummaryColumn;
|
|
139
132
|
let value2Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
140
|
-
if (y_axis_right_summary_type ===
|
|
141
|
-
rightSummaryColumn =
|
|
142
|
-
value2Key =
|
|
133
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
134
|
+
rightSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_right_summary_column);
|
|
135
|
+
value2Key = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], rightSummaryColumn.name);
|
|
143
136
|
}
|
|
144
137
|
const groupItems = [];
|
|
145
138
|
let summaries = [];
|
|
146
|
-
let leftSummaryColumn =
|
|
147
|
-
const groupItem =
|
|
139
|
+
let leftSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_left_summary_column);
|
|
140
|
+
const groupItem = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], leftSummaryColumn.name);
|
|
148
141
|
if (leftSummaryColumn && !groupItems.includes(groupItem)) {
|
|
149
142
|
groupItems.push(groupItem);
|
|
150
143
|
summaries.push({
|
|
@@ -153,10 +146,10 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
153
146
|
});
|
|
154
147
|
}
|
|
155
148
|
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
156
|
-
const column =
|
|
149
|
+
const column = TableUtils.getTableColumnByKey(selectedTable, item.column_key);
|
|
157
150
|
if (column) {
|
|
158
151
|
const method = item.summary_method;
|
|
159
|
-
const groupItem =
|
|
152
|
+
const groupItem = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[method], column.name);
|
|
160
153
|
if (!groupItems.includes(groupItem)) {
|
|
161
154
|
groupItems.push(groupItem);
|
|
162
155
|
summaries.push({
|
|
@@ -170,9 +163,9 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
170
163
|
let label = this.getLabel(selectedColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity);
|
|
171
164
|
let value2 = item[value2Key] || 0;
|
|
172
165
|
let formattedValueRight = value2;
|
|
173
|
-
if (y_axis_right_summary_type ===
|
|
174
|
-
value2 =
|
|
175
|
-
formattedValueRight =
|
|
166
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
167
|
+
value2 = formatNumericValue(value2, rightSummaryColumn);
|
|
168
|
+
formattedValueRight = StatUtils.getFormattedValue(value2, rightSummaryColumn, y_axis_right_summary_method);
|
|
176
169
|
}
|
|
177
170
|
groupItems.forEach((groupItem, index) => {
|
|
178
171
|
if (!this.isEmptyLabel(label) || x_axis_include_empty) {
|
|
@@ -181,15 +174,15 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
181
174
|
method,
|
|
182
175
|
column
|
|
183
176
|
} = summary;
|
|
184
|
-
let value =
|
|
185
|
-
let formattedValueLeft =
|
|
177
|
+
let value = formatNumericValue(item[groupItems[index]] || 0, column);
|
|
178
|
+
let formattedValueLeft = StatUtils.getFormattedValue(value, column, method);
|
|
186
179
|
newResult.push({
|
|
187
180
|
name: label,
|
|
188
181
|
value_left: value,
|
|
189
182
|
value_right: value2,
|
|
190
183
|
formatted_value_left: formattedValueLeft,
|
|
191
184
|
formatted_value_right: formattedValueRight,
|
|
192
|
-
color:
|
|
185
|
+
color: LABEL_COLORS[index % 12],
|
|
193
186
|
original_name: item[selectedColumn.key]
|
|
194
187
|
});
|
|
195
188
|
}
|
|
@@ -215,27 +208,27 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
215
208
|
} = chart;
|
|
216
209
|
const selectedTable = this.getTableById(table_id);
|
|
217
210
|
let selectedView = this.getViewById(view_id, selectedTable);
|
|
218
|
-
const selectedColumn =
|
|
219
|
-
const column1 =
|
|
220
|
-
const column2 =
|
|
211
|
+
const selectedColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
212
|
+
const column1 = TableUtils.getTableColumnByKey(selectedTable, y_axis_left_summary_column);
|
|
213
|
+
const column2 = TableUtils.getTableColumnByKey(selectedTable, y_axis_right_summary_column);
|
|
221
214
|
if (!selectedColumn) return [];
|
|
222
|
-
const sqlCondition =
|
|
215
|
+
const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
223
216
|
const sqlItems = [];
|
|
224
|
-
if (y_axis_left_summary_type ===
|
|
217
|
+
if (y_axis_left_summary_type === SUMMARY_TYPE.COUNT || y_axis_right_summary_type === SUMMARY_TYPE.COUNT) {
|
|
225
218
|
sqlItems.push("COUNT(`".concat(selectedColumn.name, "`)"));
|
|
226
219
|
}
|
|
227
|
-
if (y_axis_right_summary_type ===
|
|
228
|
-
const rightSummaryColumnMethod =
|
|
220
|
+
if (y_axis_right_summary_type === SUMMARY_TYPE.ADVANCED && column2) {
|
|
221
|
+
const rightSummaryColumnMethod = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], column2.name);
|
|
229
222
|
sqlItems.push("".concat(rightSummaryColumnMethod));
|
|
230
223
|
}
|
|
231
|
-
if (y_axis_left_summary_type ===
|
|
232
|
-
let groupItem =
|
|
224
|
+
if (y_axis_left_summary_type === SUMMARY_TYPE.ADVANCED && column1) {
|
|
225
|
+
let groupItem = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], column1.name);
|
|
233
226
|
!sqlItems.includes(groupItem) && sqlItems.push(groupItem);
|
|
234
227
|
if (y_axis_left_group_by_multiple_numeric_column) {
|
|
235
228
|
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
236
|
-
const column =
|
|
229
|
+
const column = TableUtils.getTableColumnByKey(selectedTable, item.column_key);
|
|
237
230
|
if (column) {
|
|
238
|
-
groupItem =
|
|
231
|
+
groupItem = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[item.summary_method], column.name);
|
|
239
232
|
!sqlItems.includes(groupItem) && sqlItems.push(groupItem);
|
|
240
233
|
}
|
|
241
234
|
});
|
|
@@ -245,16 +238,16 @@ class CombinationCalculator extends _baseCalculator.default {
|
|
|
245
238
|
return "select ".concat(groupName, ", ").concat(sqlColumn, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " order by ").concat(groupName, " limit 5000");
|
|
246
239
|
}
|
|
247
240
|
getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
248
|
-
const isTimeColumn =
|
|
241
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
249
242
|
let label;
|
|
250
|
-
if (isTimeColumn || groupColumn.type ===
|
|
243
|
+
if (isTimeColumn || groupColumn.type === CellType.GEOLOCATION) {
|
|
251
244
|
label = item[groupName];
|
|
252
245
|
} else {
|
|
253
246
|
const currentGroupLabel = item[groupColumn.key];
|
|
254
|
-
label =
|
|
255
|
-
label =
|
|
247
|
+
label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
248
|
+
label = getFormattedLabel(groupColumn, label);
|
|
256
249
|
}
|
|
257
250
|
return label;
|
|
258
251
|
}
|
|
259
252
|
}
|
|
260
|
-
|
|
253
|
+
export default CombinationCalculator;
|