sea-chart 1.1.31 → 1.1.32

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/dist/context.js CHANGED
@@ -19,6 +19,8 @@ class Context {
19
19
  onFail
20
20
  });
21
21
  }
22
+
23
+ // use default api to get chart result data
22
24
  const table = getTableById(tables, chart.config.table_id);
23
25
  const currentView = table.views.find(view => view._id === chart.config.view_id);
24
26
  // use default view
@@ -1,41 +1,51 @@
1
+ import { uniqueId } from 'lodash-es';
1
2
  import context from '../../context';
2
3
  import { getErrorMessage } from '..';
3
4
  import intl from '../../intl';
5
+ import concurrencyManager from '../concurrency-manager';
4
6
  import BaseUtils from './base-utils';
5
7
  import SQLStatisticsUtils from './sql-statistics-utils';
6
8
  import OriginalDataUtils from './original-data-utils';
7
9
  class ChartUtils {}
8
- ChartUtils.calculateChart = (chart, value, callback) => {
10
+ ChartUtils.calculateChart = async (chart, value, callback) => {
9
11
  if (!BaseUtils.isValidExistChart(value.tables, chart)) {
10
12
  const tip_message = 'Please_complete_the_chart_configuration_first';
11
13
  return callback && callback('', tip_message, null);
12
14
  }
13
- context.queryChartResult({
14
- chart,
15
- tables: value.tables,
16
- onSuccess: async function (res) {
17
- var _res$data;
18
- let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
19
- const {
20
- success,
21
- error_message
22
- } = res.data;
23
- if (!success) {
24
- const errMsg = intl.get(error_message);
25
- callback && callback(errMsg, '', null);
26
- return;
15
+ const id = uniqueId();
16
+ const requestData = () => {
17
+ context.queryChartResult({
18
+ chart,
19
+ tables: value.tables,
20
+ onSuccess: async function (res) {
21
+ var _res$data;
22
+ let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
23
+ // reolve request and start next request
24
+ concurrencyManager.removeRequest(id);
25
+ const {
26
+ success,
27
+ error_message
28
+ } = res.data;
29
+ if (!success) {
30
+ const errMsg = intl.get(error_message);
31
+ callback && callback(errMsg, '', null);
32
+ return;
33
+ }
34
+ if (dataSources === OriginalDataUtils.dataSources) {
35
+ OriginalDataUtils.calculateChart(chart, value, callback);
36
+ return;
37
+ }
38
+ await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
39
+ },
40
+ onFail: err => {
41
+ concurrencyManager.removeRequest(id);
42
+ let errorMessage = getErrorMessage(err);
43
+ callback && callback(errorMessage, '', null);
27
44
  }
28
- if (dataSources === OriginalDataUtils.dataSources) {
29
- OriginalDataUtils.calculateChart(chart, value, callback);
30
- return;
31
- }
32
- await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
33
- },
34
- onFail: err => {
35
- let errorMessage = getErrorMessage(err);
36
- callback && callback(errorMessage, '', null);
37
- }
38
- });
45
+ });
46
+ };
47
+ requestData.id = id;
48
+ concurrencyManager.applyRequest(requestData);
39
49
  };
40
50
  ChartUtils.calculateStaticChart = (chart, value, statisticalResult, callback) => {
41
51
  if (!BaseUtils.isValidExistChart(value.tables, chart)) {
@@ -0,0 +1,33 @@
1
+ class ConcurrencyManager {
2
+ constructor(concurrentCount) {
3
+ this.concurrentCount = concurrentCount;
4
+ this.requestList = [];
5
+ this.queue = [];
6
+ }
7
+ applyRequest(req) {
8
+ if (this.requestList.length < this.concurrentCount) {
9
+ this.requestList.push(req);
10
+ req();
11
+ } else {
12
+ this.queue.push({
13
+ req
14
+ });
15
+ }
16
+ }
17
+ removeRequest(id) {
18
+ const index = this.requestList.findIndex(req => req.id === id);
19
+ if (index > -1) {
20
+ this.requestList.splice(index, 1);
21
+ }
22
+ if (this.queue.length > 0) {
23
+ const {
24
+ req
25
+ } = this.queue.shift();
26
+ this.requestList.push(req);
27
+ req();
28
+ }
29
+ }
30
+ }
31
+ // request once a time
32
+ const concurrencyManager = new ConcurrencyManager(1);
33
+ export default concurrencyManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",