sea-chart 0.0.5 → 0.0.7
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/README.md +37 -82
- package/dist/context.js +8 -10
- package/dist/editor/index.js +6 -22
- package/dist/utils/chart-utils.js +17 -19
- package/dist/view/index.js +14 -6
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,109 +1,40 @@
|
|
|
1
1
|
# sea-chart
|
|
2
2
|
> The seatable chart displays the data in the seatable in the form of a chart.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## 查看demo
|
|
5
5
|
1. 下载源码并进入文件夹
|
|
6
6
|
```
|
|
7
7
|
git clone https://gitlab.seafile.top/seatable-extends/sea-chart/
|
|
8
8
|
cd sea-chart
|
|
9
9
|
```
|
|
10
|
+
|
|
10
11
|
2. 安装依赖
|
|
11
12
|
```
|
|
12
13
|
npm install
|
|
13
14
|
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
'id': '73c8',
|
|
23
|
-
'type': 'statistic',
|
|
24
|
-
'style_config': {
|
|
25
|
-
'border': {
|
|
26
|
-
'is_show_border': false,
|
|
27
|
-
'is_show_shadow': false,
|
|
28
|
-
'width': 0,
|
|
29
|
-
'radius': 0,
|
|
30
|
-
'color': '#EFEFEF'
|
|
31
|
-
},
|
|
32
|
-
'title': {
|
|
33
|
-
'text': 'table',
|
|
34
|
-
'font_size': 24,
|
|
35
|
-
'font_weight': 700,
|
|
36
|
-
'horizontal_align': 'left'
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
'config': {
|
|
40
|
-
'type': 'table',
|
|
41
|
-
'table_id': '0000',
|
|
42
|
-
'filters': [],
|
|
43
|
-
'filter_conjunction': 'And',
|
|
44
|
-
'groupby_column_key': '_ctime',
|
|
45
|
-
'groupby_date_granularity': 'month',
|
|
46
|
-
'groupby_geolocation_granularity': null,
|
|
47
|
-
'groupby_include_empty_cells': false,
|
|
48
|
-
'summary_column_key': null,
|
|
49
|
-
'summary_method': 'Sum',
|
|
50
|
-
'summary_type': 'count',
|
|
51
|
-
'column_groupby_multiple_numeric_column': null,
|
|
52
|
-
'summary_columns': [],
|
|
53
|
-
'column_groupby_column_key': null,
|
|
54
|
-
'column_groupby_date_granularity': null,
|
|
55
|
-
'column_groupby_geolocation_granularity': null
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
export default CHARTS;
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
3.2
|
|
64
|
-
```
|
|
65
|
-
{
|
|
66
|
-
APIToken: '0268604f535ad4fa88a2c499455a82711b6e23a4',
|
|
67
|
-
server: 'https://dev.seatable.cn',
|
|
68
|
-
fileName: '全类型数据',
|
|
69
|
-
workspaceID: '24',
|
|
70
|
-
dtableUuid: 'f7288f72-03ff-4a69-85e3-3e8a86dbfa20',
|
|
71
|
-
lang: 'zh-cn',
|
|
72
|
-
mediaUrl: '/media/',
|
|
73
|
-
permission: 'rw',
|
|
74
|
-
accessToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MDQ0NDk1NzksImR0YWJsZV91dWlkIjoiZjcyODhmNzItMDNmZi00YTY5LTg1ZTMtM2U4YTg2ZGJmYTIwIiwidXNlcm5hbWUiOiJndW94dWFuLnlhbmdAc2VhZmlsZS5jb20iLCJpZF9pbl9vcmciOiJXLTAwMDE3IiwidXNlcl9kZXBhcnRtZW50X2lkc19tYXAiOnsiY3VycmVudF91c2VyX2RlcGFydG1lbnRfaWRzIjpbMTRdLCJjdXJyZW50X3VzZXJfZGVwYXJ0bWVudF9hbmRfc3ViX2lkcyI6WzE0XX0sInBlcm1pc3Npb24iOiJydyJ9.6AEwL9jIbX6vfV2SVEpxZsvtwSgLAXN-E_jlu780HSc',
|
|
75
|
-
dtableDb: 'https://dtable-db-proxy-dev.seatable.cn/',
|
|
76
|
-
}
|
|
77
|
-
```
|
|
15
|
+
|
|
16
|
+
3. 添加配置项
|
|
17
|
+
* 切换目录:`cd example`
|
|
18
|
+
* 复制一份:'setting.local.dist.js', 并重命名为 'setting.local.js'
|
|
19
|
+
* 修改 pluginConfig, 该配置想同插件开发的配置项一样,请参照插件开发文档即可
|
|
20
|
+
* 修改 appConfig, 该配置项同 universal app 的配置项一样,请参照 universal app 的配置项进行配置即可
|
|
21
|
+
|
|
78
22
|
4. 启动
|
|
79
23
|
```
|
|
80
24
|
npm start
|
|
81
25
|
```
|
|
82
26
|
|
|
83
|
-
|
|
84
|
-
1. 定义类型
|
|
85
|
-
> 为 CHART_TYPE 追加新类型
|
|
86
|
-
|
|
87
|
-
2. 定义配置模型及设置UI
|
|
88
|
-
2.1 为新类型增加模型,便于字段的统一管理 同时写入数据类型文档中
|
|
89
|
-
2.2 为新类型增加设置字段的UI,以更改配置
|
|
90
|
-
|
|
91
|
-
3. 定义查询数据的SQL
|
|
92
|
-
> 构造恰当的 SQL 语句来获取数据
|
|
93
|
-
|
|
94
|
-
4. 定义渲染机制
|
|
95
|
-
> 未新类型增加渲染机制
|
|
27
|
+
5. 在浏览器地址栏中输入:127.0.0.1:9000,即可访问该组件库的 demo 内容
|
|
96
28
|
|
|
97
|
-
|
|
98
|
-
> View 组件将根据类型自动渲染该类型
|
|
29
|
+
**注意**:自定义API 的demo,目前不支持修改参数同步更新视图
|
|
99
30
|
|
|
100
|
-
|
|
31
|
+
## 使用
|
|
101
32
|
1. 安装 sea-chart
|
|
102
33
|
```
|
|
103
34
|
npm install sea-chart
|
|
104
35
|
```
|
|
105
36
|
|
|
106
|
-
2.
|
|
37
|
+
2. 使用
|
|
107
38
|
```
|
|
108
39
|
import React from 'react';
|
|
109
40
|
import View from 'sea-chart';
|
|
@@ -118,3 +49,27 @@
|
|
|
118
49
|
|
|
119
50
|
```
|
|
120
51
|
|
|
52
|
+
3. 具体应用请参照相关 demo
|
|
53
|
+
|
|
54
|
+
## 开发
|
|
55
|
+
### 基于现有类型开发
|
|
56
|
+
1. 请参照相关 demo, 进行相关的开发
|
|
57
|
+
|
|
58
|
+
### 增加新类型
|
|
59
|
+
1. 定义类型
|
|
60
|
+
* 为 CHART_TYPE 追加新类型
|
|
61
|
+
|
|
62
|
+
2. 定义配置模型及设置UI
|
|
63
|
+
* 为新类型增加模型,便于字段的统一管理 同时写入数据类型文档中
|
|
64
|
+
* 为新类型增加设置字段的 UI,以更改配置
|
|
65
|
+
|
|
66
|
+
3. 定义查询数据的SQL
|
|
67
|
+
* 构造恰当的 SQL 语句来获取数据(供 自定义api 使用)
|
|
68
|
+
* 构造恰当的算法,用于计算图标需要渲染的数据(当用户直接使用 base 数据时使用)
|
|
69
|
+
|
|
70
|
+
4. 定义渲染机制
|
|
71
|
+
* 未新类型增加渲染机制
|
|
72
|
+
|
|
73
|
+
5. 追加渲染机制到 View 组件中
|
|
74
|
+
* View 组件将根据类型自动渲染该类型
|
|
75
|
+
|
package/dist/context.js
CHANGED
|
@@ -12,11 +12,10 @@ class Context {
|
|
|
12
12
|
} = _ref;
|
|
13
13
|
// used custom api to get chart result data
|
|
14
14
|
if (this.api.queryChartResult) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onSuccess
|
|
18
|
-
|
|
19
|
-
onFail && onFail(error);
|
|
15
|
+
return this.api.queryChartResult({
|
|
16
|
+
chart,
|
|
17
|
+
onSuccess,
|
|
18
|
+
onFail
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
21
|
const table = getTableById(tables, chart.config.table_id);
|
|
@@ -35,8 +34,8 @@ class Context {
|
|
|
35
34
|
onFail && onFail(error);
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
37
|
+
this.queryUsers = (emails, callback) => {
|
|
38
|
+
this.api.queryUsers(emails, callback);
|
|
40
39
|
};
|
|
41
40
|
this.api = null;
|
|
42
41
|
this.settings = {};
|
|
@@ -47,7 +46,6 @@ class Context {
|
|
|
47
46
|
const {
|
|
48
47
|
config,
|
|
49
48
|
api,
|
|
50
|
-
usersAPI,
|
|
51
49
|
collaborators,
|
|
52
50
|
collaboratorManager
|
|
53
51
|
} = props;
|
|
@@ -57,8 +55,8 @@ class Context {
|
|
|
57
55
|
if (!api) {
|
|
58
56
|
throw new Error('Props api is required');
|
|
59
57
|
}
|
|
60
|
-
if (!
|
|
61
|
-
throw new Error('Props
|
|
58
|
+
if (!api.queryUsers) {
|
|
59
|
+
throw new Error('Props queryUsers api is required');
|
|
62
60
|
}
|
|
63
61
|
this.api = api;
|
|
64
62
|
this.settings = config || {};
|
package/dist/editor/index.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import View from '../view';
|
|
2
|
+
import View, { defaultProps, propTypes } from '../view';
|
|
4
3
|
import Settings from '../settings';
|
|
5
4
|
import './index.css';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
render() {
|
|
12
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
13
|
-
className: "sea-chart-editor"
|
|
14
|
-
}, /*#__PURE__*/React.createElement(View, this.props), /*#__PURE__*/React.createElement(Settings, this.props));
|
|
15
|
-
}
|
|
5
|
+
function Editor(props) {
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
7
|
+
className: "sea-chart-editor"
|
|
8
|
+
}, /*#__PURE__*/React.createElement(View, props), /*#__PURE__*/React.createElement(Settings, props));
|
|
16
9
|
}
|
|
17
|
-
Editor.defaultProps =
|
|
18
|
-
isStatisticalData: true,
|
|
19
|
-
canvasStyle: {},
|
|
20
|
-
tables: [],
|
|
21
|
-
chart: {
|
|
22
|
-
id: '',
|
|
23
|
-
config: {},
|
|
24
|
-
style_config: {}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
10
|
+
Editor.defaultProps = defaultProps;
|
|
27
11
|
export default Editor;
|
|
@@ -1376,7 +1376,7 @@ ChartUtils.convertConfig = config => {
|
|
|
1376
1376
|
ChartUtils.imEmptyChartResult = chartResult => {
|
|
1377
1377
|
return !chartResult || !chartResult.result && chartResult.result !== 0 || Array.isArray(chartResult.result) && chartResult.result.length === 0;
|
|
1378
1378
|
};
|
|
1379
|
-
ChartUtils.calculateChart = (chart, tables, callback
|
|
1379
|
+
ChartUtils.calculateChart = (chart, tables, callback) => {
|
|
1380
1380
|
if (!_class.isValidExistChart(tables, chart)) {
|
|
1381
1381
|
const tip_message = 'Please_complete_the_chart_configuration_first';
|
|
1382
1382
|
return callback && callback('', tip_message, null);
|
|
@@ -1422,26 +1422,24 @@ ChartUtils.calculateChart = (chart, tables, callback, isChartData) => {
|
|
|
1422
1422
|
error_message
|
|
1423
1423
|
} = res.data;
|
|
1424
1424
|
if (success) {
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
callback && callback('', tipMessage, null);
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
const chartResult = _class.sqlResult2JavaScript(newChart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1432
|
-
if (_class.imEmptyChartResult(chartResult)) {
|
|
1433
|
-
callback && callback('', tipMessage, null);
|
|
1434
|
-
return;
|
|
1435
|
-
}
|
|
1436
|
-
callback && callback('', '', {
|
|
1437
|
-
...chartResult,
|
|
1438
|
-
groupbyColumn,
|
|
1439
|
-
columnGroupbyColumn,
|
|
1440
|
-
summaryColumn,
|
|
1441
|
-
chartTableColumns
|
|
1442
|
-
});
|
|
1425
|
+
const tipMessage = 'There_are_no_statistic_results_yet';
|
|
1426
|
+
if (!Array.isArray(sqlRows) || sqlRows.length === 0) {
|
|
1427
|
+
callback && callback('', tipMessage, null);
|
|
1443
1428
|
return;
|
|
1444
1429
|
}
|
|
1430
|
+
const chartResult = _class.sqlResult2JavaScript(newChart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1431
|
+
if (_class.imEmptyChartResult(chartResult)) {
|
|
1432
|
+
callback && callback('', tipMessage, null);
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
callback && callback('', '', {
|
|
1436
|
+
...chartResult,
|
|
1437
|
+
groupbyColumn,
|
|
1438
|
+
columnGroupbyColumn,
|
|
1439
|
+
summaryColumn,
|
|
1440
|
+
chartTableColumns
|
|
1441
|
+
});
|
|
1442
|
+
return;
|
|
1445
1443
|
}
|
|
1446
1444
|
callback && callback(error_message, '', null);
|
|
1447
1445
|
},
|
package/dist/view/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
import classnames from 'classnames';
|
|
3
4
|
import shallowEqual from 'shallowequal';
|
|
4
5
|
import context from '../context';
|
|
@@ -52,8 +53,7 @@ class View extends React.PureComponent {
|
|
|
52
53
|
let isNeedRequestData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
53
54
|
const {
|
|
54
55
|
tables,
|
|
55
|
-
chart
|
|
56
|
-
isStatisticalData
|
|
56
|
+
chart
|
|
57
57
|
} = _this.props;
|
|
58
58
|
const {
|
|
59
59
|
data
|
|
@@ -62,7 +62,7 @@ class View extends React.PureComponent {
|
|
|
62
62
|
ChartUtils.calculateStaticChart(tables, chart, data, _this.callback);
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
ChartUtils.calculateChart(chart, tables, _this.callback
|
|
65
|
+
ChartUtils.calculateChart(chart, tables, _this.callback);
|
|
66
66
|
};
|
|
67
67
|
this.state = {
|
|
68
68
|
isCalculated: false,
|
|
@@ -155,8 +155,7 @@ class View extends React.PureComponent {
|
|
|
155
155
|
})));
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
isStatisticalData: true,
|
|
158
|
+
const defaultProps = {
|
|
160
159
|
canvasStyle: {},
|
|
161
160
|
tables: [],
|
|
162
161
|
chart: {
|
|
@@ -165,4 +164,13 @@ View.defaultProps = {
|
|
|
165
164
|
style_config: {}
|
|
166
165
|
}
|
|
167
166
|
};
|
|
168
|
-
|
|
167
|
+
const propTypes = {
|
|
168
|
+
canvasStyle: PropTypes.object,
|
|
169
|
+
config: PropTypes.object.isRequired,
|
|
170
|
+
chart: PropTypes.object.isRequired,
|
|
171
|
+
tables: PropTypes.array.isRequired,
|
|
172
|
+
className: PropTypes.string
|
|
173
|
+
};
|
|
174
|
+
View.defaultProps = defaultProps;
|
|
175
|
+
export default View;
|
|
176
|
+
export { defaultProps, propTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sea-chart",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@antv/data-set": "0.11.8",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@antv/scale": "0.3.14",
|
|
21
21
|
"babel-plugin-on-demand-loading": "^0.0.9",
|
|
22
22
|
"dtable-ui-component": "~4.4.0",
|
|
23
|
-
"dtable-utils": "~4.
|
|
23
|
+
"dtable-utils": "~4.4.*",
|
|
24
24
|
"prop-types": "15.8.1",
|
|
25
25
|
"react": "^17.0.0",
|
|
26
26
|
"react-dom": "^17.0.0"
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"css-minimizer-webpack-plugin": "5.0.1",
|
|
93
93
|
"dotenv": "6.2.0",
|
|
94
94
|
"dotenv-expand": "5.1.0",
|
|
95
|
+
"dtable-utils": "4.4.0",
|
|
95
96
|
"ejs": "3.1.8",
|
|
96
97
|
"eslint": "^6.8.0",
|
|
97
98
|
"eslint-config-react-app": "^5.0.2",
|