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,569 @@
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 { DEFAULT_NUMBER_FORMAT_OBJECT, EMPTY_NAME, LABEL_CONFIG_CHANGED, NO_STATISTIC_RESULTS, STATISTICS_COUNT_SHOW, STAT_ITEM_THEME_COLORS, STAT_TYPE, SUMMARY_TYPE, TITLE_AMOUNT, TYPE_COLOR_USING, USEABLE_COLOR_TYPES } 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 HorizontalBarChart = /*#__PURE__*/function (_BaseChart) {
30
+ _inherits(HorizontalBarChart, _BaseChart);
31
+ var _super = _createSuper(HorizontalBarChart);
32
+ function HorizontalBarChart(props) {
33
+ var _this;
34
+ _classCallCheck(this, HorizontalBarChart);
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 currentTheme = getCurrentTheme(colorThemeName);
45
+ var type = statItem.type,
46
+ sort_type = statItem.sort_type;
47
+ var data = originalData;
48
+ if (type == STAT_TYPE.STACKED_HORIZONTAL_BAR && sort_type) {
49
+ data = sortDataByGroupSum(originalData, sort_type);
50
+ }
51
+ if (isPreview) {
52
+ _this.chart = new Chart({
53
+ container: _this.container,
54
+ autoFit: true,
55
+ appendPadding: [0, 30, 0, 0]
56
+ });
57
+ } else {
58
+ _this.chart = new Chart({
59
+ container: _this.container,
60
+ autoFit: true,
61
+ height: 400,
62
+ width: 700,
63
+ appendPadding: [0, 30, 0, 0]
64
+ });
65
+ }
66
+ _this.chart.on('interval:click', function (e) {
67
+ _this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
68
+ });
69
+ var table_id = statItem.table_id,
70
+ horizontal_axis_column_key = statItem.horizontal_axis_column_key,
71
+ horizontal_axis_summary_type = statItem.horizontal_axis_summary_type,
72
+ horizontal_axis_summary_method = statItem.horizontal_axis_summary_method,
73
+ column_groupby_column_key = statItem.column_groupby_column_key,
74
+ display_data = statItem.display_data,
75
+ column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
76
+ h_axis_auto_range = statItem.h_axis_auto_range,
77
+ h_axis_min = statItem.h_axis_min,
78
+ h_axis_max = statItem.h_axis_max,
79
+ color_option = statItem.color_option;
80
+ var chartBarColor,
81
+ columnData = DEFAULT_NUMBER_FORMAT_OBJECT;
82
+ if (horizontal_axis_summary_type === SUMMARY_TYPE.ADVANCED) {
83
+ var table = getTableById(table_id);
84
+ var summaryColumn = TableUtils.getTableColumnByKey(table, horizontal_axis_column_key) || {};
85
+ columnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
86
+ }
87
+ if (column_groupby_column_key || column_groupby_multiple_numeric_column) {
88
+ chartBarColor = 'group_name';
89
+ _this.chart.scale('group_name', {
90
+ type: 'cat'
91
+ });
92
+ } else if (currentTheme && currentTheme.colors) {
93
+ chartBarColor = currentTheme.colors[0];
94
+ } else {
95
+ chartBarColor = '#2a67d1';
96
+ }
97
+ _this.chart.data(data, {
98
+ 'name': {
99
+ type: 'cat',
100
+ nice: false
101
+ }
102
+ });
103
+ var themeColors = STAT_ITEM_THEME_COLORS.light;
104
+ if (theme === 'dark' && !isEnlarge && isPreview) {
105
+ themeColors = STAT_ITEM_THEME_COLORS.dark;
106
+ }
107
+ var width = _this.chart.coordinateBBox.width;
108
+ var chartData;
109
+ if (column_groupby_column_key || column_groupby_multiple_numeric_column) {
110
+ chartData = getChartGroups(data);
111
+ } else {
112
+ chartData = data;
113
+ }
114
+ var labelCount = chartData.length;
115
+ if (Math.floor(width / labelCount) <= 20) {
116
+ var displayLabels = getChartDisplayLabels(width, 20, chartData);
117
+ labelCount = displayLabels.length;
118
+ _this.chart.scale('name', {
119
+ ticks: displayLabels
120
+ });
121
+ }
122
+
123
+ // set Coord type
124
+ _this.chart.coordinate('rect');
125
+
126
+ // set scale options for 'value'
127
+ var valueScaleOptions = {
128
+ formatter: function formatter(value) {
129
+ return getNumberDisplayString(value, columnData);
130
+ }
131
+ };
132
+ if (h_axis_auto_range == undefined || h_axis_auto_range) {
133
+ valueScaleOptions = Object.assign({}, valueScaleOptions, {
134
+ // Automatically adjust the maximum and minimum values
135
+ nice: true
136
+ });
137
+ } else {
138
+ valueScaleOptions = Object.assign({}, valueScaleOptions, {
139
+ min: h_axis_min,
140
+ max: h_axis_max
141
+ });
142
+ // set the filter rule
143
+ _this.chart.filter('value', function (value) {
144
+ return value >= h_axis_min;
145
+ });
146
+ // filter the data
147
+ _this.chart.filterData(data);
148
+ }
149
+ _this.chart.scale({
150
+ // Set the type of the name column so that g2 can draw correctly
151
+ name: {
152
+ type: 'cat'
153
+ },
154
+ value: valueScaleOptions
155
+ });
156
+ if (column_groupby_column_key || column_groupby_multiple_numeric_column) {
157
+ _this.chart.scale({
158
+ group_name: {
159
+ type: 'cat'
160
+ }
161
+ });
162
+ var labelCfg = {
163
+ offset: 5,
164
+ position: function position() {
165
+ return 'right';
166
+ },
167
+ style: {
168
+ fontSize: _this.getLabelFontSize(),
169
+ fill: themeColors.textColor
170
+ }
171
+ };
172
+ if (statItem.type == STAT_TYPE.STACKED_HORIZONTAL_BAR) {
173
+ // get the total value of each stack
174
+ var dv = new DataSet.DataView().source(data);
175
+ dv.transform({
176
+ type: 'aggregate',
177
+ fields: ['value'],
178
+ operations: ['sum'],
179
+ as: ['value_sum'],
180
+ groupBy: ['name']
181
+ });
182
+ var groupNames = [];
183
+ data.forEach(function (item) {
184
+ if (groupNames.indexOf(item.group_name) == -1) {
185
+ groupNames.push(item.group_name);
186
+ }
187
+ });
188
+ labelCfg.content = function (dataItem, mappingData, index) {
189
+ var name = dataItem.name,
190
+ group_name = dataItem.group_name;
191
+ var targetData = dv.rows.filter(function (item) {
192
+ return item.name == name;
193
+ });
194
+ // make the value displayed in the same precision with the column
195
+ var valueSum = getNumberDisplayString(targetData[0].value_sum, columnData);
196
+ var groupedItems = data.filter(function (item) {
197
+ return item.name == name;
198
+ });
199
+ if (groupedItems.length == 1) {
200
+ return valueSum;
201
+ }
202
+ var filteredGroupNameIndexes = groupedItems.map(function (item) {
203
+ return groupNames.indexOf(item.group_name);
204
+ }).filter(function (item) {
205
+ return item > -1;
206
+ });
207
+ if (filteredGroupNameIndexes.length == 0) {
208
+ return valueSum;
209
+ }
210
+ filteredGroupNameIndexes.sort(function (a, b) {
211
+ return a - b;
212
+ });
213
+ if (group_name == groupNames[filteredGroupNameIndexes[0]]) {
214
+ return valueSum;
215
+ }
216
+ return null;
217
+ };
218
+ }
219
+ var groupColorCallback = currentTheme && currentTheme.colors;
220
+ // when the 'Group by' column is a 'single-select' column,
221
+ // and the user chooses to use the colors from the column.
222
+ if (color_option === USEABLE_COLOR_TYPES[1]) {
223
+ var groupColorMapping = {};
224
+ data.forEach(function (item) {
225
+ if (!groupColorMapping[item.group_name]) {
226
+ groupColorMapping[item.group_name] = item.color;
227
+ }
228
+ });
229
+ groupColorCallback = function groupColorCallback(group_name) {
230
+ return groupColorMapping[group_name];
231
+ };
232
+ }
233
+ _this.chart.interval().label(display_data ? 'value' : false, labelCfg).position('name*value').color('group_name', groupColorCallback).tooltip('name*value*group_name', function (name, value, group_name) {
234
+ return {
235
+ title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
236
+ value: getNumberDisplayString(value, columnData),
237
+ name: !group_name && typeof group_name !== 'number' ? intl.get(EMPTY_NAME) : group_name
238
+ };
239
+ }).adjust([{
240
+ reverseOrder: true,
241
+ // for 'stack'. It only work for 'stack'.
242
+ type: statItem.type == STAT_TYPE.STACKED_HORIZONTAL_BAR ? 'stack' : 'dodge'
243
+ }]).state({
244
+ active: {
245
+ style: {
246
+ stroke: null
247
+ }
248
+ }
249
+ });
250
+ } else {
251
+ var colorRules = statItem.color_option === TYPE_COLOR_USING.USE_RULES && statItem.horizontal_axis_label_color_rules && getConvertedColorRules(statItem.horizontal_axis_label_color_rules);
252
+ _this.chart.interval().label(display_data ? 'value' : false, {
253
+ offset: 5,
254
+ position: function position() {
255
+ return 'right';
256
+ },
257
+ style: {
258
+ fontSize: _this.getLabelFontSize(),
259
+ fill: themeColors.textColor
260
+ }
261
+ }).position('name*value').tooltip('name*value', function (name, value) {
262
+ return {
263
+ title: horizontal_axis_summary_type === 'count' ? intl.get(TITLE_AMOUNT) : intl.get(STATISTICS_COUNT_SHOW[horizontal_axis_summary_method]),
264
+ value: getNumberDisplayString(value, columnData),
265
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
266
+ };
267
+ }).state({
268
+ active: {
269
+ style: {
270
+ stroke: null
271
+ }
272
+ }
273
+ }).style('value', function (value) {
274
+ var color = getLabelColor({
275
+ chart: statItem,
276
+ colorRules: colorRules,
277
+ value: value
278
+ });
279
+ if (color) {
280
+ return {
281
+ fill: color
282
+ };
283
+ }
284
+ return {
285
+ fill: chartBarColor
286
+ };
287
+ });
288
+ }
289
+ _this.chart.tooltip({
290
+ showTitle: true,
291
+ showMarkers: false,
292
+ containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
293
+ itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
294
+ domStyles: {
295
+ 'g2-tooltip': {
296
+ borderRadius: '2px',
297
+ backgroundColor: '#fff',
298
+ padding: '10px'
299
+ },
300
+ 'tooltip-item': {
301
+ marginTop: '5px'
302
+ }
303
+ }
304
+ });
305
+
306
+ // set axis label and tooltip
307
+ _this.chart.axis('name', {
308
+ label: {
309
+ style: {
310
+ fill: themeColors.textColor
311
+ },
312
+ line: {
313
+ style: themeColors.gridColor
314
+ },
315
+ autoRotate: true,
316
+ formatter: function formatter(name) {
317
+ var label = name;
318
+ if (name.length > 10) {
319
+ label = "".concat(name.slice(0, 10), "...");
320
+ }
321
+ if (name === '' || name === 'undefined') {
322
+ label = intl.get(EMPTY_NAME);
323
+ }
324
+ return label;
325
+ }
326
+ }
327
+ });
328
+ _this.chart.axis('value', {
329
+ label: {
330
+ style: {
331
+ fill: themeColors.textColor
332
+ }
333
+ },
334
+ grid: {
335
+ line: {
336
+ style: {
337
+ stroke: themeColors.gridColor
338
+ }
339
+ }
340
+ }
341
+ });
342
+ var legendPosition = 'bottom';
343
+ _this.chart.legend('group_name', {
344
+ position: legendPosition,
345
+ itemName: {
346
+ style: {
347
+ fill: themeColors.textColor
348
+ },
349
+ formatter: function formatter(name) {
350
+ return !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
351
+ }
352
+ }
353
+ });
354
+ _this.chart.interaction('active-region');
355
+ _this.chart.coordinate().transpose();
356
+ _this.chart.render();
357
+ _this.renderAxisLabel();
358
+ };
359
+ _this.renderAxisLabel = function (newStatItem) {
360
+ var _this$props2 = _this.props,
361
+ getTableById = _this$props2.getTableById,
362
+ statItem = _this$props2.statItem,
363
+ isEnlarge = _this$props2.isEnlarge,
364
+ isPreview = _this$props2.isPreview,
365
+ theme = _this$props2.theme;
366
+ if (newStatItem && newStatItem._id !== statItem._id) {
367
+ return;
368
+ }
369
+ if (!_this.chart) return;
370
+ statItem = newStatItem || statItem;
371
+ var isEdit = _this.props.isEdit;
372
+ var _statItem = statItem,
373
+ table_id = _statItem.table_id,
374
+ vertical_axis_column_key = _statItem.vertical_axis_column_key,
375
+ show_horizontal_axis_label = _statItem.show_horizontal_axis_label,
376
+ show_vertical_axis_label = _statItem.show_vertical_axis_label,
377
+ horizontal_axis_label_position = _statItem.horizontal_axis_label_position,
378
+ vertical_axis_label_position = _statItem.vertical_axis_label_position,
379
+ horizontal_axis_column_key = _statItem.horizontal_axis_column_key,
380
+ horizontal_axis_summary_type = _statItem.horizontal_axis_summary_type,
381
+ type = _statItem.type,
382
+ _statItem$title_name = _statItem.title_name,
383
+ title_name = _statItem$title_name === void 0 ? '' : _statItem$title_name;
384
+ var table = getTableById(table_id);
385
+ var autoPadding = _this.chart.autoPadding;
386
+ var textColor = '#999999';
387
+ if (theme === 'dark' && !isEnlarge && isPreview) {
388
+ textColor = '#ffffff';
389
+ }
390
+ var chartContainer = _this.chart.getCanvas().get('container');
391
+ var horizontalAxisID = "chart-horizontal-axis-label_".concat(statItem._id);
392
+ var horizontalLabel = chartContainer.querySelector("#".concat(horizontalAxisID));
393
+ if (!horizontalLabel && show_horizontal_axis_label) {
394
+ var div = document.createElement('div');
395
+ div.id = horizontalAxisID;
396
+ div.className = 'statistic-chart-axis-label';
397
+ if (horizontal_axis_summary_type === 'count') {
398
+ div.innerHTML = intl.get(TITLE_AMOUNT);
399
+ } else {
400
+ var column = TableUtils.getTableColumnByKey(table, horizontal_axis_column_key) || {};
401
+ div.innerHTML = column.name || '';
402
+ }
403
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(horizontal_axis_label_position, "; bottom: -20px"));
404
+ chartContainer.appendChild(div);
405
+ }
406
+ if (horizontalLabel && show_horizontal_axis_label) {
407
+ horizontalLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; padding-left: ").concat(autoPadding.left, "px; text-align: ").concat(horizontal_axis_label_position, "; bottom: -20px"));
408
+ }
409
+ if (horizontalLabel && !show_horizontal_axis_label) {
410
+ horizontalLabel.parentNode.removeChild(horizontalLabel);
411
+ }
412
+ var verticalAxisID = "chart-vertical-axis-label_".concat(isEdit);
413
+ var verticalLabel = document.getElementById(verticalAxisID);
414
+ if (!verticalLabel && show_vertical_axis_label) {
415
+ var _div = document.createElement('div');
416
+ _div.id = verticalAxisID;
417
+ _div.className = 'statistic-chart-axis-label';
418
+ var _column = TableUtils.getTableColumnByKey(table, vertical_axis_column_key);
419
+ _div.innerHTML = "".concat(_column ? _column.name : '');
420
+ if (type === STAT_TYPE.STACKED_HORIZONTAL_BAR) {
421
+ _div.innerHTML = title_name;
422
+ }
423
+ var containerHeight = chartContainer.offsetHeight;
424
+ var textAlign = 'center';
425
+ if (vertical_axis_label_position === 'bottom') textAlign = 'left';
426
+ if (vertical_axis_label_position === 'top') textAlign = 'right';
427
+ _div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; padding-left: ").concat(autoPadding.bottom, "px; text-align: ").concat(textAlign, "; top: 0; left: 0px; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 - 6, "px) rotate(-90deg)"));
428
+ chartContainer.appendChild(_div);
429
+ }
430
+ if (verticalLabel && show_vertical_axis_label) {
431
+ var _containerHeight = chartContainer.offsetHeight;
432
+ var _textAlign = 'center';
433
+ if (vertical_axis_label_position === 'bottom') _textAlign = 'left';
434
+ if (vertical_axis_label_position === 'top') _textAlign = 'right';
435
+ verticalLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(_containerHeight, "px; padding-left: ").concat(autoPadding.bottom, "px; text-align: ").concat(_textAlign, "; top: 0; left: 0px; transform: translate(-").concat(_containerHeight / 2 + 12, "px, ").concat((_containerHeight - autoPadding.bottom) / 2 - 6, "px) rotate(-90deg)"));
436
+ }
437
+ if (verticalLabel && !show_vertical_axis_label) {
438
+ verticalLabel.parentNode.removeChild(verticalLabel);
439
+ }
440
+ };
441
+ _this.destroyChart = function () {
442
+ _this.chart.destroy();
443
+ _this.chart = null;
444
+ };
445
+ _this.getLabelFontSize = function () {
446
+ var statItem = _this.props.statItem;
447
+ var label_font_size = statItem.label_font_size;
448
+ return getLabelFontSize(label_font_size);
449
+ };
450
+ _this.state = {
451
+ isCalculatingData: true,
452
+ showResultDescription: true
453
+ };
454
+ _this.calculateData = null;
455
+ return _this;
456
+ }
457
+ _createClass(HorizontalBarChart, [{
458
+ key: "componentDidMount",
459
+ value: function componentDidMount() {
460
+ var _this2 = this;
461
+ var _this$props3 = this.props,
462
+ statItem = _this$props3.statItem,
463
+ chartCalculator = _this$props3.chartCalculator,
464
+ eventBus = _this$props3.eventBus;
465
+ this.unsubscribeStyleChange = eventBus.subscribe(LABEL_CONFIG_CHANGED, function (newStatItem) {
466
+ _this2.renderAxisLabel(newStatItem);
467
+ });
468
+ chartCalculator.calculate(statItem).then(function (data) {
469
+ var showResultDescription = data.length > 0 ? false : true;
470
+ if (_this2.container) {
471
+ _this2.setState({
472
+ isCalculatingData: false,
473
+ showResultDescription: showResultDescription
474
+ }, function () {
475
+ if (!showResultDescription) {
476
+ _this2.drawChart(data);
477
+ _this2.calculateData = data;
478
+ }
479
+ });
480
+ }
481
+ });
482
+ }
483
+ }, {
484
+ key: "shouldComponentUpdate",
485
+ value: function shouldComponentUpdate(nextProps, nextState) {
486
+ var colorThemeName = this.props.colorThemeName;
487
+ if (this.canUpdate(this.props, nextProps)) {
488
+ return true;
489
+ }
490
+ if (nextState.isCalculatingData !== this.state.isCalculatingData) {
491
+ return true;
492
+ }
493
+ if (nextProps.colorThemeName !== colorThemeName) {
494
+ return true;
495
+ }
496
+ return false;
497
+ }
498
+ }, {
499
+ key: "componentDidUpdate",
500
+ value: function componentDidUpdate(preProps, preState) {
501
+ var _this3 = this;
502
+ var _this$props4 = this.props,
503
+ statItem = _this$props4.statItem,
504
+ chartCalculator = _this$props4.chartCalculator;
505
+ var isCalculatingData = this.state.isCalculatingData;
506
+ if (isCalculatingData !== preState.isCalculatingData) return;
507
+ if (this.shouldCalculateStatItem(preProps, this.props)) {
508
+ this.setState({
509
+ isCalculatingData: true
510
+ });
511
+ chartCalculator.calculate(statItem).then(function (data) {
512
+ var showResultDescription = data.length > 0 ? false : true;
513
+ _this3.chart && _this3.destroyChart();
514
+ _this3.calculateData = data;
515
+ _this3.setState({
516
+ isCalculatingData: false,
517
+ showResultDescription: showResultDescription
518
+ }, function () {
519
+ if (!showResultDescription) {
520
+ _this3.drawChart(data);
521
+ if (_this3.props.isPreview) _this3.chart.forceFit();
522
+ }
523
+ });
524
+ });
525
+ } else {
526
+ if (!this.state.showResultDescription) {
527
+ this.chart && this.destroyChart();
528
+ this.drawChart(this.calculateData);
529
+ if (this.props.isPreview) {
530
+ this.chart.forceFit();
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }, {
536
+ key: "componentWillUnmount",
537
+ value: function componentWillUnmount() {
538
+ this.container = null;
539
+ this.unsubscribeStyleChange();
540
+ }
541
+ }, {
542
+ key: "render",
543
+ value: function render() {
544
+ var _this4 = this;
545
+ var statItem = this.props.statItem;
546
+ var _this$state = this.state,
547
+ isCalculatingData = _this$state.isCalculatingData,
548
+ showResultDescription = _this$state.showResultDescription;
549
+ var show_horizontal_axis_label = statItem.show_horizontal_axis_label,
550
+ show_vertical_axis_label = statItem.show_vertical_axis_label;
551
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && /*#__PURE__*/React.createElement("div", {
552
+ className: 'statistic-chart-loading-container'
553
+ }, /*#__PURE__*/React.createElement(Loading, null)), showResultDescription && /*#__PURE__*/React.createElement("div", {
554
+ className: 'statistic-chart-text'
555
+ }, intl.get(NO_STATISTIC_RESULTS)), /*#__PURE__*/React.createElement("div", {
556
+ ref: function ref(_ref) {
557
+ return _this4.container = _ref;
558
+ },
559
+ style: {
560
+ padding: show_vertical_axis_label || show_horizontal_axis_label ? 30 : 20
561
+ },
562
+ className: "statistic-chart-container"
563
+ }));
564
+ }
565
+ }]);
566
+ return HorizontalBarChart;
567
+ }(BaseChart);
568
+ HorizontalBarChart.propTypes = propTypes;
569
+ export default HorizontalBarChart;