sea-chart 0.0.4 → 0.0.6

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 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
- 3. 配置以及测试用例
15
- > 可以将自定义页面中关于统计元素的配置拿过来
16
-
17
- 3.1 配置图标
18
- > /example/body/charts.js
19
- ```
20
- const CHARTS = [
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
- 5. 追加渲染机制到 View 组件中
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/api/index.js CHANGED
@@ -80,24 +80,7 @@ class SeaChartAPI {
80
80
  this.instance = new SeaChartAPI(config);
81
81
  return this.instance;
82
82
  }
83
- async init(config) {
84
- if (config && typeof config === 'object') {
85
- const {
86
- appName,
87
- accessToken,
88
- dtableUuid,
89
- dtableServer,
90
- dtableSocket,
91
- dtableDb
92
- } = config;
93
- this.appName = appName;
94
- this.accessToken = accessToken;
95
- this.dtableUuid = dtableUuid;
96
- this.dtableServer = dtableServer.replace(/\/+$/, '') + '/';
97
- this.dtableSocket = dtableSocket.replace(/\/+$/, '') + '/';
98
- this.dtableDB = dtableDb.replace(/\/+$/, '') + '/';
99
- return;
100
- }
83
+ async init() {
101
84
  const accessTokenRes = await this.getDTableAccessToken();
102
85
  const {
103
86
  app_name,
package/dist/context.js CHANGED
@@ -3,13 +3,21 @@ import CollaboratorManager from './utils/collaborator-manager';
3
3
  import { ChartDataSQL } from './utils';
4
4
  class Context {
5
5
  constructor() {
6
- this.queryResultFromDB = _ref => {
6
+ this.queryChartResult = _ref => {
7
7
  let {
8
8
  chart,
9
9
  tables,
10
10
  onSuccess,
11
11
  onFail
12
12
  } = _ref;
13
+ // used custom api to get chart result data
14
+ if (this.api.queryChartResult) {
15
+ return this.api.queryChartResult({
16
+ chart,
17
+ onSuccess,
18
+ onFail
19
+ });
20
+ }
13
21
  const table = getTableById(tables, chart.config.table_id);
14
22
  const chartDataSQL = new ChartDataSQL({
15
23
  table,
@@ -26,12 +34,11 @@ class Context {
26
34
  onFail && onFail(error);
27
35
  });
28
36
  };
29
- this.queryUser = (emails, callback) => {
30
- this.userApi.queryUsers(emails, callback);
37
+ this.queryUsers = (emails, callback) => {
38
+ this.api.queryUsers(emails, callback);
31
39
  };
32
40
  this.api = null;
33
41
  this.settings = {};
34
- this.hasInit = false;
35
42
  this.collaborators = [];
36
43
  this.collaboratorManager = null;
37
44
  }
@@ -39,19 +46,17 @@ class Context {
39
46
  const {
40
47
  config,
41
48
  api,
42
- usersAPI,
43
49
  collaborators,
44
50
  collaboratorManager
45
51
  } = props;
46
- if (this.hasInit) return;
47
52
  if (!config) {
48
53
  throw new Error('Props config is required');
49
54
  }
50
55
  if (!api) {
51
56
  throw new Error('Props api is required');
52
57
  }
53
- if (!usersAPI) {
54
- throw new Error('Props usersAPI is required');
58
+ if (!api.queryUsers) {
59
+ throw new Error('Props queryUsers api is required');
55
60
  }
56
61
  this.api = api;
57
62
  this.settings = config || {};
@@ -0,0 +1,23 @@
1
+ .sea-chart-editor {
2
+ flex: 1;
3
+ display: flex;
4
+ min-height: 0;
5
+ min-width: 0;
6
+ }
7
+
8
+ .sea-chart-editor .sea-chart-formatter {
9
+ flex: 1;
10
+ display: flex;
11
+ min-height: 0;
12
+ min-width: 0;
13
+ }
14
+
15
+ .sea-chart-editor .sea-chart-settings {
16
+ width: 300px;
17
+ height: 100%;
18
+ background-color: #fff;
19
+ margin-left: 16px;
20
+ border-top: 1px solid #e4e4e4;
21
+ border-left: 1px solid #e4e4e4;
22
+ border-right: 1px solid #e4e4e4;
23
+ }
@@ -1,41 +1,11 @@
1
1
  import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import classnames from 'classnames';
4
- import context from '../context';
5
- import View from '../view';
2
+ import View, { defaultProps, propTypes } from '../view';
6
3
  import Settings from '../settings';
7
4
  import './index.css';
8
- class Editor extends React.PureComponent {
9
- constructor(props) {
10
- super(props);
11
- context.init(props);
12
- }
13
- render() {
14
- const {
15
- settingsTarget
16
- } = this.props;
17
- let settingsTargetNode = '';
18
- if (settingsTarget) {
19
- settingsTargetNode = document.getElementById(settingsTarget);
20
- if (settingsTargetNode) {
21
- ReactDOM.render( /*#__PURE__*/React.createElement(Settings, this.props), settingsTargetNode);
22
- }
23
- }
24
- return /*#__PURE__*/React.createElement("div", {
25
- className: classnames('sea-chart-editor', {
26
- 'd-flex': !settingsTargetNode
27
- })
28
- }, /*#__PURE__*/React.createElement(View, this.props), !settingsTargetNode && /*#__PURE__*/React.createElement(Settings, this.props));
29
- }
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));
30
9
  }
31
- Editor.defaultProps = {
32
- isStatisticalData: true,
33
- canvasStyle: {},
34
- tables: [],
35
- chart: {
36
- id: '',
37
- config: {},
38
- style_config: {}
39
- }
40
- };
10
+ Editor.defaultProps = defaultProps;
41
11
  export default Editor;
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import SeaChartAPI from './api';
2
- import { CHART_TYPES } from './constants/type';
2
+ import { CHART_TYPE, CHART_TYPES } from './constants/type';
3
+ import { ChartModel } from './model';
3
4
  import View from './view';
4
5
  import Editor from './editor';
5
6
  import Settings, { StyleSettings } from './settings';
6
7
  import { ChartDataSQL } from './utils';
7
8
  import Context from './context';
8
9
  export default View;
9
- export { SeaChartAPI, CHART_TYPES, View, Editor, Settings, StyleSettings, Context, ChartDataSQL };
10
+ export { SeaChartAPI, CHART_TYPE, CHART_TYPES, View, Editor, Settings, StyleSettings, Context, ChartModel, ChartDataSQL };
@@ -544,6 +544,6 @@ const DataSettings = _ref => {
544
544
  value: getSelectedGroupType(),
545
545
  onChange: onGroupTypeChange,
546
546
  options: groupTypeOptions
547
- })), renderAdvancedStatistic);
547
+ })), renderAdvancedStatistic());
548
548
  };
549
549
  export default DataSettings;
@@ -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, isChartData) => {
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);
@@ -1412,7 +1412,7 @@ ChartUtils.calculateChart = (chart, tables, callback, isChartData) => {
1412
1412
  const error_message = 'There_are_some_problems_with_the_filters';
1413
1413
  return callback && callback(error_message, '', null);
1414
1414
  }
1415
- context.queryResultFromDB({
1415
+ context.queryChartResult({
1416
1416
  chart,
1417
1417
  tables,
1418
1418
  onSuccess: res => {
@@ -1422,26 +1422,24 @@ ChartUtils.calculateChart = (chart, tables, callback, isChartData) => {
1422
1422
  error_message
1423
1423
  } = res.data;
1424
1424
  if (success) {
1425
- if (isChartData) {
1426
- const tipMessage = 'There_are_no_statistic_results_yet';
1427
- if (!Array.isArray(sqlRows) || sqlRows.length === 0) {
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
  },
@@ -1568,11 +1566,13 @@ ChartUtils.isChartEqual = (preChartElement, curChartElement) => {
1568
1566
  return shallowEqual(preChartElement.config, curChartElement.config);
1569
1567
  };
1570
1568
  ChartUtils.isChartStyleChange = (preChartElement, curChartElement) => {
1569
+ var _preChartElement$heig, _curChartElement$heig;
1571
1570
  const elementType = preChartElement.config.type;
1572
1571
  if (elementType !== curChartElement.config.type) return false;
1573
- if (preChartElement.height.value !== curChartElement.height.value) return true;
1574
- if (preChartElement.left_in_unit !== curChartElement.left_in_unit) return true;
1575
- if (preChartElement.width_in_unit !== curChartElement.width_in_unit) return true;
1572
+ // used for app
1573
+ if ((preChartElement === null || preChartElement === void 0 ? void 0 : (_preChartElement$heig = preChartElement.height) === null || _preChartElement$heig === void 0 ? void 0 : _preChartElement$heig.value) !== (curChartElement === null || curChartElement === void 0 ? void 0 : (_curChartElement$heig = curChartElement.height) === null || _curChartElement$heig === void 0 ? void 0 : _curChartElement$heig.value)) return true;
1574
+ if ((preChartElement === null || preChartElement === void 0 ? void 0 : preChartElement.left_in_unit) !== (curChartElement === null || curChartElement === void 0 ? void 0 : curChartElement.left_in_unit)) return true;
1575
+ if ((preChartElement === null || preChartElement === void 0 ? void 0 : preChartElement.width_in_unit) !== (curChartElement === null || curChartElement === void 0 ? void 0 : curChartElement.width_in_unit)) return true;
1576
1576
  if (!ObjectUtils.isSameObject(preChartElement.style_config, curChartElement.style_config)) return true;
1577
1577
  return !CHART_STYLE_SETTING_KEYS.every(key => preChartElement.config[key] === curChartElement.config[key]);
1578
1578
  };
@@ -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, isStatisticalData);
65
+ ChartUtils.calculateChart(chart, tables, _this.callback);
66
66
  };
67
67
  this.state = {
68
68
  isCalculated: false,
@@ -70,7 +70,6 @@ class View extends React.PureComponent {
70
70
  errorMessage: '',
71
71
  tipMessage: ''
72
72
  };
73
- console.log(props);
74
73
  context.init(props);
75
74
  }
76
75
  componentDidMount() {
@@ -156,8 +155,7 @@ class View extends React.PureComponent {
156
155
  })));
157
156
  }
158
157
  }
159
- View.defaultProps = {
160
- isStatisticalData: true,
158
+ const defaultProps = {
161
159
  canvasStyle: {},
162
160
  tables: [],
163
161
  chart: {
@@ -166,4 +164,13 @@ View.defaultProps = {
166
164
  style_config: {}
167
165
  }
168
166
  };
169
- export default View;
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.4",
3
+ "version": "0.0.6",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",
@@ -126,6 +126,7 @@
126
126
  "raf": "3.4.0",
127
127
  "react": "17.0.0",
128
128
  "react-app-polyfill": "^1.0.4",
129
+ "react-cookies": "0.1.1",
129
130
  "react-dev-utils": "^12.0.1",
130
131
  "react-dom": "17.0.0",
131
132
  "react-hot-loader": "4.13.1",