dtable-statistic 4.0.6 → 4.0.8

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.
Files changed (67) hide show
  1. package/es/assets/css/dashboard.css +22 -0
  2. package/es/calculator/basic-chart-calculator.js +27 -18
  3. package/es/calculator/combination-calculator.js +34 -9
  4. package/es/calculator/compare-bar-calculator.js +37 -30
  5. package/es/calculator/heat-map-calculator.js +25 -14
  6. package/es/calculator/map-calculator.js +25 -14
  7. package/es/calculator/mirror-calculator.js +29 -14
  8. package/es/calculator/pivot-table-calculator.js +132 -76
  9. package/es/calculator/workers/basic-chart-calculator-worker.js +21 -6
  10. package/es/calculator/workers/combination-calculator-worker.js +20 -5
  11. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +12 -6
  12. package/es/calculator/workers/mirror-calculator-worker.js +15 -6
  13. package/es/calculator/workers/pivot-table-calculator-worker.js +97 -44
  14. package/es/calculator/world-map-calculator.js +25 -14
  15. package/es/components/dialog/enlarged-chart-dialog.js +2 -2
  16. package/es/components/dialog/statistic-record-dialog/index.css +2 -0
  17. package/es/components/dialog/statistic-record-dialog/index.js +80 -52
  18. package/es/constants/index.js +30 -29
  19. package/es/dashboard.js +57 -43
  20. package/es/desktop-dashboard.js +21 -56
  21. package/es/index.js +34 -2
  22. package/es/locale/lang/de.js +7 -3
  23. package/es/locale/lang/en.js +5 -1
  24. package/es/locale/lang/fr.js +7 -3
  25. package/es/locale/lang/zh_CN.js +5 -1
  26. package/es/mobile-dashboard.js +5 -5
  27. package/es/model/horizontal-bar-group.js +2 -0
  28. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +1 -2
  29. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +1 -1
  30. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +20 -3
  31. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +2 -8
  32. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +23 -2
  33. package/es/stat-list/chart-preview.js +3 -4
  34. package/es/stat-list/index.js +10 -4
  35. package/es/stat-view/area-chart.js +177 -162
  36. package/es/stat-view/bar-chart.js +221 -222
  37. package/es/stat-view/base-chart.js +79 -7
  38. package/es/stat-view/basic-number-card.js +11 -19
  39. package/es/stat-view/combination-chart.js +100 -83
  40. package/es/stat-view/compare-chart.js +133 -144
  41. package/es/stat-view/completeness-chart.js +108 -102
  42. package/es/stat-view/custom-bar.js +79 -99
  43. package/es/stat-view/dashboard-chart.js +57 -57
  44. package/es/stat-view/heat-map.js +13 -32
  45. package/es/stat-view/horizontal-bar-chart.js +200 -230
  46. package/es/stat-view/index.js +2 -2
  47. package/es/stat-view/line-chart.js +162 -158
  48. package/es/stat-view/map.js +26 -40
  49. package/es/stat-view/mirror.js +88 -94
  50. package/es/stat-view/pie-chart.js +11 -39
  51. package/es/stat-view/pivot-table/index.js +4 -16
  52. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +36 -23
  53. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +11 -5
  54. package/es/stat-view/pivot-table/pivot-table-display-name.js +206 -0
  55. package/es/stat-view/pivot-table/two-dimension-table.js +104 -60
  56. package/es/stat-view/ring-chart.js +24 -42
  57. package/es/stat-view/scatter-chart.js +4 -21
  58. package/es/stat-view/treemap-chart.js +3 -12
  59. package/es/stat-view/trend-chart.js +6 -17
  60. package/es/stat-view/world-map.js +39 -50
  61. package/es/tabs/tab.js +2 -1
  62. package/es/utils/collaborator.js +9 -0
  63. package/es/utils/common-utils.js +24 -6
  64. package/es/utils/index.js +1 -1
  65. package/es/utils/sql-utils.js +10 -9
  66. package/es/utils/stat-utils.js +8 -5
  67. package/package.json +1 -1
@@ -6,8 +6,10 @@ import React, { Fragment } from 'react';
6
6
  import intl from 'react-intl-universal';
7
7
  import { Modal, ModalBody } from 'reactstrap';
8
8
  import { CellType, Views } from 'dtable-store';
9
+ import dtableDbAPI from '../../../api/dtable-db-api';
9
10
  import { DtableSearchInput, Loading } from '../../index';
10
11
  import { searchRows } from '../../../utils';
12
+ import { getSqlString } from '../../../utils/sql-utils';
11
13
  import './index.css';
12
14
  export var UNSHOWN_COLUMN_TYPES = [CellType.LINK, CellType.LONG_TEXT, CellType.FORMULA, CellType.LINK_FORMULA];
13
15
  var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
@@ -17,11 +19,54 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
17
19
  var _this;
18
20
  _classCallCheck(this, StatisticRecordDialog);
19
21
  _this = _super.call(this, props);
22
+ _this.init = function () {
23
+ var chartRecordsParams = _this.props.chartRecordsParams;
24
+ var _ref = chartRecordsParams || {},
25
+ statisticRecord = _ref.statisticRecord,
26
+ chart = _ref.chart,
27
+ isColumn = _ref.isColumn,
28
+ isCurrentView = _ref.isCurrentView,
29
+ isRow = _ref.isRow;
30
+ var records = statisticRecord.rows,
31
+ title = statisticRecord.name;
32
+ var getTableById = _this.props.getTableById;
33
+ var table_id = chart.table_id,
34
+ 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) {
39
+ var sqlString = getSqlString(chart, statisticRecord, {
40
+ isColumn: isColumn,
41
+ isCurrentView: isCurrentView,
42
+ isRow: isRow,
43
+ getTableById: getTableById
44
+ });
45
+ dtableDbAPI.sqlQuery(sqlString).then(function (res) {
46
+ 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
+ });
54
+ });
55
+ return;
56
+ }
57
+ var searchedRows = Array.isArray(records) && records.length > 0 ? _this.getSearchedRows(records) : [];
58
+ _this.setState({
59
+ loading: false,
60
+ title: title,
61
+ rows: records,
62
+ searchedRows: searchedRows
63
+ });
64
+ };
20
65
  _this.onSearch = function (searchVal) {
21
66
  var rows = _this.state.rows;
22
- var searchRows = _this.getSearchRows(rows, searchVal);
67
+ var searchedRows = _this.getSearchedRows(rows, searchVal);
23
68
  _this.setState({
24
- searchRows: searchRows,
69
+ searchedRows: searchedRows,
25
70
  searchVal: searchVal
26
71
  });
27
72
  };
@@ -33,14 +78,14 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
33
78
  };
34
79
  _this.getStatisticTable = function () {
35
80
  var _this$props = _this.props,
36
- statistic = _this$props.statistic,
81
+ chartRecordsParams = _this$props.chartRecordsParams,
37
82
  getTableById = _this$props.getTableById;
38
- var table_id = statistic.table_id;
83
+ var table_id = chartRecordsParams.chart.table_id;
39
84
  return getTableById(table_id);
40
85
  };
41
86
  _this.getStatisticView = function (table) {
42
- var statistic = _this.props.statistic;
43
- var view_id = statistic.view_id;
87
+ var chartRecordsParams = _this.props.chartRecordsParams;
88
+ var view_id = chartRecordsParams.chart.view_id;
44
89
  return Views.getViewById(table.views, view_id);
45
90
  };
46
91
  _this.getStatisticColumns = function () {
@@ -51,11 +96,11 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
51
96
  _this.clearSearch = function () {
52
97
  var rows = _this.state.rows;
53
98
  _this.setState({
54
- searchRows: _this.getSearchRows(rows),
99
+ searchedRows: rows,
55
100
  searchVal: ''
56
101
  });
57
102
  };
58
- _this.getSearchRows = function (rows, searchVal) {
103
+ _this.getSearchedRows = function (rows, searchVal) {
59
104
  if (searchVal) {
60
105
  return searchRows(rows, _this.getStatisticColumns(), searchVal, function (row) {
61
106
  return row;
@@ -66,70 +111,56 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
66
111
  _this.toggle = function () {
67
112
  _this.props.toggleStatisticRecordsDialog();
68
113
  };
69
- _this.renderRowsCards = function (_ref) {
70
- var table = _ref.table,
71
- renderedColumns = _ref.renderedColumns,
72
- searchRows = _ref.searchRows,
73
- unShowColumnKeyList = _ref.unShowColumnKeyList;
74
- if (!window.app || !window.app.renderRowsCards) return;
114
+ _this.renderRowsCards = function () {
115
+ var searchedRows = _this.state.searchedRows;
116
+ if (!Array.isArray(searchedRows) || searchedRows.length === 0) {
117
+ return null;
118
+ }
119
+ var unShowColumnKeyList = ['0000'];
120
+ var table = _this.getStatisticTable();
121
+ var renderedColumns = table.columns.filter(function (column) {
122
+ return !unShowColumnKeyList.includes(column.key) && !UNSHOWN_COLUMN_TYPES.includes(column.type);
123
+ });
124
+ if (!window.app || !window.app.renderRowsCards) return null;
75
125
  return window.app.renderRowsCards({
76
126
  table: table,
77
127
  renderedColumns: renderedColumns,
78
128
  unShowColumnKeyList: unShowColumnKeyList,
79
129
  isShowRowCardHeader: true,
80
130
  columns: table.columns,
81
- rows: searchRows,
131
+ rows: searchedRows,
82
132
  rowCardType: 'statistic'
83
133
  });
84
134
  };
85
135
  _this.state = {
136
+ loading: true,
137
+ title: '',
86
138
  rows: [],
87
139
  searchVal: '',
88
- searchRows: []
140
+ searchedRows: []
89
141
  };
90
142
  return _this;
91
143
  }
92
144
  _createClass(StatisticRecordDialog, [{
93
- key: "componentDidUpdate",
94
- value: function componentDidUpdate(prevProps, prevState) {
95
- var oldLoading = prevProps.isLoading;
96
- var _this$props2 = this.props,
97
- isLoading = _this$props2.isLoading,
98
- rows = _this$props2.rows;
99
- if (oldLoading !== isLoading && !isLoading) {
100
- this.setState({
101
- rows: rows,
102
- searchRows: this.getSearchRows(rows)
103
- });
104
- }
145
+ key: "componentDidMount",
146
+ value: function componentDidMount() {
147
+ this.init();
105
148
  }
106
149
  }, {
107
150
  key: "render",
108
151
  value: function render() {
109
- var _this$props3 = this.props,
110
- isLoading = _this$props3.isLoading,
111
- currentDate = _this$props3.currentDate;
112
- var searchRows = this.state.searchRows;
113
- var unShowColumnKeyList = ['0000'];
114
- var table;
115
- var renderedColumns = [];
116
- if (!isLoading) {
117
- table = this.getStatisticTable();
118
- renderedColumns = table.columns.filter(function (column) {
119
- return !unShowColumnKeyList.includes(column.key) && !UNSHOWN_COLUMN_TYPES.includes(column.type);
120
- });
121
- }
152
+ var _this$state = this.state,
153
+ loading = _this$state.loading,
154
+ title = _this$state.title;
122
155
  return /*#__PURE__*/React.createElement(Modal, {
156
+ isOpen: true,
123
157
  autoFocus: false,
124
158
  toggle: this.toggle,
125
- isOpen: true,
126
159
  className: "statistic-records-dialog",
127
160
  zIndex: 1048
128
- }, isLoading && /*#__PURE__*/React.createElement("div", {
129
- className: "py-8"
130
- }, /*#__PURE__*/React.createElement(Loading, null)), !isLoading && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
161
+ }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
131
162
  className: "search-header"
132
- }, /*#__PURE__*/React.createElement("span", null, currentDate), /*#__PURE__*/React.createElement("button", {
163
+ }, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement("button", {
133
164
  type: "button",
134
165
  className: "close",
135
166
  "aria-label": "Close",
@@ -161,12 +192,9 @@ var StatisticRecordDialog = /*#__PURE__*/function (_React$Component) {
161
192
  }
162
193
  })), /*#__PURE__*/React.createElement(ModalBody, {
163
194
  className: "statistic-records-container"
164
- }, this.renderRowsCards({
165
- table: table,
166
- renderedColumns: renderedColumns,
167
- searchRows: searchRows,
168
- unShowColumnKeyList: unShowColumnKeyList
169
- }))));
195
+ }, loading ? /*#__PURE__*/React.createElement("div", {
196
+ className: "d-flex py-8"
197
+ }, /*#__PURE__*/React.createElement(Loading, null)) : this.renderRowsCards())));
170
198
  }
171
199
  }]);
172
200
  return StatisticRecordDialog;
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- var _INIT_STAT_ITEM, _MULTIPLE_CELL_VALUE_, _DATA_SORT_TYPE_LABEL, _TYPE_DISPLAY_COLOR_U, _STATISTIC_TYPE_SHOW;
2
+ var _INIT_STAT_ITEM, _MULTIPLE_CELL_VALUE_, _STAT_ITEM_THEME_COLO, _DATA_SORT_TYPE_LABEL, _TYPE_DISPLAY_COLOR_U, _STATISTIC_TYPE_SHOW;
3
3
  import { CellType } from 'dtable-store';
4
4
  import KeyCodes from './key-codes';
5
5
  import { MenuSelectStyle, UserSelectStyle } from './dtable-select-style';
@@ -97,18 +97,18 @@ export var SUMMARY_METHOD_MAP = {
97
97
  };
98
98
  export var SUMMARY_METHOD = [SUMMARY_METHOD_MAP.Sum, SUMMARY_METHOD_MAP.Max, SUMMARY_METHOD_MAP.Min, SUMMARY_METHOD_MAP.Mean, SUMMARY_METHOD_MAP.Distinct_values];
99
99
  export var MONTH_MIRROR = {
100
- '0': 'Jan.abbr',
101
- '1': 'Feb.abbr',
102
- '2': 'Mar.abbr',
103
- '3': 'Apr.abbr',
104
- '4': 'May.abbr',
105
- '5': 'Jun.abbr',
106
- '6': 'Jul.abbr',
107
- '7': 'Aug.abbr',
108
- '8': 'Sep.abbr',
109
- '9': 'Oct.abbr',
110
- '10': 'Nov.abbr',
111
- '11': 'Dec.abbr'
100
+ '0': 'Jan',
101
+ '1': 'Feb',
102
+ '2': 'Mar',
103
+ '3': 'Apr',
104
+ '4': 'May',
105
+ '5': 'Jun',
106
+ '6': 'Jul',
107
+ '7': 'Aug',
108
+ '8': 'Sep',
109
+ '9': 'Oct',
110
+ '10': 'Nov',
111
+ '11': 'Dec'
112
112
  };
113
113
  export var TIME_COLUMN_LIST = [CellType.CTIME, CellType.MTIME, CellType.DATE];
114
114
  export var MIRROR_COLUMN_LIST = [CellType.TEXT, CellType.NUMBER, CellType.CTIME, CellType.MTIME, CellType.DATE, CellType.COLLABORATOR, CellType.AUTO_NUMBER, CellType.FORMULA, CellType.GEOLOCATION, CellType.URL, CellType.SINGLE_SELECT, CellType.LINK, CellType.CREATOR, CellType.LAST_MODIFIER, CellType.DURATION, CellType.EMAIL];
@@ -409,22 +409,23 @@ export var EMPTY_NAME = 'Empty';
409
409
  export var NO_STATISTIC_RESULTS = 'There_are_no_statistic_results_yet';
410
410
  export var TOO_MANY_STATISTIC_ENTRIES = 'There_are_too_many_statistics_entries_to_display';
411
411
  export var MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP = (_MULTIPLE_CELL_VALUE_ = {}, _defineProperty(_MULTIPLE_CELL_VALUE_, CellType.MULTIPLE_SELECT, true), _defineProperty(_MULTIPLE_CELL_VALUE_, CellType.COLLABORATOR, true), _defineProperty(_MULTIPLE_CELL_VALUE_, CellType.LINK, true), _MULTIPLE_CELL_VALUE_);
412
- export var STAT_ITEM_THEME_COLORS = {
413
- dark: {
414
- textColor: '#ffffff',
415
- gridColor: '#4E4E56',
416
- labelColor: '#ffffff',
417
- legendPageNavigatorMarkerColor: '#ffffff',
418
- cardColor: '#ffffff'
419
- },
420
- light: {
421
- textColor: '#6e6e6e',
422
- gridColor: '#bfbfbf',
423
- labelColor: '#000000',
424
- legendPageNavigatorMarkerColor: '#000000',
425
- cardColor: '#545454'
426
- }
412
+ export var THEME_NAME_MAP = {
413
+ DARK: 'dark',
414
+ LIGHT: 'light'
427
415
  };
416
+ export var STAT_ITEM_THEME_COLORS = (_STAT_ITEM_THEME_COLO = {}, _defineProperty(_STAT_ITEM_THEME_COLO, THEME_NAME_MAP.DARK, {
417
+ textColor: '#ffffff',
418
+ gridColor: '#4E4E56',
419
+ labelColor: '#ffffff',
420
+ legendPageNavigatorMarkerColor: '#ffffff',
421
+ cardColor: '#ffffff'
422
+ }), _defineProperty(_STAT_ITEM_THEME_COLO, THEME_NAME_MAP.LIGHT, {
423
+ textColor: '#6e6e6e',
424
+ gridColor: '#bfbfbf',
425
+ labelColor: '#000000',
426
+ legendPageNavigatorMarkerColor: '#000000',
427
+ cardColor: '#545454'
428
+ }), _STAT_ITEM_THEME_COLO);
428
429
  export var DATA_SORT_TYPE = {
429
430
  NOT_SORTED: 'not_sorted',
430
431
  ASCENDING: 'ascending',
@@ -509,4 +510,4 @@ export var LEGEND_DIRECTION_MAP = {
509
510
  VERTICAL: 'vertical'
510
511
  };
511
512
  export var Y_AXIS_TYPE_PREFIX = '__y_axis__';
512
- export var STATISTIC_TYPE_SHOW = (_STATISTIC_TYPE_SHOW = {}, _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR, 'Basic_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR_GROUP, 'Grouped_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR_STACK, 'Stacked_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMPARE_BAR, 'Time_comparison_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.CUSTOM_BAR, 'Custom_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HORIZONTAL_BAR, 'Basic_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HORIZONTAL_GROUP_BAR, 'Grouped_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.STACKED_HORIZONTAL_BAR, 'Stacked_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMPLETENESS_CHART, 'Completeness_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.GROUP_COMPLETENESS_CHART, 'Grouped_completeness_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.LINE, 'Basic_line_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.GROUP_LINE, 'Grouped_line_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.AREA_CHART, 'Area_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.AREA_GROUP_CHART, 'Grouped_area_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.PIE, 'Basic_pie_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.RING, 'Ring_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.SCATTER, 'Scatter_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMBINATION_CHART, 'Combination_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MAP, '中国地图'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MAP_BUBBLE, '中国地图(气泡图)'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.WORLD_MAP, 'World_map'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.WORLD_MAP_BUBBLE, 'World_map_bubble'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HEAT_MAP, 'Heat_map'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MIRROR, 'Mirror_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BASIC_NUMBER_CARD, 'Basic_number_card'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.TREND_CHART, 'Trend_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.DASHBOARD, 'Gauge'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.TREEMAP, 'Treemap'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.PIVOT_TABLE, 'Pivot_table'), _STATISTIC_TYPE_SHOW);
513
+ export var STATISTIC_TYPE_SHOW = (_STATISTIC_TYPE_SHOW = {}, _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR, 'Basic_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR_GROUP, 'Grouped_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BAR_STACK, 'Stacked_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMPARE_BAR, 'Time_comparison_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.CUSTOM_BAR, 'Custom_histogram'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HORIZONTAL_BAR, 'Basic_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HORIZONTAL_GROUP_BAR, 'Grouped_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.STACKED_HORIZONTAL_BAR, 'Stacked_bar_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMPLETENESS_CHART, 'Completeness_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.GROUP_COMPLETENESS_CHART, 'Grouped_completeness_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.LINE, 'Basic_line_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.GROUP_LINE, 'Grouped_line_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.AREA_CHART, 'Area_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.AREA_GROUP_CHART, 'Grouped_area_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.PIE, 'Basic_pie_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.RING, 'Ring_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.SCATTER, 'Scatter_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.COMBINATION_CHART, 'Combination_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MAP, '中国地图'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MAP_BUBBLE, '中国地图(气泡图)'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.WORLD_MAP, 'World_map'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.HEAT_MAP, 'Heat_map'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.MIRROR, 'Mirror_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.BASIC_NUMBER_CARD, 'Basic_number_card'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.TREND_CHART, 'Trend_chart'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.DASHBOARD, 'Gauge'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.TREEMAP, 'Treemap'), _defineProperty(_STATISTIC_TYPE_SHOW, STAT_TYPE.PIVOT_TABLE, 'Pivot_table'), _STATISTIC_TYPE_SHOW);
package/es/dashboard.js CHANGED
@@ -39,30 +39,35 @@ var DashBoard = /*#__PURE__*/function (_Component) {
39
39
  console.log(error);
40
40
  }
41
41
  };
42
- _this.onDTableDataChange = function (value) {
43
- _this.clearCalculations();
44
- var _this$initDashboard = _this.initDashboard({
45
- value: value
46
- }),
42
+ _this.onLocalDTableChanged = function (value) {
43
+ if (_this.updatingLocalStatistics) {
44
+ // it's unnecessary to notify data changed during update statistics
45
+ _this.value = value;
46
+ _this.updatingLocalStatistics = false;
47
+ return;
48
+ }
49
+ _this.onDTableChanged(value);
50
+ };
51
+ _this.onServerDTableChanged = function (value) {
52
+ _this.onDTableChanged(value);
53
+ };
54
+ _this.onDTableChanged = function (value) {
55
+ _this.value = value;
56
+ _this.disabledUpdateLayout = true;
57
+ var _this$initDashboard = _this.initDashboard(),
47
58
  statistics = _this$initDashboard.statistics,
48
59
  selectedDashboardIdx = _this$initDashboard.selectedDashboardIdx;
49
60
  _this.setState({
50
61
  statistics: statistics,
51
62
  selectedDashboardIdx: selectedDashboardIdx,
52
- refresh: true
53
- }, function () {
54
- setTimeout(function () {
55
- _this.setState({
56
- refresh: false
57
- });
58
- });
63
+ dtableChangedTime: Date.now()
59
64
  });
60
65
  };
61
- _this.initDashboard = function (_ref) {
62
- var value = _ref.value;
66
+ _this.initDashboard = function () {
63
67
  var _window$dtable = window.dtable,
64
68
  username = _window$dtable.username,
65
69
  userId = _window$dtable.userId;
70
+ var value = _this.value;
66
71
  _this.chartCalculator = new ChartCalculator({
67
72
  username: username,
68
73
  userId: userId,
@@ -77,7 +82,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
77
82
  updateStatistics: _this.props.updateStatistics,
78
83
  deletePluginSettings: _this.props.deletePluginSettings
79
84
  });
80
- _this.initLabelColorConfigs(value);
85
+ _this.initLabelColorConfigs();
81
86
  var statistics = _this.dashboardService.getStatistics();
82
87
  var selectedDashboardIdx = _this.getSelectedDashboardIdxFromLocal(KEY_SELECTED_DASHBOARD) || 0;
83
88
  if (!statistics[selectedDashboardIdx]) {
@@ -88,9 +93,9 @@ var DashBoard = /*#__PURE__*/function (_Component) {
88
93
  selectedDashboardIdx: selectedDashboardIdx
89
94
  };
90
95
  };
91
- _this.initLabelColorConfigs = function (value) {
96
+ _this.initLabelColorConfigs = function () {
92
97
  var systemCustomColors = window.dtable.customColors || [];
93
- var baseSettings = value && value.settings;
98
+ var baseSettings = _this.value && _this.value.settings;
94
99
  var baseCustomColors = baseSettings && baseSettings.custom_colors || [];
95
100
  _this.labelColorConfigs = [].concat(_toConsumableArray(LABEL_COLORS.map(function (color) {
96
101
  return {
@@ -127,10 +132,8 @@ var DashBoard = /*#__PURE__*/function (_Component) {
127
132
  localStorage.setItem(KEY_SELECTED_DASHBOARD, JSON.stringify(selectedViewIds));
128
133
  };
129
134
  _this.getActiveTable = function () {
130
- var _this$props = _this.props,
131
- value = _this$props.value,
132
- activeTableIdx = _this$props.activeTableIdx;
133
- return TableUtils.getTableByIndex(value.tables, activeTableIdx);
135
+ var activeTableIdx = _this.props.activeTableIdx;
136
+ return TableUtils.getTableByIndex(_this.value.tables, activeTableIdx);
134
137
  };
135
138
  _this.getActiveView = function () {
136
139
  var activeViewId = _this.props.activeViewId;
@@ -138,11 +141,11 @@ var DashBoard = /*#__PURE__*/function (_Component) {
138
141
  if (!activeViewId) return selectedTable.views[0];
139
142
  return Views.getViewById(selectedTable.views, activeViewId);
140
143
  };
141
- _this.getInitChart = function (_ref2) {
142
- var chartType = _ref2.chartType,
143
- dashboard = _ref2.dashboard,
144
- activeTable = _ref2.activeTable,
145
- activeView = _ref2.activeView;
144
+ _this.getInitChart = function (_ref) {
145
+ var chartType = _ref.chartType,
146
+ dashboard = _ref.dashboard,
147
+ activeTable = _ref.activeTable,
148
+ activeView = _ref.activeView;
146
149
  return _this.chartService.getInitChart({
147
150
  type: chartType,
148
151
  dashboard: dashboard,
@@ -150,10 +153,10 @@ var DashBoard = /*#__PURE__*/function (_Component) {
150
153
  activeView: activeView
151
154
  });
152
155
  };
153
- _this.getConvertedChart = function (_ref3) {
154
- var originalStatistic = _ref3.originalStatistic,
155
- targetStatisticType = _ref3.targetStatisticType,
156
- activeTable = _ref3.activeTable;
156
+ _this.getConvertedChart = function (_ref2) {
157
+ var originalStatistic = _ref2.originalStatistic,
158
+ targetStatisticType = _ref2.targetStatisticType,
159
+ activeTable = _ref2.activeTable;
157
160
  return _this.chartService.getConvertedChart({
158
161
  originalStatistic: originalStatistic,
159
162
  targetStatisticType: targetStatisticType,
@@ -161,7 +164,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
161
164
  });
162
165
  };
163
166
  _this.selectDashboard = function (selectedDashboardIdx) {
164
- _this.isInitDashboard = true;
167
+ _this.disabledUpdateLayout = true;
165
168
  _this.setSelectedDashboardIdx(selectedDashboardIdx);
166
169
  _this.clearCalculations();
167
170
  _this.setState({
@@ -255,10 +258,15 @@ var DashBoard = /*#__PURE__*/function (_Component) {
255
258
  });
256
259
  };
257
260
  _this.modifyDashboardLayout = function (layout) {
261
+ // prevent unexpected refresh.
258
262
  if (_this.isInitDashboard) {
259
263
  _this.isInitDashboard = false;
260
264
  return;
261
265
  }
266
+ if (_this.disabledUpdateLayout) {
267
+ _this.disabledUpdateLayout = false;
268
+ return;
269
+ }
262
270
  var updatedStatistics = _this.dashboardService.update({
263
271
  action: DASHBOARD_ACTION_TYPE.MODIFY_DASHBOARD_LAYOUT,
264
272
  payload: {
@@ -286,6 +294,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
286
294
  _this.addChart(newChart);
287
295
  };
288
296
  _this.deleteChart = function (chartId) {
297
+ _this.disabledUpdateLayout = true;
289
298
  var updatedStatistics = _this.dashboardService.update({
290
299
  action: DASHBOARD_ACTION_TYPE.DELETE_CHART,
291
300
  payload: {
@@ -301,6 +310,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
301
310
  if (!_this.chartCalculator.isValidChart(chart)) {
302
311
  return;
303
312
  }
313
+ _this.disabledUpdateLayout = true;
304
314
  var updatedStatistics = _this.dashboardService.update({
305
315
  action: DASHBOARD_ACTION_TYPE.ADD_CHART,
306
316
  payload: {
@@ -329,16 +339,17 @@ var DashBoard = /*#__PURE__*/function (_Component) {
329
339
  };
330
340
  _this.updateStatistics = function (updates, callback) {
331
341
  var statistics = updates.statistics;
342
+ _this.updatingLocalStatistics = true;
332
343
  _this.setState(updates, function () {
333
344
  callback && callback();
334
345
  _this.props.updateStatistics(statistics);
335
346
  });
336
347
  };
337
348
  _this.getTableById = function (tableId) {
338
- return TableUtils.getTableById(_this.props.value.tables, tableId);
349
+ return TableUtils.getTableById(_this.value.tables, tableId);
339
350
  };
340
351
  _this.getTables = function () {
341
- return _this.props.value.tables;
352
+ return _this.value.tables;
342
353
  };
343
354
  _this.getViews = function (table) {
344
355
  return table.views;
@@ -353,21 +364,22 @@ var DashBoard = /*#__PURE__*/function (_Component) {
353
364
  var _value = props.value;
354
365
  var defaultChartTitle = intl.get('Untitled');
355
366
  _this.defaultDashboardName = intl.get('Default_dashboard');
367
+ _this.value = _value;
356
368
  _this.chartService = new ChartService({
357
369
  defaultChartTitle: defaultChartTitle
358
370
  });
359
371
  _this.statisticThreadManager = new ThreadManager((navigator.hardwareConcurrency || 4) - 1);
360
- var _this$initDashboard2 = _this.initDashboard({
361
- value: _value
362
- }),
372
+ var _this$initDashboard2 = _this.initDashboard(),
363
373
  _statistics = _this$initDashboard2.statistics,
364
374
  _selectedDashboardIdx = _this$initDashboard2.selectedDashboardIdx;
365
375
  _this.state = {
366
376
  statistics: _statistics,
367
377
  selectedDashboardIdx: _selectedDashboardIdx,
368
- refresh: false
378
+ dtableChangedTime: null
369
379
  };
370
380
  _this.isInitDashboard = true;
381
+ _this.updatingLocalStatistics = false;
382
+ _this.disabledUpdateLayout = false;
371
383
  _this.loadSvg();
372
384
  return _this;
373
385
  }
@@ -375,12 +387,14 @@ var DashBoard = /*#__PURE__*/function (_Component) {
375
387
  key: "componentDidMount",
376
388
  value: function componentDidMount() {
377
389
  var eventBus = this.props.eventBus;
378
- this.unsubscribeRemoteTableDataChange = eventBus.subscribe('remote-dtable-changed', this.onDTableDataChange);
390
+ this.unsubscribeLocalDtableChanged = eventBus.subscribe('local-dtable-changed', this.onLocalDTableChanged);
391
+ this.unsubscribeRemoteDtableChange = eventBus.subscribe('remote-dtable-changed', this.onServerDTableChanged);
379
392
  }
380
393
  }, {
381
394
  key: "componentWillUnmount",
382
395
  value: function componentWillUnmount() {
383
- this.unsubscribeRemoteTableDataChange();
396
+ this.unsubscribeLocalDtableChanged();
397
+ this.unsubscribeRemoteDtableChange();
384
398
  this.clearCalculations();
385
399
  }
386
400
  }, {
@@ -390,14 +404,14 @@ var DashBoard = /*#__PURE__*/function (_Component) {
390
404
  var _this$state3 = this.state,
391
405
  statistics = _this$state3.statistics,
392
406
  selectedDashboardIdx = _this$state3.selectedDashboardIdx,
393
- editingChart = _this$state3.editingChart,
394
- refresh = _this$state3.refresh;
407
+ dtableChangedTime = _this$state3.dtableChangedTime,
408
+ editingChart = _this$state3.editingChart;
395
409
  var isTableReadOnly = this.isTableReadOnly();
396
410
  var colorThemeName = this.dashboardService.getColorThemeName();
397
411
  return isMobile ? /*#__PURE__*/React.createElement(MobileDashboard, {
398
412
  isTableReadOnly: isTableReadOnly,
399
413
  colorThemeName: colorThemeName,
400
- refresh: refresh,
414
+ dtableChangedTime: dtableChangedTime,
401
415
  statistics: statistics,
402
416
  selectedDashboardIdx: selectedDashboardIdx,
403
417
  chartCalculator: this.chartCalculator,
@@ -412,7 +426,7 @@ var DashBoard = /*#__PURE__*/function (_Component) {
412
426
  }) : /*#__PURE__*/React.createElement(DesktopDashboard, {
413
427
  isTableReadOnly: isTableReadOnly,
414
428
  colorThemeName: colorThemeName,
415
- refresh: refresh,
429
+ dtableChangedTime: dtableChangedTime,
416
430
  statistics: statistics,
417
431
  editingChart: editingChart,
418
432
  selectedDashboardIdx: selectedDashboardIdx,