sea-chart 0.0.1

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 (214) hide show
  1. package/README.md +4 -0
  2. package/lib/assets/icons/area-chart.svg +10 -0
  3. package/lib/assets/icons/bar-chart.svg +12 -0
  4. package/lib/assets/icons/card.svg +22 -0
  5. package/lib/assets/icons/combination-chart.svg +17 -0
  6. package/lib/assets/icons/dtable-logo.svg +16 -0
  7. package/lib/assets/icons/facet-chart.svg +12 -0
  8. package/lib/assets/icons/gauge.svg +18 -0
  9. package/lib/assets/icons/heat-map.svg +14 -0
  10. package/lib/assets/icons/histogram.svg +12 -0
  11. package/lib/assets/icons/line-chart.svg +12 -0
  12. package/lib/assets/icons/map.svg +20 -0
  13. package/lib/assets/icons/pie-chart.svg +11 -0
  14. package/lib/assets/icons/rectangular-tree-diagram.svg +10 -0
  15. package/lib/assets/icons/scatter-chart.svg +15 -0
  16. package/lib/assets/icons/type-change.svg +17 -0
  17. package/lib/assets/img/area-chart.png +0 -0
  18. package/lib/assets/img/area-group-chart.png +0 -0
  19. package/lib/assets/img/bar-group.png +0 -0
  20. package/lib/assets/img/bar-stack.png +0 -0
  21. package/lib/assets/img/bar.png +0 -0
  22. package/lib/assets/img/combination-chart.png +0 -0
  23. package/lib/assets/img/compared-chart.png +0 -0
  24. package/lib/assets/img/completeness-chart.png +0 -0
  25. package/lib/assets/img/custom-bar.png +0 -0
  26. package/lib/assets/img/dashboard-chart.png +0 -0
  27. package/lib/assets/img/group-completeness-chart.png +0 -0
  28. package/lib/assets/img/group_line.png +0 -0
  29. package/lib/assets/img/heat-map.png +0 -0
  30. package/lib/assets/img/horizontal-bar.png +0 -0
  31. package/lib/assets/img/horizontal-group-bar.png +0 -0
  32. package/lib/assets/img/line.png +0 -0
  33. package/lib/assets/img/map-bubble.png +0 -0
  34. package/lib/assets/img/map.png +0 -0
  35. package/lib/assets/img/mirror.png +0 -0
  36. package/lib/assets/img/number-card.png +0 -0
  37. package/lib/assets/img/pie.png +0 -0
  38. package/lib/assets/img/pivot-table.png +0 -0
  39. package/lib/assets/img/ring.png +0 -0
  40. package/lib/assets/img/scatter.png +0 -0
  41. package/lib/assets/img/stacked-horizontal-bar.png +0 -0
  42. package/lib/assets/img/treemap.png +0 -0
  43. package/lib/assets/img/trend-chart.png +0 -0
  44. package/lib/assets/img/world-map-bubble.png +0 -0
  45. package/lib/assets/img/world-map.png +0 -0
  46. package/lib/components/collaborator/index.js +24 -0
  47. package/lib/components/formatter/area.js +162 -0
  48. package/lib/components/formatter/bar-group.js +160 -0
  49. package/lib/components/formatter/bar.js +150 -0
  50. package/lib/components/formatter/basic-number-card.js +138 -0
  51. package/lib/components/formatter/chart-component.js +266 -0
  52. package/lib/components/formatter/combination.js +407 -0
  53. package/lib/components/formatter/dashboard.js +182 -0
  54. package/lib/components/formatter/horizontal-bar-group.js +161 -0
  55. package/lib/components/formatter/horizontal-bar.js +152 -0
  56. package/lib/components/formatter/horizontal-component.js +91 -0
  57. package/lib/components/formatter/index.js +181 -0
  58. package/lib/components/formatter/line-group.js +157 -0
  59. package/lib/components/formatter/line.js +170 -0
  60. package/lib/components/formatter/pie.js +201 -0
  61. package/lib/components/formatter/ring.js +277 -0
  62. package/lib/components/formatter/table/index.css +103 -0
  63. package/lib/components/formatter/table/index.js +42 -0
  64. package/lib/components/formatter/table/one-dimension-table-no-numeric-columns.js +145 -0
  65. package/lib/components/formatter/table/one-dimension-table-with-numeric-columns.js +193 -0
  66. package/lib/components/formatter/table/pivot-table-display-name.js +249 -0
  67. package/lib/components/formatter/table/two-dimension-table.js +241 -0
  68. package/lib/components/formatter/treemap.js +213 -0
  69. package/lib/components/icon/index.css +5 -0
  70. package/lib/components/icon/index.js +22 -0
  71. package/lib/components/index.js +5 -0
  72. package/lib/components/loading/index.css +54 -0
  73. package/lib/components/loading/index.js +10 -0
  74. package/lib/components/number-input/index.js +31 -0
  75. package/lib/components/pixel-editor/index.css +29 -0
  76. package/lib/components/pixel-editor/index.js +42 -0
  77. package/lib/components/select-group/index.css +67 -0
  78. package/lib/components/select-group/index.js +63 -0
  79. package/lib/components/settings/advance-bar-settings/data-settings.js +120 -0
  80. package/lib/components/settings/advance-bar-settings/index.js +3 -0
  81. package/lib/components/settings/advance-bar-settings/style-settings.js +149 -0
  82. package/lib/components/settings/bar-settings/data-settings.js +137 -0
  83. package/lib/components/settings/bar-settings/index.js +3 -0
  84. package/lib/components/settings/bar-settings/style-settings.js +163 -0
  85. package/lib/components/settings/basic-number-card/data-settings.js +121 -0
  86. package/lib/components/settings/basic-number-card/index.js +3 -0
  87. package/lib/components/settings/basic-number-card/style-settings.js +42 -0
  88. package/lib/components/settings/combination-settings/data-settings.js +256 -0
  89. package/lib/components/settings/combination-settings/index.js +3 -0
  90. package/lib/components/settings/combination-settings/style-settings.js +183 -0
  91. package/lib/components/settings/dashboard-settings/data-settings.js +167 -0
  92. package/lib/components/settings/dashboard-settings/index.js +2 -0
  93. package/lib/components/settings/data-settings.js +67 -0
  94. package/lib/components/settings/horizontal-bar-settings/data-settings.js +45 -0
  95. package/lib/components/settings/horizontal-bar-settings/index.js +3 -0
  96. package/lib/components/settings/horizontal-bar-settings/style-settings.js +38 -0
  97. package/lib/components/settings/index.css +73 -0
  98. package/lib/components/settings/index.js +74 -0
  99. package/lib/components/settings/pie-settings/data-settings.js +123 -0
  100. package/lib/components/settings/pie-settings/index.js +3 -0
  101. package/lib/components/settings/pie-settings/style-settings.js +123 -0
  102. package/lib/components/settings/style-settings.js +100 -0
  103. package/lib/components/settings/table-settings/data-settings.js +488 -0
  104. package/lib/components/settings/table-settings/index.js +2 -0
  105. package/lib/components/settings/time-comparison-settings/data-settings.js +157 -0
  106. package/lib/components/settings/time-comparison-settings/index.js +3 -0
  107. package/lib/components/settings/time-comparison-settings/style-settings.js +191 -0
  108. package/lib/components/settings/widgets/basic-summary/index.css +12 -0
  109. package/lib/components/settings/widgets/basic-summary/index.js +173 -0
  110. package/lib/components/settings/widgets/common-data-settings.js +42 -0
  111. package/lib/components/settings/widgets/data-filter/index.css +17 -0
  112. package/lib/components/settings/widgets/data-filter/index.js +76 -0
  113. package/lib/components/settings/widgets/data-sort.js +38 -0
  114. package/lib/components/settings/widgets/date-summary-item.js +126 -0
  115. package/lib/components/settings/widgets/display-values-settings/index.css +13 -0
  116. package/lib/components/settings/widgets/display-values-settings/index.js +37 -0
  117. package/lib/components/settings/widgets/divider/index.css +4 -0
  118. package/lib/components/settings/widgets/divider/index.js +10 -0
  119. package/lib/components/settings/widgets/font-settings/font-size-settings.js +31 -0
  120. package/lib/components/settings/widgets/font-settings/font-weight-settings.js +46 -0
  121. package/lib/components/settings/widgets/font-settings/index.js +3 -0
  122. package/lib/components/settings/widgets/group-by.js +168 -0
  123. package/lib/components/settings/widgets/label-color.js +30 -0
  124. package/lib/components/settings/widgets/min-max-setting.js +64 -0
  125. package/lib/components/settings/widgets/mininum-slice-percent.js +72 -0
  126. package/lib/components/settings/widgets/numeric-summary-item.js +109 -0
  127. package/lib/components/settings/widgets/select-table/index.css +0 -0
  128. package/lib/components/settings/widgets/select-table/index.js +49 -0
  129. package/lib/components/settings/widgets/stack.js +58 -0
  130. package/lib/components/settings/widgets/statistic-type/index.css +31 -0
  131. package/lib/components/settings/widgets/statistic-type/index.js +54 -0
  132. package/lib/components/settings/widgets/summary-method-setting.js +80 -0
  133. package/lib/components/settings/widgets/summary-settings.js +394 -0
  134. package/lib/components/settings/widgets/switch/index.css +37 -0
  135. package/lib/components/settings/widgets/switch/index.js +21 -0
  136. package/lib/components/settings/widgets/text-horizontal-settings.js +23 -0
  137. package/lib/components/settings/widgets/time-picker.js +182 -0
  138. package/lib/components/settings/widgets/title-settings/index.js +58 -0
  139. package/lib/components/settings/widgets/title-settings/title-text.js +31 -0
  140. package/lib/components/settings/widgets/x-axios.js +0 -0
  141. package/lib/components/settings/widgets/y-axis-group-settings.js +399 -0
  142. package/lib/components/types-dialog/index.css +97 -0
  143. package/lib/components/types-dialog/index.js +127 -0
  144. package/lib/constants/geolocation.js +11 -0
  145. package/lib/constants/index.js +164 -0
  146. package/lib/constants/model.js +167 -0
  147. package/lib/constants/style.js +13 -0
  148. package/lib/constants/type-image.js +32 -0
  149. package/lib/constants/type.js +97 -0
  150. package/lib/context.js +49 -0
  151. package/lib/index.js +6 -0
  152. package/lib/intl.js +37 -0
  153. package/lib/layout/index.js +4 -0
  154. package/lib/layout/statistic/index.css +53 -0
  155. package/lib/layout/statistic/index.js +190 -0
  156. package/lib/layout/title/index.css +3 -0
  157. package/lib/layout/title/index.js +41 -0
  158. package/lib/locale/index.js +11 -0
  159. package/lib/locale/lang/de.js +141 -0
  160. package/lib/locale/lang/en.js +143 -0
  161. package/lib/locale/lang/es.js +141 -0
  162. package/lib/locale/lang/fr.js +141 -0
  163. package/lib/locale/lang/pt.js +141 -0
  164. package/lib/locale/lang/ru.js +141 -0
  165. package/lib/locale/lang/zh_CN.js +143 -0
  166. package/lib/model/area-group.js +51 -0
  167. package/lib/model/area.js +42 -0
  168. package/lib/model/bar-group.js +54 -0
  169. package/lib/model/bar-stack.js +51 -0
  170. package/lib/model/bar.js +48 -0
  171. package/lib/model/base-model.js +11 -0
  172. package/lib/model/basic-number-card.js +32 -0
  173. package/lib/model/combination.js +48 -0
  174. package/lib/model/compare-bar.js +49 -0
  175. package/lib/model/completeness-group.js +34 -0
  176. package/lib/model/completeness.js +28 -0
  177. package/lib/model/dashboard.js +26 -0
  178. package/lib/model/generic-model.js +235 -0
  179. package/lib/model/heat-map.js +33 -0
  180. package/lib/model/horizontal-bar.js +48 -0
  181. package/lib/model/horizontal-group-bar.js +53 -0
  182. package/lib/model/index.js +36 -0
  183. package/lib/model/line-group.js +54 -0
  184. package/lib/model/line.js +48 -0
  185. package/lib/model/map-bubble.js +37 -0
  186. package/lib/model/map.js +37 -0
  187. package/lib/model/mirror.js +36 -0
  188. package/lib/model/pie.js +36 -0
  189. package/lib/model/ring.js +36 -0
  190. package/lib/model/scatter.js +29 -0
  191. package/lib/model/stacked-horizontal-bar.js +42 -0
  192. package/lib/model/statistic.js +22 -0
  193. package/lib/model/table.js +33 -0
  194. package/lib/model/tree-map.js +30 -0
  195. package/lib/model/trend.js +34 -0
  196. package/lib/model/user.js +22 -0
  197. package/lib/model/world-map-bubble.js +36 -0
  198. package/lib/model/world-map.js +36 -0
  199. package/lib/utils/cell-format-utils.js +41 -0
  200. package/lib/utils/chart.js +6 -0
  201. package/lib/utils/collaborator-utils.js +40 -0
  202. package/lib/utils/column-utils.js +247 -0
  203. package/lib/utils/custom-g2.js +612 -0
  204. package/lib/utils/data-filter/filter-item-utils.js +80 -0
  205. package/lib/utils/data-filter/filters-utils.js +406 -0
  206. package/lib/utils/data-filter/index.js +3 -0
  207. package/lib/utils/date-translate.js +66 -0
  208. package/lib/utils/index.js +50 -0
  209. package/lib/utils/key-generator.js +13 -0
  210. package/lib/utils/object-utils.js +61 -0
  211. package/lib/utils/options-utils.js +61 -0
  212. package/lib/utils/statistic-column-2-sql-column-utils.js +499 -0
  213. package/lib/utils/statistic-utils.js +1685 -0
  214. package/package.json +160 -0
@@ -0,0 +1,266 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import { Component } from 'react';
6
+ import { getTableById, getTableColumnByKey } from 'dtable-utils';
7
+ import { Chart } from '../../utils/custom-g2';
8
+ import { StatisticsUtils } from '../../utils';
9
+ import { STATISTIC_SUMMARY_TYPE, LABEL_POSITION_TYPE, STATISTIC_THEME_COLOR, EMPTY_NAME } from '../../constants';
10
+ import intl from '../../intl';
11
+ var ChartComponent = /*#__PURE__*/function (_Component) {
12
+ _inherits(ChartComponent, _Component);
13
+ var _super = _createSuper(ChartComponent);
14
+ function ChartComponent() {
15
+ var _this;
16
+ _classCallCheck(this, ChartComponent);
17
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
+ args[_key] = arguments[_key];
19
+ }
20
+ _this = _super.call.apply(_super, [this].concat(args));
21
+ _this.initChart = function (container, _ref) {
22
+ var appendPadding = _ref.appendPadding;
23
+ var config = {
24
+ container: container,
25
+ autoFit: true,
26
+ width: '100%',
27
+ height: '100%'
28
+ };
29
+ if (appendPadding) {
30
+ config.appendPadding = appendPadding;
31
+ }
32
+ _this.chart = new Chart(config);
33
+ };
34
+ _this.loadData = function (data) {
35
+ _this.chart.data(data, {
36
+ 'name': {
37
+ type: 'cat',
38
+ nice: false
39
+ }
40
+ });
41
+ };
42
+ _this.getChartDisplayLabels = function (containerWidth, minItemWidth, statistics) {
43
+ var labels = [];
44
+ var labelCount = Math.floor(containerWidth / minItemWidth);
45
+ labelCount = labelCount % 2 ? labelCount + 1 : labelCount;
46
+ var avg = Math.round(statistics.length / labelCount);
47
+ avg = avg > 2 ? avg : 2;
48
+ Array.isArray(statistics) && statistics.forEach(function (v, i) {
49
+ if (i % avg === 0) {
50
+ labels.push(v.name);
51
+ }
52
+ });
53
+ return labels;
54
+ };
55
+ _this.getChartGroupData = function (data) {
56
+ var chartGroupData = [];
57
+ Array.isArray(data) && data.forEach(function (item) {
58
+ if (!chartGroupData.find(function (g) {
59
+ return g.name === item.name;
60
+ })) {
61
+ chartGroupData.push(item);
62
+ }
63
+ });
64
+ return chartGroupData;
65
+ };
66
+ _this.drawLabels = function () {
67
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
68
+ if (!_this.chart) return;
69
+ var width = _this.chart.coordinateBBox.width;
70
+ _this.labelCount = data.length;
71
+ if (Math.floor(width / _this.labelCount) <= 20) {
72
+ var displayLabels = _this.getChartDisplayLabels(width, 20, data);
73
+ _this.labelCount = displayLabels.length;
74
+ _this.chart.scale('name', {
75
+ type: 'cat',
76
+ ticks: displayLabels
77
+ });
78
+ }
79
+ };
80
+ _this.renderAxisLabel = function (statistic, tables) {
81
+ if (!_this.chart || !statistic) return;
82
+ var _statistic$config = statistic.config,
83
+ table_id = _statistic$config.table_id,
84
+ x_axis_column_key = _statistic$config.x_axis_column_key,
85
+ y_axis_summary_column_key = _statistic$config.y_axis_summary_column_key,
86
+ y_axis_show_label = _statistic$config.y_axis_show_label,
87
+ x_axis_show_label = _statistic$config.x_axis_show_label,
88
+ y_axis_label_position = _statistic$config.y_axis_label_position,
89
+ x_axis_label_position = _statistic$config.x_axis_label_position,
90
+ y_axis_summary_type = _statistic$config.y_axis_summary_type;
91
+ var table = getTableById(tables, table_id);
92
+ var autoPadding = _this.chart.autoPadding;
93
+ var textColor = '#999';
94
+ var xAxisID = "chart-x-axis-label_".concat(statistic.id);
95
+ var chartContainer = _this.chart.getCanvas().get('container');
96
+ var xLabel = chartContainer.querySelector("#".concat(xAxisID));
97
+ if (!xLabel && x_axis_show_label) {
98
+ var div = document.createElement('div');
99
+ div.id = xAxisID;
100
+ div.className = 'chart-axis-label';
101
+ var column = getTableColumnByKey(table, x_axis_column_key);
102
+ div.innerHTML = "".concat(column ? column.name : '');
103
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
104
+ chartContainer.appendChild(div);
105
+ }
106
+ if (xLabel && x_axis_show_label) {
107
+ xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
108
+ }
109
+ if (xLabel && !x_axis_show_label) {
110
+ xLabel.parentNode.removeChild(xLabel);
111
+ }
112
+ var yAxisID = "chart-y-axis-label_".concat(statistic.id);
113
+ var yLabel = chartContainer.querySelector("#".concat(yAxisID));
114
+ if (!yLabel && y_axis_show_label) {
115
+ var _div = document.createElement('div');
116
+ _div.id = yAxisID;
117
+ _div.className = 'chart-axis-label';
118
+ if (y_axis_summary_type === STATISTIC_SUMMARY_TYPE.COUNT) {
119
+ _div.innerHTML = intl.get('Amount');
120
+ } else {
121
+ var _column = getTableColumnByKey(table, y_axis_summary_column_key) || {};
122
+ _div.innerHTML = _column.name || '';
123
+ }
124
+ var containerHeight = chartContainer.offsetHeight;
125
+ var textAlign = 'center';
126
+ if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
127
+ if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
128
+ _div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
129
+ chartContainer.appendChild(_div);
130
+ }
131
+ if (yLabel && y_axis_show_label) {
132
+ var _containerHeight = chartContainer.offsetHeight;
133
+ var _textAlign = 'center';
134
+ if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) _textAlign = 'left';
135
+ if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) _textAlign = 'right';
136
+ yLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(_containerHeight, "px; text-align: ").concat(_textAlign, "; top: 0; left: 0; transform: translate(-").concat(_containerHeight / 2 + 12, "px, ").concat((_containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
137
+ }
138
+ if (yLabel && !y_axis_show_label) {
139
+ yLabel.parentNode.removeChild(yLabel);
140
+ }
141
+ };
142
+ // Automatic adjustment of maximum and minimum values
143
+ _this.autoAdjustDataOptions = function (statistic) {
144
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
145
+ var summaryColumn = arguments.length > 2 ? arguments[2] : undefined;
146
+ if (!_this.chart || !statistic) return;
147
+ var valueScaleOptions = {};
148
+ var config = statistic.config;
149
+ var y_axis_auto_range = config.y_axis_auto_range,
150
+ y_axis_min = config.y_axis_min,
151
+ y_axis_max = config.y_axis_max,
152
+ y_axis_summary_method = config.y_axis_summary_method;
153
+ if (summaryColumn) {
154
+ valueScaleOptions['formatter'] = function (value) {
155
+ return StatisticsUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method);
156
+ };
157
+ }
158
+ if (y_axis_auto_range === undefined || y_axis_auto_range) {
159
+ valueScaleOptions['nice'] = true;
160
+ } else {
161
+ valueScaleOptions['min'] = y_axis_min;
162
+ valueScaleOptions['max'] = y_axis_max;
163
+ // set the filter rule
164
+ _this.chart.filter('value', function (value) {
165
+ return value >= y_axis_min;
166
+ });
167
+ // filter the data
168
+ _this.chart.filterData(data);
169
+ }
170
+ _this.chart.scale({
171
+ name: {
172
+ type: 'cat'
173
+ },
174
+ value: valueScaleOptions
175
+ });
176
+ };
177
+ // set axis label and tooltip
178
+ _this.setNameLabelAndTooltip = function () {
179
+ var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : STATISTIC_THEME_COLOR['light'];
180
+ var labelCount = arguments.length > 1 ? arguments[1] : undefined;
181
+ if (!_this.chart) return;
182
+ _this.chart.axis('name', {
183
+ line: {
184
+ style: theme.gridColor
185
+ },
186
+ label: {
187
+ style: {
188
+ fill: theme.textColor
189
+ },
190
+ offset: 20,
191
+ autoRotate: true,
192
+ rotate: labelCount > 11 ? 0.3 : 0,
193
+ formatter: function formatter(name) {
194
+ var isString = typeof name === 'string';
195
+ if (!isString) name = String(name);
196
+ if (name === 'undefined') {
197
+ return intl.get(EMPTY_NAME);
198
+ }
199
+ if (name.length > 10) {
200
+ return "".concat(name.slice(0, 10), "...");
201
+ }
202
+ return name;
203
+ }
204
+ }
205
+ });
206
+ };
207
+ // set value label
208
+ _this.setValueLabel = function () {
209
+ var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : STATISTIC_THEME_COLOR['light'];
210
+ if (!_this.chart) return;
211
+ _this.chart.axis('value', {
212
+ label: {
213
+ style: {
214
+ fill: theme.textColor
215
+ }
216
+ },
217
+ grid: {
218
+ line: {
219
+ style: {
220
+ stroke: theme.gridColor
221
+ }
222
+ }
223
+ }
224
+ });
225
+ };
226
+ // set legend
227
+ _this.setLegend = function (legendName, theme) {
228
+ var legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom';
229
+ if (!_this.chart) return;
230
+ _this.chart.legend(legendName, {
231
+ position: legendPosition,
232
+ itemName: {
233
+ style: {
234
+ fill: theme.textColor
235
+ },
236
+ formatter: function formatter(name) {
237
+ return !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
238
+ }
239
+ },
240
+ pageNavigator: {
241
+ text: {
242
+ style: {
243
+ fill: theme.textColor
244
+ }
245
+ },
246
+ marker: {
247
+ style: {
248
+ fill: theme.legendPageNavigatorMarkerColor,
249
+ inactiveFill: theme.legendPageNavigatorMarkerColor,
250
+ inactiveOpacity: 0.45
251
+ }
252
+ }
253
+ }
254
+ });
255
+ };
256
+ _this.isShowXAxisLabel = function (statistic) {
257
+ return !!(statistic && statistic.config && statistic.config.x_axis_show_label);
258
+ };
259
+ _this.isShowYAxisLabel = function (statistic) {
260
+ return !!(statistic && statistic.config && statistic.config.y_axis_show_label);
261
+ };
262
+ return _this;
263
+ }
264
+ return _createClass(ChartComponent);
265
+ }(Component);
266
+ export { ChartComponent as default };
@@ -0,0 +1,407 @@
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 classnames from 'classnames';
7
+ import { getTableById, getTableColumnByKey } from 'dtable-utils';
8
+ import { Chart } from '../../utils/custom-g2';
9
+ import { StatisticsUtils } from '../../utils';
10
+ import { STATISTIC_SUMMARY_TYPE, LABEL_COLORS, STATISTIC_SUMMARY_SHOW, LABEL_POSITION_TYPE, EMPTY_NAME } from '../../constants';
11
+ import intl from '../../intl';
12
+ var Combination = /*#__PURE__*/function (_React$Component) {
13
+ _inherits(Combination, _React$Component);
14
+ var _super = _createSuper(Combination);
15
+ function Combination(props) {
16
+ var _this;
17
+ _classCallCheck(this, Combination);
18
+ _this = _super.call(this, props);
19
+ _this.clearChart = function () {
20
+ _this.chart.annotation().clear(true);
21
+ _this.chart.clear(true);
22
+ };
23
+ _this.drawChart = function () {
24
+ var data = _this.props.result;
25
+ _this.draw(data);
26
+ };
27
+ _this.draw = function (data) {
28
+ if (!Array.isArray(data)) return;
29
+ var _this$props = _this.props,
30
+ statistic = _this$props.statistic,
31
+ theme = _this$props.theme,
32
+ tables = _this$props.tables,
33
+ themeName = _this$props.themeName;
34
+ var _statistic$config = statistic.config,
35
+ table_id = _statistic$config.table_id,
36
+ y_axis_left_summary_column = _statistic$config.y_axis_left_summary_column,
37
+ y_axis_right_summary_column = _statistic$config.y_axis_right_summary_column,
38
+ y_axis_left_summary_method = _statistic$config.y_axis_left_summary_method,
39
+ y_axis_right_summary_method = _statistic$config.y_axis_right_summary_method,
40
+ y_axis_left_summary_type = _statistic$config.y_axis_left_summary_type,
41
+ y_axis_right_summary_type = _statistic$config.y_axis_right_summary_type,
42
+ y_axis_left_group_by_multiple_numeric_column = _statistic$config.y_axis_left_group_by_multiple_numeric_column,
43
+ y_axis_auto_range_left = _statistic$config.y_axis_auto_range_left,
44
+ y_axis_min_left = _statistic$config.y_axis_min_left,
45
+ y_axis_max_left = _statistic$config.y_axis_max_left,
46
+ y_axis_auto_range_right = _statistic$config.y_axis_auto_range_right,
47
+ y_axis_min_right = _statistic$config.y_axis_min_right,
48
+ y_axis_max_right = _statistic$config.y_axis_max_right,
49
+ display_data = _statistic$config.display_data,
50
+ label_font_size = _statistic$config.label_font_size;
51
+ _this.chart = new Chart({
52
+ container: _this.container,
53
+ autoFit: true,
54
+ width: '100%',
55
+ height: '100%',
56
+ appendPadding: [display_data ? 17 : 0, 0, 0, 0]
57
+ });
58
+ var currentTheme = StatisticsUtils.getCurrentTheme(themeName);
59
+ _this.chart.data(data);
60
+ _this.chart.coordinate('rect');
61
+ var table = getTableById(tables, table_id);
62
+ var leftSummaryColumn = getTableColumnByKey(table, y_axis_left_summary_column) || {};
63
+ var rightSummaryColumn = getTableColumnByKey(table, y_axis_right_summary_column) || {};
64
+ var leftValueScaleOptions = {
65
+ formatter: function formatter(value) {
66
+ return StatisticsUtils.getSummaryValueDisplayString(leftSummaryColumn, value, y_axis_left_summary_method);
67
+ }
68
+ };
69
+ var rightValueScaleOptions = {
70
+ formatter: function formatter(value) {
71
+ return StatisticsUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method);
72
+ }
73
+ };
74
+ if (!y_axis_auto_range_left) {
75
+ leftValueScaleOptions = Object.assign(leftValueScaleOptions, {
76
+ min: y_axis_min_left,
77
+ max: y_axis_max_left
78
+ });
79
+ }
80
+ if (!y_axis_auto_range_right) {
81
+ rightValueScaleOptions = Object.assign(rightValueScaleOptions, {
82
+ min: y_axis_min_right,
83
+ max: y_axis_max_right
84
+ });
85
+ }
86
+ _this.chart.scale({
87
+ name: {
88
+ type: 'cat'
89
+ },
90
+ // Automatic adjustment of maximum and minimum values
91
+ value_left: leftValueScaleOptions,
92
+ value_right: rightValueScaleOptions
93
+ });
94
+ _this.chart.axis('name', {
95
+ label: {
96
+ style: {
97
+ fill: theme.textColor
98
+ },
99
+ formatter: function formatter(name) {
100
+ var isString = typeof name === 'string';
101
+ if (!isString) name = String(name);
102
+ if (name === 'undefined') {
103
+ return intl.get(EMPTY_NAME);
104
+ }
105
+ if (name.length > 10) {
106
+ return "".concat(name.slice(0, 10), "...");
107
+ }
108
+ return name;
109
+ }
110
+ },
111
+ line: {
112
+ style: theme.gridColor
113
+ }
114
+ });
115
+ _this.chart.axis('value_left', {
116
+ grid: {
117
+ line: {
118
+ style: {
119
+ stroke: theme.gridColor
120
+ }
121
+ }
122
+ },
123
+ label: {
124
+ style: {
125
+ fill: theme.textColor
126
+ }
127
+ }
128
+ });
129
+ _this.chart.axis('value_right', {
130
+ grid: null,
131
+ label: {
132
+ style: {
133
+ fill: theme.textColor
134
+ }
135
+ }
136
+ });
137
+ var legendPosition = 'bottom';
138
+ _this.chart.legend({
139
+ custom: true,
140
+ position: legendPosition,
141
+ itemName: {
142
+ style: {
143
+ fill: theme.textColor
144
+ }
145
+ },
146
+ items: _this.getLegend(leftSummaryColumn, rightSummaryColumn, table, currentTheme)
147
+ });
148
+ _this.chart.interval().position('name*value_left').color('color', function (color) {
149
+ if (!y_axis_left_group_by_multiple_numeric_column) {
150
+ return currentTheme.colors[0];
151
+ }
152
+ return color;
153
+ }).adjust('dodge').tooltip('name*value_left', function (name, value) {
154
+ return {
155
+ title: y_axis_left_summary_type === STATISTIC_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(STATISTIC_SUMMARY_SHOW[y_axis_left_summary_method]),
156
+ value: StatisticsUtils.getSummaryValueDisplayString(leftSummaryColumn, value, y_axis_left_summary_method),
157
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
158
+ };
159
+ });
160
+ _this.chart.tooltip({
161
+ showMarkers: false
162
+ });
163
+ _this.chart.line().position('name*value_right').color(currentTheme.colors[1]).size(3).tooltip('name*value_right', function (name, value) {
164
+ return {
165
+ title: y_axis_right_summary_type === STATISTIC_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(STATISTIC_SUMMARY_SHOW[y_axis_right_summary_method]),
166
+ value: StatisticsUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method),
167
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
168
+ };
169
+ });
170
+ _this.chart.point().position('name*value_right').color(currentTheme.colors[1]).size(3).shape('circle').label(display_data ? 'value_right' : false, {
171
+ style: {
172
+ fontSize: StatisticsUtils.getLabelFontSize(label_font_size),
173
+ fill: theme.textColor
174
+ }
175
+ }).tooltip('name*value_right', function (name, value) {
176
+ return {
177
+ title: y_axis_right_summary_type === STATISTIC_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(STATISTIC_SUMMARY_SHOW[y_axis_right_summary_method]),
178
+ value: StatisticsUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method),
179
+ name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
180
+ };
181
+ });
182
+ _this.chart.removeInteraction('legend-filter');
183
+ _this.chart.render();
184
+ _this.renderAxisLabel();
185
+ };
186
+ _this.renderAxisLabel = function () {
187
+ if (!_this.chart) return;
188
+ var _this$props2 = _this.props,
189
+ statistic = _this$props2.statistic,
190
+ tables = _this$props2.tables;
191
+ var config = statistic.config;
192
+ var table_id = config.table_id,
193
+ x_axis_column_key = config.x_axis_column_key,
194
+ show_y_axis_left_label = config.show_y_axis_left_label,
195
+ show_y_axis_right_label = config.show_y_axis_right_label,
196
+ x_axis_show_label = config.x_axis_show_label,
197
+ y_axis_left_label_position = config.y_axis_left_label_position,
198
+ y_axis_right_label_position = config.y_axis_right_label_position,
199
+ y_axis_left_summary_column = config.y_axis_left_summary_column,
200
+ y_axis_right_summary_column = config.y_axis_right_summary_column,
201
+ x_axis_label_position = config.x_axis_label_position,
202
+ y_axis_left_summary_type = config.y_axis_left_summary_type,
203
+ y_axis_right_summary_type = config.y_axis_right_summary_type;
204
+ var table = getTableById(tables, table_id);
205
+ var autoPadding = _this.chart.autoPadding;
206
+ var textColor = '#999';
207
+ var xAxisID = "chart-x-axis-label_".concat(statistic.id);
208
+ var chartContainer = _this.chart.getCanvas().get('container');
209
+ var xLabel = chartContainer.querySelector("#".concat(xAxisID));
210
+ if (!xLabel && x_axis_show_label) {
211
+ var div = document.createElement('div');
212
+ div.id = xAxisID;
213
+ div.className = 'chart-axis-label text-truncate';
214
+ var column = getTableColumnByKey(table, x_axis_column_key);
215
+ div.innerHTML = "".concat(column ? column.name : '');
216
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
217
+ chartContainer.appendChild(div);
218
+ }
219
+ if (xLabel && x_axis_show_label) {
220
+ xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
221
+ }
222
+ if (xLabel && !x_axis_show_label) {
223
+ xLabel.parentNode.removeChild(xLabel);
224
+ }
225
+ var yAxisLeftID = "chart-y-axis-left-label_".concat(statistic.id);
226
+ var yAxisLeftLabel = chartContainer.querySelector("#".concat(yAxisLeftID));
227
+ if (!yAxisLeftLabel && show_y_axis_left_label) {
228
+ var _div = document.createElement('div');
229
+ _div.id = yAxisLeftID;
230
+ _div.className = 'chart-axis-label text-truncate';
231
+ if (y_axis_left_summary_type === STATISTIC_SUMMARY_TYPE.COUNT) {
232
+ _div.innerHTML = intl.get('Amount');
233
+ } else {
234
+ var _column = getTableColumnByKey(table, y_axis_left_summary_column) || {};
235
+ _div.innerHTML = _column.name || '';
236
+ }
237
+ var containerHeight = chartContainer.offsetHeight;
238
+ var textAlign = 'center';
239
+ if (y_axis_left_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
240
+ if (y_axis_left_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
241
+ _div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
242
+ chartContainer.appendChild(_div);
243
+ }
244
+ if (yAxisLeftLabel && show_y_axis_left_label) {
245
+ var _containerHeight = chartContainer.offsetHeight;
246
+ var _textAlign = 'center';
247
+ if (y_axis_left_label_position === 'bottom') _textAlign = 'left';
248
+ if (y_axis_left_label_position === 'top') _textAlign = 'right';
249
+ yAxisLeftLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(_containerHeight, "px; text-align: ").concat(_textAlign, "; top: 0; left: 0; transform: translate(-").concat(_containerHeight / 2 + 12, "px, ").concat((_containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
250
+ }
251
+ if (yAxisLeftLabel && !show_y_axis_left_label) {
252
+ yAxisLeftLabel.parentNode.removeChild(yAxisLeftLabel);
253
+ }
254
+ var yAxisRightID = "chart-y-axis-right-label_".concat(statistic.id);
255
+ var yAxisRightLabel = chartContainer.querySelector("#".concat(yAxisRightID));
256
+ if (!yAxisRightLabel && show_y_axis_right_label) {
257
+ var _div2 = document.createElement('div');
258
+ _div2.id = yAxisRightID;
259
+ _div2.className = 'chart-axis-label text-truncate';
260
+ if (y_axis_right_summary_type === STATISTIC_SUMMARY_TYPE.COUNT) {
261
+ _div2.innerHTML = intl.get('Amount');
262
+ } else {
263
+ var _column2 = getTableColumnByKey(table, y_axis_right_summary_column) || {};
264
+ _div2.innerHTML = _column2.name || '';
265
+ }
266
+ var _containerHeight2 = chartContainer.offsetHeight;
267
+ var _textAlign2 = 'center';
268
+ if (y_axis_right_label_position === LABEL_POSITION_TYPE.BOTTOM) _textAlign2 = 'left';
269
+ if (y_axis_right_label_position === LABEL_POSITION_TYPE.TOP) _textAlign2 = 'right';
270
+ _div2.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(_containerHeight2, "px; text-align: ").concat(_textAlign2, "; top: 0; right: 0; transform: translate(").concat(_containerHeight2 / 2 + 12, "px, ").concat((_containerHeight2 - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
271
+ chartContainer.appendChild(_div2);
272
+ }
273
+ if (yAxisRightLabel && show_y_axis_right_label) {
274
+ var _containerHeight3 = chartContainer.offsetHeight;
275
+ var _textAlign3 = 'center';
276
+ if (y_axis_right_label_position === 'bottom') _textAlign3 = 'left';
277
+ if (y_axis_right_label_position === 'top') _textAlign3 = 'right';
278
+ yAxisRightLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(_containerHeight3, "px; text-align: ").concat(_textAlign3, "; top: 0; right: 0; transform: translate(").concat(_containerHeight3 / 2 + 12, "px, ").concat((_containerHeight3 - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
279
+ }
280
+ if (yAxisRightLabel && !show_y_axis_right_label) {
281
+ yAxisRightLabel.parentNode.removeChild(yAxisRightLabel);
282
+ }
283
+ };
284
+ _this.getLegend = function (leftSummaryColumn, rightSummaryColumn, table, currentTheme) {
285
+ var statistic = _this.props.statistic;
286
+ var _statistic$config2 = statistic.config,
287
+ y_axis_left_group_by_multiple_numeric_column = _statistic$config2.y_axis_left_group_by_multiple_numeric_column,
288
+ y_axis_left_group_by_numeric_columns = _statistic$config2.y_axis_left_group_by_numeric_columns;
289
+ var legendItems = [];
290
+ if (!y_axis_left_group_by_multiple_numeric_column) {
291
+ legendItems.push({
292
+ value: 'value_left',
293
+ name: leftSummaryColumn.name || intl.get('Left'),
294
+ marker: {
295
+ symbol: 'square',
296
+ style: {
297
+ fill: currentTheme.colors[0],
298
+ r: 5
299
+ }
300
+ }
301
+ }, {
302
+ value: 'value_right',
303
+ name: rightSummaryColumn.name || intl.get('Right'),
304
+ marker: {
305
+ symbol: 'hyphen',
306
+ style: {
307
+ stroke: currentTheme.colors[1],
308
+ r: 5,
309
+ lineWidth: 3
310
+ }
311
+ }
312
+ });
313
+ } else {
314
+ legendItems.push({
315
+ value: 'value_left',
316
+ name: leftSummaryColumn.name || intl.get('Left'),
317
+ marker: {
318
+ fill: LABEL_COLORS[0],
319
+ symbol: 'square',
320
+ style: {
321
+ r: 5
322
+ }
323
+ }
324
+ });
325
+ y_axis_left_group_by_numeric_columns.forEach(function (item, index) {
326
+ var column = getTableColumnByKey(table, item.column_key);
327
+ if (column) {
328
+ legendItems.push({
329
+ value: 'group_name',
330
+ name: column.name || intl.get('Left'),
331
+ marker: {
332
+ symbol: 'square',
333
+ style: {
334
+ fill: LABEL_COLORS[(index + 1) % 12],
335
+ r: 5
336
+ }
337
+ }
338
+ });
339
+ }
340
+ });
341
+ legendItems.push({
342
+ value: 'value_right',
343
+ name: rightSummaryColumn.name || intl.get('Right'),
344
+ marker: {
345
+ symbol: 'hyphen',
346
+ style: {
347
+ stroke: currentTheme.colors[1],
348
+ r: 5,
349
+ lineWidth: 3
350
+ }
351
+ }
352
+ });
353
+ }
354
+ return legendItems;
355
+ };
356
+ _this.isShowXAxisLabel = function (statistic) {
357
+ return !!(statistic && statistic.config && statistic.config.x_axis_show_label);
358
+ };
359
+ _this.isShowYAxisLeftLabel = function (statistic) {
360
+ return !!(statistic && statistic.config && statistic.config.show_y_axis_left_label);
361
+ };
362
+ _this.isShowYAxisRightLabel = function (statistic) {
363
+ return !!(statistic && statistic.config && statistic.config.show_y_axis_right_label);
364
+ };
365
+ _this.chart = null;
366
+ return _this;
367
+ }
368
+ _createClass(Combination, [{
369
+ key: "componentDidMount",
370
+ value: function componentDidMount() {
371
+ this.drawChart();
372
+ this.renderAxisLabel(this.props.statistic, this.props.tables);
373
+ }
374
+ }, {
375
+ key: "componentDidUpdate",
376
+ value: function componentDidUpdate(prevProps) {
377
+ if (StatisticsUtils.shouldChartComponentUpdate(prevProps, this.props)) {
378
+ this.chart && this.chart.destroy();
379
+ this.drawChart();
380
+ this.renderAxisLabel(prevProps.statistic, prevProps.tables);
381
+ }
382
+ }
383
+ }, {
384
+ key: "componentWillUnmount",
385
+ value: function componentWillUnmount() {
386
+ this.chart && this.chart.destroy();
387
+ }
388
+ }, {
389
+ key: "render",
390
+ value: function render() {
391
+ var _this2 = this;
392
+ var statistic = this.props.statistic;
393
+ return /*#__PURE__*/React.createElement("div", {
394
+ className: classnames('seastatistic-container w-100', {
395
+ 'show-x-axis-label': this.isShowXAxisLabel(statistic),
396
+ 'show-y-axis-left-label': this.isShowYAxisLeftLabel(statistic),
397
+ 'show-y-axis-right-label': this.isShowYAxisRightLabel(statistic)
398
+ }),
399
+ ref: function ref(_ref) {
400
+ return _this2.container = _ref;
401
+ }
402
+ });
403
+ }
404
+ }]);
405
+ return Combination;
406
+ }(React.Component);
407
+ export default Combination;