@nocobase/plugin-data-visualization 0.10.1-alpha.1 → 0.11.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.
- package/lib/client/Settings.js +13 -13
- package/lib/client/block/ChartBlock.js +16 -15
- package/lib/client/block/ChartBlockInitializer.js +4 -4
- package/lib/client/block/ChartConfigure.d.ts +6 -7
- package/lib/client/block/ChartConfigure.js +140 -125
- package/lib/client/block/schemas/configure.js +7 -7
- package/lib/client/block/transformers.js +18 -19
- package/lib/client/hooks.d.ts +1 -1
- package/lib/client/index.d.ts +5 -3
- package/lib/client/index.js +12 -2
- package/lib/client/locale/index.d.ts +2 -2
- package/lib/client/locale/index.js +3 -5
- package/lib/client/locale/zh-CN.d.ts +1 -0
- package/lib/client/locale/zh-CN.js +2 -1
- package/lib/client/renderer/ChartLibrary.d.ts +5 -4
- package/lib/client/renderer/ChartLibrary.js +9 -3
- package/lib/client/renderer/ChartRenderer.d.ts +1 -4
- package/lib/client/renderer/ChartRenderer.js +28 -103
- package/lib/client/renderer/ChartRendererProvider.d.ts +16 -6
- package/lib/client/renderer/ChartRendererProvider.js +75 -8
- package/lib/client/renderer/library/AntdLibrary.js +1 -1
- package/lib/client/renderer/library/G2PlotLibrary.js +24 -25
- package/lib/server/actions/query.d.ts +4 -4
- package/lib/server/actions/query.js +6 -1
- package/package.json +28 -16
- package/src/client/Settings.tsx +2 -2
- package/src/client/__tests__/hooks.test.ts +3 -2
- package/src/client/block/ChartBlock.tsx +5 -3
- package/src/client/block/ChartBlockInitializer.tsx +2 -3
- package/src/client/block/ChartConfigure.tsx +110 -89
- package/src/client/block/schemas/configure.ts +7 -7
- package/src/client/block/transformers.ts +1 -1
- package/src/client/index.tsx +9 -3
- package/src/client/locale/index.ts +2 -3
- package/src/client/locale/zh-CN.ts +1 -0
- package/src/client/renderer/ChartLibrary.tsx +6 -1
- package/src/client/renderer/ChartRenderer.tsx +22 -90
- package/src/client/renderer/ChartRendererProvider.tsx +69 -4
- package/src/client/renderer/library/G2PlotLibrary.tsx +24 -25
- package/src/server/__tests__/api.test.ts +47 -50
- package/src/server/actions/query.ts +6 -1
|
@@ -11,7 +11,6 @@ function _plots() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
-
var _locale = require("../../locale");
|
|
15
14
|
var _ChartLibrary = require("../ChartLibrary");
|
|
16
15
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -23,7 +22,7 @@ const basicSchema = {
|
|
|
23
22
|
type: 'object',
|
|
24
23
|
properties: {
|
|
25
24
|
xField: {
|
|
26
|
-
title: (
|
|
25
|
+
title: '{{t("xField")}}',
|
|
27
26
|
type: 'string',
|
|
28
27
|
'x-decorator': 'FormItem',
|
|
29
28
|
'x-component': 'Select',
|
|
@@ -31,7 +30,7 @@ const basicSchema = {
|
|
|
31
30
|
required: true
|
|
32
31
|
},
|
|
33
32
|
yField: {
|
|
34
|
-
title: (
|
|
33
|
+
title: '{{t("yField")}}',
|
|
35
34
|
type: 'string',
|
|
36
35
|
'x-decorator': 'FormItem',
|
|
37
36
|
'x-component': 'Select',
|
|
@@ -39,7 +38,7 @@ const basicSchema = {
|
|
|
39
38
|
required: true
|
|
40
39
|
},
|
|
41
40
|
seriesField: {
|
|
42
|
-
title: (
|
|
41
|
+
title: '{{t("seriesField")}}',
|
|
43
42
|
type: 'string',
|
|
44
43
|
'x-decorator': 'FormItem',
|
|
45
44
|
'x-component': 'Select',
|
|
@@ -67,40 +66,40 @@ const _useProps = ({
|
|
|
67
66
|
};
|
|
68
67
|
const G2PlotLibrary = {
|
|
69
68
|
line: {
|
|
70
|
-
name:
|
|
69
|
+
name: 'Line Chart',
|
|
71
70
|
component: _plots().Line,
|
|
72
71
|
schema: basicSchema,
|
|
73
72
|
init,
|
|
74
73
|
useProps: _useProps,
|
|
75
74
|
reference: {
|
|
76
|
-
title:
|
|
75
|
+
title: 'Line Chart',
|
|
77
76
|
link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
|
|
78
77
|
}
|
|
79
78
|
},
|
|
80
79
|
area: {
|
|
81
|
-
name:
|
|
80
|
+
name: 'Area Chart',
|
|
82
81
|
component: _plots().Area,
|
|
83
82
|
schema: basicSchema,
|
|
84
83
|
init,
|
|
85
84
|
useProps: _useProps,
|
|
86
85
|
reference: {
|
|
87
|
-
title:
|
|
86
|
+
title: 'Area Chart',
|
|
88
87
|
link: 'https://g2plot.antv.antgroup.com/api/plots/area'
|
|
89
88
|
}
|
|
90
89
|
},
|
|
91
90
|
column: {
|
|
92
|
-
name:
|
|
91
|
+
name: 'Column Chart',
|
|
93
92
|
component: _plots().Column,
|
|
94
93
|
schema: basicSchema,
|
|
95
94
|
init,
|
|
96
95
|
useProps: _useProps,
|
|
97
96
|
reference: {
|
|
98
|
-
title:
|
|
97
|
+
title: 'Column Chart',
|
|
99
98
|
link: 'https://g2plot.antv.antgroup.com/api/plots/column'
|
|
100
99
|
}
|
|
101
100
|
},
|
|
102
101
|
bar: {
|
|
103
|
-
name:
|
|
102
|
+
name: 'Bar Chart',
|
|
104
103
|
component: _plots().Bar,
|
|
105
104
|
schema: basicSchema,
|
|
106
105
|
init: (fields, {
|
|
@@ -124,18 +123,18 @@ const G2PlotLibrary = {
|
|
|
124
123
|
},
|
|
125
124
|
useProps: _useProps,
|
|
126
125
|
reference: {
|
|
127
|
-
title:
|
|
126
|
+
title: 'Bar Chart',
|
|
128
127
|
link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
|
|
129
128
|
}
|
|
130
129
|
},
|
|
131
130
|
pie: {
|
|
132
|
-
name:
|
|
131
|
+
name: 'Pie Chart',
|
|
133
132
|
component: _plots().Pie,
|
|
134
133
|
schema: {
|
|
135
134
|
type: 'object',
|
|
136
135
|
properties: {
|
|
137
136
|
angleField: {
|
|
138
|
-
title: (
|
|
137
|
+
title: '{{t("angleField")}}',
|
|
139
138
|
type: 'string',
|
|
140
139
|
'x-decorator': 'FormItem',
|
|
141
140
|
'x-component': 'Select',
|
|
@@ -143,7 +142,7 @@ const G2PlotLibrary = {
|
|
|
143
142
|
required: true
|
|
144
143
|
},
|
|
145
144
|
colorField: {
|
|
146
|
-
title: (
|
|
145
|
+
title: '{{t("colorField")}}',
|
|
147
146
|
type: 'string',
|
|
148
147
|
'x-decorator': 'FormItem',
|
|
149
148
|
'x-component': 'Select',
|
|
@@ -171,12 +170,12 @@ const G2PlotLibrary = {
|
|
|
171
170
|
},
|
|
172
171
|
useProps: _useProps,
|
|
173
172
|
reference: {
|
|
174
|
-
title:
|
|
173
|
+
title: 'Pie Chart',
|
|
175
174
|
link: 'https://g2plot.antv.antgroup.com/api/plots/pie'
|
|
176
175
|
}
|
|
177
176
|
},
|
|
178
177
|
dualAxes: {
|
|
179
|
-
name:
|
|
178
|
+
name: 'Dual Axes Chart',
|
|
180
179
|
component: _plots().DualAxes,
|
|
181
180
|
useProps: ({
|
|
182
181
|
data,
|
|
@@ -197,7 +196,7 @@ const G2PlotLibrary = {
|
|
|
197
196
|
type: 'object',
|
|
198
197
|
properties: {
|
|
199
198
|
xField: {
|
|
200
|
-
title: (
|
|
199
|
+
title: '{{t("xField")}}',
|
|
201
200
|
type: 'string',
|
|
202
201
|
'x-decorator': 'FormItem',
|
|
203
202
|
'x-component': 'Select',
|
|
@@ -205,7 +204,7 @@ const G2PlotLibrary = {
|
|
|
205
204
|
required: true
|
|
206
205
|
},
|
|
207
206
|
yField: {
|
|
208
|
-
title: (
|
|
207
|
+
title: '{{t("yField")}}',
|
|
209
208
|
type: 'array',
|
|
210
209
|
'x-decorator': 'FormItem',
|
|
211
210
|
'x-component': 'ArrayItems',
|
|
@@ -225,7 +224,7 @@ const G2PlotLibrary = {
|
|
|
225
224
|
'x-reactions': '{{ useChartFields }}',
|
|
226
225
|
'x-component-props': {
|
|
227
226
|
style: {
|
|
228
|
-
|
|
227
|
+
minWidth: '200px'
|
|
229
228
|
}
|
|
230
229
|
},
|
|
231
230
|
required: true
|
|
@@ -240,7 +239,7 @@ const G2PlotLibrary = {
|
|
|
240
239
|
properties: {
|
|
241
240
|
add: {
|
|
242
241
|
type: 'void',
|
|
243
|
-
title: (
|
|
242
|
+
title: '{{t("Add")}}',
|
|
244
243
|
'x-component': 'ArrayItems.Addition'
|
|
245
244
|
}
|
|
246
245
|
}
|
|
@@ -265,22 +264,22 @@ const G2PlotLibrary = {
|
|
|
265
264
|
};
|
|
266
265
|
},
|
|
267
266
|
reference: {
|
|
268
|
-
title:
|
|
267
|
+
title: 'Dual Axes Chart',
|
|
269
268
|
link: 'https://g2plot.antv.antgroup.com/api/plots/dual-axes'
|
|
270
269
|
}
|
|
271
270
|
},
|
|
272
271
|
// gauge: {
|
|
273
|
-
// name:
|
|
272
|
+
// name: 'Gauge Chart',
|
|
274
273
|
// component: Gauge,
|
|
275
274
|
// },
|
|
276
275
|
scatter: {
|
|
277
|
-
name:
|
|
276
|
+
name: 'Scatter Chart',
|
|
278
277
|
component: _plots().Scatter,
|
|
279
278
|
schema: basicSchema,
|
|
280
279
|
init,
|
|
281
280
|
useProps: _useProps,
|
|
282
281
|
reference: {
|
|
283
|
-
title:
|
|
282
|
+
title: 'Scatter Chart',
|
|
284
283
|
link: 'https://g2plot.antv.antgroup.com/api/plots/scatter'
|
|
285
284
|
}
|
|
286
285
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { Context, Next } from '@nocobase/actions';
|
|
2
2
|
import { Cache } from '@nocobase/cache';
|
|
3
|
-
|
|
3
|
+
type MeasureProps = {
|
|
4
4
|
field: string | string[];
|
|
5
5
|
type?: string;
|
|
6
6
|
aggregation?: string;
|
|
7
7
|
alias?: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type DimensionProps = {
|
|
10
10
|
field: string | string[];
|
|
11
11
|
type?: string;
|
|
12
12
|
alias?: string;
|
|
13
13
|
format?: string;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type OrderProps = {
|
|
16
16
|
field: string | string[];
|
|
17
17
|
alias?: string;
|
|
18
18
|
order?: 'asc' | 'desc';
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type QueryParams = Partial<{
|
|
21
21
|
uid: string;
|
|
22
22
|
collection: string;
|
|
23
23
|
measures: MeasureProps[];
|
|
@@ -161,7 +161,12 @@ const parseBuilder = (ctx, builder) => {
|
|
|
161
161
|
fieldMap[alias || field] = dimension;
|
|
162
162
|
});
|
|
163
163
|
orders.forEach(item => {
|
|
164
|
-
const
|
|
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);
|
|
165
170
|
order.push([name, item.order || 'ASC']);
|
|
166
171
|
});
|
|
167
172
|
return {
|
package/package.json
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-data-visualization",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "lib/server/index.js",
|
|
5
|
-
"devDependencies": {
|
|
6
|
-
"@nocobase/actions": "0.10.1-alpha.1",
|
|
7
|
-
"@nocobase/cache": "0.10.1-alpha.1",
|
|
8
|
-
"@nocobase/server": "0.10.1-alpha.1",
|
|
9
|
-
"@nocobase/test": "0.10.1-alpha.1",
|
|
10
|
-
"@testing-library/react": "^14.0.0",
|
|
11
|
-
"lodash": "^4.17.21"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@ant-design/plots": "^1.2.5",
|
|
15
|
-
"dayjs": "^1.11.7",
|
|
16
|
-
"react-error-boundary": "^4.0.4"
|
|
17
|
-
},
|
|
3
|
+
"version": "0.11.1-alpha.1",
|
|
18
4
|
"displayName": "Data Visualization",
|
|
19
5
|
"displayName.zh-CN": "数据可视化",
|
|
20
6
|
"description": "Provides business intelligence and data visualization features",
|
|
21
7
|
"description.zh-CN": "提供BI面板和数据可视化功能",
|
|
22
|
-
"
|
|
8
|
+
"main": "lib/server/index.js",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@ant-design/plots": "^1.2.5",
|
|
11
|
+
"classnames": "^2.3.1",
|
|
12
|
+
"react-error-boundary": "^4.0.10"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@ant-design/icons": "^5.1.4",
|
|
16
|
+
"@formily/antd-v5": "1.1.0-beta.4",
|
|
17
|
+
"@formily/core": "2.2.26",
|
|
18
|
+
"@formily/react": "2.2.26",
|
|
19
|
+
"@formily/shared": "2.2.26",
|
|
20
|
+
"@nocobase/actions": "0.11.1-alpha.1",
|
|
21
|
+
"@nocobase/cache": "0.11.1-alpha.1",
|
|
22
|
+
"@nocobase/client": "0.11.1-alpha.1",
|
|
23
|
+
"@nocobase/database": "0.11.1-alpha.1",
|
|
24
|
+
"@nocobase/server": "0.11.1-alpha.1",
|
|
25
|
+
"@nocobase/test": "0.11.1-alpha.1",
|
|
26
|
+
"@nocobase/utils": "0.11.1-alpha.1",
|
|
27
|
+
"@testing-library/react": "^12.1.5",
|
|
28
|
+
"antd": "^5.6.4",
|
|
29
|
+
"lodash": "^4.17.21",
|
|
30
|
+
"react": "^18.2.0",
|
|
31
|
+
"react-i18next": "^11.15.1",
|
|
32
|
+
"vitest": "^0.33.0"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
|
|
23
35
|
}
|
package/src/client/Settings.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CheckOutlined } from '@ant-design/icons';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Form, FormItem } from '@formily/antd-v5';
|
|
3
|
+
import { css } from '@nocobase/client';
|
|
4
4
|
import { Button, Card } from 'antd';
|
|
5
5
|
import cls from 'classnames';
|
|
6
6
|
import React, { useContext } from 'react';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as client from '@nocobase/client';
|
|
2
|
-
import { renderHook } from '@testing-library/react';
|
|
2
|
+
// import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { vi } from 'vitest';
|
|
4
4
|
import formatters from '../block/formatters';
|
|
5
5
|
import transformers from '../block/transformers';
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
useTransformers,
|
|
14
14
|
} from '../hooks';
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// TODO: 为了暂时解决很多 Warning 的问题把 `@testing-library/react` 降级到了 12.x 所以不支持 `renderHook`,等到再次升级到 14.x 时再把 skip 去掉
|
|
17
|
+
describe.skip('hooks', () => {
|
|
17
18
|
beforeEach(() => {
|
|
18
19
|
vi.spyOn(client, 'useCollectionManager').mockReturnValue({
|
|
19
20
|
getCollectionFields: (name: string) =>
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { SchemaInitializerButtonContext, useDesignable } from '@nocobase/client';
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
|
+
import { ChartRendererProvider } from '../renderer';
|
|
3
4
|
import { ChartConfigContext, ChartConfigCurrent, ChartConfigure } from './ChartConfigure';
|
|
4
5
|
|
|
5
6
|
export const ChartV2Block: React.FC = (props) => {
|
|
6
7
|
const { insertAdjacent } = useDesignable();
|
|
7
8
|
const [visible, setVisible] = useState(false);
|
|
8
9
|
const [current, setCurrent] = useState<ChartConfigCurrent>({} as any);
|
|
9
|
-
const [data, setData] = useState<string | any[]>([]);
|
|
10
10
|
const [initialVisible, setInitialVisible] = useState(false);
|
|
11
11
|
const [searchValue, setSearchValue] = useState('');
|
|
12
12
|
return (
|
|
13
13
|
<SchemaInitializerButtonContext.Provider
|
|
14
14
|
value={{ visible: initialVisible, setVisible: setInitialVisible, searchValue, setSearchValue }}
|
|
15
15
|
>
|
|
16
|
-
<ChartConfigContext.Provider value={{ visible, setVisible, current, setCurrent
|
|
16
|
+
<ChartConfigContext.Provider value={{ visible, setVisible, current, setCurrent }}>
|
|
17
17
|
{props.children}
|
|
18
|
-
<
|
|
18
|
+
<ChartRendererProvider {...current.field?.decoratorProps}>
|
|
19
|
+
<ChartConfigure insert={(schema, options) => insertAdjacent('beforeEnd', schema, options)} />
|
|
20
|
+
</ChartRendererProvider>
|
|
19
21
|
</ChartConfigContext.Provider>
|
|
20
22
|
</SchemaInitializerButtonContext.Provider>
|
|
21
23
|
);
|
|
@@ -8,13 +8,12 @@ import { ChartConfigContext } from './ChartConfigure';
|
|
|
8
8
|
|
|
9
9
|
const itemWrap = SchemaInitializer.itemWrap;
|
|
10
10
|
const ConfigureButton = itemWrap((props) => {
|
|
11
|
-
const { setVisible, setCurrent
|
|
11
|
+
const { setVisible, setCurrent } = useContext(ChartConfigContext);
|
|
12
12
|
return (
|
|
13
13
|
<SchemaInitializer.Item
|
|
14
14
|
{...props}
|
|
15
15
|
onClick={() => {
|
|
16
|
-
setCurrent({ schema: {}, field: null, collection: props.item?.name });
|
|
17
|
-
setData([]);
|
|
16
|
+
setCurrent({ schema: {}, field: null, collection: props.item?.name, service: null, data: undefined });
|
|
18
17
|
setVisible(true);
|
|
19
18
|
}}
|
|
20
19
|
/>
|