@nocobase/plugin-data-visualization 0.11.0-alpha.1 → 0.11.1-alpha.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 (32) hide show
  1. package/lib/client/block/ChartBlock.js +16 -15
  2. package/lib/client/block/ChartBlockInitializer.js +4 -4
  3. package/lib/client/block/ChartConfigure.d.ts +4 -5
  4. package/lib/client/block/ChartConfigure.js +109 -94
  5. package/lib/client/block/schemas/configure.js +7 -7
  6. package/lib/client/index.js +1 -1
  7. package/lib/client/locale/index.d.ts +2 -2
  8. package/lib/client/locale/index.js +3 -5
  9. package/lib/client/locale/zh-CN.d.ts +1 -0
  10. package/lib/client/locale/zh-CN.js +2 -1
  11. package/lib/client/renderer/ChartLibrary.d.ts +1 -0
  12. package/lib/client/renderer/ChartLibrary.js +8 -2
  13. package/lib/client/renderer/ChartRenderer.d.ts +1 -4
  14. package/lib/client/renderer/ChartRenderer.js +28 -103
  15. package/lib/client/renderer/ChartRendererProvider.d.ts +11 -1
  16. package/lib/client/renderer/ChartRendererProvider.js +62 -11
  17. package/lib/client/renderer/library/G2PlotLibrary.js +24 -25
  18. package/lib/server/actions/query.js +6 -1
  19. package/package.json +9 -9
  20. package/src/client/block/ChartBlock.tsx +5 -3
  21. package/src/client/block/ChartBlockInitializer.tsx +2 -3
  22. package/src/client/block/ChartConfigure.tsx +106 -85
  23. package/src/client/block/schemas/configure.ts +7 -7
  24. package/src/client/index.tsx +1 -1
  25. package/src/client/locale/index.ts +2 -3
  26. package/src/client/locale/zh-CN.ts +1 -0
  27. package/src/client/renderer/ChartLibrary.tsx +6 -1
  28. package/src/client/renderer/ChartRenderer.tsx +22 -90
  29. package/src/client/renderer/ChartRendererProvider.tsx +60 -7
  30. package/src/client/renderer/library/G2PlotLibrary.tsx +24 -25
  31. package/src/server/__tests__/api.test.ts +47 -50
  32. package/src/server/actions/query.ts +6 -1
@@ -1,5 +1,4 @@
1
1
  import { Area, Bar, Column, DualAxes, Line, Pie, Scatter } from '@ant-design/plots';
2
- import { lang } from '../../locale';
3
2
  import { Charts, commonInit, infer, usePropsFunc } from '../ChartLibrary';
4
3
  const init = commonInit;
5
4
 
@@ -7,7 +6,7 @@ const basicSchema = {
7
6
  type: 'object',
8
7
  properties: {
9
8
  xField: {
10
- title: lang('xField'),
9
+ title: '{{t("xField")}}',
11
10
  type: 'string',
12
11
  'x-decorator': 'FormItem',
13
12
  'x-component': 'Select',
@@ -15,7 +14,7 @@ const basicSchema = {
15
14
  required: true,
16
15
  },
17
16
  yField: {
18
- title: lang('yField'),
17
+ title: '{{t("yField")}}',
19
18
  type: 'string',
20
19
  'x-decorator': 'FormItem',
21
20
  'x-component': 'Select',
@@ -23,7 +22,7 @@ const basicSchema = {
23
22
  required: true,
24
23
  },
25
24
  seriesField: {
26
- title: lang('seriesField'),
25
+ title: '{{t("seriesField")}}',
27
26
  type: 'string',
28
27
  'x-decorator': 'FormItem',
29
28
  'x-component': 'Select',
@@ -50,40 +49,40 @@ const useProps: usePropsFunc = ({ data, fieldProps, general, advanced }) => {
50
49
 
51
50
  export const G2PlotLibrary: Charts = {
52
51
  line: {
53
- name: lang('Line Chart'),
52
+ name: 'Line Chart',
54
53
  component: Line,
55
54
  schema: basicSchema,
56
55
  init,
57
56
  useProps,
58
57
  reference: {
59
- title: lang('Line Chart'),
58
+ title: 'Line Chart',
60
59
  link: 'https://g2plot.antv.antgroup.com/api/plots/bar',
61
60
  },
62
61
  },
63
62
  area: {
64
- name: lang('Area Chart'),
63
+ name: 'Area Chart',
65
64
  component: Area,
66
65
  schema: basicSchema,
67
66
  init,
68
67
  useProps,
69
68
  reference: {
70
- title: lang('Area Chart'),
69
+ title: 'Area Chart',
71
70
  link: 'https://g2plot.antv.antgroup.com/api/plots/area',
72
71
  },
73
72
  },
74
73
  column: {
75
- name: lang('Column Chart'),
74
+ name: 'Column Chart',
76
75
  component: Column,
77
76
  schema: basicSchema,
78
77
  init,
79
78
  useProps,
80
79
  reference: {
81
- title: lang('Column Chart'),
80
+ title: 'Column Chart',
82
81
  link: 'https://g2plot.antv.antgroup.com/api/plots/column',
83
82
  },
84
83
  },
85
84
  bar: {
86
- name: lang('Bar Chart'),
85
+ name: 'Bar Chart',
87
86
  component: Bar,
88
87
  schema: basicSchema,
89
88
  init: (fields, { measures, dimensions }) => {
@@ -98,18 +97,18 @@ export const G2PlotLibrary: Charts = {
98
97
  },
99
98
  useProps,
100
99
  reference: {
101
- title: lang('Bar Chart'),
100
+ title: 'Bar Chart',
102
101
  link: 'https://g2plot.antv.antgroup.com/api/plots/bar',
103
102
  },
104
103
  },
105
104
  pie: {
106
- name: lang('Pie Chart'),
105
+ name: 'Pie Chart',
107
106
  component: Pie,
108
107
  schema: {
109
108
  type: 'object',
110
109
  properties: {
111
110
  angleField: {
112
- title: lang('angleField'),
111
+ title: '{{t("angleField")}}',
113
112
  type: 'string',
114
113
  'x-decorator': 'FormItem',
115
114
  'x-component': 'Select',
@@ -117,7 +116,7 @@ export const G2PlotLibrary: Charts = {
117
116
  required: true,
118
117
  },
119
118
  colorField: {
120
- title: lang('colorField'),
119
+ title: '{{t("colorField")}}',
121
120
  type: 'string',
122
121
  'x-decorator': 'FormItem',
123
122
  'x-component': 'Select',
@@ -137,12 +136,12 @@ export const G2PlotLibrary: Charts = {
137
136
  },
138
137
  useProps,
139
138
  reference: {
140
- title: lang('Pie Chart'),
139
+ title: 'Pie Chart',
141
140
  link: 'https://g2plot.antv.antgroup.com/api/plots/pie',
142
141
  },
143
142
  },
144
143
  dualAxes: {
145
- name: lang('Dual Axes Chart'),
144
+ name: 'Dual Axes Chart',
146
145
  component: DualAxes,
147
146
  useProps: ({ data, fieldProps, general, advanced }) => {
148
147
  return {
@@ -154,7 +153,7 @@ export const G2PlotLibrary: Charts = {
154
153
  type: 'object',
155
154
  properties: {
156
155
  xField: {
157
- title: lang('xField'),
156
+ title: '{{t("xField")}}',
158
157
  type: 'string',
159
158
  'x-decorator': 'FormItem',
160
159
  'x-component': 'Select',
@@ -162,7 +161,7 @@ export const G2PlotLibrary: Charts = {
162
161
  required: true,
163
162
  },
164
163
  yField: {
165
- title: lang('yField'),
164
+ title: '{{t("yField")}}',
166
165
  type: 'array',
167
166
  'x-decorator': 'FormItem',
168
167
  'x-component': 'ArrayItems',
@@ -182,7 +181,7 @@ export const G2PlotLibrary: Charts = {
182
181
  'x-reactions': '{{ useChartFields }}',
183
182
  'x-component-props': {
184
183
  style: {
185
- 'min-width': '200px',
184
+ minWidth: '200px',
186
185
  },
187
186
  },
188
187
  required: true,
@@ -197,7 +196,7 @@ export const G2PlotLibrary: Charts = {
197
196
  properties: {
198
197
  add: {
199
198
  type: 'void',
200
- title: lang('Add'),
199
+ title: '{{t("Add")}}',
201
200
  'x-component': 'ArrayItems.Addition',
202
201
  },
203
202
  },
@@ -214,22 +213,22 @@ export const G2PlotLibrary: Charts = {
214
213
  };
215
214
  },
216
215
  reference: {
217
- title: lang('Dual Axes Chart'),
216
+ title: 'Dual Axes Chart',
218
217
  link: 'https://g2plot.antv.antgroup.com/api/plots/dual-axes',
219
218
  },
220
219
  },
221
220
  // gauge: {
222
- // name: lang('Gauge Chart'),
221
+ // name: 'Gauge Chart',
223
222
  // component: Gauge,
224
223
  // },
225
224
  scatter: {
226
- name: lang('Scatter Chart'),
225
+ name: 'Scatter Chart',
227
226
  component: Scatter,
228
227
  schema: basicSchema,
229
228
  init,
230
229
  useProps,
231
230
  reference: {
232
- title: lang('Scatter Chart'),
231
+ title: 'Scatter Chart',
233
232
  link: 'https://g2plot.antv.antgroup.com/api/plots/scatter',
234
233
  },
235
234
  },
@@ -41,8 +41,8 @@ describe('api', () => {
41
41
  const repo = db.getRepository('chart_test');
42
42
  await repo.create({
43
43
  values: [
44
- { price: 1, count: 1, title: 'title1' },
45
- { price: 2, count: 2, title: 'title2' },
44
+ { price: 1, count: 1, title: 'title1', createdAt: '2023-02-02' },
45
+ { price: 2, count: 2, title: 'title2', createdAt: '2023-01-01' },
46
46
  ],
47
47
  });
48
48
  });
@@ -51,55 +51,52 @@ describe('api', () => {
51
51
  await db.close();
52
52
  });
53
53
 
54
- test('query', () => {
55
- expect.assertions(1);
56
- return expect(
57
- queryData({ db } as any, {
58
- collection: 'chart_test',
59
- measures: [
60
- {
61
- field: ['price'],
62
- alias: 'Price',
63
- },
64
- {
65
- field: ['count'],
66
- alias: 'Count',
67
- },
68
- ],
69
- dimensions: [
70
- {
71
- field: ['title'],
72
- alias: 'Title',
73
- },
74
- ],
75
- }),
76
- ).resolves.toBeDefined();
54
+ test('query', async () => {
55
+ const result = await queryData({ db } as any, {
56
+ collection: 'chart_test',
57
+ measures: [
58
+ {
59
+ field: ['price'],
60
+ alias: 'Price',
61
+ },
62
+ {
63
+ field: ['count'],
64
+ alias: 'Count',
65
+ },
66
+ ],
67
+ dimensions: [
68
+ {
69
+ field: ['title'],
70
+ alias: 'Title',
71
+ },
72
+ ],
73
+ });
74
+ expect(result).toBeDefined();
77
75
  });
78
76
 
79
- test('query with sort', () => {
80
- expect.assertions(1);
81
- return expect(
82
- queryData({ db } as any, {
83
- collection: 'chart_test',
84
- measures: [
85
- {
86
- field: ['price'],
87
- aggregation: 'sum',
88
- alias: 'Price',
89
- },
90
- ],
91
- dimensions: [
92
- {
93
- field: ['title'],
94
- alias: 'Title',
95
- },
96
- {
97
- field: ['createdAt'],
98
- format: 'YYYY',
99
- },
100
- ],
101
- orders: [{ field: 'createdAt', order: 'asc' }],
102
- }),
103
- ).resolves.toBeDefined();
77
+ test('query with sort', async () => {
78
+ const result = await queryData({ db } as any, {
79
+ collection: 'chart_test',
80
+ measures: [
81
+ {
82
+ field: ['price'],
83
+ aggregation: 'sum',
84
+ alias: 'Price',
85
+ },
86
+ ],
87
+ dimensions: [
88
+ {
89
+ field: ['title'],
90
+ alias: 'Title',
91
+ },
92
+ {
93
+ field: ['createdAt'],
94
+ format: 'YYYY-MM',
95
+ },
96
+ ],
97
+ orders: [{ field: 'createdAt', order: 'asc' }],
98
+ });
99
+ expect(result).toBeDefined();
100
+ expect(result).toMatchObject([{ createdAt: '2023-01' }, { createdAt: '2023-02' }]);
104
101
  });
105
102
  });
@@ -161,7 +161,12 @@ export const parseBuilder = (ctx: Context, builder: QueryParams) => {
161
161
  });
162
162
 
163
163
  orders.forEach((item: OrderProps) => {
164
- const name = hasAgg ? sequelize.literal(`"${item.alias}"`) : sequelize.col(item.field as string);
164
+ const dialect = sequelize.getDialect();
165
+ let alias = `"${item.alias}"`;
166
+ if (dialect === 'mysql') {
167
+ alias = `\`${item.alias}\``;
168
+ }
169
+ const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field as string);
165
170
  order.push([name, item.order || 'ASC']);
166
171
  });
167
172