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,501 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import React from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import dayjs from 'dayjs';
9
+ import weekOfYear from 'dayjs/plugin/weekOfYear';
10
+ import intl from 'react-intl-universal';
11
+ import { TableUtils, getNumberDisplayString } from 'dtable-store';
12
+ import BaseChart from './base-chart';
13
+ import { Chart, registerShape, getRectWithCornerRadius } from '../custom-g2';
14
+ import { Loading } from '../components';
15
+ import { isShapeEqual } from '../utils/common-utils';
16
+ import { COLOR_OPTIONS, DEFAULT_GRID_DISTANCE, DEFAULT_GRID_SIZE, DEFAULT_NUMBER_FORMAT_OBJECT, FILL_BORDER_COLOR_MAP, MONTH_MIRROR, NO_STATISTIC_RESULTS, STAT_ITEM_THEME_COLORS, SUMMARY_TYPE, TITLE_AMOUNT } from '../constants';
17
+ import styles from '../assets/css/statistic-custom.module.css';
18
+ dayjs.extend(weekOfYear);
19
+ var HeatMap = /*#__PURE__*/function (_BaseChart) {
20
+ _inherits(HeatMap, _BaseChart);
21
+ var _super = _createSuper(HeatMap);
22
+ function HeatMap(props) {
23
+ var _this;
24
+ _classCallCheck(this, HeatMap);
25
+ _this = _super.call(this, props);
26
+ _this.transformData = function (statData) {
27
+ var data = {};
28
+ var yearFirstDate = dayjs(statData[0].name);
29
+ _this.firstDate = yearFirstDate.year() + '-01-01';
30
+ statData.forEach(function (item) {
31
+ data[item.name] = data[item.name] ? data[item.name] + item.value : item.value;
32
+ });
33
+ return data;
34
+ };
35
+ _this.generateBackgroundGridData = function (statData) {
36
+ var momentDate = dayjs(_this.firstDate);
37
+ var year = momentDate.year();
38
+ var gridData = [];
39
+ var isLeapYear = year % 4 > 0 ? false : true;
40
+ var yearDayCount = 365;
41
+ if (isLeapYear) {
42
+ yearDayCount = 366;
43
+ }
44
+ for (var i = 0; i < yearDayCount; i++) {
45
+ var day = momentDate.day();
46
+ var week = momentDate.week() - 1;
47
+ var month = momentDate.month();
48
+ if (week === 0 && month === 11) {
49
+ week = 52;
50
+ }
51
+ var yearDate = momentDate.format('YYYY-MM-DD');
52
+ var value = statData[yearDate] || 0;
53
+ _this.maxValue = Math.max(_this.maxValue, value);
54
+ gridData.push({
55
+ date: yearDate,
56
+ value: statData[yearDate],
57
+ day: day,
58
+ week: week,
59
+ month: month
60
+ });
61
+ momentDate = momentDate.add(1, 'days');
62
+ }
63
+ return gridData;
64
+ };
65
+ _this.getLabel = function (val) {
66
+ var currentDate = dayjs(_this.firstDate).add(val * 7, 'days');
67
+ var month = currentDate.month();
68
+ var monthDate = currentDate.date();
69
+ var isFirst = monthDate <= 7 || false;
70
+
71
+ // if the week is the first week of a month
72
+ // mark it to axis
73
+ if (isFirst) {
74
+ return intl.get(MONTH_MIRROR[month]);
75
+ }
76
+ return '';
77
+ };
78
+ _this.drawChart = function (statData) {
79
+ _this.maxValue = 0;
80
+ var _this$props = _this.props,
81
+ getTableById = _this$props.getTableById,
82
+ isPreview = _this$props.isPreview,
83
+ isEnlarge = _this$props.isEnlarge,
84
+ theme = _this$props.theme,
85
+ statItem = _this$props.statItem;
86
+ var currentColorOption = COLOR_OPTIONS.filter(function (item) {
87
+ return item.name == statItem.data_color;
88
+ })[0] || COLOR_OPTIONS[0];
89
+ var exampleColors = currentColorOption.exampleColors;
90
+ var count = statData.years.length;
91
+ /**
92
+ * 114: 12 * 7 + 6 * 4 + 8(mistake)
93
+ * 30: the bottom padding of one calendar
94
+ * count: the calendar count
95
+ * 30: the top padding of the chart
96
+ * 15: the spacing of calendar
97
+ */
98
+
99
+ var grid_size = statItem.grid_size,
100
+ grid_distance = statItem.grid_distance;
101
+ grid_size = grid_size || DEFAULT_GRID_SIZE;
102
+ grid_distance = grid_distance || DEFAULT_GRID_DISTANCE;
103
+ // height for 1 year
104
+ var yearHeight = grid_size * 7 + grid_distance * 6 + 8;
105
+ var chartHeight = (yearHeight + 30) * count + 30 + (count - 1) * 15;
106
+ _this.chart = new Chart({
107
+ container: _this.container,
108
+ autoFit: false,
109
+ height: chartHeight,
110
+ width: grid_size * 53 + grid_distance * 52 + 75,
111
+ // 75: left padding + right padding
112
+ padding: [30, 30, 0, 45]
113
+ });
114
+ _this.chart.on('element:click', function (e) {
115
+ var clickDate = e.data.data.date;
116
+ var data = statData.data.find(function (i) {
117
+ return i.name === clickDate;
118
+ });
119
+ _this.props.toggleStatisticRecordsDialog(data, statItem);
120
+ });
121
+ _this.chart.tooltip({
122
+ title: 'date',
123
+ showMarkers: false,
124
+ showTitle: false,
125
+ shared: true,
126
+ containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
127
+ itemTpl: "<div class=\"g2-tooltip-content\"><div style=\"width: max-content; text-align: left;\" class=\"tooltip-name\">{date}<div><div style=\"word-break: keep-all;\" class=\"tooltip-item\">".concat(intl.get(TITLE_AMOUNT), " : {value}<div></div>"),
128
+ domStyles: {
129
+ 'g2-tooltip': {
130
+ borderRadius: '2px',
131
+ backgroundColor: '#fff',
132
+ padding: '10px'
133
+ },
134
+ 'tooltip-item': {
135
+ marginTop: '5px'
136
+ }
137
+ }
138
+ });
139
+ _this.chart.axis(false);
140
+ _this.chart.data(statData.data);
141
+ var themeColors = STAT_ITEM_THEME_COLORS.light;
142
+ if (theme === 'dark' && !isEnlarge && isPreview) {
143
+ themeColors = STAT_ITEM_THEME_COLORS.dark;
144
+ }
145
+ var columnData = DEFAULT_NUMBER_FORMAT_OBJECT;
146
+ var table_id = statItem.table_id,
147
+ summary_type = statItem.summary_type,
148
+ summary_column = statItem.summary_column;
149
+ if (summary_type === SUMMARY_TYPE.ADVANCED) {
150
+ var table = getTableById(table_id);
151
+ var summaryColumn = TableUtils.getTableColumnByKey(table, summary_column) || {};
152
+ columnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
153
+ }
154
+ _this.chart.facet('list', {
155
+ fields: ['year'],
156
+ cols: 1,
157
+ showTitle: true,
158
+ title: {
159
+ offsetY: yearHeight + 15,
160
+ offsetX: -((grid_size * 53 + grid_distance * 52) / 2 + 20),
161
+ style: {
162
+ fontSize: 12,
163
+ fill: '#000',
164
+ fontWeight: '500'
165
+ }
166
+ },
167
+ padding: [0, 0, 15, 0],
168
+ spacing: [0, 15],
169
+ eachView: function eachView(view, facet) {
170
+ var groupStatData = _this.transformData(facet.data);
171
+ var gridData = _this.generateBackgroundGridData(groupStatData);
172
+ var gridView = view.createView();
173
+ gridView.axis('week', {
174
+ position: 'top',
175
+ tickLine: null,
176
+ line: null,
177
+ label: {
178
+ offset: 3,
179
+ rotate: 0,
180
+ autoHide: false,
181
+ autoRotate: false,
182
+ autoEllipsis: false,
183
+ style: {
184
+ fontSize: 12,
185
+ fill: themeColors.textColor
186
+ },
187
+ formatter: function formatter(val, label, index) {
188
+ return _this.getLabel(val);
189
+ }
190
+ },
191
+ grid: null
192
+ });
193
+ gridView.axis('day', {
194
+ grid: null,
195
+ label: {
196
+ autoHide: false,
197
+ autoEllipsis: false,
198
+ style: {
199
+ fill: themeColors.textColor
200
+ }
201
+ }
202
+ });
203
+ gridView.scale({
204
+ day: {
205
+ type: 'cat',
206
+ values: [intl.get('Sun'), intl.get('Mon'), intl.get('Tue'), intl.get('Wed'), intl.get('Thu'), intl.get('Fri'), intl.get('Sat')]
207
+ },
208
+ week: {
209
+ type: 'cat'
210
+ },
211
+ value: {
212
+ sync: true
213
+ },
214
+ date: {
215
+ type: 'cat'
216
+ }
217
+ });
218
+ gridView.data(gridData);
219
+ gridView.polygon().position('week*day*date').color('value', function (value) {
220
+ if (!value || value <= 0) {
221
+ return '#EBEDF0';
222
+ }
223
+ if (value === _this.maxValue) return exampleColors[8];
224
+ return exampleColors[Math.floor(value / (_this.maxValue / 9))];
225
+ }).customInfo({
226
+ grid_size: grid_size,
227
+ grid_distance: grid_distance
228
+ }).shape('boundary-polygon').label(false).tooltip('date*value', function (date, value) {
229
+ return {
230
+ date: date,
231
+ value: getNumberDisplayString(value, columnData)
232
+ };
233
+ });
234
+ gridView.coordinate().reflect('y');
235
+ }
236
+ });
237
+ _this.chart.legend('value', {
238
+ position: 'top-left',
239
+ layout: 'horizontal',
240
+ offsetY: -6,
241
+ custom: true,
242
+ itemSpacing: 2,
243
+ itemName: {
244
+ style: {
245
+ fontWeight: 'bold',
246
+ fill: themeColors.textColor
247
+ }
248
+ },
249
+ items: _this.getLegendItems(exampleColors)
250
+ });
251
+ _this.chart.removeInteraction('legend-filter');
252
+ _this.chart.render();
253
+ };
254
+ // get text width in canvas
255
+ _this.getTextWidthInCanvas = function (text) {
256
+ var canvas = document.createElement('canvas');
257
+ var context = canvas.getContext('2d');
258
+ var font = context.font;
259
+ var fontStyle = font.slice(font.indexOf('px'));
260
+ font = 'bold ' + 12 + fontStyle;
261
+ context.font = font;
262
+ return Math.ceil(context.measureText(text).width);
263
+ };
264
+ _this.destroyChart = function () {
265
+ _this.chart.destroy();
266
+ _this.chart = null;
267
+ };
268
+ dayjs.locale('en');
269
+ _this.state = {
270
+ isCalculatingData: true,
271
+ showResultDescription: true
272
+ };
273
+ _this.calculateData = null;
274
+ _this.maxValue = 0;
275
+ return _this;
276
+ }
277
+ _createClass(HeatMap, [{
278
+ key: "componentDidMount",
279
+ value: function componentDidMount() {
280
+ var _this2 = this;
281
+ var _this$props2 = this.props,
282
+ statItem = _this$props2.statItem,
283
+ chartCalculator = _this$props2.chartCalculator;
284
+ registerShape('polygon', 'boundary-polygon', {
285
+ draw: function draw(cfg, container) {
286
+ if (cfg && cfg.points && cfg.points.length > 0) {
287
+ var group = container.addGroup();
288
+ var attrs = {
289
+ fill: cfg.color,
290
+ lineWidth: 1,
291
+ stroke: FILL_BORDER_COLOR_MAP[cfg.color]
292
+ };
293
+ var points = cfg.points,
294
+ customInfo = cfg.customInfo;
295
+ var grid_size = customInfo.grid_size,
296
+ grid_distance = customInfo.grid_distance;
297
+ var distance = grid_distance / 2;
298
+ var offset = grid_size - 1;
299
+ var parsedPoint = this.parsePoints(points);
300
+ var _parsedPoint = _slicedToArray(parsedPoint, 4),
301
+ p0 = _parsedPoint[0],
302
+ p1 = _parsedPoint[1],
303
+ p2 = _parsedPoint[2],
304
+ p3 = _parsedPoint[3];
305
+ p0.y = p0.y + distance;
306
+ p1.x = p0.x;
307
+ p1.y = p0.y + offset;
308
+ p2.x = p0.x + offset;
309
+ p2.y = p1.y;
310
+ p3.x = p0.x + offset;
311
+ p3.y = p0.y;
312
+ // get cell path that has radius, the cell radius is 2;
313
+ var path = getRectWithCornerRadius(parsedPoint, this.coordinate, 2);
314
+ attrs.path = path;
315
+ group.addShape('path', {
316
+ attrs: attrs,
317
+ capture: cfg.data.value > 0,
318
+ visible: true
319
+ });
320
+ return group;
321
+ }
322
+ }
323
+ });
324
+ if (this.container) {
325
+ chartCalculator.calculate(statItem).then(function (data) {
326
+ var showResultDescription = data.years && data.years.length > 0 ? false : true;
327
+ _this2.calculateData = data;
328
+ _this2.setState({
329
+ isCalculatingData: false,
330
+ showResultDescription: showResultDescription
331
+ }, function () {
332
+ if (!showResultDescription) {
333
+ _this2.drawChart(data);
334
+ _this2.calculateData = data;
335
+ }
336
+ });
337
+ });
338
+ }
339
+ }
340
+ }, {
341
+ key: "shouldComponentUpdate",
342
+ value: function shouldComponentUpdate(nextProps, nextState) {
343
+ var statItem = this.props.statItem;
344
+ if (this.canUpdate(this.props, nextProps)) {
345
+ if (!isShapeEqual(nextProps.statItem.layout, statItem.layout)) {
346
+ return false;
347
+ }
348
+ return true;
349
+ }
350
+ if (nextState.isCalculatingData !== this.state.isCalculatingData) {
351
+ return true;
352
+ }
353
+ return false;
354
+ }
355
+ }, {
356
+ key: "componentDidUpdate",
357
+ value: function componentDidUpdate(preProps, preState) {
358
+ var _this3 = this;
359
+ var _this$props3 = this.props,
360
+ statItem = _this$props3.statItem,
361
+ chartCalculator = _this$props3.chartCalculator;
362
+ var isCalculatingData = this.state.isCalculatingData;
363
+ if (isCalculatingData !== preState.isCalculatingData) return;
364
+ if (this.shouldCalculateStatItem(preProps, this.props)) {
365
+ this.setState({
366
+ isCalculatingData: true
367
+ });
368
+ if (this.container) {
369
+ chartCalculator.calculate(statItem).then(function (data) {
370
+ var showResultDescription = data.years && data.years.length > 0 ? false : true;
371
+ _this3.chart && _this3.destroyChart();
372
+ _this3.calculateData = data;
373
+ _this3.setState({
374
+ isCalculatingData: false,
375
+ showResultDescription: showResultDescription
376
+ }, function () {
377
+ if (!showResultDescription) {
378
+ _this3.drawChart(data);
379
+ }
380
+ });
381
+ });
382
+ }
383
+ } else {
384
+ if (!this.state.showResultDescription) {
385
+ this.chart && this.destroyChart();
386
+ this.drawChart(this.calculateData);
387
+ }
388
+ }
389
+ }
390
+ }, {
391
+ key: "componentWillUnmount",
392
+ value: function componentWillUnmount() {
393
+ this.container = null;
394
+ }
395
+ }, {
396
+ key: "getLegendItems",
397
+ value: function getLegendItems(colors) {
398
+ var _this4 = this;
399
+ var text = intl.get('Less');
400
+ var textWidth = this.getTextWidthInCanvas(text);
401
+ var items = [{
402
+ name: text,
403
+ marker: {
404
+ symbol: function symbol(x, y, r) {
405
+ return _this4.getLegendItemPath(x, y, r, 0, textWidth);
406
+ },
407
+ spacing: 0,
408
+ style: {
409
+ fill: '#E1E3E6',
410
+ lineWidth: 1,
411
+ stroke: '#EBEDF0',
412
+ r: 5
413
+ }
414
+ }
415
+ }];
416
+ colors.forEach(function (color, index) {
417
+ items.push({
418
+ marker: {
419
+ symbol: function symbol(x, y, r) {
420
+ return _this4.getLegendItemPath(x, y, r, index + 1, textWidth);
421
+ },
422
+ spacing: 2,
423
+ style: {
424
+ fill: color,
425
+ lineWidth: 1,
426
+ stroke: FILL_BORDER_COLOR_MAP[color],
427
+ r: 5
428
+ }
429
+ }
430
+ });
431
+ });
432
+ items[9].name = intl.get('More');
433
+ items[9].marker.spacing = 22;
434
+ return items;
435
+ }
436
+ }, {
437
+ key: "getLegendItemPath",
438
+ value: function getLegendItemPath(x, y, r, index, textWidth) {
439
+ // x, y represents the coordinates of the center point of the legend item marker
440
+ var p0 = {
441
+ x: x - 6,
442
+ y: y + 6
443
+ };
444
+ // translate the lengend marker to right to make the first legend item text to left of the marker
445
+ if (index === 0) {
446
+ p0.x = p0.x + textWidth + 16;
447
+ } else {
448
+ p0.x = p0.x + 18;
449
+ }
450
+ var p1 = {
451
+ x: p0.x,
452
+ y: p0.y - 12
453
+ };
454
+ var p2 = {
455
+ x: p0.x + 12,
456
+ y: p0.y - 12
457
+ };
458
+ var p3 = {
459
+ x: p0.x + 12,
460
+ y: p0.y
461
+ };
462
+ var path = getRectWithCornerRadius([p0, p1, p2, p3], this.chart.coordinateInstance, 2);
463
+ return path;
464
+ }
465
+ }, {
466
+ key: "render",
467
+ value: function render() {
468
+ var _this5 = this;
469
+ var _this$state = this.state,
470
+ isCalculatingData = _this$state.isCalculatingData,
471
+ showResultDescription = _this$state.showResultDescription;
472
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && /*#__PURE__*/React.createElement("div", {
473
+ className: 'statistic-chart-loading-container'
474
+ }, /*#__PURE__*/React.createElement(Loading, null)), showResultDescription && /*#__PURE__*/React.createElement("div", {
475
+ className: 'statistic-chart-text'
476
+ }, intl.get(NO_STATISTIC_RESULTS)), /*#__PURE__*/React.createElement("div", {
477
+ style: {
478
+ overflow: 'auto',
479
+ height: '100%',
480
+ display: 'flex',
481
+ padding: 15
482
+ },
483
+ ref: function ref(_ref) {
484
+ return _this5.container = _ref;
485
+ },
486
+ className: "".concat(styles['statistic-heatmap-container'], " statistic-chart-container")
487
+ }));
488
+ }
489
+ }]);
490
+ return HeatMap;
491
+ }(BaseChart);
492
+ HeatMap.propTypes = {
493
+ isPreview: PropTypes.bool,
494
+ isEnlarge: PropTypes.bool,
495
+ theme: PropTypes.string,
496
+ statItem: PropTypes.object,
497
+ chartCalculator: PropTypes.object,
498
+ getTableById: PropTypes.func,
499
+ toggleStatisticRecordsDialog: PropTypes.func
500
+ };
501
+ export default HeatMap;