@nocobase/plugin-data-visualization 0.10.1-alpha.1

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 (108) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +88 -0
  3. package/client.d.ts +3 -0
  4. package/client.js +65 -0
  5. package/lib/client/Settings.d.ts +2 -0
  6. package/lib/client/Settings.js +81 -0
  7. package/lib/client/block/ChartBlock.d.ts +2 -0
  8. package/lib/client/block/ChartBlock.js +73 -0
  9. package/lib/client/block/ChartBlockDesigner.d.ts +2 -0
  10. package/lib/client/block/ChartBlockDesigner.js +35 -0
  11. package/lib/client/block/ChartBlockInitializer.d.ts +6 -0
  12. package/lib/client/block/ChartBlockInitializer.js +114 -0
  13. package/lib/client/block/ChartConfigure.d.ts +33 -0
  14. package/lib/client/block/ChartConfigure.js +501 -0
  15. package/lib/client/block/formatters.d.ts +15 -0
  16. package/lib/client/block/formatters.js +58 -0
  17. package/lib/client/block/index.d.ts +4 -0
  18. package/lib/client/block/index.js +49 -0
  19. package/lib/client/block/schemas/configure.d.ts +4 -0
  20. package/lib/client/block/schemas/configure.js +492 -0
  21. package/lib/client/block/transformers.d.ts +6 -0
  22. package/lib/client/block/transformers.js +69 -0
  23. package/lib/client/hooks.d.ts +312 -0
  24. package/lib/client/hooks.js +275 -0
  25. package/lib/client/index.d.ts +5 -0
  26. package/lib/client/index.js +70 -0
  27. package/lib/client/locale/en-US.d.ts +23 -0
  28. package/lib/client/locale/en-US.js +29 -0
  29. package/lib/client/locale/index.d.ts +3 -0
  30. package/lib/client/locale/index.js +39 -0
  31. package/lib/client/locale/ja-JP.d.ts +2 -0
  32. package/lib/client/locale/ja-JP.js +8 -0
  33. package/lib/client/locale/pt-BR.d.ts +23 -0
  34. package/lib/client/locale/pt-BR.js +29 -0
  35. package/lib/client/locale/ru-RU.d.ts +2 -0
  36. package/lib/client/locale/ru-RU.js +8 -0
  37. package/lib/client/locale/tr-TR.d.ts +2 -0
  38. package/lib/client/locale/tr-TR.js +8 -0
  39. package/lib/client/locale/zh-CN.d.ts +70 -0
  40. package/lib/client/locale/zh-CN.js +76 -0
  41. package/lib/client/renderer/ChartLibrary.d.ts +71 -0
  42. package/lib/client/renderer/ChartLibrary.js +140 -0
  43. package/lib/client/renderer/ChartRenderer.d.ts +7 -0
  44. package/lib/client/renderer/ChartRenderer.js +258 -0
  45. package/lib/client/renderer/ChartRendererProvider.d.ts +43 -0
  46. package/lib/client/renderer/ChartRendererProvider.js +38 -0
  47. package/lib/client/renderer/index.d.ts +4 -0
  48. package/lib/client/renderer/index.js +49 -0
  49. package/lib/client/renderer/library/AntdLibrary.d.ts +2 -0
  50. package/lib/client/renderer/library/AntdLibrary.js +123 -0
  51. package/lib/client/renderer/library/G2PlotLibrary.d.ts +2 -0
  52. package/lib/client/renderer/library/G2PlotLibrary.js +288 -0
  53. package/lib/client/renderer/library/index.d.ts +3 -0
  54. package/lib/client/renderer/library/index.js +15 -0
  55. package/lib/client/utils.d.ts +96 -0
  56. package/lib/client/utils.js +137 -0
  57. package/lib/index.d.ts +1 -0
  58. package/lib/index.js +13 -0
  59. package/lib/server/actions/formatter.d.ts +3 -0
  60. package/lib/server/actions/formatter.js +44 -0
  61. package/lib/server/actions/query.d.ts +86 -0
  62. package/lib/server/actions/query.js +326 -0
  63. package/lib/server/index.d.ts +1 -0
  64. package/lib/server/index.js +13 -0
  65. package/lib/server/plugin.d.ts +13 -0
  66. package/lib/server/plugin.js +64 -0
  67. package/package.json +23 -0
  68. package/server.d.ts +3 -0
  69. package/server.js +65 -0
  70. package/src/client/Settings.tsx +43 -0
  71. package/src/client/__tests__/chart-configure.test.tsx +14 -0
  72. package/src/client/__tests__/chart-library.test.ts +78 -0
  73. package/src/client/__tests__/chart-renderer.test.tsx +30 -0
  74. package/src/client/__tests__/hooks.test.ts +261 -0
  75. package/src/client/block/ChartBlock.tsx +22 -0
  76. package/src/client/block/ChartBlockDesigner.tsx +19 -0
  77. package/src/client/block/ChartBlockInitializer.tsx +83 -0
  78. package/src/client/block/ChartConfigure.tsx +450 -0
  79. package/src/client/block/formatters.ts +70 -0
  80. package/src/client/block/index.ts +4 -0
  81. package/src/client/block/schemas/configure.ts +474 -0
  82. package/src/client/block/transformers.ts +52 -0
  83. package/src/client/hooks.ts +239 -0
  84. package/src/client/index.tsx +41 -0
  85. package/src/client/locale/en-US.ts +23 -0
  86. package/src/client/locale/index.ts +19 -0
  87. package/src/client/locale/ja-JP.ts +1 -0
  88. package/src/client/locale/pt-BR.ts +23 -0
  89. package/src/client/locale/ru-RU.ts +1 -0
  90. package/src/client/locale/tr-TR.ts +1 -0
  91. package/src/client/locale/zh-CN.ts +71 -0
  92. package/src/client/renderer/ChartLibrary.tsx +178 -0
  93. package/src/client/renderer/ChartRenderer.tsx +201 -0
  94. package/src/client/renderer/ChartRendererProvider.tsx +58 -0
  95. package/src/client/renderer/index.ts +4 -0
  96. package/src/client/renderer/library/AntdLibrary.tsx +94 -0
  97. package/src/client/renderer/library/G2PlotLibrary.tsx +236 -0
  98. package/src/client/renderer/library/index.tsx +4 -0
  99. package/src/client/utils.ts +102 -0
  100. package/src/index.ts +1 -0
  101. package/src/server/__tests__/api.test.ts +105 -0
  102. package/src/server/__tests__/formatter.test.ts +49 -0
  103. package/src/server/__tests__/query.test.ts +220 -0
  104. package/src/server/actions/formatter.ts +49 -0
  105. package/src/server/actions/query.ts +285 -0
  106. package/src/server/collections/.gitkeep +0 -0
  107. package/src/server/index.ts +1 -0
  108. package/src/server/plugin.ts +37 -0
@@ -0,0 +1,474 @@
1
+ import { ISchema } from '@formily/react';
2
+ import { uid } from '@formily/shared';
3
+ import { lang } from '../../locale';
4
+
5
+ const getArraySchema = (fields = {}, extra = {}) => ({
6
+ type: 'array',
7
+ 'x-decorator': 'FormItem',
8
+ 'x-component': 'ArrayItems',
9
+ ...extra,
10
+ items: {
11
+ type: 'object',
12
+ properties: {
13
+ space: {
14
+ type: 'void',
15
+ 'x-component': 'Space',
16
+ properties: {
17
+ sort: {
18
+ type: 'void',
19
+ 'x-decorator': 'FormItem',
20
+ 'x-component': 'ArrayItems.SortHandle',
21
+ },
22
+ ...fields,
23
+ remove: {
24
+ type: 'void',
25
+ 'x-decorator': 'FormItem',
26
+ 'x-component': 'ArrayItems.Remove',
27
+ },
28
+ },
29
+ },
30
+ },
31
+ },
32
+ properties: {
33
+ add: {
34
+ type: 'void',
35
+ title: '{{t("Add field")}}',
36
+ 'x-component': 'ArrayItems.Addition',
37
+ },
38
+ },
39
+ });
40
+
41
+ export const getConfigSchema = (general: any): ISchema => ({
42
+ type: 'void',
43
+ properties: {
44
+ config: {
45
+ type: 'object',
46
+ properties: {
47
+ chartType: {
48
+ type: 'string',
49
+ title: '{{t("Chart type")}}',
50
+ 'x-decorator': 'FormItem',
51
+ 'x-component': 'Select',
52
+ 'x-component-props': {
53
+ placeholder: '{{t("Please select a chart type.")}}',
54
+ },
55
+ enum: '{{ chartTypes }}',
56
+ },
57
+ [uid()]: {
58
+ type: 'void',
59
+ properties: {
60
+ general,
61
+ },
62
+ },
63
+ [uid()]: {
64
+ type: 'void',
65
+ properties: {
66
+ advanced: {
67
+ type: 'json',
68
+ title: '{{t("JSON config")}}',
69
+ 'x-decorator': 'FormItem',
70
+ 'x-decorator-props': {
71
+ extra: lang('Same properties set in the form above will be overwritten by this JSON config.'),
72
+ },
73
+ 'x-component': 'Input.JSON',
74
+ 'x-component-props': {
75
+ autoSize: {
76
+ minRows: 3,
77
+ },
78
+ },
79
+ },
80
+ },
81
+ },
82
+ reference: {
83
+ type: 'string',
84
+ 'x-reactions': {
85
+ dependencies: ['.chartType'],
86
+ fulfill: {
87
+ schema: {
88
+ 'x-content': '{{ getReference($deps[0]) }}',
89
+ },
90
+ },
91
+ },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ });
97
+
98
+ export const querySchema: ISchema = {
99
+ type: 'void',
100
+ properties: {
101
+ settings: {
102
+ type: 'void',
103
+ // 'x-component': 'FormItem',
104
+ properties: {
105
+ // mode: {
106
+ // type: 'string',
107
+ // 'x-decorator': 'FormItem',
108
+ // 'x-decorator-props': {
109
+ // style: {
110
+ // display: 'inline-block',
111
+ // width: '45%',
112
+ // },
113
+ // },
114
+ // 'x-component': 'Radio.Group',
115
+ // 'x-component-props': {
116
+ // defaultValue: 'builder',
117
+ // optionType: 'button',
118
+ // buttonStyle: 'solid',
119
+ // },
120
+ // enum: [
121
+ // {
122
+ // label: lang('Builder mode'),
123
+ // value: 'builder',
124
+ // },
125
+ // {
126
+ // label: lang('SQL mode'),
127
+ // value: 'sql',
128
+ // },
129
+ // ],
130
+ // 'x-reactions': [
131
+ // {
132
+ // target: 'query.builder',
133
+ // fulfill: {
134
+ // state: {
135
+ // visible: '{{ $self.value !== "sql" }}',
136
+ // },
137
+ // },
138
+ // },
139
+ // {
140
+ // target: 'query.sql',
141
+ // fulfill: {
142
+ // state: {
143
+ // visible: '{{ $self.value === "sql" }}',
144
+ // },
145
+ // },
146
+ // },
147
+ // ],
148
+ // },
149
+ collection: {
150
+ title: '{{t("Collection")}}',
151
+ type: 'string',
152
+ 'x-decorator': 'FormItem',
153
+ 'x-component': 'Select',
154
+ 'x-component-props': {
155
+ options: '{{ collectionOptions }}',
156
+ onChange: '{{ onCollectionChange }}',
157
+ placeholder: lang('Collection'),
158
+ },
159
+ },
160
+ },
161
+ },
162
+ query: {
163
+ type: 'object',
164
+ properties: {
165
+ builder: {
166
+ type: 'void',
167
+ properties: {
168
+ collapse: {
169
+ type: 'void',
170
+ 'x-decorator': 'FormItem',
171
+ 'x-component': 'FormCollapse',
172
+ 'x-component-props': {
173
+ formCollapse: '{{formCollapse}}',
174
+ },
175
+ properties: {
176
+ pane1: {
177
+ type: 'void',
178
+ 'x-component': 'FormCollapse.CollapsePanel',
179
+ 'x-component-props': {
180
+ header: lang('Measures'),
181
+ key: 'measures',
182
+ },
183
+ properties: {
184
+ measures: getArraySchema(
185
+ {
186
+ field: {
187
+ type: 'string',
188
+ 'x-decorator': 'FormItem',
189
+ 'x-component': 'Cascader',
190
+ 'x-component-props': {
191
+ placeholder: '{{t("Field")}}',
192
+ fieldNames: {
193
+ label: 'title',
194
+ value: 'name',
195
+ children: 'children',
196
+ },
197
+ },
198
+ enum: '{{ fieldOptions }}',
199
+ required: true,
200
+ },
201
+ aggregation: {
202
+ type: 'string',
203
+ 'x-decorator': 'FormItem',
204
+ 'x-component': 'Select',
205
+ 'x-component-props': {
206
+ placeholder: '{{t("Aggregation")}}',
207
+ },
208
+ enum: [
209
+ { label: lang('Sum'), value: 'sum' },
210
+ { label: lang('Count'), value: 'count' },
211
+ { label: lang('Avg'), value: 'avg' },
212
+ { label: lang('Max'), value: 'max' },
213
+ { label: lang('Min'), value: 'min' },
214
+ ],
215
+ },
216
+ alias: {
217
+ type: 'string',
218
+ 'x-decorator': 'FormItem',
219
+ 'x-component': 'Input',
220
+ 'x-component-props': {
221
+ placeholder: '{{t("Alias")}}',
222
+ },
223
+ },
224
+ },
225
+ { required: true },
226
+ ),
227
+ },
228
+ },
229
+ pane2: {
230
+ type: 'void',
231
+ 'x-component': 'FormCollapse.CollapsePanel',
232
+ 'x-component-props': {
233
+ header: lang('Dimensions'),
234
+ key: 'dimensions',
235
+ },
236
+ properties: {
237
+ dimensions: getArraySchema({
238
+ field: {
239
+ type: 'string',
240
+ 'x-decorator': 'FormItem',
241
+ 'x-component': 'Cascader',
242
+ 'x-component-props': {
243
+ placeholder: '{{t("Field")}}',
244
+ fieldNames: {
245
+ label: 'title',
246
+ value: 'name',
247
+ children: 'children',
248
+ },
249
+ },
250
+ enum: '{{ fieldOptions }}',
251
+ required: true,
252
+ },
253
+ format: {
254
+ type: 'string',
255
+ 'x-decorator': 'FormItem',
256
+ 'x-component': 'Select',
257
+ 'x-component-props': {
258
+ placeholder: '{{t("Format")}}',
259
+ style: {
260
+ maxWidth: '120px',
261
+ },
262
+ },
263
+ 'x-reactions': '{{ useFormatterOptions }}',
264
+ 'x-visible': '{{ $self.dataSource && $self.dataSource.length }}',
265
+ },
266
+ alias: {
267
+ type: 'string',
268
+ 'x-decorator': 'FormItem',
269
+ 'x-component': 'Input',
270
+ 'x-component-props': {
271
+ placeholder: '{{t("Alias")}}',
272
+ },
273
+ },
274
+ }),
275
+ },
276
+ },
277
+ pane3: {
278
+ type: 'void',
279
+ 'x-component': 'FormCollapse.CollapsePanel',
280
+ 'x-component-props': {
281
+ header: lang('Filter'),
282
+ key: 'filter',
283
+ },
284
+ properties: {
285
+ filter: {
286
+ type: 'object',
287
+ 'x-decorator': 'FormItem',
288
+ 'x-decorator-props': {
289
+ style: {
290
+ overflow: 'scroll',
291
+ },
292
+ },
293
+ 'x-component': 'Filter',
294
+ 'x-component-props': {
295
+ options: '{{ filterOptions }}',
296
+ // dynamicComponent: 'Input',
297
+ },
298
+ },
299
+ },
300
+ },
301
+ pane4: {
302
+ type: 'void',
303
+ 'x-component': 'FormCollapse.CollapsePanel',
304
+ 'x-component-props': {
305
+ header: lang('Sort'),
306
+ key: 'sort',
307
+ },
308
+ properties: {
309
+ orders: getArraySchema(
310
+ {
311
+ field: {
312
+ type: 'string',
313
+ 'x-decorator': 'FormItem',
314
+ 'x-component': 'Cascader',
315
+ 'x-component-props': {
316
+ placeholder: '{{t("Field")}}',
317
+ },
318
+ 'x-reactions': '{{ useOrderOptions }}',
319
+ required: true,
320
+ },
321
+ order: {
322
+ type: 'string',
323
+ 'x-decorator': 'FormItem',
324
+ 'x-component': 'Radio.Group',
325
+ 'x-component-props': {
326
+ defaultValue: 'ASC',
327
+ optionType: 'button',
328
+ },
329
+ enum: ['ASC', 'DESC'],
330
+ },
331
+ },
332
+ {
333
+ 'x-reactions': '{{ useOrderReaction }}',
334
+ },
335
+ ),
336
+ },
337
+ },
338
+ },
339
+ },
340
+ limit: {
341
+ title: '{{t("Limit")}}',
342
+ type: 'number',
343
+ 'x-decorator': 'FormItem',
344
+ 'x-component': 'InputNumber',
345
+ 'x-component-props': {
346
+ defaultValue: 2000,
347
+ max: 2000,
348
+ min: 1,
349
+ style: {
350
+ width: '100px',
351
+ },
352
+ },
353
+ },
354
+ },
355
+ },
356
+ // sql: {
357
+ // type: 'object',
358
+ // properties: {
359
+ // select: {
360
+ // type: 'void',
361
+ // 'x-decorator': 'p',
362
+ // 'x-component': 'Text',
363
+ // 'x-component-props': {
364
+ // code: true,
365
+ // },
366
+ // 'x-content': 'SELECT',
367
+ // },
368
+ // fields: {
369
+ // type: 'string',
370
+ // 'x-decorator': 'FormItem',
371
+ // 'x-component': 'Input.TextArea',
372
+ // 'x-component-props': {
373
+ // autoSize: {
374
+ // minRows: 2,
375
+ // },
376
+ // placeholder: 'Fields',
377
+ // },
378
+ // required: true,
379
+ // },
380
+ // from: {
381
+ // type: 'void',
382
+ // 'x-decorator': 'p',
383
+ // 'x-component': 'FromSql',
384
+ // },
385
+ // clauses: {
386
+ // type: 'string',
387
+ // 'x-decorator': 'FormItem',
388
+ // 'x-component': 'Input.TextArea',
389
+ // 'x-component-props': {
390
+ // autoSize: {
391
+ // minRows: 5,
392
+ // },
393
+ // placeholder: 'Join, Where, Group By, Having, Order By, Limit',
394
+ // },
395
+ // required: true,
396
+ // },
397
+ // },
398
+ // },
399
+ cache: {
400
+ type: 'object',
401
+ properties: {
402
+ enabled: {
403
+ type: 'boolean',
404
+ title: '{{t("Enable cache")}}',
405
+ 'x-decorator': 'FormItem',
406
+ 'x-component': 'Switch',
407
+ },
408
+ ttl: {
409
+ type: 'number',
410
+ title: '{{t("TTL (second)")}}',
411
+ 'x-decorator': 'FormItem',
412
+ 'x-component': 'InputNumber',
413
+ 'x-component-props': {
414
+ defaultValue: 60,
415
+ min: 1,
416
+ style: {
417
+ width: '100px',
418
+ },
419
+ },
420
+ },
421
+ },
422
+ },
423
+ },
424
+ },
425
+ },
426
+ };
427
+
428
+ export const transformSchema: ISchema = {
429
+ type: 'void',
430
+ properties: {
431
+ transform: getArraySchema(
432
+ {
433
+ field: {
434
+ type: 'string',
435
+ 'x-decorator': 'FormItem',
436
+ 'x-component': 'Select',
437
+ 'x-component-props': {
438
+ placeholder: '{{t("Field")}}',
439
+ style: {
440
+ maxWidth: '100px',
441
+ },
442
+ },
443
+ 'x-reactions': '{{ useChartFields }}',
444
+ },
445
+ type: {
446
+ type: 'string',
447
+ 'x-decorator': 'FormItem',
448
+ 'x-component': 'Select',
449
+ 'x-component-props': {
450
+ placeholder: '{{t("Type")}}',
451
+ },
452
+ 'x-reactions': '{{ useFieldTypeOptions }}',
453
+ },
454
+ format: {
455
+ type: 'string',
456
+ 'x-decorator': 'FormItem',
457
+ 'x-component': 'Select',
458
+ 'x-component-props': {
459
+ placeholder: '{{t("Format")}}',
460
+ },
461
+ 'x-reactions': '{{ useTransformers }}',
462
+ 'x-visible': '{{ $self.dataSource && $self.dataSource.length }}',
463
+ },
464
+ },
465
+ {
466
+ 'x-decorator-props': {
467
+ style: {
468
+ width: '50%',
469
+ },
470
+ },
471
+ },
472
+ ),
473
+ },
474
+ };
@@ -0,0 +1,52 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ const transformers: {
4
+ [key: string]: {
5
+ [key: string]: (val: any, locale?: string) => string | number;
6
+ };
7
+ } = {
8
+ datetime: {
9
+ YYYY: (val: string) => dayjs(val).format('YYYY'),
10
+ MM: (val: string) => dayjs(val).format('MM'),
11
+ DD: (val: string) => dayjs(val).format('DD'),
12
+ 'YYYY-MM': (val: string) => dayjs(val).format('YYYY-MM'),
13
+ 'YYYY-MM-DD': (val: string) => dayjs(val).format('YYYY-MM-DD'),
14
+ 'YYYY-MM-DD hh:mm': (val: string) => dayjs(val).format('YYYY-MM-DD hh:mm'),
15
+ 'YYYY-MM-DD hh:mm:ss': (val: string) => dayjs(val).format('YYYY-MM-DD hh:mm:ss'),
16
+ },
17
+ date: {
18
+ YYYY: (val: string) => dayjs(val).format('YYYY'),
19
+ MM: (val: string) => dayjs(val).format('MM'),
20
+ DD: (val: string) => dayjs(val).format('DD'),
21
+ 'YYYY-MM': (val: string) => dayjs(val).format('YYYY-MM'),
22
+ 'YYYY-MM-DD': (val: string) => dayjs(val).format('YYYY-MM-DD'),
23
+ },
24
+ time: {
25
+ 'hh:mm:ss': (val: string) => dayjs(val).format('hh:mm:ss'),
26
+ 'hh:mm': (val: string) => dayjs(val).format('hh:mm'),
27
+ hh: (val: string) => dayjs(val).format('hh'),
28
+ },
29
+ number: {
30
+ Percent: (val: number) =>
31
+ new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
32
+ val,
33
+ ),
34
+ Currency: (val: number, locale = 'en-US') => {
35
+ const currency = {
36
+ 'zh-CN': 'CNY',
37
+ 'en-US': 'USD',
38
+ 'ja-JP': 'JPY',
39
+ 'ko-KR': 'KRW',
40
+ 'pt-BR': 'BRL',
41
+ 'ru-RU': 'RUB',
42
+ 'tr-TR': 'TRY',
43
+ 'es-ES': 'EUR',
44
+ }[locale];
45
+ return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
46
+ },
47
+ Exponential: (val: number | string) => (+val)?.toExponential(),
48
+ Abbreviation: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val),
49
+ },
50
+ };
51
+
52
+ export default transformers;