@seafile/sdoc-editor 0.3.25 → 0.3.26-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 (93) hide show
  1. package/dist/api/seafile-api.js +20 -0
  2. package/dist/basic-sdk/constants/index.js +2 -1
  3. package/dist/basic-sdk/editor/sdoc-editor.js +20 -2
  4. package/dist/basic-sdk/extension/constants/element-type.js +1 -0
  5. package/dist/basic-sdk/extension/constants/index.js +2 -2
  6. package/dist/basic-sdk/extension/constants/menus-config.js +6 -1
  7. package/dist/basic-sdk/extension/plugins/chart/chart-components/base-setting/index.js +46 -0
  8. package/dist/basic-sdk/extension/plugins/chart/chart-components/chart-type-setting/index.css +29 -0
  9. package/dist/basic-sdk/extension/plugins/chart/chart-components/chart-type-setting/index.js +23 -0
  10. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/column-setting.js +119 -0
  11. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/data-sort-setting.js +54 -0
  12. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/date-granularities.js +55 -0
  13. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/dtable-select-setting.js +86 -0
  14. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/geolocation-granularities.js +97 -0
  15. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/groupby-numeric-item.js +108 -0
  16. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/groupby-numeric-items.js +87 -0
  17. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/include-empty-setting.js +35 -0
  18. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/summary-field-setting.js +64 -0
  19. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/summary-method-setting.js +61 -0
  20. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/summary-type-setting.js +74 -0
  21. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/x-axis-group-setting.js +108 -0
  22. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/y-axis-group-settings.js +182 -0
  23. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/common-add-tool.js +23 -0
  24. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/common-hooks.js +15 -0
  25. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/constants.js +10 -0
  26. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/index.js +98 -0
  27. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/option-group.js +236 -0
  28. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/option.js +40 -0
  29. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/select.css +135 -0
  30. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/date-translate.js +54 -0
  31. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/department-multiple-select.js +146 -0
  32. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/department-single-select.js +272 -0
  33. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/index.css +209 -0
  34. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/index.js +98 -0
  35. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/selected-departments.js +85 -0
  36. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/dtable-search-input.js +127 -0
  37. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/collaborator-filter.js +106 -0
  38. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/department-multiple-select-filter.js +86 -0
  39. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/department-single-select-filter.js +85 -0
  40. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-calendar.js +166 -0
  41. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-item-utils.js +144 -0
  42. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-item.js +679 -0
  43. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filters-list.css +320 -0
  44. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filters-list.js +121 -0
  45. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/rate-item.js +72 -0
  46. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover.js +208 -0
  47. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filters-popover.css +30 -0
  48. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/index.css +18 -0
  49. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/index.js +79 -0
  50. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/utils.js +531 -0
  51. package/dist/basic-sdk/extension/plugins/chart/chart-components/seatable-radio/index.js +28 -0
  52. package/dist/basic-sdk/extension/plugins/chart/chart-components/seatable-radio/style.css +52 -0
  53. package/dist/basic-sdk/extension/plugins/chart/chart-components/table-setting/index.js +46 -0
  54. package/dist/basic-sdk/extension/plugins/chart/chart-components/toggle-setting/index.js +27 -0
  55. package/dist/basic-sdk/extension/plugins/chart/chart-components/toggle-setting/style.css +29 -0
  56. package/dist/basic-sdk/extension/plugins/chart/chart-edit-dialog/index.css +22 -0
  57. package/dist/basic-sdk/extension/plugins/chart/chart-edit-dialog/index.js +111 -0
  58. package/dist/basic-sdk/extension/plugins/chart/chart-setting/index.css +24 -0
  59. package/dist/basic-sdk/extension/plugins/chart/chart-setting/index.js +120 -0
  60. package/dist/basic-sdk/extension/plugins/chart/chart-utils/common-utils/base-utils.js +430 -0
  61. package/dist/basic-sdk/extension/plugins/chart/chart-utils/common-utils/dtable-utils.js +144 -0
  62. package/dist/basic-sdk/extension/plugins/chart/chart-utils/histogram-bar-utils.js +83 -0
  63. package/dist/basic-sdk/extension/plugins/chart/constants/date-constants.js +9 -0
  64. package/dist/basic-sdk/extension/plugins/chart/constants/geolocation-constants.js +11 -0
  65. package/dist/basic-sdk/extension/plugins/chart/constants/index.js +109 -0
  66. package/dist/basic-sdk/extension/plugins/chart/constants/special-column-types.js +7 -0
  67. package/dist/basic-sdk/extension/plugins/chart/constants/summary-constants.js +18 -0
  68. package/dist/basic-sdk/extension/plugins/chart/helpers.js +98 -0
  69. package/dist/basic-sdk/extension/plugins/chart/hover-menu/index.css +55 -0
  70. package/dist/basic-sdk/extension/plugins/chart/hover-menu/index.js +54 -0
  71. package/dist/basic-sdk/extension/plugins/chart/index.js +12 -0
  72. package/dist/basic-sdk/extension/plugins/chart/menu/index.js +23 -0
  73. package/dist/basic-sdk/extension/plugins/chart/model.js +34 -0
  74. package/dist/basic-sdk/extension/plugins/chart/plugin.js +20 -0
  75. package/dist/basic-sdk/extension/plugins/chart/render-elem.css +26 -0
  76. package/dist/basic-sdk/extension/plugins/chart/render-elem.js +229 -0
  77. package/dist/basic-sdk/extension/plugins/index.js +3 -2
  78. package/dist/basic-sdk/extension/plugins/link/hover/index.js +3 -1
  79. package/dist/basic-sdk/extension/plugins/link/render-elem.js +4 -3
  80. package/dist/basic-sdk/extension/render/custom-element.js +10 -4
  81. package/dist/basic-sdk/extension/toolbar/header-toolbar/insert-toolbar/index.js +2 -1
  82. package/dist/components/doc-operations/more-operations.js +21 -12
  83. package/dist/constants/index.js +3 -0
  84. package/dist/context.js +44 -0
  85. package/package.json +9 -1
  86. package/public/locales/en/sdoc-editor.json +34 -1
  87. package/public/locales/zh_CN/sdoc-editor.json +35 -1
  88. package/public/media/{sdoc-editor-font.css → iconfont.css} +10 -10
  89. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  90. package/public/media/sdoc-editor-font/iconfont.svg +2 -2
  91. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  92. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  93. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
@@ -0,0 +1,430 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { CellType, FORMULA_RESULT_TYPE, sortText, sortNumber, sortDate, sortSingleSelect, getFormulaDisplayString, getNumberDisplayString } from 'dtable-utils';
3
+ import { FORMULA_COLUMN_TYPES, COLLABORATOR_COLUMN_TYPES } from '../../constants/special-column-types';
4
+ import { DEFAULT_LABEL_FONT_SIZE, STATISTICS_COUNT_TYPE, STAT_TYPE } from '../../constants';
5
+ const Y_AXIS_SUPPORT_ROW_COUNT_CHARTS = [STAT_TYPE.BASIC_NUMBER_CARD];
6
+ const SUPPORT_SORT_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.SINGLE_SELECT, CellType.FORMULA, CellType.LINK_FORMULA, CellType.CTIME, CellType.MTIME, CellType.RATE];
7
+ export const isNumber = num => {
8
+ return (num || num === 0) && Object.prototype.toString.call(num) === '[object Number]';
9
+ };
10
+ export function isEmptyGeolocationCell(value, format) {
11
+ if (!value) return null;
12
+ if (format === 'lng_lat') {
13
+ return value.lng && value.lat;
14
+ }
15
+ if (format === 'country_region') {
16
+ return value.country_region;
17
+ }
18
+ return value.province;
19
+ }
20
+ export function isValidRow(row, column, includeEmpty) {
21
+ const {
22
+ type: columnType
23
+ } = column;
24
+ if (includeEmpty || columnType === CellType.CHECKBOX) return true;
25
+ let cellValue;
26
+ if (FORMULA_COLUMN_TYPES.includes(columnType) || columnType === CellType.LINK) {
27
+ cellValue = row[column['id']] ? row[column['id']] : null;
28
+ } else if (columnType === CellType.GEOLOCATION) {
29
+ const value = row[column['id']];
30
+ const {
31
+ geo_format
32
+ } = column.data;
33
+ return isEmptyGeolocationCell(value, geo_format);
34
+ } else {
35
+ cellValue = row[column['id']];
36
+ }
37
+ return cellValue || cellValue === 0;
38
+ }
39
+ export function sortStatisticData(statistics, sort_type) {
40
+ statistics.sort((currResult, nextResult) => {
41
+ let {
42
+ value: current
43
+ } = currResult;
44
+ let {
45
+ value: next
46
+ } = nextResult;
47
+ if (!current && current !== 0) {
48
+ return -1;
49
+ }
50
+ if (!next && next !== 0) {
51
+ return 1;
52
+ }
53
+ if (sort_type === 'ascending') {
54
+ return current > next ? 1 : -1;
55
+ } else {
56
+ return current > next ? -1 : 1;
57
+ }
58
+ });
59
+ }
60
+ export function getTotal(summary_column_key, summary_column_type, summary_type, summary_method) {
61
+ let rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
62
+ let rowsLength = rows.length;
63
+ let total;
64
+ if (summary_type === STATISTICS_COUNT_TYPE.COUNT) {
65
+ total = rowsLength;
66
+ return total;
67
+ }
68
+ if (summary_type === STATISTICS_COUNT_TYPE.ADVANCED) {
69
+ switch (summary_method) {
70
+ case 'Distinct_values':
71
+ {
72
+ let count = 0;
73
+ let existMap = {};
74
+ rows.forEach(r => {
75
+ console.log(r);
76
+ let num;
77
+ if (FORMULA_COLUMN_TYPES.includes(summary_column_type)) {
78
+ num = r[summary_column_key];
79
+ num = Array.isArray(num) ? num[0] : num;
80
+ } else {
81
+ num = r[summary_column_key];
82
+ }
83
+ if (!num) {
84
+ if (num === 0) {
85
+ num = '0';
86
+ } else {
87
+ num = !!num;
88
+ }
89
+ }
90
+ if (!existMap[num]) {
91
+ existMap[num] = true;
92
+ count++;
93
+ }
94
+ });
95
+ total = count;
96
+ break;
97
+ }
98
+ case 'Sum':
99
+ case 'Mean':
100
+ {
101
+ let sum = 0;
102
+ let validNumbersCount = 0;
103
+ rows.forEach(r => {
104
+ let num;
105
+ if (FORMULA_COLUMN_TYPES.includes(summary_column_type)) {
106
+ num = r[summary_column_key];
107
+ num = Array.isArray(num) ? num[0] : num;
108
+ } else {
109
+ num = r[summary_column_key];
110
+ }
111
+ if (isNumber(num)) {
112
+ validNumbersCount++;
113
+ sum += num;
114
+ }
115
+ });
116
+ if (summary_method === 'Sum') {
117
+ total = Number.parseFloat(sum.toFixed(8));
118
+ } else if (summary_method === 'Mean') {
119
+ total = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
120
+ }
121
+ break;
122
+ }
123
+ case 'Max':
124
+ case 'Min':
125
+ {
126
+ if (rowsLength > 0) {
127
+ let result = rows.reduce((current, next) => {
128
+ let currentValue, nextValue;
129
+ if (FORMULA_COLUMN_TYPES.includes(summary_column_type)) {
130
+ currentValue = current[summary_column_key];
131
+ nextValue = next[summary_column_key];
132
+ currentValue = Array.isArray(currentValue) ? currentValue[0] : currentValue;
133
+ nextValue = Array.isArray(nextValue) ? nextValue[0] : nextValue;
134
+ } else {
135
+ currentValue = current[summary_column_key];
136
+ nextValue = next[summary_column_key];
137
+ }
138
+ if (!nextValue && nextValue !== 0) {
139
+ return current;
140
+ }
141
+ let isNextGreater = currentValue < nextValue;
142
+ if (summary_method === 'Min') {
143
+ return isNextGreater ? current : next;
144
+ } else {
145
+ return isNextGreater ? next : current;
146
+ }
147
+ });
148
+ if (FORMULA_COLUMN_TYPES.includes(summary_column_type)) {
149
+ total = result[summary_column_key];
150
+ total = Array.isArray(total) ? total[0] : total;
151
+ } else {
152
+ total = result[summary_column_key];
153
+ }
154
+ }
155
+ break;
156
+ }
157
+ default:
158
+ {
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ return total || 0;
164
+ }
165
+ export function getClientFormulaDisplayString(value, columnData) {
166
+ let {
167
+ collaborators = []
168
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
169
+ if (!columnData || !value && value !== 0) return '';
170
+ const {
171
+ result_type,
172
+ array_type
173
+ } = columnData;
174
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
175
+ if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
176
+ if (!value) {
177
+ return null;
178
+ }
179
+ const collaboratorList = Array.isArray(value) ? value : [value];
180
+ return getCollaboratorsName(collaborators, collaboratorList);
181
+ }
182
+ }
183
+ return getFormulaDisplayString(value, columnData, {
184
+ collaborators
185
+ });
186
+ }
187
+ export function getCollaboratorsName(emails, collaborators) {
188
+ if (!emails) {
189
+ return null;
190
+ }
191
+ let collaboratorsName = [];
192
+ emails.forEach(email => {
193
+ const collaborator = collaborators.find(collaborator => collaborator.email === email);
194
+ if (collaborator) {
195
+ collaboratorsName.push(collaborator.name);
196
+ }
197
+ });
198
+ if (collaboratorsName.length === 0) {
199
+ return '';
200
+ }
201
+ return collaboratorsName.join(', ');
202
+ }
203
+ export function getColorFromSingleSelectColumn(column, name) {
204
+ let {
205
+ type: columnType,
206
+ data: columnData
207
+ } = column;
208
+ if (columnType === CellType.SINGLE_SELECT) {
209
+ let options = columnData ? columnData.options : [];
210
+ let selectedOption = options.find(o => {
211
+ let id = name;
212
+ if (Array.isArray(name)) {
213
+ id = name[0];
214
+ }
215
+ return o.id === id;
216
+ });
217
+ let {
218
+ color
219
+ } = selectedOption || {};
220
+ if (selectedOption) {
221
+ return color;
222
+ }
223
+ }
224
+ }
225
+ export function getFormattedLabel(column, name, collaborators) {
226
+ let {
227
+ type: columnType,
228
+ data: columnData
229
+ } = column;
230
+ if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
231
+ let options = columnData ? columnData.options : [];
232
+ let selectedOption = options.find(o => {
233
+ let id = name;
234
+ if (Array.isArray(name)) {
235
+ id = name[0];
236
+ }
237
+ return o.id === id;
238
+ });
239
+ let {
240
+ name: optionName
241
+ } = selectedOption || {};
242
+ if (selectedOption) {
243
+ return optionName;
244
+ }
245
+ } else if (columnType === CellType.COLLABORATOR) {
246
+ let collaborator = collaborators.find(item => {
247
+ let email = name;
248
+ if (Array.isArray(name)) {
249
+ email = name[0];
250
+ }
251
+ return item.email === email;
252
+ });
253
+ if (collaborator) {
254
+ return collaborator.name;
255
+ }
256
+ } else if (columnType === CellType.CREATOR || columnType === CellType.LAST_MODIFIER) {
257
+ if (name === 'anonymous') {
258
+ return name;
259
+ } else {
260
+ let collaborator = collaborators.find(item => item.email === name);
261
+ if (collaborator) {
262
+ return collaborator.name;
263
+ }
264
+ }
265
+ } else if (columnType === CellType.LINK) {
266
+ return getClientFormulaDisplayString([name], columnData, {
267
+ collaborators
268
+ });
269
+ } else if (columnType === CellType.CHECKBOX) {
270
+ // return name == 'true' ? intl.get('Checked') : intl.get('Unchecked');
271
+ return name === 'true' ? 'Checked' : 'Unchecked';
272
+ } else if (FORMULA_COLUMN_TYPES.includes(columnType)) {
273
+ let {
274
+ result_type
275
+ } = columnData || {};
276
+ if (!name && !isNumber(name)) return '';
277
+ if (result_type === 'number') {
278
+ let valueNumber = parseFloat(name);
279
+ return isNumber(valueNumber) ? getNumberDisplayString(valueNumber, column.data) : name;
280
+ }
281
+ }
282
+ if (!name) {
283
+ return '';
284
+ }
285
+ return name;
286
+ }
287
+ export function getLabelFontSize(statItem) {
288
+ const {
289
+ label_font_size
290
+ } = statItem;
291
+ return isNumber(label_font_size) ? label_font_size : DEFAULT_LABEL_FONT_SIZE;
292
+ }
293
+ export function getInitLabelFontSize(chart) {
294
+ const {
295
+ type,
296
+ label_font_size
297
+ } = chart;
298
+ if (type === STAT_TYPE.BASIC_NUMBER_CARD || type === STAT_TYPE.TREND_CHART) {
299
+ return isNumber(label_font_size) ? label_font_size : 4;
300
+ }
301
+ return getLabelFontSize(chart);
302
+ }
303
+ export function getInitYAxisSummaryMethod(y_axis_summary_method, type) {
304
+ if (Y_AXIS_SUPPORT_ROW_COUNT_CHARTS.includes(type)) {
305
+ return y_axis_summary_method || STATISTICS_COUNT_TYPE.ROW_COUNT;
306
+ }
307
+ if (y_axis_summary_method === STATISTICS_COUNT_TYPE.ROW_COUNT) {
308
+ return STATISTICS_COUNT_TYPE.MAX;
309
+ }
310
+ return y_axis_summary_method;
311
+ }
312
+ export function getChartDisplayLabels(containerWidth, minItemWidth, statistics) {
313
+ let labels = [];
314
+ let labelCount = Math.floor(containerWidth / minItemWidth);
315
+ labelCount = labelCount % 2 ? labelCount + 1 : labelCount;
316
+ let avg = Math.round(statistics.length / labelCount);
317
+ avg = avg > 2 ? avg : 2;
318
+ Array.isArray(statistics) && statistics.forEach((v, i) => {
319
+ if (i % avg === 0) {
320
+ labels.push(v.name);
321
+ }
322
+ });
323
+ return labels;
324
+ }
325
+ export function updateChartRows(results, index, name, row) {
326
+ let updatedResult;
327
+ if (index > -1) {
328
+ updatedResult = results[index];
329
+ updatedResult.rows.push(row);
330
+ results[index] = updatedResult;
331
+ } else {
332
+ updatedResult = {
333
+ name,
334
+ rows: [row]
335
+ };
336
+ results.push(updatedResult);
337
+ }
338
+ }
339
+ export function updateChartValue(summary_column_key, summary_column_type, summary_type, summary_method) {
340
+ let results = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
341
+ summary_type = summary_type || 'count';
342
+ Array.isArray(results) && results.forEach((item, index) => {
343
+ const {
344
+ rows
345
+ } = item;
346
+ let updated = _objectSpread({}, item);
347
+ updated.value = getTotal(summary_column_key, summary_column_type, summary_type, summary_method, rows);
348
+ results[index] = updated;
349
+ });
350
+ }
351
+ export function sortStatistics(statistics, column, sort_key) {
352
+ let {
353
+ type: column_type,
354
+ data
355
+ } = column;
356
+ let sortType = 'up';
357
+ let option_id_index_map = {};
358
+ if (column_type === CellType.SINGLE_SELECT) {
359
+ const {
360
+ options
361
+ } = data || {};
362
+ Array.isArray(options) && options.forEach((option, index) => {
363
+ option_id_index_map[option.id] = index;
364
+ });
365
+ }
366
+ statistics.sort((currResult, nextResult) => {
367
+ let {
368
+ [sort_key]: current
369
+ } = currResult;
370
+ let {
371
+ [sort_key]: next
372
+ } = nextResult;
373
+ if (!current && current !== 0) {
374
+ return -1;
375
+ }
376
+ if (!next && next !== 0) {
377
+ return 1;
378
+ }
379
+ if (SUPPORT_SORT_COLUMNS.includes(column_type)) {
380
+ switch (column_type) {
381
+ case CellType.NUMBER:
382
+ {
383
+ if (current) {
384
+ current = current - 0;
385
+ }
386
+ if (next) {
387
+ next = next - 0;
388
+ }
389
+ return sortNumber(current, next, sortType);
390
+ }
391
+ case CellType.DATE:
392
+ case CellType.CTIME:
393
+ case CellType.MTIME:
394
+ {
395
+ return sortDate(current, next, sortType);
396
+ }
397
+ case CellType.SINGLE_SELECT:
398
+ case CellType.MULTIPLE_SELECT:
399
+ {
400
+ return sortSingleSelect(current, next, {
401
+ sort_type: sortType,
402
+ option_id_index_map
403
+ });
404
+ }
405
+ case CellType.FORMULA:
406
+ case CellType.LINK_FORMULA:
407
+ {
408
+ let {
409
+ result_type
410
+ } = data || {};
411
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
412
+ if (current) {
413
+ current = current - 0;
414
+ }
415
+ if (next) {
416
+ next = next - 0;
417
+ }
418
+ return sortNumber(current, next, sortType);
419
+ }
420
+ return sortText(current, next, sortType);
421
+ }
422
+ default:
423
+ {
424
+ return sortText(current, next, sortType);
425
+ }
426
+ }
427
+ }
428
+ return 0;
429
+ });
430
+ }
@@ -0,0 +1,144 @@
1
+ import { CellType, FORMULA_RESULT_TYPE, getNumberDisplayString } from 'dtable-utils';
2
+ import { DATE_COLUMN_TYPES, FORMULA_COLUMN_TYPES, MULTIPLE_CELL_VALUE_COLUMN_TYPES, NAME_FIELD_COLUMN_TYPES } from '../../constants/special-column-types';
3
+ const MIRROR_COLUMN_LIST = [CellType.TEXT, CellType.NUMBER, CellType.CTIME, CellType.MTIME, CellType.DATE, CellType.COLLABORATOR, CellType.AUTO_NUMBER, CellType.FORMULA, CellType.GEOLOCATION, CellType.URL, CellType.SINGLE_SELECT, CellType.LINK, CellType.CREATOR, CellType.LAST_MODIFIER, CellType.DURATION, CellType.EMAIL];
4
+ class DtableUtils {
5
+ static isArrayCellValue(columnType) {
6
+ return MULTIPLE_CELL_VALUE_COLUMN_TYPES.includes(columnType);
7
+ }
8
+ }
9
+ DtableUtils.getTableById = (value, table_id) => {
10
+ const tables = value.tables;
11
+ return tables.find(table => table._id === table_id);
12
+ };
13
+ DtableUtils.getViewById = (table, view_id) => {
14
+ const views = table.views;
15
+ return views.find(view => view._id === view_id);
16
+ };
17
+ DtableUtils.getColumnByKey = (table, columnKey) => {
18
+ const columns = table.columns;
19
+ return columns.find(column => column.key === columnKey);
20
+ };
21
+ DtableUtils.isNumericColumn = column => {
22
+ const {
23
+ type,
24
+ data
25
+ } = column;
26
+ if (type === CellType.NUMBER) {
27
+ return true;
28
+ }
29
+ if (FORMULA_COLUMN_TYPES.includes(type)) {
30
+ const {
31
+ result_type,
32
+ array_type
33
+ } = data || {};
34
+ return result_type === FORMULA_RESULT_TYPE.NUMBER || result_type === FORMULA_RESULT_TYPE.ARRAY && array_type === CellType.NUMBER;
35
+ }
36
+ return false;
37
+ };
38
+ DtableUtils.getCellValue = (row, formulaRow, column) => {
39
+ const {
40
+ type,
41
+ key
42
+ } = column;
43
+ if (FORMULA_COLUMN_TYPES.includes(type)) {
44
+ const cellValue = formulaRow && formulaRow[key];
45
+ if (Array.isArray(cellValue)) {
46
+ return cellValue[0];
47
+ }
48
+ return cellValue;
49
+ }
50
+ return row[key];
51
+ };
52
+ DtableUtils.isDateColumn = column => {
53
+ if (!column) return false;
54
+ const {
55
+ type,
56
+ data = {}
57
+ } = column;
58
+ return DATE_COLUMN_TYPES.includes(type) || FORMULA_COLUMN_TYPES.includes(type) && data.result_type && data.result_type === FORMULA_RESULT_TYPE.DATE;
59
+ };
60
+ DtableUtils.isTextColumn = column => {
61
+ if (!column) return false;
62
+ const {
63
+ type
64
+ } = column;
65
+ return NAME_FIELD_COLUMN_TYPES.includes(type);
66
+ };
67
+ DtableUtils.isMapColumn = column => {
68
+ if (!column) return false;
69
+ const {
70
+ type,
71
+ data
72
+ } = column;
73
+ if (type === CellType.GEOLOCATION) {
74
+ const {
75
+ geo_format
76
+ } = data || {};
77
+ if (geo_format === 'lng_lat' || geo_format === 'country_region') {
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+ if (FORMULA_COLUMN_TYPES.includes(type)) {
83
+ const {
84
+ result_type,
85
+ array_type,
86
+ array_data
87
+ } = data || {};
88
+ if (result_type !== FORMULA_RESULT_TYPE.ARRAY || array_type !== CellType.GEOLOCATION) {
89
+ return false;
90
+ }
91
+ const {
92
+ geo_format
93
+ } = array_data || {};
94
+ if (geo_format === 'lng_lat' || geo_format === 'country_region') {
95
+ return false;
96
+ }
97
+ return true;
98
+ }
99
+ return false;
100
+ };
101
+ DtableUtils.isWorldMapColumn = column => {
102
+ if (!column) return false;
103
+ const {
104
+ type,
105
+ data
106
+ } = column;
107
+ if (type === CellType.TEXT) return true;
108
+ if (type === CellType.GEOLOCATION) {
109
+ const {
110
+ geo_format
111
+ } = data || {};
112
+ if (geo_format === 'country_region') {
113
+ return true;
114
+ }
115
+ }
116
+ if (FORMULA_COLUMN_TYPES.includes(type)) {
117
+ const {
118
+ data
119
+ } = column;
120
+ const {
121
+ result_type,
122
+ array_type,
123
+ array_data
124
+ } = data || {};
125
+ if (result_type !== FORMULA_RESULT_TYPE.ARRAY || array_type !== CellType.GEOLOCATION) {
126
+ return false;
127
+ }
128
+ const {
129
+ geo_format
130
+ } = array_data || {};
131
+ if (geo_format === 'country_region') {
132
+ return true;
133
+ }
134
+ }
135
+ return false;
136
+ };
137
+ DtableUtils.isMirrorColumn = column => {
138
+ if (!column) return false;
139
+ return MIRROR_COLUMN_LIST.includes(column.type);
140
+ };
141
+ DtableUtils.getNumberDisplayString = (value, columnData) => {
142
+ return getNumberDisplayString(value, columnData);
143
+ };
144
+ export default DtableUtils;
@@ -0,0 +1,83 @@
1
+ import DtableUtils from './common-utils/dtable-utils';
2
+ import { isValidRow, sortStatisticData, sortStatistics, updateChartRows, updateChartValue } from '../chart-utils/common-utils/base-utils';
3
+ import { DATE_COLUMN_TYPES, GEOLOCATION_COLUMN_OPTIONS } from '../constants/special-column-types';
4
+ import { DATA_SORT_TYPE } from '../constants';
5
+ export const calculateStat = (statItem, metaData, rows) => {
6
+ let {
7
+ // table_id,
8
+ // view_id: viewId,
9
+ x_axis_column_key: groupbyColumnKey,
10
+ x_axis_date_granularity: groupbyDateGranularity,
11
+ x_axis_geolocation_granularity: groupbyGeolocationGranularity,
12
+ x_axis_include_empty: includeEmpty,
13
+ y_axis_summary_type: summaryType,
14
+ y_axis_column_key: summaryColumnKey,
15
+ y_axis_summary_method: summaryMethod,
16
+ sort_type: sortType
17
+ } = statItem;
18
+ if (!metaData) return;
19
+ if (!rows) return;
20
+ if (!groupbyColumnKey) return;
21
+ const groupbyColumn = metaData.find(item => item.key === groupbyColumnKey);
22
+ if (!groupbyColumn) return;
23
+ const {
24
+ type: groupbyColumnType
25
+ } = groupbyColumn;
26
+ if (DATE_COLUMN_TYPES.includes(groupbyColumnType) && !groupbyDateGranularity) {
27
+ groupbyDateGranularity = 'month';
28
+ }
29
+ if (GEOLOCATION_COLUMN_OPTIONS.includes(groupbyColumnType) && !groupbyGeolocationGranularity) {
30
+ groupbyGeolocationGranularity = 'province';
31
+ }
32
+ const statRows = rows;
33
+ const isColumnDataAsAnArray = DtableUtils.isArrayCellValue(groupbyColumn.type);
34
+
35
+ // 1. group by stat data by groupby column
36
+ let results = []; // results = [{name: '', rows: [], value: ''}]
37
+ statRows.forEach(row => {
38
+ if (isValidRow(row, groupbyColumn, includeEmpty)) {
39
+ const name = row[groupbyColumn['id']];
40
+ if (isColumnDataAsAnArray) {
41
+ if (name.length === 0 && includeEmpty) {
42
+ const nameIndex = results.findIndex(r => r.name === name);
43
+ updateChartRows(results, nameIndex, null, row);
44
+ } else {
45
+ name.forEach(name => {
46
+ const nameIndex = results.findIndex(r => r.name === name);
47
+ updateChartRows(results, nameIndex, name, row);
48
+ });
49
+ }
50
+ } else {
51
+ const nameIndex = results.findIndex(r => r.name === name);
52
+ updateChartRows(results, nameIndex, name, row);
53
+ }
54
+ }
55
+ });
56
+
57
+ // 2. reconcile stat data by summary_type
58
+ const summaryColumn = metaData.find(item => item.key === groupbyColumnKey);
59
+ const {
60
+ type: summaryColumnType
61
+ } = summaryColumn || {};
62
+ const summarYaxisColumn = metaData.find(item => item.key === summaryColumnKey);
63
+ if (summarYaxisColumn) {
64
+ summaryColumnKey = summarYaxisColumn['name'];
65
+ }
66
+ updateChartValue(summaryColumnKey, summaryColumnType, summaryType, summaryMethod, results);
67
+ let newSortType = sortType;
68
+ if (newSortType === DATA_SORT_TYPE.ASCENDING) {
69
+ newSortType = DATA_SORT_TYPE.DESCENDING;
70
+ } else if (newSortType === DATA_SORT_TYPE.DESCENDING) {
71
+ newSortType = DATA_SORT_TYPE.ASCENDING;
72
+ }
73
+
74
+ // 3. sort stat data
75
+ if (sortType) {
76
+ // sort statistic value
77
+ sortStatisticData(results, sortType);
78
+ } else {
79
+ // sort statistic label
80
+ sortStatistics(results, groupbyColumn, 'name');
81
+ }
82
+ return results;
83
+ };
@@ -0,0 +1,9 @@
1
+ export const DATE_GRANULARITY = {
2
+ DAY: 'day',
3
+ WEEK: 'week',
4
+ MONTH: 'month',
5
+ QUARTER: 'quarter',
6
+ YEAR: 'year'
7
+ };
8
+ export const DATE_GRANULARITIES = [DATE_GRANULARITY.DAY, DATE_GRANULARITY.WEEK, DATE_GRANULARITY.MONTH, DATE_GRANULARITY.QUARTER, DATE_GRANULARITY.YEAR];
9
+ export const DEFAULT_DATE_GRANULARITY = DATE_GRANULARITY.MONTH;
@@ -0,0 +1,11 @@
1
+ export const GEOLOCATION_GRANULARITY = {
2
+ PROVINCE: 'province',
3
+ CITY: 'city',
4
+ DISTRICT: 'district'
5
+ };
6
+ export const GEOLOCATION_GRANULARITIES = [GEOLOCATION_GRANULARITY.PROVINCE, GEOLOCATION_GRANULARITY.CITY, GEOLOCATION_GRANULARITY.DISTRICT];
7
+ export const DEFAULT_GEOLOCATION_GRANULARITY_MAP = {
8
+ PROVINCE: 'province',
9
+ PROVINCE_CITY: 'province_city',
10
+ GEOLOCATION: 'geolocation'
11
+ };