dtable-statistic 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/assets/css/dashboard.css +1 -0
- package/es/assets/css/dialog.css +35 -0
- package/es/components/dialog/chart-edit-dialog.js +93 -0
- package/es/components/dialog/enlarged-chart-dialog.js +8 -13
- package/es/components/dialog/statistic-record-dialog/index.js +27 -35
- package/es/components/dialog/table-select-dialog.js +3 -3
- package/es/components/dropdown-menu/statistic-dropdown-menu.js +2 -2
- package/es/constants/index.js +3 -499
- package/es/dashboard.js +9 -87
- package/es/desktop-dashboard.js +51 -32
- package/es/index.js +56 -1
- package/es/mobile-dashboard.js +8 -16
- package/es/model/conver-statItem.js +124 -0
- package/es/service/chart-service.js +8 -27
- package/es/service/dashboard-service.js +25 -29
- package/es/stat-list/chart-preview.js +19 -20
- package/es/stat-list/index.js +17 -23
- package/es/stat-view/index.js +47 -156
- package/es/tabs/tab.js +18 -15
- package/es/utils/common-utils.js +2 -352
- package/es/utils/export-table-utils.js +0 -69
- package/es/utils/index.js +12 -89
- package/package.json +5 -8
- package/es/assets/css/color-picker.css +0 -53
- package/es/assets/css/color-rules-popover.css +0 -144
- package/es/assets/css/slider.css +0 -77
- package/es/assets/css/statistic-chart.module.css +0 -11
- package/es/assets/css/statistic-custom-title.module.css +0 -3
- package/es/assets/css/statistic-custom.module.css +0 -4
- package/es/assets/css/statistic-numeric-column-item.module.css +0 -43
- package/es/assets/css/statistic-time-picker.module.css +0 -21
- package/es/calculator/base-calculator.js +0 -80
- package/es/calculator/basic-chart-calculator.js +0 -349
- package/es/calculator/combination-calculator.js +0 -246
- package/es/calculator/compare-bar-calculator.js +0 -197
- package/es/calculator/completeness-calculator.js +0 -215
- package/es/calculator/copy-value.js +0 -53
- package/es/calculator/dashboard-calculator.js +0 -70
- package/es/calculator/heat-map-calculator.js +0 -148
- package/es/calculator/horizontal-bar-calculator.js +0 -67
- package/es/calculator/index.js +0 -81
- package/es/calculator/map-calculator.js +0 -103
- package/es/calculator/mirror-calculator.js +0 -146
- package/es/calculator/number-card-calculator.js +0 -60
- package/es/calculator/pivot-table-calculator.js +0 -821
- package/es/calculator/scatter-calculator.js +0 -75
- package/es/calculator/thread-manager.js +0 -57
- package/es/calculator/trend-calculator.js +0 -113
- package/es/calculator/workers/basic-chart-calculator-worker.js +0 -495
- package/es/calculator/workers/calculator.worker.js +0 -44
- package/es/calculator/workers/card-calculator-worker.js +0 -40
- package/es/calculator/workers/combination-calculator-worker.js +0 -276
- package/es/calculator/workers/compare-bar-chart-calculator-worker.js +0 -150
- package/es/calculator/workers/completeness-calculator-worker.js +0 -208
- package/es/calculator/workers/dashboard-calculator-worker.js +0 -68
- package/es/calculator/workers/mirror-calculator-worker.js +0 -152
- package/es/calculator/workers/pivot-table-calculator-worker.js +0 -718
- package/es/calculator/workers/scatter-calculator-worker.js +0 -80
- package/es/calculator/workers/trend-calculator-worker.js +0 -108
- package/es/calculator/world-map-calculator.js +0 -124
- package/es/components/dialog/chart-addition-edit-dialog.js +0 -90
- package/es/components/dialog/chart-addition-widgets/chart-selector.js +0 -259
- package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +0 -83
- package/es/components/dialog/statistic-types-dialog/index.css +0 -14
- package/es/components/dialog/statistic-types-dialog/index.js +0 -62
- package/es/components/popover/color-rules/color-rule.js +0 -183
- package/es/components/popover/color-rules/index.js +0 -87
- package/es/components/popover/color-rules/rule-filters/filter.js +0 -221
- package/es/components/popover/color-rules/rule-filters/index.css +0 -210
- package/es/components/popover/color-rules/rule-filters/index.js +0 -97
- package/es/components/popover/color-rules/rule-filters/number-input.js +0 -78
- package/es/components/popover/color-rules-popover.js +0 -218
- package/es/components/popover/color-selector-popover.js +0 -83
- package/es/constants/color-rules.js +0 -17
- package/es/constants/map.js +0 -13
- package/es/constants/model.js +0 -26
- package/es/constants/regions.js +0 -2111
- package/es/constants/zIndexes.js +0 -7
- package/es/custom-g2.js +0 -644
- package/es/model/bar-group.js +0 -58
- package/es/model/bar.js +0 -47
- package/es/model/base-model.js +0 -18
- package/es/model/basic-number-card.js +0 -25
- package/es/model/combination.js +0 -48
- package/es/model/compare-bar.js +0 -56
- package/es/model/completeness-group.js +0 -31
- package/es/model/completeness.js +0 -25
- package/es/model/custom-bar.js +0 -25
- package/es/model/dashboard.js +0 -20
- package/es/model/generic-model.js +0 -222
- package/es/model/heat-map.js +0 -33
- package/es/model/horizontal-bar-group.js +0 -55
- package/es/model/horizontal-bar.js +0 -47
- package/es/model/index.js +0 -187
- package/es/model/map.js +0 -38
- package/es/model/mirror.js +0 -33
- package/es/model/pie.js +0 -38
- package/es/model/ring.js +0 -40
- package/es/model/scatter.js +0 -22
- package/es/model/table.js +0 -32
- package/es/model/trend.js +0 -32
- package/es/model/world-map.js +0 -34
- package/es/service/map-json.js +0 -140
- package/es/stat-editor/chart-name-editor.js +0 -68
- package/es/stat-editor/index.js +0 -75
- package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +0 -153
- package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +0 -422
- package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +0 -203
- package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +0 -23
- package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +0 -104
- package/es/stat-editor/stat-settings/advance-chart-settings/index.js +0 -334
- package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +0 -119
- package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +0 -132
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +0 -240
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +0 -89
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +0 -138
- package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +0 -331
- package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +0 -143
- package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +0 -109
- package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +0 -153
- package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +0 -144
- package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +0 -214
- package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +0 -121
- package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +0 -172
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +0 -366
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +0 -142
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +0 -150
- package/es/stat-editor/stat-settings/basic-chart-settings/index.js +0 -473
- package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +0 -182
- package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +0 -564
- package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +0 -112
- package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +0 -87
- package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +0 -187
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +0 -300
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +0 -113
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +0 -289
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +0 -58
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +0 -359
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +0 -48
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +0 -121
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +0 -143
- package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +0 -269
- package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +0 -104
- package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +0 -366
- package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +0 -55
- package/es/stat-editor/stat-settings/color-setting/color-picker.js +0 -130
- package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +0 -374
- package/es/stat-editor/stat-settings/map/map-level.js +0 -72
- package/es/stat-editor/stat-settings/map/map-province-city.js +0 -151
- package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +0 -108
- package/es/stat-editor/stat-settings/public-setting/base-settings.js +0 -154
- package/es/stat-editor/stat-settings/public-setting/calender.js +0 -125
- package/es/stat-editor/stat-settings/public-setting/column-settings.js +0 -24
- package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +0 -62
- package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +0 -61
- package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +0 -35
- package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +0 -60
- package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +0 -123
- package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +0 -33
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.css +0 -29
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +0 -82
- package/es/stat-view/area-chart.js +0 -551
- package/es/stat-view/bar-chart.js +0 -582
- package/es/stat-view/base-chart.js +0 -132
- package/es/stat-view/basic-number-card.js +0 -201
- package/es/stat-view/combination-chart.js +0 -546
- package/es/stat-view/compare-chart.js +0 -483
- package/es/stat-view/completeness-chart.js +0 -390
- package/es/stat-view/custom-bar.js +0 -418
- package/es/stat-view/dashboard-chart.js +0 -266
- package/es/stat-view/heat-map.js +0 -463
- package/es/stat-view/horizontal-bar-chart.js +0 -562
- package/es/stat-view/line-chart.js +0 -518
- package/es/stat-view/map.js +0 -448
- package/es/stat-view/mirror.js +0 -275
- package/es/stat-view/pie-chart.js +0 -290
- package/es/stat-view/pivot-table/index.js +0 -196
- package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +0 -156
- package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +0 -176
- package/es/stat-view/pivot-table/pivot-table-display-name.js +0 -215
- package/es/stat-view/pivot-table/statistic-pivot-table.module.css +0 -132
- package/es/stat-view/pivot-table/two-dimension-table.js +0 -384
- package/es/stat-view/ring-chart.js +0 -392
- package/es/stat-view/scatter-chart.js +0 -306
- package/es/stat-view/treemap-chart.js +0 -253
- package/es/stat-view/trend-chart.js +0 -249
- package/es/stat-view/world-map.js +0 -431
- package/es/utils/basic-chart-utils.js +0 -29
- package/es/utils/cell-format.js +0 -115
- package/es/utils/collaborator.js +0 -50
- package/es/utils/color-utils.js +0 -134
- package/es/utils/column-utils.js +0 -110
- package/es/utils/column.js +0 -20
- package/es/utils/date-format.js +0 -71
- package/es/utils/map.js +0 -114
- package/es/utils/model.js +0 -19
- package/es/utils/row-utils.js +0 -134
- package/es/utils/search.js +0 -73
- package/es/utils/sql-utils.js +0 -359
- package/es/utils/stat-utils.js +0 -351
- package/es/utils/trend-utils.js +0 -135
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _dtableUtils = require("dtable-utils");
|
|
9
|
-
var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
|
|
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 {
|
|
17
|
-
isValidChart(chart) {
|
|
18
|
-
if (!this.validateBaseConfigs(chart)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (chart.type === _constants.STAT_TYPE.CUSTOM_BAR) {
|
|
22
|
-
return this.isValidCustomBar(chart);
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
table_id,
|
|
26
|
-
groupby_column_key,
|
|
27
|
-
x_axis_column_key,
|
|
28
|
-
summary_column_key,
|
|
29
|
-
y_axis_column_key
|
|
30
|
-
} = chart;
|
|
31
|
-
const table = this.getTableById(table_id);
|
|
32
|
-
const groupbyColumnKey = groupby_column_key || x_axis_column_key;
|
|
33
|
-
if (!groupbyColumnKey || !(0, _dtableUtils.getTableColumnByKey)(table, groupbyColumnKey)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const summaryColumnKey = summary_column_key || y_axis_column_key;
|
|
37
|
-
if (summaryColumnKey && !(0, _dtableUtils.getTableColumnByKey)(table, summaryColumnKey)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
isValidCustomBar(chart) {
|
|
43
|
-
const {
|
|
44
|
-
table_id,
|
|
45
|
-
x_axis_column_key,
|
|
46
|
-
y_axises
|
|
47
|
-
} = chart;
|
|
48
|
-
const table = this.getTableById(table_id);
|
|
49
|
-
if (!table.columns.find(column => column.key === x_axis_column_key) || !Array.isArray(y_axises) || y_axises.length === 0 || y_axises.every(yAxis => !Array.isArray(yAxis.column_groupby_numeric_columns) || yAxis.column_groupby_numeric_columns.length === 0)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
async calculate(chart) {
|
|
55
|
-
if (!this.isValidChart(chart)) return [];
|
|
56
|
-
if (this.isCalcByQueryDB(chart)) {
|
|
57
|
-
return await this.queryDb(chart);
|
|
58
|
-
}
|
|
59
|
-
return await this.calculateWithWorker(chart);
|
|
60
|
-
}
|
|
61
|
-
async queryDb(chart) {
|
|
62
|
-
if (chart.type === _constants.STAT_TYPE.CUSTOM_BAR) {
|
|
63
|
-
return this.queryDbFromCustomBar(chart);
|
|
64
|
-
}
|
|
65
|
-
const {
|
|
66
|
-
table_id,
|
|
67
|
-
view_id,
|
|
68
|
-
column_groupby_multiple_numeric_column
|
|
69
|
-
} = chart;
|
|
70
|
-
let groupby_column_key, summary_type, summary_method, summary_column_key, groupby_date_granularity, include_empty, groupby_geolocation_granularity;
|
|
71
|
-
const column_groupby_column_key = chart.column_groupby_column_key;
|
|
72
|
-
const sortType = chart.sort_type;
|
|
73
|
-
if (chart.type === _constants.STAT_TYPE.PIE || chart.type === _constants.STAT_TYPE.RING || chart.type === _constants.STAT_TYPE.TREEMAP) {
|
|
74
|
-
groupby_column_key = chart.groupby_column_key;
|
|
75
|
-
summary_type = chart.summary_type;
|
|
76
|
-
summary_method = chart.summary_method;
|
|
77
|
-
summary_column_key = chart.summary_column_key;
|
|
78
|
-
groupby_date_granularity = chart.groupby_date_granularity;
|
|
79
|
-
include_empty = chart.groupby_include_empty_cells;
|
|
80
|
-
groupby_geolocation_granularity = chart.groupby_geolocation_granularity;
|
|
81
|
-
} else {
|
|
82
|
-
groupby_column_key = chart.x_axis_column_key;
|
|
83
|
-
summary_type = chart.y_axis_summary_type;
|
|
84
|
-
summary_method = chart.y_axis_summary_method;
|
|
85
|
-
summary_column_key = chart.y_axis_column_key;
|
|
86
|
-
groupby_date_granularity = chart.x_axis_date_granularity;
|
|
87
|
-
groupby_geolocation_granularity = chart.x_axis_geolocation_granularity;
|
|
88
|
-
include_empty = chart.x_axis_include_empty;
|
|
89
|
-
}
|
|
90
|
-
const yAxisType = null;
|
|
91
|
-
const selectedTable = this.getTableById(table_id);
|
|
92
|
-
const selectedView = this.getViewById(view_id, selectedTable);
|
|
93
|
-
if (!selectedView) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
const groupbyColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, groupby_column_key);
|
|
97
|
-
const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
|
|
98
|
-
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
99
|
-
const isTimeColumn = _constants.TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
100
|
-
if (isTimeColumn) {
|
|
101
|
-
groupbyName = (0, _sqlUtils.getSqlGroup)(groupby_date_granularity, groupbyColumn);
|
|
102
|
-
} else if (groupbyColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
103
|
-
groupbyName = (0, _sqlUtils.getSqlGroup)(groupby_geolocation_granularity, groupbyColumn);
|
|
104
|
-
}
|
|
105
|
-
let results;
|
|
106
|
-
if (!column_groupby_column_key && !column_groupby_multiple_numeric_column) {
|
|
107
|
-
results = await this.getNoneGroupbyResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summary_column_key, summary_method, sortType, sqlCondition, selectedTable, yAxisType);
|
|
108
|
-
} else if (column_groupby_multiple_numeric_column) {
|
|
109
|
-
const {
|
|
110
|
-
column_groupby_numeric_columns
|
|
111
|
-
} = chart;
|
|
112
|
-
const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, summary_column_key);
|
|
113
|
-
if (!summaryColumn) return [];
|
|
114
|
-
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);
|
|
115
|
-
} else {
|
|
116
|
-
const {
|
|
117
|
-
column_groupby_date_granularity,
|
|
118
|
-
column_groupby_geolocation_granularity
|
|
119
|
-
} = chart;
|
|
120
|
-
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);
|
|
121
|
-
}
|
|
122
|
-
sortType && _statUtils.default.sortStatisticData(results, sortType);
|
|
123
|
-
return results;
|
|
124
|
-
}
|
|
125
|
-
async queryDbFromCustomBar(chart) {
|
|
126
|
-
const {
|
|
127
|
-
table_id,
|
|
128
|
-
view_id,
|
|
129
|
-
x_axis_column_key,
|
|
130
|
-
x_axis_date_granularity,
|
|
131
|
-
x_axis_geolocation_granularity,
|
|
132
|
-
x_axis_include_empty,
|
|
133
|
-
y_axises,
|
|
134
|
-
sort_type
|
|
135
|
-
} = chart;
|
|
136
|
-
const selectedTable = this.getTableById(table_id);
|
|
137
|
-
const selectedView = this.getViewById(view_id, selectedTable);
|
|
138
|
-
if (!selectedView || !x_axis_column_key || !Array.isArray(y_axises) || y_axises.length === 0) {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
const groupbyColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column_key);
|
|
142
|
-
if (!groupbyColumn) {
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
|
|
146
|
-
const isTimeColumn = _constants.TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
147
|
-
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
148
|
-
if (isTimeColumn) {
|
|
149
|
-
groupbyName = (0, _sqlUtils.getSqlGroup)(x_axis_date_granularity, groupbyColumn);
|
|
150
|
-
} else if (groupbyColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
151
|
-
groupbyName = (0, _sqlUtils.getSqlGroup)(x_axis_geolocation_granularity, groupbyColumn);
|
|
152
|
-
}
|
|
153
|
-
const summaryType = _constants.SUMMARY_TYPE.ADVANCED;
|
|
154
|
-
const yAxisSummaryColumn = null;
|
|
155
|
-
const yAxisSummaryMethod = null;
|
|
156
|
-
let results = [];
|
|
157
|
-
for (let i = 0, len = y_axises.length; i < len; i++) {
|
|
158
|
-
const stack = y_axises[i];
|
|
159
|
-
const {
|
|
160
|
-
type: yAxisType,
|
|
161
|
-
column_groupby_numeric_columns
|
|
162
|
-
} = stack;
|
|
163
|
-
if (yAxisType === _constants.STAT_TYPE.BAR_STACK) {
|
|
164
|
-
// just support summary numeric columns.
|
|
165
|
-
if (!Array.isArray(column_groupby_numeric_columns) || column_groupby_numeric_columns.length === 0) {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
const yAxisType = "".concat(_constants.Y_AXIS_TYPE_PREFIX).concat(i);
|
|
169
|
-
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);
|
|
170
|
-
results = results.concat(currentResults);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
sort_type && _statUtils.default.sortStatisticData(results, sort_type);
|
|
174
|
-
return results;
|
|
175
|
-
}
|
|
176
|
-
async getNoneGroupbyResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, sortType, sqlCondition, table, yAxisType) {
|
|
177
|
-
const isAdvanced = summaryType === _constants.SUMMARY_TYPE.ADVANCED;
|
|
178
|
-
let selectedSummaryColumn;
|
|
179
|
-
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
180
|
-
if (isAdvanced) {
|
|
181
|
-
selectedSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summaryColumnKey);
|
|
182
|
-
if (!selectedSummaryColumn) return [];
|
|
183
|
-
summaryColumnName = selectedSummaryColumn.name;
|
|
184
|
-
}
|
|
185
|
-
const method = isAdvanced ? _constants.DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
186
|
-
const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
|
|
187
|
-
const sqlOrder = (0, _sqlUtils.getSqlOrder)(sortType, groupbyName);
|
|
188
|
-
const sqlString = "select ".concat(groupbyName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " ").concat(sqlOrder, " limit 5000");
|
|
189
|
-
const queryResult = await this.sqlQuery(sqlString);
|
|
190
|
-
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
191
|
-
return [];
|
|
192
|
-
}
|
|
193
|
-
const data = queryResult.data;
|
|
194
|
-
if (!data.results) return [];
|
|
195
|
-
let newResult = [];
|
|
196
|
-
const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
197
|
-
data.results.forEach(item => {
|
|
198
|
-
let label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
199
|
-
if (!includeEmpty && this.isEmptyLabel(label)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
let value = item[valueKey] || 0;
|
|
203
|
-
let formatted_value = value;
|
|
204
|
-
if (isAdvanced) {
|
|
205
|
-
value = (0, _commonUtils.formatNumericValue)(value, selectedSummaryColumn);
|
|
206
|
-
formatted_value = _statUtils.default.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
207
|
-
}
|
|
208
|
-
newResult.push({
|
|
209
|
-
name: label,
|
|
210
|
-
value,
|
|
211
|
-
formatted_value,
|
|
212
|
-
original_name: item[groupbyColumn.key],
|
|
213
|
-
y_axis_type: yAxisType
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
return newResult;
|
|
217
|
-
}
|
|
218
|
-
async getGroupbyOneColumnResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, columnGroupbyColumnKey, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, sqlCondition, table, yAxisType) {
|
|
219
|
-
const isAdvanced = summaryType === _constants.SUMMARY_TYPE.ADVANCED;
|
|
220
|
-
let selectedSummaryColumn;
|
|
221
|
-
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
222
|
-
if (isAdvanced) {
|
|
223
|
-
selectedSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summaryColumnKey);
|
|
224
|
-
if (!selectedSummaryColumn) return [];
|
|
225
|
-
summaryColumnName = selectedSummaryColumn.name;
|
|
226
|
-
}
|
|
227
|
-
const columnGroupbyColumn = (0, _dtableUtils.getTableColumnByKey)(table, columnGroupbyColumnKey);
|
|
228
|
-
let columnGroupbyColumnName = "`".concat(columnGroupbyColumn.name, "`");
|
|
229
|
-
if (_constants.TIME_COLUMN_LIST.includes(columnGroupbyColumn.type)) {
|
|
230
|
-
columnGroupbyColumnName = (0, _sqlUtils.getSqlGroup)(columnGroupbyDateGranularity, columnGroupbyColumn);
|
|
231
|
-
} else if (columnGroupbyColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
232
|
-
columnGroupbyColumnName = (0, _sqlUtils.getSqlGroup)(columnGroupbyGeolocationGranularity, columnGroupbyColumn);
|
|
233
|
-
}
|
|
234
|
-
const method = isAdvanced ? _constants.DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
235
|
-
const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
|
|
236
|
-
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");
|
|
237
|
-
const queryResult = await this.sqlQuery(sqlString);
|
|
238
|
-
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
239
|
-
return [];
|
|
240
|
-
}
|
|
241
|
-
const data = queryResult.data;
|
|
242
|
-
if (!data.results) return [];
|
|
243
|
-
const newResult = [];
|
|
244
|
-
const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
245
|
-
data.results.forEach(item => {
|
|
246
|
-
const label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
247
|
-
if (!includeEmpty && this.isEmptyLabel(label)) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
let value = item[valueKey] || 0;
|
|
251
|
-
let formatted_value = value;
|
|
252
|
-
if (isAdvanced) {
|
|
253
|
-
value = (0, _commonUtils.formatNumericValue)(value, selectedSummaryColumn);
|
|
254
|
-
formatted_value = _statUtils.default.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
255
|
-
}
|
|
256
|
-
let color;
|
|
257
|
-
if (columnGroupbyColumn.type === _dtableUtils.CellType.SINGLE_SELECT) {
|
|
258
|
-
const tempValue = _statUtils.default.getGroupLabel(item[columnGroupbyColumn.key], item, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, this.value);
|
|
259
|
-
color = (0, _columnUtils.getColorFromSingleSelectColumn)(columnGroupbyColumn, tempValue);
|
|
260
|
-
}
|
|
261
|
-
const groupLabel = this.getLabel(columnGroupbyColumn, columnGroupbyColumnName, item, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity);
|
|
262
|
-
newResult.push({
|
|
263
|
-
value,
|
|
264
|
-
formatted_value,
|
|
265
|
-
color,
|
|
266
|
-
name: label,
|
|
267
|
-
group_name: groupLabel,
|
|
268
|
-
group_original_name: item[columnGroupbyColumn.key],
|
|
269
|
-
original_name: item[groupbyColumn.key],
|
|
270
|
-
y_axis_type: yAxisType
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
return newResult;
|
|
274
|
-
}
|
|
275
|
-
async getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumn, summaryMethod, columnGroupbyNumericColumns, sqlCondition, table, yAxisType) {
|
|
276
|
-
const isAdvanced = summaryType === _constants.SUMMARY_TYPE.ADVANCED;
|
|
277
|
-
let numericColumns = [];
|
|
278
|
-
let groupColumnNames = [];
|
|
279
|
-
let groupMethods = [];
|
|
280
|
-
let originalMethods = [];
|
|
281
|
-
if (summaryColumn) {
|
|
282
|
-
const summaryColumnName = isAdvanced ? summaryColumn.name : "`".concat(groupbyColumn.name, "`");
|
|
283
|
-
const method = isAdvanced ? _constants.DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
284
|
-
const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
|
|
285
|
-
numericColumns.push(summaryColumn);
|
|
286
|
-
groupColumnNames.push(summaryColumnName);
|
|
287
|
-
groupMethods.push(summaryColumnMethod);
|
|
288
|
-
originalMethods.push(summaryMethod);
|
|
289
|
-
}
|
|
290
|
-
columnGroupbyNumericColumns.forEach(item => {
|
|
291
|
-
const numericColumn = (0, _dtableUtils.getTableColumnByKey)(table, item.column_key);
|
|
292
|
-
const groupColumnName = numericColumn.name;
|
|
293
|
-
numericColumns.push(numericColumn);
|
|
294
|
-
groupColumnNames.push(groupColumnName);
|
|
295
|
-
groupMethods.push((0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[item.summary_method], groupColumnName));
|
|
296
|
-
originalMethods.push(item.summary_method);
|
|
297
|
-
});
|
|
298
|
-
const sqlString = "select ".concat(groupbyName, ", ").concat(groupMethods.join(','), " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " order by ").concat(groupbyName, " limit 5000");
|
|
299
|
-
const result = await this.sqlQuery(sqlString);
|
|
300
|
-
if (result.status !== 200 || !result.data.success) {
|
|
301
|
-
return [];
|
|
302
|
-
}
|
|
303
|
-
const data = result.data;
|
|
304
|
-
if (!data.results) return [];
|
|
305
|
-
let newResult = [];
|
|
306
|
-
data.results.forEach(item => {
|
|
307
|
-
const label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
308
|
-
const isEmpty = this.isEmptyLabel(label);
|
|
309
|
-
const groupItems = [];
|
|
310
|
-
groupMethods.forEach((_, index) => {
|
|
311
|
-
if (!includeEmpty && isEmpty) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
let value = item[groupMethods[index]] || 0;
|
|
315
|
-
let formatted_value = value;
|
|
316
|
-
if (isAdvanced) {
|
|
317
|
-
value = (0, _commonUtils.formatNumericValue)(value, numericColumns[index]);
|
|
318
|
-
formatted_value = _statUtils.default.getFormattedValue(value, numericColumns[index], originalMethods[index]);
|
|
319
|
-
}
|
|
320
|
-
groupItems.push({
|
|
321
|
-
name: label,
|
|
322
|
-
value,
|
|
323
|
-
formatted_value,
|
|
324
|
-
group_name: groupColumnNames[index],
|
|
325
|
-
original_name: item[groupbyColumn.key],
|
|
326
|
-
y_axis_type: yAxisType
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
newResult = newResult.concat(groupItems);
|
|
330
|
-
});
|
|
331
|
-
return newResult;
|
|
332
|
-
}
|
|
333
|
-
getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
334
|
-
const isTimeColumn = _constants.TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
335
|
-
let label;
|
|
336
|
-
if (isTimeColumn || groupColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
337
|
-
label = item[groupName];
|
|
338
|
-
} else {
|
|
339
|
-
const currentGroupLabel = item[groupColumn.key];
|
|
340
|
-
label = _statUtils.default.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
341
|
-
label = (0, _rowUtils.getFormattedLabel)(groupColumn, label, this.value.collaborators);
|
|
342
|
-
}
|
|
343
|
-
return label;
|
|
344
|
-
}
|
|
345
|
-
isEmptyLabel(label) {
|
|
346
|
-
return !label;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
var _default = exports.default = BasicChartCalculator;
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _dtableUtils = require("dtable-utils");
|
|
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 {
|
|
16
|
-
isValidChart(chart) {
|
|
17
|
-
if (!this.validateBaseConfigs(chart)) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const {
|
|
21
|
-
table_id,
|
|
22
|
-
x_axis_column_key,
|
|
23
|
-
y_axis_left_summary_column,
|
|
24
|
-
y_axis_right_summary_column,
|
|
25
|
-
y_axis_left_summary_method,
|
|
26
|
-
y_axis_right_summary_method,
|
|
27
|
-
y_axis_right_summary_type,
|
|
28
|
-
y_axis_left_summary_type
|
|
29
|
-
} = chart;
|
|
30
|
-
const table = this.getTableById(table_id);
|
|
31
|
-
if (x_axis_column_key && !(0, _dtableUtils.getTableColumnByKey)(table, x_axis_column_key)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (!y_axis_left_summary_type || !y_axis_right_summary_type) return false;
|
|
35
|
-
if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED && y_axis_left_summary_method && !(0, _dtableUtils.getTableColumnByKey)(table, y_axis_left_summary_column)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED && y_axis_right_summary_method && !(0, _dtableUtils.getTableColumnByKey)(table, y_axis_right_summary_column)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
async calculate(chart) {
|
|
44
|
-
if (!this.isValidChart(chart)) return [];
|
|
45
|
-
if (this.isCalcByQueryDB(chart)) {
|
|
46
|
-
return await this.queryDb(chart);
|
|
47
|
-
}
|
|
48
|
-
return await this.calculateWithWorker(chart);
|
|
49
|
-
}
|
|
50
|
-
async queryDb(chart) {
|
|
51
|
-
const {
|
|
52
|
-
table_id,
|
|
53
|
-
x_axis_column_key,
|
|
54
|
-
x_axis_include_empty,
|
|
55
|
-
x_axis_date_granularity: groupby_date_granularity,
|
|
56
|
-
x_axis_geolocation_granularity: groupby_geolocation_granularity,
|
|
57
|
-
y_axis_left_summary_type,
|
|
58
|
-
y_axis_right_summary_type,
|
|
59
|
-
y_axis_right_summary_method,
|
|
60
|
-
y_axis_left_summary_method,
|
|
61
|
-
y_axis_left_summary_column,
|
|
62
|
-
y_axis_right_summary_column,
|
|
63
|
-
y_axis_left_group_by_multiple_numeric_column,
|
|
64
|
-
y_axis_left_group_by_numeric_columns
|
|
65
|
-
} = chart;
|
|
66
|
-
const selectedTable = this.getTableById(table_id);
|
|
67
|
-
const selectedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column_key);
|
|
68
|
-
if (!selectedColumn) return [];
|
|
69
|
-
let groupName = "`".concat(selectedColumn.name, "`");
|
|
70
|
-
if (_constants.TIME_COLUMN_LIST.includes(selectedColumn.type)) {
|
|
71
|
-
groupName = (0, _sqlUtils.getSqlGroup)(groupby_date_granularity, selectedColumn);
|
|
72
|
-
} else if (selectedColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
73
|
-
groupName = (0, _sqlUtils.getSqlGroup)(groupby_geolocation_granularity, selectedColumn);
|
|
74
|
-
}
|
|
75
|
-
let sqlString = this.getSqlString(chart, groupName);
|
|
76
|
-
const result = await this.sqlQuery(sqlString);
|
|
77
|
-
if (result.status !== 200 || !result.data.success) return [];
|
|
78
|
-
const newResult = [];
|
|
79
|
-
if (result.status === 200 && result.data.success) {
|
|
80
|
-
const results = result.data || {};
|
|
81
|
-
const data = results.results;
|
|
82
|
-
if (!data) return [];
|
|
83
|
-
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
84
|
-
let value1Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
85
|
-
let leftSummaryColumn, rightSummaryColumn;
|
|
86
|
-
if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
87
|
-
leftSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_left_summary_column);
|
|
88
|
-
value1Key = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], leftSummaryColumn.name);
|
|
89
|
-
}
|
|
90
|
-
let value2Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
91
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
92
|
-
rightSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_right_summary_column);
|
|
93
|
-
value2Key = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], rightSummaryColumn.name);
|
|
94
|
-
}
|
|
95
|
-
data.forEach(item => {
|
|
96
|
-
let label = this.getLabel(selectedColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity);
|
|
97
|
-
let value1 = item[value1Key] || 0;
|
|
98
|
-
let value2 = item[value2Key] || 0;
|
|
99
|
-
let formattedValueLeft = value1;
|
|
100
|
-
let formattedValueRight = value2;
|
|
101
|
-
if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
102
|
-
value1 = (0, _commonUtils.formatNumericValue)(value1, leftSummaryColumn);
|
|
103
|
-
formattedValueLeft = _statUtils.default.getFormattedValue(value1, leftSummaryColumn, y_axis_left_summary_method);
|
|
104
|
-
}
|
|
105
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
106
|
-
value2 = (0, _commonUtils.formatNumericValue)(value2, rightSummaryColumn);
|
|
107
|
-
formattedValueRight = _statUtils.default.getFormattedValue(value2, rightSummaryColumn, y_axis_right_summary_method);
|
|
108
|
-
}
|
|
109
|
-
if (!this.isEmptyLabel(label) || x_axis_include_empty) {
|
|
110
|
-
newResult.push({
|
|
111
|
-
name: label,
|
|
112
|
-
value_left: value1,
|
|
113
|
-
value_right: value2,
|
|
114
|
-
formatted_value_left: formattedValueLeft,
|
|
115
|
-
formatted_value_right: formattedValueRight,
|
|
116
|
-
original_name: item[selectedColumn.key]
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
} else {
|
|
121
|
-
let rightSummaryColumn;
|
|
122
|
-
let value2Key = "COUNT(".concat(selectedColumn.name, ")");
|
|
123
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
124
|
-
rightSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_right_summary_column);
|
|
125
|
-
value2Key = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], rightSummaryColumn.name);
|
|
126
|
-
}
|
|
127
|
-
const groupItems = [];
|
|
128
|
-
let summaries = [];
|
|
129
|
-
let leftSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_left_summary_column);
|
|
130
|
-
const groupItem = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], leftSummaryColumn.name);
|
|
131
|
-
if (leftSummaryColumn && !groupItems.includes(groupItem)) {
|
|
132
|
-
groupItems.push(groupItem);
|
|
133
|
-
summaries.push({
|
|
134
|
-
column: leftSummaryColumn,
|
|
135
|
-
method: y_axis_left_summary_method
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
139
|
-
const column = (0, _dtableUtils.getTableColumnByKey)(selectedTable, item.column_key);
|
|
140
|
-
if (column) {
|
|
141
|
-
const method = item.summary_method;
|
|
142
|
-
const groupItem = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[method], column.name);
|
|
143
|
-
if (!groupItems.includes(groupItem)) {
|
|
144
|
-
groupItems.push(groupItem);
|
|
145
|
-
summaries.push({
|
|
146
|
-
column,
|
|
147
|
-
method
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
data.forEach((item, index) => {
|
|
153
|
-
let label = this.getLabel(selectedColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity);
|
|
154
|
-
let value2 = item[value2Key] || 0;
|
|
155
|
-
let formattedValueRight = value2;
|
|
156
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
|
|
157
|
-
value2 = (0, _commonUtils.formatNumericValue)(value2, rightSummaryColumn);
|
|
158
|
-
formattedValueRight = _statUtils.default.getFormattedValue(value2, rightSummaryColumn, y_axis_right_summary_method);
|
|
159
|
-
}
|
|
160
|
-
groupItems.forEach((groupItem, index) => {
|
|
161
|
-
if (!this.isEmptyLabel(label) || x_axis_include_empty) {
|
|
162
|
-
const summary = summaries[index];
|
|
163
|
-
const {
|
|
164
|
-
method,
|
|
165
|
-
column
|
|
166
|
-
} = summary;
|
|
167
|
-
let value = (0, _commonUtils.formatNumericValue)(item[groupItems[index]] || 0, column);
|
|
168
|
-
let formattedValueLeft = _statUtils.default.getFormattedValue(value, column, method);
|
|
169
|
-
newResult.push({
|
|
170
|
-
name: label,
|
|
171
|
-
value_left: value,
|
|
172
|
-
value_right: value2,
|
|
173
|
-
formatted_value_left: formattedValueLeft,
|
|
174
|
-
formatted_value_right: formattedValueRight,
|
|
175
|
-
color: _constants.LABEL_COLORS[index % 12],
|
|
176
|
-
original_name: item[selectedColumn.key]
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return newResult;
|
|
184
|
-
}
|
|
185
|
-
getSqlString(chart, groupName) {
|
|
186
|
-
const {
|
|
187
|
-
table_id,
|
|
188
|
-
view_id,
|
|
189
|
-
x_axis_column_key,
|
|
190
|
-
y_axis_left_summary_type,
|
|
191
|
-
y_axis_right_summary_type,
|
|
192
|
-
y_axis_right_summary_method,
|
|
193
|
-
y_axis_left_summary_method,
|
|
194
|
-
y_axis_left_summary_column,
|
|
195
|
-
y_axis_right_summary_column,
|
|
196
|
-
y_axis_left_group_by_multiple_numeric_column,
|
|
197
|
-
y_axis_left_group_by_numeric_columns
|
|
198
|
-
} = chart;
|
|
199
|
-
const selectedTable = this.getTableById(table_id);
|
|
200
|
-
let selectedView = this.getViewById(view_id, selectedTable);
|
|
201
|
-
const selectedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column_key);
|
|
202
|
-
const column1 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_left_summary_column);
|
|
203
|
-
const column2 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_right_summary_column);
|
|
204
|
-
if (!selectedColumn) return [];
|
|
205
|
-
const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
|
|
206
|
-
const sqlItems = [];
|
|
207
|
-
if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.COUNT || y_axis_right_summary_type === _constants.SUMMARY_TYPE.COUNT) {
|
|
208
|
-
sqlItems.push("COUNT(`".concat(selectedColumn.name, "`)"));
|
|
209
|
-
}
|
|
210
|
-
if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED && column2) {
|
|
211
|
-
const rightSummaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_right_summary_method], column2.name);
|
|
212
|
-
sqlItems.push("".concat(rightSummaryColumnMethod));
|
|
213
|
-
}
|
|
214
|
-
if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED && column1) {
|
|
215
|
-
let groupItem = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[y_axis_left_summary_method], column1.name);
|
|
216
|
-
!sqlItems.includes(groupItem) && sqlItems.push(groupItem);
|
|
217
|
-
if (y_axis_left_group_by_multiple_numeric_column) {
|
|
218
|
-
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
219
|
-
const column = (0, _dtableUtils.getTableColumnByKey)(selectedTable, item.column_key);
|
|
220
|
-
if (column) {
|
|
221
|
-
groupItem = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[item.summary_method], column.name);
|
|
222
|
-
!sqlItems.includes(groupItem) && sqlItems.push(groupItem);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const sqlColumn = sqlItems.join(',');
|
|
228
|
-
return "select ".concat(groupName, ", ").concat(sqlColumn, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " order by ").concat(groupName, " limit 5000");
|
|
229
|
-
}
|
|
230
|
-
getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
231
|
-
const isTimeColumn = _constants.TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
232
|
-
let label;
|
|
233
|
-
if (isTimeColumn || groupColumn.type === _dtableUtils.CellType.GEOLOCATION) {
|
|
234
|
-
label = item[groupName];
|
|
235
|
-
} else {
|
|
236
|
-
const currentGroupLabel = item[groupColumn.key];
|
|
237
|
-
label = _statUtils.default.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
238
|
-
label = (0, _rowUtils.getFormattedLabel)(groupColumn, label);
|
|
239
|
-
}
|
|
240
|
-
return label;
|
|
241
|
-
}
|
|
242
|
-
isEmptyLabel(label) {
|
|
243
|
-
return !label;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
var _default = exports.default = CombinationCalculator;
|