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,353 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import { DateUtils, isNumber, isNumericColumn, CellType, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, sortText, sortNumber, sortDate, sortSingleSelect, getPrecisionNumber, getFormulaDisplayString, getGeolocationDisplayString, getDateDisplayString, getNumberDisplayString } from 'dtable-store';
4
+ import { getClientFormulaDisplayString } from '../utils';
5
+ import { STATISTICS_COUNT_TYPE } from '../constants';
6
+ var SUPPORT_SORT_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.SINGLE_SELECT, CellType.FORMULA, CellType.LINK_FORMULA, CellType.CTIME, CellType.MTIME, CellType.RATE];
7
+ var getValidCollaborators = function getValidCollaborators(collaborators, emails) {
8
+ if (!Array.isArray(emails)) {
9
+ return [];
10
+ }
11
+ return emails.filter(function (e) {
12
+ return collaborators.findIndex(function (c) {
13
+ return c.email === e;
14
+ }) > -1;
15
+ });
16
+ };
17
+ var StatUtils = /*#__PURE__*/function () {
18
+ function StatUtils() {
19
+ _classCallCheck(this, StatUtils);
20
+ }
21
+ _createClass(StatUtils, null, [{
22
+ key: "getGroupLabel",
23
+ value: function getGroupLabel(cellValue, formulaRow, column, dateGranularity, geoGranularity, value) {
24
+ var type = column.type,
25
+ key = column.key,
26
+ data = column.data;
27
+ switch (type) {
28
+ case CellType.TEXT:
29
+ {
30
+ return cellValue || null;
31
+ }
32
+ case CellType.NUMBER:
33
+ {
34
+ if (!cellValue && cellValue !== 0) {
35
+ return null;
36
+ }
37
+ var number = getPrecisionNumber(cellValue, data);
38
+ var valueNumber = parseFloat(number);
39
+ return isNumber(valueNumber) ? getNumberDisplayString(valueNumber, column.data) : valueNumber;
40
+ }
41
+ case CellType.SINGLE_SELECT:
42
+ {
43
+ var isInvalidValue = data && data.options.findIndex(function (opt) {
44
+ return opt.id === cellValue;
45
+ }) < 0;
46
+ if (isInvalidValue) {
47
+ return null;
48
+ }
49
+ return cellValue;
50
+ }
51
+ case CellType.DATE:
52
+ case CellType.CTIME:
53
+ case CellType.MTIME:
54
+ {
55
+ if (!dateGranularity) {
56
+ return getDateDisplayString(cellValue);
57
+ }
58
+ return DateUtils.getDateByGranularity(cellValue, dateGranularity);
59
+ }
60
+ case CellType.MULTIPLE_SELECT:
61
+ {
62
+ var options = data && data.options;
63
+ if (!Array.isArray(cellValue)) {
64
+ return [];
65
+ }
66
+ return cellValue.filter(function (id) {
67
+ return options.findIndex(function (o) {
68
+ return o.id === id;
69
+ }) > -1;
70
+ });
71
+ }
72
+ case CellType.COLLABORATOR:
73
+ {
74
+ return getValidCollaborators(value.collaborators, cellValue);
75
+ }
76
+ case CellType.CREATOR:
77
+ case CellType.LAST_MODIFIER:
78
+ {
79
+ return cellValue ? cellValue : null;
80
+ }
81
+ case CellType.LINK_FORMULA:
82
+ case CellType.FORMULA:
83
+ {
84
+ if (!formulaRow) return '';
85
+ var formulaCellValue = formulaRow[key];
86
+ var _ref = data || {},
87
+ result_type = _ref.result_type;
88
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
89
+ return getFormulaDisplayString(formulaCellValue, data, {
90
+ tables: value.tables
91
+ }) || null;
92
+ }
93
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
94
+ return getPrecisionNumber(formulaCellValue, data);
95
+ }
96
+ return formulaCellValue ? formulaCellValue + '' : null;
97
+ }
98
+ case CellType.GEOLOCATION:
99
+ {
100
+ var _ref2 = data || {},
101
+ geo_format = _ref2.geo_format;
102
+ if (geo_format === 'country_region' || geo_format === 'lng_lat' || !geoGranularity) {
103
+ return getGeolocationDisplayString(cellValue, data);
104
+ }
105
+ return cellValue ? cellValue[geoGranularity] : null;
106
+ }
107
+ case CellType.LINK:
108
+ {
109
+ var linkCellValue = formulaRow && formulaRow[key];
110
+ if (!Array.isArray(linkCellValue)) {
111
+ return [];
112
+ }
113
+ return linkCellValue.map(function (linkVal) {
114
+ return linkVal.display_value;
115
+ });
116
+ }
117
+ case CellType.CHECKBOX:
118
+ {
119
+ return String(!!cellValue);
120
+ }
121
+ case CellType.RATE:
122
+ {
123
+ if (!cellValue) return null;
124
+ return cellValue + '';
125
+ }
126
+ default:
127
+ {
128
+ return null;
129
+ }
130
+ }
131
+ }
132
+ }, {
133
+ key: "sortStatistics",
134
+ value: function sortStatistics(statistics, column, sort_key) {
135
+ var column_type = column.type,
136
+ data = column.data;
137
+ var sortType = 'up';
138
+ var option_id_index_map = {};
139
+ if (column_type === CellType.SINGLE_SELECT) {
140
+ var _ref3 = data || {},
141
+ options = _ref3.options;
142
+ Array.isArray(options) && options.forEach(function (option, index) {
143
+ option_id_index_map[option.id] = index;
144
+ });
145
+ }
146
+ statistics.sort(function (currResult, nextResult) {
147
+ var current = currResult[sort_key];
148
+ var next = nextResult[sort_key];
149
+ if (!current && current !== 0) {
150
+ return -1;
151
+ }
152
+ if (!next && next !== 0) {
153
+ return 1;
154
+ }
155
+ if (SUPPORT_SORT_COLUMNS.includes(column_type)) {
156
+ switch (column_type) {
157
+ case CellType.NUMBER:
158
+ {
159
+ if (current) {
160
+ current = current - 0;
161
+ }
162
+ if (next) {
163
+ next = next - 0;
164
+ }
165
+ return sortNumber(current, next, sortType);
166
+ }
167
+ case CellType.DATE:
168
+ case CellType.CTIME:
169
+ case CellType.MTIME:
170
+ {
171
+ return sortDate(current, next, sortType);
172
+ }
173
+ case CellType.SINGLE_SELECT:
174
+ case CellType.MULTIPLE_SELECT:
175
+ {
176
+ return sortSingleSelect(current, next, {
177
+ sort_type: sortType,
178
+ option_id_index_map: option_id_index_map
179
+ });
180
+ }
181
+ case CellType.FORMULA:
182
+ case CellType.LINK_FORMULA:
183
+ {
184
+ var _ref4 = data || {},
185
+ result_type = _ref4.result_type;
186
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
187
+ if (current) {
188
+ current = current - 0;
189
+ }
190
+ if (next) {
191
+ next = next - 0;
192
+ }
193
+ return sortNumber(current, next, sortType);
194
+ }
195
+ return sortText(result_type, current, next, sortType);
196
+ }
197
+ default:
198
+ {
199
+ return sortText(current, next, sortType);
200
+ }
201
+ }
202
+ }
203
+ });
204
+ }
205
+ }, {
206
+ key: "sortStatisticData",
207
+ value: function sortStatisticData(statistics, sort_type) {
208
+ statistics.sort(function (currResult, nextResult) {
209
+ var current = currResult.value;
210
+ var next = nextResult.value;
211
+ if (!current && current !== 0) {
212
+ return -1;
213
+ }
214
+ if (!next && next !== 0) {
215
+ return 1;
216
+ }
217
+ if (sort_type === 'ascending') {
218
+ return current > next ? 1 : -1;
219
+ } else {
220
+ return current > next ? -1 : 1;
221
+ }
222
+ });
223
+ }
224
+ }, {
225
+ key: "getTotal",
226
+ value: function getTotal(summary_column_key, summary_column_type, summary_type, summary_method) {
227
+ var rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
228
+ var formula_rows = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
229
+ var rowsLength = rows.length;
230
+ var total;
231
+ if (summary_type === STATISTICS_COUNT_TYPE.COUNT) {
232
+ total = rowsLength;
233
+ } else if (summary_type === STATISTICS_COUNT_TYPE.ADVANCED) {
234
+ switch (summary_method) {
235
+ case 'Distinct_values':
236
+ {
237
+ var count = 0;
238
+ var existMap = {};
239
+ rows.forEach(function (r) {
240
+ var num;
241
+ if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
242
+ var formulaRow = formula_rows[r._id] || {};
243
+ num = formulaRow[summary_column_key];
244
+ num = Array.isArray(num) ? num[0] : num;
245
+ } else {
246
+ num = r[summary_column_key];
247
+ }
248
+ if (!num) {
249
+ if (num === 0) {
250
+ num = '0';
251
+ } else {
252
+ num = !!num;
253
+ }
254
+ }
255
+ if (!existMap[num]) {
256
+ existMap[num] = true;
257
+ count++;
258
+ }
259
+ });
260
+ total = count;
261
+ break;
262
+ }
263
+ case 'Sum':
264
+ case 'Mean':
265
+ {
266
+ var sum = 0;
267
+ var validNumbersCount = 0;
268
+ rows.forEach(function (r) {
269
+ var num;
270
+ if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
271
+ var formulaRow = formula_rows[r._id] || {};
272
+ num = formulaRow[summary_column_key];
273
+ num = Array.isArray(num) ? num[0] : num;
274
+ } else {
275
+ num = r[summary_column_key];
276
+ }
277
+ if (isNumber(num)) {
278
+ validNumbersCount++;
279
+ sum += num;
280
+ }
281
+ });
282
+ if (summary_method === 'Sum') {
283
+ total = Number.parseFloat(sum.toFixed(8));
284
+ } else if (summary_method === 'Mean') {
285
+ total = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
286
+ }
287
+ break;
288
+ }
289
+ case 'Max':
290
+ case 'Min':
291
+ {
292
+ if (rowsLength > 0) {
293
+ var result = rows.reduce(function (current, next) {
294
+ var currentValue, nextValue;
295
+ if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
296
+ var currentFormulaRow = formula_rows[current._id];
297
+ var nextFormulaRow = formula_rows[next._id];
298
+ currentValue = currentFormulaRow && currentFormulaRow[summary_column_key];
299
+ nextValue = nextFormulaRow && nextFormulaRow[summary_column_key];
300
+ currentValue = Array.isArray(currentValue) ? currentValue[0] : currentValue;
301
+ nextValue = Array.isArray(nextValue) ? nextValue[0] : nextValue;
302
+ } else {
303
+ currentValue = current[summary_column_key];
304
+ nextValue = next[summary_column_key];
305
+ }
306
+ if (!nextValue && nextValue !== 0) {
307
+ return current;
308
+ }
309
+ var isNextGreater = currentValue < nextValue;
310
+ if (summary_method === 'Min') {
311
+ return isNextGreater ? current : next;
312
+ } else {
313
+ return isNextGreater ? next : current;
314
+ }
315
+ });
316
+ if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
317
+ var formulaRow = formula_rows[result._id];
318
+ total = formulaRow && formulaRow[summary_column_key];
319
+ total = Array.isArray(total) ? total[0] : total;
320
+ } else {
321
+ total = result[summary_column_key];
322
+ }
323
+ }
324
+ break;
325
+ }
326
+ default:
327
+ {
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ return total || 0;
333
+ }
334
+ }, {
335
+ key: "getFormattedValue",
336
+ value: function getFormattedValue(value, column) {
337
+ if (!column) {
338
+ return value;
339
+ }
340
+ var type = column.type,
341
+ data = column.data;
342
+ if (FORMULA_COLUMN_TYPES_MAP[type]) {
343
+ return getClientFormulaDisplayString(value, data);
344
+ }
345
+ if (isNumericColumn(column)) {
346
+ return getNumberDisplayString(value, data);
347
+ }
348
+ return value;
349
+ }
350
+ }]);
351
+ return StatUtils;
352
+ }();
353
+ export default StatUtils;
@@ -0,0 +1,136 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import dayjs from 'dayjs';
3
+ import quarterOfYear from 'dayjs/plugin/quarterOfYear';
4
+ import { getSummaryResult } from './common-utils';
5
+ import { DATE_GRANULARITY, SUMMARY_TYPE } from '../constants';
6
+ dayjs.extend(quarterOfYear);
7
+ export function getCompareDate(dateGranularity) {
8
+ var currentDate = dayjs();
9
+ switch (dateGranularity) {
10
+ case DATE_GRANULARITY.DAY:
11
+ {
12
+ var compareDate = dayjs(currentDate).subtract(1, 'days').format('YYYY-MM-DD');
13
+ var comparedDate = dayjs(currentDate).subtract(2, 'days').format('YYYY-MM-DD');
14
+ return {
15
+ compareDate: compareDate,
16
+ comparedDate: comparedDate
17
+ };
18
+ }
19
+ case DATE_GRANULARITY.WEEK:
20
+ {
21
+ var currentWeek = dayjs().day(1);
22
+ var _compareDate = dayjs(currentWeek).subtract(1, 'weeks').format('YYYY-MM-DD');
23
+ var _comparedDate = dayjs(currentWeek).subtract(2, 'weeks').format('YYYY-MM-DD');
24
+ return {
25
+ compareDate: _compareDate,
26
+ comparedDate: _comparedDate
27
+ };
28
+ }
29
+ case DATE_GRANULARITY.MONTH:
30
+ {
31
+ var _compareDate2 = dayjs(currentDate).subtract(1, 'months').format('YYYY-MM');
32
+ var _comparedDate2 = dayjs(currentDate).subtract(2, 'months').format('YYYY-MM');
33
+ return {
34
+ compareDate: _compareDate2,
35
+ comparedDate: _comparedDate2
36
+ };
37
+ }
38
+ case DATE_GRANULARITY.QUARTER:
39
+ {
40
+ var currentQuarter = dayjs().quarter();
41
+ var currentYear = dayjs().year();
42
+ var lastQuarter = currentQuarter - 1;
43
+ var _compareDate3, _comparedDate3;
44
+ if (lastQuarter < 1) {
45
+ _compareDate3 = currentYear - 1 + '-Q4';
46
+ _comparedDate3 = currentYear - 1 + '-Q3';
47
+ return {
48
+ compareDate: _compareDate3,
49
+ comparedDate: _comparedDate3
50
+ };
51
+ }
52
+ _compareDate3 = currentYear + '-Q' + lastQuarter;
53
+ _comparedDate3 = currentYear + '-Q' + (lastQuarter - 1);
54
+ if (lastQuarter - 1 < 1) {
55
+ _comparedDate3 = currentYear - 1 + '-Q4';
56
+ }
57
+ return {
58
+ compareDate: _compareDate3,
59
+ comparedDate: _comparedDate3
60
+ };
61
+ }
62
+ case DATE_GRANULARITY.YEAR:
63
+ {
64
+ var _currentYear = dayjs().year();
65
+ return {
66
+ compareDate: _currentYear - 1 + '',
67
+ comparedDate: _currentYear - 2 + ''
68
+ };
69
+ }
70
+ default:
71
+ {
72
+ return {};
73
+ }
74
+ }
75
+ }
76
+ export function summaryDurationResult(result, duration, summaryType, summaryMethod, useDataDb, dbDateKey, valueKey) {
77
+ var currentTime = dayjs();
78
+ var days = duration === 'days_30' ? 30 : 7;
79
+ var endDate = currentTime.format('YYYY-MM-DD');
80
+ var middleDate = currentTime.subtract(days, 'days').format('YYYY-MM-DD');
81
+ var startDate = currentTime.subtract(days, 'days').format('YYYY-MM-DD');
82
+ var compareValue = [];
83
+ var comparedValue = [];
84
+ if (useDataDb) {
85
+ var days1 = [];
86
+ var days2 = [];
87
+ for (var index = 0; index < result.length; index++) {
88
+ var item = result[index];
89
+ var key = item[dbDateKey];
90
+ if (key >= startDate && key < middleDate) {
91
+ comparedValue.push(item[valueKey]);
92
+ days1.push(key);
93
+ } else if (key >= middleDate && key < endDate) {
94
+ compareValue.push(item[valueKey]);
95
+ days2.push(key);
96
+ }
97
+ }
98
+ } else {
99
+ var _iterator = _createForOfIteratorHelper(result),
100
+ _step;
101
+ try {
102
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
103
+ var _item = _step.value;
104
+ var _key = _item[0];
105
+ if (_key >= startDate && _key < middleDate) {
106
+ if (summaryType === SUMMARY_TYPE.ADVANCED) {
107
+ comparedValue = comparedValue.concat(_item[1] || []);
108
+ } else {
109
+ comparedValue.push(_item[1]);
110
+ }
111
+ } else if (_key >= middleDate && _key < endDate) {
112
+ if (summaryType === SUMMARY_TYPE.ADVANCED) {
113
+ compareValue = compareValue.concat(_item[1] || []);
114
+ } else {
115
+ compareValue.push(_item[1]);
116
+ }
117
+ }
118
+ }
119
+ } catch (err) {
120
+ _iterator.e(err);
121
+ } finally {
122
+ _iterator.f();
123
+ }
124
+ }
125
+ if (summaryType === SUMMARY_TYPE.ADVANCED) {
126
+ comparedValue = getSummaryResult(comparedValue, summaryMethod);
127
+ compareValue = getSummaryResult(compareValue, summaryMethod);
128
+ } else {
129
+ compareValue = getSummaryResult(compareValue, 'Sum');
130
+ comparedValue = getSummaryResult(comparedValue, 'Sum');
131
+ }
132
+ return {
133
+ compareValue: compareValue,
134
+ comparedValue: comparedValue
135
+ };
136
+ }
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/dtable-statistic');
package/package.json ADDED
@@ -0,0 +1,188 @@
1
+ {
2
+ "name": "dtable-statistic",
3
+ "version": "4.0.2-test-2",
4
+ "description": "statistics",
5
+ "main": "dist/dtable-statistic.js",
6
+ "author": "seafile",
7
+ "private": false,
8
+ "dependencies": {
9
+ "@antv/data-set": "^0.11.8",
10
+ "@antv/g2": "^4.1.42",
11
+ "@antv/util": "^3.3.2",
12
+ "@seafile/seafile-calendar": "0.0.24",
13
+ "comlink": "^4.3.1",
14
+ "dayjs": "1.10.7",
15
+ "dtable-store": "4.0.2",
16
+ "dtable-web-api": "4.0.1",
17
+ "html2canvas": "^1.4.1",
18
+ "rc-slider": "^9.7.4",
19
+ "react": "16.14.0",
20
+ "react-color": "2.19.3",
21
+ "react-dom": "16.14.0",
22
+ "react-grid-layout": "^1.2.5",
23
+ "react-intl-universal": "^2.4.8",
24
+ "react-select": "^3.1.0",
25
+ "reactstrap": "8.9.0"
26
+ },
27
+ "scripts": {
28
+ "clean:esm": "rm -rf es && mkdir es",
29
+ "clean:lib": "rm -rf lib && mkdir lib",
30
+ "clean:dist": "rm -rf dist && mkdir dist",
31
+ "start": "node scripts/start.js",
32
+ "build": "node scripts/build.js",
33
+ "test": "node scripts/test.js",
34
+ "translate": "node scripts/translate.js",
35
+ "push-translate": "tx push -s",
36
+ "pull-translate": "tx pull -a -f && npm run translate",
37
+ "pub:esm": "npm run clean:esm && export BABEL_ENV=production && ./node_modules/.bin/babel src --out-dir es --copy-files",
38
+ "pub:optimized": "rm es/settings.js es/index.local.*",
39
+ "prepublishOnly": "npm run pub:esm && npm run pub:optimized"
40
+ },
41
+ "files": [
42
+ "es",
43
+ "index.js",
44
+ "package.json"
45
+ ],
46
+ "eslintConfig": {
47
+ "extends": "react-app"
48
+ },
49
+ "browserslist": {
50
+ "production": [
51
+ ">0.2%",
52
+ "not dead",
53
+ "not op_mini all"
54
+ ],
55
+ "development": [
56
+ "last 1 chrome version",
57
+ "last 1 firefox version",
58
+ "last 1 safari version"
59
+ ]
60
+ },
61
+ "jest": {
62
+ "roots": [
63
+ "<rootDir>/src"
64
+ ],
65
+ "collectCoverageFrom": [
66
+ "src/**/*.{js,jsx,ts,tsx}",
67
+ "!src/**/*.d.ts"
68
+ ],
69
+ "setupFiles": [
70
+ "react-app-polyfill/jsdom"
71
+ ],
72
+ "setupFilesAfterEnv": [
73
+ "<rootDir>/src/setupTests.js"
74
+ ],
75
+ "testMatch": [
76
+ "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
77
+ "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
78
+ ],
79
+ "testEnvironment": "jest-environment-jsdom-fourteen",
80
+ "transform": {
81
+ "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
82
+ "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
83
+ "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
84
+ },
85
+ "transformIgnorePatterns": [
86
+ "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
87
+ "^.+\\.module\\.(css|sass|scss)$"
88
+ ],
89
+ "modulePaths": [],
90
+ "moduleNameMapper": {
91
+ "^react-native$": "react-native-web",
92
+ "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
93
+ },
94
+ "moduleFileExtensions": [
95
+ "web.js",
96
+ "js",
97
+ "web.ts",
98
+ "ts",
99
+ "web.tsx",
100
+ "tsx",
101
+ "json",
102
+ "web.jsx",
103
+ "jsx",
104
+ "node"
105
+ ],
106
+ "watchPlugins": [
107
+ "jest-watch-typeahead/filename",
108
+ "jest-watch-typeahead/testname"
109
+ ]
110
+ },
111
+ "devDependencies": {
112
+ "@babel/cli": "^7.4.4",
113
+ "@babel/core": "7.4.3",
114
+ "@babel/plugin-proposal-class-properties": "^7.4.4",
115
+ "@babel/plugin-proposal-export-default-from": "^7.5.2",
116
+ "@babel/plugin-proposal-export-namespace-from": "^7.5.2",
117
+ "@babel/plugin-proposal-object-rest-spread": "^7.5.2",
118
+ "@babel/plugin-transform-member-expression-literals": "^7.2.0",
119
+ "@babel/plugin-transform-property-literals": "^7.2.0",
120
+ "@babel/plugin-transform-runtime": "^7.4.4",
121
+ "@babel/preset-env": "^7.4.5",
122
+ "@babel/preset-react": "^7.0.0",
123
+ "@babel/runtime": "^7.14.0",
124
+ "@svgr/webpack": "4.1.0",
125
+ "@typescript-eslint/eslint-plugin": "1.6.0",
126
+ "@typescript-eslint/parser": "1.6.0",
127
+ "babel-eslint": "10.0.1",
128
+ "babel-jest": "^24.8.0",
129
+ "babel-loader": "8.0.5",
130
+ "babel-plugin-named-asset-import": "^0.3.2",
131
+ "babel-preset-react-app": "^9.0.0",
132
+ "camelcase": "^5.2.0",
133
+ "case-sensitive-paths-webpack-plugin": "2.2.0",
134
+ "css-loader": "^3.0.0",
135
+ "debug": "^4.1.1",
136
+ "dotenv": "6.2.0",
137
+ "dotenv-expand": "4.2.0",
138
+ "enzyme": "^3.10.0",
139
+ "enzyme-adapter-react-16": "^1.14.0",
140
+ "eslint": "^5.16.0",
141
+ "eslint-config-react-app": "^4.0.1",
142
+ "eslint-loader": "2.1.2",
143
+ "eslint-plugin-flowtype": "2.50.1",
144
+ "eslint-plugin-import": "2.16.0",
145
+ "eslint-plugin-jsx-a11y": "6.2.1",
146
+ "eslint-plugin-react": "7.12.4",
147
+ "eslint-plugin-react-hooks": "^1.5.0",
148
+ "file-loader": "^4.0.0",
149
+ "fs-extra": "7.0.1",
150
+ "html-webpack-plugin": "4.0.0-beta.5",
151
+ "identity-obj-proxy": "3.0.0",
152
+ "is-wsl": "^1.1.0",
153
+ "jest": "24.7.1",
154
+ "jest-environment-jsdom-fourteen": "0.1.0",
155
+ "jest-resolve": "24.7.1",
156
+ "jest-watch-typeahead": "0.3.0",
157
+ "less": "^3.10.3",
158
+ "less-loader": "^5.0.0",
159
+ "mini-css-extract-plugin": "0.5.0",
160
+ "optimize-css-assets-webpack-plugin": "5.0.1",
161
+ "pnp-webpack-plugin": "1.2.1",
162
+ "postcss-flexbugs-fixes": "^4.1.0",
163
+ "postcss-loader": "^3.0.0",
164
+ "postcss-normalize": "7.0.1",
165
+ "postcss-preset-env": "6.6.0",
166
+ "postcss-safe-parser": "4.0.1",
167
+ "react": "16.14.0",
168
+ "react-app-polyfill": "^1.0.1",
169
+ "react-dev-utils": "^9.0.1",
170
+ "react-dom": "16.14.0",
171
+ "resolve": "1.10.0",
172
+ "sass-loader": "^7.1.0",
173
+ "semver": "6.0.0",
174
+ "style-loader": "^0.23.1",
175
+ "svg-sprite-loader": "^6.0.11",
176
+ "svgo-loader": "^3.0.0",
177
+ "terser-webpack-plugin": "^1.2.3",
178
+ "ts-pnp": "1.1.2",
179
+ "url-loader": "^2.0.0",
180
+ "webpack": "4.29.6",
181
+ "webpack-bundle-analyzer": "^4.7.0",
182
+ "webpack-cli": "^3.3.4",
183
+ "webpack-dev-server": "3.2.1",
184
+ "webpack-manifest-plugin": "2.0.4",
185
+ "workbox-webpack-plugin": "4.2.0",
186
+ "worker-loader": "^3.0.8"
187
+ }
188
+ }