dtable-statistic 4.4.24-alpha.9 → 5.0.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.
Files changed (198) hide show
  1. package/es/assets/css/color-picker.css +53 -0
  2. package/es/assets/css/color-rules-popover.css +144 -0
  3. package/es/assets/css/dashboard.css +0 -1
  4. package/es/assets/css/dialog.css +0 -30
  5. package/es/assets/css/slider.css +77 -0
  6. package/es/assets/css/statistic-chart.module.css +11 -0
  7. package/es/assets/css/statistic-custom-title.module.css +3 -0
  8. package/es/assets/css/statistic-custom.module.css +4 -0
  9. package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
  10. package/es/assets/css/statistic-time-picker.module.css +21 -0
  11. package/es/calculator/base-calculator.js +80 -0
  12. package/es/calculator/basic-chart-calculator.js +349 -0
  13. package/es/calculator/combination-calculator.js +246 -0
  14. package/es/calculator/compare-bar-calculator.js +197 -0
  15. package/es/calculator/completeness-calculator.js +215 -0
  16. package/es/calculator/copy-value.js +53 -0
  17. package/es/calculator/dashboard-calculator.js +70 -0
  18. package/es/calculator/heat-map-calculator.js +148 -0
  19. package/es/calculator/horizontal-bar-calculator.js +67 -0
  20. package/es/calculator/index.js +81 -0
  21. package/es/calculator/map-calculator.js +103 -0
  22. package/es/calculator/mirror-calculator.js +146 -0
  23. package/es/calculator/number-card-calculator.js +60 -0
  24. package/es/calculator/pivot-table-calculator.js +821 -0
  25. package/es/calculator/scatter-calculator.js +75 -0
  26. package/es/calculator/thread-manager.js +57 -0
  27. package/es/calculator/trend-calculator.js +113 -0
  28. package/es/calculator/workers/basic-chart-calculator-worker.js +495 -0
  29. package/es/calculator/workers/calculator.worker.js +44 -0
  30. package/es/calculator/workers/card-calculator-worker.js +40 -0
  31. package/es/calculator/workers/combination-calculator-worker.js +276 -0
  32. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +150 -0
  33. package/es/calculator/workers/completeness-calculator-worker.js +208 -0
  34. package/es/calculator/workers/dashboard-calculator-worker.js +68 -0
  35. package/es/calculator/workers/mirror-calculator-worker.js +152 -0
  36. package/es/calculator/workers/pivot-table-calculator-worker.js +718 -0
  37. package/es/calculator/workers/scatter-calculator-worker.js +80 -0
  38. package/es/calculator/workers/trend-calculator-worker.js +108 -0
  39. package/es/calculator/world-map-calculator.js +124 -0
  40. package/es/components/dialog/chart-addition-edit-dialog.js +90 -0
  41. package/es/components/dialog/chart-addition-widgets/chart-selector.js +259 -0
  42. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +83 -0
  43. package/es/components/dialog/enlarged-chart-dialog.js +13 -8
  44. package/es/components/dialog/statistic-record-dialog/index.js +34 -25
  45. package/es/components/dialog/statistic-types-dialog/index.css +14 -0
  46. package/es/components/dialog/statistic-types-dialog/index.js +62 -0
  47. package/es/components/dropdown-menu/statistic-dropdown-menu.js +2 -2
  48. package/es/components/popover/color-rules/color-rule.js +183 -0
  49. package/es/components/popover/color-rules/index.js +87 -0
  50. package/es/components/popover/color-rules/rule-filters/filter.js +221 -0
  51. package/es/components/popover/color-rules/rule-filters/index.css +210 -0
  52. package/es/components/popover/color-rules/rule-filters/index.js +97 -0
  53. package/es/components/popover/color-rules/rule-filters/number-input.js +78 -0
  54. package/es/components/popover/color-rules-popover.js +218 -0
  55. package/es/components/popover/color-selector-popover.js +83 -0
  56. package/es/constants/index.js +2 -1
  57. package/es/custom-g2.js +644 -0
  58. package/es/dashboard.js +31 -9
  59. package/es/desktop-dashboard.js +32 -51
  60. package/es/mobile-dashboard.js +16 -8
  61. package/es/model/bar-group.js +58 -0
  62. package/es/model/bar.js +47 -0
  63. package/es/model/base-model.js +18 -0
  64. package/es/model/basic-number-card.js +25 -0
  65. package/es/model/combination.js +48 -0
  66. package/es/model/compare-bar.js +56 -0
  67. package/es/model/completeness-group.js +31 -0
  68. package/es/model/completeness.js +25 -0
  69. package/es/model/custom-bar.js +25 -0
  70. package/es/model/dashboard.js +20 -0
  71. package/es/model/generic-model.js +222 -0
  72. package/es/model/heat-map.js +33 -0
  73. package/es/model/horizontal-bar-group.js +55 -0
  74. package/es/model/horizontal-bar.js +47 -0
  75. package/es/model/index.js +187 -0
  76. package/es/model/map.js +38 -0
  77. package/es/model/mirror.js +33 -0
  78. package/es/model/pie.js +38 -0
  79. package/es/model/ring.js +40 -0
  80. package/es/model/scatter.js +22 -0
  81. package/es/model/table.js +32 -0
  82. package/es/model/trend.js +32 -0
  83. package/es/model/world-map.js +34 -0
  84. package/es/service/chart-service.js +15 -8
  85. package/es/service/dashboard-service.js +29 -25
  86. package/es/stat-editor/chart-name-editor.js +68 -0
  87. package/es/stat-editor/index.js +75 -0
  88. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +153 -0
  89. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +422 -0
  90. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +203 -0
  91. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +23 -0
  92. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +104 -0
  93. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +334 -0
  94. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +119 -0
  95. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +132 -0
  96. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +240 -0
  97. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
  98. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +138 -0
  99. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +331 -0
  100. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +143 -0
  101. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +109 -0
  102. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +153 -0
  103. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +144 -0
  104. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +214 -0
  105. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +121 -0
  106. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +172 -0
  107. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +366 -0
  108. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +142 -0
  109. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +150 -0
  110. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +473 -0
  111. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +182 -0
  112. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +564 -0
  113. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +112 -0
  114. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +87 -0
  115. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +187 -0
  116. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +300 -0
  117. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +113 -0
  118. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +289 -0
  119. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +58 -0
  120. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +359 -0
  121. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +48 -0
  122. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +121 -0
  123. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +143 -0
  124. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +269 -0
  125. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +104 -0
  126. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +366 -0
  127. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +55 -0
  128. package/es/stat-editor/stat-settings/color-setting/color-picker.js +130 -0
  129. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +374 -0
  130. package/es/stat-editor/stat-settings/map/map-level.js +72 -0
  131. package/es/stat-editor/stat-settings/map/map-province-city.js +151 -0
  132. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +108 -0
  133. package/es/stat-editor/stat-settings/public-setting/base-settings.js +154 -0
  134. package/es/stat-editor/stat-settings/public-setting/calender.js +125 -0
  135. package/es/stat-editor/stat-settings/public-setting/column-settings.js +24 -0
  136. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +62 -0
  137. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +61 -0
  138. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +35 -0
  139. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +60 -0
  140. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +123 -0
  141. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +33 -0
  142. package/es/stat-editor/stat-settings/public-setting/type-settings/index.css +29 -0
  143. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +82 -0
  144. package/es/stat-list/chart-preview.js +20 -19
  145. package/es/stat-list/index.js +21 -15
  146. package/es/stat-view/area-chart.js +551 -0
  147. package/es/stat-view/bar-chart.js +582 -0
  148. package/es/stat-view/base-chart.js +132 -0
  149. package/es/stat-view/basic-number-card.js +201 -0
  150. package/es/stat-view/combination-chart.js +546 -0
  151. package/es/stat-view/compare-chart.js +483 -0
  152. package/es/stat-view/completeness-chart.js +390 -0
  153. package/es/stat-view/custom-bar.js +418 -0
  154. package/es/stat-view/dashboard-chart.js +266 -0
  155. package/es/stat-view/heat-map.js +463 -0
  156. package/es/stat-view/horizontal-bar-chart.js +562 -0
  157. package/es/stat-view/index.js +156 -47
  158. package/es/stat-view/line-chart.js +518 -0
  159. package/es/stat-view/map.js +448 -0
  160. package/es/stat-view/mirror.js +275 -0
  161. package/es/stat-view/pie-chart.js +290 -0
  162. package/es/stat-view/pivot-table/index.js +196 -0
  163. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +156 -0
  164. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +176 -0
  165. package/es/stat-view/pivot-table/pivot-table-display-name.js +215 -0
  166. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
  167. package/es/stat-view/pivot-table/two-dimension-table.js +384 -0
  168. package/es/stat-view/ring-chart.js +392 -0
  169. package/es/stat-view/scatter-chart.js +306 -0
  170. package/es/stat-view/treemap-chart.js +253 -0
  171. package/es/stat-view/trend-chart.js +249 -0
  172. package/es/stat-view/world-map.js +431 -0
  173. package/es/tabs/tab.js +2 -2
  174. package/es/utils/basic-chart-utils.js +29 -0
  175. package/es/utils/cell-format.js +115 -0
  176. package/es/utils/collaborator.js +50 -0
  177. package/es/utils/color-utils.js +134 -0
  178. package/es/utils/column-utils.js +110 -0
  179. package/es/utils/column.js +20 -0
  180. package/es/utils/common-utils.js +352 -2
  181. package/es/utils/date-format.js +71 -0
  182. package/es/utils/export-table-utils.js +69 -0
  183. package/es/utils/index.js +89 -12
  184. package/es/utils/map.js +114 -0
  185. package/es/utils/model.js +19 -0
  186. package/es/utils/row-utils.js +134 -0
  187. package/es/utils/search.js +73 -0
  188. package/es/utils/sql-utils.js +359 -0
  189. package/es/utils/stat-utils.js +351 -0
  190. package/es/utils/trend-utils.js +135 -0
  191. package/package.json +8 -6
  192. package/es/components/dialog/chart-edit-dialog.js +0 -93
  193. package/es/components/dtable-popover.js +0 -97
  194. package/es/components/dtable-search-input.js +0 -135
  195. package/es/components/index.js +0 -41
  196. package/es/components/loading.js +0 -15
  197. package/es/components/modal-portal.js +0 -26
  198. package/es/model/conver-statItem.js +0 -124
@@ -0,0 +1,392 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _reactIntlUniversal = _interopRequireDefault(require("react-intl-universal"));
11
+ var _dtableUtils = require("dtable-utils");
12
+ var _baseChart = _interopRequireDefault(require("./base-chart"));
13
+ var _customG = require("../custom-g2");
14
+ var _commonUtils = require("../utils/common-utils");
15
+ var _constants = require("../constants");
16
+ var _statisticChartModule = _interopRequireDefault(require("../assets/css/statistic-chart.module.css"));
17
+ const propTypes = {
18
+ isPreview: _propTypes.default.bool,
19
+ colorThemeName: _propTypes.default.string,
20
+ statItem: _propTypes.default.object,
21
+ chartCalculator: _propTypes.default.object,
22
+ toggleStatisticRecordsDialog: _propTypes.default.func
23
+ };
24
+ class RingChart extends _baseChart.default {
25
+ constructor(props) {
26
+ super(props);
27
+ this.drawChart = data => {
28
+ const {
29
+ isPreview,
30
+ statItem
31
+ } = this.props;
32
+ if (isPreview) {
33
+ this.chart = new _customG.Chart({
34
+ container: this.container,
35
+ autoFit: true,
36
+ padding: [20, 0]
37
+ });
38
+ } else {
39
+ this.chart = new _customG.Chart({
40
+ container: this.container,
41
+ autoFit: true,
42
+ height: 400,
43
+ width: 700
44
+ });
45
+ }
46
+ this.chart.on('element:click', e => {
47
+ const clickData = e.data.data;
48
+ if (clickData.name !== 'Others') {
49
+ this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
50
+ }
51
+ });
52
+ this.drawRingChart(data, !isPreview);
53
+ this.chart.render();
54
+ };
55
+ this.drawRingChart = (data, isCreating) => {
56
+ this.sum = data.total;
57
+ if (data.length === 0) return;
58
+ let {
59
+ getTableById,
60
+ statItem,
61
+ colorThemeName
62
+ } = this.props;
63
+ let summaryColumn = null;
64
+ let summaryColumnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
65
+ const {
66
+ summary_type,
67
+ summary_method,
68
+ summary_column_key,
69
+ table_id,
70
+ show_legend,
71
+ show_percent,
72
+ display_label,
73
+ label_position,
74
+ display_annotation
75
+ } = statItem;
76
+ const table = getTableById(table_id);
77
+ if (summary_type !== _constants.SUMMARY_TYPE.COUNT) {
78
+ summaryColumn = summary_column_key && (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key);
79
+ summaryColumnData = summaryColumn && summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
80
+ }
81
+ this.chart.coordinate('theta', {
82
+ radius: isCreating ? 0.75 : 0.95,
83
+ innerRadius: isCreating ? 0.6 : 0.7
84
+ });
85
+ const currentTheme = (0, _commonUtils.getCurrentTheme)(colorThemeName);
86
+ const themeColors = this.getThemeColors();
87
+ const newData = (0, _commonUtils.formatPieChartData)(data, statItem, table, currentTheme);
88
+ this.chart.data(newData, {
89
+ 'name': {
90
+ type: 'cat',
91
+ nice: false
92
+ }
93
+ });
94
+ const colorSet = newData.colorSet;
95
+ this.sum = newData.total;
96
+ if (show_legend) {
97
+ this.chart.legend('name', {
98
+ position: 'right',
99
+ custom: true,
100
+ pageNavigator: {
101
+ text: {
102
+ style: {
103
+ fill: themeColors.textColor
104
+ }
105
+ },
106
+ marker: {
107
+ style: {
108
+ fill: themeColors.legendPageNavigatorMarkerColor,
109
+ inactiveFill: themeColors.legendPageNavigatorMarkerColor,
110
+ inactiveOpacity: 0.45
111
+ }
112
+ }
113
+ },
114
+ itemName: {
115
+ style: {
116
+ fill: themeColors.textColor
117
+ }
118
+ },
119
+ items: newData.map((obj, index) => {
120
+ const sIndex = String(index);
121
+ const colorIndex = sIndex.charAt(sIndex.length - 1);
122
+ let name = obj.name;
123
+ if (!obj.name && typeof obj.name !== 'number') {
124
+ name = _reactIntlUniversal.default.get(_constants.EMPTY_NAME);
125
+ } else if (obj.name === 'Others') {
126
+ name = _reactIntlUniversal.default.get('Others');
127
+ }
128
+ return {
129
+ name,
130
+ value: obj.value,
131
+ marker: {
132
+ symbol: 'circle',
133
+ style: {
134
+ r: 5,
135
+ fill: colorSet[colorIndex]
136
+ }
137
+ }
138
+ };
139
+ })
140
+ });
141
+ } else {
142
+ this.chart.legend(false);
143
+ }
144
+
145
+ // Do not automatically adjust the maximum and minimum values in ring chart
146
+ this.chart.scale({
147
+ value: {
148
+ nice: false
149
+ }
150
+ });
151
+ this.chart.interval().adjust('stack').position('value').color('name', colorSet).label('formatted_value*percent', (value, percent) => {
152
+ return {
153
+ content: this.getLabel(value, percent)
154
+ };
155
+ }, {
156
+ offset: !label_position || label_position === _constants.LABEL_POSITIONS[0] ? isCreating ? -10 : -2 : undefined,
157
+ style: {
158
+ fill: themeColors.labelColor,
159
+ fontSize: this.getLabelFontSize(),
160
+ shadowBlur: 2,
161
+ shadowColor: 'rgba(0, 0, 0, .45)'
162
+ }
163
+ }).tooltip('name*formatted_value*percent', (name, value, percent) => {
164
+ let title = name;
165
+ if (!name || name === 'undefined') {
166
+ title = _reactIntlUniversal.default.get(_constants.EMPTY_NAME);
167
+ }
168
+ return show_percent || display_label ? {
169
+ name: title,
170
+ value: this.getLabel(value, percent)
171
+ } : {
172
+ name: title,
173
+ value
174
+ };
175
+ }).state({
176
+ active: {
177
+ style: {
178
+ fillOpacity: 0.7,
179
+ border: 'none',
180
+ stroke: 0
181
+ }
182
+ }
183
+ });
184
+ this.chart.tooltip({
185
+ showTitle: false,
186
+ showMarkers: false,
187
+ itemTpl: '<div class="g2-tooltip-list-item"><span style="background-color:{color};" class="g2-tooltip-marker"></span>{name}: {value}</div>'
188
+ });
189
+ this.chart.interaction('element-active');
190
+ if (display_annotation === undefined || display_annotation === null || display_annotation) {
191
+ this.setAnnotation({
192
+ name: _reactIntlUniversal.default.get(_constants.TITLE_TOTAL),
193
+ value: summaryColumn ? this.getNumberDisplayString(this.sum, summaryColumnData, summary_method) : this.sum
194
+ }, themeColors.labelColor);
195
+ this.chart.on('interval:mouseenter', evt => this.onEnterRingChart(evt, themeColors.labelColor, summaryColumn, summaryColumnData));
196
+ this.chart.on('interval:mouseleave', evt => this.onLeaveRingChart(evt, themeColors.labelColor, summaryColumn, summaryColumnData));
197
+ }
198
+ };
199
+ this.getLabel = (value, percent) => {
200
+ const {
201
+ show_percent,
202
+ display_label,
203
+ label_format
204
+ } = this.props.statItem;
205
+ let content;
206
+ if (show_percent) {
207
+ content = percent;
208
+ return content;
209
+ } else {
210
+ if (!display_label) {
211
+ content = '';
212
+ return content;
213
+ }
214
+ }
215
+ switch (label_format) {
216
+ case _constants.LABEL_FORMATS[0]:
217
+ content = percent;
218
+ break;
219
+ case _constants.LABEL_FORMATS[1]:
220
+ content = value;
221
+ break;
222
+ case _constants.LABEL_FORMATS[2]:
223
+ content = "".concat(value, " (").concat(percent, ")");
224
+ break;
225
+ default:
226
+ content = percent;
227
+ }
228
+ return content;
229
+ };
230
+ this.getAnnotationFontSize = () => {
231
+ const {
232
+ statItem
233
+ } = this.props;
234
+ const {
235
+ annotation_font_size
236
+ } = statItem;
237
+ const mainFontSize = annotation_font_size || _constants.DEFAULT_ANNOTATION_SIZE;
238
+ const subFontSize = Math.max(mainFontSize - 12, 12);
239
+ return {
240
+ mainFontSize,
241
+ subFontSize
242
+ };
243
+ };
244
+ this.setAnnotation = (content, fontColor, summaryColumn, summaryColumnData) => {
245
+ const {
246
+ summary_method
247
+ } = this.props.statItem;
248
+ let name = content.name;
249
+ if (!name || name === 'undefined') {
250
+ name = _reactIntlUniversal.default.get(_constants.EMPTY_NAME);
251
+ } else if (name === 'Others') {
252
+ name = _reactIntlUniversal.default.get('Others');
253
+ }
254
+ const {
255
+ mainFontSize,
256
+ subFontSize
257
+ } = this.getAnnotationFontSize();
258
+ this.chart.annotation().text({
259
+ content: name,
260
+ position: ['50%', '50%'],
261
+ style: {
262
+ fontSize: subFontSize,
263
+ fill: fontColor,
264
+ fontWeight: '300',
265
+ textAlign: 'center'
266
+ },
267
+ offsetY: -20
268
+ }).text({
269
+ position: ['50%', '50%'],
270
+ content: summaryColumn ? this.getNumberDisplayString(content.value, summaryColumnData, summary_method) : content.value,
271
+ style: {
272
+ fontSize: mainFontSize,
273
+ fill: fontColor,
274
+ textAlign: 'center'
275
+ },
276
+ offsetY: 20
277
+ });
278
+ };
279
+ this.onEnterRingChart = (ev, color, summaryColumn, summaryColumnData) => {
280
+ const item = ev.data.data;
281
+ this.chart.annotation().clear(true);
282
+ this.setAnnotation(item, color, summaryColumn, summaryColumnData);
283
+ this.chart.render(true);
284
+ };
285
+ this.onLeaveRingChart = (ev, color, summaryColumn, summaryColumnData) => {
286
+ this.chart.annotation().clear(true);
287
+ this.setAnnotation({
288
+ name: _reactIntlUniversal.default.get(_constants.TITLE_TOTAL),
289
+ value: this.sum
290
+ }, color, summaryColumn, summaryColumnData);
291
+ this.chart.render(true);
292
+ };
293
+ this.destroyChart = () => {
294
+ this.chart.destroy();
295
+ this.chart = null;
296
+ };
297
+ this.state = {
298
+ isCalculatingData: true,
299
+ showResultDescription: true
300
+ };
301
+ this.calculateData = null;
302
+ }
303
+ componentDidMount() {
304
+ const {
305
+ statItem,
306
+ chartCalculator
307
+ } = this.props;
308
+ if (this.container) {
309
+ chartCalculator.calculate(statItem).then(data => {
310
+ const showResultDescription = data.length > 0 ? false : true;
311
+ this.setState({
312
+ isCalculatingData: false,
313
+ showResultDescription
314
+ }, () => {
315
+ if (!showResultDescription) {
316
+ this.drawChart(data);
317
+ this.calculateData = data;
318
+ }
319
+ });
320
+ });
321
+ }
322
+ }
323
+ shouldComponentUpdate(nextProps, nextState) {
324
+ const {
325
+ colorThemeName
326
+ } = this.props;
327
+ if (this.canUpdate(this.props, nextProps)) {
328
+ return true;
329
+ }
330
+ if (nextState.isCalculatingData !== this.state.isCalculatingData) {
331
+ return true;
332
+ }
333
+ if (nextProps.colorThemeName !== colorThemeName) {
334
+ return true;
335
+ }
336
+ return false;
337
+ }
338
+ componentDidUpdate(preProps, preState) {
339
+ const {
340
+ statItem,
341
+ chartCalculator
342
+ } = this.props;
343
+ const {
344
+ isCalculatingData
345
+ } = this.state;
346
+ if (isCalculatingData !== preState.isCalculatingData) return;
347
+ if (this.shouldCalculateStatItem(preProps, this.props)) {
348
+ this.setState({
349
+ isCalculatingData: true
350
+ });
351
+ if (this.container) {
352
+ chartCalculator.calculate(statItem).then(data => {
353
+ const showResultDescription = data.length > 0 ? false : true;
354
+ this.chart && this.destroyChart();
355
+ this.calculateData = data;
356
+ this.setState({
357
+ isCalculatingData: false,
358
+ showResultDescription
359
+ }, () => {
360
+ if (!showResultDescription) {
361
+ this.drawChart(data);
362
+ if (this.props.isPreview) this.chart.forceFit();
363
+ }
364
+ });
365
+ });
366
+ }
367
+ } else {
368
+ if (!this.state.showResultDescription) {
369
+ this.chart && this.destroyChart();
370
+ this.drawChart(this.calculateData);
371
+ if (this.props.isPreview) {
372
+ this.chart.forceFit();
373
+ }
374
+ }
375
+ }
376
+ }
377
+ componentWillUnmount() {
378
+ this.container = null;
379
+ }
380
+ render() {
381
+ const {
382
+ isCalculatingData,
383
+ showResultDescription
384
+ } = this.state;
385
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isCalculatingData && this.renderLoading(), showResultDescription && this.renderEmpty(), /*#__PURE__*/_react.default.createElement("div", {
386
+ ref: ref => this.container = ref,
387
+ className: "".concat(_statisticChartModule.default['statistic-pie-chart-container'], " statistic-chart-container")
388
+ }));
389
+ }
390
+ }
391
+ RingChart.propTypes = propTypes;
392
+ var _default = exports.default = RingChart;
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _reactIntlUniversal = _interopRequireDefault(require("react-intl-universal"));
11
+ var _dtableUtils = require("dtable-utils");
12
+ var _baseChart = _interopRequireDefault(require("./base-chart"));
13
+ var _customG = require("../custom-g2");
14
+ var _commonUtils = require("../utils/common-utils");
15
+ var _constants = require("../constants");
16
+ var _statisticChartModule = _interopRequireDefault(require("../assets/css/statistic-chart.module.css"));
17
+ const propTypes = {
18
+ isPreview: _propTypes.default.bool,
19
+ colorThemeName: _propTypes.default.string,
20
+ statItem: _propTypes.default.object,
21
+ chartCalculator: _propTypes.default.object,
22
+ eventBus: _propTypes.default.object,
23
+ getTableById: _propTypes.default.func,
24
+ toggleStatisticRecordsDialog: _propTypes.default.func
25
+ };
26
+ class ScatterChart extends _baseChart.default {
27
+ constructor(props) {
28
+ super(props);
29
+ this.drawChart = data => {
30
+ const {
31
+ getTableById,
32
+ isPreview,
33
+ statItem,
34
+ colorThemeName
35
+ } = this.props;
36
+ const currentTheme = (0, _commonUtils.getCurrentTheme)(colorThemeName);
37
+ const {
38
+ table_id,
39
+ x_axis_column,
40
+ y_axis_column
41
+ } = statItem;
42
+ const selectedTable = getTableById(table_id);
43
+ const selectedXAxisColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column);
44
+ const selectedYAxisColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_column);
45
+ if (isPreview) {
46
+ this.chart = new _customG.Chart({
47
+ container: this.container,
48
+ autoFit: true
49
+ });
50
+ } else {
51
+ this.chart = new _customG.Chart({
52
+ container: this.container,
53
+ height: 400,
54
+ width: 700
55
+ });
56
+ }
57
+ this.chart.on('element:click', e => {
58
+ this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
59
+ });
60
+ const themeColors = this.getThemeColors();
61
+ this.chart.axis('x_axis', {
62
+ label: {
63
+ style: {
64
+ fill: themeColors.textColor
65
+ }
66
+ },
67
+ line: {
68
+ style: themeColors.gridColor
69
+ }
70
+ });
71
+ this.chart.axis('y_axis', {
72
+ grid: {
73
+ line: {
74
+ style: {
75
+ stroke: themeColors.gridColor
76
+ }
77
+ }
78
+ },
79
+ label: {
80
+ style: {
81
+ fill: themeColors.textColor
82
+ }
83
+ }
84
+ });
85
+ const chart = this.chart;
86
+ chart.data(data);
87
+ chart.scale({
88
+ x_axis: {
89
+ nice: true
90
+ },
91
+ y_axis: {
92
+ nice: true
93
+ }
94
+ });
95
+ chart.tooltip({
96
+ showTitle: false,
97
+ showCrosshairs: true,
98
+ crosshairs: {
99
+ type: 'xy'
100
+ },
101
+ itemTpl: '<li class="g2-tooltip-list-item" data-index={index} style="margin-bottom:4px;">' + '<span style="background-color:{color};" class="g2-tooltip-marker"></span>' + '{name}<br/>' + '{valueX}<br/>' + '{valueY}' + '</li>'
102
+ });
103
+ chart.point().position('x_axis*y_axis').color('group_by', currentTheme && currentTheme.colors).shape('circle').tooltip('group_by*x_axis*y_axis', (group_by, x_axis, y_axis) => {
104
+ return {
105
+ name: group_by || group_by === 0 ? group_by : _reactIntlUniversal.default.get(_constants.EMPTY_NAME),
106
+ valueX: "".concat(selectedXAxisColumn.name, ": ").concat(x_axis),
107
+ valueY: "".concat(selectedYAxisColumn.name, ": ").concat(y_axis)
108
+ };
109
+ }).style({
110
+ fillOpacity: 0.85
111
+ });
112
+ chart.legend('group_by', {
113
+ position: 'bottom',
114
+ itemName: {
115
+ formatter: name => {
116
+ return name || name === 0 ? name : _reactIntlUniversal.default.get(_constants.EMPTY_NAME);
117
+ },
118
+ style: {
119
+ fill: themeColors.textColor
120
+ }
121
+ },
122
+ pageNavigator: {
123
+ text: {
124
+ style: {
125
+ fill: themeColors.textColor
126
+ }
127
+ },
128
+ marker: {
129
+ style: {
130
+ fill: themeColors.legendPageNavigatorMarkerColor,
131
+ inactiveFill: themeColors.legendPageNavigatorMarkerColor,
132
+ inactiveOpacity: 0.45
133
+ }
134
+ }
135
+ }
136
+ });
137
+ chart.interaction('legend-highlight');
138
+ chart.render();
139
+ this.renderAxisLabel();
140
+ };
141
+ this.renderAxisLabel = newStatItem => {
142
+ let {
143
+ getTableById,
144
+ statItem
145
+ } = this.props;
146
+ if (newStatItem && newStatItem._id !== statItem._id) {
147
+ return;
148
+ }
149
+ if (!this.chart) return;
150
+ statItem = newStatItem || statItem;
151
+ const {
152
+ table_id,
153
+ x_axis_column,
154
+ y_axis_column,
155
+ show_y_axis_label,
156
+ show_x_axis_label,
157
+ y_axis_label_position,
158
+ x_axis_label_position
159
+ } = statItem;
160
+ const table = getTableById(table_id);
161
+ const autoPadding = this.chart.autoPadding;
162
+ const textColor = this.getAxisLabelColor();
163
+ const xAxisID = "chart-x-axis-label_".concat(statItem._id);
164
+ const chartContainer = this.chart.getCanvas().get('container');
165
+ const xLabel = chartContainer.querySelector("#".concat(xAxisID));
166
+ if (!xLabel && show_x_axis_label) {
167
+ const div = document.createElement('div');
168
+ div.id = xAxisID;
169
+ div.className = 'statistic-chart-axis-label';
170
+ const column = (0, _dtableUtils.getTableColumnByKey)(table, x_axis_column);
171
+ div.innerHTML = "".concat(column ? column.name : '');
172
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(x_axis_label_position, "; bottom: -20px"));
173
+ chartContainer.appendChild(div);
174
+ }
175
+ if (xLabel && show_x_axis_label) {
176
+ xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(x_axis_label_position, "; bottom: -20px"));
177
+ }
178
+ if (xLabel && !show_x_axis_label) {
179
+ xLabel.parentNode.removeChild(xLabel);
180
+ }
181
+ const yAxisID = "chart-y-axis-label_".concat(statItem._id);
182
+ const yLabel = chartContainer.querySelector("#".concat(yAxisID));
183
+ let paddingLeft = autoPadding.bottom + (show_x_axis_label ? 10 : 0);
184
+ if (!yLabel && show_y_axis_label) {
185
+ const div = document.createElement('div');
186
+ div.id = yAxisID;
187
+ div.className = 'statistic-chart-axis-label';
188
+ const column = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_column) || {};
189
+ div.innerHTML = column.name || '';
190
+ const containerHeight = chartContainer.offsetHeight;
191
+ let textAlign = 'center';
192
+ if (y_axis_label_position === 'bottom') textAlign = 'left';
193
+ if (y_axis_label_position === 'top') textAlign = 'right';
194
+ 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)"));
195
+ chartContainer.appendChild(div);
196
+ }
197
+ if (yLabel && show_y_axis_label) {
198
+ const containerHeight = chartContainer.offsetHeight;
199
+ let textAlign = 'center';
200
+ if (y_axis_label_position === 'bottom') textAlign = 'left';
201
+ if (y_axis_label_position === 'top') textAlign = 'right';
202
+ 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)"));
203
+ }
204
+ if (yLabel && !show_y_axis_label) {
205
+ yLabel.parentNode.removeChild(yLabel);
206
+ }
207
+ };
208
+ this.state = {
209
+ isCalculatingData: true
210
+ };
211
+ this.calculateData = null;
212
+ }
213
+ async componentDidMount() {
214
+ const {
215
+ statItem,
216
+ chartCalculator,
217
+ eventBus
218
+ } = this.props;
219
+ if (this.container) {
220
+ const data = await chartCalculator.calculate(statItem);
221
+ this.setState({
222
+ isCalculatingData: false
223
+ });
224
+ this.drawChart(data);
225
+ this.calculateData = data;
226
+ }
227
+ this.unsubscribeStyleChange = eventBus.subscribe(_constants.LABEL_CONFIG_CHANGED, newStatItem => {
228
+ this.renderAxisLabel(newStatItem);
229
+ });
230
+ }
231
+ shouldComponentUpdate(nextProps, nextState) {
232
+ const {
233
+ colorThemeName
234
+ } = this.props;
235
+ if (this.canUpdate(this.props, nextProps)) {
236
+ return true;
237
+ }
238
+ if (nextState.isCalculatingData !== this.state.isCalculatingData) {
239
+ return true;
240
+ }
241
+ if (nextProps.colorThemeName !== colorThemeName) {
242
+ return true;
243
+ }
244
+ return false;
245
+ }
246
+ async componentDidUpdate(preProps, preState) {
247
+ const {
248
+ statItem,
249
+ chartCalculator
250
+ } = this.props;
251
+ const {
252
+ isCalculatingData
253
+ } = this.state;
254
+ if (isCalculatingData !== preState.isCalculatingData) return;
255
+ if (this.shouldCalculateStatItem(preProps, this.props)) {
256
+ if (this.container) {
257
+ this.setState({
258
+ isCalculatingData: true
259
+ });
260
+ const data = await chartCalculator.calculate(statItem);
261
+ this.calculateData = data;
262
+ this.setState({
263
+ isCalculatingData: false
264
+ });
265
+ this.chart && this.chart.destroy();
266
+ this.drawChart(data);
267
+ if (this.props.isPreview) {
268
+ this.chart.forceFit();
269
+ }
270
+ }
271
+ } else {
272
+ this.chart && this.chart.destroy();
273
+ this.drawChart(this.calculateData);
274
+ if (this.props.isPreview) {
275
+ this.chart.forceFit();
276
+ }
277
+ }
278
+ }
279
+ componentWillUnmount() {
280
+ this.container = null;
281
+ this.unsubscribeStyleChange && this.unsubscribeStyleChange();
282
+ }
283
+ render() {
284
+ const {
285
+ isCalculatingData
286
+ } = this.state;
287
+ const {
288
+ show_x_axis_label,
289
+ show_y_axis_label
290
+ } = this.props.statItem;
291
+ const style = {};
292
+ if (show_x_axis_label) {
293
+ style.paddingBottom = 38;
294
+ }
295
+ if (show_y_axis_label) {
296
+ style.paddingLeft = 38;
297
+ }
298
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isCalculatingData && this.renderLoading(), /*#__PURE__*/_react.default.createElement("div", {
299
+ ref: ref => this.container = ref,
300
+ className: "".concat(_statisticChartModule.default['statistic-scatter-chart-container'], " statistic-chart-container"),
301
+ style: style
302
+ }));
303
+ }
304
+ }
305
+ ScatterChart.propTypes = propTypes;
306
+ var _default = exports.default = ScatterChart;