dtable-statistic 4.0.2-test-2

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 (210) hide show
  1. package/README.md +3 -0
  2. package/es/api/dtable-db-api.js +43 -0
  3. package/es/assets/css/color-picker.css +53 -0
  4. package/es/assets/css/color-rules-popover.css +144 -0
  5. package/es/assets/css/color-theme-dialog.css +40 -0
  6. package/es/assets/css/dashboard.css +562 -0
  7. package/es/assets/css/dialog.css +415 -0
  8. package/es/assets/css/mobile-dashboard.module.css +91 -0
  9. package/es/assets/css/slider.css +77 -0
  10. package/es/assets/css/statistic-chart.module.css +11 -0
  11. package/es/assets/css/statistic-custom-title.module.css +3 -0
  12. package/es/assets/css/statistic-custom.module.css +4 -0
  13. package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
  14. package/es/assets/css/statistic-time-picker.module.css +21 -0
  15. package/es/assets/css/theme.css +61 -0
  16. package/es/assets/images/icon.png +0 -0
  17. package/es/calculator/base-calculator.js +111 -0
  18. package/es/calculator/basic-chart-calculator.js +571 -0
  19. package/es/calculator/combination-calculator.js +296 -0
  20. package/es/calculator/compare-bar-calculator.js +291 -0
  21. package/es/calculator/completeness-calculator.js +307 -0
  22. package/es/calculator/copy-value.js +47 -0
  23. package/es/calculator/dashboard-calculator.js +146 -0
  24. package/es/calculator/heat-map-calculator.js +225 -0
  25. package/es/calculator/horizontal-bar-calculator.js +100 -0
  26. package/es/calculator/index.js +88 -0
  27. package/es/calculator/map-calculator.js +169 -0
  28. package/es/calculator/mirror-calculator.js +217 -0
  29. package/es/calculator/number-card-calculator.js +135 -0
  30. package/es/calculator/pivot-table-calculator.js +810 -0
  31. package/es/calculator/scatter-calculator.js +150 -0
  32. package/es/calculator/thread-manager.js +70 -0
  33. package/es/calculator/trend-calculator.js +204 -0
  34. package/es/calculator/workers/basic-chart-calculator-worker.js +410 -0
  35. package/es/calculator/workers/calculator.worker.js +22 -0
  36. package/es/calculator/workers/card-calculator-worker.js +28 -0
  37. package/es/calculator/workers/combination-calculator-worker.js +257 -0
  38. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +149 -0
  39. package/es/calculator/workers/completeness-calculator-worker.js +153 -0
  40. package/es/calculator/workers/dashboard-calculator-worker.js +56 -0
  41. package/es/calculator/workers/mirror-calculator-worker.js +132 -0
  42. package/es/calculator/workers/pivot-table-calculator-worker.js +615 -0
  43. package/es/calculator/workers/scatter-calculator-worker.js +67 -0
  44. package/es/calculator/workers/trend-calculator-worker.js +93 -0
  45. package/es/calculator/world-map-calculator.js +193 -0
  46. package/es/components/common-add-tool.js +19 -0
  47. package/es/components/dialog/chart-addition-edit-dialog.js +89 -0
  48. package/es/components/dialog/chart-addition-widgets/chart-selector.js +261 -0
  49. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +74 -0
  50. package/es/components/dialog/color-theme-dialog.js +71 -0
  51. package/es/components/dialog/enlarged-chart-dialog.js +73 -0
  52. package/es/components/dialog/new-table-dialog.js +113 -0
  53. package/es/components/dialog/new-view-dialog.js +87 -0
  54. package/es/components/dialog/rename-view-dialog.js +87 -0
  55. package/es/components/dialog/statistic-record-dialog/index.css +114 -0
  56. package/es/components/dialog/statistic-record-dialog/index.js +174 -0
  57. package/es/components/dialog/table-select-dialog.js +93 -0
  58. package/es/components/dropdown-menu/statistic-dropdown-menu.js +94 -0
  59. package/es/components/dtable-popover.js +109 -0
  60. package/es/components/dtable-search-input.js +137 -0
  61. package/es/components/dtable-select.js +104 -0
  62. package/es/components/index.js +11 -0
  63. package/es/components/loading.js +8 -0
  64. package/es/components/modal-portal.js +36 -0
  65. package/es/components/popover/color-rules/color-rule.js +179 -0
  66. package/es/components/popover/color-rules/index.js +87 -0
  67. package/es/components/popover/color-rules/rule-filters/filter.js +214 -0
  68. package/es/components/popover/color-rules/rule-filters/index.css +214 -0
  69. package/es/components/popover/color-rules/rule-filters/index.js +97 -0
  70. package/es/components/popover/color-rules/rule-filters/number-input.js +85 -0
  71. package/es/components/popover/color-rules-popover.js +213 -0
  72. package/es/components/popover/color-selector-popover.js +85 -0
  73. package/es/components/seatable-radio/index.css +51 -0
  74. package/es/components/seatable-radio/index.js +28 -0
  75. package/es/components/select/index.js +2 -0
  76. package/es/components/select/option-group.css +104 -0
  77. package/es/components/select/option-group.js +225 -0
  78. package/es/components/select/option.js +51 -0
  79. package/es/components/select/select.css +211 -0
  80. package/es/components/select/select.js +157 -0
  81. package/es/components/toast/alert.js +130 -0
  82. package/es/components/toast/index.js +3 -0
  83. package/es/components/toast/toast.js +164 -0
  84. package/es/components/toast/toastManager.js +150 -0
  85. package/es/components/toast/toaster.js +64 -0
  86. package/es/constants/color-rules.js +8 -0
  87. package/es/constants/dtable-select-style.js +61 -0
  88. package/es/constants/event-types.js +1 -0
  89. package/es/constants/index.js +501 -0
  90. package/es/constants/key-codes.js +102 -0
  91. package/es/constants/zIndexes.js +1 -0
  92. package/es/custom-g2.js +614 -0
  93. package/es/dashboard.js +408 -0
  94. package/es/desktop-dashboard.js +299 -0
  95. package/es/index.js +33 -0
  96. package/es/locale/index.js +17 -0
  97. package/es/locale/lang/de.js +237 -0
  98. package/es/locale/lang/en.js +237 -0
  99. package/es/locale/lang/fr.js +237 -0
  100. package/es/locale/lang/zh_CN.js +237 -0
  101. package/es/mobile-dashboard.js +103 -0
  102. package/es/model/collaborators.js +11 -0
  103. package/es/model/stat-item.js +340 -0
  104. package/es/model/statistic-dashboard.js +8 -0
  105. package/es/service/chart-service.js +192 -0
  106. package/es/service/dashboard-service.js +415 -0
  107. package/es/stat-editor/chart-name-editor.js +75 -0
  108. package/es/stat-editor/index.js +74 -0
  109. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +149 -0
  110. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +415 -0
  111. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +193 -0
  112. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +13 -0
  113. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +107 -0
  114. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +332 -0
  115. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +170 -0
  116. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +141 -0
  117. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +219 -0
  118. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
  119. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +132 -0
  120. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +319 -0
  121. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +138 -0
  122. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +135 -0
  123. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +156 -0
  124. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +147 -0
  125. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +195 -0
  126. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +126 -0
  127. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +169 -0
  128. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +352 -0
  129. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +145 -0
  130. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +153 -0
  131. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +466 -0
  132. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +183 -0
  133. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +542 -0
  134. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +111 -0
  135. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +86 -0
  136. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +169 -0
  137. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +273 -0
  138. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +105 -0
  139. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +243 -0
  140. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +65 -0
  141. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +318 -0
  142. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +49 -0
  143. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +124 -0
  144. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +150 -0
  145. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +267 -0
  146. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +109 -0
  147. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +351 -0
  148. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +60 -0
  149. package/es/stat-editor/stat-settings/color-setting/color-picker.js +129 -0
  150. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +348 -0
  151. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +102 -0
  152. package/es/stat-editor/stat-settings/public-setting/base-settings.js +124 -0
  153. package/es/stat-editor/stat-settings/public-setting/calender.js +124 -0
  154. package/es/stat-editor/stat-settings/public-setting/column-settings.js +15 -0
  155. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +60 -0
  156. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +57 -0
  157. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +41 -0
  158. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +64 -0
  159. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +118 -0
  160. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +39 -0
  161. package/es/stat-list/chart-preview.js +139 -0
  162. package/es/stat-list/index.js +275 -0
  163. package/es/stat-view/area-chart.js +521 -0
  164. package/es/stat-view/bar-chart.js +568 -0
  165. package/es/stat-view/base-chart.js +44 -0
  166. package/es/stat-view/basic-number-card.js +255 -0
  167. package/es/stat-view/combination-chart.js +558 -0
  168. package/es/stat-view/compare-chart.js +485 -0
  169. package/es/stat-view/completeness-chart.js +389 -0
  170. package/es/stat-view/custom-bar.js +433 -0
  171. package/es/stat-view/dashboard-chart.js +317 -0
  172. package/es/stat-view/heat-map.js +501 -0
  173. package/es/stat-view/horizontal-bar-chart.js +569 -0
  174. package/es/stat-view/index.js +183 -0
  175. package/es/stat-view/line-chart.js +505 -0
  176. package/es/stat-view/map.js +428 -0
  177. package/es/stat-view/mirror.js +285 -0
  178. package/es/stat-view/pie-chart.js +326 -0
  179. package/es/stat-view/pivot-table/index.js +206 -0
  180. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +133 -0
  181. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +164 -0
  182. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
  183. package/es/stat-view/pivot-table/two-dimension-table.js +344 -0
  184. package/es/stat-view/ring-chart.js +416 -0
  185. package/es/stat-view/scatter-chart.js +367 -0
  186. package/es/stat-view/treemap-chart.js +318 -0
  187. package/es/stat-view/trend-chart.js +299 -0
  188. package/es/stat-view/world-map.js +443 -0
  189. package/es/tabs/index.js +252 -0
  190. package/es/tabs/statistic-tabs.module.css +154 -0
  191. package/es/tabs/tab.js +167 -0
  192. package/es/utils/basic-chart-utils.js +24 -0
  193. package/es/utils/cell-format.js +110 -0
  194. package/es/utils/cell-value.js +27 -0
  195. package/es/utils/collaborator.js +31 -0
  196. package/es/utils/color-utils.js +112 -0
  197. package/es/utils/column-utils.js +18 -0
  198. package/es/utils/column.js +13 -0
  199. package/es/utils/common-utils.js +303 -0
  200. package/es/utils/date-format.js +65 -0
  201. package/es/utils/export-table-utils.js +632 -0
  202. package/es/utils/index.js +26 -0
  203. package/es/utils/object.js +26 -0
  204. package/es/utils/row-utils.js +115 -0
  205. package/es/utils/search.js +67 -0
  206. package/es/utils/sql-utils.js +293 -0
  207. package/es/utils/stat-utils.js +353 -0
  208. package/es/utils/trend-utils.js +136 -0
  209. package/index.js +1 -0
  210. package/package.json +188 -0
@@ -0,0 +1,568 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import DataSet from '@antv/data-set';
8
+ import intl from 'react-intl-universal';
9
+ import { TableUtils, getNumberDisplayString } from 'dtable-store';
10
+ import BaseChart from './base-chart';
11
+ import { Chart } from '../custom-g2';
12
+ import { Loading } from '../components';
13
+ import { getCurrentTheme, getLabelFontSize, sortDataByGroupSum } from '../utils/common-utils';
14
+ import { getChartDisplayLabels, getChartGroups } from '../utils/basic-chart-utils';
15
+ import { getConvertedColorRules, getLabelColor } from '../utils/color-utils';
16
+ import { EMPTY_NAME, DEFAULT_NUMBER_FORMAT_OBJECT, SUMMARY_TYPE, STATISTICS_COUNT_SHOW, STAT_ITEM_THEME_COLORS, LABEL_CONFIG_CHANGED, STAT_TYPE, NO_STATISTIC_RESULTS, TITLE_AMOUNT, TYPE_COLOR_USING, STATISTICS_COUNT_TYPE } from '../constants';
17
+ var propTypes = {
18
+ isPreview: PropTypes.bool,
19
+ isEnlarge: PropTypes.bool,
20
+ isEdit: PropTypes.bool,
21
+ theme: PropTypes.string,
22
+ colorThemeName: PropTypes.string,
23
+ statItem: PropTypes.object,
24
+ chartCalculator: PropTypes.object,
25
+ eventBus: PropTypes.object,
26
+ getTableById: PropTypes.func,
27
+ toggleStatisticRecordsDialog: PropTypes.func
28
+ };
29
+ var BarChart = /*#__PURE__*/function (_BaseChart) {
30
+ _inherits(BarChart, _BaseChart);
31
+ var _super = _createSuper(BarChart);
32
+ function BarChart(props) {
33
+ var _this;
34
+ _classCallCheck(this, BarChart);
35
+ _this = _super.call(this, props);
36
+ _this.drawChart = function (originalData) {
37
+ var _this$props = _this.props,
38
+ getTableById = _this$props.getTableById,
39
+ isPreview = _this$props.isPreview,
40
+ statItem = _this$props.statItem,
41
+ isEnlarge = _this$props.isEnlarge,
42
+ theme = _this$props.theme,
43
+ colorThemeName = _this$props.colorThemeName;
44
+ var display_data = statItem.display_data,
45
+ type = statItem.type,
46
+ sort_type = statItem.sort_type;
47
+ var currentTheme = getCurrentTheme(colorThemeName);
48
+ var data = originalData;
49
+ if (type == STAT_TYPE.BAR_STACK && sort_type) {
50
+ data = sortDataByGroupSum(originalData, sort_type);
51
+ }
52
+ if (isPreview) {
53
+ _this.chart = new Chart({
54
+ container: _this.container,
55
+ autoFit: true,
56
+ appendPadding: [display_data ? 17 : 0, 0, 0, 0]
57
+ });
58
+ } else {
59
+ _this.chart = new Chart({
60
+ container: _this.container,
61
+ autoFit: true,
62
+ height: 400,
63
+ width: 700,
64
+ appendPadding: [display_data ? 17 : 0, 0, 0, 0]
65
+ });
66
+ }
67
+ _this.chart.on('interval:click', function (e) {
68
+ _this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
69
+ });
70
+ var table_id = statItem.table_id,
71
+ summary_type = statItem.summary_type,
72
+ y_axis_column_key = statItem.y_axis_column_key,
73
+ y_axis_summary_type = statItem.y_axis_summary_type,
74
+ summary_method = statItem.summary_method,
75
+ y_axis_summary_method = statItem.y_axis_summary_method,
76
+ column_groupby_column_key = statItem.column_groupby_column_key,
77
+ column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
78
+ y_axis_use_stack = statItem.y_axis_use_stack,
79
+ y_axis_auto_range = statItem.y_axis_auto_range,
80
+ y_axis_min = statItem.y_axis_min,
81
+ y_axis_max = statItem.y_axis_max,
82
+ color_option = statItem.color_option;
83
+ var chartBarColor,
84
+ columnData = DEFAULT_NUMBER_FORMAT_OBJECT;
85
+ var isGroupBar = column_groupby_column_key || column_groupby_multiple_numeric_column;
86
+ if (y_axis_summary_type === SUMMARY_TYPE.ADVANCED) {
87
+ var table = getTableById(table_id);
88
+ var summaryColumn = TableUtils.getTableColumnByKey(table, y_axis_column_key) || {};
89
+ columnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
90
+ }
91
+ if (!summary_type && y_axis_summary_type) {
92
+ summary_type = y_axis_summary_type;
93
+ }
94
+ if (!summary_method && y_axis_summary_method) {
95
+ summary_method = y_axis_summary_method;
96
+ }
97
+ if (isGroupBar) {
98
+ chartBarColor = 'group_name';
99
+ _this.chart.scale('group_name', {
100
+ type: 'cat'
101
+ });
102
+ } else if (currentTheme && currentTheme.colors) {
103
+ chartBarColor = currentTheme.colors[0];
104
+ } else {
105
+ chartBarColor = '#2a67d1';
106
+ }
107
+ _this.chart.data(data, {
108
+ 'name': {
109
+ type: 'cat',
110
+ nice: false
111
+ }
112
+ });
113
+ var width = _this.chart.coordinateBBox.width;
114
+ var chartData;
115
+ var themeColors = STAT_ITEM_THEME_COLORS.light;
116
+ if (theme === 'dark' && !isEnlarge && isPreview) {
117
+ themeColors = STAT_ITEM_THEME_COLORS.dark;
118
+ }
119
+ if (isGroupBar) {
120
+ chartData = getChartGroups(data);
121
+ } else {
122
+ chartData = data;
123
+ }
124
+ var labelCount = chartData.length;
125
+ if (Math.floor(width / labelCount) <= 20) {
126
+ var displayLabels = getChartDisplayLabels(width, 20, chartData);
127
+ labelCount = displayLabels.length;
128
+ _this.chart.scale('name', {
129
+ ticks: displayLabels
130
+ });
131
+ }
132
+
133
+ // set Coord type
134
+ _this.chart.coordinate('rect');
135
+ var valueScaleOptions = {
136
+ formatter: function formatter(value) {
137
+ return getNumberDisplayString(value, columnData);
138
+ }
139
+ };
140
+ if (y_axis_auto_range == undefined || y_axis_auto_range) {
141
+ valueScaleOptions = Object.assign({}, valueScaleOptions, {
142
+ nice: true
143
+ });
144
+ } else {
145
+ valueScaleOptions = Object.assign({}, valueScaleOptions, {
146
+ min: y_axis_min,
147
+ max: y_axis_max
148
+ });
149
+ // set the filter rule
150
+ _this.chart.filter('value', function (value) {
151
+ return value >= y_axis_min;
152
+ });
153
+ // filter the data
154
+ _this.chart.filterData(data);
155
+ }
156
+ _this.chart.scale({
157
+ // Set the type of the name column so that g2 can draw correctly
158
+ name: {
159
+ type: 'cat'
160
+ },
161
+ value: valueScaleOptions
162
+ });
163
+ if (isGroupBar) {
164
+ var labelCfg = {
165
+ style: {
166
+ fontSize: _this.getLabelFontSize(),
167
+ fill: themeColors.textColor
168
+ }
169
+ };
170
+ var displayData = display_data;
171
+ if (statItem.type == STAT_TYPE.BAR_STACK) {
172
+ var display_each_block_data = statItem.display_each_block_data;
173
+ displayData = display_each_block_data;
174
+ if (displayData) {
175
+ labelCfg.position = 'middle';
176
+ }
177
+
178
+ // get the total value of each stack
179
+ var dv = new DataSet.DataView().source(data);
180
+ dv.transform({
181
+ type: 'aggregate',
182
+ fields: ['value'],
183
+ operations: ['sum'],
184
+ as: ['value_sum'],
185
+ groupBy: ['name']
186
+ });
187
+ if (display_data) {
188
+ dv.rows.forEach(function (item) {
189
+ _this.chart.annotation().text({
190
+ content: getNumberDisplayString(item.value_sum, columnData),
191
+ position: {
192
+ name: item.name,
193
+ value: item.value_sum
194
+ },
195
+ offsetY: -10,
196
+ offsetX: -5
197
+ });
198
+ });
199
+ }
200
+ }
201
+ var groupColorCallback = currentTheme && currentTheme.colors;
202
+ // when the 'Group by' column is a 'single-select' column,
203
+ // and the user chooses to use the colors from the column.
204
+ if (color_option === TYPE_COLOR_USING.USE_COLUMN_COLORS) {
205
+ var groupColorMapping = {};
206
+ data.forEach(function (item) {
207
+ if (!groupColorMapping[item.group_name]) {
208
+ groupColorMapping[item.group_name] = item.color;
209
+ }
210
+ });
211
+ groupColorCallback = function groupColorCallback(group_name) {
212
+ return groupColorMapping[group_name];
213
+ };
214
+ }
215
+ _this.chart.scale({
216
+ group_name: {
217
+ type: 'cat'
218
+ }
219
+ });
220
+ _this.chart.interval().label(displayData ? 'value' : false, labelCfg).position('name*value').color('group_name', groupColorCallback).tooltip('name*value*group_name*raw_name', function (name, value, group_name, raw_name) {
221
+ var nameContent = !group_name && typeof group_name !== 'number' ? intl.get(EMPTY_NAME) : group_name;
222
+ var titleContent = !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
223
+ return {
224
+ title: titleContent,
225
+ value: getNumberDisplayString(value, columnData),
226
+ name: nameContent
227
+ };
228
+ }).adjust([{
229
+ type: y_axis_use_stack ? 'stack' : 'dodge'
230
+ }]).state({
231
+ active: {
232
+ style: {
233
+ stroke: null
234
+ }
235
+ }
236
+ });
237
+ } else {
238
+ var colorRules = statItem.color_option === TYPE_COLOR_USING.USE_RULES && statItem.y_axis_label_color_rules && getConvertedColorRules(statItem.y_axis_label_color_rules);
239
+ _this.chart.interval().label(display_data ? 'value' : false, {
240
+ style: {
241
+ fontSize: _this.getLabelFontSize(),
242
+ fill: themeColors.textColor
243
+ }
244
+ }).position('name*value').tooltip('name*value', function (name, value) {
245
+ return {
246
+ title: summary_type === STATISTICS_COUNT_TYPE.COUNT ? intl.get(TITLE_AMOUNT) : intl.get(STATISTICS_COUNT_SHOW[summary_method]),
247
+ value: getNumberDisplayString(value, columnData),
248
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
249
+ };
250
+ }).state({
251
+ active: {
252
+ style: {
253
+ stroke: null
254
+ }
255
+ }
256
+ }).style('value', function (value) {
257
+ var color = getLabelColor({
258
+ chart: statItem,
259
+ colorRules: colorRules,
260
+ value: value
261
+ });
262
+ if (color) {
263
+ return {
264
+ fill: color
265
+ };
266
+ }
267
+ return {
268
+ fill: chartBarColor
269
+ };
270
+ });
271
+ }
272
+ _this.chart.tooltip({
273
+ showTitle: true,
274
+ showMarkers: false,
275
+ containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
276
+ itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
277
+ domStyles: {
278
+ 'g2-tooltip': {
279
+ borderRadius: '2px',
280
+ backgroundColor: '#fff',
281
+ padding: '10px'
282
+ },
283
+ 'tooltip-item': {
284
+ marginTop: '5px'
285
+ }
286
+ }
287
+ });
288
+
289
+ // set axis label and tooltip
290
+ _this.chart.axis('name', {
291
+ line: {
292
+ style: themeColors.gridColor
293
+ },
294
+ label: {
295
+ autoRotate: true,
296
+ style: {
297
+ fill: themeColors.textColor
298
+ },
299
+ formatter: function formatter(name) {
300
+ var label = name;
301
+ if (name.length > 10) {
302
+ label = "".concat(name.slice(0, 10), "...");
303
+ }
304
+ if (name === '' || name === 'undefined') {
305
+ label = intl.get(EMPTY_NAME);
306
+ }
307
+ return label;
308
+ }
309
+ }
310
+ });
311
+ _this.chart.axis('value', {
312
+ label: {
313
+ style: {
314
+ fill: themeColors.textColor
315
+ }
316
+ },
317
+ grid: {
318
+ line: {
319
+ style: {
320
+ stroke: themeColors.gridColor
321
+ }
322
+ }
323
+ }
324
+ });
325
+ var legendPosition = 'bottom';
326
+ _this.chart.legend('group_name', {
327
+ position: legendPosition,
328
+ itemName: {
329
+ style: {
330
+ fill: themeColors.textColor
331
+ },
332
+ formatter: function formatter(name) {
333
+ return !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
334
+ }
335
+ },
336
+ pageNavigator: {
337
+ text: {
338
+ style: {
339
+ fill: themeColors.textColor
340
+ }
341
+ },
342
+ marker: {
343
+ style: {
344
+ fill: themeColors.legendPageNavigatorMarkerColor,
345
+ inactiveFill: themeColors.legendPageNavigatorMarkerColor,
346
+ inactiveOpacity: 0.45
347
+ }
348
+ }
349
+ }
350
+ });
351
+ _this.chart.interaction('active-region');
352
+ _this.chart.render();
353
+ _this.renderAxisLabel();
354
+ };
355
+ _this.renderAxisLabel = function (newStatItem) {
356
+ var _this$props2 = _this.props,
357
+ getTableById = _this$props2.getTableById,
358
+ statItem = _this$props2.statItem;
359
+ if (newStatItem && newStatItem._id !== statItem._id) {
360
+ return;
361
+ }
362
+ if (!_this.chart) return;
363
+ statItem = newStatItem || statItem;
364
+ var _this$props3 = _this.props,
365
+ isEnlarge = _this$props3.isEnlarge,
366
+ isPreview = _this$props3.isPreview,
367
+ theme = _this$props3.theme;
368
+ var _statItem = statItem,
369
+ type = _statItem.type,
370
+ table_id = _statItem.table_id,
371
+ x_axis_column_key = _statItem.x_axis_column_key,
372
+ y_axis_column_key = _statItem.y_axis_column_key,
373
+ show_y_axis_label = _statItem.show_y_axis_label,
374
+ show_x_axis_label = _statItem.show_x_axis_label,
375
+ y_axis_label_position = _statItem.y_axis_label_position,
376
+ x_axis_label_position = _statItem.x_axis_label_position,
377
+ y_axis_summary_type = _statItem.y_axis_summary_type,
378
+ title_name = _statItem.title_name;
379
+ var table = getTableById(table_id);
380
+ var autoPadding = _this.chart.autoPadding;
381
+ var textColor = '#999999';
382
+ if (theme === 'dark' && !isEnlarge && isPreview) {
383
+ textColor = '#ffffff';
384
+ }
385
+ var xAxisID = "chart-x-axis-label_".concat(statItem._id);
386
+ var chartContainer = _this.chart.getCanvas().get('container');
387
+ var xLabel = chartContainer.querySelector("#".concat(xAxisID));
388
+ if (!xLabel && show_x_axis_label) {
389
+ var div = document.createElement('div');
390
+ div.id = xAxisID;
391
+ div.className = 'statistic-chart-axis-label';
392
+ var column = TableUtils.getTableColumnByKey(table, x_axis_column_key);
393
+ div.innerHTML = "".concat(column ? column.name : '');
394
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(x_axis_label_position, "; bottom: -20px"));
395
+ chartContainer.appendChild(div);
396
+ }
397
+ if (xLabel && show_x_axis_label) {
398
+ xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(x_axis_label_position, "; bottom: -20px"));
399
+ }
400
+ if (xLabel && !show_x_axis_label) {
401
+ xLabel.parentNode.removeChild(xLabel);
402
+ }
403
+ var yAxisID = "chart-y-axis-label_".concat(statItem._id);
404
+ var yLabel = chartContainer.querySelector("#".concat(yAxisID));
405
+ var paddingLeft = autoPadding.bottom + (show_x_axis_label ? 10 : 0);
406
+ if (!yLabel && show_y_axis_label) {
407
+ var _div = document.createElement('div');
408
+ _div.id = yAxisID;
409
+ _div.className = 'statistic-chart-axis-label';
410
+ if (y_axis_summary_type === SUMMARY_TYPE.COUNT) {
411
+ _div.innerHTML = intl.get(TITLE_AMOUNT);
412
+ } else {
413
+ var _column = TableUtils.getTableColumnByKey(table, y_axis_column_key) || {};
414
+ _div.innerHTML = _column.name || '';
415
+ if (type === STAT_TYPE.BAR_STACK) {
416
+ _div.innerHTML = title_name || '';
417
+ }
418
+ }
419
+ var containerHeight = chartContainer.offsetHeight;
420
+ var textAlign = 'center';
421
+ if (y_axis_label_position === 'bottom') textAlign = 'left';
422
+ if (y_axis_label_position === 'top') textAlign = 'right';
423
+ _div.setAttribute('style', "color:".concat(textColor, "; padding-right: ").concat(autoPadding.top, "px; padding-left: ").concat(paddingLeft, "px; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0px; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
424
+ chartContainer.appendChild(_div);
425
+ }
426
+ if (yLabel && show_y_axis_label) {
427
+ var _containerHeight = chartContainer.offsetHeight;
428
+ var _textAlign = 'center';
429
+ if (y_axis_label_position === 'bottom') _textAlign = 'left';
430
+ if (y_axis_label_position === 'top') _textAlign = 'right';
431
+ yLabel.setAttribute('style', "color:".concat(textColor, "; padding-right: ").concat(autoPadding.top, "px; padding-left: ").concat(paddingLeft, "px; position: absolute; width: ").concat(_containerHeight, "px; text-align: ").concat(_textAlign, "; top: 0; left: 0px; transform: translate(-").concat(_containerHeight / 2 + 12, "px, ").concat((_containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
432
+ }
433
+ if (yLabel && !show_y_axis_label) {
434
+ yLabel.parentNode.removeChild(yLabel);
435
+ }
436
+ };
437
+ _this.destroyChart = function () {
438
+ _this.chart.destroy();
439
+ _this.chart = null;
440
+ };
441
+ _this.getLabelFontSize = function () {
442
+ var statItem = _this.props.statItem;
443
+ var label_font_size = statItem.label_font_size;
444
+ return getLabelFontSize(label_font_size);
445
+ };
446
+ _this.state = {
447
+ isCalculatingData: true,
448
+ showResultDescription: true
449
+ };
450
+ _this.calculateData = null;
451
+ return _this;
452
+ }
453
+ _createClass(BarChart, [{
454
+ key: "componentDidMount",
455
+ value: function componentDidMount() {
456
+ var _this2 = this;
457
+ var _this$props4 = this.props,
458
+ statItem = _this$props4.statItem,
459
+ chartCalculator = _this$props4.chartCalculator,
460
+ eventBus = _this$props4.eventBus;
461
+ this.unsubscribeStyleChange = eventBus.subscribe(LABEL_CONFIG_CHANGED, function (newStatItem) {
462
+ _this2.renderAxisLabel(newStatItem);
463
+ });
464
+ if (this.container) {
465
+ chartCalculator.calculate(statItem).then(function (data) {
466
+ if (!data) return;
467
+ var showResultDescription = data.length > 0 ? false : true;
468
+ _this2.setState({
469
+ isCalculatingData: false,
470
+ showResultDescription: showResultDescription
471
+ }, function () {
472
+ if (!showResultDescription) {
473
+ _this2.drawChart(data);
474
+ _this2.calculateData = data;
475
+ }
476
+ });
477
+ });
478
+ }
479
+ }
480
+ }, {
481
+ key: "shouldComponentUpdate",
482
+ value: function shouldComponentUpdate(nextProps, nextState) {
483
+ var colorThemeName = this.props.colorThemeName;
484
+ if (this.canUpdate(this.props, nextProps)) {
485
+ return true;
486
+ }
487
+ if (nextState.isCalculatingData !== this.state.isCalculatingData) {
488
+ return true;
489
+ }
490
+ if (nextProps.colorThemeName !== colorThemeName) {
491
+ return true;
492
+ }
493
+ return false;
494
+ }
495
+ }, {
496
+ key: "componentDidUpdate",
497
+ value: function componentDidUpdate(preProps, preState) {
498
+ var _this3 = this;
499
+ var _this$props5 = this.props,
500
+ statItem = _this$props5.statItem,
501
+ chartCalculator = _this$props5.chartCalculator;
502
+ var isCalculatingData = this.state.isCalculatingData;
503
+ if (isCalculatingData !== preState.isCalculatingData) return;
504
+ if (this.shouldCalculateStatItem(preProps, this.props)) {
505
+ this.setState({
506
+ isCalculatingData: true
507
+ });
508
+ if (this.container) {
509
+ chartCalculator.calculate(statItem).then(function (data) {
510
+ var showResultDescription = data.length > 0 ? false : true;
511
+ _this3.chart && _this3.destroyChart();
512
+ _this3.calculateData = data;
513
+ _this3.setState({
514
+ isCalculatingData: false,
515
+ showResultDescription: showResultDescription
516
+ }, function () {
517
+ if (!showResultDescription) {
518
+ _this3.drawChart(data);
519
+ if (_this3.props.isPreview) _this3.chart.forceFit();
520
+ }
521
+ });
522
+ });
523
+ }
524
+ } else {
525
+ if (!this.state.showResultDescription) {
526
+ this.chart && this.destroyChart();
527
+ this.drawChart(this.calculateData);
528
+ if (this.props.isPreview) {
529
+ this.chart.forceFit();
530
+ }
531
+ }
532
+ }
533
+ }
534
+ }, {
535
+ key: "componentWillUnmount",
536
+ value: function componentWillUnmount() {
537
+ this.container = null;
538
+ this.unsubscribeStyleChange();
539
+ }
540
+ }, {
541
+ key: "render",
542
+ value: function render() {
543
+ var _this4 = this;
544
+ var statItem = this.props.statItem;
545
+ var _this$state = this.state,
546
+ isCalculatingData = _this$state.isCalculatingData,
547
+ showResultDescription = _this$state.showResultDescription;
548
+ var show_y_axis_label = statItem.show_y_axis_label,
549
+ show_x_axis_label = statItem.show_x_axis_label;
550
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && /*#__PURE__*/React.createElement("div", {
551
+ className: 'statistic-chart-loading-container'
552
+ }, /*#__PURE__*/React.createElement(Loading, null)), showResultDescription && /*#__PURE__*/React.createElement("div", {
553
+ className: 'statistic-chart-text'
554
+ }, intl.get(NO_STATISTIC_RESULTS)), /*#__PURE__*/React.createElement("div", {
555
+ ref: function ref(_ref) {
556
+ return _this4.container = _ref;
557
+ },
558
+ style: {
559
+ padding: show_y_axis_label || show_x_axis_label ? 30 : 20
560
+ },
561
+ className: "statistic-chart-container"
562
+ }));
563
+ }
564
+ }]);
565
+ return BarChart;
566
+ }(BaseChart);
567
+ BarChart.propTypes = propTypes;
568
+ export default BarChart;
@@ -0,0 +1,44 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
3
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
4
+ import { Component } from 'react';
5
+ import { getNumberDisplayString } from 'dtable-store';
6
+ import { isStatItemEqual, shouldCalculateStatItem } from '../utils/common-utils';
7
+ import { SUMMARY_METHOD_MAP } from '../constants';
8
+ var BaseChart = /*#__PURE__*/function (_Component) {
9
+ _inherits(BaseChart, _Component);
10
+ var _super = _createSuper(BaseChart);
11
+ function BaseChart() {
12
+ var _this;
13
+ _classCallCheck(this, BaseChart);
14
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15
+ args[_key] = arguments[_key];
16
+ }
17
+ _this = _super.call.apply(_super, [this].concat(args));
18
+ _this.needRefresh = function (preProps, nextProps) {
19
+ var refresh = nextProps.refresh;
20
+ return refresh && refresh !== preProps.refresh;
21
+ };
22
+ _this.canUpdate = function (preProps, nextProps) {
23
+ var statItem = preProps.statItem,
24
+ theme = preProps.theme;
25
+ var nextStatItem = nextProps.statItem,
26
+ nextTheme = nextProps.theme;
27
+ return !isStatItemEqual(statItem, nextStatItem) || _this.needRefresh(preProps, nextProps) || nextTheme !== theme;
28
+ };
29
+ _this.shouldCalculateStatItem = function (preProps, nextProps) {
30
+ var statItem = preProps.statItem;
31
+ var nextStatItem = nextProps.statItem;
32
+ return shouldCalculateStatItem(statItem, nextStatItem) || _this.needRefresh(preProps, nextProps);
33
+ };
34
+ _this.getNumberDisplayString = function (value, columnData, summaryType) {
35
+ if (summaryType === SUMMARY_METHOD_MAP.Distinct_values) {
36
+ return value;
37
+ }
38
+ return getNumberDisplayString(value, columnData);
39
+ };
40
+ return _this;
41
+ }
42
+ return BaseChart;
43
+ }(Component);
44
+ export default BaseChart;