dtable-statistic 4.0.2-test-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.
Files changed (210) hide show
  1. package/README.md +3 -0
  2. package/es/api/dtable-db-api.js +43 -0
  3. package/es/assets/css/color-picker.css +53 -0
  4. package/es/assets/css/color-rules-popover.css +144 -0
  5. package/es/assets/css/color-theme-dialog.css +40 -0
  6. package/es/assets/css/dashboard.css +562 -0
  7. package/es/assets/css/dialog.css +415 -0
  8. package/es/assets/css/mobile-dashboard.module.css +91 -0
  9. package/es/assets/css/slider.css +77 -0
  10. package/es/assets/css/statistic-chart.module.css +11 -0
  11. package/es/assets/css/statistic-custom-title.module.css +3 -0
  12. package/es/assets/css/statistic-custom.module.css +4 -0
  13. package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
  14. package/es/assets/css/statistic-time-picker.module.css +21 -0
  15. package/es/assets/css/theme.css +61 -0
  16. package/es/assets/images/icon.png +0 -0
  17. package/es/calculator/base-calculator.js +111 -0
  18. package/es/calculator/basic-chart-calculator.js +571 -0
  19. package/es/calculator/combination-calculator.js +296 -0
  20. package/es/calculator/compare-bar-calculator.js +291 -0
  21. package/es/calculator/completeness-calculator.js +307 -0
  22. package/es/calculator/copy-value.js +47 -0
  23. package/es/calculator/dashboard-calculator.js +146 -0
  24. package/es/calculator/heat-map-calculator.js +225 -0
  25. package/es/calculator/horizontal-bar-calculator.js +100 -0
  26. package/es/calculator/index.js +88 -0
  27. package/es/calculator/map-calculator.js +169 -0
  28. package/es/calculator/mirror-calculator.js +217 -0
  29. package/es/calculator/number-card-calculator.js +135 -0
  30. package/es/calculator/pivot-table-calculator.js +810 -0
  31. package/es/calculator/scatter-calculator.js +150 -0
  32. package/es/calculator/thread-manager.js +70 -0
  33. package/es/calculator/trend-calculator.js +204 -0
  34. package/es/calculator/workers/basic-chart-calculator-worker.js +410 -0
  35. package/es/calculator/workers/calculator.worker.js +22 -0
  36. package/es/calculator/workers/card-calculator-worker.js +28 -0
  37. package/es/calculator/workers/combination-calculator-worker.js +257 -0
  38. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +149 -0
  39. package/es/calculator/workers/completeness-calculator-worker.js +153 -0
  40. package/es/calculator/workers/dashboard-calculator-worker.js +56 -0
  41. package/es/calculator/workers/mirror-calculator-worker.js +132 -0
  42. package/es/calculator/workers/pivot-table-calculator-worker.js +615 -0
  43. package/es/calculator/workers/scatter-calculator-worker.js +67 -0
  44. package/es/calculator/workers/trend-calculator-worker.js +93 -0
  45. package/es/calculator/world-map-calculator.js +193 -0
  46. package/es/components/common-add-tool.js +19 -0
  47. package/es/components/dialog/chart-addition-edit-dialog.js +89 -0
  48. package/es/components/dialog/chart-addition-widgets/chart-selector.js +261 -0
  49. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +74 -0
  50. package/es/components/dialog/color-theme-dialog.js +71 -0
  51. package/es/components/dialog/enlarged-chart-dialog.js +73 -0
  52. package/es/components/dialog/new-table-dialog.js +113 -0
  53. package/es/components/dialog/new-view-dialog.js +87 -0
  54. package/es/components/dialog/rename-view-dialog.js +87 -0
  55. package/es/components/dialog/statistic-record-dialog/index.css +114 -0
  56. package/es/components/dialog/statistic-record-dialog/index.js +174 -0
  57. package/es/components/dialog/table-select-dialog.js +93 -0
  58. package/es/components/dropdown-menu/statistic-dropdown-menu.js +94 -0
  59. package/es/components/dtable-popover.js +109 -0
  60. package/es/components/dtable-search-input.js +137 -0
  61. package/es/components/dtable-select.js +104 -0
  62. package/es/components/index.js +11 -0
  63. package/es/components/loading.js +8 -0
  64. package/es/components/modal-portal.js +36 -0
  65. package/es/components/popover/color-rules/color-rule.js +179 -0
  66. package/es/components/popover/color-rules/index.js +87 -0
  67. package/es/components/popover/color-rules/rule-filters/filter.js +214 -0
  68. package/es/components/popover/color-rules/rule-filters/index.css +214 -0
  69. package/es/components/popover/color-rules/rule-filters/index.js +97 -0
  70. package/es/components/popover/color-rules/rule-filters/number-input.js +85 -0
  71. package/es/components/popover/color-rules-popover.js +213 -0
  72. package/es/components/popover/color-selector-popover.js +85 -0
  73. package/es/components/seatable-radio/index.css +51 -0
  74. package/es/components/seatable-radio/index.js +28 -0
  75. package/es/components/select/index.js +2 -0
  76. package/es/components/select/option-group.css +104 -0
  77. package/es/components/select/option-group.js +225 -0
  78. package/es/components/select/option.js +51 -0
  79. package/es/components/select/select.css +211 -0
  80. package/es/components/select/select.js +157 -0
  81. package/es/components/toast/alert.js +130 -0
  82. package/es/components/toast/index.js +3 -0
  83. package/es/components/toast/toast.js +164 -0
  84. package/es/components/toast/toastManager.js +150 -0
  85. package/es/components/toast/toaster.js +64 -0
  86. package/es/constants/color-rules.js +8 -0
  87. package/es/constants/dtable-select-style.js +61 -0
  88. package/es/constants/event-types.js +1 -0
  89. package/es/constants/index.js +501 -0
  90. package/es/constants/key-codes.js +102 -0
  91. package/es/constants/zIndexes.js +1 -0
  92. package/es/custom-g2.js +614 -0
  93. package/es/dashboard.js +408 -0
  94. package/es/desktop-dashboard.js +299 -0
  95. package/es/index.js +33 -0
  96. package/es/locale/index.js +17 -0
  97. package/es/locale/lang/de.js +237 -0
  98. package/es/locale/lang/en.js +237 -0
  99. package/es/locale/lang/fr.js +237 -0
  100. package/es/locale/lang/zh_CN.js +237 -0
  101. package/es/mobile-dashboard.js +103 -0
  102. package/es/model/collaborators.js +11 -0
  103. package/es/model/stat-item.js +340 -0
  104. package/es/model/statistic-dashboard.js +8 -0
  105. package/es/service/chart-service.js +192 -0
  106. package/es/service/dashboard-service.js +415 -0
  107. package/es/stat-editor/chart-name-editor.js +75 -0
  108. package/es/stat-editor/index.js +74 -0
  109. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +149 -0
  110. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +415 -0
  111. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +193 -0
  112. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +13 -0
  113. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +107 -0
  114. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +332 -0
  115. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +170 -0
  116. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +141 -0
  117. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +219 -0
  118. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
  119. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +132 -0
  120. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +319 -0
  121. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +138 -0
  122. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +135 -0
  123. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +156 -0
  124. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +147 -0
  125. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +195 -0
  126. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +126 -0
  127. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +169 -0
  128. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +352 -0
  129. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +145 -0
  130. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +153 -0
  131. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +466 -0
  132. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +183 -0
  133. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +542 -0
  134. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +111 -0
  135. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +86 -0
  136. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +169 -0
  137. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +273 -0
  138. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +105 -0
  139. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +243 -0
  140. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +65 -0
  141. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +318 -0
  142. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +49 -0
  143. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +124 -0
  144. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +150 -0
  145. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +267 -0
  146. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +109 -0
  147. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +351 -0
  148. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +60 -0
  149. package/es/stat-editor/stat-settings/color-setting/color-picker.js +129 -0
  150. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +348 -0
  151. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +102 -0
  152. package/es/stat-editor/stat-settings/public-setting/base-settings.js +124 -0
  153. package/es/stat-editor/stat-settings/public-setting/calender.js +124 -0
  154. package/es/stat-editor/stat-settings/public-setting/column-settings.js +15 -0
  155. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +60 -0
  156. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +57 -0
  157. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +41 -0
  158. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +64 -0
  159. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +118 -0
  160. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +39 -0
  161. package/es/stat-list/chart-preview.js +139 -0
  162. package/es/stat-list/index.js +275 -0
  163. package/es/stat-view/area-chart.js +521 -0
  164. package/es/stat-view/bar-chart.js +568 -0
  165. package/es/stat-view/base-chart.js +44 -0
  166. package/es/stat-view/basic-number-card.js +255 -0
  167. package/es/stat-view/combination-chart.js +558 -0
  168. package/es/stat-view/compare-chart.js +485 -0
  169. package/es/stat-view/completeness-chart.js +389 -0
  170. package/es/stat-view/custom-bar.js +433 -0
  171. package/es/stat-view/dashboard-chart.js +317 -0
  172. package/es/stat-view/heat-map.js +501 -0
  173. package/es/stat-view/horizontal-bar-chart.js +569 -0
  174. package/es/stat-view/index.js +183 -0
  175. package/es/stat-view/line-chart.js +505 -0
  176. package/es/stat-view/map.js +428 -0
  177. package/es/stat-view/mirror.js +285 -0
  178. package/es/stat-view/pie-chart.js +326 -0
  179. package/es/stat-view/pivot-table/index.js +206 -0
  180. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +133 -0
  181. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +164 -0
  182. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
  183. package/es/stat-view/pivot-table/two-dimension-table.js +344 -0
  184. package/es/stat-view/ring-chart.js +416 -0
  185. package/es/stat-view/scatter-chart.js +367 -0
  186. package/es/stat-view/treemap-chart.js +318 -0
  187. package/es/stat-view/trend-chart.js +299 -0
  188. package/es/stat-view/world-map.js +443 -0
  189. package/es/tabs/index.js +252 -0
  190. package/es/tabs/statistic-tabs.module.css +154 -0
  191. package/es/tabs/tab.js +167 -0
  192. package/es/utils/basic-chart-utils.js +24 -0
  193. package/es/utils/cell-format.js +110 -0
  194. package/es/utils/cell-value.js +27 -0
  195. package/es/utils/collaborator.js +31 -0
  196. package/es/utils/color-utils.js +112 -0
  197. package/es/utils/column-utils.js +18 -0
  198. package/es/utils/column.js +13 -0
  199. package/es/utils/common-utils.js +303 -0
  200. package/es/utils/date-format.js +65 -0
  201. package/es/utils/export-table-utils.js +632 -0
  202. package/es/utils/index.js +26 -0
  203. package/es/utils/object.js +26 -0
  204. package/es/utils/row-utils.js +115 -0
  205. package/es/utils/search.js +67 -0
  206. package/es/utils/sql-utils.js +293 -0
  207. package/es/utils/stat-utils.js +353 -0
  208. package/es/utils/trend-utils.js +136 -0
  209. package/index.js +1 -0
  210. package/package.json +188 -0
@@ -0,0 +1,115 @@
1
+ import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, isNumber, getNumberDisplayString } from 'dtable-store';
2
+ import { getClientFormulaDisplayString } from '../utils';
3
+ export var isEmptyGeolocationCell = function isEmptyGeolocationCell(cellValue, format) {
4
+ if (!cellValue) return null;
5
+ if (format === 'lng_lat') {
6
+ return (cellValue.lng || cellValue.lng === 0) && (cellValue.lat || cellValue.lat === 0);
7
+ }
8
+ if (format === 'country_region') {
9
+ return cellValue.country_region;
10
+ }
11
+ return cellValue.province;
12
+ };
13
+ export var isValidRow = function isValidRow(row, formulaRow, column, includeEmpty) {
14
+ var columnType = column.type,
15
+ columnKey = column.key;
16
+ if (includeEmpty || columnType === CellType.CHECKBOX) return true;
17
+ if (columnType === CellType.GEOLOCATION) {
18
+ var geo_format = column.data.geo_format;
19
+ return isEmptyGeolocationCell(row[columnKey], geo_format);
20
+ }
21
+ var cellValue = row[columnKey];
22
+ if (FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === CellType.LINK) {
23
+ cellValue = formulaRow ? formulaRow[columnKey] : null;
24
+ }
25
+ return cellValue || cellValue === 0;
26
+ };
27
+ export var getFormattedLabel = function getFormattedLabel(column, name, collaborators) {
28
+ var columnType = column.type,
29
+ columnData = column.data;
30
+ if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
31
+ var options = columnData ? columnData.options : [];
32
+ var selectedOption = options.find(function (o) {
33
+ var id = name;
34
+ if (Array.isArray(name)) {
35
+ id = name[0];
36
+ }
37
+ return o.id === id;
38
+ });
39
+ var _ref = selectedOption || {},
40
+ optionName = _ref.name;
41
+ if (selectedOption) {
42
+ return optionName;
43
+ }
44
+ } else if (columnType === CellType.COLLABORATOR) {
45
+ var collaborator = collaborators.find(function (item) {
46
+ var email = name;
47
+ if (Array.isArray(name)) {
48
+ email = name[0];
49
+ }
50
+ return item.email === email;
51
+ });
52
+ if (collaborator) {
53
+ return collaborator.name;
54
+ }
55
+ } else if (columnType === CellType.CREATOR || columnType === CellType.LAST_MODIFIER) {
56
+ if (name === 'anonymous') {
57
+ return name;
58
+ } else {
59
+ var _collaborator = collaborators.find(function (item) {
60
+ return item.email === name;
61
+ });
62
+ if (_collaborator) {
63
+ return _collaborator.name;
64
+ }
65
+ }
66
+ } else if (columnType === CellType.LINK) {
67
+ return getClientFormulaDisplayString([name], columnData, {
68
+ collaborators: collaborators
69
+ });
70
+ } else if (columnType === CellType.CHECKBOX) {
71
+ return name == 'true' ? 'Checked' : 'Unchecked';
72
+ } else if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
73
+ var _ref2 = columnData || {},
74
+ result_type = _ref2.result_type,
75
+ array_type = _ref2.array_type;
76
+ if (!name && !isNumber(name)) return '';
77
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
78
+ var valueNumber = parseFloat(name);
79
+ return isNumber(valueNumber) ? getNumberDisplayString(valueNumber, column.data) : name;
80
+ }
81
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
82
+ if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
83
+ if ([CellType.CREATOR, CellType.LAST_MODIFIER].includes(array_type) && name === 'anonymous') {
84
+ return name;
85
+ }
86
+ var _collaborator2 = collaborators.find(function (item) {
87
+ var email = name;
88
+ if (Array.isArray(name)) {
89
+ email = name[0];
90
+ }
91
+ return item.email === email;
92
+ });
93
+ if (_collaborator2) {
94
+ return _collaborator2.name;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ if (!name) {
100
+ return '';
101
+ }
102
+ return name;
103
+ };
104
+ export function getCellValue(row, formulaRow, column) {
105
+ var type = column.type,
106
+ key = column.key;
107
+ if (FORMULA_COLUMN_TYPES_MAP[type]) {
108
+ var cellValue = formulaRow && formulaRow[key];
109
+ if (Array.isArray(cellValue)) {
110
+ return cellValue[0];
111
+ }
112
+ return cellValue;
113
+ }
114
+ return row[key];
115
+ }
@@ -0,0 +1,67 @@
1
+ import dayjs from 'dayjs';
2
+ import { CellType, getNumberDisplayString, getMultipleOptionName, getCollaboratorsName, getGeolocationDisplayString } from 'dtable-store';
3
+ import { getSelectColumnOptions } from './column';
4
+ var SUPPORT_SEARCH_COLUMN_TYPES = [CellType.DATE, CellType.TEXT, CellType.LONG_TEXT, CellType.NUMBER, CellType.URL, CellType.EMAIL, CellType.SINGLE_SELECT, CellType.CTIME, CellType.MTIME, CellType.MULTIPLE_SELECT, CellType.LAST_MODIFIER, CellType.CREATOR, CellType.COLLABORATOR, CellType.LINK, CellType.FORMULA, CellType.LINK_FORMULA, CellType.AUTO_NUMBER, CellType.GEOLOCATION, CellType.DURATION];
5
+ export var searchRows = function searchRows(rows, columns, val, processRow) {
6
+ var dtableCollaborators = window.app.collaboratorsCache || [];
7
+ var collaborators = window.app.state.collaborators;
8
+ var searchResult = [];
9
+ rows.forEach(function (row) {
10
+ var column = columns.find(function (column) {
11
+ var columnType = column.type,
12
+ columnKey = column.key;
13
+ if (!SUPPORT_SEARCH_COLUMN_TYPES.includes(columnType)) {
14
+ return false;
15
+ }
16
+ var cellValue = row[columnKey];
17
+ if (cellValue) {
18
+ var text;
19
+ if (columnType === CellType.LONG_TEXT) {
20
+ text = cellValue.text;
21
+ } else if (columnType === CellType.NUMBER || columnType === CellType.DURATION) {
22
+ text = getNumberDisplayString(cellValue, column.data);
23
+ } else if (columnType === CellType.SINGLE_SELECT) {
24
+ var options = getSelectColumnOptions(column);
25
+ var option = options.find(function (option) {
26
+ return option.id === cellValue;
27
+ });
28
+ text = option ? option.name : '';
29
+ } else if (columnType === CellType.MULTIPLE_SELECT) {
30
+ var _options = getSelectColumnOptions(column);
31
+ text = getMultipleOptionName(_options, cellValue);
32
+ } else if (columnType === CellType.COLLABORATOR) {
33
+ text = getCollaboratorsName(collaborators, cellValue);
34
+ } else if (columnType === CellType.LAST_MODIFIER || columnType === CellType.CREATOR) {
35
+ if (cellValue === 'anonymous') {
36
+ text = cellValue;
37
+ } else {
38
+ var collaborator = collaborators.find(function (collaborator) {
39
+ return collaborator.email === cellValue;
40
+ });
41
+ if (!collaborator) {
42
+ collaborator = dtableCollaborators[cellValue];
43
+ }
44
+ if (collaborator) {
45
+ text = collaborator.name;
46
+ }
47
+ }
48
+ } else if (columnType === CellType.GEOLOCATION) {
49
+ text = getGeolocationDisplayString(cellValue, column.data);
50
+ } else if (columnType === CellType.CTIME || columnType === CellType.MTIME) {
51
+ text = dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss');
52
+ } else {
53
+ text = cellValue;
54
+ }
55
+ if (!text || typeof text !== 'string') return false;
56
+ if (text.toLowerCase().indexOf(val.toLowerCase()) > -1) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ });
62
+ if (column) {
63
+ searchResult.push(processRow(row));
64
+ }
65
+ });
66
+ return searchResult;
67
+ };
@@ -0,0 +1,293 @@
1
+ import { CellType, filter2SqlCondition, TableUtils, Views } from 'dtable-store';
2
+ import { STATISTICS_COUNT_TYPE, STAT_TYPE, TIME_COLUMN_LIST } from '../constants';
3
+ export var getSqlOrder = function getSqlOrder(sortType, groupName) {
4
+ if (!sortType) {
5
+ return "order by ".concat(groupName);
6
+ }
7
+ return '';
8
+ };
9
+ export var getSqlGroup = function getSqlGroup(granularity, column) {
10
+ var name = column.name,
11
+ type = column.type;
12
+ var columnName = "`".concat(name, "`");
13
+ if (TIME_COLUMN_LIST.includes(type)) {
14
+ if (granularity && granularity.includes(STATISTICS_COUNT_TYPE.DAY)) {
15
+ return "ISODATE(".concat(columnName, ")");
16
+ }
17
+ if (granularity === STATISTICS_COUNT_TYPE.WEEK) {
18
+ return 'ISODATE(STARTOFWEEK(' + columnName + ', "monday"))';
19
+ }
20
+ if (granularity === STATISTICS_COUNT_TYPE.MONTH) {
21
+ return "ISOMONTH(".concat(columnName, ")");
22
+ }
23
+ if (granularity === STATISTICS_COUNT_TYPE.QUARTER) {
24
+ return "CONCATENATE(year(".concat(columnName, "), \"-Q\", quarter(").concat(columnName, "))");
25
+ }
26
+ return "YEAR(".concat(columnName, ")");
27
+ } else if (type === CellType.GEOLOCATION) {
28
+ if (granularity === STATISTICS_COUNT_TYPE.PROVINCE) {
29
+ return "PROVINCE(".concat(columnName, ")");
30
+ }
31
+ if (granularity === STATISTICS_COUNT_TYPE.CITY) {
32
+ return "CITY(".concat(columnName, ")");
33
+ }
34
+ if (granularity === STATISTICS_COUNT_TYPE.DISTRICT) {
35
+ return "DISTRICT(".concat(columnName, ")");
36
+ }
37
+ }
38
+ return "`".concat(columnName, "`");
39
+ };
40
+ export var getSqlString = function getSqlString(statItem, statisticRecord, _ref) {
41
+ var isColumn = _ref.isColumn,
42
+ isCurrentView = _ref.isCurrentView,
43
+ isRow = _ref.isRow,
44
+ getTableById = _ref.getTableById;
45
+ var table_id = statItem.table_id,
46
+ view_id = statItem.view_id,
47
+ column_groupby_column_key = statItem.column_groupby_column_key,
48
+ column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
49
+ type = statItem.type;
50
+ var selectedTable = getTableById(table_id);
51
+ var selectedView = Views.getViewById(selectedTable.views, view_id);
52
+ var _getDatabaseGroupName = getDatabaseGroupName(statItem, selectedTable, {
53
+ isCurrentView: isCurrentView
54
+ }),
55
+ groupName = _getDatabaseGroupName.groupName,
56
+ selectedColumn = _getDatabaseGroupName.selectedColumn,
57
+ columnGroupName = _getDatabaseGroupName.columnGroupName,
58
+ columnSelectedColumn = _getDatabaseGroupName.columnSelectedColumn;
59
+ var sqlCondition = filter2SqlCondition(selectedTable, selectedView);
60
+ var isGroup = column_groupby_column_key && !column_groupby_multiple_numeric_column;
61
+ var name = statisticRecord.name,
62
+ original_name = statisticRecord.original_name,
63
+ group_original_name = statisticRecord.group_original_name,
64
+ group_name = statisticRecord.group_name;
65
+ var sqlName = getSqlGroupName(name, original_name, selectedColumn);
66
+ var sqlGroupName;
67
+ if (isGroup) {
68
+ sqlGroupName = getSqlGroupName(group_name, group_original_name, columnSelectedColumn);
69
+ }
70
+ var sqlString;
71
+ if (STAT_TYPE.PIVOT_TABLE === type) {
72
+ var pivotGroupName = "".concat(isGroup ? "".concat(columnGroupName, "=").concat(sqlGroupName) : '');
73
+ if (isColumn) {
74
+ if (sqlCondition && pivotGroupName) {
75
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " and ").concat(pivotGroupName, " limit 5000");
76
+ } else if (groupName && !sqlCondition) {
77
+ sqlString = "select * from ".concat(selectedTable.name, " where ").concat(pivotGroupName, " limit 5000");
78
+ } else {
79
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " limit 5000");
80
+ }
81
+ return sqlString;
82
+ }
83
+ if (isRow) {
84
+ if (groupName && sqlCondition) {
85
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " and ").concat(groupName, "=").concat(sqlName, " limit 5000");
86
+ } else if (groupName && !sqlCondition) {
87
+ sqlString = "select * from ".concat(selectedTable.name, " where ").concat(groupName, "=").concat(sqlName, " limit 5000");
88
+ } else {
89
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " limit 5000");
90
+ }
91
+ return sqlString;
92
+ }
93
+ }
94
+ if (groupName && sqlCondition) {
95
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " and ").concat(groupName, "=").concat(sqlName, " ").concat(isGroup ? "and ".concat(columnGroupName, "=").concat(sqlGroupName) : '', " limit 5000");
96
+ } else if (groupName && !sqlCondition) {
97
+ sqlString = "select * from ".concat(selectedTable.name, " where ").concat(groupName, "=").concat(sqlName, " ").concat(isGroup ? "and ".concat(columnGroupName, "=").concat(sqlGroupName) : '', " limit 5000");
98
+ } else {
99
+ sqlString = "select * from ".concat(selectedTable.name, " ").concat(sqlCondition, " limit 5000");
100
+ }
101
+ return sqlString;
102
+ };
103
+ var getSqlGroupName = function getSqlGroupName(name, original_name, column) {
104
+ var type = column.type;
105
+ if (type === CellType.SINGLE_SELECT || type === CellType.MULTIPLE_SELECT) {
106
+ return "'".concat(name, "'");
107
+ }
108
+ var newName = original_name ? original_name : name;
109
+ if (typeof newName === 'number') {
110
+ return newName;
111
+ }
112
+ return "'".concat(newName, "'");
113
+ };
114
+ var getGroupName = function getGroupName(selectedColumn, _ref2) {
115
+ var groupby_date_granularity = _ref2.groupby_date_granularity,
116
+ groupby_geolocation_granularity = _ref2.groupby_geolocation_granularity;
117
+ var groupName = "`".concat(selectedColumn.name, "`");
118
+ var isTimeColumn = TIME_COLUMN_LIST.includes(selectedColumn.type);
119
+ if (isTimeColumn) {
120
+ groupName = getSqlGroup(groupby_date_granularity, selectedColumn);
121
+ } else if (selectedColumn.type === CellType.GEOLOCATION) {
122
+ groupName = getSqlGroup(groupby_geolocation_granularity, selectedColumn);
123
+ }
124
+ return groupName;
125
+ };
126
+ var getDatabaseGroupName = function getDatabaseGroupName(statItem, selectedTable, _ref3) {
127
+ var _ref3$isColumn = _ref3.isColumn,
128
+ isColumn = _ref3$isColumn === void 0 ? false : _ref3$isColumn,
129
+ _ref3$isCurrentView = _ref3.isCurrentView,
130
+ isCurrentView = _ref3$isCurrentView === void 0 ? false : _ref3$isCurrentView;
131
+ if (isCurrentView) return '';
132
+ var type = statItem.type;
133
+ var groupName, selectedColumn, columnGroupName, columnSelectedColumn;
134
+ switch (type) {
135
+ case STAT_TYPE.BAR:
136
+ case STAT_TYPE.BAR_GROUP:
137
+ case STAT_TYPE.BAR_STACK:
138
+ case STAT_TYPE.LINE:
139
+ case STAT_TYPE.PIE:
140
+ case STAT_TYPE.RING:
141
+ case STAT_TYPE.AREA_CHART:
142
+ case STAT_TYPE.AREA_GROUP_CHART:
143
+ case STAT_TYPE.TREEMAP:
144
+ case STAT_TYPE.HORIZONTAL_BAR:
145
+ case STAT_TYPE.HORIZONTAL_GROUP_BAR:
146
+ case STAT_TYPE.STACKED_HORIZONTAL_BAR:
147
+ {
148
+ var groupby_column_key, groupby_date_granularity, groupby_geolocation_granularity;
149
+ var column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
150
+ column_groupby_column_key = statItem.column_groupby_column_key,
151
+ column_groupby_date_granularity = statItem.column_groupby_date_granularity,
152
+ column_groupby_geolocation_granularity = statItem.column_groupby_geolocation_granularity;
153
+ if (type === STAT_TYPE.PIE || type === STAT_TYPE.RING || type === STAT_TYPE.TREEMAP) {
154
+ groupby_column_key = statItem.groupby_column_key;
155
+ groupby_date_granularity = statItem.groupby_date_granularity;
156
+ groupby_geolocation_granularity = statItem.groupby_geolocation_granularity;
157
+ } else if (type === STAT_TYPE.HORIZONTAL_BAR || type === STAT_TYPE.HORIZONTAL_GROUP_BAR || type === STAT_TYPE.STACKED_HORIZONTAL_BAR) {
158
+ groupby_column_key = statItem.vertical_axis_column_key;
159
+ groupby_date_granularity = statItem.vertical_axis_date_granularity;
160
+ groupby_geolocation_granularity = statItem.vertical_axis_geolocation_granularity;
161
+ } else {
162
+ groupby_column_key = statItem.x_axis_column_key;
163
+ groupby_date_granularity = statItem.x_axis_date_granularity;
164
+ groupby_geolocation_granularity = statItem.x_axis_geolocation_granularity;
165
+ }
166
+ if (!column_groupby_multiple_numeric_column && column_groupby_column_key) {
167
+ columnSelectedColumn = TableUtils.getTableColumnByKey(selectedTable, column_groupby_column_key);
168
+ columnGroupName = getGroupName(columnSelectedColumn, {
169
+ groupby_date_granularity: column_groupby_date_granularity,
170
+ groupby_geolocation_granularity: column_groupby_geolocation_granularity
171
+ });
172
+ }
173
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, groupby_column_key);
174
+ groupName = getGroupName(selectedColumn, {
175
+ groupby_date_granularity: groupby_date_granularity,
176
+ groupby_geolocation_granularity: groupby_geolocation_granularity
177
+ });
178
+ break;
179
+ }
180
+ case STAT_TYPE.MAP:
181
+ case STAT_TYPE.MAP_BUBBLE:
182
+ {
183
+ var geolocation_granularity = statItem.geolocation_granularity,
184
+ geo_column = statItem.geo_column;
185
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, geo_column);
186
+ groupName = getSqlGroup(geolocation_granularity, selectedColumn);
187
+ break;
188
+ }
189
+ case STAT_TYPE.WORLD_MAP:
190
+ case STAT_TYPE.WORLD_MAP_BUBBLE:
191
+ case STAT_TYPE.MIRROR:
192
+ {
193
+ var column = statItem.column;
194
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, column);
195
+ groupName = selectedColumn.name;
196
+ break;
197
+ }
198
+ case STAT_TYPE.HEAT_MAP:
199
+ {
200
+ var time_column = statItem.time_column;
201
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, time_column);
202
+ groupName = "ISODATE(".concat(selectedColumn.name, ")");
203
+ break;
204
+ }
205
+ case STAT_TYPE.SCATTER:
206
+ {
207
+ var group_column = statItem.group_column;
208
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, group_column);
209
+ groupName = selectedColumn.name;
210
+ break;
211
+ }
212
+ case STAT_TYPE.BASIC_NUMBER_CARD:
213
+ {
214
+ // todo
215
+ break;
216
+ }
217
+ case STAT_TYPE.COMPARE_BAR:
218
+ {
219
+ var x_axis_column_key = statItem.x_axis_column_key,
220
+ x_axis_date_granularity = statItem.x_axis_date_granularity;
221
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
222
+ groupName = getSqlGroup(x_axis_date_granularity, selectedColumn);
223
+ break;
224
+ }
225
+ case STAT_TYPE.COMBINATION_CHART:
226
+ {
227
+ var _x_axis_column_key = statItem.x_axis_column_key,
228
+ _groupby_date_granularity = statItem.x_axis_date_granularity,
229
+ _groupby_geolocation_granularity = statItem.x_axis_geolocation_granularity;
230
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, _x_axis_column_key);
231
+ if (!selectedColumn) return [];
232
+ groupName = "`".concat(selectedColumn.name, "`");
233
+ if (TIME_COLUMN_LIST.includes(selectedColumn.type)) {
234
+ groupName = getSqlGroup(_groupby_date_granularity, selectedColumn);
235
+ } else if (selectedColumn.type === CellType.GEOLOCATION) {
236
+ groupName = getSqlGroup(_groupby_geolocation_granularity, selectedColumn);
237
+ }
238
+ break;
239
+ }
240
+ case STAT_TYPE.TREND_CHART:
241
+ {
242
+ var date_column = statItem.date_column,
243
+ date_granularity = statItem.date_granularity;
244
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, date_column);
245
+ groupName = getSqlGroup(date_granularity, selectedColumn);
246
+ break;
247
+ }
248
+ case STAT_TYPE.COMPLETENESS_CHART:
249
+ case STAT_TYPE.GROUP_COMPLETENESS_CHART:
250
+ {
251
+ var name_column = statItem.name_column;
252
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, name_column);
253
+ groupName = "`".concat(selectedColumn.name, "`");
254
+ break;
255
+ }
256
+ case STAT_TYPE.DASHBOARD:
257
+ {
258
+ // todo
259
+ break;
260
+ }
261
+ case STAT_TYPE.PIVOT_TABLE:
262
+ {
263
+ var _groupby_column_key = statItem.groupby_column_key,
264
+ _groupby_date_granularity2 = statItem.groupby_date_granularity,
265
+ _groupby_geolocation_granularity2 = statItem.groupby_geolocation_granularity,
266
+ _column_groupby_column_key = statItem.column_groupby_column_key,
267
+ _column_groupby_date_granularity = statItem.column_groupby_date_granularity,
268
+ _column_groupby_geolocation_granularity = statItem.column_groupby_geolocation_granularity,
269
+ _column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column;
270
+ if (!_column_groupby_multiple_numeric_column && _column_groupby_column_key) {
271
+ columnSelectedColumn = TableUtils.getTableColumnByKey(selectedTable, _column_groupby_column_key);
272
+ columnGroupName = getGroupName(columnSelectedColumn, {
273
+ groupby_date_granularity: _column_groupby_date_granularity,
274
+ groupby_geolocation_granularity: _column_groupby_geolocation_granularity
275
+ });
276
+ }
277
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, _groupby_column_key);
278
+ groupName = getGroupName(selectedColumn, {
279
+ groupby_date_granularity: _groupby_date_granularity2,
280
+ groupby_geolocation_granularity: _groupby_geolocation_granularity2
281
+ });
282
+ break;
283
+ }
284
+ default:
285
+ break;
286
+ }
287
+ return {
288
+ groupName: groupName,
289
+ selectedColumn: selectedColumn,
290
+ columnGroupName: columnGroupName,
291
+ columnSelectedColumn: columnSelectedColumn
292
+ };
293
+ };