sea-chart 0.0.31 → 0.0.33-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,5 @@
1
1
  import React from 'react';
2
+ import { getTableById } from 'dtable-utils';
2
3
  import intl from '../../intl';
3
4
  import Divider from '../widgets/divider';
4
5
  import CommonDataSettings from '../widgets/common-data-settings';
@@ -28,8 +29,8 @@ const MapDataSettings = _ref => {
28
29
  map_location
29
30
  } = chart.config;
30
31
  const isCountryLevel = map_level === MAP_LEVEL.COUNTRY;
31
- const selectedTable = tables.find(table => table._id === table_id);
32
- const locationColumns = selectedTable.columns.filter(column => [CHART_TYPE.WORLD_MAP, CHART_TYPE.WORLD_MAP_BUBBLE].includes(type) ? isWorldMapColumn(column) : isMapColumn(column));
32
+ const selectedTable = getTableById(tables, table_id);
33
+ const locationColumns = (selectedTable === null || selectedTable === void 0 ? void 0 : selectedTable.columns.filter(column => [CHART_TYPE.WORLD_MAP, CHART_TYPE.WORLD_MAP_BUBBLE].includes(type) ? isWorldMapColumn(column) : isMapColumn(column))) || [];
33
34
  function handleYAxisGroupSettingsChange(value) {
34
35
  const update = {};
35
36
  Object.keys(value).forEach(key => {
@@ -82,7 +82,7 @@ const DataSettings = _ref => {
82
82
  label: intl.get('Statistic_field'),
83
83
  selectedTableId: table_id,
84
84
  selectedColumnKey: column_key,
85
- onlySupportMirror: true,
85
+ isMirror: true,
86
86
  onGroupByChange: onXAxisColumnChange
87
87
  }), /*#__PURE__*/React.createElement(Switch, {
88
88
  key: "x_axis_include_empty_cells",
@@ -61,12 +61,12 @@ class GroupBy extends Component {
61
61
  this.getAvailableColumns = columns => {
62
62
  const {
63
63
  onlySupportDate,
64
- onlySupportMirror,
64
+ isMirror,
65
65
  onlySupportSingleSelect
66
66
  } = this.props;
67
67
  if (!columns || !Array.isArray(columns)) return [];
68
68
  let newColumns = [];
69
- if (onlySupportMirror) {
69
+ if (isMirror) {
70
70
  newColumns = columns.filter(column => MIRROR_COLUMN_LIST.includes(column.type));
71
71
  return newColumns;
72
72
  }
@@ -163,8 +163,10 @@ class GroupBy extends Component {
163
163
  };
164
164
  this.renderGroupBy = () => {
165
165
  const {
166
- selectedColumnKey
166
+ selectedColumnKey,
167
+ isMirror
167
168
  } = this.props;
169
+ if (isMirror) return null;
168
170
  if (!selectedColumnKey) return null;
169
171
  const groupbyColumn = getTableColumnByKey(this.selectedTable, selectedColumnKey);
170
172
  if (!groupbyColumn) return null;
@@ -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;
@@ -136,6 +136,9 @@ BaseUtils.getGroupColumn = (table, chart) => {
136
136
  if (type === CHART_TYPE.TREND) {
137
137
  return getTableColumnByKey(table, config.date_column_key);
138
138
  }
139
+ if (type === CHART_TYPE.HEAT_MAP) {
140
+ return getTableColumnByKey(table, config.time_column_key);
141
+ }
139
142
  return getTableColumnByKey(table, config.x_axis_column_key);
140
143
  };
141
144
  BaseUtils.getColumnGroupColumn = (table, chart) => {
@@ -154,6 +157,9 @@ BaseUtils.getColumnGroupColumn = (table, chart) => {
154
157
  if ([CHART_TYPE.MIRROR].includes(type)) {
155
158
  return getTableColumnByKey(table, config.group_column_key);
156
159
  }
160
+ if (type === CHART_TYPE.SCATTER) {
161
+ return getTableColumnByKey(table, config.column_groupby_column_key);
162
+ }
157
163
  return getTableColumnByKey(table, config.y_axis_summary_column_key);
158
164
  };
159
165
  BaseUtils.getSummaryColumn = (table, chart) => {
@@ -182,6 +188,10 @@ BaseUtils.getSummaryColumn = (table, chart) => {
182
188
  {
183
189
  return getTableColumnByKey(table, numeric_column_key);
184
190
  }
191
+ case CHART_TYPE.SCATTER:
192
+ {
193
+ return getTableColumnByKey(table, config.y_axis_column_key);
194
+ }
185
195
  default:
186
196
  {
187
197
  return getTableColumnByKey(table, summary_column_key);
@@ -193,7 +203,7 @@ BaseUtils.getGroupName = (tables, chart) => {
193
203
  config
194
204
  } = chart;
195
205
  const table = getTableById(tables, config.table_id);
196
- const column = _class.getGroupColumn(table, chart);
206
+ const column = _BaseUtils.getGroupColumn(table, chart);
197
207
  return column.name;
198
208
  };
199
209
  BaseUtils.getChartGroups = charts => {
@@ -228,7 +238,7 @@ BaseUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue)
228
238
  const {
229
239
  data
230
240
  } = summaryColumn;
231
- if (_class.isDateSummaryColumn(summaryColumn)) {
241
+ if (_BaseUtils.isDateSummaryColumn(summaryColumn)) {
232
242
  if (typeof summaryValue !== 'string') return summaryValue;
233
243
 
234
244
  // Compatible with previous data
@@ -263,7 +273,7 @@ BaseUtils.getSummaryValue = (_ref, currentValue, nextValue) => {
263
273
  summaryMethod,
264
274
  summaryColumn
265
275
  } = _ref;
266
- if (_class.isDateSummaryColumn(summaryColumn)) {
276
+ if (_BaseUtils.isDateSummaryColumn(summaryColumn)) {
267
277
  if (summaryMethod === 'MAX') {
268
278
  if (currentValue && nextValue) {
269
279
  return dayjs(currentValue).isBefore(nextValue) ? nextValue : currentValue;
@@ -340,7 +350,7 @@ BaseUtils.isChartStyleChanged = (prevElement, currElement) => {
340
350
  return !shallowEqual(prevBorder, currBorder) || !shallowEqual(prevTitle, currTitle);
341
351
  };
342
352
  BaseUtils.shouldChartComponentUpdate = (prevProps, currentProps) => {
343
- return !_class.isChartEqual(prevProps.chart, currentProps.chart) ||
353
+ return !_BaseUtils.isChartEqual(prevProps.chart, currentProps.chart) ||
344
354
  // chart attributes changed
345
355
  !shallowEqual(prevProps.canvasStyle, currentProps.canvasStyle) ||
346
356
  // canvasStyle
@@ -350,7 +360,7 @@ BaseUtils.shouldChartComponentUpdate = (prevProps, currentProps) => {
350
360
  // columnGroupbyColumn's data、type changed or not exist
351
361
  !shallowEqual(prevProps.summaryColumn, currentProps.summaryColumn) ||
352
362
  // summaryColumn's data、type changed or not exist
353
- _class._isChartDataChange(prevProps, currentProps) || _class.isChartStyleChanged(prevProps.chart, currentProps.chart);
363
+ _BaseUtils._isChartDataChange(prevProps, currentProps) || _BaseUtils.isChartStyleChanged(prevProps.chart, currentProps.chart);
354
364
  };
355
365
  BaseUtils._isCombinationDataChange = (prevResult, currentResult) => {
356
366
  if (prevResult.value_left !== currentResult.value_left) return true;
@@ -366,7 +376,7 @@ BaseUtils._isChartDataChange = (prevProps, currentProps) => {
366
376
  result: oldData
367
377
  } = currentProps;
368
378
  if (chart.config.type === CHART_TYPE.COMBINATION) {
369
- return _class._isCombinationDataChange(newData, oldData);
379
+ return _BaseUtils._isCombinationDataChange(newData, oldData);
370
380
  }
371
381
  if (!newData && !oldData) return false;
372
382
  if (!newData && oldData || newData && !oldData) return true;
@@ -421,7 +431,7 @@ BaseUtils.getPieColorSet = (tables, chart, result) => {
421
431
  table_id,
422
432
  groupby_column_key: column_id
423
433
  } = chart.config;
424
- const column = _class.getColumn(tables, table_id, column_id);
434
+ const column = _BaseUtils.getColumn(tables, table_id, column_id);
425
435
  const {
426
436
  type: columnType
427
437
  } = column || {};
@@ -488,7 +498,7 @@ BaseUtils.formatPieChartData = (data, chart, tables) => {
488
498
  const value = item.value;
489
499
  if (value >= threshold) {
490
500
  item.percent = String(Number.parseFloat(value / sum * 100).toFixed(1)) + '%';
491
- const color = _class.getPieColor(column, index, item);
501
+ const color = _BaseUtils.getPieColor(column, index, item);
492
502
  item.color = color;
493
503
  colorSet.push(color);
494
504
  filteredData.push(item);
@@ -603,7 +613,7 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
603
613
  };
604
614
  BaseUtils.updateTableViewList = (result, column, nameKey, colorKey) => {
605
615
  result.forEach(result => {
606
- _class.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey);
616
+ _BaseUtils.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey);
607
617
  });
608
618
  };
609
619
  // sort chart
@@ -739,10 +749,10 @@ BaseUtils.formatGroupsLabel = (results, chart, tables) => {
739
749
  group_name
740
750
  } = item;
741
751
  if (groupbyColumn) {
742
- _class.convertResultName(item, groupbyColumn, name, 'name', 'color');
752
+ _BaseUtils.convertResultName(item, groupbyColumn, name, 'name', 'color');
743
753
  }
744
754
  if (columnGroupbyColumn) {
745
- _class.convertResultName(item, columnGroupbyColumn, group_name, 'group_name', 'group_color');
755
+ _BaseUtils.convertResultName(item, columnGroupbyColumn, group_name, 'group_name', 'group_color');
746
756
  }
747
757
  });
748
758
  };
@@ -1166,19 +1176,19 @@ BaseUtils.getSummaryResult = function (results, summaryMethod) {
1166
1176
  switch (summaryMethod) {
1167
1177
  case CHART_SUMMARY_TYPE.MAX:
1168
1178
  {
1169
- return _class.getMax(numericResults);
1179
+ return _BaseUtils.getMax(numericResults);
1170
1180
  }
1171
1181
  case CHART_SUMMARY_TYPE.MIN:
1172
1182
  {
1173
- return _class.getMin(numericResults);
1183
+ return _BaseUtils.getMin(numericResults);
1174
1184
  }
1175
1185
  case CHART_SUMMARY_TYPE.SUM:
1176
1186
  {
1177
- return _class.getSum(numericResults, precision);
1187
+ return _BaseUtils.getSum(numericResults, precision);
1178
1188
  }
1179
1189
  case CHART_SUMMARY_TYPE.MEAN:
1180
1190
  {
1181
- return _class.getMean(numericResults, precision);
1191
+ return _BaseUtils.getMean(numericResults, precision);
1182
1192
  }
1183
1193
  case CHART_SUMMARY_TYPE.Distinct_values:
1184
1194
  {
@@ -1225,7 +1235,7 @@ BaseUtils.getSum = function (list) {
1225
1235
  BaseUtils.getMean = function (list) {
1226
1236
  let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
1227
1237
  if (list.length === 0) return 0;
1228
- const sum = _class.getSum(list);
1238
+ const sum = _BaseUtils.getSum(list);
1229
1239
  return Number.parseFloat((sum / list.length).toFixed(precision));
1230
1240
  };
1231
1241
  BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod, useDataDb, dbDateKey, valueKey) => {
@@ -1271,11 +1281,11 @@ BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod,
1271
1281
  // }
1272
1282
 
1273
1283
  if (summaryType === CHART_SUMMARY_TYPE.ADVANCED) {
1274
- comparedValue = _class.getSummaryResult(comparedValue, summaryMethod);
1275
- compareValue = _class.getSummaryResult(compareValue, summaryMethod);
1284
+ comparedValue = _BaseUtils.getSummaryResult(comparedValue, summaryMethod);
1285
+ compareValue = _BaseUtils.getSummaryResult(compareValue, summaryMethod);
1276
1286
  } else {
1277
- compareValue = _class.getSummaryResult(compareValue, 'Sum');
1278
- comparedValue = _class.getSummaryResult(comparedValue, 'Sum');
1287
+ compareValue = _BaseUtils.getSummaryResult(compareValue, 'Sum');
1288
+ comparedValue = _BaseUtils.getSummaryResult(comparedValue, 'Sum');
1279
1289
  }
1280
1290
  return {
1281
1291
  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,