sea-chart 0.0.30 → 0.0.31-beta

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
@@ -1,7 +1,7 @@
1
1
  import { getTableById } from 'dtable-utils';
2
2
  import CollaboratorManager from './utils/collaborator-manager';
3
3
  import { ChartDataSQL } from './utils';
4
- import { CHART_TYPE_IMAGE } from './constants';
4
+ import { CHART_TYPE, CHART_TYPE_IMAGE } from './constants';
5
5
  class Context {
6
6
  constructor() {
7
7
  this.queryChartResult = async _ref => {
@@ -32,28 +32,55 @@ class Context {
32
32
  onFail && onFail(error);
33
33
  return;
34
34
  }
35
-
36
- // Custom bar
37
- if (Array.isArray(sql) && sql.length !== 0) {
38
- for (let i = 0; i < sql.length; i++) {
39
- await this.api.sqlQuery(sql[i].sqlString).then(res => {
40
- sql[i].res = res;
41
- }).catch(error => {
42
- onFail && onFail(error);
35
+ const type = chart.config.type;
36
+ if (type === CHART_TYPE.BAR_CUSTOM) {
37
+ let allPromises = [];
38
+ Array.isArray(sql) && sql.forEach(item => {
39
+ if (item) {
40
+ const res = this.api.sqlQuery(item);
41
+ allPromises.push(res);
42
+ } else {
43
+ allPromises.push(new Promise((resolve, reject) => {
44
+ return resolve({
45
+ data: {
46
+ success: true,
47
+ results: []
48
+ }
49
+ });
50
+ }));
51
+ }
52
+ });
53
+ let newRes = {
54
+ data: {
55
+ success: true,
56
+ results: []
57
+ }
58
+ };
59
+ return Promise.all(allPromises).then(allRes => {
60
+ if (!allRes.every(item => item.data.success)) {
61
+ onFail && onFail('Network_error');
62
+ return;
63
+ }
64
+ allRes.forEach(res => {
65
+ const {
66
+ results
67
+ } = res.data;
68
+ newRes.data.results.push(results);
43
69
  });
44
- }
45
- onSuccess && onSuccess(sql);
46
- return;
70
+ onSuccess && onSuccess(newRes);
71
+ }).catch(error => {
72
+ onFail && onFail(error);
73
+ });
47
74
  }
48
75
  return this.api.sqlQuery(sql).then(res => {
49
76
  onSuccess && onSuccess(res);
50
77
  }).catch(error => {
51
78
  var _error$response, _error$response$data;
52
79
  // if geolocation format is wrong, still display the chart
53
- if (chart.config.type.includes('map') && (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_message.includes('invalid geolocation format'))) {
80
+ if (type.includes('map') && (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_message.includes('invalid geolocation format'))) {
54
81
  var _error$response2, _error$response2$data;
55
82
  console.error(error === null || error === void 0 ? void 0 : (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.message);
56
- onSuccess({
83
+ onSuccess && onSuccess({
57
84
  data: {
58
85
  results: [],
59
86
  success: true
@@ -1,4 +1,4 @@
1
- var _class;
1
+ var _BaseUtils;
2
2
  import shallowEqual from 'shallowequal';
3
3
  import dayjs from 'dayjs';
4
4
  import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, getDateDisplayString, getNumberDisplayString, getOption, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber, isNumericColumn, isDateColumn, sortText, sortNumber, sortDate, sortSingleSelect, sortFormula, getColumnOptions, DateUtils, getGeolocationDisplayString, getFormulaDisplayString } from 'dtable-utils';
@@ -31,7 +31,7 @@ class BaseUtils {
31
31
  };
32
32
  }
33
33
  }
34
- _class = BaseUtils;
34
+ _BaseUtils = BaseUtils;
35
35
  // valid chart
36
36
  BaseUtils.isValidCombinationChart = (config, table) => {
37
37
  const summaryLeftColumnKey = config.y_axis_left_summary_column;
@@ -101,7 +101,7 @@ BaseUtils.isValidExistChart = (tables, chart) => {
101
101
  if (!groupByColumnKey) return false;
102
102
  if (!getTableColumnByKey(table, groupByColumnKey)) return false;
103
103
  if (type === CHART_TYPE.COMBINATION) {
104
- const isExist = _class.isValidCombinationChart(config, table);
104
+ const isExist = _BaseUtils.isValidCombinationChart(config, table);
105
105
  if (!isExist) return false;
106
106
  } else {
107
107
  const summaryColumnKey = config.summary_column_key || config.y_axis_summary_column_key || config.horizontal_axis_column_key;
@@ -193,7 +193,7 @@ BaseUtils.getGroupName = (tables, chart) => {
193
193
  config
194
194
  } = chart;
195
195
  const table = getTableById(tables, config.table_id);
196
- const column = _class.getGroupColumn(table, chart);
196
+ const column = _BaseUtils.getGroupColumn(table, chart);
197
197
  return column.name;
198
198
  };
199
199
  BaseUtils.getChartGroups = charts => {
@@ -228,7 +228,7 @@ BaseUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue)
228
228
  const {
229
229
  data
230
230
  } = summaryColumn;
231
- if (_class.isDateSummaryColumn(summaryColumn)) {
231
+ if (_BaseUtils.isDateSummaryColumn(summaryColumn)) {
232
232
  if (typeof summaryValue !== 'string') return summaryValue;
233
233
 
234
234
  // Compatible with previous data
@@ -263,7 +263,7 @@ BaseUtils.getSummaryValue = (_ref, currentValue, nextValue) => {
263
263
  summaryMethod,
264
264
  summaryColumn
265
265
  } = _ref;
266
- if (_class.isDateSummaryColumn(summaryColumn)) {
266
+ if (_BaseUtils.isDateSummaryColumn(summaryColumn)) {
267
267
  if (summaryMethod === 'MAX') {
268
268
  if (currentValue && nextValue) {
269
269
  return dayjs(currentValue).isBefore(nextValue) ? nextValue : currentValue;
@@ -340,7 +340,7 @@ BaseUtils.isChartStyleChanged = (prevElement, currElement) => {
340
340
  return !shallowEqual(prevBorder, currBorder) || !shallowEqual(prevTitle, currTitle);
341
341
  };
342
342
  BaseUtils.shouldChartComponentUpdate = (prevProps, currentProps) => {
343
- return !_class.isChartEqual(prevProps.chart, currentProps.chart) ||
343
+ return !_BaseUtils.isChartEqual(prevProps.chart, currentProps.chart) ||
344
344
  // chart attributes changed
345
345
  !shallowEqual(prevProps.canvasStyle, currentProps.canvasStyle) ||
346
346
  // canvasStyle
@@ -350,7 +350,7 @@ BaseUtils.shouldChartComponentUpdate = (prevProps, currentProps) => {
350
350
  // columnGroupbyColumn's data、type changed or not exist
351
351
  !shallowEqual(prevProps.summaryColumn, currentProps.summaryColumn) ||
352
352
  // summaryColumn's data、type changed or not exist
353
- _class._isChartDataChange(prevProps, currentProps) || _class.isChartStyleChanged(prevProps.chart, currentProps.chart);
353
+ _BaseUtils._isChartDataChange(prevProps, currentProps) || _BaseUtils.isChartStyleChanged(prevProps.chart, currentProps.chart);
354
354
  };
355
355
  BaseUtils._isCombinationDataChange = (prevResult, currentResult) => {
356
356
  if (prevResult.value_left !== currentResult.value_left) return true;
@@ -366,7 +366,7 @@ BaseUtils._isChartDataChange = (prevProps, currentProps) => {
366
366
  result: oldData
367
367
  } = currentProps;
368
368
  if (chart.config.type === CHART_TYPE.COMBINATION) {
369
- return _class._isCombinationDataChange(newData, oldData);
369
+ return _BaseUtils._isCombinationDataChange(newData, oldData);
370
370
  }
371
371
  if (!newData && !oldData) return false;
372
372
  if (!newData && oldData || newData && !oldData) return true;
@@ -421,7 +421,7 @@ BaseUtils.getPieColorSet = (tables, chart, result) => {
421
421
  table_id,
422
422
  groupby_column_key: column_id
423
423
  } = chart.config;
424
- const column = _class.getColumn(tables, table_id, column_id);
424
+ const column = _BaseUtils.getColumn(tables, table_id, column_id);
425
425
  const {
426
426
  type: columnType
427
427
  } = column || {};
@@ -488,7 +488,7 @@ BaseUtils.formatPieChartData = (data, chart, tables) => {
488
488
  const value = item.value;
489
489
  if (value >= threshold) {
490
490
  item.percent = String(Number.parseFloat(value / sum * 100).toFixed(1)) + '%';
491
- const color = _class.getPieColor(column, index, item);
491
+ const color = _BaseUtils.getPieColor(column, index, item);
492
492
  item.color = color;
493
493
  colorSet.push(color);
494
494
  filteredData.push(item);
@@ -603,7 +603,7 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
603
603
  };
604
604
  BaseUtils.updateTableViewList = (result, column, nameKey, colorKey) => {
605
605
  result.forEach(result => {
606
- _class.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey);
606
+ _BaseUtils.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey);
607
607
  });
608
608
  };
609
609
  // sort chart
@@ -739,10 +739,10 @@ BaseUtils.formatGroupsLabel = (results, chart, tables) => {
739
739
  group_name
740
740
  } = item;
741
741
  if (groupbyColumn) {
742
- _class.convertResultName(item, groupbyColumn, name, 'name', 'color');
742
+ _BaseUtils.convertResultName(item, groupbyColumn, name, 'name', 'color');
743
743
  }
744
744
  if (columnGroupbyColumn) {
745
- _class.convertResultName(item, columnGroupbyColumn, group_name, 'group_name', 'group_color');
745
+ _BaseUtils.convertResultName(item, columnGroupbyColumn, group_name, 'group_name', 'group_color');
746
746
  }
747
747
  });
748
748
  };
@@ -1166,19 +1166,19 @@ BaseUtils.getSummaryResult = function (results, summaryMethod) {
1166
1166
  switch (summaryMethod) {
1167
1167
  case CHART_SUMMARY_TYPE.MAX:
1168
1168
  {
1169
- return _class.getMax(numericResults);
1169
+ return _BaseUtils.getMax(numericResults);
1170
1170
  }
1171
1171
  case CHART_SUMMARY_TYPE.MIN:
1172
1172
  {
1173
- return _class.getMin(numericResults);
1173
+ return _BaseUtils.getMin(numericResults);
1174
1174
  }
1175
1175
  case CHART_SUMMARY_TYPE.SUM:
1176
1176
  {
1177
- return _class.getSum(numericResults, precision);
1177
+ return _BaseUtils.getSum(numericResults, precision);
1178
1178
  }
1179
1179
  case CHART_SUMMARY_TYPE.MEAN:
1180
1180
  {
1181
- return _class.getMean(numericResults, precision);
1181
+ return _BaseUtils.getMean(numericResults, precision);
1182
1182
  }
1183
1183
  case CHART_SUMMARY_TYPE.Distinct_values:
1184
1184
  {
@@ -1225,7 +1225,7 @@ BaseUtils.getSum = function (list) {
1225
1225
  BaseUtils.getMean = function (list) {
1226
1226
  let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
1227
1227
  if (list.length === 0) return 0;
1228
- const sum = _class.getSum(list);
1228
+ const sum = _BaseUtils.getSum(list);
1229
1229
  return Number.parseFloat((sum / list.length).toFixed(precision));
1230
1230
  };
1231
1231
  BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod, useDataDb, dbDateKey, valueKey) => {
@@ -1271,11 +1271,11 @@ BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod,
1271
1271
  // }
1272
1272
 
1273
1273
  if (summaryType === CHART_SUMMARY_TYPE.ADVANCED) {
1274
- comparedValue = _class.getSummaryResult(comparedValue, summaryMethod);
1275
- compareValue = _class.getSummaryResult(compareValue, summaryMethod);
1274
+ comparedValue = _BaseUtils.getSummaryResult(comparedValue, summaryMethod);
1275
+ compareValue = _BaseUtils.getSummaryResult(compareValue, summaryMethod);
1276
1276
  } else {
1277
- compareValue = _class.getSummaryResult(compareValue, 'Sum');
1278
- comparedValue = _class.getSummaryResult(comparedValue, 'Sum');
1277
+ compareValue = _BaseUtils.getSummaryResult(compareValue, 'Sum');
1278
+ comparedValue = _BaseUtils.getSummaryResult(comparedValue, 'Sum');
1279
1279
  }
1280
1280
  return {
1281
1281
  compareValue,
@@ -12,16 +12,8 @@ ChartUtils.calculateChart = (chart, value, callback) => {
12
12
  chart,
13
13
  tables: value.tables,
14
14
  onSuccess: function (res) {
15
+ var _res$data;
15
16
  let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
16
- // Custom Bar
17
- if (Array.isArray(res)) {
18
- if (dataSources === OriginalDataUtils.dataSources) {
19
- OriginalDataUtils.calculateChart(chart, value, callback);
20
- return;
21
- }
22
- SQLStatisticsUtils.calculateChart(chart, value, callback, res);
23
- return;
24
- }
25
17
  const {
26
18
  success,
27
19
  error_message
@@ -34,7 +26,7 @@ ChartUtils.calculateChart = (chart, value, callback) => {
34
26
  OriginalDataUtils.calculateChart(chart, value, callback);
35
27
  return;
36
28
  }
37
- SQLStatisticsUtils.calculateChart(chart, value, callback, res);
29
+ 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) || []);
38
30
  },
39
31
  onFail: err => {
40
32
  let errorMessage = String(err) || 'Network_error';
@@ -1,4 +1,4 @@
1
- var _class;
1
+ var _OriginalDataUtils;
2
2
  import { getTableById, getViewById } from 'dtable-utils';
3
3
  import PivotTableCalculator from './pivot-table-calculator';
4
4
  import BasicChartCalculator from './basic-chart-calculator';
@@ -34,7 +34,7 @@ const calculatorMap = {
34
34
  [CHART_TYPE.DASHBOARD]: DashboardCalculator
35
35
  };
36
36
  class OriginalDataUtils {}
37
- _class = OriginalDataUtils;
37
+ _OriginalDataUtils = OriginalDataUtils;
38
38
  OriginalDataUtils.dataSources = 'original_data';
39
39
  OriginalDataUtils.isValidExistChart = (tables, chart) => {
40
40
  const isValid = BaseUtils.isValidExistChart(tables || [], chart);
@@ -49,7 +49,7 @@ OriginalDataUtils.isValidExistChart = (tables, chart) => {
49
49
  return true;
50
50
  };
51
51
  OriginalDataUtils.calculateChart = async (chart, value, callback) => {
52
- if (!_class.isValidExistChart((value === null || value === void 0 ? void 0 : value.tables) || [], chart)) {
52
+ if (!_OriginalDataUtils.isValidExistChart((value === null || value === void 0 ? void 0 : value.tables) || [], chart)) {
53
53
  const tip_message = 'Please_complete_the_chart_configuration_first';
54
54
  return callback && callback('', tip_message, null);
55
55
  }
@@ -76,7 +76,7 @@ OriginalDataUtils.calculateChart = async (chart, value, callback) => {
76
76
  const chartTableColumns = table.columns;
77
77
  return callback && callback('', '', {
78
78
  result,
79
- data_sources: _class.dataSources,
79
+ data_sources: _OriginalDataUtils.dataSources,
80
80
  groupbyColumn,
81
81
  columnGroupbyColumn,
82
82
  summaryColumn,