dtable-statistic 4.0.12 → 4.1.0

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.
@@ -56,9 +56,8 @@ function calculateOneDimensionTable(chart, value, username, userId) {
56
56
  });
57
57
  }
58
58
  } else {
59
- pivotRowIndex = pivot_rows.findIndex(function (r) {
60
- var resName = r.name;
61
- return resName === null && name === null || resName === undefined && name === undefined || resName === 0 && name === 0 || resName === name;
59
+ pivotRowIndex = pivot_rows.findIndex(function (pivotRow) {
60
+ return isSameName(pivotRow.name, name);
62
61
  });
63
62
  updateOneDimensionRows(pivot_rows, pivotRowIndex, name, row);
64
63
  }
@@ -99,7 +98,8 @@ function calculateOneDimensionTable(chart, value, username, userId) {
99
98
  return {
100
99
  pivot_columns_total: pivot_columns_total,
101
100
  pivot_rows: pivot_rows,
102
- pivot_columns: pivot_columns
101
+ pivot_columns: pivot_columns,
102
+ formulaRows: formulaRows
103
103
  };
104
104
  }
105
105
  function updateOneDimensionRows(pivot_rows, index, name, row) {
@@ -286,9 +286,8 @@ function calculateTwoDimensionTable(chart, value, username, userId) {
286
286
  });
287
287
  }
288
288
  } else {
289
- pivotRowIndex = pivot_rows.findIndex(function (r) {
290
- var resName = r.name;
291
- return resName === null && name === null || resName === undefined && name === undefined || resName === 0 && name === 0 || resName === name;
289
+ pivotRowIndex = pivot_rows.findIndex(function (pivotRow) {
290
+ return isSameName(pivotRow.name, name);
292
291
  });
293
292
  updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, name, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
294
293
  }
@@ -403,6 +402,15 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
403
402
  });
404
403
  }
405
404
  }
405
+ function isSameName(prevName, currName) {
406
+ if (isNumber(prevName) && isNumber(currName)) {
407
+ return prevName === currName;
408
+ }
409
+ if (!prevName && !currName) {
410
+ return prevName === null && currName === null || prevName === undefined && currName === undefined || isNaN(prevName) && isNaN(currName);
411
+ }
412
+ return prevName === currName;
413
+ }
406
414
  function isSameGroup(isColumnDataAsAnArray, source, target) {
407
415
  if (isColumnDataAsAnArray) {
408
416
  return (!source || source.length === 0) && !target || source && source.includes(target);
@@ -68,6 +68,7 @@ var ChartAdditionEditDialog = /*#__PURE__*/function (_Component) {
68
68
  }, intl.get(editMode ? 'Edit_the_chart' : 'Choose_a_chart')), /*#__PURE__*/React.createElement(ModalBody, {
69
69
  className: "statistic-modal-body"
70
70
  }, editMode ? /*#__PURE__*/React.createElement(StatEditor, {
71
+ dtableChangedTime: this.props.dtableChangedTime,
71
72
  colorThemeName: colorThemeName,
72
73
  statItem: chart,
73
74
  labelColorConfigs: labelColorConfigs,
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
4
  import _inherits from "@babel/runtime/helpers/esm/inherits";
@@ -10,6 +11,7 @@ import dtableDbAPI from '../../../api/dtable-db-api';
10
11
  import { DtableSearchInput, Loading } from '../../index';
11
12
  import { searchRows } from '../../../utils';
12
13
  import { getSqlString } from '../../../utils/sql-utils';
14
+ import { CommonEventTypes } from '../../../constants';
13
15
  import './index.css';
14
16
  export var UNSHOWN_COLUMN_TYPES = [CellType.LINK, CellType.LONG_TEXT, CellType.FORMULA, CellType.LINK_FORMULA];
15
17
  var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
@@ -21,21 +23,21 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
21
23
  _this = _super.call(this, props);
22
24
  _this.init = function () {
23
25
  var chartRecordsParams = _this.props.chartRecordsParams;
26
+ if (!chartRecordsParams) return;
24
27
  var _ref = chartRecordsParams || {},
25
28
  statisticRecord = _ref.statisticRecord,
26
29
  chart = _ref.chart,
27
30
  isColumn = _ref.isColumn,
28
31
  isCurrentView = _ref.isCurrentView,
29
32
  isRow = _ref.isRow;
30
- var records = statisticRecord.rows,
31
- title = statisticRecord.name;
33
+ var records = statisticRecord.rows;
32
34
  var getTableById = _this.props.getTableById;
33
35
  var table_id = chart.table_id,
34
36
  view_id = chart.view_id;
35
- var table = getTableById(table_id);
36
- var view = Views.getViewById(table.views, view_id);
37
- var isArchiveView = Views.isArchiveView(view);
38
- if (isArchiveView || !records) {
37
+ _this.table = getTableById(table_id);
38
+ _this.view = Views.getViewById(_this.table.views, view_id);
39
+ _this.isArchiveView = Views.isArchiveView(_this.view);
40
+ if (_this.isArchiveView || !records) {
39
41
  var sqlString = getSqlString(chart, statisticRecord, {
40
42
  isColumn: isColumn,
41
43
  isCurrentView: isCurrentView,
@@ -44,29 +46,33 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
44
46
  });
45
47
  dtableDbAPI.sqlQuery(sqlString).then(function (res) {
46
48
  var rows = res.data.results;
47
- var searchedRows = Array.isArray(rows) && rows.length > 0 ? _this.getSearchedRows(rows) : [];
48
- _this.setState({
49
- loading: false,
50
- title: title,
51
- rows: rows,
52
- searchedRows: searchedRows
53
- });
49
+ _this.processDrilledRows(rows);
54
50
  });
55
51
  return;
56
52
  }
57
- var searchedRows = Array.isArray(records) && records.length > 0 ? _this.getSearchedRows(records) : [];
53
+ _this.processDrilledRows(records);
54
+ };
55
+ _this.processDrilledRows = function (drilledRows) {
56
+ var statisticRecord = _this.props.chartRecordsParams.statisticRecord;
57
+ var name = statisticRecord.name;
58
+ var searchedRowsIds = _this.getSearchedRows(drilledRows);
59
+ var idRowMap = {};
60
+ drilledRows.forEach(function (row) {
61
+ idRowMap[row._id] = row;
62
+ });
58
63
  _this.setState({
59
64
  loading: false,
60
- title: title,
61
- rows: records,
62
- searchedRows: searchedRows
65
+ title: name,
66
+ rows: drilledRows,
67
+ idRowMap: idRowMap,
68
+ searchedRowsIds: searchedRowsIds
63
69
  });
64
70
  };
65
71
  _this.onSearch = function (searchVal) {
66
72
  var rows = _this.state.rows;
67
- var searchedRows = _this.getSearchedRows(rows, searchVal);
73
+ var searchedRowsIds = _this.getSearchedRows(rows, searchVal);
68
74
  _this.setState({
69
- searchedRows: searchedRows,
75
+ searchedRowsIds: searchedRowsIds,
70
76
  searchVal: searchVal
71
77
  });
72
78
  };
@@ -76,58 +82,116 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
76
82
  _this.timer = null;
77
83
  }
78
84
  };
79
- _this.getStatisticTable = function () {
80
- var _this$props = _this.props,
81
- chartRecordsParams = _this$props.chartRecordsParams,
82
- getTableById = _this$props.getTableById;
83
- var table_id = chartRecordsParams.chart.table_id;
84
- return getTableById(table_id);
85
- };
86
- _this.getStatisticView = function (table) {
87
- var chartRecordsParams = _this.props.chartRecordsParams;
88
- var view_id = chartRecordsParams.chart.view_id;
89
- return Views.getViewById(table.views, view_id);
90
- };
91
- _this.getStatisticColumns = function () {
92
- var table = _this.getStatisticTable();
93
- var view = _this.getStatisticView(table);
94
- return Views.getColumns(view, table);
95
- };
96
85
  _this.clearSearch = function () {
97
86
  var rows = _this.state.rows;
87
+ var searchedRowsIds = _this.getSearchedRows(rows);
98
88
  _this.setState({
99
- searchedRows: rows,
89
+ searchedRowsIds: searchedRowsIds,
100
90
  searchVal: ''
101
91
  });
102
92
  };
103
93
  _this.getSearchedRows = function (rows, searchVal) {
94
+ if (!Array.isArray(rows) || rows.length === 0) return [];
104
95
  if (searchVal) {
105
- return searchRows(rows, _this.getStatisticColumns(), searchVal, function (row) {
96
+ return searchRows(rows, Views.getColumns(_this.view, _this.table), searchVal, function (row) {
106
97
  return row;
98
+ }).map(function (row) {
99
+ return row._id;
107
100
  });
108
101
  }
109
- return rows;
102
+ return rows.map(function (row) {
103
+ return row._id;
104
+ });
105
+ };
106
+ _this.getRowsByIds = function (rowsIds) {
107
+ if (!Array.isArray(rowsIds) || rowsIds.length === 0) {
108
+ return [];
109
+ }
110
+ var idRowMap = _this.state.idRowMap;
111
+ return rowsIds.map(function (rowId) {
112
+ return idRowMap[rowId];
113
+ }).filter(Boolean);
110
114
  };
111
115
  _this.toggle = function () {
116
+ if (_this.valueChanged) {
117
+ _this.props.eventBus.dispatch(CommonEventTypes.REFRESH_CHARTS);
118
+ }
112
119
  _this.props.toggleStatisticRecordsDialog();
113
120
  };
114
- _this.renderRowsCards = function () {
115
- var searchedRows = _this.state.searchedRows;
116
- if (!Array.isArray(searchedRows) || searchedRows.length === 0) {
117
- return null;
121
+ _this.expandRowUpdated = function (_ref2) {
122
+ var table_id = _ref2.table_id,
123
+ updatedRow = _ref2.updatedRow;
124
+ // none-matched
125
+ if (table_id !== _this.table._id) return;
126
+ var _this$state = _this.state,
127
+ rows = _this$state.rows,
128
+ searchedRowsIds = _this$state.searchedRowsIds,
129
+ idRowMap = _this$state.idRowMap,
130
+ searchVal = _this$state.searchVal;
131
+ var updatedSearchedRowsIds = searchedRowsIds;
132
+ var updatedRows = _toConsumableArray(rows);
133
+ var updatedIdRowMap = idRowMap;
134
+ rows.forEach(function (row, index) {
135
+ var rowId = row._id;
136
+ if (rowId === updatedRow._id) {
137
+ updatedRows[index] = updatedRow;
138
+ updatedIdRowMap[rowId] = updatedRow;
139
+ }
140
+ });
141
+ if (searchedRowsIds.length > 0) {
142
+ var searchedRows = _this.getRowsByIds(searchedRowsIds);
143
+ updatedSearchedRowsIds = _this.getSearchedRows(searchedRows, searchVal);
118
144
  }
145
+ _this.valueChanged = true;
146
+ _this.setState({
147
+ rows: updatedRows,
148
+ idRowMap: updatedIdRowMap,
149
+ searchedRowsIds: updatedSearchedRowsIds
150
+ });
151
+ };
152
+ _this.expandRowDeleted = function (_ref3) {
153
+ var table_id = _ref3.table_id,
154
+ row_id = _ref3.row_id;
155
+ // none-matched
156
+ if (table_id !== _this.table._id) return;
157
+ var _this$state2 = _this.state,
158
+ rows = _this$state2.rows,
159
+ searchedRowsIds = _this$state2.searchedRowsIds,
160
+ idRowMap = _this$state2.idRowMap;
161
+ var updatedSearchedRowsIds = searchedRowsIds;
162
+ var updatedIdRowMap = idRowMap;
163
+ var updatedRows = rows.filter(function (row) {
164
+ return row._id !== row_id;
165
+ });
166
+ delete updatedIdRowMap[row_id];
167
+ if (searchedRowsIds.length > 0) {
168
+ updatedSearchedRowsIds = searchedRowsIds.filter(function (rowId) {
169
+ return rowId !== row_id;
170
+ });
171
+ }
172
+ _this.valueChanged = true;
173
+ _this.setState({
174
+ rows: updatedRows,
175
+ idRowMap: updatedIdRowMap,
176
+ searchedRowsIds: updatedSearchedRowsIds
177
+ });
178
+ };
179
+ _this.renderRowsCards = function () {
180
+ var searchedRowsIds = _this.state.searchedRowsIds;
181
+ var searchedRows = _this.getRowsByIds(searchedRowsIds);
182
+ if (searchedRows.length === 0) return null;
119
183
  var unShowColumnKeyList = ['0000'];
120
- var table = _this.getStatisticTable();
121
- var renderedColumns = table.columns.filter(function (column) {
184
+ var allColumns = _this.table.columns;
185
+ var renderedColumns = allColumns.filter(function (column) {
122
186
  return !unShowColumnKeyList.includes(column.key) && !UNSHOWN_COLUMN_TYPES.includes(column.type);
123
187
  });
124
188
  if (!window.app || !window.app.renderRowsCards) return null;
125
189
  return window.app.renderRowsCards({
126
- table: table,
190
+ table: _this.table,
127
191
  renderedColumns: renderedColumns,
128
192
  unShowColumnKeyList: unShowColumnKeyList,
129
193
  isShowRowCardHeader: true,
130
- columns: table.columns,
194
+ columns: allColumns,
131
195
  rows: searchedRows,
132
196
  rowCardType: 'statistic'
133
197
  });
@@ -136,22 +200,35 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
136
200
  loading: true,
137
201
  title: '',
138
202
  rows: [],
203
+ idRowMap: {},
139
204
  searchVal: '',
140
- searchedRows: []
205
+ searchedRowsIds: []
141
206
  };
207
+ _this.table = null;
208
+ _this.view = null;
209
+ _this.isArchiveView = false;
210
+ _this.valueChanged = false;
142
211
  return _this;
143
212
  }
144
213
  _createClass(StatisticRecordDialog, [{
145
214
  key: "componentDidMount",
146
215
  value: function componentDidMount() {
216
+ this.unsubscribeExpandRowUpdated = this.props.eventBus.subscribe(CommonEventTypes.EXPAND_ROW_UPDATED, this.expandRowUpdated);
217
+ this.unsubscribeExpandRowDeleted = this.props.eventBus.subscribe(CommonEventTypes.EXPAND_ROW_DELETED, this.expandRowDeleted);
147
218
  this.init();
148
219
  }
220
+ }, {
221
+ key: "componentWillUnmount",
222
+ value: function componentWillUnmount() {
223
+ this.unsubscribeExpandRowUpdated();
224
+ this.unsubscribeExpandRowDeleted();
225
+ }
149
226
  }, {
150
227
  key: "render",
151
228
  value: function render() {
152
- var _this$state = this.state,
153
- loading = _this$state.loading,
154
- title = _this$state.title;
229
+ var _this$state3 = this.state,
230
+ loading = _this$state3.loading,
231
+ title = _this$state3.title;
155
232
  return /*#__PURE__*/React.createElement(Modal, {
156
233
  isOpen: true,
157
234
  autoFocus: false,
@@ -1 +1,4 @@
1
- export var OPEN_SELECT = 'OPEN_SELECT';
1
+ export var OPEN_SELECT = 'OPEN_SELECT';
2
+ export var EXPAND_ROW_UPDATED = 'EXPAND_ROW_UPDATED';
3
+ export var EXPAND_ROW_DELETED = 'EXPAND_ROW_DELETED';
4
+ export var REFRESH_CHARTS = 'REFRESH_CHARTS';
package/es/dashboard.js CHANGED
@@ -16,7 +16,7 @@ import ThreadManager from './calculator/thread-manager';
16
16
  import ChartCalculator from './calculator';
17
17
  import { isMobile } from './utils';
18
18
  import { generatorUniqueId } from './utils/common-utils';
19
- import { DASHBOARD_ACTION_TYPE, KEY_SELECTED_DASHBOARD, LABEL_COLORS } from './constants';
19
+ import { CommonEventTypes, DASHBOARD_ACTION_TYPE, KEY_SELECTED_DASHBOARD, LABEL_COLORS } from './constants';
20
20
  import './locale';
21
21
  import './assets/css/dashboard.css';
22
22
  import './assets/css/theme.css';
@@ -46,12 +46,17 @@ var DashBoard = /*#__PURE__*/function (_Component) {
46
46
  _this.updatingLocalStatistics = false;
47
47
  return;
48
48
  }
49
- _this.onDTableChanged(value);
49
+ _this.onDTableChanged({
50
+ value: value
51
+ });
50
52
  };
51
53
  _this.onServerDTableChanged = function (value) {
52
- _this.onDTableChanged(value);
54
+ _this.onDTableChanged({
55
+ value: value
56
+ });
53
57
  };
54
- _this.onDTableChanged = function (value) {
58
+ _this.onDTableChanged = function (_ref) {
59
+ var value = _ref.value;
55
60
  _this.value = value;
56
61
  _this.disabledUpdateLayout = true;
57
62
  var _this$initDashboard = _this.initDashboard(),
@@ -59,7 +64,11 @@ var DashBoard = /*#__PURE__*/function (_Component) {
59
64
  selectedDashboardIdx = _this$initDashboard.selectedDashboardIdx;
60
65
  _this.setState({
61
66
  statistics: statistics,
62
- selectedDashboardIdx: selectedDashboardIdx,
67
+ selectedDashboardIdx: selectedDashboardIdx
68
+ });
69
+ };
70
+ _this.refreshCharts = function () {
71
+ _this.setState({
63
72
  dtableChangedTime: Date.now()
64
73
  });
65
74
  };
@@ -141,11 +150,11 @@ var DashBoard = /*#__PURE__*/function (_Component) {
141
150
  if (!activeViewId) return selectedTable.views[0];
142
151
  return Views.getViewById(selectedTable.views, activeViewId);
143
152
  };
144
- _this.getInitChart = function (_ref) {
145
- var chartType = _ref.chartType,
146
- dashboard = _ref.dashboard,
147
- activeTable = _ref.activeTable,
148
- activeView = _ref.activeView;
153
+ _this.getInitChart = function (_ref2) {
154
+ var chartType = _ref2.chartType,
155
+ dashboard = _ref2.dashboard,
156
+ activeTable = _ref2.activeTable,
157
+ activeView = _ref2.activeView;
149
158
  return _this.chartService.getInitChart({
150
159
  type: chartType,
151
160
  dashboard: dashboard,
@@ -153,10 +162,10 @@ var DashBoard = /*#__PURE__*/function (_Component) {
153
162
  activeView: activeView
154
163
  });
155
164
  };
156
- _this.getConvertedChart = function (_ref2) {
157
- var originalStatistic = _ref2.originalStatistic,
158
- targetStatisticType = _ref2.targetStatisticType,
159
- activeTable = _ref2.activeTable;
165
+ _this.getConvertedChart = function (_ref3) {
166
+ var originalStatistic = _ref3.originalStatistic,
167
+ targetStatisticType = _ref3.targetStatisticType,
168
+ activeTable = _ref3.activeTable;
160
169
  return _this.chartService.getConvertedChart({
161
170
  originalStatistic: originalStatistic,
162
171
  targetStatisticType: targetStatisticType,
@@ -225,7 +234,6 @@ var DashBoard = /*#__PURE__*/function (_Component) {
225
234
  var nextSelectedDashboardIdx = selectedDashboardIdx;
226
235
  if (index === statistics.length - 1) {
227
236
  nextSelectedDashboardIdx--;
228
- _this.clearCalculations();
229
237
  }
230
238
  var updatedStatistics = _this.dashboardService.update({
231
239
  action: DASHBOARD_ACTION_TYPE.DELETE_DASHBOARD,
@@ -234,6 +242,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
234
242
  }
235
243
  });
236
244
  _this.setSelectedDashboardIdx(nextSelectedDashboardIdx);
245
+ _this.clearCalculations();
237
246
  _this.updateStatistics({
238
247
  statistics: updatedStatistics,
239
248
  selectedDashboardIdx: nextSelectedDashboardIdx
@@ -389,12 +398,14 @@ var DashBoard = /*#__PURE__*/function (_Component) {
389
398
  var eventBus = this.props.eventBus;
390
399
  this.unsubscribeLocalDtableChanged = eventBus.subscribe('local-dtable-changed', this.onLocalDTableChanged);
391
400
  this.unsubscribeRemoteDtableChange = eventBus.subscribe('remote-dtable-changed', this.onServerDTableChanged);
401
+ this.unsubscribeRefreshCharts = eventBus.subscribe(CommonEventTypes.REFRESH_CHARTS, this.refreshCharts);
392
402
  }
393
403
  }, {
394
404
  key: "componentWillUnmount",
395
405
  value: function componentWillUnmount() {
396
406
  this.unsubscribeLocalDtableChanged();
397
407
  this.unsubscribeRemoteDtableChange();
408
+ this.unsubscribeRefreshCharts();
398
409
  this.clearCalculations();
399
410
  }
400
411
  }, {
@@ -235,6 +235,7 @@ var DesktopDashboard = /*#__PURE__*/function (_Component) {
235
235
  onCloseDashboard: this.props.onCloseDashboard,
236
236
  toggleStatisticRecordsDialog: this.toggleStatisticRecordsDialog
237
237
  })), this.state.isShowChartAdditionDialog && /*#__PURE__*/React.createElement(ChartAdditionEditDialog, {
238
+ dtableChangedTime: dtableChangedTime,
238
239
  colorThemeName: colorThemeName,
239
240
  editingChart: editingChart,
240
241
  labelColorConfigs: labelColorConfigs,
@@ -254,6 +255,7 @@ var DesktopDashboard = /*#__PURE__*/function (_Component) {
254
255
  onToggleColorThemeDialog: this.onToggleColorThemeDialog,
255
256
  modifyColorTheme: this.props.modifyColorTheme
256
257
  }), !!chartRecordsParams && /*#__PURE__*/React.createElement(StatisticRecordDialog, {
258
+ eventBus: this.props.eventBus,
257
259
  chartRecordsParams: chartRecordsParams,
258
260
  getTableById: getTableById,
259
261
  toggleStatisticRecordsDialog: this.toggleStatisticRecordsDialog
@@ -6,7 +6,7 @@ import BaseModel from './base-model';
6
6
  import { getChartConfigValueFromKey, getChartConfigValueFromKeys } from '../utils/model';
7
7
  import { isBoolean } from '../utils/common-utils';
8
8
  import { DATE_GRANULARITY, DATE_GRANULARITY_LIST, DEFAULT_LABEL_FONT_SIZE, GEOLOCATION_GRANULARITY, GEOLOCATION_GRANULARITY_LIST } from '../constants';
9
- import { COLUMN_DATE_GRANULARITY_KEYS, COLUMN_GEO_GRANULARITY_KEYS, COLUMN_GROUPBY_KEYS, LABEL_FRONT_SIZE_KEYS, X_DATE_GRANULARITY_KEYS, X_GEO_GRANULARITY_KEYS, X_GROUPBY_KEYS, X_INCLUDE_EMPTY_KEYS, X_LABEL_POSITION_KEYS, Y_AUTO_RANGE_KEYS, Y_AUTO_RANGE_MAX_KEYS, Y_AUTO_RANGE_MIN_KEYS, Y_LABEL_COLOR_KEYS, Y_LABEL_COLOR_RULES_KEYS, Y_LABEL_POSITION_KEYS, Y_SHOW_AXIS_LABEL_KEYS, Y_SUMMARY_BY_KEYS, Y_SUMMARY_METHOD_KEYS, Y_SUMMARY_TYPE_KEYS } from '../constants/model';
9
+ import { COLUMN_DATE_GRANULARITY_KEYS, COLUMN_GEO_GRANULARITY_KEYS, COLUMN_GROUPBY_KEYS, LABEL_FRONT_SIZE_KEYS, X_DATE_GRANULARITY_KEYS, X_GEO_GRANULARITY_KEYS, X_GROUPBY_KEYS, X_INCLUDE_EMPTY_KEYS, X_LABEL_POSITION_KEYS, X_SHOW_AXIS_LABEL, Y_AUTO_RANGE_KEYS, Y_AUTO_RANGE_MAX_KEYS, Y_AUTO_RANGE_MIN_KEYS, Y_LABEL_COLOR_KEYS, Y_LABEL_COLOR_RULES_KEYS, Y_LABEL_POSITION_KEYS, Y_SHOW_AXIS_LABEL_KEYS, Y_SUMMARY_BY_KEYS, Y_SUMMARY_METHOD_KEYS, Y_SUMMARY_TYPE_KEYS } from '../constants/model';
10
10
  var GenericModel = /*#__PURE__*/function (_BaseModel) {
11
11
  _inherits(GenericModel, _BaseModel);
12
12
  var _super = _createSuper(GenericModel);
@@ -35,7 +35,7 @@ var GenericModel = /*#__PURE__*/function (_BaseModel) {
35
35
  _this.x_axis_compared_date_range_end = getChartConfigValueFromKey('x_axis_compared_date_range_end', object);
36
36
 
37
37
  // x style
38
- _this.show_x_axis_label = getChartConfigValueFromKeys(X_INCLUDE_EMPTY_KEYS, object);
38
+ _this.show_x_axis_label = getChartConfigValueFromKeys(X_SHOW_AXIS_LABEL, object);
39
39
  if (!isBoolean(_this.show_x_axis_label)) {
40
40
  _this.show_x_axis_label = null;
41
41
  }
@@ -42,6 +42,7 @@ var StatEditor = /*#__PURE__*/function (_Component) {
42
42
  isEdit: true,
43
43
  isPreview: false,
44
44
  isEnlarge: false,
45
+ dtableChangedTime: this.props.dtableChangedTime,
45
46
  colorThemeName: colorThemeName,
46
47
  statItem: statItem,
47
48
  labelColorConfigs: labelColorConfigs,
@@ -13,7 +13,7 @@ import { NewTableDialog, toaster } from '../components';
13
13
  import EnlargeChartDialog from '../components/dialog/enlarged-chart-dialog';
14
14
  import TableSelectDialog from '../components/dialog/table-select-dialog';
15
15
  import { exportStatisticToTable, updateStatisticToTable } from '../utils/export-table-utils';
16
- import { STAT_TYPE } from '../constants';
16
+ import { CommonEventTypes, STAT_TYPE } from '../constants';
17
17
  var ReactGridLayout = WidthProvider(GridLayout);
18
18
  var StatList = /*#__PURE__*/function (_Component) {
19
19
  _inherits(StatList, _Component);
@@ -155,6 +155,11 @@ var StatList = /*#__PURE__*/function (_Component) {
155
155
  rowIds: rowIds,
156
156
  oldRows: oldRows
157
157
  });
158
+
159
+ // refresh charts if has updates
160
+ if (Array.isArray(rowIds) && rowIds.length > 0 || Array.isArray(newRows) && newRows.length > 0) {
161
+ _this.props.eventBus.dispatch(CommonEventTypes.REFRESH_CHARTS);
162
+ }
158
163
  }
159
164
  _this.statisticalResult4Update = null;
160
165
  _this.closeSelectTableDialog();
@@ -87,8 +87,6 @@ var PieChart = /*#__PURE__*/function (_BaseChart) {
87
87
  var name = obj.name;
88
88
  if (!obj.name && typeof obj.name !== 'number') {
89
89
  name = intl.get(EMPTY_NAME);
90
- } else if (obj.name === 'Others') {
91
- name = intl.get('Others');
92
90
  }
93
91
  return {
94
92
  name: name,
@@ -77,10 +77,10 @@ var PivotTable = /*#__PURE__*/function (_BaseChart) {
77
77
  var summaryMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SUMMARY_TYPE.COUNT;
78
78
  if (!summaryColumn || !summaryColumn.type) return summaryValue;
79
79
  if (!summaryValue && summaryValue !== 0) return summaryValue;
80
- if (summaryMethod.toUpperCase() === 'DISTINCT_VALUES') return summaryValue;
80
+ if (summaryMethod && summaryMethod.toUpperCase() === 'DISTINCT_VALUES') return summaryValue;
81
81
  var data = summaryColumn.data;
82
82
  if (TIME_COLUMN_LIST.includes(summaryColumn.type)) {
83
- if (typeof summaryValue !== 'string') return summaryValue;
83
+ if (typeof summaryValue !== 'string') return '';
84
84
  // The date returned by db carries T and Z, so that there is a time difference in data formatting
85
85
  var _ref = data || {},
86
86
  format = _ref.format;
@@ -6,10 +6,11 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
6
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
7
  import React, { PureComponent } from 'react';
8
8
  import intl from 'react-intl-universal';
9
- import { FORMULA_COLUMN_TYPES_MAP, isNumber, TableUtils, Views } from 'dtable-store';
9
+ import { isNumber, TableUtils, Views } from 'dtable-store';
10
10
  import PivotTableDisplayName from './pivot-table-display-name';
11
11
  import { isMobile } from '../../utils';
12
- import { STATISTICS_COUNT_TYPE, SUMMARY_METHOD_MAP, TITLE_TOTAL } from '../../constants';
12
+ import { getPivotTableSummaryTotal } from '../../utils/pivot-table';
13
+ import { STATISTICS_COUNT_TYPE, TITLE_TOTAL } from '../../constants';
13
14
  import styles from './statistic-pivot-table.module.css';
14
15
  var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
15
16
  _inherits(TwoDimensionTable, _PureComponent);
@@ -59,95 +60,6 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
59
60
  }
60
61
  return 0;
61
62
  };
62
- _this.getCellValueFromRow = function (row, formulaRow, columnType, columnKey, sqlKey, isSqlQuery) {
63
- if (!isSqlQuery) {
64
- if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
65
- var cellValue = formulaRow[columnKey];
66
- return Array.isArray(cellValue) ? cellValue[0] : cellValue;
67
- }
68
- return row[columnKey];
69
- }
70
- return row[sqlKey];
71
- };
72
- _this.getSummaryTotal = function (summaryColumnType, summaryColumnKey, sqlKey, summaryType, summaryMethod, rows, formulaRows, isSqlQuery) {
73
- if (summaryType === STATISTICS_COUNT_TYPE.COUNT) {
74
- return rows.length;
75
- }
76
- if (summaryType !== STATISTICS_COUNT_TYPE.ADVANCED) {
77
- return 0;
78
- }
79
- switch (summaryMethod) {
80
- case SUMMARY_METHOD_MAP.Distinct_values:
81
- {
82
- var count = 0;
83
- var existMap = {};
84
- rows.forEach(function (row) {
85
- var formulaRow = formulaRows && formulaRows[row._id];
86
- var cellValue = _this.getCellValueFromRow(row, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
87
- if (!cellValue) {
88
- if (cellValue === 0) {
89
- cellValue = '0';
90
- } else {
91
- cellValue = !!cellValue;
92
- }
93
- }
94
- if (!existMap[cellValue]) {
95
- existMap[cellValue] = true;
96
- count++;
97
- }
98
- });
99
- return count;
100
- }
101
- case SUMMARY_METHOD_MAP.Sum:
102
- case SUMMARY_METHOD_MAP.Mean:
103
- {
104
- var sum = 0;
105
- var validNumbersCount = 0;
106
- rows.forEach(function (row) {
107
- var formulaRow = formulaRows && formulaRows[row._id];
108
- var cellValue = _this.getCellValueFromRow(row, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
109
- if (isNumber(cellValue)) {
110
- validNumbersCount++;
111
- sum += cellValue;
112
- }
113
- });
114
- if (summaryMethod === SUMMARY_METHOD_MAP.Sum) {
115
- sum = Number.parseFloat(sum.toFixed(8));
116
- } else if (summaryMethod === SUMMARY_METHOD_MAP.Mean) {
117
- sum = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
118
- }
119
- return sum;
120
- }
121
- case SUMMARY_METHOD_MAP.Max:
122
- case SUMMARY_METHOD_MAP.Min:
123
- {
124
- if (rows.length === 0) {
125
- return 0;
126
- }
127
- var result = rows.reduce(function (current, next) {
128
- var currentFormulaRow = formulaRows && formulaRows[current._id];
129
- var nextFormulaRow = formulaRows && formulaRows[next._id];
130
- var currentValue = _this.getCellValueFromRow(current, currentFormulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
131
- var nextValue = _this.getCellValueFromRow(next, nextFormulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
132
- if (!nextValue && nextValue !== 0) {
133
- return current;
134
- }
135
- var isNextGreater = currentValue < nextValue;
136
- if (summaryMethod === SUMMARY_METHOD_MAP.Min) {
137
- return isNextGreater ? current : next;
138
- } else {
139
- return isNextGreater ? next : current;
140
- }
141
- });
142
- var formulaRow = formulaRows && formulaRows[result._id];
143
- return _this.getCellValueFromRow(result, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
144
- }
145
- default:
146
- {
147
- return 0;
148
- }
149
- }
150
- };
151
63
  _this.getCells = function (row, summaryColumn) {
152
64
  var _this$props2 = _this.props,
153
65
  pivotResult = _this$props2.pivotResult,
@@ -172,7 +84,7 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
172
84
  sqlKey = column.sqlKey,
173
85
  method = column.method;
174
86
  if (Array.isArray(rowData)) {
175
- var sum = _this.getSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, rowData, formulaRows, isSqlQuery);
87
+ var sum = getPivotTableSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, rowData, formulaRows, isSqlQuery);
176
88
  summary_multiple_columns.push(sum);
177
89
  formatted_summary_multiple_columns.push(getSummaryValueDisplayString(column, sum, method));
178
90
  return;
@@ -386,7 +298,7 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
386
298
  key = summaryCol.key,
387
299
  sqlKey = summaryCol.sqlKey,
388
300
  method = summaryCol.method;
389
- total += _this.getSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, pivotColumnCell, formulaRows, isSqlQuery);
301
+ total += getPivotTableSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, pivotColumnCell, formulaRows, isSqlQuery);
390
302
  });
391
303
  totalDisplayValue = total;
392
304
  allTotalDisplay += total;
@@ -161,8 +161,6 @@ var RingChart = /*#__PURE__*/function (_BaseChart) {
161
161
  var title = name;
162
162
  if (!name || name === 'undefined') {
163
163
  title = intl.get(EMPTY_NAME);
164
- } else if (name === 'Others') {
165
- title = intl.get('Others');
166
164
  }
167
165
  return show_percent || display_label ? {
168
166
  name: title,