dtable-statistic 4.0.7 → 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 (60) hide show
  1. package/es/calculator/basic-chart-calculator.js +27 -18
  2. package/es/calculator/combination-calculator.js +34 -9
  3. package/es/calculator/compare-bar-calculator.js +37 -30
  4. package/es/calculator/heat-map-calculator.js +25 -14
  5. package/es/calculator/map-calculator.js +25 -14
  6. package/es/calculator/mirror-calculator.js +29 -14
  7. package/es/calculator/pivot-table-calculator.js +78 -51
  8. package/es/calculator/workers/basic-chart-calculator-worker.js +21 -6
  9. package/es/calculator/workers/combination-calculator-worker.js +20 -5
  10. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +12 -6
  11. package/es/calculator/workers/mirror-calculator-worker.js +15 -6
  12. package/es/calculator/workers/pivot-table-calculator-worker.js +87 -41
  13. package/es/calculator/world-map-calculator.js +25 -14
  14. package/es/components/dialog/enlarged-chart-dialog.js +2 -2
  15. package/es/components/dialog/statistic-record-dialog/index.js +71 -41
  16. package/es/constants/index.js +30 -29
  17. package/es/dashboard.js +57 -43
  18. package/es/desktop-dashboard.js +16 -51
  19. package/es/index.js +34 -2
  20. package/es/locale/lang/de.js +2 -0
  21. package/es/locale/lang/en.js +2 -0
  22. package/es/locale/lang/fr.js +2 -0
  23. package/es/locale/lang/zh_CN.js +2 -0
  24. package/es/mobile-dashboard.js +5 -5
  25. package/es/model/horizontal-bar-group.js +2 -0
  26. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +1 -2
  27. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +1 -1
  28. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +20 -3
  29. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +2 -8
  30. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +23 -2
  31. package/es/stat-list/chart-preview.js +3 -4
  32. package/es/stat-list/index.js +10 -4
  33. package/es/stat-view/area-chart.js +177 -162
  34. package/es/stat-view/bar-chart.js +221 -222
  35. package/es/stat-view/base-chart.js +79 -7
  36. package/es/stat-view/basic-number-card.js +11 -19
  37. package/es/stat-view/combination-chart.js +100 -83
  38. package/es/stat-view/compare-chart.js +133 -144
  39. package/es/stat-view/completeness-chart.js +108 -102
  40. package/es/stat-view/custom-bar.js +79 -99
  41. package/es/stat-view/dashboard-chart.js +57 -57
  42. package/es/stat-view/heat-map.js +13 -32
  43. package/es/stat-view/horizontal-bar-chart.js +200 -230
  44. package/es/stat-view/index.js +2 -2
  45. package/es/stat-view/line-chart.js +162 -158
  46. package/es/stat-view/map.js +26 -40
  47. package/es/stat-view/mirror.js +88 -94
  48. package/es/stat-view/pie-chart.js +11 -39
  49. package/es/stat-view/pivot-table/index.js +4 -16
  50. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +22 -15
  51. package/es/stat-view/ring-chart.js +24 -42
  52. package/es/stat-view/scatter-chart.js +4 -21
  53. package/es/stat-view/treemap-chart.js +3 -12
  54. package/es/stat-view/trend-chart.js +6 -17
  55. package/es/stat-view/world-map.js +39 -50
  56. package/es/tabs/tab.js +2 -1
  57. package/es/utils/common-utils.js +24 -6
  58. package/es/utils/sql-utils.js +10 -9
  59. package/es/utils/stat-utils.js +8 -5
  60. package/package.json +1 -1
@@ -5,18 +5,15 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import intl from 'react-intl-universal';
8
- import { TableUtils, getNumberDisplayString } from 'dtable-store';
8
+ import { TableUtils } from 'dtable-store';
9
9
  import BaseChart from './base-chart';
10
10
  import { Chart } from '../custom-g2';
11
- import { Loading } from '../components';
12
- import { getCurrentTheme, getLabelFontSize } from '../utils/common-utils';
13
- import { getChartDisplayLabels, getChartGroups } from '../utils/basic-chart-utils';
14
- import { DEFAULT_NUMBER_FORMAT_OBJECT, EMPTY_NAME, STAT_ITEM_THEME_COLORS, SUMMARY_TYPE, LABEL_CONFIG_CHANGED, NO_STATISTIC_RESULTS, STATISTICS_COUNT_SHOW, TITLE_AMOUNT, TITLE_INCREASE } from '../constants';
11
+ import { getCurrentTheme } from '../utils/common-utils';
12
+ import { getChartGroups } from '../utils/basic-chart-utils';
13
+ import { DEFAULT_NUMBER_FORMAT_OBJECT, EMPTY_NAME, SUMMARY_TYPE, LABEL_CONFIG_CHANGED, STATISTICS_COUNT_SHOW, TITLE_AMOUNT, TITLE_INCREASE } from '../constants';
15
14
  var propTypes = {
16
15
  isPreview: PropTypes.bool,
17
- isEnlarge: PropTypes.bool,
18
16
  isEdit: PropTypes.bool,
19
- theme: PropTypes.string,
20
17
  colorThemeName: PropTypes.string,
21
18
  statItem: PropTypes.object,
22
19
  chartCalculator: PropTypes.object,
@@ -34,46 +31,21 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
34
31
  _this.drawChart = function (data) {
35
32
  var _this$props = _this.props,
36
33
  getTableById = _this$props.getTableById,
37
- isPreview = _this$props.isPreview,
38
34
  statItem = _this$props.statItem,
39
- isEnlarge = _this$props.isEnlarge,
40
- theme = _this$props.theme,
41
35
  colorThemeName = _this$props.colorThemeName;
42
- var display_data = statItem.display_data,
43
- display_increase_percentage = statItem.display_increase_percentage;
44
- var currentTheme = getCurrentTheme(colorThemeName);
45
- if (isPreview) {
46
- _this.chart = new Chart({
47
- container: _this.container,
48
- autoFit: true,
49
- appendPadding: [display_data || display_increase_percentage ? 17 : 0, 0, 0, 0]
50
- });
51
- } else {
52
- _this.chart = new Chart({
53
- container: _this.container,
54
- autoFit: true,
55
- height: 400,
56
- width: 700,
57
- appendPadding: [display_data || display_increase_percentage ? 17 : 0, 0, 0, 0]
58
- });
59
- }
60
- _this.chart.on('interval:click', function (e) {
61
- _this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
62
- });
63
36
  var table_id = statItem.table_id,
64
37
  y_axis_column_key = statItem.y_axis_column_key,
65
38
  y_axis_summary_type = statItem.y_axis_summary_type,
66
- y_axis_summary_method = statItem.y_axis_summary_method,
67
- y_axis_auto_range = statItem.y_axis_auto_range,
68
- y_axis_min = statItem.y_axis_min,
69
- y_axis_max = statItem.y_axis_max,
70
- display_increase = statItem.display_increase,
71
- increase_line_color = statItem.increase_line_color;
72
- var columnData = DEFAULT_NUMBER_FORMAT_OBJECT;
39
+ display_increase = statItem.display_increase;
40
+ _this.initChartHandler();
41
+ _this.chart.on('interval:click', function (e) {
42
+ _this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
43
+ });
44
+ var summaryColumnData = DEFAULT_NUMBER_FORMAT_OBJECT;
73
45
  if (y_axis_summary_type === SUMMARY_TYPE.ADVANCED) {
74
46
  var table = getTableById(table_id);
75
47
  var summaryColumn = TableUtils.getTableColumnByKey(table, y_axis_column_key) || {};
76
- columnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
48
+ summaryColumnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
77
49
  }
78
50
  _this.chart.data(data, {
79
51
  'name': {
@@ -83,35 +55,85 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
83
55
  });
84
56
  var width = _this.chart.coordinateBBox.width;
85
57
  var chartData = getChartGroups(data);
86
- var labelCount = chartData.length;
87
- if (Math.floor(width / labelCount) <= 20) {
88
- var displayLabels = getChartDisplayLabels(width, 20, chartData);
89
- labelCount = displayLabels.length;
58
+ var ticks = _this.getTicks(chartData, width);
59
+ if (ticks.length > 0) {
90
60
  _this.chart.scale('name', {
91
- ticks: displayLabels
61
+ ticks: ticks
92
62
  });
93
63
  }
94
64
 
95
65
  // set Coord type
96
66
  _this.chart.coordinate('rect');
67
+ _this.handleAutoRange(data, summaryColumnData);
68
+ _this.chart.scale({
69
+ group_name: {
70
+ type: 'cat'
71
+ }
72
+ });
73
+ var currentTheme = getCurrentTheme(colorThemeName);
74
+ var themeColors = _this.getThemeColors();
75
+ _this.drawBar({
76
+ currentTheme: currentTheme,
77
+ themeColors: themeColors
78
+ });
79
+ _this.setTooltip();
80
+ if (display_increase) {
81
+ _this.drawIncreaseLine({
82
+ themeColors: themeColors
83
+ });
84
+ }
85
+ _this.setAxis(themeColors);
86
+ _this.setLegend(themeColors);
87
+ _this.chart.interaction('active-region');
88
+ _this.chart.removeInteraction('legend-filter');
89
+ _this.chart.render();
90
+ _this.renderAxisLabel();
91
+ };
92
+ _this.initChartHandler = function () {
93
+ var _this$props2 = _this.props,
94
+ isPreview = _this$props2.isPreview,
95
+ statItem = _this$props2.statItem;
96
+ var display_data = statItem.display_data,
97
+ display_increase_percentage = statItem.display_increase_percentage;
98
+ var config = {
99
+ container: _this.container,
100
+ autoFit: true,
101
+ appendPadding: [display_data || display_increase_percentage ? 17 : 0, 0, 0, 0]
102
+ };
103
+ if (!isPreview) {
104
+ config.height = 400;
105
+ config.width = 700;
106
+ }
107
+ _this.chart = new Chart(config);
108
+ };
109
+ _this.handleAutoRange = function (data, summaryColumnData) {
110
+ var _this$props$statItem = _this.props.statItem,
111
+ y_axis_summary_method = _this$props$statItem.y_axis_summary_method,
112
+ y_axis_auto_range = _this$props$statItem.y_axis_auto_range,
113
+ y_axis_min = _this$props$statItem.y_axis_min,
114
+ y_axis_max = _this$props$statItem.y_axis_max;
97
115
  var valueScaleOptions = {
98
116
  formatter: function formatter(value) {
99
- return getNumberDisplayString(value, columnData);
117
+ return _this.getNumberDisplayString(value, summaryColumnData, y_axis_summary_method);
100
118
  }
101
119
  };
120
+
121
+ // eslint-disable-next-line
102
122
  if (y_axis_auto_range == undefined || y_axis_auto_range) {
103
- valueScaleOptions = Object.assign({}, valueScaleOptions, {
123
+ valueScaleOptions = Object.assign(valueScaleOptions, {
104
124
  nice: true
105
125
  });
106
126
  } else {
107
- valueScaleOptions = Object.assign({}, valueScaleOptions, {
127
+ valueScaleOptions = Object.assign(valueScaleOptions, {
108
128
  min: y_axis_min,
109
129
  max: y_axis_max
110
130
  });
131
+
111
132
  // set the filter rule
112
133
  _this.chart.filter('value', function (value) {
113
134
  return value >= y_axis_min;
114
135
  });
136
+
115
137
  // filter the data
116
138
  _this.chart.filterData(data);
117
139
  }
@@ -122,31 +144,25 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
122
144
  },
123
145
  value: valueScaleOptions
124
146
  });
125
- _this.chart.scale({
126
- group_name: {
127
- type: 'cat'
128
- }
129
- });
130
- var themeColors = STAT_ITEM_THEME_COLORS.light;
131
- if (theme === 'dark' && !isEnlarge && isPreview) {
132
- themeColors = STAT_ITEM_THEME_COLORS.dark;
133
- }
134
-
135
- // bar chart
136
- _this.chart.interval().label(display_data ? 'value' : false, {
137
- formatter: function formatter(value) {
138
- return getNumberDisplayString(value, columnData);
139
- },
147
+ };
148
+ _this.drawBar = function (_ref) {
149
+ var themeColors = _ref.themeColors,
150
+ currentTheme = _ref.currentTheme;
151
+ var _this$props$statItem2 = _this.props.statItem,
152
+ y_axis_summary_type = _this$props$statItem2.y_axis_summary_type,
153
+ y_axis_summary_method = _this$props$statItem2.y_axis_summary_method,
154
+ display_data = _this$props$statItem2.display_data;
155
+ _this.chart.interval().label(display_data ? 'formatted_value' : false, {
140
156
  style: {
141
157
  fontSize: _this.getLabelFontSize(),
142
158
  fill: themeColors.textColor
143
159
  }
144
- }).position('name*value').color('group_name', currentTheme && currentTheme.colors).tooltip('name*value*raw_name', function (name, value, raw_name) {
160
+ }).position('name*value').color('group_name', currentTheme && currentTheme.colors).tooltip('name*formatted_value*raw_name', function (name, value, raw_name) {
145
161
  var nameContent = !raw_name && typeof raw_name !== 'number' ? intl.get(EMPTY_NAME) : raw_name;
146
162
  var titleContent = y_axis_summary_type === 'count' ? intl.get(TITLE_AMOUNT) : intl.get(STATISTICS_COUNT_SHOW[y_axis_summary_method]);
147
163
  return {
164
+ value: value,
148
165
  title: titleContent,
149
- value: getNumberDisplayString(value, columnData),
150
166
  name: nameContent
151
167
  };
152
168
  }).adjust('dodge').state({
@@ -156,57 +172,57 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
156
172
  }
157
173
  }
158
174
  });
175
+ };
176
+ _this.setTooltip = function () {
159
177
  _this.chart.tooltip({
160
178
  showTitle: true,
161
179
  showMarkers: false,
162
180
  containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
163
181
  itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
164
182
  domStyles: {
165
- 'g2-tooltip': {
166
- borderRadius: '2px',
167
- backgroundColor: '#fff',
168
- padding: '10px'
169
- },
170
- 'tooltip-item': {
171
- marginTop: '5px'
172
- }
183
+ 'g2-tooltip': _this.getDefaultChartStyleByKey('g2-tooltip'),
184
+ 'tooltip-item': _this.getDefaultChartStyleByKey('tooltip-item')
173
185
  }
174
186
  });
175
- if (display_increase) {
176
- // line chart
177
- _this.chart.line().position('name*increase_value').size(3).color(increase_line_color || '#fbd44a').shape('smooth').tooltip('name*increase_value', function (name, value) {
178
- return {
179
- title: intl.get(TITLE_INCREASE),
180
- value: getNumberDisplayString(value, {
181
- format: 'percent'
182
- }),
183
- name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
184
- };
185
- });
186
- _this.chart.point().label(display_increase_percentage ? 'increase_value' : false, function (value) {
187
- return {
188
- content: getNumberDisplayString(value, {
189
- format: 'percent'
190
- }),
191
- style: {
192
- fill: themeColors.textColor
193
- }
194
- };
195
- }).color(increase_line_color || '#fbd44a').position('name*increase_value').size(3).tooltip('name*increase_value', function (name, value) {
196
- return {
197
- title: intl.get(TITLE_INCREASE),
198
- value: getNumberDisplayString(value, {
199
- format: 'percent'
200
- }),
201
- name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
202
- };
203
- });
204
- _this.chart.axis('increase_value', {
205
- label: null,
206
- grid: null
207
- });
208
- }
209
- // set axis label and tooltip
187
+ };
188
+ _this.drawIncreaseLine = function (_ref2) {
189
+ var themeColors = _ref2.themeColors;
190
+ var _this$props$statItem3 = _this.props.statItem,
191
+ increase_line_color = _this$props$statItem3.increase_line_color,
192
+ display_increase_percentage = _this$props$statItem3.display_increase_percentage;
193
+ _this.chart.line().position('name*increase_value').size(3).color(increase_line_color || '#fbd44a').shape('smooth').tooltip('name*increase_value', function (name, value) {
194
+ return {
195
+ title: intl.get(TITLE_INCREASE),
196
+ value: _this.getNumberDisplayString(value || 0, {
197
+ format: 'percent'
198
+ }),
199
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
200
+ };
201
+ });
202
+ _this.chart.point().label(display_increase_percentage ? 'increase_value' : false, function (value) {
203
+ return {
204
+ content: _this.getNumberDisplayString(value || 0, {
205
+ format: 'percent'
206
+ }),
207
+ style: {
208
+ fill: themeColors.textColor
209
+ }
210
+ };
211
+ }).color(increase_line_color || '#fbd44a').position('name*increase_value').size(3).tooltip('name*increase_value', function (name, value) {
212
+ return {
213
+ title: intl.get(TITLE_INCREASE),
214
+ value: _this.getNumberDisplayString(value || 0, {
215
+ format: 'percent'
216
+ }),
217
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
218
+ };
219
+ });
220
+ _this.chart.axis('increase_value', {
221
+ label: null,
222
+ grid: null
223
+ });
224
+ };
225
+ _this.setAxis = function (themeColors) {
210
226
  _this.chart.axis('name', {
211
227
  line: {
212
228
  style: themeColors.gridColor
@@ -216,16 +232,7 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
216
232
  style: {
217
233
  fill: themeColors.textColor
218
234
  },
219
- formatter: function formatter(name) {
220
- var label = name;
221
- if (name.length > 10) {
222
- label = "".concat(name.slice(0, 10), "...");
223
- }
224
- if (name === '' || name === 'undefined') {
225
- label = intl.get(EMPTY_NAME);
226
- }
227
- return label;
228
- }
235
+ formatter: _this.labelFormatter
229
236
  }
230
237
  });
231
238
  _this.chart.axis('value', {
@@ -242,6 +249,8 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
242
249
  }
243
250
  }
244
251
  });
252
+ };
253
+ _this.setLegend = function (themeColors) {
245
254
  var legendPosition = 'bottom';
246
255
  _this.chart.legend('group_name', {
247
256
  position: legendPosition,
@@ -268,29 +277,16 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
268
277
  }
269
278
  }
270
279
  });
271
- _this.chart.interaction('active-region');
272
- _this.chart.removeInteraction('legend-filter');
273
- _this.chart.render();
274
- _this.renderAxisLabel();
275
- };
276
- _this.getLabelFontSize = function () {
277
- var statItem = _this.props.statItem;
278
- var label_font_size = statItem.label_font_size;
279
- return getLabelFontSize(label_font_size);
280
280
  };
281
281
  _this.renderAxisLabel = function (newStatItem) {
282
- var _this$props2 = _this.props,
283
- getTableById = _this$props2.getTableById,
284
- statItem = _this$props2.statItem;
282
+ var _this$props3 = _this.props,
283
+ getTableById = _this$props3.getTableById,
284
+ statItem = _this$props3.statItem;
285
285
  if (newStatItem && newStatItem._id !== statItem._id) {
286
286
  return;
287
287
  }
288
288
  if (!_this.chart) return;
289
289
  statItem = newStatItem || statItem;
290
- var _this$props3 = _this.props,
291
- isEnlarge = _this$props3.isEnlarge,
292
- isPreview = _this$props3.isPreview,
293
- theme = _this$props3.theme;
294
290
  var _statItem = statItem,
295
291
  table_id = _statItem.table_id,
296
292
  x_axis_column_key = _statItem.x_axis_column_key,
@@ -302,10 +298,7 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
302
298
  y_axis_summary_type = _statItem.y_axis_summary_type;
303
299
  var table = getTableById(table_id);
304
300
  var autoPadding = _this.chart.autoPadding;
305
- var textColor = '#999999';
306
- if (theme === 'dark' && !isEnlarge && isPreview) {
307
- textColor = '#ffffff';
308
- }
301
+ var textColor = _this.getAxisLabelColor();
309
302
  var xAxisID = "chart-x-axis-label_".concat(statItem._id);
310
303
  var chartContainer = _this.chart.getCanvas().get('container');
311
304
  var xLabel = chartContainer.querySelector("#".concat(xAxisID));
@@ -464,13 +457,9 @@ var CompareChart = /*#__PURE__*/function (_BaseChart) {
464
457
  showResultDescription = _this$state.showResultDescription;
465
458
  var show_y_axis_label = statItem.show_y_axis_label,
466
459
  show_x_axis_label = statItem.show_x_axis_label;
467
- return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && /*#__PURE__*/React.createElement("div", {
468
- className: 'statistic-chart-loading-container'
469
- }, /*#__PURE__*/React.createElement(Loading, null)), showResultDescription && /*#__PURE__*/React.createElement("div", {
470
- className: 'statistic-chart-text'
471
- }, intl.get(NO_STATISTIC_RESULTS)), /*#__PURE__*/React.createElement("div", {
472
- ref: function ref(_ref) {
473
- return _this4.container = _ref;
460
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && this.renderLoading(), showResultDescription && this.renderEmpty(), /*#__PURE__*/React.createElement("div", {
461
+ ref: function ref(_ref3) {
462
+ return _this4.container = _ref3;
474
463
  },
475
464
  style: {
476
465
  padding: show_y_axis_label || show_x_axis_label ? 30 : 20