@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
@@ -47,115 +47,30 @@ var _ChartLibrary = require("./ChartLibrary");
47
47
  var _ChartRendererProvider = require("./ChartRendererProvider");
48
48
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
49
49
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
50
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
51
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
52
50
  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; }
53
51
  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; }
54
52
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
55
53
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
56
54
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
57
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
58
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
59
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
60
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
61
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
62
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
63
55
  const Paragraph = _antd().Typography.Paragraph,
64
56
  Text = _antd().Typography.Text;
65
57
  const ChartRenderer = props => {
66
58
  var _chart$useProps;
67
59
  const _useChartsTranslation = (0, _locale.useChartsTranslation)(),
68
60
  t = _useChartsTranslation.t;
69
- const _useContext = (0, _react2().useContext)(_block.ChartConfigContext),
70
- setQueryData = _useContext.setData,
71
- current = _useContext.current;
72
- const _useContext2 = (0, _react2().useContext)(_ChartRendererProvider.ChartRendererContext),
73
- query = _useContext2.query,
74
- config = _useContext2.config,
75
- collection = _useContext2.collection,
76
- transform = _useContext2.transform;
77
- const configuring = props.configuring,
78
- runQuery = props.runQuery;
61
+ const ctx = (0, _react2().useContext)(_ChartRendererProvider.ChartRendererContext);
62
+ const config = ctx.config,
63
+ transform = ctx.transform,
64
+ collection = ctx.collection,
65
+ service = ctx.service,
66
+ _data = ctx.data;
67
+ const fields = (0, _hooks.useFieldsWithAssociation)(collection);
68
+ const data = (0, _utils.processData)(fields, (service === null || service === void 0 ? void 0 : service.data) || _data || [], {
69
+ t
70
+ });
79
71
  const general = (config === null || config === void 0 ? void 0 : config.general) || {};
80
72
  const advanced = (config === null || config === void 0 ? void 0 : config.advanced) || {};
81
- const schema = (0, _react().useFieldSchema)();
82
- const currentSchema = schema || (current === null || current === void 0 ? void 0 : current.schema);
83
- const fields = (0, _hooks.useFieldsWithAssociation)(collection);
84
73
  const api = (0, _client().useAPIClient)();
85
- const _useState = (0, _react2().useState)([]),
86
- _useState2 = _slicedToArray(_useState, 2),
87
- data = _useState2[0],
88
- setData = _useState2[1];
89
- const _useRequest = (0, _client().useRequest)(query => api.request({
90
- url: 'charts:query',
91
- method: 'POST',
92
- data: _objectSpread(_objectSpread({
93
- uid: currentSchema === null || currentSchema === void 0 ? void 0 : currentSchema['x-uid'],
94
- collection
95
- }, query), {}, {
96
- dimensions: ((query === null || query === void 0 ? void 0 : query.dimensions) || []).map(item => {
97
- const dimension = _objectSpread({}, item);
98
- if (item.format && !item.alias) {
99
- const _parseField = (0, _utils.parseField)(item.field),
100
- alias = _parseField.alias;
101
- dimension.alias = alias;
102
- }
103
- return dimension;
104
- }),
105
- measures: ((query === null || query === void 0 ? void 0 : query.measures) || []).map(item => {
106
- const measure = _objectSpread({}, item);
107
- if (item.aggregation && !item.alias) {
108
- const _parseField2 = (0, _utils.parseField)(item.field),
109
- alias = _parseField2.alias;
110
- measure.alias = alias;
111
- }
112
- return measure;
113
- })
114
- })
115
- }).then(res => {
116
- var _res$data;
117
- const data = (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.data) || [];
118
- return (0, _utils.processData)(fields, data, {
119
- t
120
- });
121
- }), {
122
- manual: true,
123
- onSuccess: data => {
124
- setData(data);
125
- },
126
- onFinally(params, data, error) {
127
- if (!configuring) {
128
- return;
129
- }
130
- if (error) {
131
- var _error$response, _error$response$data, _error$response$data$, _error$response$data$2;
132
- const message = error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : (_error$response$data = _error$response.data) === null || _error$response$data === void 0 ? void 0 : (_error$response$data$ = _error$response$data.errors) === null || _error$response$data$ === void 0 ? void 0 : (_error$response$data$2 = _error$response$data$.map) === null || _error$response$data$2 === void 0 ? void 0 : _error$response$data$2.call(_error$response$data$, error => error.message).join('\n');
133
- setQueryData(message || error.message);
134
- return;
135
- }
136
- setQueryData(data);
137
- }
138
- }),
139
- runAsync = _useRequest.runAsync;
140
- (0, _react2().useEffect)(() => {
141
- setData([]);
142
- const run = /*#__PURE__*/function () {
143
- var _ref = _asyncToGenerator(function* (query) {
144
- var _query$measures;
145
- if (query !== null && query !== void 0 && (_query$measures = query.measures) !== null && _query$measures !== void 0 && _query$measures.length // || (query?.sql?.fields && query?.sql?.clauses)
146
- ) {
147
- yield runAsync(query);
148
- }
149
- });
150
- return function run(_x2) {
151
- return _ref.apply(this, arguments);
152
- };
153
- }();
154
- if (runQuery) {
155
- runQuery.current = run;
156
- }
157
- run(query);
158
- }, [query, runAsync, runQuery]);
159
74
  const charts = (0, _ChartLibrary.useCharts)();
160
75
  const chart = charts[config === null || config === void 0 ? void 0 : config.chartType];
161
76
  const Component = chart === null || chart === void 0 ? void 0 : chart.component;
@@ -187,18 +102,26 @@ const ChartRenderer = props => {
187
102
  image: _antd().Empty.PRESENTED_IMAGE_SIMPLE,
188
103
  description: t('Please configure chart')
189
104
  });
190
- return data && data.length ? _react2().default.createElement(C, null) : _react2().default.createElement(_antd().Empty, {
191
- image: _antd().Empty.PRESENTED_IMAGE_SIMPLE,
192
- description: t('Please configure and run query')
193
- });
105
+ if (service.loading) {
106
+ return _react2().default.createElement(_antd().Spin, null);
107
+ }
108
+ if (!(data && data.length)) {
109
+ return _react2().default.createElement(_antd().Empty, {
110
+ image: _antd().Empty.PRESENTED_IMAGE_SIMPLE,
111
+ description: t('Please configure and run query')
112
+ });
113
+ }
114
+ return _react2().default.createElement(C, null);
194
115
  };
195
116
  exports.ChartRenderer = ChartRenderer;
196
117
  ChartRenderer.Designer = function Designer() {
197
118
  const _useChartsTranslation2 = (0, _locale.useChartsTranslation)(),
198
119
  t = _useChartsTranslation2.t;
199
- const _useContext3 = (0, _react2().useContext)(_block.ChartConfigContext),
200
- setVisible = _useContext3.setVisible,
201
- setCurrent = _useContext3.setCurrent;
120
+ const _useContext = (0, _react2().useContext)(_block.ChartConfigContext),
121
+ setVisible = _useContext.setVisible,
122
+ setCurrent = _useContext.setCurrent;
123
+ const _useContext2 = (0, _react2().useContext)(_ChartRendererProvider.ChartRendererContext),
124
+ service = _useContext2.service;
202
125
  const field = (0, _react().useField)();
203
126
  const schema = (0, _react().useFieldSchema)();
204
127
  const _useDesignable = (0, _client().useDesignable)(),
@@ -215,7 +138,9 @@ ChartRenderer.Designer = function Designer() {
215
138
  setCurrent({
216
139
  schema,
217
140
  field,
218
- collection: name
141
+ collection: name,
142
+ service,
143
+ data: service === null || service === void 0 ? void 0 : service.data
219
144
  });
220
145
  setVisible(true);
221
146
  }
@@ -39,5 +39,15 @@ export type ChartRendererProps = {
39
39
  transform?: TransformProps[];
40
40
  mode?: 'builder' | 'sql';
41
41
  };
42
- export declare const ChartRendererContext: React.Context<ChartRendererProps>;
42
+ export declare const ChartRendererContext: React.Context<{
43
+ collection: string;
44
+ config?: {
45
+ chartType: string;
46
+ general: any;
47
+ advanced: any;
48
+ };
49
+ transform?: TransformProps[];
50
+ service: any;
51
+ data?: any[];
52
+ }>;
43
53
  export declare const ChartRendererProvider: React.FC<ChartRendererProps>;
@@ -11,6 +11,13 @@ function _css() {
11
11
  };
12
12
  return data;
13
13
  }
14
+ function _react() {
15
+ const data = require("@formily/react");
16
+ _react = function _react() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
14
21
  function _client() {
15
22
  const data = require("@nocobase/client");
16
23
  _client = function _client() {
@@ -18,13 +25,14 @@ function _client() {
18
25
  };
19
26
  return data;
20
27
  }
21
- function _react() {
28
+ function _react2() {
22
29
  const data = _interopRequireWildcard(require("react"));
23
- _react = function _react() {
30
+ _react2 = function _react2() {
24
31
  return data;
25
32
  };
26
33
  return data;
27
34
  }
35
+ var _utils = require("../utils");
28
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
37
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
30
38
  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; }
@@ -32,23 +40,66 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
32
40
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
41
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
34
42
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
35
- const ChartRendererContext = (0, _react().createContext)({});
43
+ const ChartRendererContext = (0, _react2().createContext)({});
36
44
  exports.ChartRendererContext = ChartRendererContext;
37
45
  const ChartRendererProvider = props => {
38
- const collection = props.collection;
39
- return _react().default.createElement(_client().MaybeCollectionProvider, {
46
+ const query = props.query,
47
+ config = props.config,
48
+ collection = props.collection,
49
+ transform = props.transform;
50
+ const schema = (0, _react().useFieldSchema)();
51
+ const api = (0, _client().useAPIClient)();
52
+ const service = (0, _client().useRequest)((collection, query) => new Promise((resolve, reject) => {
53
+ var _query$measures;
54
+ if (!(collection && query !== null && query !== void 0 && (_query$measures = query.measures) !== null && _query$measures !== void 0 && _query$measures.length)) return resolve(undefined);
55
+ api.request({
56
+ url: 'charts:query',
57
+ method: 'POST',
58
+ data: _objectSpread(_objectSpread({
59
+ uid: schema === null || schema === void 0 ? void 0 : schema['x-uid'],
60
+ collection
61
+ }, query), {}, {
62
+ dimensions: ((query === null || query === void 0 ? void 0 : query.dimensions) || []).map(item => {
63
+ const dimension = _objectSpread({}, item);
64
+ if (item.format && !item.alias) {
65
+ const _parseField = (0, _utils.parseField)(item.field),
66
+ alias = _parseField.alias;
67
+ dimension.alias = alias;
68
+ }
69
+ return dimension;
70
+ }),
71
+ measures: ((query === null || query === void 0 ? void 0 : query.measures) || []).map(item => {
72
+ const measure = _objectSpread({}, item);
73
+ if (item.aggregation && !item.alias) {
74
+ const _parseField2 = (0, _utils.parseField)(item.field),
75
+ alias = _parseField2.alias;
76
+ measure.alias = alias;
77
+ }
78
+ return measure;
79
+ })
80
+ })
81
+ }).then(res => {
82
+ var _res$data;
83
+ resolve(res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.data);
84
+ }).catch(reject);
85
+ }), {
86
+ defaultParams: [collection, query]
87
+ });
88
+ return _react2().default.createElement(_client().MaybeCollectionProvider, {
40
89
  collection: collection
41
- }, _react().default.createElement("div", {
90
+ }, _react2().default.createElement("div", {
42
91
  className: (0, _css().css)`
43
92
  .ant-card {
44
93
  box-shadow: none;
45
94
  }
46
- .ant-card-body {
47
- padding: 0;
48
- }
49
95
  `
50
- }, _react().default.createElement(ChartRendererContext.Provider, {
51
- value: _objectSpread({}, props)
96
+ }, _react2().default.createElement(ChartRendererContext.Provider, {
97
+ value: {
98
+ collection,
99
+ config,
100
+ transform,
101
+ service
102
+ }
52
103
  }, props.children)));
53
104
  };
54
105
  exports.ChartRendererProvider = ChartRendererProvider;
@@ -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: (0, _locale.lang)('xField'),
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: (0, _locale.lang)('yField'),
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: (0, _locale.lang)('seriesField'),
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: (0, _locale.lang)('Line Chart'),
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: (0, _locale.lang)('Line Chart'),
75
+ title: 'Line Chart',
77
76
  link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
78
77
  }
79
78
  },
80
79
  area: {
81
- name: (0, _locale.lang)('Area Chart'),
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: (0, _locale.lang)('Area Chart'),
86
+ title: 'Area Chart',
88
87
  link: 'https://g2plot.antv.antgroup.com/api/plots/area'
89
88
  }
90
89
  },
91
90
  column: {
92
- name: (0, _locale.lang)('Column Chart'),
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: (0, _locale.lang)('Column Chart'),
97
+ title: 'Column Chart',
99
98
  link: 'https://g2plot.antv.antgroup.com/api/plots/column'
100
99
  }
101
100
  },
102
101
  bar: {
103
- name: (0, _locale.lang)('Bar Chart'),
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: (0, _locale.lang)('Bar Chart'),
126
+ title: 'Bar Chart',
128
127
  link: 'https://g2plot.antv.antgroup.com/api/plots/bar'
129
128
  }
130
129
  },
131
130
  pie: {
132
- name: (0, _locale.lang)('Pie Chart'),
131
+ name: 'Pie Chart',
133
132
  component: _plots().Pie,
134
133
  schema: {
135
134
  type: 'object',
136
135
  properties: {
137
136
  angleField: {
138
- title: (0, _locale.lang)('angleField'),
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: (0, _locale.lang)('colorField'),
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: (0, _locale.lang)('Pie Chart'),
173
+ title: 'Pie Chart',
175
174
  link: 'https://g2plot.antv.antgroup.com/api/plots/pie'
176
175
  }
177
176
  },
178
177
  dualAxes: {
179
- name: (0, _locale.lang)('Dual Axes Chart'),
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: (0, _locale.lang)('xField'),
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: (0, _locale.lang)('yField'),
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
- 'min-width': '200px'
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: (0, _locale.lang)('Add'),
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: (0, _locale.lang)('Dual Axes Chart'),
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: lang('Gauge Chart'),
272
+ // name: 'Gauge Chart',
274
273
  // component: Gauge,
275
274
  // },
276
275
  scatter: {
277
- name: (0, _locale.lang)('Scatter Chart'),
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: (0, _locale.lang)('Scatter Chart'),
282
+ title: 'Scatter Chart',
284
283
  link: 'https://g2plot.antv.antgroup.com/api/plots/scatter'
285
284
  }
286
285
  }
@@ -161,7 +161,12 @@ const parseBuilder = (ctx, builder) => {
161
161
  fieldMap[alias || field] = dimension;
162
162
  });
163
163
  orders.forEach(item => {
164
- const name = hasAgg ? sequelize.literal(`"${item.alias}"`) : sequelize.col(item.field);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-data-visualization",
3
- "version": "0.11.0-alpha.1",
3
+ "version": "0.11.1-alpha.2",
4
4
  "displayName": "Data Visualization",
5
5
  "displayName.zh-CN": "数据可视化",
6
6
  "description": "Provides business intelligence and data visualization features",
@@ -17,13 +17,13 @@
17
17
  "@formily/core": "2.2.26",
18
18
  "@formily/react": "2.2.26",
19
19
  "@formily/shared": "2.2.26",
20
- "@nocobase/actions": "0.11.0-alpha.1",
21
- "@nocobase/cache": "0.11.0-alpha.1",
22
- "@nocobase/client": "0.11.0-alpha.1",
23
- "@nocobase/database": "0.11.0-alpha.1",
24
- "@nocobase/server": "0.11.0-alpha.1",
25
- "@nocobase/test": "0.11.0-alpha.1",
26
- "@nocobase/utils": "0.11.0-alpha.1",
20
+ "@nocobase/actions": "0.11.1-alpha.2",
21
+ "@nocobase/cache": "0.11.1-alpha.2",
22
+ "@nocobase/client": "0.11.1-alpha.2",
23
+ "@nocobase/database": "0.11.1-alpha.2",
24
+ "@nocobase/server": "0.11.1-alpha.2",
25
+ "@nocobase/test": "0.11.1-alpha.2",
26
+ "@nocobase/utils": "0.11.1-alpha.2",
27
27
  "@testing-library/react": "^12.1.5",
28
28
  "antd": "^5.6.4",
29
29
  "lodash": "^4.17.21",
@@ -31,5 +31,5 @@
31
31
  "react-i18next": "^11.15.1",
32
32
  "vitest": "^0.33.0"
33
33
  },
34
- "gitHead": "7581b6d3a3a54f09f06a9effb7e3e65328281b2b"
34
+ "gitHead": "8482aa720ea1c3abbbb9fe1208e73778bd63f1cf"
35
35
  }
@@ -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, data, setData }}>
16
+ <ChartConfigContext.Provider value={{ visible, setVisible, current, setCurrent }}>
17
17
  {props.children}
18
- <ChartConfigure insert={(schema, options) => insertAdjacent('beforeEnd', schema, options)} />
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, setData } = useContext(ChartConfigContext);
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
  />